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

plpixel24.h

00001 /*
00002 /--------------------------------------------------------------------
00003 |
00004 |      $Id: plpixel24_8h-source.html,v 1.4 2004/09/15 15:26:32 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     //!
00048     operator PLPixel32 () const;
00049 
00050     //!
00051     bool operator ==(const PLPixel24&) const;
00052 
00053     //!
00054     bool operator !=(const PLPixel24&) const;
00055 
00056     //! Simple and fast 'distance' between two pixels. Just adds the
00057     //! distances between the color components and treats colors
00058     //! equally.
00059     int BoxDist (const PLPixel24 Pix) const;
00060 
00061     //! Returns a weighed average between two pixels. Factor must be 
00062     //! between 0 and 256. Factor=256 means Pix1 is the result, Factor=0 
00063     //! means Pix2 is the result.
00064     static PLPixel24 Blend (int Factor, const PLPixel24 Pix1, 
00065                             const PLPixel24 Pix2);
00066 
00067   private:
00068     PLBYTE m_Data[3];
00069 };
00070 
00071 inline PLPixel24::PLPixel24()
00072 {
00073 }
00074 
00075 
00076 inline PLPixel24::PLPixel24(PLBYTE r, PLBYTE g, PLBYTE b)
00077 {
00078   Set (r, g, b);
00079 }
00080 
00081 
00082 inline void PLPixel24::Set(PLBYTE r, PLBYTE g, PLBYTE b)
00083 {
00084   m_Data[PL_RGBA_RED] = r;
00085   m_Data[PL_RGBA_GREEN] = g;
00086   m_Data[PL_RGBA_BLUE] = b;
00087 }
00088 
00089 
00090 inline void PLPixel24::SetR(PLBYTE r)
00091 {
00092   m_Data[PL_RGBA_RED] = r;
00093 }
00094 
00095 
00096 inline void PLPixel24::SetG(PLBYTE g)
00097 {
00098   m_Data[PL_RGBA_GREEN] = g;
00099 }
00100 
00101 
00102 inline void PLPixel24::SetB(PLBYTE b)
00103 {
00104   m_Data[PL_RGBA_BLUE] = b;
00105 }
00106 
00107 
00108 inline PLBYTE PLPixel24::GetR() const
00109 {
00110   return m_Data[PL_RGBA_RED];
00111 }
00112 
00113 
00114 inline PLBYTE PLPixel24::GetG() const
00115 {
00116   return m_Data[PL_RGBA_GREEN];
00117 }
00118 
00119 
00120 inline PLBYTE PLPixel24::GetB() const
00121 {
00122   return m_Data[PL_RGBA_BLUE];
00123 }
00124 
00125 
00126 inline int PLPixel24::BoxDist (const PLPixel24 Pix) const
00127 {
00128   return (abs ((int)GetR()-Pix.GetR()) +
00129           abs ((int)GetG()-Pix.GetG()) +
00130           abs ((int)GetB()-Pix.GetB()));
00131 }
00132 
00133 
00134 inline PLPixel24 PLPixel24::Blend (int Factor, const PLPixel24 Pix1, const PLPixel24 Pix2)
00135 {
00136   PLASSERT (Factor >= 0 && Factor <= 256);
00137 
00138   return PLPixel24 ((Pix1.GetR()*Factor+Pix2.GetR()*(256-Factor))>>8,
00139                     (Pix1.GetG()*Factor+Pix2.GetG()*(256-Factor))>>8,
00140                     (Pix1.GetB()*Factor+Pix2.GetB()*(256-Factor))>>8);
00141 }
00142 
00143 inline PLPixel24 PLPixel24::operator = (const PLPixel32& Pix)
00144 {
00145   SetR (Pix.GetR());
00146   SetG (Pix.GetG());
00147   SetB (Pix.GetB());
00148 
00149   return *this;
00150 }
00151 
00152 inline PLPixel24::operator PLPixel32 () const
00153 {
00154   return PLPixel32 (GetR(), GetG(), GetB(), 255);
00155 }
00156 
00157 inline bool PLPixel24::operator ==(const PLPixel24& Pix) const
00158 {
00159   return (GetR() == Pix.GetR() && GetG() == Pix.GetG() && GetB() == Pix.GetB());
00160 }
00161 
00162 inline bool PLPixel24::operator !=(const PLPixel24& Pix) const
00163 {
00164   return (!(*this == Pix));
00165 }
00166 
00167 
00168 #endif
00169 
00170 /*
00171 /--------------------------------------------------------------------
00172 |
00173 |      $Log: plpixel24_8h-source.html,v $
00173 |      Revision 1.4  2004/09/15 15:26:32  uzadow
00173 |      Linux compatibility changes, doc update.
00173 |
00174 |      Revision 1.5  2004/06/09 21:34:53  uzadow
00175 |      Added 16 bpp support to plbitmap, planybmp and pldirectfbbmp
00176 |
00177 |      Revision 1.4  2004/06/09 20:27:48  uzadow
00178 |      Added 16 bpp pixel class.
00179 |
00180 |      Revision 1.3  2002/02/24 13:00:35  uzadow
00181 |      Documentation update; removed buggy PLFilterRotate.
00182 |
00183 |      Revision 1.2  2001/10/06 22:03:26  uzadow
00184 |      Added PL prefix to basic data types.
00185 |
00186 |      Revision 1.1  2001/10/03 13:58:43  uzadow
00187 |      Added.
00188 |
00189 |      Revision 1.1  2001/09/26 10:21:09  uzadow
00190 |      Added PLPixel24, PLBmp::CreateCopy now supports 24 bpp in most cases.
00191 |
00192 |
00193 |
00194 \--------------------------------------------------------------------
00195 */

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