Logo ROOT   6.12/07
Reference Guide
TImage.cxx
Go to the documentation of this file.
1 // @(#)root/graf:$Id$
2 // Author: Fons Rademakers 15/10/2001
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2001, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "TImage.h"
13 #include "TROOT.h"
14 #include "TPluginManager.h"
15 #include "TApplication.h"
16 #include "TSystem.h"
17 
19 
20 /** \class TImage
21 \ingroup BasicGraphics
22 
23 An abstract interface to image processing library.
24 
25 It allows for the reading and writing of images in different formats, several
26 image manipulations (scaling, tiling, merging, etc.) and displaying in pads.
27 
28 The concrete implementation of this class is done by the TASImage class. The
29 methods are documented in that class.
30 */
31 
32 ////////////////////////////////////////////////////////////////////////////////
33 /// Create an image.
34 /// Use ReadImage() or SetImage() to initialize the image.
35 
37 {
38  static TPluginHandler *h = 0;
39 
40  if (!h) {
41  h = gROOT->GetPluginManager()->FindHandler("TImage");
42  if (!h) return 0;
43  if (h->LoadPlugin() == -1) {
44  h = 0; // try to reload plugin next time
45  return 0;
46  }
47  }
48  TImage *img = (TImage *) h->ExecPlugin(0);
49  if (img) img->SetName("dummy_image");
50 
51  return img;
52 }
53 
54 ////////////////////////////////////////////////////////////////////////////////
55 /// Return the image type for the extension specified in filename.
56 /// Case of the extension is ignored. E.g. for a filename "myimg.GIF",
57 /// kGif is returned.
58 /// kAnimGif is returned if the file extension is ".anim.gif".
59 
61 {
62  if (!filename) return kUnknown;
63 
64  TString sFilename(filename);
65  if (sFilename.EndsWith(".xpm.gz", TString::kIgnoreCase))
66  return kGZCompressedXpm;
67  else if (sFilename.EndsWith(".xpm.z", TString::kIgnoreCase))
68  return kZCompressedXpm;
69  else if (sFilename.EndsWith(".png", TString::kIgnoreCase))
70  return kPng;
71  else if (sFilename.EndsWith(".jpeg", TString::kIgnoreCase))
72  return kJpeg;
73  else if (sFilename.EndsWith(".jpg", TString::kIgnoreCase))
74  return kJpeg;
75  else if (sFilename.EndsWith(".xcf", TString::kIgnoreCase))
76  return kXcf;
77  else if (sFilename.EndsWith(".ppm", TString::kIgnoreCase))
78  return kPpm;
79  else if (sFilename.EndsWith(".pnm", TString::kIgnoreCase))
80  return kPnm;
81  else if (sFilename.EndsWith(".bmp", TString::kIgnoreCase))
82  return kBmp;
83  else if (sFilename.EndsWith(".ico", TString::kIgnoreCase))
84  return kIco;
85  else if (sFilename.EndsWith(".cur", TString::kIgnoreCase))
86  return kCur;
87  else if (sFilename.EndsWith(".gif", TString::kIgnoreCase))
88  return kGif;
89  else if (sFilename.EndsWith(".tiff", TString::kIgnoreCase))
90  return kTiff;
91  else if (sFilename.EndsWith(".tif", TString::kIgnoreCase))
92  return kTiff;
93  else if (sFilename.EndsWith(".xbm", TString::kIgnoreCase))
94  return kXbm;
95  else if (sFilename.EndsWith(".fits", TString::kIgnoreCase))
96  return kFits;
97  else if (sFilename.EndsWith(".tga", TString::kIgnoreCase))
98  return kTga;
99  else if (sFilename.EndsWith(".xml", TString::kIgnoreCase))
100  return kXml;
101  else if (sFilename.EndsWith(".anim.gif", TString::kIgnoreCase))
102  return kAnimGif;
103 
104  return kUnknown;
105 }
106 
107 ////////////////////////////////////////////////////////////////////////////////
108 /// Open a specified image file.
109 
111 {
112  TImage *img = Create();
113  char *fullname = gSystem->ExpandPathName(file);
114 
115  if (img)
116  img->ReadImage(fullname, type);
117 
118  delete [] fullname;
119 
120  return img;
121 }
122 
123 ////////////////////////////////////////////////////////////////////////////////
124 /// Open an image with the specified data in a Double_t array.
125 
126 TImage *TImage::Open(const char *name, const Double_t *imageData, UInt_t width,
127  UInt_t height, TImagePalette *palette)
128 {
129  TImage *img = Create();
130 
131  if (img) {
132  img->SetImage(imageData, width, height, palette);
133  img->SetName(name);
134  }
135  return img;
136 }
137 
138 ////////////////////////////////////////////////////////////////////////////////
139 /// Open an image with the specified data in a TArrayD.
140 
141 TImage *TImage::Open(const char *name, const TArrayD &imageData, UInt_t width,
142  TImagePalette *palette)
143 {
144  TImage *img = Create();
145 
146  if (img) {
147  img->SetImage(imageData, width, palette);
148  img->SetName(name);
149  }
150  return img;
151 }
152 
153 ////////////////////////////////////////////////////////////////////////////////
154 /// Open an image with the specified data in a TVectorD.
155 
156 TImage *TImage::Open(const char *name, const TVectorD &imageData, UInt_t width,
157  TImagePalette *palette)
158 {
159  TImage *img = Create();
160 
161  if (img) {
162  img->SetImage(imageData, width, palette);
163  img->SetName(name);
164  }
165  return img;
166 }
167 
168 ////////////////////////////////////////////////////////////////////////////////
169 /// Create image from XPM data array.
170 
172 {
173  TImage *img = Create();
174 
175  if (img) {
176  img->SetImageBuffer(data, TImage::kXpm);
177  img->SetName("XPM_image");
178  }
179  return img;
180 }
181 
182 
183 TImage operator+(const TImage &i1, const TImage &i2) { TImage ret(i1); ret.Append(&i2, "+"); return ret; }
184 TImage operator/(const TImage &i1, const TImage &i2) { TImage ret(i1); ret.Append(&i2, "/"); return ret; }
virtual void Append(const TImage *, const char *="+", const char *="#00000000")
Definition: TImage.h:175
EImageFileTypes
Definition: TImage.h:36
friend TImage operator/(const TImage &i1, const TImage &s2)
Definition: TImage.cxx:184
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
TH1 * h
Definition: legend2.C:5
#define gROOT
Definition: TROOT.h:402
Int_t LoadPlugin()
Load the plugin library for this handler.
Basic string class.
Definition: TString.h:125
An abstract interface to image processing library.
Definition: TImage.h:29
virtual void SetImage(const Double_t *, UInt_t, UInt_t, TImagePalette *=0)
Definition: TImage.h:116
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2231
R__EXTERN TSystem * gSystem
Definition: TSystem.h:540
Long_t ExecPlugin(int nargs, const T &... params)
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void ReadImage(const char *, EImageFileTypes=TImage::kUnknown)
Definition: TImage.h:114
#define ClassImp(name)
Definition: Rtypes.h:359
double Double_t
Definition: RtypesCore.h:55
int type
Definition: TGX11.cxx:120
A class to define a conversion from pixel values to pixel color.
Definition: TAttImage.h:33
Array of doubles (64 bits per element).
Definition: TArrayD.h:27
static EImageFileTypes GetImageFileTypeFromFilename(const char *opt)
Return the image type for the extension specified in filename.
Definition: TImage.cxx:60
friend TImage operator+(const TImage &i1, const TImage &s2)
Definition: TImage.cxx:183
Definition: file.py:1
static TImage * Open(const char *file, EImageFileTypes type=kUnknown)
Open a specified image file.
Definition: TImage.cxx:110
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition: TSystem.cxx:1254
static TImage * Create()
Create an image.
Definition: TImage.cxx:36
virtual Bool_t SetImageBuffer(char **, EImageFileTypes=TImage::kPng)
Definition: TImage.h:242
char name[80]
Definition: TGX11.cxx:109