Path: blob/master/libmupen64plus/mupen64plus-video-glide64mk2/src/Glide64/TexModCI.h
2 views
/*1* Glide64 - Glide video plugin for Nintendo 64 emulators.2* Copyright (c) 2002 Dave20013* Copyright (c) 2003-2009 Sergey 'Gonetz' Lipski4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License as published by7* the Free Software Foundation; either version 2 of the License, or8* any later version.9*10* This program is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13* GNU General Public License for more details.14*15* You should have received a copy of the GNU General Public License16* along with this program; if not, write to the Free Software17* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA18*/1920//****************************************************************21//22// Glide64 - Glide Plugin for Nintendo 64 emulators23// Project started on December 29th, 200124//25// Authors:26// Dave2001, original author, founded the project in 2001, left it in 200227// Gugaman, joined the project in 2002, left it in 200228// Sergey 'Gonetz' Lipski, joined the project in 2002, main author since fall of 200229// Hiroshi 'KoolSmoky' Morii, joined the project in 200730//31//****************************************************************32//33// To modify Glide64:34// * 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.35// * 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.36//37//****************************************************************3839static void mod_tex_inter_color_using_factor_CI (wxUint32 color, wxUint32 factor)40{41float percent = factor / 255.0f;42float percent_i = 1 - percent;43wxUint8 cr, cg, cb;44wxUint16 col;45wxUint8 a, r, g, b;4647cr = (wxUint8)((color >> 24) & 0xFF);48cg = (wxUint8)((color >> 16) & 0xFF);49cb = (wxUint8)((color >> 8) & 0xFF);5051for (int i=0; i<256; i++)52{53col = rdp.pal_8[i];54a = (wxUint8)(col&0x0001);;55r = (wxUint8)((float)((col&0xF800) >> 11) / 31.0f * 255.0f);56g = (wxUint8)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f);57b = (wxUint8)((float)((col&0x003E) >> 1) / 31.0f * 255.0f);58r = (wxUint8)(min(255, percent_i * r + percent * cr));59g = (wxUint8)(min(255, percent_i * g + percent * cg));60b = (wxUint8)(min(255, percent_i * b + percent * cb));61rdp.pal_8[i] = (wxUint16)(((wxUint16)(r >> 3) << 11) |62((wxUint16)(g >> 3) << 6) |63((wxUint16)(b >> 3) << 1) |64((wxUint16)(a ) << 0));65}66}6768static void mod_tex_inter_col_using_col1_CI (wxUint32 color0, wxUint32 color1)69{70wxUint8 cr, cg, cb;71wxUint16 col;72wxUint8 a, r, g, b;7374float percent_r = ((color1 >> 24) & 0xFF) / 255.0f;75float percent_g = ((color1 >> 16) & 0xFF) / 255.0f;76float percent_b = ((color1 >> 8) & 0xFF) / 255.0f;77float percent_r_i = 1.0f - percent_r;78float percent_g_i = 1.0f - percent_g;79float percent_b_i = 1.0f - percent_b;8081cr = (wxUint8)((color0 >> 24) & 0xFF);82cg = (wxUint8)((color0 >> 16) & 0xFF);83cb = (wxUint8)((color0 >> 8) & 0xFF);8485for (int i=0; i<256; i++)86{87col = rdp.pal_8[i];88a = (wxUint8)(col&0x0001);;89r = (wxUint8)((float)((col&0xF800) >> 11) / 31.0f * 255.0f);90g = (wxUint8)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f);91b = (wxUint8)((float)((col&0x003E) >> 1) / 31.0f * 255.0f);92r = (wxUint8)(min(255, percent_r_i * r + percent_r * cr));93g = (wxUint8)(min(255, percent_g_i * g + percent_g * cg));94b = (wxUint8)(min(255, percent_b_i * b + percent_b * cb));95rdp.pal_8[i] = (wxUint16)(((wxUint16)(r >> 3) << 11) |96((wxUint16)(g >> 3) << 6) |97((wxUint16)(b >> 3) << 1) |98((wxUint16)(a ) << 0));99}100}101102static void mod_full_color_sub_tex_CI (wxUint32 color)103{104wxUint8 cr, cg, cb, ca;105wxUint16 col;106wxUint8 a, r, g, b;107108cr = (wxUint8)((color >> 24) & 0xFF);109cg = (wxUint8)((color >> 16) & 0xFF);110cb = (wxUint8)((color >> 8) & 0xFF);111ca = (wxUint8)(color & 0xFF);112113for (int i=0; i<256; i++)114{115col = rdp.pal_8[i];116a = (wxUint8)(col&0x0001);;117r = (wxUint8)((float)((col&0xF800) >> 11) / 31.0f * 255.0f);118g = (wxUint8)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f);119b = (wxUint8)((float)((col&0x003E) >> 1) / 31.0f * 255.0f);120a = max(0, ca - a);121r = max(0, cr - r);122g = max(0, cg - g);123b = max(0, cb - b);124rdp.pal_8[i] = (wxUint16)(((wxUint16)(r >> 3) << 11) |125((wxUint16)(g >> 3) << 6) |126((wxUint16)(b >> 3) << 1) |127((wxUint16)(a ) << 0));128}129}130131static void mod_col_inter_col1_using_tex_CI (wxUint32 color0, wxUint32 color1)132{133wxUint32 cr0, cg0, cb0, cr1, cg1, cb1;134wxUint16 col;135wxUint8 a, r, g, b;136float percent_r, percent_g, percent_b;137138cr0 = (wxUint8)((color0 >> 24) & 0xFF);139cg0 = (wxUint8)((color0 >> 16) & 0xFF);140cb0 = (wxUint8)((color0 >> 8) & 0xFF);141cr1 = (wxUint8)((color1 >> 24) & 0xFF);142cg1 = (wxUint8)((color1 >> 16) & 0xFF);143cb1 = (wxUint8)((color1 >> 8) & 0xFF);144145for (int i=0; i<256; i++)146{147col = rdp.pal_8[i];148a = (wxUint8)(col&0x0001);;149percent_r = ((col&0xF800) >> 11) / 31.0f;150percent_g = ((col&0x07C0) >> 6) / 31.0f;151percent_b = ((col&0x003E) >> 1) / 31.0f;152r = (wxUint8)(min((1.0f-percent_r) * cr0 + percent_r * cr1, 255));153g = (wxUint8)(min((1.0f-percent_g) * cg0 + percent_g * cg1, 255));154b = (wxUint8)(min((1.0f-percent_b) * cb0 + percent_b * cb1, 255));155rdp.pal_8[i] = (wxUint16)(((wxUint16)(r >> 3) << 11) |156((wxUint16)(g >> 3) << 6) |157((wxUint16)(b >> 3) << 1) |158((wxUint16)(a ) << 0));159}160}161162163164static void mod_tex_sub_col_mul_fac_add_tex_CI (wxUint32 color, wxUint32 factor)165{166float percent = factor / 255.0f;167wxUint8 cr, cg, cb, a;168wxUint16 col;169float r, g, b;170171cr = (wxUint8)((color >> 24) & 0xFF);172cg = (wxUint8)((color >> 16) & 0xFF);173cb = (wxUint8)((color >> 8) & 0xFF);174175for (int i=0; i<256; i++)176{177col = rdp.pal_8[i];178a = (wxUint8)(col&0x0001);;179r = (wxUint8)((float)((col&0xF800) >> 11) / 31.0f * 255.0f);180g = (wxUint8)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f);181b = (wxUint8)((float)((col&0x003E) >> 1) / 31.0f * 255.0f);182r = (r - cr) * percent + r;183if (r > 255.0f) r = 255.0f;184if (r < 0.0f) r = 0.0f;185g = (g - cg) * percent + g;186if (g > 255.0f) g = 255.0f;187if (g < 0.0f) g = 0.0f;188b = (b - cb) * percent + b;189if (b > 255.0f) g = 255.0f;190if (b < 0.0f) b = 0.0f;191rdp.pal_8[i] = (wxUint16)(((wxUint16)((wxUint8)(r) >> 3) << 11) |192((wxUint16)((wxUint8)(g) >> 3) << 6) |193((wxUint16)((wxUint8)(b) >> 3) << 1) |194(wxUint16)(a) );195}196}197198static void mod_tex_scale_col_add_col_CI (wxUint32 color0, wxUint32 color1)199{200wxUint8 cr, cg, cb;201wxUint16 col;202wxUint8 a, r, g, b;203204float percent_r = ((color0 >> 24) & 0xFF) / 255.0f;205float percent_g = ((color0 >> 16) & 0xFF) / 255.0f;206float percent_b = ((color0 >> 8) & 0xFF) / 255.0f;207cr = (wxUint8)((color1 >> 24) & 0xFF);208cg = (wxUint8)((color1 >> 16) & 0xFF);209cb = (wxUint8)((color1 >> 8) & 0xFF);210211for (int i=0; i<256; i++)212{213col = rdp.pal_8[i];214a = (wxUint8)(col&0x0001);;215r = (wxUint8)((float)((col&0xF800) >> 11) / 31.0f * 255.0f);216g = (wxUint8)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f);217b = (wxUint8)((float)((col&0x003E) >> 1) / 31.0f * 255.0f);218r = (wxUint8)(min(255, percent_r * r + cr));219g = (wxUint8)(min(255, percent_g * g + cg));220b = (wxUint8)(min(255, percent_b * b + cb));221rdp.pal_8[i] = (wxUint16)(((wxUint16)(r >> 3) << 11) |222((wxUint16)(g >> 3) << 6) |223((wxUint16)(b >> 3) << 1) |224((wxUint16)(a ) << 0));225}226}227228static void mod_tex_add_col_CI (wxUint32 color)229{230wxUint8 cr, cg, cb;231wxUint16 col;232wxUint8 a, r, g, b;233234cr = (wxUint8)((color >> 24) & 0xFF);235cg = (wxUint8)((color >> 16) & 0xFF);236cb = (wxUint8)((color >> 8) & 0xFF);237238for (int i=0; i<256; i++)239{240col = rdp.pal_8[i];241a = (wxUint8)(col&0x0001);;242r = (wxUint8)((float)((col&0xF800) >> 11) / 31.0f * 255.0f);243g = (wxUint8)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f);244b = (wxUint8)((float)((col&0x003E) >> 1) / 31.0f * 255.0f);245r = min(cr + r, 255);246g = min(cg + g, 255);247b = min(cb + b, 255);248rdp.pal_8[i] = (wxUint16)(((wxUint16)(r >> 3) << 11) |249((wxUint16)(g >> 3) << 6) |250((wxUint16)(b >> 3) << 1) |251((wxUint16)(a ) << 0));252}253}254255static void mod_tex_sub_col_CI (wxUint32 color)256{257wxUint8 cr, cg, cb;258wxUint16 col;259wxUint8 a, r, g, b;260261cr = (wxUint8)((color >> 24) & 0xFF);262cg = (wxUint8)((color >> 16) & 0xFF);263cb = (wxUint8)((color >> 8) & 0xFF);264265for (int i=0; i<256; i++)266{267col = rdp.pal_8[i];268a = (wxUint8)(col&0x0001);;269r = (wxUint8)((float)((col&0xF800) >> 11) / 31.0f * 255.0f);270g = (wxUint8)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f);271b = (wxUint8)((float)((col&0x003E) >> 1) / 31.0f * 255.0f);272r = max(r - cr, 0);273g = max(g - cg, 0);274b = max(b - cb, 0);275rdp.pal_8[i] = (wxUint16)(((wxUint16)(r >> 3) << 11) |276((wxUint16)(g >> 3) << 6) |277((wxUint16)(b >> 3) << 1) |278((wxUint16)(a ) << 0));279}280}281282static void mod_tex_sub_col_mul_fac_CI (wxUint32 color, wxUint32 factor)283{284float percent = factor / 255.0f;285wxUint8 cr, cg, cb;286wxUint16 col;287wxUint8 a;288float r, g, b;289290cr = (wxUint8)((color >> 24) & 0xFF);291cg = (wxUint8)((color >> 16) & 0xFF);292cb = (wxUint8)((color >> 8) & 0xFF);293294for (int i=0; i<256; i++)295{296col = rdp.pal_8[i];297a = (wxUint8)(col&0x0001);298r = (float)((col&0xF800) >> 11) / 31.0f * 255.0f;299g = (float)((col&0x07C0) >> 6) / 31.0f * 255.0f;300b = (float)((col&0x003E) >> 1) / 31.0f * 255.0f;301r = (r - cr) * percent;302if (r > 255.0f) r = 255.0f;303if (r < 0.0f) r = 0.0f;304g = (g - cg) * percent;305if (g > 255.0f) g = 255.0f;306if (g < 0.0f) g = 0.0f;307b = (b - cb) * percent;308if (b > 255.0f) g = 255.0f;309if (b < 0.0f) b = 0.0f;310311rdp.pal_8[i] = (wxUint16)(((wxUint16)((wxUint8)(r) >> 3) << 11) |312((wxUint16)((wxUint8)(g) >> 3) << 6) |313((wxUint16)((wxUint8)(b) >> 3) << 1) |314(wxUint16)(a) );315}316}317318static void mod_col_inter_tex_using_col1_CI (wxUint32 color0, wxUint32 color1)319{320wxUint8 cr, cg, cb;321wxUint16 col;322wxUint8 a, r, g, b;323324float percent_r = ((color1 >> 24) & 0xFF) / 255.0f;325float percent_g = ((color1 >> 16) & 0xFF) / 255.0f;326float percent_b = ((color1 >> 8) & 0xFF) / 255.0f;327float percent_r_i = 1.0f - percent_r;328float percent_g_i = 1.0f - percent_g;329float percent_b_i = 1.0f - percent_b;330331cr = (wxUint8)((color0 >> 24) & 0xFF);332cg = (wxUint8)((color0 >> 16) & 0xFF);333cb = (wxUint8)((color0 >> 8) & 0xFF);334335for (int i=0; i<256; i++)336{337col = rdp.pal_8[i];338a = (wxUint8)(col&0x0001);;339r = (wxUint8)((float)((col&0xF800) >> 11) / 31.0f * 255.0f);340g = (wxUint8)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f);341b = (wxUint8)((float)((col&0x003E) >> 1) / 31.0f * 255.0f);342r = (wxUint8)(min(255, percent_r * r + percent_r_i * cr));343g = (wxUint8)(min(255, percent_g * g + percent_g_i * cg));344b = (wxUint8)(min(255, percent_b * b + percent_b_i * cb));345rdp.pal_8[i] = (wxUint16)(((wxUint16)(r >> 3) << 11) |346((wxUint16)(g >> 3) << 6) |347((wxUint16)(b >> 3) << 1) |348((wxUint16)(a ) << 0));349}350}351352static void mod_tex_inter_col_using_texa_CI (wxUint32 color)353{354wxUint8 a, r, g, b;355356r = (wxUint8)((float)((color >> 24) & 0xFF) / 255.0f * 31.0f);357g = (wxUint8)((float)((color >> 16) & 0xFF) / 255.0f * 31.0f);358b = (wxUint8)((float)((color >> 8) & 0xFF) / 255.0f * 31.0f);359a = (color&0xFF) ? 1 : 0;360wxUint16 col16 = (wxUint16)((r<<11)|(g<<6)|(b<<1)|a);361362for (int i=0; i<256; i++)363{364if (rdp.pal_8[i]&1)365rdp.pal_8[i] = col16;366}367}368369static void mod_tex_mul_col_CI (wxUint32 color)370{371wxUint8 a, r, g, b;372wxUint16 col;373float cr, cg, cb;374375cr = (float)((color >> 24) & 0xFF) / 255.0f;376cg = (float)((color >> 16) & 0xFF) / 255.0f;377cb = (float)((color >> 8) & 0xFF) / 255.0f;378379for (int i=0; i<256; i++)380{381col = rdp.pal_8[i];382a = (wxUint8)(col&0x0001);;383r = (wxUint8)((float)((col&0xF800) >> 11) * cr);384g = (wxUint8)((float)((col&0x07C0) >> 6) * cg);385b = (wxUint8)((float)((col&0x003E) >> 1) * cb);386rdp.pal_8[i] = (wxUint16)(((wxUint16)(r >> 3) << 11) |387((wxUint16)(g >> 3) << 6) |388((wxUint16)(b >> 3) << 1) |389((wxUint16)(a ) << 0));390}391}392393static void ModifyPalette(wxUint32 mod, wxUint32 modcolor, wxUint32 modcolor1, wxUint32 modfactor)394{395switch (mod)396{397case TMOD_TEX_INTER_COLOR_USING_FACTOR:398mod_tex_inter_color_using_factor_CI (modcolor, modfactor);399break;400case TMOD_TEX_INTER_COL_USING_COL1:401mod_tex_inter_col_using_col1_CI (modcolor, modcolor1);402break;403case TMOD_FULL_COLOR_SUB_TEX:404mod_full_color_sub_tex_CI (modcolor);405break;406case TMOD_COL_INTER_COL1_USING_TEX:407mod_col_inter_col1_using_tex_CI (modcolor, modcolor1);408break;409case TMOD_TEX_SUB_COL_MUL_FAC_ADD_TEX:410mod_tex_sub_col_mul_fac_add_tex_CI (modcolor, modfactor);411break;412case TMOD_TEX_SCALE_COL_ADD_COL:413mod_tex_scale_col_add_col_CI (modcolor, modcolor1);414break;415case TMOD_TEX_ADD_COL:416mod_tex_add_col_CI (modcolor);417break;418case TMOD_TEX_SUB_COL:419mod_tex_sub_col_CI (modcolor);420break;421case TMOD_TEX_SUB_COL_MUL_FAC:422mod_tex_sub_col_mul_fac_CI (modcolor, modfactor);423break;424case TMOD_COL_INTER_TEX_USING_COL1:425mod_col_inter_tex_using_col1_CI (modcolor, modcolor1);426break;427case TMOD_TEX_INTER_COL_USING_TEXA:428mod_tex_inter_col_using_texa_CI (modcolor);429break;430case TMOD_TEX_MUL_COL:431mod_tex_mul_col_CI (modcolor);432break;433default:434;435}436}437438439