mirror of https://github.com/PCSX2/pcsx2.git
pcsx2: Add IPU dithering to RGB32->RGB16 conversion
This commit is contained in:
parent
1ac1bc9a95
commit
f9b51e2656
|
@ -23,12 +23,35 @@
|
||||||
|
|
||||||
__ri void ipu_dither(const macroblock_rgb32 &rgb32, macroblock_rgb16 &rgb16, int dte)
|
__ri void ipu_dither(const macroblock_rgb32 &rgb32, macroblock_rgb16 &rgb16, int dte)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 16; ++i) {
|
if (dte) {
|
||||||
for (int j = 0; j < 16; ++j) {
|
// I'm guessing values are rounded down when clamping.
|
||||||
rgb16.c[i][j].r = rgb32.c[i][j].r >> 3;
|
const int dither_coefficient[4][4] = {
|
||||||
rgb16.c[i][j].g = rgb32.c[i][j].g >> 3;
|
{-4, 0, -3, 1},
|
||||||
rgb16.c[i][j].b = rgb32.c[i][j].b >> 3;
|
{2, -2, 3, -1},
|
||||||
rgb16.c[i][j].a = rgb32.c[i][j].a == 0x40;
|
{-3, 1, -4, 0},
|
||||||
|
{3, -1, 2, -2},
|
||||||
|
};
|
||||||
|
for (int i = 0; i < 16; ++i) {
|
||||||
|
for (int j = 0; j < 16; ++j) {
|
||||||
|
const int dither = dither_coefficient[i & 3][j & 3];
|
||||||
|
const int r = std::max(0, std::min(rgb32.c[i][j].r + dither, 255));
|
||||||
|
const int g = std::max(0, std::min(rgb32.c[i][j].g + dither, 255));
|
||||||
|
const int b = std::max(0, std::min(rgb32.c[i][j].b + dither, 255));
|
||||||
|
|
||||||
|
rgb16.c[i][j].r = r >> 3;
|
||||||
|
rgb16.c[i][j].g = g >> 3;
|
||||||
|
rgb16.c[i][j].b = b >> 3;
|
||||||
|
rgb16.c[i][j].a = rgb32.c[i][j].a == 0x40;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < 16; ++i) {
|
||||||
|
for (int j = 0; j < 16; ++j) {
|
||||||
|
rgb16.c[i][j].r = rgb32.c[i][j].r >> 3;
|
||||||
|
rgb16.c[i][j].g = rgb32.c[i][j].g >> 3;
|
||||||
|
rgb16.c[i][j].b = rgb32.c[i][j].b >> 3;
|
||||||
|
rgb16.c[i][j].a = rgb32.c[i][j].a == 0x40;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue