Logo ROOT  
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 "TSystem.h"
16 
18 
19 /** \class TImage
20 \ingroup BasicGraphics
21 
22 An abstract interface to image processing library.
23 
24 It allows for the reading and writing of images in different formats, several
25 image manipulations (scaling, tiling, merging, etc.) and displaying in pads.
26 
27 The concrete implementation of this class is done by the TASImage class. The
28 methods are documented in that class.
29 */
30 
31 ////////////////////////////////////////////////////////////////////////////////
32 /// Create an image.
33 /// Use ReadImage() or SetImage() to initialize the image.
34 
36 {
37  static TPluginHandler *h = 0;
38 
39  if (!h) {
40  h = gROOT->GetPluginManager()->FindHandler("TImage");
41  if (!h) return 0;
42  if (h->LoadPlugin() == -1) {
43  h = 0; // try to reload plugin next time
44  return 0;
45  }
46  }
47  TImage *img = (TImage *) h->ExecPlugin(0);
48  if (img) img->SetName("dummy_image");
49 
50  return img;
51 }
52 
53 ////////////////////////////////////////////////////////////////////////////////
54 /// Return the image type for the extension specified in filename.
55 /// Case of the extension is ignored. E.g. for a filename "myimg.GIF",
56 /// kGif is returned.
57 /// kAnimGif is returned if the file extension is ".anim.gif".
58 
60 {
61  if (!filename) return kUnknown;
62 
63  TString sFilename(filename);
64  if (sFilename.EndsWith(".xpm.gz", TString::kIgnoreCase))
65  return kGZCompressedXpm;
66  else if (sFilename.EndsWith(".xpm.z", TString::kIgnoreCase))
67  return kZCompressedXpm;
68  else if (sFilename.EndsWith(".png", TString::kIgnoreCase))
69  return kPng;
70  else if (sFilename.EndsWith(".jpeg", TString::kIgnoreCase))
71  return kJpeg;
72  else if (sFilename.EndsWith(".jpg", TString::kIgnoreCase))
73  return kJpeg;
74  else if (sFilename.EndsWith(".xcf", TString::kIgnoreCase))
75  return kXcf;
76  else if (sFilename.EndsWith(".ppm", TString::kIgnoreCase))
77  return kPpm;
78  else if (sFilename.EndsWith(".pnm", TString::kIgnoreCase))
79  return kPnm;
80  else if (sFilename.EndsWith(".bmp", TString::kIgnoreCase))
81  return kBmp;
82  else if (sFilename.EndsWith(".ico", TString::kIgnoreCase))
83  return kIco;
84  else if (sFilename.EndsWith(".cur", TString::kIgnoreCase))
85  return kCur;
86  else if (sFilename.EndsWith(".gif", TString::kIgnoreCase))
87  return kGif;
88  else if (sFilename.EndsWith(".tiff", TString::kIgnoreCase))
89  return kTiff;
90  else if (sFilename.EndsWith(".tif", TString::kIgnoreCase))
91  return kTiff;
92  else if (sFilename.EndsWith(".xbm", TString::kIgnoreCase))
93  return kXbm;
94  else if (sFilename.EndsWith(".fits", TString::kIgnoreCase))
95  return kFits;
96  else if (sFilename.EndsWith(".tga", TString::kIgnoreCase))
97  return kTga;
98  else if (sFilename.EndsWith(".xml", TString::kIgnoreCase))
99  return kXml;
100  else if (sFilename.EndsWith(".anim.gif", TString::kIgnoreCase))
101  return kAnimGif;
102 
103  return kUnknown;
104 }
105 
106 ////////////////////////////////////////////////////////////////////////////////
107 /// List this image with its attributes.
108 
109 void TImage::ls(Option_t *) const
110 {
112  printf("TImage: \"%s\"\n", GetName() );
113 }
114 
115 ////////////////////////////////////////////////////////////////////////////////
116 /// Open a specified image file.
117 
119 {
120  TImage *img = Create();
121  char *fullname = gSystem->ExpandPathName(file);
122 
123  if (img)
124  img->ReadImage(fullname, type);
125 
126  delete [] fullname;
127 
128  return img;
129 }
130 
131 ////////////////////////////////////////////////////////////////////////////////
132 /// Open an image with the specified data in a Double_t array.
133 
134 TImage *TImage::Open(const char *name, const Double_t *imageData, UInt_t width,
135  UInt_t height, TImagePalette *palette)
136 {
137  TImage *img = Create();
138 
139  if (img) {
140  img->SetImage(imageData, width, height, palette);
141  img->SetName(name);
142  }
143  return img;
144 }
145 
146 ////////////////////////////////////////////////////////////////////////////////
147 /// Open an image with the specified data in a TArrayD.
148 
149 TImage *TImage::Open(const char *name, const TArrayD &imageData, UInt_t width,
150  TImagePalette *palette)
151 {
152  TImage *img = Create();
153 
154  if (img) {
155  img->SetImage(imageData, width, palette);
156  img->SetName(name);
157  }
158  return img;
159 }
160 
161 ////////////////////////////////////////////////////////////////////////////////
162 /// Open an image with the specified data in a TVectorD.
163 
164 TImage *TImage::Open(const char *name, const TVectorD &imageData, UInt_t width,
165  TImagePalette *palette)
166 {
167  TImage *img = Create();
168 
169  if (img) {
170  img->SetImage(imageData, width, palette);
171  img->SetName(name);
172  }
173  return img;
174 }
175 
176 ////////////////////////////////////////////////////////////////////////////////
177 /// Create image from XPM data array.
178 
179 TImage *TImage::Open(char **data)
180 {
181  TImage *img = Create();
182 
183  if (img) {
184  img->SetImageBuffer(data, TImage::kXpm);
185  img->SetName("XPM_image");
186  }
187  return img;
188 }
189 
190 
191 TImage operator+(const TImage &i1, const TImage &i2) { TImage ret(i1); ret.Append(&i2, "+"); return ret; }
192 TImage operator/(const TImage &i1, const TImage &i2) { TImage ret(i1); ret.Append(&i2, "/"); return ret; }
TImage::kPpm
@ kPpm
Definition: TImage.h:43
TNamed::SetName
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
Option_t
const char Option_t
Definition: RtypesCore.h:66
TImage::Create
static TImage * Create()
Create an image.
Definition: TImage.cxx:35
TImage::kCur
@ kCur
Definition: TImage.h:47
TImage::kBmp
@ kBmp
Definition: TImage.h:45
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TImage::SetImageBuffer
virtual Bool_t SetImageBuffer(char **, EImageFileTypes=TImage::kPng)
Definition: TImage.h:242
operator+
TImage operator+(const TImage &i1, const TImage &i2)
Definition: TImage.cxx:191
TString::kIgnoreCase
@ kIgnoreCase
Definition: TString.h:268
width
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
TImage::ls
virtual void ls(Option_t *option="") const
List this image with its attributes.
Definition: TImage.cxx:109
TImage
An abstract interface to image processing library.
Definition: TImage.h:29
TString::EndsWith
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2177
operator/
TImage operator/(const TImage &i1, const TImage &i2)
Definition: TImage.cxx:192
TImage::kGif
@ kGif
Definition: TImage.h:48
TImage::Open
static TImage * Open(const char *file, EImageFileTypes type=kUnknown)
Open a specified image file.
Definition: TImage.cxx:118
TString
Basic string class.
Definition: TString.h:136
TImage::GetImageFileTypeFromFilename
static EImageFileTypes GetImageFileTypeFromFilename(const char *opt)
Return the image type for the extension specified in filename.
Definition: TImage.cxx:59
TImage.h
TImage::kPnm
@ kPnm
Definition: TImage.h:44
TROOT.h
TImage::kGZCompressedXpm
@ kGZCompressedXpm
Definition: TImage.h:39
TPluginHandler
Definition: TPluginManager.h:101
TImage::Append
virtual void Append(const TImage *, const char *="+", const char *="#00000000")
Definition: TImage.h:175
TSystem.h
h
#define h(i)
Definition: RSha256.hxx:106
TImage::kXml
@ kXml
Definition: TImage.h:53
TImage::kJpeg
@ kJpeg
Definition: TImage.h:41
TImage::kUnknown
@ kUnknown
Definition: TImage.h:54
TImage::kZCompressedXpm
@ kZCompressedXpm
Definition: TImage.h:38
TImage::kTiff
@ kTiff
Definition: TImage.h:49
TSystem::ExpandPathName
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition: TSystem.cxx:1272
TImage::kXbm
@ kXbm
Definition: TImage.h:50
TROOT::IndentLevel
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition: TROOT.cxx:2806
unsigned int
TImage::kAnimGif
@ kAnimGif
Definition: TImage.h:55
gSystem
R__EXTERN TSystem * gSystem
Definition: TSystem.h:559
TVectorT< Double_t >
Double_t
double Double_t
Definition: RtypesCore.h:59
TPluginManager.h
file
Definition: file.py:1
TImage::kTga
@ kTga
Definition: TImage.h:52
name
char name[80]
Definition: TGX11.cxx:110
TImage::ReadImage
virtual void ReadImage(const char *, EImageFileTypes=TImage::kUnknown)
Definition: TImage.h:114
TImagePalette
A class to define a conversion from pixel values to pixel color.
Definition: TAttImage.h:33
TImage::SetImage
virtual void SetImage(const Double_t *, UInt_t, UInt_t, TImagePalette *=0)
Definition: TImage.h:116
TImage::kXcf
@ kXcf
Definition: TImage.h:42
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
type
int type
Definition: TGX11.cxx:121
TArrayD
Array of doubles (64 bits per element).
Definition: TArrayD.h:27
TImage::EImageFileTypes
EImageFileTypes
Definition: TImage.h:36
TImage::kIco
@ kIco
Definition: TImage.h:46
TImage::kPng
@ kPng
Definition: TImage.h:40
TImage::kFits
@ kFits
Definition: TImage.h:51
gROOT
#define gROOT
Definition: TROOT.h:406
TImage::kXpm
@ kXpm
Definition: TImage.h:37