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
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
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
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
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
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
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
190TImage operator+(const TImage &i1, const TImage &i2) { TImage ret(i1); ret.Append(&i2, "+"); return ret; }
191TImage operator/(const TImage &i1, const TImage &i2) { TImage ret(i1); ret.Append(&i2, "/"); return ret; }
#define h(i)
Definition RSha256.hxx:106
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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 const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
char name[80]
Definition TGX11.cxx:110
TImage operator+(const TImage &i1, const TImage &i2)
Definition TImage.cxx:190
TImage operator/(const TImage &i1, const TImage &i2)
Definition TImage.cxx:191
#define gROOT
Definition TROOT.h:411
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
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: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
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
static EImageFileTypes GetImageFileTypeFromFilename(const char *opt)
Return the image type for the extension specified in filename.
Definition TImage.cxx:58
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition TROOT.cxx:2898
Basic string class.
Definition TString.h:138
@ kIgnoreCase
Definition TString.h:285
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition TSystem.cxx:1285