all repos — mgba @ a2a306bb0326a1d4e530d08925c614fe1299e948

mGBA Game Boy Advance Emulator

Significantly optimize 16-bit color mixing
Jeffrey Pfau jeffrey@endrift.com
Thu, 14 Nov 2013 00:19:18 -0800
commit

a2a306bb0326a1d4e530d08925c614fe1299e948

parent

620adbd5777f75fbb5d7b01b1ac534d72293f240

1 files changed, 24 insertions(+), 28 deletions(-)

jump to
M src/gba/renderers/video-software.csrc/gba/renderers/video-software.c

@@ -1535,40 +1535,36 @@ static unsigned _mix(int weightA, unsigned colorA, int weightB, unsigned colorB) {

unsigned c = 0; unsigned a, b; #ifdef COLOR_16_BIT - a = colorA & 0x1F; - b = colorB & 0x1F; - c |= ((a * weightA + b * weightB) / 16) & 0x3F; - if (c & 0x0020) { - c = 0x001F; - } - #ifdef COLOR_5_6_5 - a = colorA & 0x7C0; - b = colorB & 0x7C0; - c |= ((a * weightA + b * weightB) / 16) & 0xFC0; - if (c & 0x0800) { - c = (c & 0x001F) | 0x07C0; + a = colorA & ~0x7C0; + b = colorB & ~0x7C0; + a |= (colorA & 0x7C0) << 16; + b |= (colorB & 0x7C0) << 16; + c |= ((a * weightA + b * weightB) / 16); + if (c & 0x0020) { + c = (c & ~0x0020) | 0x001F; } - - a = colorA & 0xF800; - b = colorB & 0xF800; - c |= ((a * weightA + b * weightB) / 16) & 0x1F800; if (c & 0x10000) { - c = (c &0x07FF) | 0xF800; + c = (c & ~0x10000) | 0xF800; } + if (c & 0x08000000) { + c = (c & 0x08000000) | 0x07C00000; + } + c = (c & 0xFFFF) | (c >> 16); #else - a = colorA & 0x3E0; - b = colorB & 0x3E0; - c |= ((a * weightA + b * weightB) / 16) & 0x7E0; - if (c & 0x0400) { - c = (c & 0x001F) | 0x03E0; + a = colorA & ~0x3E0; + b = colorB & ~0x3E0; + a |= (colorA & 0x3E0) << 16; + b |= (colorB & 0x3E0) << 16; + c |= ((a * weightA + b * weightB) / 16); + if (c & 0x0020) { + c = (c & ~0x0020) | 0x001F; } - - a = colorA & 0x7C00; - b = colorB & 0x7C00; - c |= ((a * weightA + b * weightB) / 16) & 0xFC00; - if (c & 0x8000) { - c = (c &0x03FF) | 0x7C00; + if (c & 0x10000) { + c = (c & ~0x10000) | 0xF800; + } + if (c & 0x04000000) { + c = (c & 0x04000000) | 0x03E00000; } #endif #else