File indexing completed on 2026-09-21 09:26:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TASImage
0013 #define ROOT_TASImage
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 #include "TImage.h"
0025
0026 struct ASImage;
0027 struct ASVisual;
0028 class TBrowser;
0029 class THashTable;
0030
0031 class TASImage : public TImage {
0032
0033 private:
0034 enum { kNoZoom = 0, kZoom = 1, kZoomOps = -1 };
0035 enum { kReadWritePNG, kReadWriteVector };
0036
0037 void DrawVLine(UInt_t x, UInt_t y1, UInt_t y2, UInt_t col, UInt_t thick);
0038 void DrawHLine(UInt_t y, UInt_t x1, UInt_t x2, UInt_t col, UInt_t thick);
0039 void DrawLineInternal(UInt_t x1, UInt_t y1, UInt_t x2, UInt_t y2, UInt_t col, UInt_t thick);
0040 void DrawWideLine(UInt_t x1, UInt_t y1, UInt_t x2, UInt_t y2, UInt_t col, UInt_t thick);
0041 void DrawDashHLine(UInt_t y, UInt_t x1, UInt_t x2, UInt_t nDash, const char *pDash, UInt_t col, UInt_t thick);
0042 void DrawDashVLine(UInt_t x, UInt_t y1, UInt_t y2, UInt_t nDash, const char *pDash, UInt_t col, UInt_t thick);
0043 void DrawDashZLine(UInt_t x1, UInt_t y1, UInt_t x2, UInt_t y2, UInt_t nDash, const char *pDash, UInt_t col);
0044 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);
0045 Bool_t GetPolygonSpans(UInt_t npt, TPoint *ppt, UInt_t *nspans, TPoint **firstPoint, UInt_t **firstWidth);
0046 void GetFillAreaSpans(UInt_t npt, TPoint *ppt, UInt_t *nspans, TPoint **firstPoint, UInt_t **firstWidth);
0047 inline Int_t Idx(Int_t idx);
0048 void FillRectangleInternal(UInt_t col, Int_t x, Int_t y, UInt_t width, UInt_t height);
0049 void DrawTextTTF(Int_t x, Int_t y, const char *text, Int_t size, UInt_t color, const char *font_name, Float_t angle);
0050 void DrawGlyph(void *bitmap, UInt_t color, Int_t x, Int_t y);
0051 void SetDefaults();
0052 void CreateThumbnail();
0053 void DestroyImage();
0054 const char *TypeFromMagicNumber(const char *file);
0055
0056 protected:
0057 ASImage *fImage;
0058 TASImage *fScaledImage;
0059 Double_t fMaxValue;
0060 Double_t fMinValue;
0061 UInt_t fZoomOffX;
0062 UInt_t fZoomOffY;
0063 UInt_t fZoomWidth;
0064 UInt_t fZoomHeight;
0065 Int_t fZoomUpdate;
0066 Bool_t fEditable;
0067 Int_t fPaintMode;
0068 ASImage *fGrayImage;
0069 Bool_t fIsGray;
0070 static THashTable *fgPlugList;
0071
0072 static ASVisual *fgVisual;
0073 static Bool_t fgInit;
0074 static Bool_t fgBatch;
0075
0076 EImageFileTypes GetFileType(const char *ext);
0077 void MapFileTypes(EImageFileTypes &type, UInt_t &astype, Bool_t toas = kTRUE);
0078 void MapQuality(EImageQuality &quality, UInt_t &asquality, Bool_t toas = kTRUE);
0079
0080 static Bool_t InitVisual();
0081 Bool_t InitImage(const char *caller);
0082
0083 public:
0084 TASImage();
0085 TASImage(UInt_t w, UInt_t h);
0086 TASImage(const char *file, EImageFileTypes type = kUnknown);
0087 TASImage(const char *name, const Double_t *imageData, UInt_t width, UInt_t height, TImagePalette *palette = nullptr);
0088 TASImage(const char *name, const TArrayD &imageData, UInt_t width, TImagePalette *palette = nullptr);
0089 TASImage(const char *name, const TVectorD &imageData, UInt_t width, TImagePalette *palette = nullptr);
0090 TASImage(const TASImage &img);
0091 TASImage &operator=(const TASImage &img);
0092 ~TASImage() override;
0093
0094 TObject *Clone(const char *newname = "") const override;
0095
0096 void SetEditable(Bool_t on = kTRUE) override { fEditable = on; }
0097 Bool_t IsEditable() const override { return fEditable; }
0098 void Browse(TBrowser *) override;
0099 void SetTitle(const char *title = "") override;
0100 const char *GetTitle() const override;
0101 const char *GetIconName() const override { return GetTitle(); }
0102
0103
0104 void FromPad(TVirtualPad *pad, Int_t x = 0, Int_t y = 0,
0105 UInt_t w = 0, UInt_t h = 0) override;
0106 void Draw(Option_t *option = "") override;
0107 void Paint(Option_t *option = "") override;
0108 Int_t DistancetoPrimitive(Int_t px, Int_t py) override;
0109 void ExecuteEvent(Int_t event, Int_t px, Int_t py) override;
0110 char *GetObjectInfo(Int_t px, Int_t py) const override;
0111
0112
0113 void SetPalette(const TImagePalette *palette) override;
0114 void Zoom(UInt_t offX, UInt_t offY, UInt_t width, UInt_t height) override;
0115 void UnZoom() override;
0116 void Flip(Int_t flip = 180) override;
0117 void Mirror(Bool_t vert = kTRUE) override;
0118 void Scale(UInt_t width, UInt_t height) override;
0119 void Slice(UInt_t xStart, UInt_t xEnd, UInt_t yStart, UInt_t yEnd,
0120 UInt_t toWidth, UInt_t toHeight) override;
0121 void Tile(UInt_t width, UInt_t height) override;
0122 void Crop(Int_t x = 0, Int_t y = 0, UInt_t width = 0, UInt_t height = 0) override;
0123 void Pad(const char *color = "#00FFFFFF", UInt_t left = 0,
0124 UInt_t right = 0, UInt_t top = 0, UInt_t bottom = 0) override;
0125 void Blur(Double_t hr = 3, Double_t vr = 3) override;
0126 Double_t *Vectorize(UInt_t max_colors = 256, UInt_t dither = 4, Int_t opaque_threshold = 1) override;
0127 void Gray(Bool_t on = kTRUE) override;
0128 void StartPaletteEditor() override;
0129 void HSV(UInt_t hue = 0, UInt_t radius = 360, Int_t H = 0, Int_t S = 0, Int_t V = 0,
0130 Int_t x = 0, Int_t y = 0, UInt_t width = 0, UInt_t height = 0) override;
0131 void Merge(const TImage *im, const char *op = "alphablend", Int_t x = 0, Int_t y = 0) override;
0132 void Append(const TImage *im, const char * option = "+", const char *color = "#00000000") override;
0133 void Gradient(UInt_t angle = 0, const char *colors = "#FFFFFF #000000", const char *offsets = nullptr,
0134 Int_t x = 0, Int_t y = 0, UInt_t width = 0, UInt_t height = 0) override;
0135 void Bevel(Int_t x = 0, Int_t y = 0, UInt_t width = 0, UInt_t height = 0, const char *hi = "#ffdddddd",
0136 const char *lo = "#ff555555", UShort_t thick = 1, Bool_t pressed = kFALSE) override;
0137 void DrawText(Int_t x = 0, Int_t y = 0, const char *text = "", Int_t size = 12,
0138 const char *color = nullptr, const char *font = "fixed", EText3DType type = TImage::kPlain,
0139 const char *fore_file = nullptr, Float_t angle = 0) override;
0140 void DrawText(TText *text, Int_t x = 0, Int_t y = 0) override;
0141
0142
0143 void BeginPaint(Bool_t fast = kTRUE) override;
0144 void EndPaint() override;
0145 void DrawLine(UInt_t x1, UInt_t y1, UInt_t x2, UInt_t y2, const char *col = "#000000", UInt_t thick = 1) override;
0146 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) override;
0147 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) override;
0148 void DrawRectangle(UInt_t x, UInt_t y, UInt_t w, UInt_t h, const char *col = "#000000", UInt_t thick = 1) override;
0149 void FillRectangle(const char *col = nullptr, Int_t x = 0, Int_t y = 0, UInt_t width = 0, UInt_t height = 0) override;
0150 void DrawPolyLine(UInt_t nn, TPoint *xy, const char *col = "#000000", UInt_t thick = 1, TImage::ECoordMode mode = kCoordModeOrigin) override;
0151 void PutPixel(Int_t x, Int_t y, const char *col = "#000000") override;
0152 void PolyPoint(UInt_t npt, TPoint *ppt, const char *col = "#000000", TImage::ECoordMode mode = kCoordModeOrigin) override;
0153 void DrawSegments(UInt_t nseg, Segment_t *seg, const char *col = "#000000", UInt_t thick = 1) override;
0154 void FillPolygon(UInt_t npt, TPoint *ppt, const char *col = "#000000", const char *stipple = nullptr, UInt_t w = 16, UInt_t h = 16) override;
0155 void FillPolygon(UInt_t npt, TPoint *ppt, TImage *tile) override;
0156 void CropPolygon(UInt_t npt, TPoint *ppt) override;
0157 void DrawFillArea(UInt_t npt, TPoint *ppt, const char *col = "#000000", const char *stipple = nullptr, UInt_t w = 16, UInt_t h = 16) override;
0158 void DrawFillArea(UInt_t npt, TPoint *ppt, TImage *tile) override;
0159 void FillSpans(UInt_t npt, TPoint *ppt, UInt_t *widths, const char *col = "#000000", const char *stipple = nullptr, UInt_t w = 16, UInt_t h = 16) override;
0160 void FillSpans(UInt_t npt, TPoint *ppt, UInt_t *widths, TImage *tile) override;
0161 void CropSpans(UInt_t npt, TPoint *ppt, UInt_t *widths) override;
0162 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) override;
0163 void DrawCellArray(Int_t x1, Int_t y1, Int_t x2, Int_t y2, Int_t nx, Int_t ny, UInt_t *ic) override;
0164 void FloodFill(Int_t x, Int_t y, const char *col, const char *min_col, const char *max_col = nullptr) override;
0165 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) override;
0166 void DrawStraightEllips(Int_t x, Int_t y, Int_t rx, Int_t ry, const char *col = "#000000", Int_t thick = 1) override;
0167 void DrawCircle(Int_t x, Int_t y, Int_t r, const char *col = "#000000", Int_t thick = 1) override;
0168 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) override;
0169 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) override;
0170
0171
0172 void ReadImage(const char *file, EImageFileTypes type = TImage::kUnknown) override;
0173 void WriteImage(const char *file, EImageFileTypes type = TImage::kUnknown) override;
0174 void SetImage(const Double_t *imageData, UInt_t width, UInt_t height, TImagePalette *palette = nullptr) override;
0175 void SetImage(const TArrayD &imageData, UInt_t width, TImagePalette *palette = nullptr) override;
0176 void SetImage(const TVectorD &imageData, UInt_t width, TImagePalette *palette = nullptr) override;
0177 void SetImage(Pixmap_t pxm, Pixmap_t mask = 0) override;
0178 void FromWindow(Drawable_t wid, Int_t x = 0, Int_t y = 0, UInt_t w = 0, UInt_t h = 0) override;
0179 void FromGLBuffer(UChar_t* buf, UInt_t w, UInt_t h) override;
0180
0181
0182 UInt_t GetWidth() const override;
0183 UInt_t GetHeight() const override;
0184 UInt_t GetScaledWidth() const;
0185 UInt_t GetScaledHeight() const;
0186 Bool_t IsValid() const override { return fImage ? kTRUE : kFALSE; }
0187 Bool_t IsGray() const override { return fIsGray; }
0188 ASImage *GetImage() const { return fImage; }
0189 void SetImage(ASImage *image) { DestroyImage(); fImage = image; }
0190 TImage *GetScaledImage() const override { return fScaledImage; }
0191 Pixmap_t GetPixmap() override;
0192 Pixmap_t GetMask() override;
0193 TArrayL *GetPixels(Int_t x = 0, Int_t y = 0, UInt_t w = 0, UInt_t h = 0) override;
0194 TArrayD *GetArray(UInt_t w = 0, UInt_t h = 0, TImagePalette *pal = gWebImagePalette) override;
0195 UInt_t *GetArgbArray() override;
0196 UInt_t *GetRgbaArray() override;
0197 Double_t *GetVecArray() override;
0198 UInt_t *GetScanline(UInt_t y) override;
0199 void GetImageBuffer(char **buffer, int *size, EImageFileTypes type = TImage::kPng) override;
0200 void GetZoomPosition(UInt_t &x, UInt_t &y, UInt_t &w, UInt_t &h) const;
0201 Bool_t SetImageBuffer(char **buffer, EImageFileTypes type = TImage::kPng) override;
0202 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 = "") override;
0203 void SetPaletteEnabled(Bool_t on = kTRUE) override;
0204 void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0205
0206 static const ASVisual *GetVisual();
0207 static UInt_t AlphaBlend(UInt_t bot, UInt_t top);
0208 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 = "");
0209
0210
0211 Bool_t SetJpegDpi(const char *name, UInt_t dpi = 72);
0212
0213 ClassDefOverride(TASImage,2)
0214 };
0215
0216 #endif