00001 /* 00002 /-------------------------------------------------------------------- 00003 | 00004 | $Id: plbmpbase_8h-source.html,v 1.2 2004/09/15 15:26:29 uzadow Exp $ 00005 | 00006 | Copyright (c) 1996-2002 Ulrich von Zadow 00007 | 00008 \-------------------------------------------------------------------- 00009 */ 00010 00011 #ifndef INCL_PLBMPBASE 00012 #define INCL_PLBMPBASE 00013 00014 #include "plbmpinfo.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 //! Base class for PLBmp and PLSubBmp. PLBmpBase supports all operations 00024 //! on a bitmap that PLBmp supports except those that depend on being able 00025 //! to change the size or bpp. 00026 class PLBmpBase : public PLBmpInfo 00027 { 00028 00029 public: 00030 00031 //! Empty constructor. 00032 PLBmpBase 00033 (); 00034 00035 //! Empty destructor. 00036 virtual ~PLBmpBase 00037 (); 00038 00039 //! Test for equality. This function actually tests every pixel, so 00040 //! it's not fast. It's meant mainly for use in asserts and such. 00041 bool const operator == 00042 ( PLBmpBase const &Other 00043 ); 00044 00045 #ifdef _DEBUG 00046 virtual void AssertValid 00047 () const; // Tests internal object state 00048 #endif 00049 00050 // PLBmpBase manipulation 00051 00052 //! BitBlts SrcBmp on the current bitmap. Color depth conversion is 00053 //! performed as nessesary. 00054 void CopyPixels 00055 ( const PLBmpBase& SrcBmp 00056 ); 00057 00058 //! Fills the color table with a grayscale palette. This function 00059 //! is only usable for bitmaps containing a color table. Index 0 00060 //! contains black (0) and the last index contains white (255). The 00061 //! alpha channel is set to opaque (255) for every palette entry. 00062 void SetGrayPalette 00063 (); 00064 00065 //! Sets the color table to pPal. The contents of pPal are copied. 00066 void SetPalette 00067 ( PLPixel32 * pPal 00068 ); 00069 00070 //! Sets one entry in the color table. The function may only be 00071 //! called if there is a color table stored with the bitmap. The 00072 //! color table entry is set to the red, green, blue, and alpha 00073 //! values specified. 00074 void SetPaletteEntry 00075 ( PLBYTE Entry, 00076 PLBYTE r, 00077 PLBYTE g, 00078 PLBYTE b, 00079 PLBYTE a 00080 ); 00081 00082 //! Sets one entry in the color table. The function may only be 00083 //! called if there is a color table stored with the bitmap. The 00084 //! color table entry is set to the red, green, blue, and alpha 00085 //! values specified. 00086 void SetPaletteEntry 00087 ( PLBYTE Entry, 00088 PLPixel32 Value 00089 ); 00090 00091 //! Sets whether a bitmap stores an alpha channel. Works for 8 and 32 bpp 00092 //! bitmaps. In either case, if b is true and the bitmap did not have an 00093 //! alpha channel before the call, the complete alpha channel is set to 00094 //! opaque by the call. 00095 void SetHasAlpha 00096 (bool b 00097 ); 00098 00099 //! Replaces the alpha channel of the bitmap with a new one. This 00100 //! only works for bitmaps with 32 bpp. pAlphaBmp must point to an 00101 //! 8 bpp bitmap with the same dimensions as the object. The alpha 00102 //! channel information is physically copied into the bitmap. 00103 void SetAlphaChannel 00104 ( PLBmpBase * pAlphaBmp 00105 ); 00106 00107 //! Slow but simple function to set a single pixel. 32 bpp only. 00108 void SetPixel 00109 ( int x, 00110 int y, 00111 PLPixel32 pixel 00112 ); 00113 00114 //! Slow but simple function to get a single pixel. 32 bpp only. 00115 PLPixel32 GetPixel 00116 ( int x, 00117 int y 00118 ) const; 00119 00120 //! Find the nearest color to cr in the palette used by this bitmap 00121 //! Only works for 8 bpp bitmaps. 00122 PLBYTE FindNearestColor 00123 ( PLPixel32 cr 00124 ); 00125 00126 // PLBmpBase information. 00127 00128 //! Returns number of colors that can be stored by a bitmap with this 00129 //! color depth. 00130 int GetNumColors 00131 (); 00132 00133 // PLBmpBase direct manipulation 00134 00135 //! Returns the address of the color table of the bitmap or NULL if 00136 //! no color table exists. The color table is stored as an array of 00137 //! consecutive PLPixel32 objects. 00138 PLPixel32 * GetPalette 00139 () const; 00140 00141 //! Returns pointer to an array containing the starting addresses of 00142 //! the bitmap lines. This array should be used whenever the bitmap 00143 //! bits need to be manipulated directly. 00144 PLBYTE ** GetLineArray 00145 () const; 00146 00147 //! Returns pointer to an array containing the starting addresses of 00148 //! the bitmap lines. This array should be used whenever the bitmap 00149 //! bits need to be manipulated directly. 00150 PLPixel32 ** GetLineArray32 00151 () const; 00152 00153 //! Returns pointer to an array containing the starting addresses of 00154 //! the bitmap lines. This array should be used whenever the bitmap 00155 //! bits need to be manipulated directly. 00156 PLPixel24 ** GetLineArray24 00157 () const; 00158 00159 //! Returns pointer to an array containing the starting addresses of 00160 //! the bitmap lines. This array should be used whenever the bitmap 00161 //! bits need to be manipulated directly. 00162 PLPixel16 ** GetLineArray16 00163 () const; 00164 00165 //! Returns true if Bmp and this are almost equal. The comparison is done by 00166 //! comparing the pixels in the bitmaps component-wise. If all components are 00167 //! closer than epsilon, the bitmaps are considered almost equal. 00168 bool AlmostEqual 00169 ( const PLBmpBase& Bmp, 00170 int epsilon 00171 ) const; 00172 00173 //! Sets the bitmap resolution in pixels per inch. 00174 void SetResolution (const PLPoint& Resolution); 00175 00176 //! Sets quality of conversion to 8 bpp by CreateCopy(). Valid parameters are 00177 //! defined in FilterQuantize.h. 00178 void SetQuantizationMode 00179 ( int DitherType, 00180 int DitherPaletteType 00181 ); 00182 00183 protected: 00184 //! Can be called from internalCreate() to initialize object state. 00185 virtual void initLocals 00186 ( PLLONG Width, 00187 PLLONG Height, 00188 const PLPixelFormat & pf 00189 ); 00190 00191 void create8BPPCopy 00192 ( const PLBmpBase & rSrcBmp 00193 ); 00194 00195 void create1BPPCopy 00196 ( const PLBmpBase & rSrcBmp 00197 ); 00198 00199 // Member variables 00200 PLPixel32 * m_pClrTab; // Pointer to the color table. 00201 PLBYTE ** m_pLineArray; // Table of the starting addresses of 00202 // the lines. 00203 00204 int m_DitherType; 00205 int m_DitherPaletteType; 00206 }; 00207 00208 inline void PLBmpBase::SetPaletteEntry 00209 ( PLBYTE Entry, 00210 PLBYTE r, 00211 PLBYTE g, 00212 PLBYTE b, 00213 PLBYTE a 00214 ) 00215 { 00216 m_pClrTab[Entry].Set (r, g, b, a); 00217 } 00218 00219 inline void PLBmpBase::SetPaletteEntry 00220 ( PLBYTE Entry, 00221 PLPixel32 Value 00222 ) 00223 { 00224 m_pClrTab[Entry] = Value; 00225 } 00226 00227 00228 inline PLPixel32 PLBmpBase::GetPixel (int x, int y) const 00229 { 00230 PLASSERT (GetBitsPerPixel() == 32); 00231 return *((PLPixel32 *)GetLineArray()[y]+x); 00232 } 00233 00234 inline void PLBmpBase::SetPixel (int x, int y, PLPixel32 pixel) 00235 { 00236 PLASSERT (GetBitsPerPixel() == 32); 00237 *(GetLineArray32()[y]+x) = pixel; 00238 } 00239 00240 inline void PLBmpBase::SetResolution(const PLPoint& Resolution) 00241 { 00242 PLASSERT_VALID(this); 00243 m_Resolution = Resolution; 00244 } 00245 00246 inline int PLBmpBase::GetNumColors 00247 () 00248 { 00249 PLASSERT_VALID (this); 00250 return m_pf.GetNumColors(); 00251 } 00252 00253 00254 // PLBmpBase direct manipulation 00255 00256 inline PLBYTE ** PLBmpBase::GetLineArray 00257 () const 00258 { 00259 PLASSERT (m_pLineArray); 00260 return m_pLineArray; 00261 } 00262 00263 inline PLPixel32 ** PLBmpBase::GetLineArray32 00264 () const 00265 { 00266 PLASSERT (m_pLineArray); 00267 PLASSERT (GetBitsPerPixel() == 32); 00268 return (PLPixel32**)m_pLineArray; 00269 } 00270 00271 inline PLPixel24 ** PLBmpBase::GetLineArray24 00272 () const 00273 { 00274 PLASSERT (m_pLineArray); 00275 PLASSERT (GetBitsPerPixel() == 24); 00276 return (PLPixel24**)m_pLineArray; 00277 } 00278 00279 inline PLPixel16 ** PLBmpBase::GetLineArray16 00280 () const 00281 { 00282 PLASSERT (m_pLineArray); 00283 PLASSERT (GetBitsPerPixel() == 16); 00284 return (PLPixel16**)m_pLineArray; 00285 } 00286 00287 inline PLPixel32 * PLBmpBase::GetPalette 00288 () const 00289 // Returns adress of the color table of the bitmap or NULL if no 00290 // color table exists. 00291 { 00292 PLASSERT_VALID (this); 00293 00294 return m_pClrTab; 00295 } 00296 00297 #endif 00298 /* 00299 /-------------------------------------------------------------------- 00300 | 00301 | $Log: plbmpbase_8h-source.html,v $ 00301 | Revision 1.2 2004/09/15 15:26:29 uzadow 00301 | Linux compatibility changes, doc update. 00301 | 00302 | Revision 1.6 2004/09/09 16:52:49 artcom 00303 | refactored PixelFormat 00304 | 00305 | Revision 1.5 2004/06/20 16:59:34 uzadow 00306 | Added PLBmpBase::CopyPixels() and PLInPlaceFilter 00307 | 00308 | Revision 1.4 2004/06/19 17:34:27 uzadow 00309 | Documentation update 00310 | 00311 | Revision 1.3 2004/06/19 16:49:07 uzadow 00312 | Changed GetImage so it works with PLBmpBase 00313 | 00314 | Revision 1.2 2004/06/15 14:17:11 uzadow 00315 | First working version of PLSubBmp. 00316 | 00317 | Revision 1.1 2004/06/15 10:46:41 uzadow 00318 | Initial nonfunctioning version of plbmpbase. 00319 | 00320 | 00321 \-------------------------------------------------------------------- 00322 */