00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef ROOT_TASImage
00013 #define ROOT_TASImage
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef ROOT_TImage
00025 #include "TImage.h"
00026 #endif
00027
00028 struct ASImage;
00029 struct ASVisual;
00030 class TBrowser;
00031 class THashTable;
00032
00033 class TASImage : public TImage {
00034
00035 private:
00036 enum { kNoZoom = 0, kZoom = 1, kZoomOps = -1 };
00037 enum { kReadWritePNG, kReadWriteVector };
00038
00039 void DrawVLine(UInt_t x, UInt_t y1, UInt_t y2, UInt_t col, UInt_t thick);
00040 void DrawHLine(UInt_t y, UInt_t x1, UInt_t x2, UInt_t col, UInt_t thick);
00041 void DrawLineInternal(UInt_t x1, UInt_t y1, UInt_t x2, UInt_t y2, UInt_t col, UInt_t thick);
00042 void DrawWideLine(UInt_t x1, UInt_t y1, UInt_t x2, UInt_t y2, UInt_t col, UInt_t thick);
00043 void DrawDashHLine(UInt_t y, UInt_t x1, UInt_t x2, UInt_t nDash, const char *pDash, UInt_t col, UInt_t thick);
00044 void DrawDashVLine(UInt_t x, UInt_t y1, UInt_t y2, UInt_t nDash, const char *pDash, UInt_t col, UInt_t thick);
00045 void DrawDashZLine(UInt_t x1, UInt_t y1, UInt_t x2, UInt_t y2, UInt_t nDash, const char *pDash, UInt_t col);
00046 void DrawDashZTLine(UInt_t x1, UInt_t y1, UInt_t x2, UInt_t y2, UInt_t nDash, const char *pDash, UInt_t col, UInt_t thick);
00047 Bool_t GetPolygonSpans(UInt_t npt, TPoint *ppt, UInt_t *nspans, TPoint **firstPoint, UInt_t **firstWidth);
00048 void GetFillAreaSpans(UInt_t npt, TPoint *ppt, UInt_t *nspans, TPoint **firstPoint, UInt_t **firstWidth);
00049 void FillRectangleInternal(UInt_t col, Int_t x, Int_t y, UInt_t width, UInt_t height);
00050 void DrawTextTTF(Int_t x, Int_t y, const char *text, Int_t size, UInt_t color, const char *font_name, Float_t angle);
00051 void DrawGlyph(void *bitmap, UInt_t color, Int_t x, Int_t y);
00052 void SetDefaults();
00053 void CreateThumbnail();
00054 void DestroyImage();
00055 const char *TypeFromMagicNumber(const char *file);
00056
00057 protected:
00058 ASImage *fImage;
00059 TASImage *fScaledImage;
00060 Double_t fMaxValue;
00061 Double_t fMinValue;
00062 UInt_t fZoomOffX;
00063 UInt_t fZoomOffY;
00064 UInt_t fZoomWidth;
00065 UInt_t fZoomHeight;
00066 Int_t fZoomUpdate;
00067 Bool_t fEditable;
00068 Int_t fPaintMode;
00069 ASImage *fGrayImage;
00070 Bool_t fIsGray;
00071 static THashTable *fgPlugList;
00072
00073 static ASVisual *fgVisual;
00074 static Bool_t fgInit;
00075
00076 EImageFileTypes GetFileType(const char *ext);
00077 void MapFileTypes(EImageFileTypes &type, UInt_t &astype, Bool_t toas = kTRUE);
00078 void MapQuality(EImageQuality &quality, UInt_t &asquality, Bool_t toas = kTRUE);
00079
00080 static Bool_t InitVisual();
00081
00082 public:
00083 TASImage();
00084 TASImage(UInt_t w, UInt_t h);
00085 TASImage(const char *file, EImageFileTypes type = kUnknown);
00086 TASImage(const char *name, const Double_t *imageData, UInt_t width, UInt_t height, TImagePalette *palette = 0);
00087 TASImage(const char *name, const TArrayD &imageData, UInt_t width, TImagePalette *palette = 0);
00088 TASImage(const char *name, const TVectorD &imageData, UInt_t width, TImagePalette *palette = 0);
00089 TASImage(const TASImage &img);
00090 TASImage &operator=(const TASImage &img);
00091 virtual ~TASImage();
00092
00093 TObject *Clone(const char *newname) const;
00094
00095 void SetEditable(Bool_t on = kTRUE) { fEditable = on; }
00096 Bool_t IsEditable() const { return fEditable; }
00097 void Browse(TBrowser *);
00098 void SetTitle(const char *title="");
00099 const char *GetTitle() const;
00100 const char *GetIconName() const { return GetTitle(); }
00101
00102
00103 void FromPad(TVirtualPad *pad, Int_t x = 0, Int_t y = 0,
00104 UInt_t w = 0, UInt_t h = 0);
00105 void Draw(Option_t *option = "");
00106 void Paint(Option_t *option = "");
00107 Int_t DistancetoPrimitive(Int_t px, Int_t py);
00108 void ExecuteEvent(Int_t event, Int_t px, Int_t py);
00109 char *GetObjectInfo(Int_t px, Int_t py) const;
00110
00111
00112 void SetPalette(const TImagePalette *palette);
00113 void Zoom(UInt_t offX, UInt_t offY, UInt_t width, UInt_t height);
00114 void UnZoom();
00115 void Flip(Int_t flip = 180);
00116 void Mirror(Bool_t vert = kTRUE);
00117 void Scale(UInt_t width, UInt_t height);
00118 void Slice(UInt_t xStart, UInt_t xEnd, UInt_t yStart, UInt_t yEnd,
00119 UInt_t toWidth, UInt_t toHeight);
00120 void Tile(UInt_t width, UInt_t height);
00121 void Crop(Int_t x = 0, Int_t y = 0, UInt_t width = 0, UInt_t height = 0);
00122 void Pad(const char *color = "#00FFFFFF", UInt_t left = 0,
00123 UInt_t right = 0, UInt_t top = 0, UInt_t bottom = 0);
00124 void Blur(Double_t hr = 3, Double_t vr = 3);
00125 Double_t *Vectorize(UInt_t max_colors = 256, UInt_t dither = 4, Int_t opaque_threshold = 1);
00126 void Gray(Bool_t on = kTRUE);
00127 void StartPaletteEditor();
00128 void HSV(UInt_t hue = 0, UInt_t radius = 360, Int_t H = 0, Int_t S = 0, Int_t V = 0,
00129 Int_t x = 0, Int_t y = 0, UInt_t width = 0, UInt_t height = 0);
00130 void Merge(const TImage *im, const char *op = "alphablend", Int_t x = 0, Int_t y = 0);
00131 void Append(const TImage *im, const char * option = "+", const char *color = "#00000000");
00132 void Gradient(UInt_t angle = 0, const char *colors = "#FFFFFF #000000", const char *offsets = 0,
00133 Int_t x = 0, Int_t y = 0, UInt_t width = 0, UInt_t height = 0);
00134 void Bevel(Int_t x = 0, Int_t y = 0, UInt_t width = 0, UInt_t height = 0, const char *hi = "#ffdddddd",
00135 const char *lo = "#ff555555", UShort_t thick = 1, Bool_t pressed = kFALSE);
00136 void DrawText(Int_t x = 0, Int_t y = 0, const char *text = "", Int_t size = 12,
00137 const char *color = 0, const char *font = "fixed", EText3DType type = TImage::kPlain,
00138 const char *fore_file = 0, Float_t angle = 0);
00139 void DrawText(TText *text, Int_t x = 0, Int_t y = 0);
00140
00141
00142 void BeginPaint(Bool_t fast = kTRUE);
00143 void EndPaint();
00144 void DrawLine(UInt_t x1, UInt_t y1, UInt_t x2, UInt_t y2, const char *col = "#000000", UInt_t thick = 1);
00145 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);
00146 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);
00147 void DrawRectangle(UInt_t x, UInt_t y, UInt_t w, UInt_t h, const char *col = "#000000", UInt_t thick = 1);
00148 void FillRectangle(const char *col = 0, Int_t x = 0, Int_t y = 0, UInt_t width = 0, UInt_t height = 0);
00149 void DrawPolyLine(UInt_t nn, TPoint *xy, const char *col = "#000000", UInt_t thick = 1, TImage::ECoordMode mode = kCoordModeOrigin);
00150 void PutPixel(Int_t x, Int_t y, const char *col = "#000000");
00151 void PolyPoint(UInt_t npt, TPoint *ppt, const char *col = "#000000", TImage::ECoordMode mode = kCoordModeOrigin);
00152 void DrawSegments(UInt_t nseg, Segment_t *seg, const char *col = "#000000", UInt_t thick = 1);
00153 void FillPolygon(UInt_t npt, TPoint *ppt, const char *col = "#000000", const char *stipple = 0, UInt_t w = 16, UInt_t h = 16);
00154 void FillPolygon(UInt_t npt, TPoint *ppt, TImage *tile);
00155 void CropPolygon(UInt_t npt, TPoint *ppt);
00156 void DrawFillArea(UInt_t npt, TPoint *ppt, const char *col = "#000000", const char *stipple = 0, UInt_t w = 16, UInt_t h = 16);
00157 void DrawFillArea(UInt_t npt, TPoint *ppt, TImage *tile);
00158 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);
00159 void FillSpans(UInt_t npt, TPoint *ppt, UInt_t *widths, TImage *tile);
00160 void CropSpans(UInt_t npt, TPoint *ppt, UInt_t *widths);
00161 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);
00162 void DrawCellArray(Int_t x1, Int_t y1, Int_t x2, Int_t y2, Int_t nx, Int_t ny, UInt_t *ic);
00163 void FloodFill(Int_t x, Int_t y, const char *col, const char *min_col, const char *max_col = 0);
00164 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);
00165 void DrawStraightEllips(Int_t x, Int_t y, Int_t rx, Int_t ry, const char *col = "#000000", Int_t thick = 1);
00166 void DrawCircle(Int_t x, Int_t y, Int_t r, const char *col = "#000000", Int_t thick = 1);
00167 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);
00168 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);
00169
00170
00171 void ReadImage(const char *file, EImageFileTypes type = TImage::kUnknown);
00172 void WriteImage(const char *file, EImageFileTypes type = TImage::kUnknown);
00173 void SetImage(const Double_t *imageData, UInt_t width, UInt_t height, TImagePalette *palette = 0);
00174 void SetImage(const TArrayD &imageData, UInt_t width, TImagePalette *palette = 0);
00175 void SetImage(const TVectorD &imageData, UInt_t width, TImagePalette *palette = 0);
00176 void SetImage(Pixmap_t pxm, Pixmap_t mask = 0);
00177 void FromWindow(Drawable_t wid, Int_t x = 0, Int_t y = 0, UInt_t w = 0, UInt_t h = 0);
00178 void FromGLBuffer(UChar_t* buf, UInt_t w, UInt_t h);
00179
00180
00181 UInt_t GetWidth() const;
00182 UInt_t GetHeight() const;
00183 UInt_t GetScaledWidth() const;
00184 UInt_t GetScaledHeight() const;
00185 Bool_t IsValid() const { return fImage ? kTRUE : kFALSE; }
00186 Bool_t IsGray() const { return fIsGray; }
00187 ASImage *GetImage() const { return fImage; }
00188 void SetImage(ASImage *image) { DestroyImage(); fImage = image; }
00189 TImage *GetScaledImage() const { return fScaledImage; }
00190 Pixmap_t GetPixmap();
00191 Pixmap_t GetMask();
00192 TArrayL *GetPixels(Int_t x = 0, Int_t y = 0, UInt_t w = 0, UInt_t h = 0);
00193 TArrayD *GetArray(UInt_t w = 0, UInt_t h = 0, TImagePalette *pal = gWebImagePalette);
00194 UInt_t *GetArgbArray();
00195 UInt_t *GetRgbaArray();
00196 Double_t *GetVecArray();
00197 UInt_t *GetScanline(UInt_t y);
00198 void GetImageBuffer(char **buffer, int *size, EImageFileTypes type = TImage::kPng);
00199 void GetZoomPosition(UInt_t &x, UInt_t &y, UInt_t &w, UInt_t &h) const;
00200 Bool_t SetImageBuffer(char **buffer, EImageFileTypes type = TImage::kPng);
00201 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 = "");
00202 void SetPaletteEnabled(Bool_t on = kTRUE);
00203 void SavePrimitive(ostream &out, Option_t *option = "");
00204
00205 static const ASVisual *GetVisual();
00206 static UInt_t AlphaBlend(UInt_t bot, UInt_t top);
00207 static void Image2Drawable(ASImage *im, 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 = "");
00208
00209
00210 Bool_t SetJpegDpi(const char *name, UInt_t dpi = 72);
00211
00212 ClassDef(TASImage,2)
00213 };
00214
00215 #endif