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

plpixelformat.h

00001 /*
00002 /--------------------------------------------------------------------
00003 |
00004 |      $Id: plpixelformat_8h-source.html,v 1.1 2004/09/15 15:26:32 uzadow Exp $
00005 |
00006 |      Copyright (c) 1996-2002 Ulrich von Zadow
00007 |
00008 \--------------------------------------------------------------------
00009 */
00010 
00011 #ifndef INCL_PLPIXELFORMAT
00012 #define INCL_PLPIXELFORMAT
00013 
00014 #include "pldebug.h"
00015 
00016 #include <string>
00017 #include <list>
00018 
00019 class PLPixelFormat {
00020 public:
00021         static const PLPixelFormat DONTCARE;
00022 
00023     // Pixel format descriptions are MSB first on all machines.
00024         static const PLPixelFormat L1;
00025         static const PLPixelFormat I8;
00026         static const PLPixelFormat L8;
00027         static const PLPixelFormat L16;
00028 
00029         static const PLPixelFormat X1R5G5B5;
00030         static const PLPixelFormat A1R5G5B5;
00031         static const PLPixelFormat R5G6B5;
00032         static const PLPixelFormat R8G8B8;
00033         static const PLPixelFormat A8R8G8B8;
00034         static const PLPixelFormat X8R8G8B8;
00035         static const PLPixelFormat R16G16B16;
00036 
00037         static const PLPixelFormat B5G5R5X1;
00038         static const PLPixelFormat B5G5R5A1;
00039         static const PLPixelFormat B5G6R5;
00040         static const PLPixelFormat B8G8R8;
00041         static const PLPixelFormat B8G8R8A8;
00042         static const PLPixelFormat B8G8R8X8;
00043         static const PLPixelFormat B16G16R16;
00044 
00045         static const PLPixelFormat L8Cbr8;      // aka YUV 4:2:2
00046         static const PLPixelFormat L8Cb8Cr8;    // aka YUV 4:4:4
00047 
00048     PLPixelFormat();
00049         PLPixelFormat(const PLPixelFormat & that);
00050         PLPixelFormat& operator=(const PLPixelFormat & that);
00051         bool operator==(const PLPixelFormat & that) const;
00052         bool operator!=(const PLPixelFormat & that) const;
00053 
00054         enum Channel {R=0,G,B,A,I,L,Cbr,Cb,Cr,C,M,Y,K,X, COUNT};
00055         
00056         typedef unsigned long long Mask;
00057 
00058         Mask GetMask(Channel ch) const;
00059         unsigned GetBitsPerPixel() const;
00060         bool HasAlpha() const;
00061         const PLPixelFormat & UseAlpha(bool useAlpha) const;
00062         bool IsGrayscale() const;
00063         const std::string& GetName() const;
00064         static const PLPixelFormat & FromName(const std::string & name);
00065         int GetNumColors() const;
00066 
00067         struct UnsupportedPixelFormat { 
00068                 UnsupportedPixelFormat(const std::string& what) : m_what(what) {};
00069                 const std::string m_what;
00070         };
00071 
00072 private:
00073         PLPixelFormat(const std::string& sName);
00074         
00075         std::string m_sName;
00076         int m_BitsPerPixel;
00077         Mask m_Channelmasks[COUNT];
00078 
00079         typedef std::list<PLPixelFormat *> PixelFormatList;
00080         static PixelFormatList s_pixelFormatList;
00081 };
00082 
00083 inline bool PLPixelFormat :: HasAlpha() const {
00084         return GetMask(A) != 0;
00085 }       
00086 
00087 inline bool PLPixelFormat :: IsGrayscale() const {
00088         return GetMask(L) == (((Mask)1 << m_BitsPerPixel) - 1);
00089 }
00090 
00091 inline unsigned PLPixelFormat :: GetBitsPerPixel() const {
00092         return m_BitsPerPixel;
00093 }
00094 
00095 inline const std::string& PLPixelFormat :: GetName() const {
00096         return m_sName;
00097 }
00098 
00099 inline PLPixelFormat :: Mask PLPixelFormat :: GetMask(PLPixelFormat :: Channel ch) const {
00100         PLASSERT(ch!=COUNT);
00101         return m_Channelmasks[ch];      
00102 }
00103   
00104 #endif

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