Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXImage.h

00001 /******************************************************************************** 00002 * * 00003 * I m a g e O b j e c t * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 1997,2004 by Jeroen van der Zijp. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2.1 of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public * 00019 * License along with this library; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 00021 ********************************************************************************* 00022 * $Id: FXImage.h,v 1.56 2004/04/28 16:29:07 fox Exp $ * 00023 ********************************************************************************/ 00024 #ifndef FXIMAGE_H 00025 #define FXIMAGE_H 00026 00027 #ifndef FXDRAWABLE_H 00028 #include "FXDrawable.h" 00029 #endif 00030 00031 namespace FX { 00032 00033 00034 /// Image rendering hints 00035 enum { 00036 IMAGE_KEEP = 0x00000001, /// Keep pixel data in client 00037 IMAGE_OWNED = 0x00000002, /// Pixel data is owned by image 00038 IMAGE_DITHER = 0, /// Dither image to look better 00039 IMAGE_NEAREST = 0x00000004, /// Turn off dithering and map to nearest color 00040 IMAGE_OPAQUE = 0x00000008, /// Force opaque background 00041 IMAGE_ALPHACOLOR = 0x00000010, /// Override transparancy color 00042 IMAGE_SHMI = 0x00000020, /// Using shared memory image 00043 IMAGE_SHMP = 0x00000040, /// Using shared memory pixmap 00044 IMAGE_ALPHAGUESS = 0x00000080 /// Guess transparency color from corners 00045 }; 00046 00047 00048 class FXDC; 00049 class FXDCWindow; 00050 00051 00052 /** 00053 * An Image is a rectangular array of pixels. It supports two representations 00054 * of these pixels: a client-side pixel buffer which is stored as an array of 00055 * FXColor, and a server-side pixmap which is stored in an organization directly 00056 * compatible with the screen, for fast drawing onto the device. 00057 * The server-side representation is not directly accessible from the current 00058 * process as it lives in the process of the X Server or GDI. 00059 */ 00060 class FXAPI FXImage : public FXDrawable { 00061 FXDECLARE(FXImage) 00062 friend class FXDC; 00063 friend class FXDCWindow; 00064 protected: 00065 FXColor *data; // Pixel data 00066 FXuint options; // Options 00067 private: 00068 #ifdef WIN32 00069 virtual FXID GetDC() const; 00070 virtual int ReleaseDC(FXID) const; 00071 #endif 00072 #ifndef WIN32 00073 void render_true_32(void *xim,FXuchar *img); 00074 void render_true_24(void *xim,FXuchar *img); 00075 void render_true_16_fast(void *xim,FXuchar *img); 00076 void render_true_16_dither(void *xim,FXuchar *img); 00077 void render_true_8_fast(void *xim,FXuchar *img); 00078 void render_true_8_dither(void *xim,FXuchar *img); 00079 void render_true_N_fast(void *xim,FXuchar *img); 00080 void render_true_N_dither(void *xim,FXuchar *img); 00081 void render_index_4_fast(void *xim,FXuchar *img); 00082 void render_index_4_dither(void *xim,FXuchar *img); 00083 void render_index_8_fast(void *xim,FXuchar *img); 00084 void render_index_8_dither(void *xim,FXuchar *img); 00085 void render_index_N_fast(void *xim,FXuchar *img); 00086 void render_index_N_dither(void *xim,FXuchar *img); 00087 void render_gray_8_fast(void *xim,FXuchar *img); 00088 void render_gray_8_dither(void *xim,FXuchar *img); 00089 void render_gray_N_fast(void *xim,FXuchar *img); 00090 void render_gray_N_dither(void *xim,FXuchar *img); 00091 void render_mono_1_fast(void *xim,FXuchar *img); 00092 void render_mono_1_dither(void *xim,FXuchar *img); 00093 #endif 00094 protected: 00095 FXImage(); 00096 private: 00097 FXImage(const FXImage&); 00098 FXImage &operator=(const FXImage&); 00099 public: 00100 00101 /** 00102 * Create an image. If a client-side pixel buffer has been specified, 00103 * the image does not own the pixel buffer unless the IMAGE_OWNED flag is 00104 * set. If the IMAGE_OWNED flag is set but a NULL pixel buffer is 00105 * passed, a pixel buffer will be automatically created and will be owned 00106 * by the image. The flags IMAGE_SHMI and IMAGE_SHMP may be specified for 00107 * large images to instruct render() to use shared memory to communicate 00108 * with the server. 00109 */ 00110 FXImage(FXApp* a,const FXColor *pix=NULL,FXuint opts=0,FXint w=1,FXint h=1); 00111 00112 /// To get to the pixel data 00113 FXColor* getData() const { return data; } 00114 00115 /// To get to the option flags 00116 FXuint getOptions() const { return options; } 00117 00118 /// Change options 00119 void setOptions(FXuint opts); 00120 00121 /// Get pixel at x,y 00122 FXColor getPixel(FXint x,FXint y) const { return data[y*width+x]; } 00123 00124 /// Change pixel at x,y 00125 void setPixel(FXint x,FXint y,FXColor color){ data[y*width+x]=color; } 00126 00127 /// Scan the image and return FALSE if fully opaque 00128 FXbool hasAlpha() const; 00129 00130 /** 00131 * Create the server side pixmap, then call render() to fill it with the 00132 * pixel data from the client-side buffer. After the server-side image has 00133 * been created, the client-side pixel buffer will be deleted unless 00134 * IMAGE_KEEP has been specified. If the pixel buffer is not owned, i.e. 00135 * the flag IMAGE_OWNED is not set, the pixel buffer will not be deleted. 00136 */ 00137 virtual void create(); 00138 00139 /** 00140 * Detach the server side pixmap from the Image. 00141 * Afterwards, the Image is left as if it never had a server-side resources. 00142 */ 00143 virtual void detach(); 00144 00145 /** 00146 * Destroy the server-side pixmap. 00147 * The client-side pixel buffer is not affected. 00148 */ 00149 virtual void destroy(); 00150 00151 /** 00152 * Retrieves pixels from the server-side image. For example, to make 00153 * screen snapshots, or to retrieve an image after it has been drawin 00154 * into by various means. 00155 */ 00156 virtual void restore(); 00157 00158 /** 00159 * Render the server-side representation of the image from client-side 00160 * pixels. Normally, IMAGE_DITHER is used which causes the server-side 00161 * representation to be rendered using a 16x16 ordered dither if necessary; 00162 * however if IMAGE_NEAREST is used a faster (but uglier-looking), nearest 00163 * neighbor algorithm is used. 00164 */ 00165 virtual void render(); 00166 00167 /** 00168 * Release the client-side pixels buffer, free it if it was owned. 00169 * If it is not owned, the image just forgets about the buffer. 00170 */ 00171 virtual void release(); 00172 00173 /** 00174 * Resize both client-side and server-side representations (if any) to the 00175 * given width and height. The new representations typically contain garbage 00176 * after this operation and need to be re-filled. 00177 */ 00178 virtual void resize(FXint w,FXint h); 00179 00180 /** 00181 * Rescale pixels image to the specified width and height; this calls 00182 * resize() to adjust the client and server side representations. 00183 */ 00184 virtual void scale(FXint w,FXint h,FXint quality=0); 00185 00186 /// Mirror image horizontally and/or vertically 00187 virtual void mirror(FXbool horizontal,FXbool vertical); 00188 00189 /** 00190 * Rotate image by degrees ccw; this calls resize() to adjust the client 00191 * and server side representations if necessary. 00192 */ 00193 virtual void rotate(FXint degrees); 00194 00195 /** 00196 * Crop image to given rectangle; this calls resize() to adjust the client 00197 * and server side representations. 00198 */ 00199 virtual void crop(FXint x,FXint y,FXint w,FXint h); 00200 00201 /// Fill image with uniform color 00202 virtual void fill(FXColor color); 00203 00204 /// Fade image to uniform color 00205 virtual void fade(FXColor color,FXint factor=255); 00206 00207 /** 00208 * Shear image horizontally; the number of pixels is equal to the 00209 * shear parameter times 256. The area outside the image is filled 00210 * with transparent black, unless another color is specified. 00211 */ 00212 virtual void xshear(FXint shear,FXColor clr=0); 00213 00214 /** 00215 * Shear image vertically; the number of pixels is equal to the 00216 * shear parameter times 256. The area outside the image is filled 00217 * with transparent black, unless another color is specified. 00218 */ 00219 virtual void yshear(FXint shear,FXColor clr=0); 00220 00221 /// Fill horizontal gradient 00222 virtual void hgradient(FXColor left,FXColor right); 00223 00224 /// Fill vertical gradient 00225 virtual void vgradient(FXColor top,FXColor bottom); 00226 00227 /// Fill with gradient 00228 virtual void gradient(FXColor topleft,FXColor topright,FXColor bottomleft,FXColor bottomright); 00229 00230 /// Blend image over uniform color 00231 virtual void blend(FXColor color); 00232 00233 /// Save object to stream 00234 virtual void save(FXStream& store) const; 00235 00236 /// Load object from stream 00237 virtual void load(FXStream& store); 00238 00239 /// Save pixel data only 00240 virtual FXbool savePixels(FXStream& store) const; 00241 00242 /// Load pixel data only 00243 virtual FXbool loadPixels(FXStream& store); 00244 00245 /// Destructor 00246 virtual ~FXImage(); 00247 }; 00248 00249 } 00250 00251 #endif

Copyright © 1997-2004 Jeroen van der Zijp