ROOT logo
// @(#)root/graf:$Id$
// Author: Fons Rademakers   15/10/2001

/*************************************************************************
 * Copyright (C) 1995-2001, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "TImage.h"
#include "TROOT.h"
#include "TPluginManager.h"
#include "TApplication.h"
#include "TSystem.h"

ClassImp(TImage)


//______________________________________________________________________________
/* Begin_Html
<center><h2>Image class</h2></center>
TImage is an abstract interface to image processing library.
It allows for the reading and writing of images in different formats, several
image manipulations (scaling, tiling, merging, etc.) and displaying in pads.
<p>
The concrete implementation of this class is done by the
<a href="http://root.cern.ch/root/html/TASImage.html">TASImage</a> class. The 
methods are documented in that class.
End_Html */


//______________________________________________________________________________
TImage *TImage::Create()
{
   // Create an image.
   // Use ReadImage() or SetImage() to initialize the image.

   static TPluginHandler *h = 0;

   if (!h) {
      h = gROOT->GetPluginManager()->FindHandler("TImage");
      if (!h) return 0;
      if (h->LoadPlugin() == -1) {
         h = 0;   // try to reload plugin next time
         return 0;
      }
   }
   TImage *img = (TImage *) h->ExecPlugin(0);
   if (img) img->SetName("dummy_image");

   return img;
}


//______________________________________________________________________________
TImage::EImageFileTypes TImage::GetImageFileTypeFromFilename(const char* filename)
{
   // Return the image type for the extension specified in filename.
   // Case of the extension is ignored. E.g. for a filename "myimg.GIF",
   // kGif is returned.
   // kAnimGif is returned if the file extension is ".anim.gif".

   if (!filename) return kUnknown;

   TString sFilename(filename);
   if (sFilename.EndsWith(".xpm.gz", TString::kIgnoreCase))
      return kGZCompressedXpm;
   else if (sFilename.EndsWith(".xpm.z", TString::kIgnoreCase))
      return kZCompressedXpm;
   else if (sFilename.EndsWith(".png", TString::kIgnoreCase))
      return kPng;
   else if (sFilename.EndsWith(".jpeg", TString::kIgnoreCase))
      return kJpeg;
   else if (sFilename.EndsWith(".jpg", TString::kIgnoreCase))
      return kJpeg;
   else if (sFilename.EndsWith(".xcf", TString::kIgnoreCase))
      return kXcf;
   else if (sFilename.EndsWith(".ppm", TString::kIgnoreCase))
      return kPpm;
   else if (sFilename.EndsWith(".pnm", TString::kIgnoreCase))
      return kPnm;
   else if (sFilename.EndsWith(".bmp", TString::kIgnoreCase))
      return kBmp;
   else if (sFilename.EndsWith(".ico", TString::kIgnoreCase))
      return kIco;
   else if (sFilename.EndsWith(".cur", TString::kIgnoreCase))
      return kCur;
   else if (sFilename.EndsWith(".gif", TString::kIgnoreCase))
      return kGif;
   else if (sFilename.EndsWith(".tiff", TString::kIgnoreCase))
      return kTiff;
   else if (sFilename.EndsWith(".tif", TString::kIgnoreCase))
      return kTiff;
   else if (sFilename.EndsWith(".xbm", TString::kIgnoreCase))
      return kXbm;
   else if (sFilename.EndsWith(".fits", TString::kIgnoreCase))
      return kFits;
   else if (sFilename.EndsWith(".tga", TString::kIgnoreCase))
      return kTga;
   else if (sFilename.EndsWith(".xml", TString::kIgnoreCase))
      return kXml;
   else if (sFilename.EndsWith(".anim.gif", TString::kIgnoreCase))
      return kAnimGif;

   return kUnknown;
}


//______________________________________________________________________________
TImage *TImage::Open(const char *file, EImageFileTypes type)
{
   // Open a specified image file.

   TImage *img = Create();
   char *fullname = gSystem->ExpandPathName(file);

   if (img)
      img->ReadImage(fullname, type);

   delete [] fullname;

   return img;
}


//______________________________________________________________________________
TImage *TImage::Open(const char *name, const Double_t *imageData, UInt_t width,
                     UInt_t height, TImagePalette *palette)
{
   // Open an image with the specified data in a Double_t array.

   TImage *img = Create();

   if (img) {
      img->SetImage(imageData, width, height, palette);
      img->SetName(name);
   }
   return img;
}


//______________________________________________________________________________
TImage *TImage::Open(const char *name, const TArrayD &imageData, UInt_t width,
                     TImagePalette *palette)
{
   // Open an image with the specified data in a TArrayD.

   TImage *img = Create();

   if (img) {
      img->SetImage(imageData, width, palette);
      img->SetName(name);
   }
   return img;
}


//______________________________________________________________________________
TImage *TImage::Open(const char *name, const TVectorD &imageData, UInt_t width,
                     TImagePalette *palette)
{
   // Open an image with the specified data in a TVectorD.

   TImage *img = Create();

   if (img) {
      img->SetImage(imageData, width, palette);
      img->SetName(name);
   }
   return img;
}


//______________________________________________________________________________
TImage *TImage::Open(char **data)
{
   // Create image from XPM data array.

   TImage *img = Create();

   if (img) {
      img->SetImageBuffer(data, TImage::kXpm);
      img->SetName("XPM_image");
   }
   return img;
}


TImage operator+(const TImage &i1, const TImage &i2) { TImage ret(i1); ret.Append(&i2, "+"); return ret; }
TImage operator/(const TImage &i1, const TImage &i2) { TImage ret(i1); ret.Append(&i2, "/"); return ret; }
 TImage.cxx:1
 TImage.cxx:2
 TImage.cxx:3
 TImage.cxx:4
 TImage.cxx:5
 TImage.cxx:6
 TImage.cxx:7
 TImage.cxx:8
 TImage.cxx:9
 TImage.cxx:10
 TImage.cxx:11
 TImage.cxx:12
 TImage.cxx:13
 TImage.cxx:14
 TImage.cxx:15
 TImage.cxx:16
 TImage.cxx:17
 TImage.cxx:18
 TImage.cxx:19
 TImage.cxx:20
 TImage.cxx:21
 TImage.cxx:22
 TImage.cxx:23
 TImage.cxx:24
 TImage.cxx:25
 TImage.cxx:26
 TImage.cxx:27
 TImage.cxx:28
 TImage.cxx:29
 TImage.cxx:30
 TImage.cxx:31
 TImage.cxx:32
 TImage.cxx:33
 TImage.cxx:34
 TImage.cxx:35
 TImage.cxx:36
 TImage.cxx:37
 TImage.cxx:38
 TImage.cxx:39
 TImage.cxx:40
 TImage.cxx:41
 TImage.cxx:42
 TImage.cxx:43
 TImage.cxx:44
 TImage.cxx:45
 TImage.cxx:46
 TImage.cxx:47
 TImage.cxx:48
 TImage.cxx:49
 TImage.cxx:50
 TImage.cxx:51
 TImage.cxx:52
 TImage.cxx:53
 TImage.cxx:54
 TImage.cxx:55
 TImage.cxx:56
 TImage.cxx:57
 TImage.cxx:58
 TImage.cxx:59
 TImage.cxx:60
 TImage.cxx:61
 TImage.cxx:62
 TImage.cxx:63
 TImage.cxx:64
 TImage.cxx:65
 TImage.cxx:66
 TImage.cxx:67
 TImage.cxx:68
 TImage.cxx:69
 TImage.cxx:70
 TImage.cxx:71
 TImage.cxx:72
 TImage.cxx:73
 TImage.cxx:74
 TImage.cxx:75
 TImage.cxx:76
 TImage.cxx:77
 TImage.cxx:78
 TImage.cxx:79
 TImage.cxx:80
 TImage.cxx:81
 TImage.cxx:82
 TImage.cxx:83
 TImage.cxx:84
 TImage.cxx:85
 TImage.cxx:86
 TImage.cxx:87
 TImage.cxx:88
 TImage.cxx:89
 TImage.cxx:90
 TImage.cxx:91
 TImage.cxx:92
 TImage.cxx:93
 TImage.cxx:94
 TImage.cxx:95
 TImage.cxx:96
 TImage.cxx:97
 TImage.cxx:98
 TImage.cxx:99
 TImage.cxx:100
 TImage.cxx:101
 TImage.cxx:102
 TImage.cxx:103
 TImage.cxx:104
 TImage.cxx:105
 TImage.cxx:106
 TImage.cxx:107
 TImage.cxx:108
 TImage.cxx:109
 TImage.cxx:110
 TImage.cxx:111
 TImage.cxx:112
 TImage.cxx:113
 TImage.cxx:114
 TImage.cxx:115
 TImage.cxx:116
 TImage.cxx:117
 TImage.cxx:118
 TImage.cxx:119
 TImage.cxx:120
 TImage.cxx:121
 TImage.cxx:122
 TImage.cxx:123
 TImage.cxx:124
 TImage.cxx:125
 TImage.cxx:126
 TImage.cxx:127
 TImage.cxx:128
 TImage.cxx:129
 TImage.cxx:130
 TImage.cxx:131
 TImage.cxx:132
 TImage.cxx:133
 TImage.cxx:134
 TImage.cxx:135
 TImage.cxx:136
 TImage.cxx:137
 TImage.cxx:138
 TImage.cxx:139
 TImage.cxx:140
 TImage.cxx:141
 TImage.cxx:142
 TImage.cxx:143
 TImage.cxx:144
 TImage.cxx:145
 TImage.cxx:146
 TImage.cxx:147
 TImage.cxx:148
 TImage.cxx:149
 TImage.cxx:150
 TImage.cxx:151
 TImage.cxx:152
 TImage.cxx:153
 TImage.cxx:154
 TImage.cxx:155
 TImage.cxx:156
 TImage.cxx:157
 TImage.cxx:158
 TImage.cxx:159
 TImage.cxx:160
 TImage.cxx:161
 TImage.cxx:162
 TImage.cxx:163
 TImage.cxx:164
 TImage.cxx:165
 TImage.cxx:166
 TImage.cxx:167
 TImage.cxx:168
 TImage.cxx:169
 TImage.cxx:170
 TImage.cxx:171
 TImage.cxx:172
 TImage.cxx:173
 TImage.cxx:174
 TImage.cxx:175
 TImage.cxx:176
 TImage.cxx:177
 TImage.cxx:178
 TImage.cxx:179
 TImage.cxx:180
 TImage.cxx:181
 TImage.cxx:182
 TImage.cxx:183
 TImage.cxx:184
 TImage.cxx:185
 TImage.cxx:186
 TImage.cxx:187
 TImage.cxx:188
 TImage.cxx:189
 TImage.cxx:190
 TImage.cxx:191
 TImage.cxx:192