Logo ROOT   6.16/01
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/// Open a specified image file.
109
111{
112 TImage *img = Create();
113 char *fullname = gSystem->ExpandPathName(file);
114
115 if (img)
116 img->ReadImage(fullname, type);
117
118 delete [] fullname;
119
120 return img;
121}
122
123////////////////////////////////////////////////////////////////////////////////
124/// Open an image with the specified data in a Double_t array.
125
126TImage *TImage::Open(const char *name, const Double_t *imageData, UInt_t width,
127 UInt_t height, TImagePalette *palette)
128{
129 TImage *img = Create();
130
131 if (img) {
132 img->SetImage(imageData, width, height, palette);
133 img->SetName(name);
134 }
135 return img;
136}
137
138////////////////////////////////////////////////////////////////////////////////
139/// Open an image with the specified data in a TArrayD.
140
141TImage *TImage::Open(const char *name, const TArrayD &imageData, UInt_t width,
142 TImagePalette *palette)
143{
144 TImage *img = Create();
145
146 if (img) {
147 img->SetImage(imageData, width, palette);
148 img->SetName(name);
149 }
150 return img;
151}
152
153////////////////////////////////////////////////////////////////////////////////
154/// Open an image with the specified data in a TVectorD.
155
156TImage *TImage::Open(const char *name, const TVectorD &imageData, UInt_t width,
157 TImagePalette *palette)
158{
159 TImage *img = Create();
160
161 if (img) {
162 img->SetImage(imageData, width, palette);
163 img->SetName(name);
164 }
165 return img;
166}
167
168////////////////////////////////////////////////////////////////////////////////
169/// Create image from XPM data array.
170
172{
173 TImage *img = Create();
174
175 if (img) {
177 img->SetName("XPM_image");
178 }
179 return img;
180}
181
182
183TImage operator+(const TImage &i1, const TImage &i2) { TImage ret(i1); ret.Append(&i2, "+"); return ret; }
184TImage operator/(const TImage &i1, const TImage &i2) { TImage ret(i1); ret.Append(&i2, "/"); return ret; }
#define h(i)
Definition: RSha256.hxx:106
unsigned int UInt_t
Definition: RtypesCore.h:42
double Double_t
Definition: RtypesCore.h:55
#define ClassImp(name)
Definition: Rtypes.h:363
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
int type
Definition: TGX11.cxx:120
TImage operator+(const TImage &i1, const TImage &i2)
Definition: TImage.cxx:183
TImage operator/(const TImage &i1, const TImage &i2)
Definition: TImage.cxx:184
#define gROOT
Definition: TROOT.h:410
R__EXTERN TSystem * gSystem
Definition: TSystem.h:540
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:110
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 SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
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:2152
@ kIgnoreCase
Definition: TString.h:263
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition: TSystem.cxx:1264
Definition: file.py:1