2 * Glide64 - Glide video plugin for Nintendo 64 emulators.
3 * Copyright (c) 2002 Dave2001
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 //****************************************************************
22 // Glide64 - Glide Plugin for Nintendo 64 emulators (tested mostly with Project64)
23 // Project started on December 29th, 2001
26 // * 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.
27 // * 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.
29 // Official Glide64 development channel: #Glide64 on EFnet
31 // Original author: Dave2001 (Dave2999@hotmail.com)
32 // Other authors: Gonetz, Gugaman
34 //****************************************************************
40 static void mod_tex_inter_color_using_factor (WORD
*dst
, int size
, DWORD color
, DWORD factor
)
42 float percent
= factor
/ 255.0f
;
43 float percent_i
= 1 - percent
;
48 cr
= (color
>> 12) & 0xF;
49 cg
= (color
>> 8) & 0xF;
50 cb
= (color
>> 4) & 0xF;
52 for (int i
=0; i
<size
; i
++)
56 r
= (BYTE
)(percent_i
* ((col
>> 8) & 0xF) + percent
* cr
);
57 g
= (BYTE
)(percent_i
* ((col
>> 4) & 0xF) + percent
* cg
);
58 b
= (BYTE
)(percent_i
* (col
& 0xF) + percent
* cb
);
59 *(dst
++) = a
| (r
<< 8) | (g
<< 4) | b
;
63 static void mod_tex_inter_col_using_col1 (WORD
*dst
, int size
, DWORD color0
, DWORD color1
)
69 float percent_r
= ((color1
>> 12) & 0xF) / 15.0f
;
70 float percent_g
= ((color1
>> 8) & 0xF) / 15.0f
;
71 float percent_b
= ((color1
>> 4) & 0xF) / 15.0f
;
72 float percent_r_i
= 1.0f
- percent_r
;
73 float percent_g_i
= 1.0f
- percent_g
;
74 float percent_b_i
= 1.0f
- percent_b
;
76 cr
= (color0
>> 12) & 0xF;
77 cg
= (color0
>> 8) & 0xF;
78 cb
= (color0
>> 4) & 0xF;
80 for (int i
=0; i
<size
; i
++)
84 r
= (BYTE
)(percent_r_i
* ((col
>> 8) & 0xF) + percent_r
* cr
);
85 g
= (BYTE
)(percent_g_i
* ((col
>> 4) & 0xF) + percent_g
* cg
);
86 b
= (BYTE
)(percent_b_i
* (col
& 0xF) + percent_b
* cb
);
87 *(dst
++) = a
| (r
<< 8) | (g
<< 4) | b
;
91 static void mod_full_color_sub_tex (WORD
*dst
, int size
, DWORD color
)
97 cr
= (color
>> 12) & 0xF;
98 cg
= (color
>> 8) & 0xF;
99 cb
= (color
>> 4) & 0xF;
102 for (int i
=0; i
<size
; i
++)
105 a
= (BYTE
)(ca
- ((col
>> 12) & 0xF));
106 r
= (BYTE
)(cr
- ((col
>> 8) & 0xF));
107 g
= (BYTE
)(cg
- ((col
>> 4) & 0xF));
108 b
= (BYTE
)(cb
- (col
& 0xF));
109 *(dst
++) = (a
<< 12) | (r
<< 8) | (g
<< 4) | b
;
113 static void mod_col_inter_col1_using_tex (WORD
*dst
, int size
, DWORD color0
, DWORD color1
)
115 DWORD cr0
, cg0
, cb0
, cr1
, cg1
, cb1
;
119 float percent_r
, percent_g
, percent_b
;
121 cr0
= (color0
>> 12) & 0xF;
122 cg0
= (color0
>> 8) & 0xF;
123 cb0
= (color0
>> 4) & 0xF;
124 cr1
= (color1
>> 12) & 0xF;
125 cg1
= (color1
>> 8) & 0xF;
126 cb1
= (color1
>> 4) & 0xF;
128 for (int i
=0; i
<size
; i
++)
132 percent_r
= ((col
>> 8) & 0xF) / 15.0f
;
133 percent_g
= ((col
>> 4) & 0xF) / 15.0f
;
134 percent_b
= (col
& 0xF) / 15.0f
;
135 r
= min(15, (BYTE
)((1.0f
-percent_r
) * cr0
+ percent_r
* cr1
));
136 g
= min(15, (BYTE
)((1.0f
-percent_g
) * cg0
+ percent_g
* cg1
));
137 b
= min(15, (BYTE
)((1.0f
-percent_b
) * cb0
+ percent_b
* cb1
));
138 *(dst
++) = a
| (r
<< 8) | (g
<< 4) | b
;
142 static void mod_col_inter_col1_using_texa (WORD
*dst
, int size
, DWORD color0
, DWORD color1
)
144 DWORD cr0
, cg0
, cb0
, cr1
, cg1
, cb1
;
148 float percent
, percent_i
;
150 cr0
= (color0
>> 12) & 0xF;
151 cg0
= (color0
>> 8) & 0xF;
152 cb0
= (color0
>> 4) & 0xF;
153 cr1
= (color1
>> 12) & 0xF;
154 cg1
= (color1
>> 8) & 0xF;
155 cb1
= (color1
>> 4) & 0xF;
157 for (int i
=0; i
<size
; i
++)
161 percent
= (a
>> 12) / 15.0f
;
162 percent_i
= 1.0f
- percent
;
163 r
= (BYTE
)(percent_i
* cr0
+ percent
* cr1
);
164 g
= (BYTE
)(percent_i
* cg0
+ percent
* cg1
);
165 b
= (BYTE
)(percent_i
* cb0
+ percent
* cb1
);
166 *(dst
++) = a
| (r
<< 8) | (g
<< 4) | b
;
170 static void mod_col_inter_col1_using_texa__mul_tex (WORD
*dst
, int size
, DWORD color0
, DWORD color1
)
172 DWORD cr0
, cg0
, cb0
, cr1
, cg1
, cb1
;
176 float percent
, percent_i
;
178 cr0
= (color0
>> 12) & 0xF;
179 cg0
= (color0
>> 8) & 0xF;
180 cb0
= (color0
>> 4) & 0xF;
181 cr1
= (color1
>> 12) & 0xF;
182 cg1
= (color1
>> 8) & 0xF;
183 cb1
= (color1
>> 4) & 0xF;
185 for (int i
=0; i
<size
; i
++)
189 percent
= (a
>> 12) / 15.0f
;
190 percent_i
= 1.0f
- percent
;
191 r
= (BYTE
)(((percent_i
* cr0
+ percent
* cr1
) / 15.0f
) * (((col
& 0x0F00) >> 8) / 15.0f
) * 15.0f
);
192 g
= (BYTE
)(((percent_i
* cg0
+ percent
* cg1
) / 15.0f
) * (((col
& 0x00F0) >> 4) / 15.0f
) * 15.0f
);
193 b
= (BYTE
)(((percent_i
* cb0
+ percent
* cb1
) / 15.0f
) * ((col
& 0x000F) / 15.0f
) * 15.0f
);
194 *(dst
++) = a
| (r
<< 8) | (g
<< 4) | b
;
198 static void mod_col_inter_tex_using_tex (WORD
*dst
, int size
, DWORD color
)
204 float percent_r
, percent_g
, percent_b
;
206 cr
= (color
>> 12) & 0xF;
207 cg
= (color
>> 8) & 0xF;
208 cb
= (color
>> 4) & 0xF;
210 for (int i
=0; i
<size
; i
++)
214 percent_r
= ((col
>> 8) & 0xF) / 15.0f
;
215 percent_g
= ((col
>> 4) & 0xF) / 15.0f
;
216 percent_b
= (col
& 0xF) / 15.0f
;
217 r
= (BYTE
)((1.0f
-percent_r
) * cr
+ percent_r
* ((col
& 0x0F00) >> 8));
218 g
= (BYTE
)((1.0f
-percent_g
) * cg
+ percent_g
* ((col
& 0x00F0) >> 4));
219 b
= (BYTE
)((1.0f
-percent_b
) * cb
+ percent_b
* (col
& 0x000F));
220 *(dst
++) = a
| (r
<< 8) | (g
<< 4) | b
;
224 static void mod_col_inter_tex_using_texa (WORD
*dst
, int size
, DWORD color
)
230 float percent
, percent_i
;
232 cr
= (color
>> 12) & 0xF;
233 cg
= (color
>> 8) & 0xF;
234 cb
= (color
>> 4) & 0xF;
236 for (int i
=0; i
<size
; i
++)
240 percent
= (a
>> 12) / 15.0f
;
241 percent_i
= 1.0f
- percent
;
242 r
= (BYTE
)(percent_i
* cr
+ percent
* ((col
& 0x0F00) >> 8));
243 g
= (BYTE
)(percent_i
* cg
+ percent
* ((col
& 0x00F0) >> 4));
244 b
= (BYTE
)(percent_i
* cb
+ percent
* (col
& 0x000F));
245 *(dst
++) = a
| (r
<< 8) | (g
<< 4) | b
;
249 static void mod_col2_inter__col_inter_col1_using_tex__using_texa (WORD
*dst
, int size
,
250 DWORD color0
, DWORD color1
,
253 DWORD cr0
, cg0
, cb0
, cr1
, cg1
, cb1
, cr2
, cg2
, cb2
;
257 float percent_r
, percent_g
, percent_b
, percent_a
;
259 cr0
= (color0
>> 12) & 0xF;
260 cg0
= (color0
>> 8) & 0xF;
261 cb0
= (color0
>> 4) & 0xF;
262 cr1
= (color1
>> 12) & 0xF;
263 cg1
= (color1
>> 8) & 0xF;
264 cb1
= (color1
>> 4) & 0xF;
265 cr2
= (color2
>> 12) & 0xF;
266 cg2
= (color2
>> 8) & 0xF;
267 cb2
= (color2
>> 4) & 0xF;
269 for (int i
=0; i
<size
; i
++)
273 percent_a
= (a
>> 12) / 15.0f
;
274 percent_r
= ((col
>> 8) & 0xF) / 15.0f
;
275 percent_g
= ((col
>> 4) & 0xF) / 15.0f
;
276 percent_b
= (col
& 0xF) / 15.0f
;
277 r
= (BYTE
)(((1.0f
-percent_r
) * cr0
+ percent_r
* cr1
) * percent_a
+ cr2
* (1.0f
-percent_a
));
278 g
= (BYTE
)(((1.0f
-percent_g
) * cg0
+ percent_g
* cg1
) * percent_a
+ cg2
* (1.0f
-percent_a
));
279 b
= (BYTE
)(((1.0f
-percent_b
) * cb0
+ percent_b
* cb1
) * percent_a
+ cb2
* (1.0f
-percent_a
));
280 *(dst
++) = a
| (r
<< 8) | (g
<< 4) | b
;
284 static void mod_tex_scale_fac_add_fac (WORD
*dst
, int size
, DWORD factor
)
286 float percent
= factor
/ 255.0f
;
289 float base_a
= (1.0f
- percent
) * 15.0f
;
291 for (int i
=0; i
<size
; i
++)
294 a
= (BYTE
)(base_a
+ percent
* (col
>>12));
295 *(dst
++) = (a
<<12) | (col
& 0x0FFF);
299 static void mod_tex_sub_col_mul_fac_add_tex (WORD
*dst
, int size
, DWORD color
, DWORD factor
)
301 float percent
= factor
/ 255.0f
;
306 cr
= (color
>> 12) & 0xF;
307 cg
= (color
>> 8) & 0xF;
308 cb
= (color
>> 4) & 0xF;
310 for (int i
=0; i
<size
; i
++)
314 r
= (float)((col
>> 8) & 0xF);
315 r
= /*max(*/(r
- cr
) * percent
/*, 0.0f)*/ + r
;
316 if (r
> 15.0f
) r
= 15.0f
;
317 if (r
< 0.0f
) r
= 0.0f
;
318 g
= (float)((col
>> 4) & 0xF);
319 g
= /*max(*/(g
- cg
) * percent
/*, 0.0f)*/ + g
;
320 if (g
> 15.0f
) g
= 15.0f
;
321 if (g
< 0.0f
) g
= 0.0f
;
322 b
= (float)(col
& 0xF);
323 b
= /*max(*/(b
- cb
) * percent
/*, 0.0f)*/ + b
;
324 if (b
> 15.0f
) b
= 15.0f
;
325 if (b
< 0.0f
) b
= 0.0f
;
327 *(dst
++) = a
| ((WORD
)r
<< 8) | ((WORD
)g
<< 4) | (WORD
)b
;
331 static void mod_tex_scale_col_add_col (WORD
*dst
, int size
, DWORD color
, DWORD factor
)
333 float percent
= factor
/ 255.0f
;
334 float percent_r
= (1.0f
- ((color
>>12)&0xF) / 15.0f
) * percent
;
335 float percent_g
= (1.0f
- ((color
>>8)&0xF) / 15.0f
) * percent
;
336 float percent_b
= (1.0f
- ((color
>>4)&0xF) / 15.0f
) * percent
;
338 float base
= (1.0f
- percent
) * 15.0f
;
341 for (int i
=0; i
<size
; i
++)
344 r
= base
+ percent_r
* (float)((col
>>8)&0xF);
345 g
= base
+ percent_g
* (float)((col
>>4)&0xF);
346 b
= base
+ percent_b
* (float)(col
&0xF);
347 *(dst
++) = (col
&0xF000) | ((BYTE
)r
<< 8) | ((BYTE
)g
<< 4) | (BYTE
)b
;
351 static void mod_tex_add_col (WORD
*dst
, int size
, DWORD color
)
353 DWORD cr
, cg
, cb
, ca
;
357 cr
= (color
>> 12) & 0xF;
358 cg
= (color
>> 8) & 0xF;
359 cb
= (color
>> 4) & 0xF;
362 for (int i
=0; i
<size
; i
++)
365 a
= (BYTE
)((col
>> 12) & 0xF);
367 r
= (BYTE
)(cr
+ ((col
>> 8) & 0xF))&0xF;
368 g
= (BYTE
)(cg
+ ((col
>> 4) & 0xF))&0xF;
369 b
= (BYTE
)(cb
+ (col
& 0xF))&0xF;
370 *(dst
++) = (a
<< 12) | (r
<< 8) | (g
<< 4) | b
;
374 static void mod_col_mul_texa_add_tex (WORD
*dst
, int size
, DWORD color
)
382 cr
= (color
>> 12) & 0xF;
383 cg
= (color
>> 8) & 0xF;
384 cb
= (color
>> 4) & 0xF;
386 for (int i
=0; i
<size
; i
++)
390 factor
= (a
>> 12) / 15.0f
;
391 r
= (BYTE
)(cr
*factor
+ ((col
>> 8) & 0xF))&0xF;
392 g
= (BYTE
)(cg
*factor
+ ((col
>> 4) & 0xF))&0xF;
393 b
= (BYTE
)(cb
*factor
+ (col
& 0xF))&0xF;
394 *(dst
++) = a
| (r
<< 8) | (g
<< 4) | b
;
398 static void mod_tex_sub_col (WORD
*dst
, int size
, DWORD color
)
400 DWORD cr
, cg
, cb
, ca
;
404 cr
= (color
>> 12) & 0xF;
405 cg
= (color
>> 8) & 0xF;
406 cb
= (color
>> 4) & 0xF;
409 for (int i
=0; i
<size
; i
++)
412 a
= (BYTE
)(((col
>> 12) & 0xF) - ca
);
413 r
= (BYTE
)(((col
>> 8) & 0xF) - cr
);
414 g
= (BYTE
)(((col
>> 4) & 0xF) - cg
);
415 b
= (BYTE
)((col
& 0xF) - cb
);
416 *(dst
++) = (a
<< 12) | (r
<< 8) | (g
<< 4) | b
;
420 static void mod_tex_sub_col_mul_fac (WORD
*dst
, int size
, DWORD color
, DWORD factor
)
422 float percent
= factor
/ 255.0f
;
427 cr
= (color
>> 12) & 0xF;
428 cg
= (color
>> 8) & 0xF;
429 cb
= (color
>> 4) & 0xF;
431 for (int i
=0; i
<size
; i
++)
434 a
= (BYTE
)((col
>> 12) & 0xF);
435 r
= (float)((col
>> 8) & 0xF);
436 r
= (r
- cr
) * percent
;
437 if (r
> 15.0f
) r
= 15.0f
;
438 if (r
< 0.0f
) r
= 0.0f
;
439 g
= (float)((col
>> 4) & 0xF);
440 g
= (g
- cg
) * percent
;
441 if (g
> 15.0f
) g
= 15.0f
;
442 if (g
< 0.0f
) g
= 0.0f
;
443 b
= (float)(col
& 0xF);
444 b
= (b
- cb
) * percent
;
445 if (b
> 15.0f
) b
= 15.0f
;
446 if (b
< 0.0f
) b
= 0.0f
;
448 *(dst
++) = (a
<< 12) | ((WORD
)r
<< 8) | ((WORD
)g
<< 4) | (WORD
)b
;
452 static void mod_col_inter_tex_using_col1 (WORD
*dst
, int size
, DWORD color0
, DWORD color1
)
458 float percent_r
= ((color1
>> 12) & 0xF) / 15.0f
;
459 float percent_g
= ((color1
>> 8) & 0xF) / 15.0f
;
460 float percent_b
= ((color1
>> 4) & 0xF) / 15.0f
;
461 float percent_r_i
= 1.0f
- percent_r
;
462 float percent_g_i
= 1.0f
- percent_g
;
463 float percent_b_i
= 1.0f
- percent_b
;
465 cr
= (color0
>> 12) & 0xF;
466 cg
= (color0
>> 8) & 0xF;
467 cb
= (color0
>> 4) & 0xF;
469 for (int i
=0; i
<size
; i
++)
472 a
= (BYTE
)((col
>> 12) & 0xF);
473 r
= (BYTE
)(percent_r
* ((col
>> 8) & 0xF) + percent_r_i
* cr
);
474 g
= (BYTE
)(percent_g
* ((col
>> 4) & 0xF) + percent_g_i
* cg
);
475 b
= (BYTE
)(percent_b
* (col
& 0xF) + percent_b_i
* cb
);
476 *(dst
++) = (a
<< 12) | (r
<< 8) | (g
<< 4) | b
;
480 static void mod_tex_inter_noise_using_col (WORD
*dst
, int size
, DWORD color
)
485 float percent_r
= ((color
>> 12) & 0xF) / 15.0f
;
486 float percent_g
= ((color
>> 8) & 0xF) / 15.0f
;
487 float percent_b
= ((color
>> 4) & 0xF) / 15.0f
;
488 float percent_r_i
= 1.0f
- percent_r
;
489 float percent_g_i
= 1.0f
- percent_g
;
490 float percent_b_i
= 1.0f
- percent_b
;
492 for (int i
=0; i
<size
; i
++)
497 r
= (BYTE
)(percent_r_i
* ((col
>> 8) & 0xF) + percent_r
* noise
);
498 g
= (BYTE
)(percent_g_i
* ((col
>> 4) & 0xF) + percent_g
* noise
);
499 b
= (BYTE
)(percent_b_i
* (col
& 0xF) + percent_b
* noise
);
500 *(dst
++) = a
| (r
<< 8) | (g
<< 4) | b
;
504 static void mod_tex_inter_col_using_texa (WORD
*dst
, int size
, DWORD color
)
510 float percent
, percent_i
;
512 cr
= (color
>> 12) & 0xF;
513 cg
= (color
>> 8) & 0xF;
514 cb
= (color
>> 4) & 0xF;
516 for (int i
=0; i
<size
; i
++)
520 percent
= (a
>> 12) / 15.0f
;
521 percent_i
= 1.0f
- percent
;
522 r
= (BYTE
)(percent
* cr
+ percent_i
* ((col
& 0x0F00) >> 8));
523 g
= (BYTE
)(percent
* cg
+ percent_i
* ((col
& 0x00F0) >> 4));
524 b
= (BYTE
)(percent
* cb
+ percent_i
* (col
& 0x000F));
525 *(dst
++) = a
| (r
<< 8) | (g
<< 4) | b
;
529 static void mod_tex_mul_col (WORD
*dst
, int size
, DWORD color
)
535 float percent
, percent_i
;
537 cr
= (float)((color
>> 12) & 0xF)/16.0f
;
538 cg
= (float)((color
>> 8) & 0xF)/16.0f
;
539 cb
= (float)((color
>> 4) & 0xF)/16.0f
;
541 for (int i
=0; i
<size
; i
++)
545 percent
= (a
>> 12) / 15.0f
;
546 percent_i
= 1.0f
- percent
;
547 r
= (BYTE
)(cr
* ((col
& 0x0F00) >> 8));
548 g
= (BYTE
)(cg
* ((col
& 0x00F0) >> 4));
549 b
= (BYTE
)(cb
* (col
& 0x000F));
550 *(dst
++) = a
| (r
<< 8) | (g
<< 4) | b
;
554 static void mod_tex_scale_fac_add_col (WORD
*dst
, int size
, DWORD color
, DWORD factor
)
556 float percent
= factor
/ 255.0f
;
561 cr
= (color
>> 12) & 0xF;
562 cg
= (color
>> 8) & 0xF;
563 cb
= (color
>> 4) & 0xF;
565 for (int i
=0; i
<size
; i
++)
568 r
= cr
+ percent
* (float)((col
>>8)&0xF);
569 g
= cg
+ percent
* (float)((col
>>4)&0xF);
570 b
= cb
+ percent
* (float)(col
&0xF);
571 *(dst
++) = (col
&0xF000) | ((BYTE
)r
<< 8) | ((BYTE
)g
<< 4) | (BYTE
)b
;