// @(#)root/graf:$Id$
// Author: Fons Rademakers, Reiner Rohlfs   15/10/2001

/*************************************************************************
 * Copyright (C) 2001-2001, Rene Brun, Fons Rademakers and Reiner Rohlfs *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TImage
#define ROOT_TImage


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TImage                                                               //
//                                                                      //
// Abstract interface to image processing library.                      //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TNamed
#include "TNamed.h"
#endif

#ifndef ROOT_TAttImage
#include "TAttImage.h"
#endif
#ifndef ROOT_GuiTypes
#include "GuiTypes.h"
#endif
#ifndef ROOT_TVectorDfwd
#include "TVectorDfwd.h"
#endif

class TVirtualPad;
class TArrayD;
class TArrayL;
class TH2D;
class TPoint;
class TText;

class TImage : public TNamed, public TAttImage {

friend TImage operator+(const TImage &i1, const TImage &s2);
friend TImage operator/(const TImage &i1, const TImage &s2);

public:
   // Defines image file types
   enum EImageFileTypes {
      kXpm = 0,
      kZCompressedXpm,
      kGZCompressedXpm,
      kPng,
      kJpeg,
      kXcf,
      kPpm,
      kPnm,
      kBmp,
      kIco,
      kCur,
      kGif,
      kTiff,
      kXbm,
      kFits,
      kTga,
      kXml,
      kUnknown,
      kAnimGif
   };

   enum EText3DType {
      kPlain = 0,  // regular 2D text
      kEmbossed,
      kSunken,
      kShadeAbove,
      kShadeBelow,
      kEmbossedThick,
      kSunkenThick,
      kOutlineAbove,
      kOutlineBelow,
      kOutlineFull,
      k3DTypes
   };

   enum ECharType {
      kUTF8 = 0,
      kChar = 1,
      kUnicode = 4
   };

   enum ETileType {
      kStretch = 0,
      kTile,
      kStretchY,
      kStretchX
   };

   enum ECoordMode {
      kCoordModeOrigin = 0,
      kCoordModePrevious
   };

   enum EColorChan {
      kRedChan   = BIT(0),
      kGreenChan = BIT(1),
      kBlueChan  = BIT(2),
      kAlphaChan = BIT(3),
      kAllChan   = kRedChan | kGreenChan | kBlueChan | kAlphaChan
   };

protected:
   TImage(const char *file) : TNamed(file, "") { }
   TImage() { }

public:
   TImage(const TImage &img) : TNamed(img), TAttImage(img) { }
   TImage &operator=(const TImage &img)
            { TNamed::operator=(img); TAttImage::operator=(img); return *this; }
   TImage(UInt_t /*w*/, UInt_t /*h*/) : TNamed(), TAttImage() { }

   virtual ~TImage() { }

   // Cloning
   virtual TObject *Clone(const char *) const { return 0; }

   // Input / output
   virtual void ReadImage(const char * /*file*/, EImageFileTypes /*type*/ = TImage::kUnknown) {}
   virtual void WriteImage(const char * /*file*/, EImageFileTypes /*type*/ = TImage::kUnknown)  {}
   virtual void SetImage(const Double_t * /*imageData*/, UInt_t /*width*/, UInt_t /*height*/, TImagePalette * /*palette*/ = 0) {}
   virtual void SetImage(const TArrayD & /*imageData*/, UInt_t /*width*/, TImagePalette * /*palette*/ = 0) {}
   virtual void SetImage(const TVectorD & /*imageData*/, UInt_t /*width*/, TImagePalette * /*palette*/ = 0) {}
   virtual void SetImage(Pixmap_t /*pxm*/, Pixmap_t /*mask*/ = 0) {}

   // Create an image from the given pad. (See TASImage::FromPad)
   virtual void FromPad(TVirtualPad * /*pad*/, Int_t /*x*/ = 0, Int_t /*y*/ = 0, UInt_t /*w*/ = 0, UInt_t /*h*/ = 0) {}

   // Restore the image original size. (See TASImage::UnZoom)
   virtual void UnZoom() {}

   // Zoom the image. (See TASImage::Zoom)
   virtual void Zoom(UInt_t /*offX*/, UInt_t /*offY*/, UInt_t /*width*/, UInt_t /*height*/) {}

   // Flip the image by a multiple of 90 degrees. (See TASImage::Flip)
   virtual void Flip(Int_t /*flip*/ = 180) {}

   // Converts image to Gray. (See TASImage::Gray)
   virtual void Gray(Bool_t /*on*/ = kTRUE) {}
   virtual Bool_t IsGray() const { return kFALSE; }

   // Mirror the image. (See TASImage::Mirror)
   virtual void Mirror(Bool_t /*vert*/ = kTRUE) {}

   // Scale the image. (See TASImage::Scale)
   virtual void Scale(UInt_t /*width*/, UInt_t /*height*/) {}

   // Slice the image. (See TASImage::Slice)
   virtual void Slice(UInt_t /*xStart*/, UInt_t /*xEnd*/, UInt_t /*yStart*/,  UInt_t /*yEnd*/,
                      UInt_t /*toWidth*/, UInt_t /*toHeight*/) {}

   // Tile the image. (See TASImage::Tile)
   virtual void Tile(UInt_t /*width*/, UInt_t /*height*/) {}

   // Crop the image. (See TASImage::Crop)
   virtual void Crop(Int_t /*x*/ = 0, Int_t /*y*/ = 0, UInt_t /*width*/ = 0, UInt_t /*height*/ = 0) {}

   // Enlarge image. (See TASImage::Pad)
   virtual void Pad(const char * /*color*/ = "#FFFFFFFF", UInt_t /*left*/ = 0,
                   UInt_t /*right*/ = 0, UInt_t /*top*/ = 0, UInt_t /*bottom*/ = 0) {}

   // Gaussian blurr. (See TASImage::Blur)
   virtual void Blur(Double_t /*horizontal*/ = 3, Double_t /*vertical*/ = 3) { }

   // Reduces colordepth of an image. (See TASImage::Vectorize)
   virtual Double_t *Vectorize(UInt_t /*max_colors*/ = 256, UInt_t /*dither*/ = 4, Int_t /*opaque_threshold*/ = 0) { return 0; }

   // (See TASImage::HSV)
   virtual void HSV(UInt_t /*hue*/ = 0, UInt_t /*radius*/ = 360, Int_t /*H*/ = 0, Int_t /*S*/ = 0, Int_t /*V*/ = 0,
                    Int_t /*x*/ = 0, Int_t /*y*/ = 0, UInt_t /*width*/ = 0, UInt_t /*height*/ = 0) {}

   // Render multipoint gradient inside a rectangle. (See TASImage::Gradient)
   virtual void Gradient(UInt_t /*angle*/ = 0, const char * /*colors*/ = "#FFFFFF #000000", const char * /*offsets*/ = 0,
                         Int_t /*x*/ = 0, Int_t /*y*/ = 0, UInt_t /*width*/ = 0, UInt_t /*height*/ = 0) {}

   // Merge two images. (See TASImage::Merge)
   virtual void Merge(const TImage * /*im*/, const char * /*op*/ = "alphablend", Int_t /*x*/ = 0, Int_t /*y*/ = 0) {}

   // Append image. (See TASImage::Append)
   virtual void Append(const TImage * /*im*/, const char * /*option*/ = "+", const char * /*color*/ = "#00000000") {}

   // Bevel effect. (See TASImage::Bevel)
   virtual void Bevel(Int_t /*x*/ = 0, Int_t /*y*/ = 0, UInt_t /*width*/ = 0, UInt_t /*height*/ = 0,
                      const char * /*hi*/ = "#ffdddddd", const char * /*lo*/ = "#ff555555",
                      UShort_t /*thick*/ = 1, Bool_t /*pressed*/ = kFALSE) {}

   virtual void BeginPaint(Bool_t /*fast*/ = kTRUE) {}
   virtual void EndPaint() {}
   virtual void DrawLine(UInt_t /*x1*/, UInt_t /*y1*/, UInt_t /*x2*/, UInt_t /*y2*/,
                         const char * /*col*/ = "#000000", UInt_t /*thick*/ = 1) {}
   virtual void DrawDashLine(UInt_t /*x1*/, UInt_t /*y1*/, UInt_t /*x2*/, UInt_t /*y2*/, UInt_t /*nDash*/,
                             const char * /*pDash*/, const char * /*col*/ = "#000000", UInt_t /*thick*/ = 1) {}
   virtual void DrawBox(Int_t /*x1*/, Int_t /*y1*/, Int_t /*x2*/, Int_t /*y2*/,
                         const char * /*col*/ = "#000000", UInt_t /*thick*/ = 1, Int_t /*mode*/ = 0) {}
   virtual void DrawRectangle(UInt_t /*x*/, UInt_t /*y*/, UInt_t /*w*/, UInt_t /*h*/,
                              const char * /*col*/ = "#000000", UInt_t /*thick*/ = 1) {}
   virtual void FillRectangle(const char * /*col*/ = 0, Int_t /*x*/ = 0, Int_t /*y*/ = 0,
                              UInt_t /*width*/ = 0, UInt_t /*height*/ = 0) {}
   virtual void DrawPolyLine(UInt_t /*nn*/, TPoint * /*xy*/, const char * /*col*/ = "#000000",
                             UInt_t /*thick*/ = 1, TImage::ECoordMode /*mode*/ = kCoordModeOrigin) {}
   virtual void PutPixel(Int_t /*x*/, Int_t /*y*/, const char * /*col*/ = "#000000") {}
   virtual void PolyPoint(UInt_t /*npt*/, TPoint * /*ppt*/, const char * /*col*/ = "#000000",
                          TImage::ECoordMode /*mode*/ = kCoordModeOrigin) {}
   virtual void DrawSegments(UInt_t /*nseg*/, Segment_t * /*seg*/, const char * /*col*/ = "#000000", UInt_t /*thick*/ = 1) {}
   virtual void DrawText(Int_t /*x*/ = 0, Int_t /*y*/ = 0, const char * /*text*/ = "", Int_t /*size*/ = 12,
                         const char * /*color*/ = 0, const char * /*font*/ = "fixed",
                         EText3DType /*type*/ = TImage::kPlain, const char * /*fore_file*/ = 0, Float_t /*angle*/ = 0) { }
   virtual void DrawText(TText * /*text*/, Int_t /*x*/ = 0, Int_t /*y*/ = 0) { }
   virtual void FillPolygon(UInt_t /*npt*/, TPoint * /*ppt*/, const char * /*col*/ = "#000000",
                           const char * /*stipple*/ = 0, UInt_t /*w*/ = 16, UInt_t /*h*/ = 16) {}
   virtual void FillPolygon(UInt_t /*npt*/, TPoint * /*ppt*/, TImage * /*tile*/) {}
   virtual void CropPolygon(UInt_t /*npt*/, TPoint * /*ppt*/) {}
   virtual void DrawFillArea(UInt_t /*npt*/, TPoint * /*ppt*/, const char * /*col*/ = "#000000",
                           const char * /*stipple*/ = 0, UInt_t /*w*/ = 16, UInt_t /*h*/ = 16) {}
   virtual void DrawFillArea(UInt_t /*npt*/, TPoint * /*ppt*/, TImage * /*tile*/) {}
   virtual void FillSpans(UInt_t /*npt*/, TPoint * /*ppt*/, UInt_t * /*widths*/,  const char * /*col*/ = "#000000",
                         const char * /*stipple*/ = 0, UInt_t /*w*/ = 16, UInt_t /*h*/ = 16) {}
   virtual void FillSpans(UInt_t /*npt*/, TPoint * /*ppt*/, UInt_t * /*widths*/, TImage * /*tile*/) {}
   virtual void CropSpans(UInt_t /*npt*/, TPoint * /*ppt*/, UInt_t * /*widths*/) {}
   virtual void CopyArea(TImage * /*dst*/, Int_t /*xsrc*/, Int_t /*ysrc*/, UInt_t /*w*/, UInt_t /*h*/,
                         Int_t /*xdst*/ = 0, Int_t /*ydst*/ = 0, Int_t /*gfunc*/ = 3, EColorChan /*chan*/ = kAllChan) {}
   virtual void DrawCellArray(Int_t /*x1*/, Int_t /*y1*/, Int_t /*x2*/, Int_t /*y2*/, Int_t /*nx*/, Int_t /*ny*/, UInt_t * /*ic*/) {}
   virtual void FloodFill(Int_t /*x*/, Int_t /*y*/, const char * /*col*/, const char * /*min_col*/, const char * /*max_col*/ = 0) {}
   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) {}
   virtual void DrawStraightEllips(Int_t /*x*/, Int_t /*y*/, Int_t /*rx*/, Int_t /*ry*/, const char * /*col*/ = "#000000", Int_t /*thick*/ = 1) {}
   virtual void DrawCircle(Int_t /*x*/, Int_t /*y*/, Int_t /*r*/, const char * /*col*/ = "#000000", Int_t /*thick*/ = 1) {}
   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) {}
   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) {}

   virtual void SetEditable(Bool_t /*on*/ = kTRUE) {}
   virtual Bool_t IsEditable() const { return kFALSE; }

   virtual UInt_t GetWidth() const { return 0; }
   virtual UInt_t GetHeight() const { return 0; }
   virtual Bool_t IsValid() const { return kTRUE; }
   virtual TImage *GetScaledImage() const { return 0; }

   virtual TArrayL  *GetPixels(Int_t /*x*/= 0, Int_t /*y*/= 0, UInt_t /*w*/ = 0, UInt_t /*h*/ = 0) { return 0; }
   virtual TArrayD  *GetArray(UInt_t /*w*/ = 0, UInt_t /*h*/ = 0, TImagePalette * = gWebImagePalette) { return 0; }
   virtual Pixmap_t  GetPixmap() { return 0; }
   virtual Pixmap_t  GetMask() { return 0; }
   virtual UInt_t   *GetArgbArray() { return 0; }
   virtual UInt_t   *GetRgbaArray() { return 0; }
   virtual Double_t *GetVecArray() { return 0; }
   virtual UInt_t   *GetScanline(UInt_t /*y*/) { return 0; }
   virtual void      GetImageBuffer(char ** /*buffer*/, int* /*size*/, EImageFileTypes /*type*/ = TImage::kPng) {}
   virtual Bool_t    SetImageBuffer(char ** /*buffer*/, EImageFileTypes /*type*/ = TImage::kPng) { return kFALSE; }
   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*/ = "") { }
   virtual void      FromWindow(Drawable_t /*wid*/, Int_t /*x*/ = 0, Int_t /*y*/ = 0, UInt_t /*w*/ = 0, UInt_t /*h*/ = 0) {}
   virtual void      FromGLBuffer(UChar_t* /*buf*/, UInt_t /*w*/, UInt_t /*h*/) {}
   static EImageFileTypes GetImageFileTypeFromFilename(const char* opt);

   static TImage *Create();
   static TImage *Open(const char *file, EImageFileTypes type = kUnknown);
   static TImage *Open(char **data);
   static TImage *Open(const char *name, const Double_t *imageData, UInt_t width, UInt_t height, TImagePalette *palette);
   static TImage *Open(const char *name, const TArrayD &imageData, UInt_t width, TImagePalette *palette = 0);
   static TImage *Open(const char *name, const TVectorD &imageData, UInt_t width, TImagePalette *palette = 0);

   TImage    &operator+=(const TImage &i) { Append(&i, "+"); return *this; }
   TImage    &operator/=(const TImage &i) { Append(&i, "/"); return *this; }

   ClassDef(TImage,1)  // Abstract image class
};


#endif
 TImage.h:1
 TImage.h:2
 TImage.h:3
 TImage.h:4
 TImage.h:5
 TImage.h:6
 TImage.h:7
 TImage.h:8
 TImage.h:9
 TImage.h:10
 TImage.h:11
 TImage.h:12
 TImage.h:13
 TImage.h:14
 TImage.h:15
 TImage.h:16
 TImage.h:17
 TImage.h:18
 TImage.h:19
 TImage.h:20
 TImage.h:21
 TImage.h:22
 TImage.h:23
 TImage.h:24
 TImage.h:25
 TImage.h:26
 TImage.h:27
 TImage.h:28
 TImage.h:29
 TImage.h:30
 TImage.h:31
 TImage.h:32
 TImage.h:33
 TImage.h:34
 TImage.h:35
 TImage.h:36
 TImage.h:37
 TImage.h:38
 TImage.h:39
 TImage.h:40
 TImage.h:41
 TImage.h:42
 TImage.h:43
 TImage.h:44
 TImage.h:45
 TImage.h:46
 TImage.h:47
 TImage.h:48
 TImage.h:49
 TImage.h:50
 TImage.h:51
 TImage.h:52
 TImage.h:53
 TImage.h:54
 TImage.h:55
 TImage.h:56
 TImage.h:57
 TImage.h:58
 TImage.h:59
 TImage.h:60
 TImage.h:61
 TImage.h:62
 TImage.h:63
 TImage.h:64
 TImage.h:65
 TImage.h:66
 TImage.h:67
 TImage.h:68
 TImage.h:69
 TImage.h:70
 TImage.h:71
 TImage.h:72
 TImage.h:73
 TImage.h:74
 TImage.h:75
 TImage.h:76
 TImage.h:77
 TImage.h:78
 TImage.h:79
 TImage.h:80
 TImage.h:81
 TImage.h:82
 TImage.h:83
 TImage.h:84
 TImage.h:85
 TImage.h:86
 TImage.h:87
 TImage.h:88
 TImage.h:89
 TImage.h:90
 TImage.h:91
 TImage.h:92
 TImage.h:93
 TImage.h:94
 TImage.h:95
 TImage.h:96
 TImage.h:97
 TImage.h:98
 TImage.h:99
 TImage.h:100
 TImage.h:101
 TImage.h:102
 TImage.h:103
 TImage.h:104
 TImage.h:105
 TImage.h:106
 TImage.h:107
 TImage.h:108
 TImage.h:109
 TImage.h:110
 TImage.h:111
 TImage.h:112
 TImage.h:113
 TImage.h:114
 TImage.h:115
 TImage.h:116
 TImage.h:117
 TImage.h:118
 TImage.h:119
 TImage.h:120
 TImage.h:121
 TImage.h:122
 TImage.h:123
 TImage.h:124
 TImage.h:125
 TImage.h:126
 TImage.h:127
 TImage.h:128
 TImage.h:129
 TImage.h:130
 TImage.h:131
 TImage.h:132
 TImage.h:133
 TImage.h:134
 TImage.h:135
 TImage.h:136
 TImage.h:137
 TImage.h:138
 TImage.h:139
 TImage.h:140
 TImage.h:141
 TImage.h:142
 TImage.h:143
 TImage.h:144
 TImage.h:145
 TImage.h:146
 TImage.h:147
 TImage.h:148
 TImage.h:149
 TImage.h:150
 TImage.h:151
 TImage.h:152
 TImage.h:153
 TImage.h:154
 TImage.h:155
 TImage.h:156
 TImage.h:157
 TImage.h:158
 TImage.h:159
 TImage.h:160
 TImage.h:161
 TImage.h:162
 TImage.h:163
 TImage.h:164
 TImage.h:165
 TImage.h:166
 TImage.h:167
 TImage.h:168
 TImage.h:169
 TImage.h:170
 TImage.h:171
 TImage.h:172
 TImage.h:173
 TImage.h:174
 TImage.h:175
 TImage.h:176
 TImage.h:177
 TImage.h:178
 TImage.h:179
 TImage.h:180
 TImage.h:181
 TImage.h:182
 TImage.h:183
 TImage.h:184
 TImage.h:185
 TImage.h:186
 TImage.h:187
 TImage.h:188
 TImage.h:189
 TImage.h:190
 TImage.h:191
 TImage.h:192
 TImage.h:193
 TImage.h:194
 TImage.h:195
 TImage.h:196
 TImage.h:197
 TImage.h:198
 TImage.h:199
 TImage.h:200
 TImage.h:201
 TImage.h:202
 TImage.h:203
 TImage.h:204
 TImage.h:205
 TImage.h:206
 TImage.h:207
 TImage.h:208
 TImage.h:209
 TImage.h:210
 TImage.h:211
 TImage.h:212
 TImage.h:213
 TImage.h:214
 TImage.h:215
 TImage.h:216
 TImage.h:217
 TImage.h:218
 TImage.h:219
 TImage.h:220
 TImage.h:221
 TImage.h:222
 TImage.h:223
 TImage.h:224
 TImage.h:225
 TImage.h:226
 TImage.h:227
 TImage.h:228
 TImage.h:229
 TImage.h:230
 TImage.h:231
 TImage.h:232
 TImage.h:233
 TImage.h:234
 TImage.h:235
 TImage.h:236
 TImage.h:237
 TImage.h:238
 TImage.h:239
 TImage.h:240
 TImage.h:241
 TImage.h:242
 TImage.h:243
 TImage.h:244
 TImage.h:245
 TImage.h:246
 TImage.h:247
 TImage.h:248
 TImage.h:249
 TImage.h:250
 TImage.h:251
 TImage.h:252
 TImage.h:253
 TImage.h:254
 TImage.h:255
 TImage.h:256
 TImage.h:257
 TImage.h:258
 TImage.h:259
 TImage.h:260
 TImage.h:261
 TImage.h:262
 TImage.h:263
 TImage.h:264
 TImage.h:265
 TImage.h:266
 TImage.h:267
 TImage.h:268
 TImage.h:269
 TImage.h:270
 TImage.h:271
 TImage.h:272
 TImage.h:273
 TImage.h:274
 TImage.h:275
 TImage.h:276
 TImage.h:277
 TImage.h:278