Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
|
00001 /******************************************************************************** 00002 * * 00003 * B i t m a p O b j e c t * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 1998,2006 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: FXBitmap.h,v 1.37 2006/01/22 17:57:59 fox Exp $ * 00023 ********************************************************************************/ 00024 #ifndef FXBITMAP_H 00025 #define FXBITMAP_H 00026 00027 #ifndef FXDRAWABLE_H 00028 #include "FXDrawable.h" 00029 #endif 00030 00031 namespace FX { 00032 00033 // Image rendering hints 00034 enum { 00035 BITMAP_KEEP = 0x00000001, // Keep pixel data in client 00036 BITMAP_OWNED = 0x00000002, // Pixel data is owned by image 00037 BITMAP_SHMI = 0x00000020, // Using shared memory image 00038 BITMAP_SHMP = 0x00000040 // Using shared memory pixmap 00039 }; 00040 00041 00042 // Forward declarations 00043 class FXDC; 00044 class FXDCWindow; 00045 00046 00047 /** 00048 * A Bitmap is a rectangular array of pixels. It supports two representations 00049 * of these pixels: a client-side pixel buffer, and a server-side pixmap which 00050 * is stored in an organization directly compatible with the screen, for fast 00051 * drawing onto the device. 00052 * The server-side representation is not directly accessible from the current 00053 * process as it lives in the process of the X Server or GDI. 00054 * The client-side pixel array is of size height x (width+7)/8 bytes, in other 00055 * words 8 pixels packed into a single byte, starting at bit 0 on the left. 00056 */ 00057 class FXAPI FXBitmap : public FXDrawable { 00058 FXDECLARE(FXBitmap) 00059 friend class FXDC; 00060 friend class FXDCWindow; 00061 private: 00062 #ifdef WIN32 00063 virtual FXID GetDC() const; 00064 virtual int ReleaseDC(FXID) const; 00065 #endif 00066 protected: 00067 FXuchar *data; // Pixel data 00068 FXint bytewidth; // Number of bytes across 00069 FXuint options; // Options 00070 protected: 00071 FXBitmap(); 00072 private: 00073 FXBitmap(const FXBitmap&); 00074 FXBitmap &operator=(const FXBitmap&); 00075 public: 00076 00077 /** 00078 * Create a bitmap. If a client-side pixel buffer has been specified, 00079 * the bitmap does not own the pixel buffer unless the BITMAP_OWNED flag is 00080 * set. If the BITMAP_OWNED flag is set but a NULL pixel buffer is 00081 * passed, a pixel buffer will be automatically created and will be owned 00082 * by the bitmap. The flags BITMAP_SHMI and BITMAP_SHMP may be specified for 00083 * large bitmaps to instruct render() to use shared memory to communicate 00084 * with the server. 00085 */ 00086 FXBitmap(FXApp* a,const void *pix=NULL,FXuint opts=0,FXint w=1,FXint h=1); 00087 00088 /// Change options 00089 void setOptions(FXuint opts); 00090 00091 /// To get to the option flags 00092 FXuint getOptions() const { return options; } 00093 00094 /** 00095 * Populate the bitmap with new pixel data of the same size; it will assume 00096 * ownership of the pixel data if image BITMAP_OWNED option is passed. 00097 * The server-side representation of the image, if it exists, is not updated. 00098 * This can be done by calling render(). 00099 */ 00100 virtual void setData(FXuchar *pix,FXuint opts=0); 00101 00102 /** 00103 * Populate the bitmap with new pixel data of a new size; it will assume ownership 00104 * of the pixel data if image BITMAP_OWNED option is passed. The size of the server- 00105 * side representation of the image, if it exists, is adjusted but the contents are 00106 * not updated yet. This can be done by calling render(). 00107 */ 00108 virtual void setData(FXuchar *pix,FXuint opts,FXint w,FXint h); 00109 00110 /// To get to the pixel data 00111 FXuchar* getData() const { return data; } 00112 00113 /// Get pixel at x,y 00114 FXbool getPixel(FXint x,FXint y) const { return (FXbool)((data[y*bytewidth+(x>>3)]>>(x&7))&1); } 00115 00116 /// Change pixel at x,y 00117 void setPixel(FXint x,FXint y,FXbool color){ color ? data[y*bytewidth+(x>>3)]|=(1<<(x&7)) : data[y*bytewidth+(x>>3)]&=~(1<<(x&7)); } 00118 00119 /** 00120 * Create the server side pixmap, then call render() to fill it with the 00121 * pixel data from the client-side buffer. After the server-side image has 00122 * been created, the client-side pixel buffer will be deleted unless 00123 * BITMAP_KEEP has been specified. If the pixel buffer is not owned, i.e. 00124 * the flag BITMAP_OWNED is not set, the pixel buffer will not be deleted. 00125 */ 00126 virtual void create(); 00127 00128 /** 00129 * Detach the server side pixmap from the Bitmap. 00130 * Afterwards, the Bitmap is left as if it never had a server-side resources. 00131 */ 00132 virtual void detach(); 00133 00134 /** 00135 * Destroy the server-side pixmap. 00136 * The client-side pixel buffer is not affected. 00137 */ 00138 virtual void destroy(); 00139 00140 /** 00141 * Retrieves pixels from the server-side bitmap. 00142 */ 00143 virtual void restore(); 00144 00145 /** 00146 * Render the server-side representation of the bitmap from client-side 00147 * pixels. 00148 */ 00149 virtual void render(); 00150 00151 /** 00152 * Release the client-side pixels buffer, free it if it was owned. 00153 * If it is not owned, the image just forgets about the buffer. 00154 */ 00155 virtual void release(); 00156 00157 /** 00158 * Resize both client-side and server-side representations (if any) to the 00159 * given width and height. The new representations typically contain garbage 00160 * after this operation and need to be re-filled. 00161 */ 00162 virtual void resize(FXint w,FXint h); 00163 00164 /** 00165 * Rescale pixels image to the specified width and height; this calls 00166 * resize() to adjust the client and server side representations. 00167 */ 00168 virtual void scale(FXint w,FXint h); 00169 00170 /// Mirror bitmap horizontally and/or vertically 00171 virtual void mirror(FXbool horizontal,FXbool vertical); 00172 00173 /// Rotate bitmap by degrees ccw 00174 virtual void rotate(FXint degrees); 00175 00176 /** 00177 * Crop bitmap to given rectangle; this calls resize() to adjust the client 00178 * and server side representations. The new bitmap may be smaller or larger 00179 * than the old one; blank areas are filled with color. There must be at 00180 * least one pixel of overlap between the old and the new bitmap. 00181 */ 00182 virtual void crop(FXint x,FXint y,FXint w,FXint h,FXbool color=0); 00183 00184 /// Fill bitmap with uniform value 00185 virtual void fill(FXbool color); 00186 00187 /// Save object to stream 00188 virtual void save(FXStream& store) const; 00189 00190 /// Load object from stream 00191 virtual void load(FXStream& store); 00192 00193 /// Save pixel data only 00194 virtual bool savePixels(FXStream& store) const; 00195 00196 /// Load pixel data only 00197 virtual bool loadPixels(FXStream& store); 00198 00199 /// Cleanup 00200 virtual ~FXBitmap(); 00201 }; 00202 00203 } 00204 00205 #endif 00206
Copyright © 1997-2005 Jeroen van der Zijp |