00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 #ifndef __CS_RGBPIXEL_H__
00050 #define __CS_RGBPIXEL_H__
00051
00052 #include <stdio.h>
00053 #include "cstypes.h"
00054
00059 struct csRGBcolor
00060 {
00061 unsigned char red, green, blue;
00062 csRGBcolor () : red(0), green(0), blue(0) {}
00063 csRGBcolor (unsigned char r, unsigned char g, unsigned char b) :
00064 red(r), green(g), blue(b) {}
00065 void Set (unsigned char r, unsigned char g, unsigned char b)
00066 { red = r; green = g; blue = b; }
00067 bool operator == (const csRGBcolor& c) const
00068 { return (c.red == red) && (c.green == green) && (c.blue == blue); }
00069 bool operator != (const csRGBcolor& c) const
00070 { return !operator == (c); }
00071 csRGBcolor operator + (const csRGBcolor& c) const
00072 { return csRGBcolor (c.red + red, c.green + green, c.blue + blue); }
00073 };
00074
00075
00076 #ifdef CS_BIG_ENDIAN
00077 # define RGB_MASK 0xffffff00
00078 #else
00079 # define RGB_MASK 0x00ffffff
00080 #endif
00081
00087 struct csRGBpixel
00088 {
00090 unsigned char red, green, blue, alpha;
00092 csRGBpixel ()
00093 { *(uint32 *)this = (uint32)~RGB_MASK; }
00095 csRGBpixel (const csRGBpixel& p)
00096
00097 { *(uint32*)this = *(uint32*)&p; }
00099 csRGBpixel (const csRGBcolor& c) :
00100 red (c.red), green (c.green), blue (c.blue), alpha (255) {}
00102 csRGBpixel (int r, int g, int b) :
00103 red (r), green (g), blue (b), alpha (255) {}
00105 bool operator == (const csRGBcolor& c) const
00106 { return (c.red == red) && (c.green == green) && (c.blue == blue); }
00108 bool operator == (const csRGBpixel& p) const
00109
00110 { return *(uint32*)this == *(uint32*)&p; }
00112 bool operator != (const csRGBcolor& c) const
00113 { return !operator == (c); }
00118 bool operator != (const csRGBpixel& p) const
00119 { return !operator == (p); }
00121 operator csRGBcolor () const
00122 { return csRGBcolor (red, green, blue); }
00124 bool eq (const csRGBpixel& p) const
00125 { return ((*(uint32*)this) & RGB_MASK) == ((*(uint32*)&p) & RGB_MASK); }
00127 int Intensity ()
00128 { return (red + green + blue) / 3; }
00129 unsigned char Luminance ()
00130 { return (((int)red)*30 + ((int)green)*59 + ((int)blue)*11)/100; }
00132 void Set (const int r, const int g, const int b)
00133 { red = r; green = g; blue = b; alpha = 255; }
00135 void Set (const int r, const int g, const int b, const int a)
00136 { red = r; green = g; blue = b; alpha = a; }
00137 void Set (const csRGBpixel& p)
00138
00139 { *(uint32*)this = *(uint32*)&p; }
00140 };
00141
00142
00143 #undef RGB_MASK
00144
00151
00152 #define R_COEF 173
00153
00154 #define G_COEF 242
00155
00156 #define B_COEF 107
00159 #define R_COEF_SQ 299
00160
00161 #define G_COEF_SQ 587
00162
00163 #define B_COEF_SQ 114
00164
00165 #endif // __CS_RGBPIXEL_H__