00001
00002
00003
00004
00005
00006
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
00020
00021
00022
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
00060
00061
00062 int BoxDist (const PLPixel32 Pix) const;
00063
00064
00065
00066
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
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220