Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
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
17
18/** \class TImage
19\ingroup BasicGraphics
20
21An abstract interface to image processing library.
22
23It allows for the reading and writing of images in different formats, several
24image manipulations (scaling, tiling, merging, etc.) and displaying in pads.
25
26The concrete implementation of this class is done by the TASImage class. The
27methods are documented in that class.
28*/
29
30////////////////////////////////////////////////////////////////////////////////
31/// Create an image.
32/// Use ReadImage() or SetImage() to initialize the image.
33
35{
36 static TPluginHandler *h = nullptr;
37
38 if (!h) {
39 h = gROOT->GetPluginManager()->FindHandler("TImage");
40 if (!h) return nullptr;
41 if (h->LoadPlugin() == -1) {
42 h = nullptr; // try to reload plugin next time
43 return nullptr;
44 }
45 }
46 TImage *img = (TImage *) h->ExecPlugin(0);
47 if (img) img->SetName("dummy_image");
48
49 return img;
50}
51
52////////////////////////////////////////////////////////////////////////////////
53/// Return the image type for the extension specified in filename.
54/// Case of the extension is ignored. E.g. for a filename "myimg.GIF",
55/// kGif is returned.
56/// kAnimGif is returned if the file extension is ".anim.gif".
57
59{
60 if (!filename) return kUnknown;
61
62 TString sFilename(filename);
63 if (sFilename.EndsWith(".xpm.gz", TString::kIgnoreCase))
64 return kGZCompressedXpm;
65 else if (sFilename.EndsWith(".xpm.z", TString::kIgnoreCase))
66 return kZCompressedXpm;
67 else if (sFilename.EndsWith(".png", TString::kIgnoreCase))
68 return kPng;
69 else if (sFilename.EndsWith(".jpeg", TString::kIgnoreCase))
70 return kJpeg;
71 else if (sFilename.EndsWith(".jpg", TString::kIgnoreCase))
72 return kJpeg;
73 else if (sFilename.EndsWith(".xcf", TString::kIgnoreCase))
74 return kXcf;
75 else if (sFilename.EndsWith(".ppm", TString::kIgnoreCase))
76 return kPpm;
77 else if (sFilename.EndsWith(".pnm", TString::kIgnoreCase))
78 return kPnm;
79 else if (sFilename.EndsWith(".bmp", TString::kIgnoreCase))
80 return kBmp;
81 else if (sFilename.EndsWith(".ico", TString::kIgnoreCase))
82 return kIco;
83 else if (sFilename.EndsWith(".cur", TString::kIgnoreCase))
84 return kCur;
85 else if (sFilename.EndsWith(".gif", TString::kIgnoreCase))
86 return kGif;
87 else if (sFilename.EndsWith(".tiff", TString::kIgnoreCase))
88 return kTiff;
89 else if (sFilename.EndsWith(".tif", TString::kIgnoreCase))
90 return kTiff;
91 else if (sFilename.EndsWith(".xbm", TString::kIgnoreCase))
92 return kXbm;
93 else if (sFilename.EndsWith(".fits", TString::kIgnoreCase))
94 return kFits;
95 else if (sFilename.EndsWith(".tga", TString::kIgnoreCase))
96 return kTga;
97 else if (sFilename.EndsWith(".xml", TString::kIgnoreCase))
98 return kXml;
99 else if (sFilename.EndsWith(".anim.gif", TString::kIgnoreCase))
100 return kAnimGif;
101
102 return kUnknown;
103}
104
105////////////////////////////////////////////////////////////////////////////////
106/// List this image with its attributes.
107
108void TImage::ls(Option_t *) const
109{
111 printf("TImage: \"%s\"\n", GetName() );
112}
113
114////////////////////////////////////////////////////////////////////////////////
115/// Open a specified image file.
116
117TImage *TImage::Open(const char *file, EImageFileTypes type)
118{
119 TImage *img = Create();
120 char *fullname = gSystem->ExpandPathName(file);
121
122 if (img)
123 img->ReadImage(fullname, type);
124
125 delete [] fullname;
126
127 return img;
128}
129
130////////////////////////////////////////////////////////////////////////////////
131/// Open an image with the specified data in a Double_t array.
132
133TImage *TImage::Open(const char *name, const Double_t *imageData, UInt_t width,
134 UInt_t height, TImagePalette *palette)
135{
136 TImage *img = Create();
137
138 if (img) {
139 img->SetImage(imageData, width, height, palette);
140 img->SetName(name);
141 }
142 return img;
143}
144
145////////////////////////////////////////////////////////////////////////////////
146/// Open an image with the specified data in a TArrayD.
147
148TImage *TImage::Open(const char *name, const TArrayD &imageData, UInt_t width,
149 TImagePalette *palette)
150{
151 TImage *img = Create();
152
153 if (img) {
154 img->SetImage(imageData, width, palette);
155 img->SetName(name);
156 }
157 return img;
158}
159
160////////////////////////////////////////////////////////////////////////////////
161/// Open an image with the specified data in a TVectorD.
162
163TImage *TImage::Open(const char *name, const TVectorD &imageData, UInt_t width,
164 TImagePalette *palette)
165{
166 TImage *img = Create();
167
168 if (img) {
169 img->SetImage(imageData, width, palette);
170 img->SetName(name);
171 }
172 return img;
173}
174
175////////////////////////////////////////////////////////////////////////////////
176/// Create image from XPM data array.
177
178TImage *TImage::Open(char **data)
179{
180 TImage *img = Create();
181
182 if (img) {
183 img->SetImageBuffer(data, TImage::kXpm);
184 img->SetName("XPM_image");
185 }
186 return img;
187}
188
189
190////////////////////////////////////////////////////////////////////////////////
191/// Draw text on specified pad, check pad clipping rules
192
194{
195 // call simple DrawText to ensure minimal backward compatibility
196
197 DrawText(text, x, y);
198}
199
200
201TImage operator+(const TImage &i1, const TImage &i2) { TImage ret(i1); ret.Append(&i2, "+"); return ret; }
202TImage operator/(const TImage &i1, const TImage &i2) { TImage ret(i1); ret.Append(&i2, "/"); return ret; }
#define h(i)
Definition RSha256.hxx:106
char * ret
Definition Rotated.cxx:221
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
const char Option_t
Option string (const char).
Definition RtypesCore.h:80
char name[80]
Definition TGX11.cxx:148
TImage operator+(const TImage &i1, const TImage &i2)
Definition TImage.cxx:201
TImage operator/(const TImage &i1, const TImage &i2)
Definition TImage.cxx:202
#define gROOT
Definition TROOT.h:417
externTSystem * gSystem
Definition TSystem.h:582
TVectorT< Double_t > TVectorD
Definition TVectorDfwd.h:23
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
static TImage * Open(const char *file, EImageFileTypes type=kUnknown)
Open a specified image file.
Definition TImage.cxx:117
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 DrawText(Int_t=0, Int_t=0, const char *="", Int_t=12, const char *=nullptr, const char *="fixed", EText3DType=TImage::kPlain, const char *=nullptr, Float_t=0)
Definition TImage.h:200
virtual void ReadImage(const char *, EImageFileTypes=TImage::kUnknown)
Definition TImage.h:114
TImage(const char *file)
Definition TImage.h:99
void ls(Option_t *option="") const override
List this image with its attributes.
Definition TImage.cxx:108
static TImage * Create()
Create an image.
Definition TImage.cxx:34
virtual Bool_t SetImageBuffer(char **, EImageFileTypes=TImage::kPng)
Definition TImage.h:243
static EImageFileTypes GetImageFileTypeFromFilename(const char *opt)
Return the image type for the extension specified in filename.
Definition TImage.cxx:58
virtual void SetImage(const Double_t *, UInt_t, UInt_t, TImagePalette *=nullptr)
Definition TImage.h:116
virtual void DrawTextOnPad(TText *, Int_t=0, Int_t=0, TVirtualPad *=nullptr, Int_t=0, Int_t=0)
Draw text on specified pad, check pad clipping rules.
Definition TImage.cxx:193
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:149
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition TROOT.cxx:3052
Basic string class.
Definition TString.h:138
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition TString.cxx:2250
@ kIgnoreCase
Definition TString.h:285
Definition TText.h:22
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
TText * text
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17