Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

plbitmap.h

Go to the documentation of this file.
00001 /*
00002 /--------------------------------------------------------------------
00003 |
00004 |      $Id: plbitmap.h,v 1.1 2004/05/21 21:02:52 maxx Exp $
00005 |
00006 |      Copyright (c) 1996-1998 Ulrich von Zadow
00007 |
00008 \--------------------------------------------------------------------
00009 */
00010 
00011 #ifndef INCL_PLBITMAP
00012 #define INCL_PLBITMAP
00013 
00014 #include "plobject.h"
00015 #include "plpoint.h"
00016 #include "pldebug.h"
00017 #include "plpixel32.h"
00018 #include "plpixel24.h"
00019 
00020 class PLFilter;
00021 
00039 class PLBmp : public PLObject
00040 {
00041 
00042 public:
00043 
00047   PLBmp
00048     ();
00049 
00051   virtual ~PLBmp
00052     ();
00053 
00056   PLBmp &operator=
00057     ( PLBmp const &Orig
00058     );
00059 
00062   bool const operator ==
00063     ( PLBmp const &Other
00064     );
00065 
00066 #ifdef _DEBUG
00067   virtual void AssertValid
00068     () const;    // Tests internal object state
00069 #endif
00070 
00071   // PLBmp creation
00072 
00077   virtual void Create
00078     ( PLLONG Width,
00079       PLLONG Height,
00080       PLWORD BitsPerPixel,
00081       bool bAlphaChannel,
00082       const PLPoint& Resolution = PLPoint (0,0)
00083     );
00084 
00087   void CreateCopy
00088     ( const PLBmp & rSrPLBmp,
00089       int BPPWanted = 0
00090     );
00091 
00095   void CreateFilteredCopy (PLBmp & rSrPLBmp, const PLFilter & rFilter);
00096 
00097   // PLBmp manipulation
00098 
00101   void SetQuantizationMode
00102     ( int DitherType,
00103       int DitherPaletteType
00104     );
00105 
00110   void SetGrayPalette
00111     ();
00112 
00114   void SetPalette
00115     ( PLPixel32 * pPal
00116     );
00117 
00122   void SetPaletteEntry
00123     ( PLBYTE Entry,
00124       PLBYTE r,
00125       PLBYTE g,
00126       PLBYTE b,
00127       PLBYTE a
00128     );
00129 
00134   void SetPaletteEntry
00135     ( PLBYTE Entry,
00136       PLPixel32 Value
00137     );
00138 
00143   void SetAlphaChannel
00144     ( PLBmp * pAlphaBmp
00145     );
00146 
00148   void ApplyFilter
00149     ( const PLFilter& Filter
00150     );
00151 
00153   void SetPixel
00154     ( int x,
00155       int y,
00156       PLPixel32 pixel
00157     );
00158 
00160   PLPixel32 GetPixel
00161     ( int x,
00162       int y
00163     ) const;
00164 
00167   PLBYTE FindNearestColor
00168     ( PLPixel32 cr
00169     );
00170 
00171   // PLBmp information.
00172 
00174   int GetWidth
00175     () const;
00176 
00178   int GetHeight
00179     () const;
00180 
00182   virtual long GetMemUsed
00183     () = 0;
00184 
00186   int GetNumColors
00187     ();
00188 
00190   int GetBitsPerPixel
00191     () const;
00192 
00194   bool HasAlpha
00195     () const;
00196 
00198   void SetHasAlpha
00199     (bool b
00200     );
00201 
00203   virtual long GetBytesPerLine
00204     () = 0;
00205 
00206   // PLBmp direct manipulation
00207 
00211   PLPixel32 * GetPalette
00212     () const;
00213 
00217   PLBYTE ** GetLineArray
00218     () const;
00219 
00223   PLPixel32 ** GetLineArray32
00224     () const;
00225 
00229   PLPixel24 ** GetLineArray24
00230     () const;
00231 
00236   virtual void Lock
00237     ( bool bReadable,
00238       bool bWriteable
00239     );
00240 
00242   virtual void Unlock
00243     ();
00244 
00245   bool IsLocked
00246     () const;
00247 
00248   bool AlmostEqual
00249     ( const PLBmp& Bmp,
00250       int epsilon
00251     ) const;
00252 
00255   const PLPoint& GetResolution () const;
00256 
00258   void SetResolution (const PLPoint& Resolution);
00259 
00260 protected:
00261 
00262 
00265   virtual void internalCreate
00266     ( PLLONG Width,
00267       PLLONG Height,
00268       PLWORD BitsPerPixel,
00269       bool bAlphaChannel
00270     ) = 0;
00271 
00273   virtual void freeMembers
00274     () = 0;
00275 
00277   virtual void initLineArray
00278     () = 0;
00279 
00282   void internalCopy
00283     ( const PLBmp & rSrPLBmp
00284     );
00285 
00287   void initLocals
00288     ( PLLONG Width,
00289       PLLONG Height,
00290       PLWORD BitsPerPixel,
00291       bool bAlphaChannel
00292     );
00293 
00294   void create8BPPCopy
00295     ( const PLBmp & rSrPLBmp
00296     );
00297 
00298   void create1BPPCopy
00299     ( const PLBmp & rSrPLBmp
00300     );
00301 
00302   // Member variables
00303 
00304   int m_Width;
00305   int m_Height;
00306   PLWORD m_bpp;
00307   PLPoint m_Resolution;
00308 
00309   PLPixel32 * m_pClrTab;      // Pointer to the color table.
00310   bool       m_bAlphaChannel;
00311   PLBYTE    ** m_pLineArray;   // Table of the starting addresses of
00312                              // the lines.
00313   int        m_LockCount;    // Number of times the bitmap was locked.
00314                              // Default is m_LockCount always >= 1, so
00315                              // access to bits is always possible.
00316   int m_DitherType;
00317   int m_DitherPaletteType;
00318 
00319 };
00320 
00321 inline PLBmp & PLBmp::operator=
00322     ( PLBmp const &Orig
00323     )
00324 {
00325   if (this != &Orig)
00326     CreateCopy(Orig);
00327   return *this;
00328 }
00329 
00330 inline void PLBmp::SetPaletteEntry
00331     ( PLBYTE Entry,
00332       PLBYTE r,
00333       PLBYTE g,
00334       PLBYTE b,
00335       PLBYTE a
00336     )
00337 {
00338   m_pClrTab[Entry].Set (r, g, b, a);
00339 }
00340 
00341 inline void PLBmp::SetPaletteEntry
00342     ( PLBYTE Entry,
00343       PLPixel32 Value
00344     )
00345 {
00346   m_pClrTab[Entry] = Value;
00347 }
00348 
00349 
00350 inline PLPixel32 PLBmp::GetPixel (int x, int y) const
00351 {
00352   PLASSERT (GetBitsPerPixel() == 32);
00353   return *((PLPixel32 *)GetLineArray()[y]+x);
00354 }
00355 
00356 inline void PLBmp::SetPixel (int x, int y, PLPixel32 pixel)
00357 {
00358   PLASSERT (GetBitsPerPixel() == 32);
00359   *(GetLineArray32()[y]+x) = pixel;
00360 }
00361 
00362 // PLBmp information
00363 
00364 inline int PLBmp::GetWidth
00365     () const
00366 {
00367   PLASSERT_VALID (this);
00368 
00369   return m_Width;
00370 
00371 }
00372 
00373 
00374 inline int PLBmp::GetHeight
00375     () const
00376 {
00377   PLASSERT_VALID (this);
00378 
00379   return m_Height;
00380 }
00381 
00382 
00383 inline const PLPoint& PLBmp::GetResolution () const
00384 {
00385   PLASSERT_VALID(this);
00386   return m_Resolution;
00387 }
00388 
00389 inline void PLBmp::SetResolution(const PLPoint& Resolution)
00390 {
00391   PLASSERT_VALID(this);
00392   m_Resolution = Resolution;
00393 }
00394 
00395 inline int PLBmp::GetNumColors
00396     ()
00397 {
00398   PLASSERT_VALID (this);
00399 
00400   if (m_bpp == 32)
00401     return 1 << 24;
00402    else
00403     return 1 << m_bpp;
00404 }
00405 
00406 
00407 inline int PLBmp::GetBitsPerPixel
00408     () const
00409 {
00410   PLASSERT_VALID (this);
00411 
00412   return m_bpp;
00413 }
00414 
00415 
00416 inline bool PLBmp::HasAlpha
00417     () const
00418 {
00419   PLASSERT_VALID (this);
00420 
00421   return m_bAlphaChannel;
00422 }
00423 
00424 
00425 inline void PLBmp::SetHasAlpha
00426     (bool b
00427     )
00428 {
00429   PLASSERT_VALID (this);
00430   m_bAlphaChannel = b;
00431 }
00432 
00433 // PLBmp direct manipulation
00434 
00435 
00436 inline PLBYTE ** PLBmp::GetLineArray
00437     () const
00438 {
00439   PLASSERT (m_pLineArray);
00440   return m_pLineArray;
00441 }
00442 
00443 inline PLPixel32 ** PLBmp::GetLineArray32
00444     () const
00445 {
00446   PLASSERT (m_pLineArray);
00447   PLASSERT (m_bpp == 32);
00448   return (PLPixel32**)m_pLineArray;
00449 }
00450 
00451 inline PLPixel24 ** PLBmp::GetLineArray24
00452     () const
00453 {
00454   PLASSERT (m_pLineArray);
00455   PLASSERT (m_bpp == 24);
00456   return (PLPixel24**)m_pLineArray;
00457 }
00458 
00459 inline PLPixel32 * PLBmp::GetPalette
00460     () const
00461     // Returns adress of the color table of the bitmap or NULL if no
00462     // color table exists.
00463 {
00464   PLASSERT_VALID (this);
00465 
00466   return m_pClrTab;
00467 }
00468 
00469 inline bool PLBmp::IsLocked
00470     () const
00471 {
00472   return (m_LockCount >= 1);
00473 }
00474 
00475 
00476 #endif
00477 /*
00478 /--------------------------------------------------------------------
00479 |
00480 |      $Log: plbitmap.h,v $
00481 |      Revision 1.1  2004/05/21 21:02:52  maxx
00482 |      Initial Version of vuVolume, moderatly changed to make it compile on my windows and linux machine.
00483 |
00484 |      Revision 1.1  2002/11/13 01:58:20  mspindle
00485 |      *** empty log message ***
00486 |
00487 |      Revision 1.6  2001/10/21 17:12:39  uzadow
00488 |      Added PSD decoder beta, removed BPPWanted from all decoders, added PLFilterPixel.
00489 |
00490 |      Revision 1.5  2001/10/16 17:12:26  uzadow
00491 |      Added support for resolution information (Luca Piergentili)
00492 |
00493 |      Revision 1.4  2001/10/06 22:37:08  uzadow
00494 |      Linux compatibility.
00495 |
00496 |      Revision 1.3  2001/10/06 22:03:26  uzadow
00497 |      Added PL prefix to basic data types.
00498 |
00499 |      Revision 1.2  2001/09/28 19:50:56  uzadow
00500 |      Added some 24 bpp stuff & other minor features.
00501 |
00502 |      Revision 1.1  2001/09/16 19:03:22  uzadow
00503 |      Added global name prefix PL, changed most filenames.
00504 |
00505 |      Revision 1.26  2001/09/15 14:30:20  uzadow
00506 |      Fixed PLPixel32 initialization bug.
00507 |
00508 |      Revision 1.25  2001/09/13 20:47:36  uzadow
00509 |      Removed commented-out lines.
00510 |
00511 |      Revision 1.24  2001/01/15 15:05:31  uzadow
00512 |      Added PLBmp::ApplyFilter() and PLBmp::CreateFilteredCopy()
00513 |
00514 |      Revision 1.23  2000/12/18 22:42:52  uzadow
00515 |      Replaced RGBAPIXEL with PLPixel32.
00516 |
00517 |      Revision 1.22  2000/11/21 20:18:03  uzadow
00518 |      Added operator ==
00519 |
00520 |      Revision 1.21  2000/11/07 15:40:46  jmbuena
00521 |      Changes related to paintlibdefs.h and pixeldefs.h
00522 |
00523 |      Revision 1.20  2000/11/02 21:28:47  uzadow
00524 |      Fixed copy constructors.
00525 |
00526 |      Revision 1.19  2000/10/24 16:46:34  uzadow
00527 |      Fixed build problems
00528 |
00529 |      Revision 1.18  2000/10/23 17:45:03  jmbuena
00530 |      Linux compatibility changes
00531 |
00532 |      Revision 1.17  2000/09/26 14:28:47  Administrator
00533 |      Added Threshold filter
00534 |
00535 |      Revision 1.16  2000/09/26 12:14:51  Administrator
00536 |      Refactored quantization.
00537 |
00538 |      Revision 1.15  2000/08/13 12:11:43  Administrator
00539 |      Added experimental DirectDraw-Support
00540 |
00541 |      Revision 1.14  2000/07/11 17:11:00  Ulrich von Zadow
00542 |      Added support for RGBA pixel ordering (Jose Miguel Buenaposada Biencinto).
00543 |
00544 |      Revision 1.13  2000/03/31 12:20:05  Ulrich von Zadow
00545 |      Video invert filter (beta)
00546 |
00547 |      Revision 1.12  2000/03/31 11:53:30  Ulrich von Zadow
00548 |      Added quantization support.
00549 |
00550 |      Revision 1.11  2000/01/16 20:43:12  anonymous
00551 |      Removed MFC dependencies
00552 |
00553 |      Revision 1.10  1999/12/10 01:27:26  Ulrich von Zadow
00554 |      Added assignment operator and copy constructor to
00555 |      bitmap classes.
00556 |
00557 |      Revision 1.9  1999/12/09 16:35:22  Ulrich von Zadow
00558 |      no message
00559 |
00560 |      Revision 1.8  1999/12/08 15:39:45  Ulrich von Zadow
00561 |      Unix compatibility changes
00562 |
00563 |      Revision 1.7  1999/12/02 17:07:34  Ulrich von Zadow
00564 |      Changes by bdelmee.
00565 |
00566 |      Revision 1.6  1999/10/22 21:25:51  Ulrich von Zadow
00567 |      Removed buggy octree quantization
00568 |
00569 \--------------------------------------------------------------------
00570 */

Generated on Wed Dec 15 21:20:30 2004 for vuVolume by  doxygen 1.3.9.1