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

plpixel32.h

00001 /*
00002 /--------------------------------------------------------------------
00003 |
00004 |      $Id: plpixel32.h,v 1.7 2002/08/04 20:08:01 uzadow Exp $
00005 |
00006 |      Copyright (c) 1996-2002 Ulrich von Zadow
00007 |
00008 \--------------------------------------------------------------------
00009 */
00010 
00011 #ifndef INCL_PLPIXEL32
00012 #define INCL_PLPIXEL32
00013 
00014 #include <math.h>
00015 
00016 #include "plpixeldefs.h"
00017 #include "plpaintlibdefs.h"
00018 
00019 //! 32 bit pixel class. A pixel in this class contains 8 bits each of
00020 //! red, green, blue and alpha. The order of the color components is
00021 //! OS-dependent and defined in config.h. This class is meant to be
00022 //! fast, so all methods are inlined.
00023 class PLPixel32
00024 {
00025   public:
00026     //!
00027     PLPixel32 ();
00028     //!
00029     PLPixel32 (PLBYTE r, PLBYTE g, PLBYTE b, PLBYTE a);
00030     //!
00031     PLPixel32 (PLBYTE r, PLBYTE g, PLBYTE b);
00032     //!
00033     void Set (PLBYTE r, PLBYTE g, PLBYTE b, PLBYTE a);
00034     //!
00035     void Set (PLBYTE r, PLBYTE g, PLBYTE b);
00036     //!
00037     void SetR (PLBYTE r);
00038     //!
00039     void SetG (PLBYTE g);
00040     //!
00041     void SetB (PLBYTE b);
00042     //!
00043     void SetA (PLBYTE a);
00044     //!
00045     PLBYTE GetR () const;
00046     //!
00047     PLBYTE GetG () const;
00048     //!
00049     PLBYTE GetB () const;
00050     //!
00051     PLBYTE GetA () const;
00052 
00053     //!
00054     bool operator ==(const PLPixel32 Pix) const;
00055 
00056     //!
00057     bool operator !=(const PLPixel32 Pix) const;
00058 
00059     //! Simple and fast 'distance' between two pixels. Just adds the
00060     //! distances between the color components and treats colors
00061     //! equally.
00062     int BoxDist (const PLPixel32 Pix) const;
00063 
00064     //! Returns a weighed average between two pixels. Factor must be 
00065     //! between 0 and 256. Factor=256 means Pix1 is the result, Factor=0 
00066     //! means Pix2 is the result.
00067     static PLPixel32 Blend (int Factor, const PLPixel32 Pix1, 
00068                             const PLPixel32 Pix2);
00069 
00070   private:
00071     PLBYTE m_Data[4];
00072 };
00073 
00074 inline PLPixel32::PLPixel32()
00075 {
00076 }
00077 
00078 
00079 inline PLPixel32::PLPixel32(PLBYTE r, PLBYTE g, PLBYTE b, PLBYTE a)
00080 {
00081   Set (r, g, b, a);
00082 }
00083 
00084 
00085 inline PLPixel32::PLPixel32(PLBYTE r, PLBYTE g, PLBYTE b)
00086 {
00087   Set (r, g, b, 255);
00088 }
00089 
00090 
00091 inline void PLPixel32::Set(PLBYTE r, PLBYTE g, PLBYTE b, PLBYTE a)
00092 {
00093   m_Data[PL_RGBA_RED] = r;
00094   m_Data[PL_RGBA_GREEN] = g;
00095   m_Data[PL_RGBA_BLUE] = b;
00096   m_Data[PL_RGBA_ALPHA] = a;
00097 }
00098 
00099 //!
00100 inline void PLPixel32::Set (PLBYTE r, PLBYTE g, PLBYTE b)
00101 {
00102   m_Data[PL_RGBA_RED] = r;
00103   m_Data[PL_RGBA_GREEN] = g;
00104   m_Data[PL_RGBA_BLUE] = b;
00105 }
00106 
00107 inline void PLPixel32::SetR(PLBYTE r)
00108 {
00109   m_Data[PL_RGBA_RED] = r;
00110 }
00111 
00112 
00113 inline void PLPixel32::SetG(PLBYTE g)
00114 {
00115   m_Data[PL_RGBA_GREEN] = g;
00116 }
00117 
00118 
00119 inline void PLPixel32::SetB(PLBYTE b)
00120 {
00121   m_Data[PL_RGBA_BLUE] = b;
00122 }
00123 
00124 
00125 inline void PLPixel32::SetA(PLBYTE a)
00126 {
00127   m_Data[PL_RGBA_ALPHA] = a;
00128 }
00129 
00130 
00131 inline PLBYTE PLPixel32::GetR() const
00132 {
00133   return m_Data[PL_RGBA_RED];
00134 }
00135 
00136 
00137 inline PLBYTE PLPixel32::GetG() const
00138 {
00139   return m_Data[PL_RGBA_GREEN];
00140 }
00141 
00142 
00143 inline PLBYTE PLPixel32::GetB() const
00144 {
00145   return m_Data[PL_RGBA_BLUE];
00146 }
00147 
00148 
00149 inline PLBYTE PLPixel32::GetA() const
00150 {
00151   return m_Data[PL_RGBA_ALPHA];
00152 }
00153 
00154 inline int PLPixel32::BoxDist (const PLPixel32 Pix) const
00155 {
00156   return (abs ((int)GetR()-Pix.GetR()) +
00157           abs ((int)GetG()-Pix.GetG()) +
00158           abs ((int)GetB()-Pix.GetB()));
00159 }
00160 
00161 inline PLPixel32 PLPixel32::Blend (int Factor, const PLPixel32 Pix1, const PLPixel32 Pix2)
00162 {
00163   PLASSERT (Factor >= 0 && Factor <= 256);
00164 
00165   return PLPixel32 ((Pix1.GetR()*Factor+Pix2.GetR()*(256-Factor))>>8,
00166                     (Pix1.GetG()*Factor+Pix2.GetG()*(256-Factor))>>8,
00167                     (Pix1.GetB()*Factor+Pix2.GetB()*(256-Factor))>>8,
00168                     Pix1.GetA());
00169 }
00170 
00171 inline bool PLPixel32::operator ==(const PLPixel32 Pix) const
00172 {
00173   return (*(const PLLONG *)this == *(const PLLONG*)&Pix);
00174 }
00175 
00176 inline bool PLPixel32::operator !=(const PLPixel32 Pix) const
00177 {
00178   return (!(*this == Pix));
00179 }
00180 
00181 
00182 #endif
00183 
00184 /*
00185 /--------------------------------------------------------------------
00186 |
00187 |      $Log: plpixel32.h,v $
00188 |      Revision 1.7  2002/08/04 20:08:01  uzadow
00189 |      Added PLBmpInfo class, ability to extract metainformation from images without loading the whole image and proper greyscale support.
00190 |
00191 |      Revision 1.6  2002/03/31 13:36:42  uzadow
00192 |      Updated copyright.
00193 |
00194 |      Revision 1.5  2001/10/21 17:12:40  uzadow
00195 |      Added PSD decoder beta, removed BPPWanted from all decoders, added PLFilterPixel.
00196 |
00197 |      Revision 1.4  2001/10/06 22:03:26  uzadow
00198 |      Added PL prefix to basic data types.
00199 |
00200 |      Revision 1.3  2001/09/28 19:50:56  uzadow
00201 |      Added some 24 bpp stuff & other minor features.
00202 |
00203 |      Revision 1.2  2001/09/24 14:13:18  uzadow
00204 |      Added Blend, improved const-correctness.
00205 |
00206 |      Revision 1.1  2001/09/16 19:03:22  uzadow
00207 |      Added global name prefix PL, changed most filenames.
00208 |
00209 |      Revision 1.3  2001/09/15 14:30:20  uzadow
00210 |      Fixed PLPixel32 initialization bug.
00211 |
00212 |      Revision 1.2  2001/09/13 20:45:35  uzadow
00213 |      Added 8-bpp pixel class.
00214 |
00215 |      Revision 1.1  2000/12/18 22:42:52  uzadow
00216 |      Replaced RGBAPIXEL with PLPixel32.
00217 |
00218 |
00219 \--------------------------------------------------------------------
00220 */

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