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

plpixel24.h

00001 /*
00002 /--------------------------------------------------------------------
00003 |
00004 |      $Id: plpixel24.h,v 1.3 2002/02/24 13:00:35 uzadow Exp $
00005 |
00006 |      Copyright (c) 1996-2002 Ulrich von Zadow
00007 |
00008 \--------------------------------------------------------------------
00009 */
00010 
00011 #ifndef INCL_PLPIXEL24
00012 #define INCL_PLPIXEL24
00013 
00014 #include "plpixeldefs.h"
00015 #include "plpaintlibdefs.h"
00016 #include "plpixel32.h"
00017 
00018 //! 24 bit pixel class. A pixel in this class contains 8 bits each of
00019 //! red, green and blue. The order of the color components is
00020 //! OS-dependent and defined in config.h. This class is meant to be
00021 //! fast, so all methods are inlined.
00022 class PLPixel24
00023 {
00024   public:
00025     //!
00026     PLPixel24 ();
00027     //!
00028     PLPixel24 (PLBYTE r, PLBYTE g, PLBYTE b);
00029     //!
00030     void Set (PLBYTE r, PLBYTE g, PLBYTE b);
00031     //!
00032     void SetR (PLBYTE r);
00033     //!
00034     void SetG (PLBYTE g);
00035     //!
00036     void SetB (PLBYTE b);
00037     //!
00038     PLBYTE GetR () const;
00039     //!
00040     PLBYTE GetG () const;
00041     //!
00042     PLBYTE GetB () const;
00043 
00044     //!
00045     PLPixel24 operator = (const PLPixel32 Pix);
00046 
00047     operator PLPixel32 () const;
00048 
00049     //!
00050     bool operator ==(const PLPixel24&) const;
00051 
00052     //!
00053     bool operator !=(const PLPixel24&) const;
00054 
00055     //! Simple and fast 'distance' between two pixels. Just adds the
00056     //! distances between the color components and treats colors
00057     //! equally.
00058     int BoxDist (const PLPixel24 Pix) const;
00059 
00060     //! Returns a weighed average between two pixels. Factor must be 
00061     //! between 0 and 256. Factor=256 means Pix1 is the result, Factor=0 
00062     //! means Pix2 is the result.
00063     static PLPixel24 Blend (int Factor, const PLPixel24 Pix1, 
00064                             const PLPixel24 Pix2);
00065 
00066   private:
00067     PLBYTE m_Data[3];
00068 };
00069 
00070 inline PLPixel24::PLPixel24()
00071 {
00072 }
00073 
00074 
00075 inline PLPixel24::PLPixel24(PLBYTE r, PLBYTE g, PLBYTE b)
00076 {
00077   Set (r, g, b);
00078 }
00079 
00080 
00081 inline void PLPixel24::Set(PLBYTE r, PLBYTE g, PLBYTE b)
00082 {
00083   m_Data[PL_RGBA_RED] = r;
00084   m_Data[PL_RGBA_GREEN] = g;
00085   m_Data[PL_RGBA_BLUE] = b;
00086 }
00087 
00088 
00089 inline void PLPixel24::SetR(PLBYTE r)
00090 {
00091   m_Data[PL_RGBA_RED] = r;
00092 }
00093 
00094 
00095 inline void PLPixel24::SetG(PLBYTE g)
00096 {
00097   m_Data[PL_RGBA_GREEN] = g;
00098 }
00099 
00100 
00101 inline void PLPixel24::SetB(PLBYTE b)
00102 {
00103   m_Data[PL_RGBA_BLUE] = b;
00104 }
00105 
00106 
00107 inline PLBYTE PLPixel24::GetR() const
00108 {
00109   return m_Data[PL_RGBA_RED];
00110 }
00111 
00112 
00113 inline PLBYTE PLPixel24::GetG() const
00114 {
00115   return m_Data[PL_RGBA_GREEN];
00116 }
00117 
00118 
00119 inline PLBYTE PLPixel24::GetB() const
00120 {
00121   return m_Data[PL_RGBA_BLUE];
00122 }
00123 
00124 
00125 inline int PLPixel24::BoxDist (const PLPixel24 Pix) const
00126 {
00127   return (abs ((int)GetR()-Pix.GetR()) +
00128           abs ((int)GetG()-Pix.GetG()) +
00129           abs ((int)GetB()-Pix.GetB()));
00130 }
00131 
00132 
00133 inline PLPixel24 PLPixel24::Blend (int Factor, const PLPixel24 Pix1, const PLPixel24 Pix2)
00134 {
00135   PLASSERT (Factor >= 0 && Factor <= 256);
00136 
00137   return PLPixel24 ((Pix1.GetR()*Factor+Pix2.GetR()*(256-Factor))>>8,
00138                     (Pix1.GetG()*Factor+Pix2.GetG()*(256-Factor))>>8,
00139                     (Pix1.GetB()*Factor+Pix2.GetB()*(256-Factor))>>8);
00140 }
00141 
00142 inline PLPixel24 PLPixel24::operator = (const PLPixel32 Pix)
00143 {
00144   SetR (Pix.GetR());
00145   SetG (Pix.GetG());
00146   SetB (Pix.GetB());
00147 
00148   return *this;
00149 }
00150 
00151 inline PLPixel24::operator PLPixel32 () const
00152 {
00153   return PLPixel32 (GetR(), GetG(), GetB(), 255);
00154 }
00155 
00156 inline bool PLPixel24::operator ==(const PLPixel24& Pix) const
00157 {
00158   return (GetR() == Pix.GetR() && GetG() == Pix.GetG() && GetB() == Pix.GetB());
00159 }
00160 
00161 inline bool PLPixel24::operator !=(const PLPixel24& Pix) const
00162 {
00163   return (!(*this == Pix));
00164 }
00165 
00166 
00167 #endif
00168 
00169 /*
00170 /--------------------------------------------------------------------
00171 |
00172 |      $Log: plpixel24.h,v $
00173 |      Revision 1.3  2002/02/24 13:00:35  uzadow
00174 |      Documentation update; removed buggy PLFilterRotate.
00175 |
00176 |      Revision 1.2  2001/10/06 22:03:26  uzadow
00177 |      Added PL prefix to basic data types.
00178 |
00179 |      Revision 1.1  2001/10/03 13:58:43  uzadow
00180 |      Added.
00181 |
00182 |      Revision 1.1  2001/09/26 10:21:09  uzadow
00183 |      Added PLPixel24, PLBmp::CreateCopy now supports 24 bpp in most cases.
00184 |
00185 |
00186 |
00187 \--------------------------------------------------------------------
00188 */

Generated on Sun Jun 6 13:42:22 2004 for paintlib by doxygen 1.3.2