1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
|
/*
* Glide64 - Glide video plugin for Nintendo 64 emulators.
* Copyright (c) 2002 Dave2001
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA
*/
//****************************************************************
//
// Glide64 - Glide Plugin for Nintendo 64 emulators (tested mostly with Project64)
// Project started on December 29th, 2001
//
// To modify Glide64:
// * 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.
// * 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.
//
// Official Glide64 development channel: #Glide64 on EFnet
//
// Original author: Dave2001 (Dave2999@hotmail.com)
// Other authors: Gonetz, Gugaman
//
//****************************************************************
#ifndef _WIN32
#define mini(a,b) ((a) < (b) ? (a) : (b))
#define maxi(a,b) ((a) > (b) ? (a) : (b))
#endif // _WIN32
static void mod_tex_inter_color_using_factor_CI (DWORD color, DWORD factor)
{
float percent = factor / 255.0f;
float percent_i = 1 - percent;
BYTE cr, cg, cb;
WORD col;
BYTE a, r, g, b;
cr = (BYTE)((color >> 24) & 0xFF);
cg = (BYTE)((color >> 16) & 0xFF);
cb = (BYTE)((color >> 8) & 0xFF);
for (int i=0; i<256; i++)
{
col = rdp.pal_8[i];
a = (BYTE)(col&0x0001);;
r = (BYTE)((float)((col&0xF800) >> 11) / 31.0f * 255.0f);
g = (BYTE)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f);
b = (BYTE)((float)((col&0x003E) >> 1) / 31.0f * 255.0f);
r = (BYTE)(mini(255, percent_i * r + percent * cr));
g = (BYTE)(mini(255, percent_i * g + percent * cg));
b = (BYTE)(mini(255, percent_i * b + percent * cb));
rdp.pal_8[i] = (WORD)(((WORD)(r >> 3) << 11) |
((WORD)(g >> 3) << 6) |
((WORD)(b >> 3) << 1) |
((WORD)(a ) << 0));
}
}
static void mod_tex_inter_col_using_col1_CI (DWORD color0, DWORD color1)
{
BYTE cr, cg, cb;
WORD col;
BYTE a, r, g, b;
float percent_r = ((color1 >> 24) & 0xFF) / 255.0f;
float percent_g = ((color1 >> 16) & 0xFF) / 255.0f;
float percent_b = ((color1 >> 8) & 0xFF) / 255.0f;
float percent_r_i = 1.0f - percent_r;
float percent_g_i = 1.0f - percent_g;
float percent_b_i = 1.0f - percent_b;
cr = (BYTE)((color0 >> 24) & 0xFF);
cg = (BYTE)((color0 >> 16) & 0xFF);
cb = (BYTE)((color0 >> 8) & 0xFF);
for (int i=0; i<256; i++)
{
col = rdp.pal_8[i];
a = (BYTE)(col&0x0001);;
r = (BYTE)((float)((col&0xF800) >> 11) / 31.0f * 255.0f);
g = (BYTE)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f);
b = (BYTE)((float)((col&0x003E) >> 1) / 31.0f * 255.0f);
r = (BYTE)(mini(255, percent_r_i * r + percent_r * cr));
g = (BYTE)(mini(255, percent_g_i * g + percent_g * cg));
b = (BYTE)(mini(255, percent_b_i * b + percent_b * cb));
rdp.pal_8[i] = (WORD)(((WORD)(r >> 3) << 11) |
((WORD)(g >> 3) << 6) |
((WORD)(b >> 3) << 1) |
((WORD)(a ) << 0));
}
}
static void mod_full_color_sub_tex_CI (DWORD color)
{
BYTE cr, cg, cb, ca;
WORD col;
BYTE a, r, g, b;
cr = (BYTE)((color >> 24) & 0xFF);
cg = (BYTE)((color >> 16) & 0xFF);
cb = (BYTE)((color >> 8) & 0xFF);
ca = (BYTE)(color & 0xFF);
for (int i=0; i<256; i++)
{
col = rdp.pal_8[i];
a = (BYTE)(col&0x0001);;
r = (BYTE)((float)((col&0xF800) >> 11) / 31.0f * 255.0f);
g = (BYTE)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f);
b = (BYTE)((float)((col&0x003E) >> 1) / 31.0f * 255.0f);
a = maxi(0, ca - a);
r = maxi(0, cr - r);
g = maxi(0, cg - g);
b = maxi(0, cb - b);
rdp.pal_8[i] = (WORD)(((WORD)(r >> 3) << 11) |
((WORD)(g >> 3) << 6) |
((WORD)(b >> 3) << 1) |
((WORD)(a ) << 0));
}
}
static void mod_col_inter_col1_using_tex_CI (DWORD color0, DWORD color1)
{
DWORD cr0, cg0, cb0, cr1, cg1, cb1;
WORD col;
BYTE a, r, g, b;
float percent_r, percent_g, percent_b;
cr0 = (BYTE)((color0 >> 24) & 0xFF);
cg0 = (BYTE)((color0 >> 16) & 0xFF);
cb0 = (BYTE)((color0 >> 8) & 0xFF);
cr1 = (BYTE)((color1 >> 24) & 0xFF);
cg1 = (BYTE)((color1 >> 16) & 0xFF);
cb1 = (BYTE)((color1 >> 8) & 0xFF);
for (int i=0; i<256; i++)
{
col = rdp.pal_8[i];
a = (BYTE)(col&0x0001);;
percent_r = ((col&0xF800) >> 11) / 31.0f;
percent_g = ((col&0x07C0) >> 6) / 31.0f;
percent_b = ((col&0x003E) >> 1) / 31.0f;
r = (BYTE)(mini((1.0f-percent_r) * cr0 + percent_r * cr1, 255));
g = (BYTE)(mini((1.0f-percent_g) * cg0 + percent_g * cg1, 255));
b = (BYTE)(mini((1.0f-percent_b) * cb0 + percent_b * cb1, 255));
rdp.pal_8[i] = (WORD)(((WORD)(r >> 3) << 11) |
((WORD)(g >> 3) << 6) |
((WORD)(b >> 3) << 1) |
((WORD)(a ) << 0));
}
}
static void mod_tex_sub_col_mul_fac_add_tex_CI (DWORD color, DWORD factor)
{
float percent = factor / 255.0f;
BYTE cr, cg, cb, a;
WORD col;
float r, g, b;
cr = (BYTE)((color >> 24) & 0xFF);
cg = (BYTE)((color >> 16) & 0xFF);
cb = (BYTE)((color >> 8) & 0xFF);
for (int i=0; i<256; i++)
{
col = rdp.pal_8[i];
a = (BYTE)(col&0x0001);;
r = (BYTE)((float)((col&0xF800) >> 11) / 31.0f * 255.0f);
g = (BYTE)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f);
b = (BYTE)((float)((col&0x003E) >> 1) / 31.0f * 255.0f);
r = (r - cr) * percent + r;
if (r > 255.0f) r = 255.0f;
if (r < 0.0f) r = 0.0f;
g = (g - cg) * percent + g;
if (g > 255.0f) g = 255.0f;
if (g < 0.0f) g = 0.0f;
b = (b - cb) * percent + b;
if (b > 255.0f) g = 255.0f;
if (b < 0.0f) b = 0.0f;
rdp.pal_8[i] = (WORD)(((WORD)((BYTE)(r) >> 3) << 11) |
((WORD)((BYTE)(g) >> 3) << 6) |
((WORD)((BYTE)(b) >> 3) << 1) |
(WORD)(a) );
}
}
static void mod_tex_scale_col_add_col_CI (DWORD color, DWORD factor)
{
float percent = factor / 255.0f;
float percent_r = (1.0f - ((color >> 24) & 0xFF) / 255.0f) * percent;
float percent_g = (1.0f - ((color >> 16) & 0xFF) / 255.0f) * percent;
float percent_b = (1.0f - ((color >> 8) & 0xFF) / 255.0f) * percent;
WORD col;
float base = (1.0f - percent) * 255.0f;
BYTE a, r, g, b;
for (int i=0; i<256; i++)
{
col = rdp.pal_8[i];
a = (BYTE)(col&0x0001);;
r = (BYTE)((float)((col&0xF800) >> 11) / 31.0f * 255.0f);
g = (BYTE)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f);
b = (BYTE)((float)((col&0x003E) >> 1) / 31.0f * 255.0f);
r = (BYTE)(mini(base + percent_r * r, 255));
g = (BYTE)(mini(base + percent_g * g, 255));
b = (BYTE)(mini(base + percent_b * b, 255));
rdp.pal_8[i] = (WORD)(((WORD)(r >> 3) << 11) |
((WORD)(g >> 3) << 6) |
((WORD)(b >> 3) << 1) |
(WORD)(a) );
}
}
static void mod_tex_add_col_CI (DWORD color)
{
BYTE cr, cg, cb;
WORD col;
BYTE a, r, g, b;
cr = (BYTE)((color >> 24) & 0xFF);
cg = (BYTE)((color >> 16) & 0xFF);
cb = (BYTE)((color >> 8) & 0xFF);
for (int i=0; i<256; i++)
{
col = rdp.pal_8[i];
a = (BYTE)(col&0x0001);;
r = (BYTE)((float)((col&0xF800) >> 11) / 31.0f * 255.0f);
g = (BYTE)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f);
b = (BYTE)((float)((col&0x003E) >> 1) / 31.0f * 255.0f);
r = mini(cr + r, 255);
g = mini(cg + g, 255);
b = mini(cb + b, 255);
rdp.pal_8[i] = (WORD)(((WORD)(r >> 3) << 11) |
((WORD)(g >> 3) << 6) |
((WORD)(b >> 3) << 1) |
((WORD)(a ) << 0));
}
}
static void mod_tex_sub_col_CI (DWORD color)
{
BYTE cr, cg, cb;
WORD col;
BYTE a, r, g, b;
cr = (BYTE)((color >> 24) & 0xFF);
cg = (BYTE)((color >> 16) & 0xFF);
cb = (BYTE)((color >> 8) & 0xFF);
for (int i=0; i<256; i++)
{
col = rdp.pal_8[i];
a = (BYTE)(col&0x0001);;
r = (BYTE)((float)((col&0xF800) >> 11) / 31.0f * 255.0f);
g = (BYTE)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f);
b = (BYTE)((float)((col&0x003E) >> 1) / 31.0f * 255.0f);
r = maxi(r - cr, 0);
g = maxi(g - cg, 0);
b = maxi(b - cb, 0);
rdp.pal_8[i] = (WORD)(((WORD)(r >> 3) << 11) |
((WORD)(g >> 3) << 6) |
((WORD)(b >> 3) << 1) |
((WORD)(a ) << 0));
}
}
static void mod_tex_sub_col_mul_fac_CI (DWORD color, DWORD factor)
{
float percent = factor / 255.0f;
BYTE cr, cg, cb;
WORD col;
BYTE a;
float r, g, b;
cr = (BYTE)((color >> 24) & 0xFF);
cg = (BYTE)((color >> 16) & 0xFF);
cb = (BYTE)((color >> 8) & 0xFF);
for (int i=0; i<256; i++)
{
col = rdp.pal_8[i];
a = (BYTE)(col&0x0001);
r = (float)((col&0xF800) >> 11) / 31.0f * 255.0f;
g = (float)((col&0x07C0) >> 6) / 31.0f * 255.0f;
b = (float)((col&0x003E) >> 1) / 31.0f * 255.0f;
r = (r - cr) * percent;
if (r > 255.0f) r = 255.0f;
if (r < 0.0f) r = 0.0f;
g = (g - cg) * percent;
if (g > 255.0f) g = 255.0f;
if (g < 0.0f) g = 0.0f;
b = (b - cb) * percent;
if (b > 255.0f) g = 255.0f;
if (b < 0.0f) b = 0.0f;
rdp.pal_8[i] = (WORD)(((WORD)((BYTE)(r) >> 3) << 11) |
((WORD)((BYTE)(g) >> 3) << 6) |
((WORD)((BYTE)(b) >> 3) << 1) |
(WORD)(a) );
}
}
static void mod_col_inter_tex_using_col1_CI (DWORD color0, DWORD color1)
{
BYTE cr, cg, cb;
WORD col;
BYTE a, r, g, b;
float percent_r = ((color1 >> 24) & 0xFF) / 255.0f;
float percent_g = ((color1 >> 16) & 0xFF) / 255.0f;
float percent_b = ((color1 >> 8) & 0xFF) / 255.0f;
float percent_r_i = 1.0f - percent_r;
float percent_g_i = 1.0f - percent_g;
float percent_b_i = 1.0f - percent_b;
cr = (BYTE)((color0 >> 24) & 0xFF);
cg = (BYTE)((color0 >> 16) & 0xFF);
cb = (BYTE)((color0 >> 8) & 0xFF);
for (int i=0; i<256; i++)
{
col = rdp.pal_8[i];
a = (BYTE)(col&0x0001);;
r = (BYTE)((float)((col&0xF800) >> 11) / 31.0f * 255.0f);
g = (BYTE)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f);
b = (BYTE)((float)((col&0x003E) >> 1) / 31.0f * 255.0f);
r = (BYTE)(mini(255, percent_r * r + percent_r_i * cr));
g = (BYTE)(mini(255, percent_g * g + percent_g_i * cg));
b = (BYTE)(mini(255, percent_b * b + percent_b_i * cb));
rdp.pal_8[i] = (WORD)(((WORD)(r >> 3) << 11) |
((WORD)(g >> 3) << 6) |
((WORD)(b >> 3) << 1) |
((WORD)(a ) << 0));
}
}
static void mod_tex_inter_col_using_texa_CI (DWORD color)
{
BYTE a, r, g, b;
r = (BYTE)((float)((color >> 24) & 0xFF) / 255.0f * 31.0f);
g = (BYTE)((float)((color >> 16) & 0xFF) / 255.0f * 31.0f);
b = (BYTE)((float)((color >> 8) & 0xFF) / 255.0f * 31.0f);
a = (color&0xFF) ? 1 : 0;
WORD col16 = (WORD)((r<<11)|(g<<6)|(b<<1)|a);
for (int i=0; i<256; i++)
{
if (rdp.pal_8[i]&1)
rdp.pal_8[i] = col16;
}
}
static void mod_tex_mul_col_CI (DWORD color)
{
BYTE a, r, g, b;
WORD col;
float cr, cg, cb;
cr = (float)((color >> 24) & 0xFF) / 255.0f;
cg = (float)((color >> 16) & 0xFF) / 255.0f;
cb = (float)((color >> 8) & 0xFF) / 255.0f;
for (int i=0; i<256; i++)
{
col = rdp.pal_8[i];
a = (BYTE)(col&0x0001);;
r = (BYTE)((float)((col&0xF800) >> 11) * cr);
g = (BYTE)((float)((col&0x07C0) >> 6) * cg);
b = (BYTE)((float)((col&0x003E) >> 1) * cb);
rdp.pal_8[i] = (WORD)(((WORD)(r >> 3) << 11) |
((WORD)(g >> 3) << 6) |
((WORD)(b >> 3) << 1) |
((WORD)(a ) << 0));
}
}
static void ModifyPalette(DWORD mod, DWORD modcolor, DWORD modcolor1, DWORD modfactor)
{
switch (mod)
{
case TMOD_TEX_INTER_COLOR_USING_FACTOR:
mod_tex_inter_color_using_factor_CI (modcolor, modfactor);
break;
case TMOD_TEX_INTER_COL_USING_COL1:
mod_tex_inter_col_using_col1_CI (modcolor, modcolor1);
break;
case TMOD_FULL_COLOR_SUB_TEX:
mod_full_color_sub_tex_CI (modcolor);
break;
case TMOD_COL_INTER_COL1_USING_TEX:
mod_col_inter_col1_using_tex_CI (modcolor, modcolor1);
break;
case TMOD_TEX_SUB_COL_MUL_FAC_ADD_TEX:
mod_tex_sub_col_mul_fac_add_tex_CI (modcolor, modfactor);
break;
case TMOD_TEX_SCALE_COL_ADD_COL:
mod_tex_scale_col_add_col_CI (modcolor, modfactor);
break;
case TMOD_TEX_ADD_COL:
mod_tex_add_col_CI (modcolor);
break;
case TMOD_TEX_SUB_COL:
mod_tex_sub_col_CI (modcolor);
break;
case TMOD_TEX_SUB_COL_MUL_FAC:
mod_tex_sub_col_mul_fac_CI (modcolor, modfactor);
break;
case TMOD_COL_INTER_TEX_USING_COL1:
mod_col_inter_tex_using_col1_CI (modcolor, modcolor1);
break;
case TMOD_TEX_INTER_COL_USING_TEXA:
mod_tex_inter_col_using_texa_CI (modcolor);
break;
case TMOD_TEX_MUL_COL:
mod_tex_mul_col_CI (modcolor);
break;
default:
;
}
}
|