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

FXBitmap.h

00001 /******************************************************************************** 00002 * * 00003 * B i t m a p O b j e c t * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 1998,2005 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.33 2005/01/16 16:06:06 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 /// To get to the pixel data 00089 FXuchar* getData() const { return data; } 00090 00091 /// To get to the option flags 00092 FXuint getOptions() const { return options; } 00093 00094 /// Change options 00095 void setOptions(FXuint opts); 00096 00097 /// Get pixel at x,y 00098 FXbool getPixel(FXint x,FXint y) const { return (FXbool)((data[y*bytewidth+(x>>3)]>>(x&7))&1); } 00099 00100 /// Change pixel at x,y 00101 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)); } 00102 00103 /** 00104 * Create the server side pixmap, then call render() to fill it with the 00105 * pixel data from the client-side buffer. After the server-side image has 00106 * been created, the client-side pixel buffer will be deleted unless 00107 * BITMAP_KEEP has been specified. If the pixel buffer is not owned, i.e. 00108 * the flag BITMAP_OWNED is not set, the pixel buffer will not be deleted. 00109 */ 00110 virtual void create(); 00111 00112 /** 00113 * Detach the server side pixmap from the Bitmap. 00114 * Afterwards, the Bitmap is left as if it never had a server-side resources. 00115 */ 00116 virtual void detach(); 00117 00118 /** 00119 * Destroy the server-side pixmap. 00120 * The client-side pixel buffer is not affected. 00121 */ 00122 virtual void destroy(); 00123 00124 /** 00125 * Render the server-side representation of the bitmap from client-side 00126 * pixels. 00127 */ 00128 virtual void render(); 00129 00130 /** 00131 * Release the client-side pixels buffer, free it if it was owned. 00132 * If it is not owned, the image just forgets about the buffer. 00133 */ 00134 virtual void release(); 00135 00136 /** 00137 * Resize both client-side and server-side representations (if any) to the 00138 * given width and height. The new representations typically contain garbage 00139 * after this operation and need to be re-filled. 00140 */ 00141 virtual void resize(FXint w,FXint h); 00142 00143 /** 00144 * Rescale pixels image to the specified width and height; this calls 00145 * resize() to adjust the client and server side representations. 00146 */ 00147 virtual void scale(FXint w,FXint h); 00148 00149 /// Mirror bitmap horizontally and/or vertically 00150 virtual void mirror(FXbool horizontal,FXbool vertical); 00151 00152 /// Rotate bitmap by degrees ccw 00153 virtual void rotate(FXint degrees); 00154 00155 /** 00156 * Crop bitmap to given rectangle; this calls resize() to adjust the client 00157 * and server side representations. The new bitmap may be smaller or larger 00158 * than the old one; blank areas are filled with color. There must be at 00159 * least one pixel of overlap between the old and the new bitmap. 00160 */ 00161 virtual void crop(FXint x,FXint y,FXint w,FXint h,FXbool color=0); 00162 00163 /// Fill bitmap with uniform value 00164 virtual void fill(FXbool color); 00165 00166 /// Save object to stream 00167 virtual void save(FXStream& store) const; 00168 00169 /// Load object from stream 00170 virtual void load(FXStream& store); 00171 00172 /// Save pixel data only 00173 virtual FXbool savePixels(FXStream& store) const; 00174 00175 /// Load pixel data only 00176 virtual FXbool loadPixels(FXStream& store); 00177 00178 /// Cleanup 00179 virtual ~FXBitmap(); 00180 }; 00181 00182 } 00183 00184 #endif

Copyright © 1997-2005 Jeroen van der Zijp