2 * Glide64 - Glide video plugin for Nintendo 64 emulators.
3 * Copyright (c) 2002 Dave2001
4 * Copyright (c) 2003-2009 Sergey 'Gonetz' Lipski
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 //****************************************************************
23 // Glide64 - Glide Plugin for Nintendo 64 emulators
24 // Project started on December 29th, 2001
27 // Dave2001, original author, founded the project in 2001, left it in 2002
28 // Gugaman, joined the project in 2002, left it in 2002
29 // Sergey 'Gonetz' Lipski, joined the project in 2002, main author since fall of 2002
30 // Hiroshi 'KoolSmoky' Morii, joined the project in 2007
32 //****************************************************************
35 // * Write your name and (optional)email, commented by your work, so I know who did it, and so that you can find which parts you modified when it comes time to send it to me.
36 // * Do NOT send me the whole project or file that you modified. Take out your modified code sections, and tell me where to put them. If people sent the whole thing, I would have many different versions, but no idea how to combine them all.
38 //****************************************************************
40 static void mod_tex_inter_color_using_factor_CI (wxUint32 color, wxUint32 factor)
42 float percent = factor / 255.0f;
43 float percent_i = 1 - percent;
48 cr = (wxUint8)((color >> 24) & 0xFF);
49 cg = (wxUint8)((color >> 16) & 0xFF);
50 cb = (wxUint8)((color >> 8) & 0xFF);
52 for (int i=0; i<256; i++)
55 a = (wxUint8)(col&0x0001);;
56 r = (wxUint8)((float)((col&0xF800) >> 11) / 31.0f * 255.0f);
57 g = (wxUint8)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f);
58 b = (wxUint8)((float)((col&0x003E) >> 1) / 31.0f * 255.0f);
59 r = (wxUint8)(min(255, percent_i * r + percent * cr));
60 g = (wxUint8)(min(255, percent_i * g + percent * cg));
61 b = (wxUint8)(min(255, percent_i * b + percent * cb));
62 rdp.pal_8[i] = (wxUint16)(((wxUint16)(r >> 3) << 11) |
63 ((wxUint16)(g >> 3) << 6) |
64 ((wxUint16)(b >> 3) << 1) |
65 ((wxUint16)(a ) << 0));
69 static void mod_tex_inter_col_using_col1_CI (wxUint32 color0, wxUint32 color1)
75 float percent_r = ((color1 >> 24) & 0xFF) / 255.0f;
76 float percent_g = ((color1 >> 16) & 0xFF) / 255.0f;
77 float percent_b = ((color1 >> 8) & 0xFF) / 255.0f;
78 float percent_r_i = 1.0f - percent_r;
79 float percent_g_i = 1.0f - percent_g;
80 float percent_b_i = 1.0f - percent_b;
82 cr = (wxUint8)((color0 >> 24) & 0xFF);
83 cg = (wxUint8)((color0 >> 16) & 0xFF);
84 cb = (wxUint8)((color0 >> 8) & 0xFF);
86 for (int i=0; i<256; i++)
89 a = (wxUint8)(col&0x0001);;
90 r = (wxUint8)((float)((col&0xF800) >> 11) / 31.0f * 255.0f);
91 g = (wxUint8)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f);
92 b = (wxUint8)((float)((col&0x003E) >> 1) / 31.0f * 255.0f);
93 r = (wxUint8)(min(255, percent_r_i * r + percent_r * cr));
94 g = (wxUint8)(min(255, percent_g_i * g + percent_g * cg));
95 b = (wxUint8)(min(255, percent_b_i * b + percent_b * cb));
96 rdp.pal_8[i] = (wxUint16)(((wxUint16)(r >> 3) << 11) |
97 ((wxUint16)(g >> 3) << 6) |
98 ((wxUint16)(b >> 3) << 1) |
99 ((wxUint16)(a ) << 0));
103 static void mod_full_color_sub_tex_CI (wxUint32 color)
105 wxUint8 cr, cg, cb, ca;
109 cr = (wxUint8)((color >> 24) & 0xFF);
110 cg = (wxUint8)((color >> 16) & 0xFF);
111 cb = (wxUint8)((color >> 8) & 0xFF);
112 ca = (wxUint8)(color & 0xFF);
114 for (int i=0; i<256; i++)
117 a = (wxUint8)(col&0x0001);;
118 r = (wxUint8)((float)((col&0xF800) >> 11) / 31.0f * 255.0f);
119 g = (wxUint8)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f);
120 b = (wxUint8)((float)((col&0x003E) >> 1) / 31.0f * 255.0f);
125 rdp.pal_8[i] = (wxUint16)(((wxUint16)(r >> 3) << 11) |
126 ((wxUint16)(g >> 3) << 6) |
127 ((wxUint16)(b >> 3) << 1) |
128 ((wxUint16)(a ) << 0));
132 static void mod_col_inter_col1_using_tex_CI (wxUint32 color0, wxUint32 color1)
134 wxUint32 cr0, cg0, cb0, cr1, cg1, cb1;
137 float percent_r, percent_g, percent_b;
139 cr0 = (wxUint8)((color0 >> 24) & 0xFF);
140 cg0 = (wxUint8)((color0 >> 16) & 0xFF);
141 cb0 = (wxUint8)((color0 >> 8) & 0xFF);
142 cr1 = (wxUint8)((color1 >> 24) & 0xFF);
143 cg1 = (wxUint8)((color1 >> 16) & 0xFF);
144 cb1 = (wxUint8)((color1 >> 8) & 0xFF);
146 for (int i=0; i<256; i++)
149 a = (wxUint8)(col&0x0001);;
150 percent_r = ((col&0xF800) >> 11) / 31.0f;
151 percent_g = ((col&0x07C0) >> 6) / 31.0f;
152 percent_b = ((col&0x003E) >> 1) / 31.0f;
153 r = (wxUint8)(min((1.0f-percent_r) * cr0 + percent_r * cr1, 255));
154 g = (wxUint8)(min((1.0f-percent_g) * cg0 + percent_g * cg1, 255));
155 b = (wxUint8)(min((1.0f-percent_b) * cb0 + percent_b * cb1, 255));
156 rdp.pal_8[i] = (wxUint16)(((wxUint16)(r >> 3) << 11) |
157 ((wxUint16)(g >> 3) << 6) |
158 ((wxUint16)(b >> 3) << 1) |
159 ((wxUint16)(a ) << 0));
165 static void mod_tex_sub_col_mul_fac_add_tex_CI (wxUint32 color, wxUint32 factor)
167 float percent = factor / 255.0f;
168 wxUint8 cr, cg, cb, a;
172 cr = (wxUint8)((color >> 24) & 0xFF);
173 cg = (wxUint8)((color >> 16) & 0xFF);
174 cb = (wxUint8)((color >> 8) & 0xFF);
176 for (int i=0; i<256; i++)
179 a = (wxUint8)(col&0x0001);;
180 r = (wxUint8)((float)((col&0xF800) >> 11) / 31.0f * 255.0f);
181 g = (wxUint8)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f);
182 b = (wxUint8)((float)((col&0x003E) >> 1) / 31.0f * 255.0f);
183 r = (r - cr) * percent + r;
184 if (r > 255.0f) r = 255.0f;
185 if (r < 0.0f) r = 0.0f;
186 g = (g - cg) * percent + g;
187 if (g > 255.0f) g = 255.0f;
188 if (g < 0.0f) g = 0.0f;
189 b = (b - cb) * percent + b;
190 if (b > 255.0f) g = 255.0f;
191 if (b < 0.0f) b = 0.0f;
192 rdp.pal_8[i] = (wxUint16)(((wxUint16)((wxUint8)(r) >> 3) << 11) |
193 ((wxUint16)((wxUint8)(g) >> 3) << 6) |
194 ((wxUint16)((wxUint8)(b) >> 3) << 1) |
199 static void mod_tex_scale_col_add_col_CI (wxUint32 color0, wxUint32 color1)
205 float percent_r = ((color0 >> 24) & 0xFF) / 255.0f;
206 float percent_g = ((color0 >> 16) & 0xFF) / 255.0f;
207 float percent_b = ((color0 >> 8) & 0xFF) / 255.0f;
208 cr = (wxUint8)((color1 >> 24) & 0xFF);
209 cg = (wxUint8)((color1 >> 16) & 0xFF);
210 cb = (wxUint8)((color1 >> 8) & 0xFF);
212 for (int i=0; i<256; i++)
215 a = (wxUint8)(col&0x0001);;
216 r = (wxUint8)((float)((col&0xF800) >> 11) / 31.0f * 255.0f);
217 g = (wxUint8)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f);
218 b = (wxUint8)((float)((col&0x003E) >> 1) / 31.0f * 255.0f);
219 r = (wxUint8)(min(255, percent_r * r + cr));
220 g = (wxUint8)(min(255, percent_g * g + cg));
221 b = (wxUint8)(min(255, percent_b * b + cb));
222 rdp.pal_8[i] = (wxUint16)(((wxUint16)(r >> 3) << 11) |
223 ((wxUint16)(g >> 3) << 6) |
224 ((wxUint16)(b >> 3) << 1) |
225 ((wxUint16)(a ) << 0));
229 static void mod_tex_add_col_CI (wxUint32 color)
235 cr = (wxUint8)((color >> 24) & 0xFF);
236 cg = (wxUint8)((color >> 16) & 0xFF);
237 cb = (wxUint8)((color >> 8) & 0xFF);
239 for (int i=0; i<256; i++)
242 a = (wxUint8)(col&0x0001);;
243 r = (wxUint8)((float)((col&0xF800) >> 11) / 31.0f * 255.0f);
244 g = (wxUint8)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f);
245 b = (wxUint8)((float)((col&0x003E) >> 1) / 31.0f * 255.0f);
246 r = min(cr + r, 255);
247 g = min(cg + g, 255);
248 b = min(cb + b, 255);
249 rdp.pal_8[i] = (wxUint16)(((wxUint16)(r >> 3) << 11) |
250 ((wxUint16)(g >> 3) << 6) |
251 ((wxUint16)(b >> 3) << 1) |
252 ((wxUint16)(a ) << 0));
256 static void mod_tex_sub_col_CI (wxUint32 color)
262 cr = (wxUint8)((color >> 24) & 0xFF);
263 cg = (wxUint8)((color >> 16) & 0xFF);
264 cb = (wxUint8)((color >> 8) & 0xFF);
266 for (int i=0; i<256; i++)
269 a = (wxUint8)(col&0x0001);;
270 r = (wxUint8)((float)((col&0xF800) >> 11) / 31.0f * 255.0f);
271 g = (wxUint8)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f);
272 b = (wxUint8)((float)((col&0x003E) >> 1) / 31.0f * 255.0f);
276 rdp.pal_8[i] = (wxUint16)(((wxUint16)(r >> 3) << 11) |
277 ((wxUint16)(g >> 3) << 6) |
278 ((wxUint16)(b >> 3) << 1) |
279 ((wxUint16)(a ) << 0));
283 static void mod_tex_sub_col_mul_fac_CI (wxUint32 color, wxUint32 factor)
285 float percent = factor / 255.0f;
291 cr = (wxUint8)((color >> 24) & 0xFF);
292 cg = (wxUint8)((color >> 16) & 0xFF);
293 cb = (wxUint8)((color >> 8) & 0xFF);
295 for (int i=0; i<256; i++)
298 a = (wxUint8)(col&0x0001);
299 r = (float)((col&0xF800) >> 11) / 31.0f * 255.0f;
300 g = (float)((col&0x07C0) >> 6) / 31.0f * 255.0f;
301 b = (float)((col&0x003E) >> 1) / 31.0f * 255.0f;
302 r = (r - cr) * percent;
303 if (r > 255.0f) r = 255.0f;
304 if (r < 0.0f) r = 0.0f;
305 g = (g - cg) * percent;
306 if (g > 255.0f) g = 255.0f;
307 if (g < 0.0f) g = 0.0f;
308 b = (b - cb) * percent;
309 if (b > 255.0f) g = 255.0f;
310 if (b < 0.0f) b = 0.0f;
312 rdp.pal_8[i] = (wxUint16)(((wxUint16)((wxUint8)(r) >> 3) << 11) |
313 ((wxUint16)((wxUint8)(g) >> 3) << 6) |
314 ((wxUint16)((wxUint8)(b) >> 3) << 1) |
319 static void mod_col_inter_tex_using_col1_CI (wxUint32 color0, wxUint32 color1)
325 float percent_r = ((color1 >> 24) & 0xFF) / 255.0f;
326 float percent_g = ((color1 >> 16) & 0xFF) / 255.0f;
327 float percent_b = ((color1 >> 8) & 0xFF) / 255.0f;
328 float percent_r_i = 1.0f - percent_r;
329 float percent_g_i = 1.0f - percent_g;
330 float percent_b_i = 1.0f - percent_b;
332 cr = (wxUint8)((color0 >> 24) & 0xFF);
333 cg = (wxUint8)((color0 >> 16) & 0xFF);
334 cb = (wxUint8)((color0 >> 8) & 0xFF);
336 for (int i=0; i<256; i++)
339 a = (wxUint8)(col&0x0001);;
340 r = (wxUint8)((float)((col&0xF800) >> 11) / 31.0f * 255.0f);
341 g = (wxUint8)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f);
342 b = (wxUint8)((float)((col&0x003E) >> 1) / 31.0f * 255.0f);
343 r = (wxUint8)(min(255, percent_r * r + percent_r_i * cr));
344 g = (wxUint8)(min(255, percent_g * g + percent_g_i * cg));
345 b = (wxUint8)(min(255, percent_b * b + percent_b_i * cb));
346 rdp.pal_8[i] = (wxUint16)(((wxUint16)(r >> 3) << 11) |
347 ((wxUint16)(g >> 3) << 6) |
348 ((wxUint16)(b >> 3) << 1) |
349 ((wxUint16)(a ) << 0));
353 static void mod_tex_inter_col_using_texa_CI (wxUint32 color)
357 r = (wxUint8)((float)((color >> 24) & 0xFF) / 255.0f * 31.0f);
358 g = (wxUint8)((float)((color >> 16) & 0xFF) / 255.0f * 31.0f);
359 b = (wxUint8)((float)((color >> 8) & 0xFF) / 255.0f * 31.0f);
360 a = (color&0xFF) ? 1 : 0;
361 wxUint16 col16 = (wxUint16)((r<<11)|(g<<6)|(b<<1)|a);
363 for (int i=0; i<256; i++)
366 rdp.pal_8[i] = col16;
370 static void mod_tex_mul_col_CI (wxUint32 color)
376 cr = (float)((color >> 24) & 0xFF) / 255.0f;
377 cg = (float)((color >> 16) & 0xFF) / 255.0f;
378 cb = (float)((color >> 8) & 0xFF) / 255.0f;
380 for (int i=0; i<256; i++)
383 a = (wxUint8)(col&0x0001);;
384 r = (wxUint8)((float)((col&0xF800) >> 11) * cr);
385 g = (wxUint8)((float)((col&0x07C0) >> 6) * cg);
386 b = (wxUint8)((float)((col&0x003E) >> 1) * cb);
387 rdp.pal_8[i] = (wxUint16)(((wxUint16)(r >> 3) << 11) |
388 ((wxUint16)(g >> 3) << 6) |
389 ((wxUint16)(b >> 3) << 1) |
390 ((wxUint16)(a ) << 0));
394 static void ModifyPalette(wxUint32 mod, wxUint32 modcolor, wxUint32 modcolor1, wxUint32 modfactor)
398 case TMOD_TEX_INTER_COLOR_USING_FACTOR:
399 mod_tex_inter_color_using_factor_CI (modcolor, modfactor);
401 case TMOD_TEX_INTER_COL_USING_COL1:
402 mod_tex_inter_col_using_col1_CI (modcolor, modcolor1);
404 case TMOD_FULL_COLOR_SUB_TEX:
405 mod_full_color_sub_tex_CI (modcolor);
407 case TMOD_COL_INTER_COL1_USING_TEX:
408 mod_col_inter_col1_using_tex_CI (modcolor, modcolor1);
410 case TMOD_TEX_SUB_COL_MUL_FAC_ADD_TEX:
411 mod_tex_sub_col_mul_fac_add_tex_CI (modcolor, modfactor);
413 case TMOD_TEX_SCALE_COL_ADD_COL:
414 mod_tex_scale_col_add_col_CI (modcolor, modcolor1);
416 case TMOD_TEX_ADD_COL:
417 mod_tex_add_col_CI (modcolor);
419 case TMOD_TEX_SUB_COL:
420 mod_tex_sub_col_CI (modcolor);
422 case TMOD_TEX_SUB_COL_MUL_FAC:
423 mod_tex_sub_col_mul_fac_CI (modcolor, modfactor);
425 case TMOD_COL_INTER_TEX_USING_COL1:
426 mod_col_inter_tex_using_col1_CI (modcolor, modcolor1);
428 case TMOD_TEX_INTER_COL_USING_TEXA:
429 mod_tex_inter_col_using_texa_CI (modcolor);
431 case TMOD_TEX_MUL_COL:
432 mod_tex_mul_col_CI (modcolor);