00001
00002
00003
00004
00005
00006
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
00020
00021
00022
00023
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
00065
00066
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
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
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