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 "TApplication.h"
16#include "TSystem.h"
17
19
20/** \class TImage
21\ingroup BasicGraphics
22
23An abstract interface to image processing library.
24
25It allows for the reading and writing of images in different formats, several
26image manipulations (scaling, tiling, merging, etc.) and displaying in pads.
27
28The concrete implementation of this class is done by the TASImage class. The
29methods 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/// List this image with its attributes.
109
110void TImage::ls(Option_t *) const
111{
113 printf("TImage: \"%s\"\n", GetName() );
114}
115
116////////////////////////////////////////////////////////////////////////////////
117/// Open a specified image file.
118
120{
121 TImage *img = Create();
122 char *fullname = gSystem->ExpandPathName(file);
123
124 if (img)
125 img->ReadImage(fullname, type);
126
127 delete [] fullname;
128
129 return img;
130}
131
132////////////////////////////////////////////////////////////////////////////////
133/// Open an image with the specified data in a Double_t array.
134
135TImage *TImage::Open(const char *name, const Double_t *imageData, UInt_t width,
136 UInt_t height, TImagePalette *palette)
137{
138 TImage *img = Create();
139
140 if (img) {
141 img->SetImage(imageData, width, height, palette);
142 img->SetName(name);
143 }
144 return img;
145}
146
147////////////////////////////////////////////////////////////////////////////////
148/// Open an image with the specified data in a TArrayD.
149
150TImage *TImage::Open(const char *name, const TArrayD &imageData, UInt_t width,
151 TImagePalette *palette)
152{
153 TImage *img = Create();
154
155 if (img) {
156 img->SetImage(imageData, width, palette);
157 img->SetName(name);
158 }
159 return img;
160}
161
162////////////////////////////////////////////////////////////////////////////////
163/// Open an image with the specified data in a TVectorD.
164
165TImage *TImage::Open(const char *name, const TVectorD &imageData, UInt_t width,
166 TImagePalette *palette)
167{
168 TImage *img = Create();
169
170 if (img) {
171 img->SetImage(imageData, width, palette);
172 img->SetName(name);
173 }
174 return img;
175}
176
177////////////////////////////////////////////////////////////////////////////////
178/// Create image from XPM data array.
179
180TImage *TImage::Open(char **data)
181{
182 TImage *img = Create();
183
184 if (img) {
185 img->SetImageBuffer(data, TImage::kXpm);
186 img->SetName("XPM_image");
187 }
188 return img;
189}
190
191
192TImage operator+(const TImage &i1, const TImage &i2) { TImage ret(i1); ret.Append(&i2, "+"); return ret; }
193TImage operator/(const TImage &i1, const TImage &i2) { TImage ret(i1); ret.Append(&i2, "/"); return ret; }
#define h(i)
Definition: RSha256.hxx:106
double Double_t
Definition: RtypesCore.h:57
const char Option_t
Definition: RtypesCore.h:64
#define ClassImp(name)
Definition: Rtypes.h:361
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
char name[80]
Definition: TGX11.cxx:109
int type
Definition: TGX11.cxx:120
TImage operator+(const TImage &i1, const TImage &i2)
Definition: TImage.cxx:192
TImage operator/(const TImage &i1, const TImage &i2)
Definition: TImage.cxx:193
#define gROOT
Definition: TROOT.h:406
R__EXTERN TSystem * gSystem
Definition: TSystem.h:556
Array of doubles (64 bits per element).
Definition: TArrayD.h:27
A class to define a conversion from pixel values to pixel color.
Definition: TAttImage.h:33
An abstract interface to image processing library.
Definition: TImage.h:29
static TImage * Open(const char *file, EImageFileTypes type=kUnknown)
Open a specified image file.
Definition: TImage.cxx:119
EImageFileTypes
Definition: TImage.h:36
@ kBmp
Definition: TImage.h:45
@ kPng
Definition: TImage.h:40
@ kFits
Definition: TImage.h:51
@ kJpeg
Definition: TImage.h:41
@ kXcf
Definition: TImage.h:42
@ kPnm
Definition: TImage.h:44
@ kIco
Definition: TImage.h:46
@ kXml
Definition: TImage.h:53
@ kXpm
Definition: TImage.h:37
@ kPpm
Definition: TImage.h:43
@ kTga
Definition: TImage.h:52
@ kAnimGif
Definition: TImage.h:55
@ kZCompressedXpm
Definition: TImage.h:38
@ kUnknown
Definition: TImage.h:54
@ kXbm
Definition: TImage.h:50
@ kCur
Definition: TImage.h:47
@ kTiff
Definition: TImage.h:49
@ kGZCompressedXpm
Definition: TImage.h:39
@ kGif
Definition: TImage.h:48
virtual void ReadImage(const char *, EImageFileTypes=TImage::kUnknown)
Definition: TImage.h:114
virtual void SetImage(const Double_t *, UInt_t, UInt_t, TImagePalette *=0)
Definition: TImage.h:116
static TImage * Create()
Create an image.
Definition: TImage.cxx:36
virtual Bool_t SetImageBuffer(char **, EImageFileTypes=TImage::kPng)
Definition: TImage.h:242
virtual void Append(const TImage *, const char *="+", const char *="#00000000")
Definition: TImage.h:175
static EImageFileTypes GetImageFileTypeFromFilename(const char *opt)
Return the image type for the extension specified in filename.
Definition: TImage.cxx:60
virtual void ls(Option_t *option="") const
List this image with its attributes.
Definition: TImage.cxx:110
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition: TROOT.cxx:2781
Basic string class.
Definition: TString.h:131
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2177
@ kIgnoreCase
Definition: TString.h:263
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition: TSystem.cxx:1269
Definition: file.py:1