unatima.hpp

00001 /* ==================================================== ======== ======= *
00002 *
00003 *  unatima.hpp : native images and pixmaps
00004 *  Ubit Project
00005 *  Part of the Ubit Toolkit: A Brick Construction Game Model for Creating GUIs
00006 *  (C) 1999-2006 EricLecolinet / ENST Paris / http://www.enst.fr/~elc/ubit
00007 *
00008 * ***********************************************************************
00009 * COPYRIGHT NOTICE :
00010 * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE
00011 * IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
00012 * YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU
00013 * GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION;
00014 * EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
00015 * SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
00016 * ***********************************************************************
00017 * ==================================================== [(c)Elc] ======= *
00018 * ==================================================== ======== ======= */
00019 
00020 #ifndef _unatima_hpp_
00021 #define _unatima_hpp_
00022 //pragma ident  "@(#)unatima.hpp        ubit:05.05.00"
00023 #include <ubit/unatgraph.hpp>
00024 namespace ubit {
00025 
00026 /* ==================================================== ===== ======= */
00034 class UNatIma {
00035 public:
00036   static const char* const GIF;
00037   static const char* const JPG;
00038   static const char* const XPM;
00039   static const char* const XPM_DATA;
00040 
00041   static int xpmFileReader(UNatDisp*, const char* fpath, UNatIma*&);
00042   static int xpmDataReader(UNatDisp*, const char* xpm_data, UNatIma*&);
00043   static int gifFileReader(UNatDisp*, const char* fpath, UNatIma*&);
00044   static int jpegFileReader(UNatDisp*, const char* fpath,UNatIma*&, int max_w, int max_h);
00046 
00047   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00048 
00049   UNatIma(UNatDisp*, USysIma ima, USysIma imashape);
00059 //ifdef HAVE_GL
00060   UNatIma(UNatDisp*, unsigned char* glpixels, int width, int height);
00067 //endif
00068   
00069   ~UNatIma();
00070 
00071   bool isRealized() const;
00072   int getAlpha()  const {return alpha;}
00073   int getDepth()  const {return depth;}
00074   int getWidth()  const {return width;}
00075   int getHeight() const {return height;}
00076   USysIma getXImage()  {return xima;}
00077   USysIma getXImageShape() {return ximashape;}
00078   
00079   USysPixel getPixel(int x, int y) {
00080 #ifdef WITH_GDK
00081     return gdk_image_get_pixel(xima, x, y);
00082 #else
00083     return XGetPixel(xima, x, y);
00084 #endif
00085   }
00086 
00087   void setPixel(USysPixel p, int x, int y) {
00088 #ifdef WITH_GDK
00089     gdk_image_put_pixel(xima, p, x, y);
00090 #else
00091     XPutPixel(xima, p, x, y);
00092 #endif
00093   }
00094   
00095   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00096 
00097   static int readImage(UNatDisp*, const char* filename, const char* filetype, 
00098                        UNatIma*& natima);
00099   static int readImage(UNatDisp*, const char* filename, const char* filetype,
00100                        UNatIma*& natima, int max_width, int max_height);
00107   static UNatIma* createImage(UNatDisp*, int width, int height);
00108   
00109   UNatIma* createScaledImage(float xscale, float yscale);
00110   UNatIma* createScaledImage(UNatDisp* to_nd, float xscale, float yscale);
00116   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00117 
00118   static USysIma createEmptyXImage(UNatDisp*, int width, int height, int depth);
00126   static USysIma createScaledXImage(UNatDisp* to_nd, UNatDisp* from_nd,
00127                                      USysIma from_ima, float xscale, float yscale);
00136   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00137 
00138   static bool blendXImages(UNatDisp*, USysIma i1, USysIma i2, float alpha);
00139   static bool blendXImage(UNatDisp*, USysIma i1, USysPixel p2, float alpha);
00145   static USysPixel* allocXColors(UNatDisp*, USysColor* colors, int col_count); 
00147 
00148   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00149   // implementation
00150 
00151 #ifndef NO_DOC
00152 protected:
00153   friend class UGraph;
00154   friend class UIma;
00155   friend class UPix;
00156   friend class UNatPix;
00157 
00158   UNatDisp* natdisp;
00159   // !att: width,height = taille LOGIQUE de l'image, pas de la texture
00160   // qui est toujours une puissance de 2 !
00161   int width, height;
00162   mutable unsigned char alpha;  // 0, 1 or 8 bits
00163   unsigned char depth;
00164   float scale;
00165   USysIma xima, ximashape;       // image data for X11
00166   mutable unsigned char* glpix;  // image data for OpenGL
00167 #ifdef HAVE_GL
00168   mutable GLuint gltex;          // texture Identifiant
00169   void createGLTexFromPixels() const;
00170   void createGLTexFromXImages() const;
00171 #endif
00172 #endif
00173 };
00174 
00175 /* ==================================================== ===== ======= */
00178 class UNatPix {
00179   friend class UGraph;
00180   friend class UPix;
00181   UNatDisp *natdisp;
00182   USysPix xpix, xpixshape;
00183   int width, height;
00184   int depth;
00185   float scale; 
00186 
00187 public:
00188   // xpixshape == None ==> opaque image
00189   // xpixshape != None ==> transparent background
00190   UNatPix(UNatDisp*, USysPix pix, USysPix shape, int width, int height, int depth);
00191 
00192   // creates the pixmaps from the images
00193   // ximashape == null ==> opaque image
00194   // ximashape != null ==> transparent background
00195   UNatPix(UNatDisp*, USysIma xima, USysIma ximashape);
00196   UNatPix(UNatDisp*, UNatIma*);
00197   ~UNatPix();
00198 
00199   void set(USysIma xima, USysIma ximashape);
00200 
00201   int getWidth()    const {return width;}
00202   int getHeight()   const {return height;}
00203   bool isRealized() const {return xpix != USysNull;}
00204   bool isShaped()   const {return xpixshape != USysNull;}
00205   const USysPix getXPixmap()      const {return xpix;}
00206   const USysPix getXPixmapShape() const {return xpixshape;}
00207 };
00208 
00209 }
00210 #endif
00211 /* ==================================================== [TheEnd] ======= */
00212 /* ==================================================== [(c)Elc] ======= */

Generated on Mon Jan 29 00:20:39 2007 for Ubit by  doxygen 1.4.7