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
18
19/** \class TImage
20\ingroup BasicGraphics
21
22An abstract interface to image processing library.
23
24It allows for the reading and writing of images in different formats, several
25image manipulations (scaling, tiling, merging, etc.) and displaying in pads.
26
27The concrete implementation of this class is done by the TASImage class. The
28methods 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 = nullptr;
38
39 if (!h) {
40 h = gROOT->GetPluginManager()->FindHandler("TImage");
41 if (!h) return nullptr;
42 if (h->LoadPlugin() == -1) {
43 h = nullptr; // try to reload plugin next time
44 return nullptr;
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
109void 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
134TImage *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
149TImage *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
164TImage *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
180{
181 TImage *img = Create();
182
183 if (img) {
185 img->SetName("XPM_image");
186 }
187 return img;
188}
189
190
191TImage operator+(const TImage &i1, const TImage &i2) { TImage ret(i1); ret.Append(&i2, "+"); return ret; }
192TImage 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
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:382
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:191
TImage operator/(const TImage &i1, const TImage &i2)
Definition TImage.cxx:192
#define gROOT
Definition TROOT.h:406
R__EXTERN TSystem * gSystem
Definition TSystem.h:561
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:118
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
void ls(Option_t *option="") const override
List this image with its attributes.
Definition TImage.cxx:109
static TImage * Create()
Create an image.
Definition TImage.cxx:35
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:59
virtual void SetImage(const Double_t *, UInt_t, UInt_t, TImagePalette *=nullptr)
Definition TImage.h:116
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:140
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition TROOT.cxx:2895
Basic string class.
Definition TString.h:139
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition TString.cxx:2244
@ kIgnoreCase
Definition TString.h:277
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition TSystem.cxx:1274