00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _unatima_hpp_
00021 #define _unatima_hpp_
00022
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
00060 UNatIma(UNatDisp*, unsigned char* glpixels, int width, int height);
00067
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
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
00160
00161 int width, height;
00162 mutable unsigned char alpha;
00163 unsigned char depth;
00164 float scale;
00165 USysIma xima, ximashape;
00166 mutable unsigned char* glpix;
00167 #ifdef HAVE_GL
00168 mutable GLuint gltex;
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
00189
00190 UNatPix(UNatDisp*, USysPix pix, USysPix shape, int width, int height, int depth);
00191
00192
00193
00194
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
00212