22 #ifndef AGS_PLUGINS_AGS_PAL_RENDER_PAL_RENDER_H 23 #define AGS_PLUGINS_AGS_PAL_RENDER_PAL_RENDER_H 25 #include "ags/lib/allegro.h" 26 #include "ags/plugins/ags_plugin.h" 27 #include "ags/plugins/plugin_base.h" 28 #include "common/algorithm.h" 32 namespace AGSPalRender {
41 extern unsigned char clut[65536];
42 extern unsigned char cycle_remap [256];
43 extern const int alphamultiply [4096];
53 static unsigned char MixColorAlpha(
unsigned char fg,
unsigned char bg,
unsigned char alpha,
int use_objpal = 0) {
54 unsigned char rfg = cycle_remap[fg];
56 AGSColor *palette = engine->GetPalette();
61 int out_r, out_g, out_b;
62 if (use_objpal == 0) {
63 out_r = (objectivepal[rfg].r >> 1) *alpha + (palette[bg].r >> 1) *(255 - alpha);
64 out_g = objectivepal[rfg].g * alpha + palette[bg].g * (255 - alpha);
65 out_b = (objectivepal[rfg].b >> 1) *alpha + (palette[bg].b >> 1) *(255 - alpha);
67 out_r = (objectivepal[rfg].r >> 1) *alpha + (objectivepal[bg].r >> 1) *(255 - alpha);
68 out_g = objectivepal[rfg].g * alpha + objectivepal[bg].g * (255 - alpha);
69 out_b = (objectivepal[rfg].b >> 1) *alpha + (objectivepal[bg].b >> 1) *(255 - alpha);
77 out_r = (out_r + 1 + (out_r >> 8)) >> 8;
78 out_g = (out_g + 1 + (out_g >> 8)) >> 8;
79 out_b = (out_b + 1 + (out_b >> 8)) >> 8;
83 i = ((out_r << 11) | (out_g << 5) | out_b);
84 unsigned char *clutp = clut;
86 return cycle_remap[*(clutp + i)];
90 static unsigned char MixColorLightLevel(
unsigned char fg,
unsigned char intensity) {
91 unsigned char rfg = cycle_remap [fg];
96 int dark_r = (((objectivepal[rfg].r >> 1) * (intensity)) >> 8);
97 int dark_b = (((objectivepal[rfg].b >> 1) * (intensity)) >> 8);
98 int dark_g = (((objectivepal[rfg].g) * (intensity)) >> 8);
99 i = ((dark_r << 11) | (dark_g << 5) | dark_b);
100 unsigned char *clutp = clut;
101 return cycle_remap [*(clutp + i)];
104 static unsigned char MixColorAdditive(
unsigned char fg,
unsigned char bg,
unsigned char alpha,
int use_objpal = 0) {
105 unsigned char rfg = cycle_remap[fg];
110 AGSColor *palette = engine->GetPalette();
112 int add_r, add_b, add_g = 0;
117 add_r = (((objectivepal[rfg].r >> 1) * (alpha)) >> 8);
118 add_b = (((objectivepal[rfg].b >> 1) * (alpha)) >> 8);
119 add_g = (((objectivepal[rfg].g) * (alpha)) >> 8);
127 int out_r, out_g, out_b;
128 if (use_objpal == 0) {
129 out_r =
MIN(31, (palette[bg].r >> 1) + add_r);
130 out_g =
MIN(63, palette[bg].g + add_g);
131 out_b =
MIN(31, (palette[bg].b >> 1) + add_b);
133 out_r =
MIN(31, (objectivepal [bg].r >> 1) + add_r);
134 out_g =
MIN(63, objectivepal [bg].g + add_g);
135 out_b =
MIN(31, (objectivepal [bg].b >> 1) + add_b);
137 i = ((out_r << 11) | (out_g << 5) | out_b);
138 unsigned char *clutp = clut;
139 unsigned char result = cycle_remap [*(clutp + i)];
145 static unsigned char MixColorMultiply(
unsigned char fg,
unsigned char bg,
unsigned char alpha,
int use_objpal = 0) {
146 unsigned char rfg = cycle_remap [fg];
147 unsigned char rbg = cycle_remap [bg];
148 AGSColor *palette = engine->GetPalette();
150 int mul_r, mul_b, mul_g = 0;
151 int out_r, out_g, out_b = 0;
152 if (use_objpal == 0) {
153 mul_r = ((objectivepal[rfg].r >> 1) * (palette[rbg].r >> 1)) / 64;
154 mul_b = ((objectivepal[rfg].b >> 1) * (palette[rbg].b >> 1)) / 64;
155 mul_g = ((objectivepal[rfg].g * palette[rbg].g) / 64);
156 out_r = ((palette[rbg].r >> 1) * (63 - (alpha / 4)) + (mul_r * (alpha / 4))) / 63;
157 out_g = (palette[rbg].g * (63 - (alpha / 4)) + (mul_g * (alpha / 4))) / 63;
158 out_b = ((palette[rbg].b >> 1) * (63 - (alpha / 4)) + (mul_b * (alpha / 4))) / 63;
160 mul_r = ((objectivepal[rfg].r >> 1) * (objectivepal[rbg].r >> 1)) / 64;
161 mul_b = ((objectivepal[rfg].b >> 1) * (objectivepal[rbg].b >> 1)) / 64;
162 mul_g = ((objectivepal[rfg].g * objectivepal[rbg].g) / 64);
164 out_r = ((objectivepal[rbg].r >> 1) * (63 - (alpha / 4)) + (mul_r * (alpha / 4))) / 63;
165 out_g = (objectivepal[rbg].g * (63 - (alpha / 4)) + (mul_g * (alpha / 4))) / 63;
166 out_b = ((objectivepal[rbg].b >> 1) * (63 - (alpha / 4)) + (mul_b * (alpha / 4))) / 63;
168 i = ((out_r << 11) | (out_g << 5) | out_b);
169 unsigned char *clutp = clut;
170 unsigned char result = cycle_remap [*(clutp + i)];
179 unsigned short root(
unsigned short x);
180 float FastSin(
float x);
181 float FastCos(
float x);
Definition: plugin_base.h:131
Definition: ags_plugin.h:328
Definition: ags_plugin.h:79
Definition: pal_render.h:34
T MIN(T a, T b)
Definition: util.h:59
Definition: pal_render.h:49