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

plwinbmp.h

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

Generated on Sun Jun 6 13:42:22 2004 for paintlib by doxygen 1.3.2