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 else if (sFilename.EndsWith(".html", TString::kIgnoreCase))
102 return kHtml;
103 else if (sFilename.EndsWith(".svg", TString::kIgnoreCase))
104 return kSvg;
105 else if (sFilename.EndsWith(".pdf", TString::kIgnoreCase))
106 return kPdf;
107
108 return kUnknown;
109}
110
111////////////////////////////////////////////////////////////////////////////////
112/// List this image with its attributes.
113
114void TImage::ls(Option_t *) const
115{
117 printf("TImage: \"%s\"\n", GetName() );
118}
119
120////////////////////////////////////////////////////////////////////////////////
121/// Open a specified image file.
122
124{
125 TImage *img = Create();
126 char *fullname = gSystem->ExpandPathName(file);
127
128 if (img)
129 img->ReadImage(fullname, type);
130
131 delete [] fullname;
132
133 return img;
134}
135
136////////////////////////////////////////////////////////////////////////////////
137/// Open an image with the specified data in a Double_t array.
138
139TImage *TImage::Open(const char *name, const Double_t *imageData, UInt_t width,
140 UInt_t height, TImagePalette *palette)
141{
142 TImage *img = Create();
143
144 if (img) {
145 img->SetImage(imageData, width, height, palette);
146 img->SetName(name);
147 }
148 return img;
149}
150
151////////////////////////////////////////////////////////////////////////////////
152/// Open an image with the specified data in a TArrayD.
153
154TImage *TImage::Open(const char *name, const TArrayD &imageData, UInt_t width,
155 TImagePalette *palette)
156{
157 TImage *img = Create();
158
159 if (img) {
160 img->SetImage(imageData, width, palette);
161 img->SetName(name);
162 }
163 return img;
164}
165
166////////////////////////////////////////////////////////////////////////////////
167/// Open an image with the specified data in a TVectorD.
168
169TImage *TImage::Open(const char *name, const TVectorD &imageData, UInt_t width,
170 TImagePalette *palette)
171{
172 TImage *img = Create();
173
174 if (img) {
175 img->SetImage(imageData, width, palette);
176 img->SetName(name);
177 }
178 return img;
179}
180
181////////////////////////////////////////////////////////////////////////////////
182/// Create image from XPM data array.
183
185{
186 TImage *img = Create();
187
188 if (img) {
190 img->SetName("XPM_image");
191 }
192 return img;
193}
194
195
196////////////////////////////////////////////////////////////////////////////////
197/// Draw text on specified pad, check pad clipping rules
198
199void TImage::DrawTextOnPad(TText *text, Int_t x, Int_t y, TVirtualPad *, Int_t, Int_t)
200{
201 // call simple DrawText to ensure minimal backward compatibility
202
203 DrawText(text, x, y);
204}
205
206
207TImage operator+(const TImage &i1, const TImage &i2) { TImage ret(i1); ret.Append(&i2, "+"); return ret; }
208TImage operator/(const TImage &i1, const TImage &i2) { TImage ret(i1); ret.Append(&i2, "/"); return ret; }
#define h(i)
Definition RSha256.hxx:106
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
const char Option_t
Option string (const char)
Definition RtypesCore.h:81
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
Option_t Option_t TPoint TPoint DrawText
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
Option_t Option_t TPoint TPoint const char text
char name[80]
Definition TGX11.cxx:142
TImage operator+(const TImage &i1, const TImage &i2)
Definition TImage.cxx:207
TImage operator/(const TImage &i1, const TImage &i2)
Definition TImage.cxx:208
#define gROOT
Definition TROOT.h:417
R__EXTERN TSystem * gSystem
Definition TSystem.h:582
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:30
static TImage * Open(const char *file, EImageFileTypes type=kUnknown)
Open a specified image file.
Definition TImage.cxx:123
EImageFileTypes
Definition TImage.h:37
@ kBmp
Definition TImage.h:46
@ kPng
Definition TImage.h:41
@ kFits
Definition TImage.h:52
@ kPdf
Definition TImage.h:59
@ kJpeg
Definition TImage.h:42
@ kXcf
Definition TImage.h:43
@ kPnm
Definition TImage.h:45
@ kIco
Definition TImage.h:47
@ kXml
Definition TImage.h:54
@ kXpm
Definition TImage.h:38
@ kPpm
Definition TImage.h:44
@ kTga
Definition TImage.h:53
@ kAnimGif
Definition TImage.h:56
@ kZCompressedXpm
Definition TImage.h:39
@ kUnknown
Definition TImage.h:55
@ kSvg
Definition TImage.h:58
@ kXbm
Definition TImage.h:51
@ kCur
Definition TImage.h:48
@ kHtml
Definition TImage.h:57
@ kTiff
Definition TImage.h:50
@ kGZCompressedXpm
Definition TImage.h:40
@ kGif
Definition TImage.h:49
virtual void ReadImage(const char *, EImageFileTypes=TImage::kUnknown)
Definition TImage.h:118
void ls(Option_t *option="") const override
List this image with its attributes.
Definition TImage.cxx:114
static TImage * Create()
Create an image.
Definition TImage.cxx:34
virtual Bool_t SetImageBuffer(char **, EImageFileTypes=TImage::kPng)
Definition TImage.h:264
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:120
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:3067
Basic string class.
Definition TString.h:137
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition TString.cxx:2325
@ kIgnoreCase
Definition TString.h:284
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition TSystem.cxx:1296
Base class for several text objects.
Definition TText.h:22
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:53
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17