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

pldibsect.h

00001 /*
00002 /--------------------------------------------------------------------
00003 |
00004 |      $Id: pldibsect.h,v 1.3 2002/08/04 20:08:01 uzadow Exp $
00005 |
00006 |      Copyright (c) 1996-2002 Ulrich von Zadow
00007 |
00008 \--------------------------------------------------------------------
00009 */
00010 
00011 #ifndef INCL_DIBSECT
00012 #define INCL_DIBSECT
00013 
00014 #ifndef INCL_WINBMP
00015 #include "plwinbmp.h"
00016 #endif
00017 
00018 //! This is a windows DIBSection wrapped in a PLBmp-derived class.
00019 //! It can be used just like a PLWinBmp can be used. In addition,
00020 //! PLDIBSection can give access to the bitmap as a GDI bitmap handle.
00021 //! This bitmap handle can be selected into a device context. All
00022 //! normal GDI drawing functions can be used to write on the bitmap
00023 //! in this way.
00024 //!
00025 //! Internally, PLDIBSections are stored with header and bits in two
00026 //! separate buffers.
00027 class PLDIBSection : public PLWinBmp
00028 {
00029 
00030 public:
00031   //! Creates an empty bitmap.
00032   PLDIBSection
00033     ();
00034 
00035   //! Destroys the bitmap.
00036   virtual ~PLDIBSection
00037     ();
00038 
00039   //! Copy constructor
00040   PLDIBSection
00041     ( const PLBmp &Orig
00042     );
00043 
00044   //! Copy constructor
00045   PLDIBSection
00046     ( const PLDIBSection &Orig
00047     );
00048 
00049   //! Assignment operator.
00050   PLDIBSection &operator=
00051     ( PLBmp const &Orig
00052     );
00053 
00054   //! Assignment operator.
00055   PLDIBSection &operator=
00056     ( PLDIBSection const &Orig
00057     );
00058 
00059 #ifdef _DEBUG
00060   virtual void AssertValid
00061     () const;    // Tests internal object state
00062 #endif
00063 
00064   //! Calling this function causes the windows DIBSection to be detached
00065   //! from the PLDIBSection object. The bitmap data are not deleted in
00066   //! this function. This means that the bitmap handle and
00067   //! the bitmap memory (bits and BMI) must be deleted by some other object.
00068   //! The PLDIBSection object is in the same state as after a constructor
00069   //! call after this function is called.
00070   virtual void Detach
00071     ();
00072 
00073   // PLDIBSection output
00074 
00075   //! Draws the bitmap on the given device context using
00076   //! BitBlt.
00077   virtual void Draw
00078     ( HDC hDC,
00079       int x,
00080       int y,
00081       DWORD rop = SRCCOPY
00082     );
00083 
00084   //! Draws a portion of the bitmap on the given device context
00085   virtual BOOL DrawExtract
00086     ( HDC hDC,
00087       POINT pntDest,
00088       RECT rcSrc
00089     );
00090 
00091   // PLDIBSection member access
00092 
00093   //! Returns a GDI handle to the bitmap. This handle can be selected
00094   //! into a DC and used in normal GDI operations.
00095   //! Under Windows NT, GDI operations can be queued. This means that
00096   //! a program running under NT must call GdiFlush() before the
00097   //! DIBSection can be used again after GetHandle() has been called.
00098   //! See the documentation for GdiFlush() for details.
00099   HBITMAP GetHandle
00100     ();
00101 
00102 
00103 protected:
00104 
00105   // Protected callbacks
00106 
00107   //! Create a new empty DIB. Bits are uninitialized.
00108   //! Assumes that no memory is allocated before the call.
00109   virtual void internalCreate
00110     ( LONG Width,
00111       LONG Height,
00112       WORD BitsPerPixel,
00113       bool bAlphaChannel,
00114       bool bIsGreyscale
00115     );
00116 
00117   // Creates a PLDIBSection from an existing bitmap pointer.
00118   // Assumes that no memory is allocated before the call.
00119   virtual void internalCreate
00120     ( BITMAPINFOHEADER* pBMI
00121     );
00122 
00123   //! Deletes memory allocated by member variables.
00124   virtual void freeMembers
00125     ();
00126 
00127   //! Creates a copy of the current bitmap in a global memory block
00128   //! and returns a handle to this block.
00129   virtual HANDLE createCopyHandle
00130     ();
00131 
00132   //! Set color table pointer & pointer to bits based on m_pBMI.
00133   virtual void initPointers
00134     ();
00135 
00136 
00137 private:
00138   // Local functions
00139 
00140   // Member variables.
00141   HBITMAP  m_hBitmap;
00142 
00143   bool     m_bOwnsBitmap;
00144 };
00145 
00146 // Note that _both_ these copy constructors are needed. If only the 
00147 // second one is there, the compiler generates a default copy 
00148 // constructor anyway :-(.
00149 inline PLDIBSection::PLDIBSection
00150     ( const PLDIBSection &Orig
00151     )
00152 {
00153   // Delete everything the base class allocated.
00154   free(m_pBMI);
00155   m_pBMI = NULL;
00156 
00157   delete [] m_pLineArray;
00158   m_pLineArray = NULL;
00159 
00160   internalCopy (Orig);
00161 }
00162 
00163 inline PLDIBSection::PLDIBSection
00164     ( const PLBmp &Orig
00165     )
00166 {
00167   // Delete everything the base class allocated.
00168   free(m_pBMI);
00169   m_pBMI = NULL;
00170 
00171   delete [] m_pLineArray;
00172   m_pLineArray = NULL;
00173 
00174   internalCopy (Orig);
00175 }
00176 
00177 
00178 inline PLDIBSection & PLDIBSection::operator=
00179     ( PLBmp const &Orig
00180     )
00181 {
00182   PLBmp::operator=(Orig);
00183   return *this;
00184 }
00185 
00186 inline PLDIBSection & PLDIBSection::operator=
00187     ( PLDIBSection const &Orig
00188     )
00189 {
00190   PLBmp::operator=(Orig);
00191   return *this;
00192 }
00193 
00194 
00195 #endif
00196 /*
00197 /--------------------------------------------------------------------
00198 |
00199 |      $Log: pldibsect.h,v $
00200 |      Revision 1.3  2002/08/04 20:08:01  uzadow
00201 |      Added PLBmpInfo class, ability to extract metainformation from images without loading the whole image and proper greyscale support.
00202 |
00203 |      Revision 1.2  2002/03/31 13:36:42  uzadow
00204 |      Updated copyright.
00205 |
00206 |      Revision 1.1  2001/09/16 19:03:23  uzadow
00207 |      Added global name prefix PL, changed most filenames.
00208 |
00209 |      Revision 1.12  2001/01/21 14:28:22  uzadow
00210 |      Changed array cleanup from delete to delete[].
00211 |
00212 |      Revision 1.11  2000/12/09 12:16:26  uzadow
00213 |      Fixed several memory leaks.
00214 |
00215 |      Revision 1.10  2000/11/02 21:28:47  uzadow
00216 |      Fixed copy constructors.
00217 |
00218 |      Revision 1.9  2000/07/19 12:23:15  Ulrich von Zadow
00219 |      Changed HANDLE to HBITMAP.
00220 |
00221 |      Revision 1.8  2000/07/07 13:20:03  Ulrich von Zadow
00222 |      Comments
00223 |
00224 |      Revision 1.7  2000/01/17 23:37:12  Ulrich von Zadow
00225 |      Corrected bug in assignment operator.
00226 |
00227 |      Revision 1.6  2000/01/16 20:43:17  anonymous
00228 |      Removed MFC dependencies
00229 |
00230 |
00231 \--------------------------------------------------------------------
00232 */

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