TASImage.h

Go to the documentation of this file.
00001 // @(#)root/asimage:$Id: TASImage.h 30543 2009-10-02 15:30:40Z couet $
00002 // Author: Fons Rademakers, Reiner Rohlfs 28/11/2001
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2001, Rene Brun, Fons Rademakers and Reiner Rohlfs *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TASImage
00013 #define ROOT_TASImage
00014 
00015 //////////////////////////////////////////////////////////////////////////
00016 //                                                                      //
00017 // TASImage                                                             //
00018 //                                                                      //
00019 // Interface to image processing library libAfterImage.                 //
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;        //! pointer to image structure of original image
00059    TASImage *fScaledImage;  //! temporary scaled and zoomed image produced from original image
00060    Double_t  fMaxValue;     //! max value in image
00061    Double_t  fMinValue;     //! min value in image
00062    UInt_t    fZoomOffX;     //! X - offset for zooming in image pixels
00063    UInt_t    fZoomOffY;     //! Y - offset for zooming im image pixels
00064    UInt_t    fZoomWidth;    //! width of zoomed image in image pixels
00065    UInt_t    fZoomHeight;   //! hight of zoomed image in image pixels
00066    Int_t     fZoomUpdate;   //! kZoom - new zooming required, kZoomOps - other ops in action, kNoZoom - no zooming or ops
00067    Bool_t    fEditable;     //! kTRUE image can be resized, moved by resizing/moving gPad
00068    Int_t     fPaintMode;    //! 1 - fast mode, 0 - low memory slow mode
00069    ASImage  *fGrayImage;    //! gray image
00070    Bool_t    fIsGray;       //! kTRUE if image is gray
00071    static THashTable *fgPlugList;   //! hash table containing loaded plugins
00072 
00073    static ASVisual *fgVisual;  // pointer to visual structure
00074    static Bool_t    fgInit;    // global flag to init afterimage only once
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; }             //*TOGGLE*
00096    Bool_t IsEditable() const { return fEditable; }
00097    void  Browse(TBrowser *);
00098    void  SetTitle(const char *title="");                                // *MENU*
00099    const char *GetTitle() const;
00100    const char *GetIconName() const {  return GetTitle(); }
00101 
00102    // Pad conversions
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    // Transformations
00112    void  SetPalette(const TImagePalette *palette);
00113    void  Zoom(UInt_t offX, UInt_t offY, UInt_t width, UInt_t height);   //*MENU*
00114    void  UnZoom();                                                      //*MENU*
00115    void  Flip(Int_t flip = 180);                                        //*MENU*
00116    void  Mirror(Bool_t vert = kTRUE);                                   //*MENU*
00117    void  Scale(UInt_t width, UInt_t height);                            //*MENU*
00118    void  Slice(UInt_t xStart, UInt_t xEnd, UInt_t yStart, UInt_t yEnd,
00119                UInt_t toWidth, UInt_t toHeight);                        //*MENU*
00120    void  Tile(UInt_t width, UInt_t height);                             //*MENU*
00121    void  Crop(Int_t x = 0, Int_t y = 0, UInt_t width = 0, UInt_t height = 0); //*MENU*
00122    void  Pad(const char *color = "#00FFFFFF", UInt_t left = 0,
00123              UInt_t right = 0, UInt_t top = 0, UInt_t bottom = 0);      //*MENU*
00124    void  Blur(Double_t hr = 3, Double_t vr = 3);                        //*MENU*
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);                                       //*TOGGLE* *GETTER=IsGray
00127    void  StartPaletteEditor();                                          //*MENU*
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    // Vector graphics
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    // Input / output
00171    void  ReadImage(const char *file, EImageFileTypes type = TImage::kUnknown);
00172    void  WriteImage(const char *file, EImageFileTypes type = TImage::kUnknown); //*MENU*
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    // Utilities
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);  // *TOGGLE*
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    // some static functions
00210    Bool_t SetJpegDpi(const char *name, UInt_t dpi = 72);
00211 
00212    ClassDef(TASImage,2)  // image processing class
00213 };
00214 
00215 #endif

Generated on Tue Jul 5 14:13:24 2011 for ROOT_528-00b_version by  doxygen 1.5.1