Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TASImage.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // @(#)root/asimage:$Id$
0002 // Author: Fons Rademakers, Reiner Rohlfs 28/11/2001
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2001, Rene Brun, Fons Rademakers and Reiner Rohlfs *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TASImage
0013 #define ROOT_TASImage
0014 
0015 //////////////////////////////////////////////////////////////////////////
0016 //                                                                      //
0017 // TASImage                                                             //
0018 //                                                                      //
0019 // Interface to image processing library libAfterImage.                 //
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;                ///<! pointer to image structure of original image
0058    TASImage *fScaledImage;          ///<! temporary scaled and zoomed image produced from original image
0059    Double_t  fMaxValue;             ///<! max value in image
0060    Double_t  fMinValue;             ///<! min value in image
0061    UInt_t    fZoomOffX;             ///<! X - offset for zooming in image pixels
0062    UInt_t    fZoomOffY;             ///<! Y - offset for zooming im image pixels
0063    UInt_t    fZoomWidth;            ///<! width of zoomed image in image pixels
0064    UInt_t    fZoomHeight;           ///<! hight of zoomed image in image pixels
0065    Int_t     fZoomUpdate;           ///<! kZoom - new zooming required, kZoomOps - other ops in action, kNoZoom - no zooming or ops
0066    Bool_t    fEditable;             ///<! kTRUE image can be resized, moved by resizing/moving gPad
0067    Int_t     fPaintMode;            ///<! 1 - fast mode, 0 - low memory slow mode
0068    ASImage  *fGrayImage;            ///<! gray image
0069    Bool_t    fIsGray;               ///<! kTRUE if image is gray
0070    static THashTable *fgPlugList;   ///<! hash table containing loaded plugins
0071 
0072    static ASVisual *fgVisual;      ///< pointer to visual structure
0073    static Bool_t    fgInit;        ///< global flag to init afterimage only once
0074 
0075    EImageFileTypes GetFileType(const char *ext);
0076    void MapFileTypes(EImageFileTypes &type, UInt_t &astype, Bool_t toas = kTRUE);
0077    void MapQuality(EImageQuality &quality, UInt_t &asquality, Bool_t toas = kTRUE);
0078 
0079    static Bool_t InitVisual();
0080 
0081 public:
0082    TASImage();
0083    TASImage(UInt_t w, UInt_t h);
0084    TASImage(const char *file, EImageFileTypes type = kUnknown);
0085    TASImage(const char *name, const Double_t *imageData, UInt_t width, UInt_t height, TImagePalette *palette = nullptr);
0086    TASImage(const char *name, const TArrayD &imageData, UInt_t width, TImagePalette *palette = nullptr);
0087    TASImage(const char *name, const TVectorD &imageData, UInt_t width, TImagePalette *palette = nullptr);
0088    TASImage(const TASImage &img);
0089    TASImage &operator=(const TASImage &img);
0090    ~TASImage() override;
0091 
0092    TObject *Clone(const char *newname) const override;
0093 
0094    void  SetEditable(Bool_t on = kTRUE) override { fEditable = on; }             //*TOGGLE*
0095    Bool_t IsEditable() const override { return fEditable; }
0096    void  Browse(TBrowser *) override;
0097    void  SetTitle(const char *title = "") override;                              // *MENU*
0098    const char *GetTitle() const override;
0099    const char *GetIconName() const override {  return GetTitle(); }
0100 
0101    // Pad conversions
0102    void  FromPad(TVirtualPad *pad, Int_t x = 0, Int_t y = 0,
0103                  UInt_t w = 0, UInt_t h = 0) override;
0104    void  Draw(Option_t *option = "") override;
0105    void  Paint(Option_t *option = "") override;
0106    Int_t DistancetoPrimitive(Int_t px, Int_t py) override;
0107    void  ExecuteEvent(Int_t event, Int_t px, Int_t py) override;
0108    char *GetObjectInfo(Int_t px, Int_t py) const override;
0109 
0110    // Transformations
0111    void  SetPalette(const TImagePalette *palette) override;
0112    void  Zoom(UInt_t offX, UInt_t offY, UInt_t width, UInt_t height) override;   //*MENU*
0113    void  UnZoom() override;                                                      //*MENU*
0114    void  Flip(Int_t flip = 180) override;                                        //*MENU*
0115    void  Mirror(Bool_t vert = kTRUE) override;                                   //*MENU*
0116    void  Scale(UInt_t width, UInt_t height) override;                            //*MENU*
0117    void  Slice(UInt_t xStart, UInt_t xEnd, UInt_t yStart, UInt_t yEnd,
0118                UInt_t toWidth, UInt_t toHeight) override;                        //*MENU*
0119    void  Tile(UInt_t width, UInt_t height) override;                             //*MENU*
0120    void  Crop(Int_t x = 0, Int_t y = 0, UInt_t width = 0, UInt_t height = 0) override; //*MENU*
0121    void  Pad(const char *color = "#00FFFFFF", UInt_t left = 0,
0122              UInt_t right = 0, UInt_t top = 0, UInt_t bottom = 0) override;      //*MENU*
0123    void  Blur(Double_t hr = 3, Double_t vr = 3) override;                        //*MENU*
0124    Double_t *Vectorize(UInt_t max_colors = 256, UInt_t dither = 4, Int_t opaque_threshold = 1) override;
0125    void  Gray(Bool_t on = kTRUE) override;                                       //*TOGGLE* *GETTER=IsGray
0126    void  StartPaletteEditor() override;                                          //*MENU*
0127    void  HSV(UInt_t hue = 0, UInt_t radius = 360, Int_t H = 0, Int_t S = 0, Int_t V = 0,
0128              Int_t x = 0, Int_t y = 0, UInt_t width = 0, UInt_t height = 0) override;
0129    void  Merge(const TImage *im, const char *op = "alphablend", Int_t x = 0, Int_t y = 0) override;
0130    void  Append(const TImage *im, const char * option = "+", const char *color = "#00000000") override;
0131    void  Gradient(UInt_t angle = 0, const char *colors = "#FFFFFF #000000", const char *offsets = nullptr,
0132                   Int_t x = 0, Int_t y = 0, UInt_t width = 0, UInt_t height = 0) override;
0133    void  Bevel(Int_t x = 0, Int_t y = 0, UInt_t width = 0, UInt_t height = 0, const char *hi = "#ffdddddd",
0134                const char *lo = "#ff555555", UShort_t thick = 1, Bool_t pressed = kFALSE) override;
0135    void  DrawText(Int_t  x = 0, Int_t y = 0, const char *text = "", Int_t size = 12,
0136                   const char *color = nullptr, const char *font = "fixed", EText3DType type = TImage::kPlain,
0137                   const char *fore_file = nullptr, Float_t angle = 0) override;
0138    void DrawText(TText *text, Int_t x = 0, Int_t y = 0) override;
0139 
0140    // Vector graphics
0141    void  BeginPaint(Bool_t fast = kTRUE) override;
0142    void  EndPaint() override;
0143    void  DrawLine(UInt_t x1, UInt_t y1, UInt_t x2, UInt_t y2, const char *col = "#000000", UInt_t thick = 1) override;
0144    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;
0145    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;
0146    void  DrawRectangle(UInt_t x, UInt_t y, UInt_t w, UInt_t h, const char *col = "#000000", UInt_t thick = 1) override;
0147    void  FillRectangle(const char *col = nullptr, Int_t x = 0, Int_t y = 0, UInt_t width = 0, UInt_t height = 0) override;
0148    void  DrawPolyLine(UInt_t nn, TPoint *xy, const char *col = "#000000", UInt_t thick = 1, TImage::ECoordMode mode = kCoordModeOrigin) override;
0149    void  PutPixel(Int_t x, Int_t y, const char *col = "#000000") override;
0150    void  PolyPoint(UInt_t npt, TPoint *ppt, const char *col = "#000000", TImage::ECoordMode mode = kCoordModeOrigin) override;
0151    void  DrawSegments(UInt_t nseg, Segment_t *seg, const char *col = "#000000", UInt_t thick = 1) override;
0152    void  FillPolygon(UInt_t npt, TPoint *ppt, const char *col = "#000000", const char *stipple = nullptr, UInt_t w = 16, UInt_t h = 16) override;
0153    void  FillPolygon(UInt_t npt, TPoint *ppt, TImage *tile) override;
0154    void  CropPolygon(UInt_t npt, TPoint *ppt) override;
0155    void  DrawFillArea(UInt_t npt, TPoint *ppt, const char *col = "#000000", const char *stipple = nullptr, UInt_t w = 16, UInt_t h = 16) override;
0156    void  DrawFillArea(UInt_t npt, TPoint *ppt, TImage *tile) override;
0157    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;
0158    void  FillSpans(UInt_t npt, TPoint *ppt, UInt_t *widths, TImage *tile) override;
0159    void  CropSpans(UInt_t npt, TPoint *ppt, UInt_t *widths) override;
0160    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;
0161    void  DrawCellArray(Int_t x1, Int_t y1, Int_t x2, Int_t y2, Int_t nx, Int_t ny, UInt_t *ic) override;
0162    void  FloodFill(Int_t x, Int_t y, const char *col, const char *min_col, const char *max_col = nullptr) override;
0163    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;
0164    void  DrawStraightEllips(Int_t x, Int_t y, Int_t rx, Int_t ry, const char *col = "#000000", Int_t thick = 1) override;
0165    void  DrawCircle(Int_t x, Int_t y, Int_t r, const char *col = "#000000", Int_t thick = 1) override;
0166    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;
0167    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;
0168 
0169    // Input / output
0170    void  ReadImage(const char *file, EImageFileTypes type = TImage::kUnknown) override;
0171    void  WriteImage(const char *file, EImageFileTypes type = TImage::kUnknown) override; //*MENU*
0172    void  SetImage(const Double_t *imageData, UInt_t width, UInt_t height, TImagePalette *palette = nullptr) override;
0173    void  SetImage(const TArrayD &imageData, UInt_t width, TImagePalette *palette = nullptr) override;
0174    void  SetImage(const TVectorD &imageData, UInt_t width, TImagePalette *palette = nullptr) override;
0175    void  SetImage(Pixmap_t pxm, Pixmap_t mask = 0) override;
0176    void  FromWindow(Drawable_t wid, Int_t x = 0, Int_t y = 0, UInt_t w = 0, UInt_t h = 0) override;
0177    void  FromGLBuffer(UChar_t* buf, UInt_t w, UInt_t h) override;
0178 
0179    // Utilities
0180    UInt_t     GetWidth() const override;
0181    UInt_t     GetHeight() const override;
0182    UInt_t     GetScaledWidth() const;
0183    UInt_t     GetScaledHeight() const;
0184    Bool_t     IsValid() const override { return fImage ? kTRUE : kFALSE; }
0185    Bool_t     IsGray() const override { return fIsGray; }
0186    ASImage   *GetImage() const { return fImage; }
0187    void       SetImage(ASImage *image) { DestroyImage(); fImage = image; }
0188    TImage    *GetScaledImage() const override { return fScaledImage; }
0189    Pixmap_t   GetPixmap() override;
0190    Pixmap_t   GetMask() override;
0191    TArrayL   *GetPixels(Int_t x = 0, Int_t y = 0, UInt_t w = 0, UInt_t h = 0) override;
0192    TArrayD   *GetArray(UInt_t w = 0, UInt_t h = 0, TImagePalette *pal = gWebImagePalette) override;
0193    UInt_t    *GetArgbArray() override;
0194    UInt_t    *GetRgbaArray() override;
0195    Double_t  *GetVecArray() override;
0196    UInt_t    *GetScanline(UInt_t y) override;
0197    void       GetImageBuffer(char **buffer, int *size, EImageFileTypes type = TImage::kPng) override;
0198    void       GetZoomPosition(UInt_t &x, UInt_t &y, UInt_t &w, UInt_t &h) const;
0199    Bool_t     SetImageBuffer(char **buffer, EImageFileTypes type = TImage::kPng) override;
0200    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;
0201    void       SetPaletteEnabled(Bool_t on = kTRUE) override;  // *TOGGLE*
0202    void       SavePrimitive(std::ostream &out, Option_t *option = "") override;
0203 
0204    static const ASVisual *GetVisual();
0205    static UInt_t AlphaBlend(UInt_t bot, UInt_t top);
0206    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 = "");
0207 
0208    // some static functions
0209    Bool_t SetJpegDpi(const char *name, UInt_t dpi = 72);
0210 
0211    ClassDefOverride(TASImage,2)  // image processing class
0212 };
0213 
0214 #endif