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

pldibsect.h

00001 /*
00002 /--------------------------------------------------------------------
00003 |
00004 |      $Id: pldibsect_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_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 PLBmpBase &Orig
00042     );
00043 
00044   //! Copy constructor
00045   PLDIBSection
00046     ( const PLDIBSection &Orig
00047     );
00048 
00049   //! Assignment operator.
00050   PLDIBSection &operator=
00051     ( PLBmpBase 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       const PLPixelFormat& pf
00113     );
00114 
00115   // Creates a PLDIBSection from an existing bitmap pointer.
00116   // Assumes that no memory is allocated before the call.
00117   virtual void internalCreate
00118     ( BITMAPINFOHEADER* pBMI
00119     );
00120 
00121   //! Deletes memory allocated by member variables.
00122   virtual void freeMembers
00123     ();
00124 
00125   //! Creates a copy of the current bitmap in a global memory block
00126   //! and returns a handle to this block.
00127   virtual HANDLE createCopyHandle
00128     ();
00129 
00130   //! Set color table pointer & pointer to bits based on m_pBMI.
00131   virtual void initPointers
00132     ();
00133 
00134 
00135 private:
00136   // Local functions
00137 
00138   // Member variables.
00139   HBITMAP  m_hBitmap;
00140 
00141   bool     m_bOwnsBitmap;
00142 };
00143 
00144 // Note that _both_ these copy constructors are needed. If only the 
00145 // second one is there, the compiler generates a default copy 
00146 // constructor anyway :-(.
00147 inline PLDIBSection::PLDIBSection
00148     ( const PLDIBSection &Orig
00149     )
00150 {
00151   // Delete everything the base class allocated.
00152   free(m_pBMI);
00153   m_pBMI = NULL;
00154 
00155   delete [] m_pLineArray;
00156   m_pLineArray = NULL;
00157 
00158   internalCopy (Orig);
00159 }
00160 
00161 inline PLDIBSection::PLDIBSection
00162     ( const PLBmpBase &Orig
00163     )
00164 {
00165   // Delete everything the base class allocated.
00166   free(m_pBMI);
00167   m_pBMI = NULL;
00168 
00169   delete [] m_pLineArray;
00170   m_pLineArray = NULL;
00171 
00172   internalCopy (Orig);
00173 }
00174 
00175 
00176 inline PLDIBSection & PLDIBSection::operator=
00177     ( PLBmpBase const &Orig
00178     )
00179 {
00180   PLBmp::operator=(Orig);
00181   return *this;
00182 }
00183 
00184 inline PLDIBSection & PLDIBSection::operator=
00185     ( PLDIBSection const &Orig
00186     )
00187 {
00188   PLBmp::operator=(Orig);
00189   return *this;
00190 }
00191 
00192 
00193 #endif
00194 /*
00195 /--------------------------------------------------------------------
00196 |
00197 |      $Log: pldibsect_8h-source.html,v $
00197 |      Revision 1.2  2004/09/15 15:26:29  uzadow
00197 |      Linux compatibility changes, doc update.
00197 |
00198 |      Revision 1.5  2004/09/09 16:52:50  artcom
00199 |      refactored PixelFormat
00200 |
00201 |      Revision 1.4  2004/06/15 14:17:25  uzadow
00202 |      First working version of PLSubBmp.
00203 |
00204 |      Revision 1.3  2002/08/04 20:08:01  uzadow
00205 |      Added PLBmpInfo class, ability to extract metainformation from images without loading the whole image and proper greyscale support.
00206 |
00207 |      Revision 1.2  2002/03/31 13:36:42  uzadow
00208 |      Updated copyright.
00209 |
00210 |      Revision 1.1  2001/09/16 19:03:23  uzadow
00211 |      Added global name prefix PL, changed most filenames.
00212 |
00213 |      Revision 1.12  2001/01/21 14:28:22  uzadow
00214 |      Changed array cleanup from delete to delete[].
00215 |
00216 |      Revision 1.11  2000/12/09 12:16:26  uzadow
00217 |      Fixed several memory leaks.
00218 |
00219 |      Revision 1.10  2000/11/02 21:28:47  uzadow
00220 |      Fixed copy constructors.
00221 |
00222 |      Revision 1.9  2000/07/19 12:23:15  Ulrich von Zadow
00223 |      Changed HANDLE to HBITMAP.
00224 |
00225 |      Revision 1.8  2000/07/07 13:20:03  Ulrich von Zadow
00226 |      Comments
00227 |
00228 |      Revision 1.7  2000/01/17 23:37:12  Ulrich von Zadow
00229 |      Corrected bug in assignment operator.
00230 |
00231 |      Revision 1.6  2000/01/16 20:43:17  anonymous
00232 |      Removed MFC dependencies
00233 |
00234 |
00235 \--------------------------------------------------------------------
00236 */

Generated on Mon Sep 13 16:16:40 2004 for paintlib by doxygen 1.3.2