Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TImage.h
Go to the documentation of this file.
1 // @(#)root/graf:$Id$
2 // Author: Fons Rademakers, Reiner Rohlfs 15/10/2001
3 
4 /*************************************************************************
5  * Copyright (C) 2001-2001, Rene Brun, Fons Rademakers and Reiner Rohlfs *
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 #ifndef ROOT_TImage
13 #define ROOT_TImage
14 
15 
16 #include "TNamed.h"
17 
18 #include "TAttImage.h"
19 #include "GuiTypes.h"
20 #include "TVectorDfwd.h"
21 
22 class TVirtualPad;
23 class TArrayD;
24 class TArrayL;
25 class TH2D;
26 class TPoint;
27 class TText;
28 
29 class TImage : public TNamed, public TAttImage {
30 
31 friend TImage operator+(const TImage &i1, const TImage &s2);
32 friend TImage operator/(const TImage &i1, const TImage &s2);
33 
34 public:
35  // Defines image file types
36  enum EImageFileTypes {
37  kXpm = 0,
38  kZCompressedXpm,
39  kGZCompressedXpm,
40  kPng,
41  kJpeg,
42  kXcf,
43  kPpm,
44  kPnm,
45  kBmp,
46  kIco,
47  kCur,
48  kGif,
49  kTiff,
50  kXbm,
51  kFits,
52  kTga,
53  kXml,
54  kUnknown,
55  kAnimGif
56  };
57 
58  enum EText3DType {
59  kPlain = 0, // regular 2D text
60  kEmbossed,
61  kSunken,
62  kShadeAbove,
63  kShadeBelow,
64  kEmbossedThick,
65  kSunkenThick,
66  kOutlineAbove,
67  kOutlineBelow,
68  kOutlineFull,
69  k3DTypes
70  };
71 
72  enum ECharType {
73  kUTF8 = 0,
74  kChar = 1,
75  kUnicode = 4
76  };
77 
78  enum ETileType {
79  kStretch = 0,
80  kTile,
81  kStretchY,
82  kStretchX
83  };
84 
85  enum ECoordMode {
86  kCoordModeOrigin = 0,
87  kCoordModePrevious
88  };
89 
90  enum EColorChan {
91  kRedChan = BIT(0),
92  kGreenChan = BIT(1),
93  kBlueChan = BIT(2),
94  kAlphaChan = BIT(3),
95  kAllChan = kRedChan | kGreenChan | kBlueChan | kAlphaChan
96  };
97 
98 protected:
99  TImage(const char *file) : TNamed(file, "") { }
100  TImage() { }
101 
102 public:
103  TImage(const TImage &img) : TNamed(img), TAttImage(img) { }
104  TImage &operator=(const TImage &img)
105  { TNamed::operator=(img); TAttImage::operator=(img); return *this; }
106  TImage(UInt_t /*w*/, UInt_t /*h*/) : TNamed(), TAttImage() { }
107 
108  virtual ~TImage() { }
109 
110  // Cloning
111  virtual TObject *Clone(const char *) const { return 0; }
112 
113  // Input / output
114  virtual void ReadImage(const char * /*file*/, EImageFileTypes /*type*/ = TImage::kUnknown) {}
115  virtual void WriteImage(const char * /*file*/, EImageFileTypes /*type*/ = TImage::kUnknown) {}
116  virtual void SetImage(const Double_t * /*imageData*/, UInt_t /*width*/, UInt_t /*height*/, TImagePalette * /*palette*/ = 0) {}
117  virtual void SetImage(const TArrayD & /*imageData*/, UInt_t /*width*/, TImagePalette * /*palette*/ = 0) {}
118  virtual void SetImage(const TVectorD & /*imageData*/, UInt_t /*width*/, TImagePalette * /*palette*/ = 0) {}
119  virtual void SetImage(Pixmap_t /*pxm*/, Pixmap_t /*mask*/ = 0) {}
120 
121  // Create an image from the given pad. (See TASImage::FromPad)
122  virtual void FromPad(TVirtualPad * /*pad*/, Int_t /*x*/ = 0, Int_t /*y*/ = 0, UInt_t /*w*/ = 0, UInt_t /*h*/ = 0) {}
123 
124  // Restore the image original size. (See TASImage::UnZoom)
125  virtual void UnZoom() {}
126 
127  // Zoom the image. (See TASImage::Zoom)
128  virtual void Zoom(UInt_t /*offX*/, UInt_t /*offY*/, UInt_t /*width*/, UInt_t /*height*/) {}
129 
130  // Flip the image by a multiple of 90 degrees. (See TASImage::Flip)
131  virtual void Flip(Int_t /*flip*/ = 180) {}
132 
133  // Converts image to Gray. (See TASImage::Gray)
134  virtual void Gray(Bool_t /*on*/ = kTRUE) {}
135  virtual Bool_t IsGray() const { return kFALSE; }
136 
137  // Mirror the image. (See TASImage::Mirror)
138  virtual void Mirror(Bool_t /*vert*/ = kTRUE) {}
139 
140  // Scale the image. (See TASImage::Scale)
141  virtual void Scale(UInt_t /*width*/, UInt_t /*height*/) {}
142 
143  // Slice the image. (See TASImage::Slice)
144  virtual void Slice(UInt_t /*xStart*/, UInt_t /*xEnd*/, UInt_t /*yStart*/, UInt_t /*yEnd*/,
145  UInt_t /*toWidth*/, UInt_t /*toHeight*/) {}
146 
147  // Tile the image. (See TASImage::Tile)
148  virtual void Tile(UInt_t /*width*/, UInt_t /*height*/) {}
149 
150  // Crop the image. (See TASImage::Crop)
151  virtual void Crop(Int_t /*x*/ = 0, Int_t /*y*/ = 0, UInt_t /*width*/ = 0, UInt_t /*height*/ = 0) {}
152 
153  // Enlarge image. (See TASImage::Pad)
154  virtual void Pad(const char * /*color*/ = "#FFFFFFFF", UInt_t /*left*/ = 0,
155  UInt_t /*right*/ = 0, UInt_t /*top*/ = 0, UInt_t /*bottom*/ = 0) {}
156 
157  // Gaussian blurr. (See TASImage::Blur)
158  virtual void Blur(Double_t /*horizontal*/ = 3, Double_t /*vertical*/ = 3) { }
159 
160  // Reduces colordepth of an image. (See TASImage::Vectorize)
161  virtual Double_t *Vectorize(UInt_t /*max_colors*/ = 256, UInt_t /*dither*/ = 4, Int_t /*opaque_threshold*/ = 0) { return 0; }
162 
163  // (See TASImage::HSV)
164  virtual void HSV(UInt_t /*hue*/ = 0, UInt_t /*radius*/ = 360, Int_t /*H*/ = 0, Int_t /*S*/ = 0, Int_t /*V*/ = 0,
165  Int_t /*x*/ = 0, Int_t /*y*/ = 0, UInt_t /*width*/ = 0, UInt_t /*height*/ = 0) {}
166 
167  // Render multipoint gradient inside a rectangle. (See TASImage::Gradient)
168  virtual void Gradient(UInt_t /*angle*/ = 0, const char * /*colors*/ = "#FFFFFF #000000", const char * /*offsets*/ = 0,
169  Int_t /*x*/ = 0, Int_t /*y*/ = 0, UInt_t /*width*/ = 0, UInt_t /*height*/ = 0) {}
170 
171  // Merge two images. (See TASImage::Merge)
172  virtual void Merge(const TImage * /*im*/, const char * /*op*/ = "alphablend", Int_t /*x*/ = 0, Int_t /*y*/ = 0) {}
173 
174  // Append image. (See TASImage::Append)
175  virtual void Append(const TImage * /*im*/, const char * /*option*/ = "+", const char * /*color*/ = "#00000000") {}
176 
177  // Bevel effect. (See TASImage::Bevel)
178  virtual void Bevel(Int_t /*x*/ = 0, Int_t /*y*/ = 0, UInt_t /*width*/ = 0, UInt_t /*height*/ = 0,
179  const char * /*hi*/ = "#ffdddddd", const char * /*lo*/ = "#ff555555",
180  UShort_t /*thick*/ = 1, Bool_t /*pressed*/ = kFALSE) {}
181 
182  virtual void BeginPaint(Bool_t /*fast*/ = kTRUE) {}
183  virtual void EndPaint() {}
184  virtual void DrawLine(UInt_t /*x1*/, UInt_t /*y1*/, UInt_t /*x2*/, UInt_t /*y2*/,
185  const char * /*col*/ = "#000000", UInt_t /*thick*/ = 1) {}
186  virtual void DrawDashLine(UInt_t /*x1*/, UInt_t /*y1*/, UInt_t /*x2*/, UInt_t /*y2*/, UInt_t /*nDash*/,
187  const char * /*pDash*/, const char * /*col*/ = "#000000", UInt_t /*thick*/ = 1) {}
188  virtual void DrawBox(Int_t /*x1*/, Int_t /*y1*/, Int_t /*x2*/, Int_t /*y2*/,
189  const char * /*col*/ = "#000000", UInt_t /*thick*/ = 1, Int_t /*mode*/ = 0) {}
190  virtual void DrawRectangle(UInt_t /*x*/, UInt_t /*y*/, UInt_t /*w*/, UInt_t /*h*/,
191  const char * /*col*/ = "#000000", UInt_t /*thick*/ = 1) {}
192  virtual void FillRectangle(const char * /*col*/ = 0, Int_t /*x*/ = 0, Int_t /*y*/ = 0,
193  UInt_t /*width*/ = 0, UInt_t /*height*/ = 0) {}
194  virtual void DrawPolyLine(UInt_t /*nn*/, TPoint * /*xy*/, const char * /*col*/ = "#000000",
195  UInt_t /*thick*/ = 1, TImage::ECoordMode /*mode*/ = kCoordModeOrigin) {}
196  virtual void PutPixel(Int_t /*x*/, Int_t /*y*/, const char * /*col*/ = "#000000") {}
197  virtual void PolyPoint(UInt_t /*npt*/, TPoint * /*ppt*/, const char * /*col*/ = "#000000",
198  TImage::ECoordMode /*mode*/ = kCoordModeOrigin) {}
199  virtual void DrawSegments(UInt_t /*nseg*/, Segment_t * /*seg*/, const char * /*col*/ = "#000000", UInt_t /*thick*/ = 1) {}
200  virtual void DrawText(Int_t /*x*/ = 0, Int_t /*y*/ = 0, const char * /*text*/ = "", Int_t /*size*/ = 12,
201  const char * /*color*/ = 0, const char * /*font*/ = "fixed",
202  EText3DType /*type*/ = TImage::kPlain, const char * /*fore_file*/ = 0, Float_t /*angle*/ = 0) { }
203  virtual void DrawText(TText * /*text*/, Int_t /*x*/ = 0, Int_t /*y*/ = 0) { }
204  virtual void FillPolygon(UInt_t /*npt*/, TPoint * /*ppt*/, const char * /*col*/ = "#000000",
205  const char * /*stipple*/ = 0, UInt_t /*w*/ = 16, UInt_t /*h*/ = 16) {}
206  virtual void FillPolygon(UInt_t /*npt*/, TPoint * /*ppt*/, TImage * /*tile*/) {}
207  virtual void CropPolygon(UInt_t /*npt*/, TPoint * /*ppt*/) {}
208  virtual void DrawFillArea(UInt_t /*npt*/, TPoint * /*ppt*/, const char * /*col*/ = "#000000",
209  const char * /*stipple*/ = 0, UInt_t /*w*/ = 16, UInt_t /*h*/ = 16) {}
210  virtual void DrawFillArea(UInt_t /*npt*/, TPoint * /*ppt*/, TImage * /*tile*/) {}
211  virtual void FillSpans(UInt_t /*npt*/, TPoint * /*ppt*/, UInt_t * /*widths*/, const char * /*col*/ = "#000000",
212  const char * /*stipple*/ = 0, UInt_t /*w*/ = 16, UInt_t /*h*/ = 16) {}
213  virtual void FillSpans(UInt_t /*npt*/, TPoint * /*ppt*/, UInt_t * /*widths*/, TImage * /*tile*/) {}
214  virtual void CropSpans(UInt_t /*npt*/, TPoint * /*ppt*/, UInt_t * /*widths*/) {}
215  virtual void CopyArea(TImage * /*dst*/, Int_t /*xsrc*/, Int_t /*ysrc*/, UInt_t /*w*/, UInt_t /*h*/,
216  Int_t /*xdst*/ = 0, Int_t /*ydst*/ = 0, Int_t /*gfunc*/ = 3, EColorChan /*chan*/ = kAllChan) {}
217  virtual void DrawCellArray(Int_t /*x1*/, Int_t /*y1*/, Int_t /*x2*/, Int_t /*y2*/, Int_t /*nx*/, Int_t /*ny*/, UInt_t * /*ic*/) {}
218  virtual void FloodFill(Int_t /*x*/, Int_t /*y*/, const char * /*col*/, const char * /*min_col*/, const char * /*max_col*/ = 0) {}
219  virtual void DrawCubeBezier(Int_t /*x1*/, Int_t /*y1*/, Int_t /*x2*/, Int_t /*y2*/, Int_t /*x3*/, Int_t /*y3*/, const char * /*col*/ = "#000000", UInt_t /*thick*/ = 1) {}
220  virtual void DrawStraightEllips(Int_t /*x*/, Int_t /*y*/, Int_t /*rx*/, Int_t /*ry*/, const char * /*col*/ = "#000000", Int_t /*thick*/ = 1) {}
221  virtual void DrawCircle(Int_t /*x*/, Int_t /*y*/, Int_t /*r*/, const char * /*col*/ = "#000000", Int_t /*thick*/ = 1) {}
222  virtual void DrawEllips(Int_t /*x*/, Int_t /*y*/, Int_t /*rx*/, Int_t /*ry*/, Int_t /*angle*/, const char * /*col*/ = "#000000", Int_t /*thick*/ = 1) {}
223  virtual void DrawEllips2(Int_t /*x*/, Int_t /*y*/, Int_t /*rx*/, Int_t /*ry*/, Int_t /*angle*/, const char * /*col*/ = "#000000", Int_t /*thick*/ = 1) {}
224 
225  virtual void SetEditable(Bool_t /*on*/ = kTRUE) {}
226  virtual Bool_t IsEditable() const { return kFALSE; }
227 
228  virtual UInt_t GetWidth() const { return 0; }
229  virtual UInt_t GetHeight() const { return 0; }
230  virtual Bool_t IsValid() const { return kTRUE; }
231  virtual TImage *GetScaledImage() const { return 0; }
232 
233  virtual TArrayL *GetPixels(Int_t /*x*/= 0, Int_t /*y*/= 0, UInt_t /*w*/ = 0, UInt_t /*h*/ = 0) { return 0; }
234  virtual TArrayD *GetArray(UInt_t /*w*/ = 0, UInt_t /*h*/ = 0, TImagePalette * = gWebImagePalette) { return 0; }
235  virtual Pixmap_t GetPixmap() { return 0; }
236  virtual Pixmap_t GetMask() { return 0; }
237  virtual UInt_t *GetArgbArray() { return 0; }
238  virtual UInt_t *GetRgbaArray() { return 0; }
239  virtual Double_t *GetVecArray() { return 0; }
240  virtual UInt_t *GetScanline(UInt_t /*y*/) { return 0; }
241  virtual void GetImageBuffer(char ** /*buffer*/, int* /*size*/, EImageFileTypes /*type*/ = TImage::kPng) {}
242  virtual Bool_t SetImageBuffer(char ** /*buffer*/, EImageFileTypes /*type*/ = TImage::kPng) { return kFALSE; }
243  virtual void PaintImage(Drawable_t /*wid*/, Int_t /*x*/, Int_t /*y*/, Int_t /*xsrc*/ = 0, Int_t /*ysrc*/ = 0, UInt_t /*wsrc*/ = 0, UInt_t /*hsrc*/ = 0, Option_t * /*opt*/ = "") { }
244  virtual void FromWindow(Drawable_t /*wid*/, Int_t /*x*/ = 0, Int_t /*y*/ = 0, UInt_t /*w*/ = 0, UInt_t /*h*/ = 0) {}
245  virtual void FromGLBuffer(UChar_t* /*buf*/, UInt_t /*w*/, UInt_t /*h*/) {}
246  static EImageFileTypes GetImageFileTypeFromFilename(const char* opt);
247 
248  static TImage *Create();
249  static TImage *Open(const char *file, EImageFileTypes type = kUnknown);
250  static TImage *Open(char **data);
251  static TImage *Open(const char *name, const Double_t *imageData, UInt_t width, UInt_t height, TImagePalette *palette);
252  static TImage *Open(const char *name, const TArrayD &imageData, UInt_t width, TImagePalette *palette = 0);
253  static TImage *Open(const char *name, const TVectorD &imageData, UInt_t width, TImagePalette *palette = 0);
254 
255  TImage &operator+=(const TImage &i) { Append(&i, "+"); return *this; }
256  TImage &operator/=(const TImage &i) { Append(&i, "/"); return *this; }
257 
258  virtual void ls(Option_t *option="") const;
259 
260  ClassDef(TImage,1) // Abstract image class
261 };
262 
263 
264 #endif