00001 /* 00002 /-------------------------------------------------------------------- 00003 | 00004 | $Id: plwinbmp_8h-source.html,v 1.2 2004/09/15 15:26:32 uzadow Exp $ 00005 | 00006 | Copyright (c) 1996-1998 Ulrich von Zadow 00007 | 00008 \-------------------------------------------------------------------- 00009 */ 00010 00011 #ifndef INCL_WINBMP 00012 #define INCL_WINBMP 00013 00014 #ifndef INCL_PLBITMAP 00015 #include "plbitmap.h" 00016 #endif 00017 00018 #ifdef _WINDOWS 00019 #define WIN32_LEAN_AND_MEAN /* Prevent including <winsock*.h> in <windows.h> */ 00020 #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers 00021 #include <windows.h> 00022 #endif 00023 00024 //! This is the windows version of PLBmp. The internal storage format 00025 //! is a windows DIB. It supports all color depths allowed by 00026 //! windows: 1, 8, 16, 24, and 32 bpp. 00027 //! 00028 //! The subset of the windows DIB format supported is as follows: The 00029 //! DIB is stored so that header, palette, and bits are in one 00030 //! buffer. The bottom line is stored first (biHeight must be > 0) 00031 //! and the data is uncompressed (BI_RGB). Color tables for 16, 24, 00032 //! and 32 bpp are not supported. biClrUsed is always 0. The palette 00033 //! mode is DIB_RGB_COLORS. DIB_PAL_COLORS is not supported. 00034 //! 00035 //! Note that almost all real-life DIBs conform to this subset 00036 //! anyway, so there shouldn't be any problems. 00037 //! 00038 //! <i>In the current version, some functions (notably CreateCopy) only 00039 //! support 1, 8 and 32 bpp. Sorry!</i> 00040 class PLWinBmp : public PLBmp 00041 { 00042 00043 public: 00044 // Creates an empty bitmap. 00045 PLWinBmp (); 00046 00047 //! Copy constructor 00048 PLWinBmp 00049 ( const PLWinBmp &Orig 00050 ); 00051 00052 //! Copy constructor 00053 PLWinBmp 00054 ( const PLBmpBase &Orig 00055 ); 00056 00057 //! Destroys the bitmap. 00058 virtual ~PLWinBmp (); 00059 00060 //! Assignment operator. 00061 PLWinBmp &operator= (PLBmpBase const &Orig); 00062 00063 //! Assignment operator. 00064 PLWinBmp &operator= (PLWinBmp const &Orig); 00065 00066 #ifdef _DEBUG 00067 virtual void AssertValid () const; // Tests internal object state 00068 #endif 00069 00070 // PLWinBmp manipulation 00071 00072 // Do a bitblt using the alpha channel of pSrPLBmp. Restricted to 00073 // 32 bpp. 00074 // Legacy routine. Use the Blt classes instead. 00075 void AlphaBlt (PLWinBmp * pSrPLBmp, int x, int y); 00076 00077 // PLWinBmp information 00078 00079 //! Returns the amount of memory used by the object. 00080 virtual long GetMemUsed (); 00081 00082 //! Returns number of bytes used per line. 00083 virtual long GetBytesPerLine (); 00084 00085 // Windows-specific interface 00086 00087 //! Loads a bitmap from a windows resource (.rc or .res linked to 00088 //! the exe). Fails if the bitmap is compressed. 00089 virtual void CreateRes (HINSTANCE lh_ResInst, int ID); 00090 00091 //! Takes a HBITMAP and converts it to a PLWinBmp. 00092 void CreateFromHBitmap (HBITMAP hBitMap); 00093 00094 //! Takes an existing device-independent bitmap and converts it 00095 //! to a PLWinBmp. 00096 void CreateFromHDIBBitmap(BITMAPINFOHEADER* pBIH, HPALETTE hPal = NULL); 00097 00098 //! Returns the size of the bitmap in pixels 00099 SIZE GetSize (); 00100 00101 //! Access the windows bitmap structure. Using this structure, all 00102 //! standard DIB manipulations can be performed. 00103 BITMAPINFOHEADER * GetBMI (); 00104 00105 // PLWinBmp output 00106 00107 //! Draws the bitmap on the given device context using 00108 //! StretchDIBits. 00109 virtual void Draw (HDC hDC, int x, int y, DWORD rop = SRCCOPY); 00110 00111 //! Draws the bitmap on the given device context using 00112 //! StretchDIBits. Scales the bitmap by Factor. 00113 virtual void StretchDraw (HDC hDC, int x, int y, double Factor, DWORD rop = SRCCOPY); 00114 00115 //! Draws the bitmap on the given device context using 00116 //! StretchDIBits. Scales the bitmap so w is the width and 00117 //! h the height. 00118 virtual void StretchDraw (HDC hDC, int x, int y, int w, int h, DWORD rop = SRCCOPY); 00119 00120 //! Draws a portion of the bitmap on the given device context 00121 virtual BOOL DrawExtract (HDC hDC, POINT pntDest, RECT rcSrc); 00122 00123 //! Puts a copy of the bitmap in the clipboard 00124 void ToClipboard (); 00125 00126 //! Reads the clipboard into the bitmap. uFormat can be either 00127 //! CF_BITMAP or CF_DIB. 00128 bool FromClipboard (UINT uFormat = CF_BITMAP); 00129 00130 //! Gets a pointer to the bitmap bits. (Usually, using GetLineArray() 00131 //! is much easier!) 00132 BYTE * GetBits (); 00133 00134 //! Copies the palette over from pSrPLBmp. 00135 void CopyPalette (PLWinBmp * pSrPLBmp); 00136 00137 //! Traces the values in the palette via PLTRACE(); 00138 void TracePalette(); 00139 00140 // Static functions 00141 00142 //! Returns memory needed by a bitmap with the specified attributes. 00143 static long GetMemNeeded (LONG width, LONG height, WORD BitsPerPixel); 00144 00145 //! Returns memory needed by bitmap bits. 00146 static long GetBitsMemNeeded (LONG width, LONG height, WORD BitsPerPixel); 00147 00148 //! Returns memory needed by one line. 00149 static int GetLineMemNeeded (LONG width, WORD BitsPerPixel); 00150 00151 protected: 00152 00153 // Protected callbacks 00154 00155 //! Create a new empty DIB. Bits are uninitialized. 00156 //! Assumes that no memory is allocated before the call. 00157 virtual void internalCreate (LONG Width, LONG Height, 00158 const PLPixelFormat& pf); 00159 00160 //! Creates a PLWinBmp from an existing bitmap pointer. 00161 //! Assumes that no memory is allocated before the call. 00162 virtual void internalCreate (BITMAPINFOHEADER* pBMI); 00163 00164 //! Deletes memory allocated by member variables. 00165 virtual void freeMembers (); 00166 00167 //! Initializes internal table of line addresses. 00168 virtual void initLineArray (); 00169 00170 // Creates a copy of the current bitmap in a global memory block 00171 // and returns a handle to this block. 00172 virtual HANDLE createCopyHandle (); 00173 00174 // Set color table pointer & pointer to bits based on m_pBMI. 00175 virtual void initPointers (); 00176 00177 const PLPixelFormat& pixelFormatFromBMI(const BITMAPINFOHEADER * pBMI) const; 00178 00179 // Member variables. 00180 00181 BITMAPINFOHEADER * m_pBMI; // Pointer to picture format information. 00182 BYTE * m_pBits; 00183 00184 00185 private: 00186 }; 00187 00188 00189 // Note that _both_ these copy constructors are needed. If only the 00190 // second one is there, the compiler generates a default copy 00191 // constructor anyway :-(. 00192 inline PLWinBmp::PLWinBmp 00193 ( const PLWinBmp &Orig 00194 ) 00195 : PLBmp () 00196 { 00197 internalCopy (Orig); 00198 } 00199 00200 inline PLWinBmp::PLWinBmp 00201 ( const PLBmpBase &Orig 00202 ) 00203 : PLBmp () 00204 { 00205 internalCopy (Orig); 00206 } 00207 00208 inline PLWinBmp & PLWinBmp::operator= ( PLBmpBase const &Orig) 00209 { 00210 PLBmp::operator=(Orig); 00211 return *this; 00212 } 00213 00214 inline PLWinBmp & PLWinBmp::operator= ( PLWinBmp const &Orig) 00215 { 00216 PLBmp::operator=(Orig); 00217 return *this; 00218 } 00219 00220 00221 #endif 00222 /* 00223 /-------------------------------------------------------------------- 00224 | 00225 | $Log: plwinbmp_8h-source.html,v $ 00225 | Revision 1.2 2004/09/15 15:26:32 uzadow 00225 | Linux compatibility changes, doc update. 00225 | 00226 | Revision 1.6 2004/09/11 14:15:40 uzadow 00227 | Comitted testimages, resized most of them. 00228 | 00229 | Revision 1.5 2004/09/09 16:52:50 artcom 00230 | refactored PixelFormat 00231 | 00232 | Revision 1.4 2004/06/15 14:17:25 uzadow 00233 | First working version of PLSubBmp. 00234 | 00235 | Revision 1.3 2003/08/03 12:03:22 uzadow 00236 | Added unicode support; fixed some header includes. 00237 | 00238 | Revision 1.2 2002/08/04 20:08:01 uzadow 00239 | Added PLBmpInfo class, ability to extract metainformation from images without loading the whole image and proper greyscale support. 00240 | 00241 | Revision 1.1 2001/09/16 19:03:23 uzadow 00242 | Added global name prefix PL, changed most filenames. 00243 | 00244 | Revision 1.14 2001/01/14 13:36:15 uzadow 00245 | Added PLAnyPicDecoder::GetFileFormat() 00246 | 00247 | Revision 1.13 2000/11/21 20:29:39 uzadow 00248 | Added test project. 00249 | 00250 | Revision 1.12 2000/11/02 21:28:47 uzadow 00251 | Fixed copy constructors. 00252 | 00253 | Revision 1.11 2000/10/12 21:59:34 uzadow 00254 | Added CreateFromHDIBBitmap() and CopyPalette() to PLWinBmp 00255 | Added CF_DIB support to PLWinBmp::FromClipboard() (Richard Hollis) 00256 | 00257 | Revision 1.10 2000/09/01 14:13:49 Administrator 00258 | Removed MFC from paintX, added MSCV paintX sample. 00259 | 00260 | Revision 1.9 2000/08/13 12:11:43 Administrator 00261 | Added experimental DirectDraw-Support 00262 | 00263 | Revision 1.8 2000/01/17 23:37:12 Ulrich von Zadow 00264 | Corrected bug in assignment operator. 00265 | 00266 | Revision 1.7 2000/01/16 20:43:18 anonymous 00267 | Removed MFC dependencies 00268 | 00269 | Revision 1.6 2000/01/10 23:53:01 Ulrich von Zadow 00270 | Changed formatting & removed tabs. 00271 | 00272 \-------------------------------------------------------------------- 00273 */