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

plpixel16.h

00001 /*
00002 /--------------------------------------------------------------------
00003 |
00004 |      $Id: plpixel16_8h-source.html,v 1.2 2004/09/15 15:26:32 uzadow Exp $
00005 |
00006 |      Copyright (c) 1996-2002 Ulrich von Zadow
00007 |
00008 \--------------------------------------------------------------------
00009 */
00010 
00011 #ifndef INCL_PLPIXEL16
00012 #define INCL_PLPIXEL16
00013 
00014 #include <math.h>
00015 
00016 #include "plpixeldefs.h"
00017 #include "plpaintlibdefs.h"
00018 
00019 //! 16 bit pixel class. A pixel in this class contains 5 bits of
00020 //! red, 6 of green and 5 of blue (in that order). The order of the 
00021 //! color components is
00022 //! OS-dependent and defined in plpixeldefs.h. This class is meant to be
00023 //! fast, so all methods are inlined.
00024 class PLPixel16
00025 {
00026   public:
00027     //!
00028     PLPixel16 ();
00029     //!
00030     PLPixel16 (PLBYTE r, PLBYTE g, PLBYTE b);
00031     //!
00032     void Set (PLBYTE r, PLBYTE g, PLBYTE b);
00033     //!
00034     void SetR (PLBYTE r);
00035     //!
00036     void SetG (PLBYTE g);
00037     //!
00038     void SetB (PLBYTE b);
00039     //!
00040     PLBYTE GetR () const;
00041     //!
00042     PLBYTE GetG () const;
00043     //!
00044     PLBYTE GetB () const;
00045 
00046     //!
00047     PLPixel16 operator = (const PLPixel32& Pix);
00048 
00049     //!
00050     operator PLPixel32 () const;
00051 
00052     //!
00053     PLPixel16 operator = (const PLPixel24& Pix);
00054 
00055     //!
00056     operator PLPixel24 () const;
00057 
00058     //!
00059     bool operator ==(const PLPixel16 Pix) const;
00060 
00061     //!
00062     bool operator !=(const PLPixel16 Pix) const;
00063 
00064     //! Simple and fast 'distance' between two pixels. Just adds the
00065     //! distances between the color components and treats colors
00066     //! equally.
00067     int BoxDist (const PLPixel16 Pix) const;
00068 
00069   private:
00070     PLWORD m_Data;
00071 };
00072 
00073 inline PLPixel16::PLPixel16()
00074 {
00075 }
00076 
00077 
00078 inline PLPixel16::PLPixel16(PLBYTE r, PLBYTE g, PLBYTE b)
00079 {
00080   Set (r, g, b);
00081 }
00082 
00083 
00084 inline void PLPixel16::Set (PLBYTE r, PLBYTE g, PLBYTE b)
00085 {
00086 #ifdef PL_PIXEL_BGRA_ORDER
00087   m_Data = ((r&0xF8) << 8) | ((g&0xFC) << 3) | (b>>3);
00088 #else
00089   m_Data = (b&0xF8) << 8 | ((g&0xFC) << 3) | (r>>3);
00090 #endif  
00091 }
00092 
00093 inline void PLPixel16::SetR(PLBYTE r)
00094 {
00095 #ifdef PL_PIXEL_BGRA_ORDER
00096   m_Data = (m_Data&0x07FF)|((r&0xF8)<<8);
00097 #else
00098   m_Data = (m_Data&0xFFE0)|(r>>3);
00099 #endif
00100 }
00101 
00102 inline void PLPixel16::SetG(PLBYTE g)
00103 {
00104   m_Data = (m_Data&0xF81F)|((g&0xFC)<<3);
00105 }
00106 
00107 
00108 inline void PLPixel16::SetB(PLBYTE b)
00109 {
00110 #ifdef PL_PIXEL_BGRA_ORDER
00111   m_Data = (m_Data&0xFFE0)|(b>>3);
00112 #else
00113   m_Data = (m_Data&0x07FF)|((b&0xF8)<<8);
00114 #endif
00115 }
00116 
00117 inline PLBYTE PLPixel16::GetR() const
00118 {
00119 #ifdef PL_PIXEL_BGRA_ORDER
00120   return (m_Data&0xF800)>>8;
00121 #else
00122   return (m_Data&0x001F)<<3;
00123 #endif  
00124 }
00125 
00126 
00127 inline PLBYTE PLPixel16::GetG() const
00128 {
00129   return (m_Data&0x07E0)>>3;
00130 }
00131 
00132 inline PLBYTE PLPixel16::GetB() const
00133 {
00134 #ifdef PL_PIXEL_BGRA_ORDER
00135   return (m_Data&0x001F)<<3;
00136 #else
00137   return (m_Data&0xF800)>>8;
00138 #endif  
00139 }
00140 
00141 inline PLPixel16 PLPixel16::operator = (const PLPixel32& Pix)
00142 {
00143   m_Data = PLWORD((((*(const PLLONG*)&Pix) & 0xF80000) >> 8) | 
00144                                  (((*(const PLLONG*)&Pix) & 0x00FC00) >> 5) | 
00145                                  (((*(const PLLONG*)&Pix) & 0x0000F8) >> 3));
00146 
00147   return *this;
00148 }
00149 
00150 inline PLPixel16::operator PLPixel32 () const
00151 {
00152   // TODO: Make faster.
00153   return PLPixel32 (GetR(), GetG(), GetB(), 255);
00154 }
00155 
00156 inline PLPixel16 PLPixel16::operator = (const PLPixel24& Pix)
00157 {
00158   Set (Pix.GetR(), Pix.GetG(), Pix.GetB());
00159 
00160   return *this;
00161 }
00162 
00163 inline PLPixel16::operator PLPixel24 () const
00164 {
00165   // TODO: Make faster.  
00166   return PLPixel24 (GetR(), GetG(), GetB());
00167 }
00168 
00169 inline int PLPixel16::BoxDist (const PLPixel16 Pix) const
00170 {
00171   return (abs ((int)GetR()-Pix.GetR()) +
00172           abs ((int)GetG()-Pix.GetG()) +
00173           abs ((int)GetB()-Pix.GetB()));
00174 }
00175 
00176 inline bool PLPixel16::operator ==(const PLPixel16 Pix) const
00177 {
00178   return (*(const PLWORD *)this == *(const PLWORD*)&Pix);
00179 }
00180 
00181 inline bool PLPixel16::operator !=(const PLPixel16 Pix) const
00182 {
00183   return (!(*this == Pix));
00184 }
00185 
00186 
00187 #endif
00188 
00189 /*
00190 /--------------------------------------------------------------------
00191 |
00192 |      $Log: plpixel16_8h-source.html,v $
00192 |      Revision 1.2  2004/09/15 15:26:32  uzadow
00192 |      Linux compatibility changes, doc update.
00192 |
00193 |      Revision 1.3  2004/06/13 20:20:33  uzadow
00194 |      no message
00195 |
00196 |      Revision 1.2  2004/06/09 21:34:53  uzadow
00197 |      Added 16 bpp support to plbitmap, planybmp and pldirectfbbmp
00198 |
00199 |      Revision 1.1  2004/06/09 20:27:48  uzadow
00200 |      Added 16 bpp pixel class.
00201 |
00202 |
00203 \--------------------------------------------------------------------
00204 */

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