4 #define LICE_COMBINE_IMPLEMENT_HSV
5 #include "lice_combine.h"
8 LICE_pixel
LICE_AlterColorHSV_int(LICE_pixel color
, int dH
, int dS
, int dV
) // H is rolled over [0,384), S and V are clamped [0,255)
11 LICE_RGB2HSV(LICE_GETR(color
), LICE_GETG(color
), LICE_GETB(color
), &h
, &s
, &v
);
18 else if (h
>= 384) h
-= 384;
32 return LICE_HSV2Pix(h
, s
, v
, LICE_GETA(color
));
35 LICE_pixel
LICE_AlterColorHSV(LICE_pixel color
, float dH
, float dS
, float dV
) // H is rolled over, S and V are clamped, all [0,1)
37 int dHi
= (int)(dH
*384.0f
);
38 int dSi
= (int)(dS
*255.0f
);
39 int dVi
= (int)(dV
*255.0f
);
40 return LICE_AlterColorHSV_int(color
, dHi
, dSi
, dVi
);
43 void LICE_AlterBitmapHSV(LICE_IBitmap
* src
, float dH
, float dS
, float dV
) // H is rolled over, S and V are clamped
45 if (src
) LICE_AlterRectHSV(src
,0,0,src
->getWidth(),src
->getHeight(),dH
,dS
,dV
);
48 void LICE_AlterRectHSV(LICE_IBitmap
* src
, int xpos
, int ypos
, int w
, int h
, float dH
, float dS
, float dV
) // H is rolled over, S and V are clamped
61 const int span
= src
->getRowSpan();
62 const int destbm_w
= src
->getWidth(), destbm_h
= src
->getHeight();
63 if (span
< 1 || w
< 1 || h
< 1 || xpos
>= destbm_w
|| ypos
>= destbm_h
) return;
65 if (w
> destbm_w
- xpos
) w
= destbm_w
- xpos
;
66 if (h
> destbm_h
- ypos
) h
= destbm_h
- ypos
;
68 LICE_pixel
* px
= src
->getBits()+ypos
*span
+xpos
;
70 int dHi
= (int)(dH
*384.0f
);
71 int dSi
= (int)(dS
*255.0f
);
72 int dVi
= (int)(dV
*255.0f
);
73 if (dHi
> 383) dHi
=383;
74 else if (dHi
< -383) dHi
=-383;
77 if (!dHi
&& !dSi
&& !dVi
) return; // no mod
81 // generate a table of HSV translations with clip/clamp
82 unsigned char stab
[256], vtab
[256];
88 if(a
<0)a
=0; else if (a
>255)a
=255;
92 if(a
<0)a
=0; else if (a
>255)a
=255;
96 if(a
<0)a
+=384; else if (a
>=384)a
-=384;
102 if(a
<0)a
+=384; else if (a
>=384)a
-=384;
108 LICE_pixel
* tpx
= px
;
113 LICE_pixel color
= *tpx
;
115 LICE_RGB2HSV(LICE_GETR(color
), LICE_GETG(color
), LICE_GETB(color
), &hh
, &s
, &v
);
116 *tpx
++ = LICE_HSV2Pix(htab
[hh
],stab
[s
],vtab
[v
],LICE_GETA(color
));
124 LICE_pixel
* tpx
= px
;
129 *tpx
= LICE_AlterColorHSV_int(*tpx
, dHi
, dSi
, dVi
);