22 inline uint32_t
RGBA(uint32_t r, uint32_t g, uint32_t
b, uint32_t
a)
24 return ((
a & 255) << 24) | ((r & 255) << 16) | ((g & 255) << 8) | (
b & 255);
26 #define C4RGB(r, g, b) (((DWORD)(0xff)<<24)|(((DWORD)(r)&0xff)<<16)|(((DWORD)(g)&0xff)<<8)|((b)&0xff))
27 #define GetBlueValue(rgb) ((unsigned char)(rgb))
28 #define GetGreenValue(rgb) ((unsigned char)(((unsigned short)(rgb)) >> 8))
29 #define GetRedValue(rgb) ((unsigned char)((rgb)>>16))
34 if (dwDst>>24 == 0x00) { dwDst=dwSrc;
return; }
35 BYTE byAlphaSrc=
BYTE(dwSrc>>24);
BYTE byAlphaDst=255-byAlphaSrc;
36 dwDst = std::min<uint32_t>(((dwDst & 0xff ) * byAlphaDst + (dwSrc & 0xff ) * byAlphaSrc) >>8, 0xff) |
37 std::min<uint32_t>(((dwDst & 0xff00) * byAlphaDst + (dwSrc & 0xff00 ) * byAlphaSrc) >>8 & 0xff00, 0xff00) |
38 std::min<uint32_t>(((dwDst & 0xff0000) * byAlphaDst + (dwSrc & 0xff0000) * byAlphaSrc) >>8 & 0xff0000, 0xff0000) |
39 std::min<uint32_t>( (dwDst >> 24) + byAlphaSrc, 255) << 24;
45 if (dwDst>>24 == 0x00) { dwDst=dwSrc;
return; }
47 dwDst = std::min<uint32_t>((dwDst & 0xff ) + ((
int(dwSrc & 0xff ) * byAlphaSrc) >>8) , 0xff) |
48 std::min<uint32_t>(((dwDst & 0xff00) + (
int(dwSrc>>8 & 0xff ) * byAlphaSrc)) & 0x00ffff00, 0xff00) |
49 std::min<uint32_t>(((dwDst & 0xff0000) + (
int(dwSrc>>8 & 0xff00) * byAlphaSrc)) & 0xffff0000, 0xff0000) |
50 std::min<uint32_t>( (dwDst >> 24) + byAlphaSrc, 255) << 24;
57 int iA1=dwDst>>24, iA2=dwMod>>24;
59 dwDst = ((dwDst & 0xff) * (dwMod & 0xff) / 0xff) |
60 ((dwDst>> 8 & 0xff) * (dwMod>> 8 & 0xff) / 0xff) << 8 |
61 ((dwDst>>16 & 0xff) * (dwMod>>16 & 0xff) / 0xff) << 16|
62 std::min(iA1*iA2/0xff, 255) << 24;
68 dwDst = ((dwDst & 0xff) * (dwMod & 0xff) / 0xff) |
69 ((dwDst>> 8 & 0xff) * (dwMod>> 8 & 0xff) / 0xff) << 8 |
70 ((dwDst>>16 & 0xff) * (dwMod>>16 & 0xff) / 0xff) << 16|
71 (std::max<uint32_t>((dwDst>>24)+(dwMod>>24), 0xff) - 0xff)<<24;
76 dwDst = (Clamp<int>(((
int)(dwDst&0xff)+(dwMod&0xff)-0x7f)<<1,0,0xff)&0xff) |
77 (Clamp<int>(((
int)(dwDst&0xff00)+(dwMod&0xff00)-0x7f00)<<1,0,0xff00)&0xff00) |
78 (Clamp<int>(((
int)(dwDst&0xff0000)+(dwMod&0xff0000)-0x7f0000)<<1,0,0xff0000)&0xff0000) |
79 (std::max<uint32_t>((dwDst>>24)+(dwMod>>24), 0xff) - 0xff)<<24;
86 dwDst = std::min<int>((dwDst & 0xff) + iBy, 255) |
87 std::min<int>((dwDst>> 8 & 0xff) + iBy, 255) << 8 |
88 std::min<int>((dwDst>>16 & 0xff) + iBy, 255) << 16 |
97 dwDst = std::max<int>(
int(dwDst & 0xff) - iBy, 0) |
98 std::max<int>(
int(dwDst>> 8 & 0xff) - iBy, 0) << 8 |
99 std::max<int>(
int(dwDst>>16 & 0xff) - iBy, 0) << 16 |
100 (dwDst & 0xff000000);
109 return dwClr|0xff000000;
117 BYTE sB=
BYTE(dwSrcClr); dwSrcClr=dwSrcClr>>8;
118 BYTE sG=
BYTE(dwSrcClr); dwSrcClr=dwSrcClr>>8;
119 BYTE sR=
BYTE(dwSrcClr); dwSrcClr=dwSrcClr>>8;
121 BYTE dB=
BYTE(dwDstClr); dwDstClr=dwDstClr>>8;
122 BYTE dG=
BYTE(dwDstClr); dwDstClr=dwDstClr>>8;
123 BYTE dR=
BYTE(dwDstClr); dwDstClr=dwDstClr>>8;
131 if (cG>0) diffN=std::max(diffN, cG);
132 if (cB>0) diffN=std::max(diffN, cB);
137 int bR=sR+(cR*255)/diffN;
138 int bG=sG+(cG*255)/diffN;
139 int bB=sB+(cB*255)/diffN;
140 dwBack=
RGBA(bR, bG, bB, 255);
145 return RGBA(std::min((
int)dR*256/sR, 255), std::min((
int)dG*256/sG, 255), std::min((
int)dB*256/sB, 255), 255-diffN);
148 inline bool rgb2xyY(
double r,
double g,
double b,
double *px,
double *py,
double *pY)
150 double X = 0.412453*r + 0.357580*g + 0.180423*
b;
151 double Y = 0.212671*r + 0.715160*g + 0.072169*
b;
152 double Z = 0.019334*r + 0.119193*g + 0.950227*
b;
160 *px =
X/XYZ; *py = Y/XYZ;
166 inline bool xy2upvp(
double x,
double y,
double *pu,
double *pv)
168 double n = -2.0*x+12.0*y+3.0;
169 if (!n)
return false;
175 inline bool RGB2rgb(
int R,
int G,
int B,
double *pr,
double *pg,
double *pb,
double gamma=2.2)
177 *pr = pow((
double) R / 255.0, 1.0/gamma);
178 *pg = pow((
double) G / 255.0, 1.0/gamma);
179 *pb = pow((
double) B / 255.0, 1.0/gamma);
uint32_t RGBA(uint32_t r, uint32_t g, uint32_t b, uint32_t a)
void ModulateClrMOD2(DWORD &dwDst, DWORD dwMod)
void ModulateClr(DWORD &dwDst, DWORD dwMod)
void BltAlpha(DWORD &dwDst, DWORD dwSrc)
DWORD PlrClr2TxtClr(DWORD dwClr)
#define GetGreenValue(rgb)
DWORD GetClrModulation(DWORD dwSrcClr, DWORD dwDstClr, DWORD &dwBack)
DWORD LightenClrBy(DWORD &dwDst, int iBy)
#define GetBlueValue(rgb)
bool rgb2xyY(double r, double g, double b, double *px, double *py, double *pY)
void ModulateClrA(DWORD &dwDst, DWORD dwMod)
void BltAlphaAdd(DWORD &dwDst, DWORD dwSrc)
DWORD DarkenClrBy(DWORD &dwDst, int iBy)
bool xy2upvp(double x, double y, double *pu, double *pv)
bool RGB2rgb(int R, int G, int B, double *pr, double *pg, double *pb, double gamma=2.2)