00001
00002
00003
00004
00005
00006
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;
00069 #endif
00070
00071
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
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
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
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
00303
00304 int m_Width;
00305 int m_Height;
00306 PLWORD m_bpp;
00307 PLPoint m_Resolution;
00308
00309 PLPixel32 * m_pClrTab;
00310 bool m_bAlphaChannel;
00311 PLBYTE ** m_pLineArray;
00312
00313 int m_LockCount;
00314
00315
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
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
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
00462
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
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570