00001 /* 00002 /-------------------------------------------------------------------- 00003 | 00004 | $Id: plbitmap_8h-source.html,v 1.4 2004/09/15 15:26:26 uzadow Exp $ 00005 | 00006 | Copyright (c) 1996-2002 Ulrich von Zadow 00007 | 00008 \-------------------------------------------------------------------- 00009 */ 00010 00011 #ifndef INCL_PLBITMAP 00012 #define INCL_PLBITMAP 00013 00014 #include "plbmpbase.h" 00015 #include "plpoint.h" 00016 #include "pldebug.h" 00017 #include "plpixel32.h" 00018 #include "plpixel24.h" 00019 #include "plpixel16.h" 00020 00021 class PLFilter; 00022 00023 //! Device- and OS-independent bitmap class. Manipulates uncompressed 00024 //! bitmaps of all color depths. 00025 //! 00026 //! This class is an abstract base class. It exists to define a 00027 //! format-independent interface for bitmap manipulation and to 00028 //! provide common routines. Derived classes must support at least 00029 //! the color depths 1, 8 and 32 bpp. PLBmp defines a public interface 00030 //! for general use and a protected interface for use by derived 00031 //! classes. 00032 //! 00033 //! For 32 bpp, alpha channel information is stored in one byte 00034 //! (PL_RGBA_ALPHA) of each 4-byte pixel. To allow for optimizations 00035 //! when no alpha channel is present, a flag is set whenever the 00036 //! alpha information is valid. The complete alpha channel of a 00037 //! bitmap can be replaced by a different one by calling 00038 //! SetAlphaChannel(). A 0 in an alpha channel entry is completely 00039 //! transparent; a 255 is completely opaque. 00040 class PLBmp : public PLBmpBase 00041 { 00042 00043 public: 00044 00045 //! Empty constructor. Constructors in derived classes create a 00046 //! small empty bitmap to ensure that the object is always in a 00047 //! sane state. 00048 PLBmp 00049 (); 00050 00051 //! Empty destructor. 00052 virtual ~PLBmp 00053 (); 00054 00055 //! Assignment operator. Note that assignment between different derived 00056 //! classes is possible and results in a format conversion. 00057 PLBmp &operator= 00058 ( PLBmpBase const &Orig 00059 ); 00060 00061 PLBmp &operator= 00062 ( PLBmp const &Orig 00063 ); 00064 00065 // PLBmp creation 00066 00067 //! Creates a new empty bitmap. Memory for the bits is allocated 00068 //! but not initialized. Previous contents of the bitmap object are 00069 //! discarded. If bAlphaChannel is true, the bitmap is assumed to 00070 //! contain a valid alpha channel. If pBits is non-null, it contains 00071 //! pixel data in the format expected by the bitmap and Stride is the 00072 //! distance in bytes from one source line to the next. In this case, 00073 //! the data in pBits is copied into the internal buffer of the PLBmp. 00074 virtual void Create 00075 ( PLLONG Width, 00076 PLLONG Height, 00077 const PLPixelFormat& pf, 00078 PLBYTE * pBits = 0, 00079 int Stride = 0, 00080 const PLPoint& Resolution = PLPoint (0,0) 00081 ); 00082 00083 //! Creates a new empty bitmap. Info contains the metadata (width, height, 00084 //! etc.) to be used in creation. 00085 virtual void Create 00086 ( const PLBmpInfo& Info 00087 ); 00088 00089 //! Creates a copy of rSrcBmp, converting color depth if nessesary. 00090 //! Supports 1, 8, 16, 24 and 32 BPP. Alpha channel information is preserved if 00091 //! supported by the target bit depth. Conversion to 8 bpp is possible only 00092 //! from 1 and 32 bpp. 00093 void CreateCopy 00094 ( const PLBmpBase & rSrcBmp, 00095 const PLPixelFormat& pfWanted = PLPixelFormat::DONTCARE 00096 ); 00097 00098 //! Creates a copy of rSrcBmp, applying rFilter on the way. Depending 00099 //! on the filter called, this is often much faster than CreateCopy() 00100 //! followed by ApplyFilter(). 00101 void CreateFilteredCopy (PLBmpBase & rSrcBmp, const PLFilter & rFilter); 00102 00103 // PLBmp information 00104 00105 //! Returns memory used by a bitmap 00106 virtual long GetMemUsed 00107 () = 0; 00108 00109 //! Returns number of bytes used per line. Note that this is not the 00110 //! stride of the bitmap. 00111 virtual long GetBytesPerLine 00112 () = 0; 00113 00114 // PLBmp manipulation 00115 00116 //! Applies a filter to the bitmap. 00117 void ApplyFilter 00118 ( const PLFilter& Filter 00119 ); 00120 00121 00122 protected: 00123 //! Can be called from internalCreate() to initialize object state. 00124 virtual void initLocals 00125 ( PLLONG Width, 00126 PLLONG Height, 00127 const PLPixelFormat& pf 00128 ); 00129 00130 //! Create a new bitmap with uninitialized bits. (Assume no memory 00131 //! is allocated yet.) 00132 virtual void internalCreate 00133 ( PLLONG Width, 00134 PLLONG Height, 00135 const PLPixelFormat& pf 00136 ) = 0; 00137 00138 //! Initialize internal table of line addresses. 00139 virtual void initLineArray 00140 () = 0; 00141 00142 //! Delete memory allocated by member variables. 00143 virtual void freeMembers 00144 () = 0; 00145 00146 //! Creates a new PLBmp as copy of rSrcBmp. Assumes there is no memory 00147 //! allocated yet. 00148 void internalCopy 00149 ( const PLBmpBase & rSrcBmp 00150 ); 00151 00152 }; 00153 00154 inline PLBmp & PLBmp::operator= 00155 ( PLBmpBase const &Orig 00156 ) 00157 { 00158 if (this != &Orig) 00159 CreateCopy(Orig); 00160 return *this; 00161 } 00162 00163 inline PLBmp & PLBmp::operator= 00164 ( PLBmp const &Orig 00165 ) 00166 { 00167 if (this != &Orig) 00168 CreateCopy(Orig); 00169 return *this; 00170 } 00171 00172 #endif 00173 /* 00174 /-------------------------------------------------------------------- 00175 | 00176 | $Log: plbitmap_8h-source.html,v $ 00176 | Revision 1.4 2004/09/15 15:26:26 uzadow 00176 | Linux compatibility changes, doc update. 00176 | 00177 | Revision 1.22 2004/09/11 10:30:40 uzadow 00178 | Linux build fixes, automake dependency fixes. 00179 | 00180 | Revision 1.21 2004/09/09 16:52:49 artcom 00181 | refactored PixelFormat 00182 | 00183 | Revision 1.20 2004/06/20 16:59:34 uzadow 00184 | Added PLBmpBase::CopyPixels() and PLInPlaceFilter 00185 | 00186 | Revision 1.19 2004/06/19 17:04:22 uzadow 00187 | Removed Lock(), Unlock(), PLDDrawBmp 00188 | 00189 | Revision 1.18 2004/06/19 16:49:07 uzadow 00190 | Changed GetImage so it works with PLBmpBase 00191 | 00192 | Revision 1.17 2004/06/15 14:17:11 uzadow 00193 | First working version of PLSubBmp. 00194 | 00195 | Revision 1.16 2004/06/15 11:18:17 uzadow 00196 | First working version of PLBmpBase. 00197 | 00198 | Revision 1.15 2004/06/15 10:26:05 uzadow 00199 | Initial nonfunctioning version of plbmpbase. 00200 | 00201 | Revision 1.14 2004/06/10 16:05:28 artcom 00202 | Doc update 00203 | 00204 | Revision 1.13 2004/06/09 21:34:53 uzadow 00205 | Added 16 bpp support to plbitmap, planybmp and pldirectfbbmp 00206 | 00207 | Revision 1.12 2004/06/06 12:56:38 uzadow 00208 | Doxygenified documentation. 00209 | 00210 | Revision 1.11 2003/11/05 15:17:23 artcom 00211 | Added ability to specify initial data in PLBitmap::Create() 00212 | 00213 | Revision 1.10 2003/07/29 21:27:41 uzadow 00214 | Fixed PLDirectFBBmp::GetBytesPerLine(), im2* Makefiles 00215 | 00216 | Revision 1.9 2003/02/15 21:26:58 uzadow 00217 | Added win32 version of url data source. 00218 | 00219 | Revision 1.8 2002/08/04 20:08:01 uzadow 00220 | Added PLBmpInfo class, ability to extract metainformation from images without loading the whole image and proper greyscale support. 00221 | 00222 | Revision 1.7 2002/03/31 13:36:41 uzadow 00223 | Updated copyright. 00224 | 00225 | Revision 1.6 2001/10/21 17:12:39 uzadow 00226 | Added PSD decoder beta, removed BPPWanted from all decoders, added PLFilterPixel. 00227 | 00228 | Revision 1.5 2001/10/16 17:12:26 uzadow 00229 | Added support for resolution information (Luca Piergentili) 00230 | 00231 | Revision 1.4 2001/10/06 22:37:08 uzadow 00232 | Linux compatibility. 00233 | 00234 | Revision 1.3 2001/10/06 22:03:26 uzadow 00235 | Added PL prefix to basic data types. 00236 | 00237 | Revision 1.2 2001/09/28 19:50:56 uzadow 00238 | Added some 24 bpp stuff & other minor features. 00239 | 00240 | Revision 1.1 2001/09/16 19:03:22 uzadow 00241 | Added global name prefix PL, changed most filenames. 00242 | 00243 | Revision 1.26 2001/09/15 14:30:20 uzadow 00244 | Fixed PLPixel32 initialization bug. 00245 | 00246 | Revision 1.25 2001/09/13 20:47:36 uzadow 00247 | Removed commented-out lines. 00248 | 00249 | Revision 1.24 2001/01/15 15:05:31 uzadow 00250 | Added PLBmp::ApplyFilter() and PLBmp::CreateFilteredCopy() 00251 | 00252 | Revision 1.23 2000/12/18 22:42:52 uzadow 00253 | Replaced RGBAPIXEL with PLPixel32. 00254 | 00255 | Revision 1.22 2000/11/21 20:18:03 uzadow 00256 | Added operator == 00257 | 00258 | Revision 1.21 2000/11/07 15:40:46 jmbuena 00259 | Changes related to paintlibdefs.h and pixeldefs.h 00260 | 00261 | Revision 1.20 2000/11/02 21:28:47 uzadow 00262 | Fixed copy constructors. 00263 | 00264 | Revision 1.19 2000/10/24 16:46:34 uzadow 00265 | Fixed build problems 00266 | 00267 | Revision 1.18 2000/10/23 17:45:03 jmbuena 00268 | Linux compatibility changes 00269 | 00270 | Revision 1.17 2000/09/26 14:28:47 Administrator 00271 | Added Threshold filter 00272 | 00273 | Revision 1.16 2000/09/26 12:14:51 Administrator 00274 | Refactored quantization. 00275 | 00276 | Revision 1.15 2000/08/13 12:11:43 Administrator 00277 | Added experimental DirectDraw-Support 00278 | 00279 | Revision 1.14 2000/07/11 17:11:00 Ulrich von Zadow 00280 | Added support for RGBA pixel ordering (Jose Miguel Buenaposada Biencinto). 00281 | 00282 | Revision 1.13 2000/03/31 12:20:05 Ulrich von Zadow 00283 | Video invert filter (beta) 00284 | 00285 | Revision 1.12 2000/03/31 11:53:30 Ulrich von Zadow 00286 | Added quantization support. 00287 | 00288 | Revision 1.11 2000/01/16 20:43:12 anonymous 00289 | Removed MFC dependencies 00290 | 00291 | Revision 1.10 1999/12/10 01:27:26 Ulrich von Zadow 00292 | Added assignment operator and copy constructor to 00293 | bitmap classes. 00294 | 00295 | Revision 1.9 1999/12/09 16:35:22 Ulrich von Zadow 00296 | no message 00297 | 00298 | Revision 1.8 1999/12/08 15:39:45 Ulrich von Zadow 00299 | Unix compatibility changes 00300 | 00301 | Revision 1.7 1999/12/02 17:07:34 Ulrich von Zadow 00302 | Changes by bdelmee. 00303 | 00304 | Revision 1.6 1999/10/22 21:25:51 Ulrich von Zadow 00305 | Removed buggy octree quantization 00306 | 00307 \-------------------------------------------------------------------- 00308 */