git.y1.nz

SameBoy

Accurate GB/GBC emulator
download: https://git.y1.nz/archives/sameboy.tar.gz
README | Files | Log | Refs | LICENSE

commit 0894c1dcda263a894402220dbc744e9a0f914b00
parent 86a05e25912ec4482064bf5f4bc9636dc296a559
Author: Lior Halphon <LIJI32@gmail.com>
Date:   Fri, 29 Jul 2022 20:31:27 +0300

Avoid rounding errors in color correction, minor optimization

Diffstat:
M.github/actions/sanity_tests.sh4++--
MCore/display.c9+++++++--
2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/.github/actions/sanity_tests.sh b/.github/actions/sanity_tests.sh @@ -16,10 +16,10 @@ set +e FAILED_TESTS=` shasum .github/actions/*.bmp | grep -E -v \(\ -7673e1836eaa28c2967689d0b399f69a597c0c5a\ \ .github/actions/cgb-acid2.bmp\|\ +64c3fd9a5fe9aee40fe15f3371029c0d2f20f5bc\ \ .github/actions/cgb-acid2.bmp\|\ dbcc438dcea13b5d1b80c5cd06bda2592cc5d9e0\ \ .github/actions/cgb_sound.bmp\|\ 0caadf9634e40247ae9c15ff71992e8f77bbf89e\ \ .github/actions/dmg-acid2.bmp\|\ -e3494dcba47af69e8d35fb84c49c272a0d735809\ \ .github/actions/dmg-mode-acid2.bmp\|\ +fbdb5e342bfdd2edda3ea5601d35d0ca60d18034\ \ .github/actions/dmg-mode-acid2.bmp\|\ c9e944b7e01078bdeba1819bc2fa9372b111f52d\ \ .github/actions/dmg_sound-2.bmp\|\ f0172cc91867d3343fbd113a2bb98100074be0de\ \ .github/actions/oam_bug-2.bmp\ \)` diff --git a/Core/display.c b/Core/display.c @@ -281,6 +281,7 @@ uint32_t GB_convert_rgb15(GB_gameboy_t *gb, uint16_t color, bool for_border) if (gb->color_correction_mode != GB_COLOR_CORRECTION_CORRECT_CURVES) { uint8_t new_r, new_g, new_b; + if (g != b) { // Minor optimization double gamma = 2.2; if (gb->color_correction_mode < GB_COLOR_CORRECTION_REDUCE_CONTRAST) { /* Don't use absolutely gamma-correct mixing for the high-contrast @@ -290,10 +291,14 @@ uint32_t GB_convert_rgb15(GB_gameboy_t *gb, uint16_t color, bool for_border) // TODO: Optimze pow out using a LUT if (agb) { - new_g = pow((pow(g / 255.0, gamma) * 5 + pow(b / 255.0, gamma)) / 6, 1 / gamma) * 255; + new_g = round(pow((pow(g / 255.0, gamma) * 5 + pow(b / 255.0, gamma)) / 6, 1 / gamma) * 255); } else { - new_g = pow((pow(g / 255.0, gamma) * 3 + pow(b / 255.0, gamma)) / 4, 1 / gamma) * 255; + new_g = round(pow((pow(g / 255.0, gamma) * 3 + pow(b / 255.0, gamma)) / 4, 1 / gamma) * 255); + } + } + else { + new_g = g; } new_r = r;

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.