diff --git a/include/gfx/rgba.hpp b/include/gfx/rgba.hpp index 3d5e1a45..b86968b9 100644 --- a/include/gfx/rgba.hpp +++ b/include/gfx/rgba.hpp @@ -18,7 +18,10 @@ struct Rgba { : red(rgba >> 24), green(rgba >> 16), blue(rgba >> 8), alpha(rgba) {} static constexpr Rgba fromCGBColor(uint16_t color) { - constexpr auto _5to8 = [](uint8_t c) -> uint8_t { return ((c & 0b11111) * 255 + 15) / 31; }; + constexpr auto _5to8 = [](uint8_t channel) -> uint8_t { + channel &= 0b11111; // For caller's convenience + return channel << 3 | channel >> 2; + }; return { _5to8(color), _5to8(color >> 5), diff --git a/man/rgbasm-old.5 b/man/rgbasm-old.5 index a7b390c3..094c4f31 100644 --- a/man/rgbasm-old.5 +++ b/man/rgbasm-old.5 @@ -461,24 +461,6 @@ Previously we had .Pp Instead, now we have .Ql p ** q ** r == p ** (q ** r) . -.Ss 8-bit and 5-bit color conversion -Changed in 1.0.0. -.Pp -RGBGFX takes 8-bit RGB colors as its PNG input, and outputs 5-bit GBC colors. -Its -.Ql -r/--reverse -mode does the opposite 5-bit to 8-bit conversion. -Instead of the previous inaccurate conversions, we now do accurate rounding to the nearest equivalent. -.Pp -Previously to convert an 8-bit color channel to 5-bit, we truncated it as -.Ql c >> 3 ; -and to reverse a 5-bit color channel to 8-bit, we extended it as -.Ql (c << 3) | (c >> 2) . -.Pp -Instead, now we round 8-bit to 5-bit as -.Ql (c * 31 + 127) / 255 , -and round 5-bit to 8-bit as -.Ql (c * 255 + 15) / 31 . .Sh BUGS These are misfeatures that may have been possible by mistake. They do not get deprecated, just fixed. diff --git a/src/gfx/rgba.cpp b/src/gfx/rgba.cpp index e3f54cc1..ef37eace 100644 --- a/src/gfx/rgba.cpp +++ b/src/gfx/rgba.cpp @@ -50,10 +50,9 @@ uint16_t Rgba::cgbColor() const { g = reverse_curve[g]; b = reverse_curve[b]; } else { - constexpr auto _8to5 = [](uint8_t c) -> uint8_t { return (c * 31 + 127) / 255; }; - r = _8to5(r); - g = _8to5(g); - b = _8to5(b); + r >>= 3; + g >>= 3; + b >>= 3; } return r | g << 5 | b << 10; } diff --git a/test/gfx/alpha_embedded.err b/test/gfx/alpha_embedded.err index d5ecfd17..8efb02a9 100644 --- a/test/gfx/alpha_embedded.err +++ b/test/gfx/alpha_embedded.err @@ -1,4 +1,4 @@ -error: Failed to fit tile colors [$1527, $15cc, $1a93] in specified palettes +error: Failed to fit tile colors [$1527, $15cc, $1ab4] in specified palettes note: The following palette was specified: - [$1a93, $15cc] + [$1ab4, $15cc] Conversion aborted after 1 error diff --git a/test/gfx/at-file-ref.err b/test/gfx/at-file-ref.err index 2de5a93f..f480fa6e 100644 --- a/test/gfx/at-file-ref.err +++ b/test/gfx/at-file-ref.err @@ -1,4 +1,4 @@ -error: Failed to fit tile colors [$688b, $7f55, $7fff] in specified palettes +error: Failed to fit tile colors [$6c8a, $7f55, $7fff] in specified palettes note: The following palettes were specified: [$5f77, $213d, $41a6, $40ee] [$3f65, $36b3, $262a, $50b0] diff --git a/test/gfx/bad_manual_pals.err b/test/gfx/bad_manual_pals.err index 8817b39c..0815a1ff 100644 --- a/test/gfx/bad_manual_pals.err +++ b/test/gfx/bad_manual_pals.err @@ -1,5 +1,5 @@ -error: Failed to fit tile colors [$688b, $7f55, $7fff] in specified palettes +error: Failed to fit tile colors [$6c8a, $7f55, $7fff] in specified palettes note: The following palettes were specified: [$7fff, $7f55] - [$7fff, $688b] + [$7fff, $6c8a] Conversion aborted after 1 error diff --git a/test/gfx/base_ids.out.pal b/test/gfx/base_ids.out.pal index e431fa47..6baa19cf 100644 Binary files a/test/gfx/base_ids.out.pal and b/test/gfx/base_ids.out.pal differ diff --git a/test/gfx/bg_fuse.err b/test/gfx/bg_fuse.err index 47d61d0f..ecbbd45c 100644 --- a/test/gfx/bg_fuse.err +++ b/test/gfx/bg_fuse.err @@ -1,3 +1,3 @@ -warning: Fusing colors #a9bacbff and #aabbccff into Game Boy color $66f5 [first seen at x: 1, y: 1] +warning: Fusing colors #a9b9c9ff and #aabbccff into Game Boy color $66f5 [first seen at x: 1, y: 1] FATAL: Tile (0, 0) contains the background color (#aabbccff)! Conversion aborted after 1 error diff --git a/test/gfx/bg_fuse.png b/test/gfx/bg_fuse.png index e48fb6e2..2fee135f 100644 Binary files a/test/gfx/bg_fuse.png and b/test/gfx/bg_fuse.png differ diff --git a/test/gfx/empty_lines.out.pal b/test/gfx/empty_lines.out.pal index 61337e6c..ca034125 100644 --- a/test/gfx/empty_lines.out.pal +++ b/test/gfx/empty_lines.out.pal @@ -1 +1 @@ -‹hU˙˙˙ \ No newline at end of file +ŠlU˙˙˙ \ No newline at end of file diff --git a/test/gfx/full_aco.out.pal b/test/gfx/full_aco.out.pal index 45edb6b8..820ff240 100644 Binary files a/test/gfx/full_aco.out.pal and b/test/gfx/full_aco.out.pal differ diff --git a/test/gfx/full_aco.png b/test/gfx/full_aco.png index a7b2c255..de5a5849 100644 Binary files a/test/gfx/full_aco.png and b/test/gfx/full_aco.png differ diff --git a/test/gfx/full_act.out.pal b/test/gfx/full_act.out.pal index 45edb6b8..820ff240 100644 Binary files a/test/gfx/full_act.out.pal and b/test/gfx/full_act.out.pal differ diff --git a/test/gfx/full_act.png b/test/gfx/full_act.png index a7b2c255..de5a5849 100644 Binary files a/test/gfx/full_act.png and b/test/gfx/full_act.png differ diff --git a/test/gfx/full_gpl.out.pal b/test/gfx/full_gpl.out.pal index 45edb6b8..820ff240 100644 Binary files a/test/gfx/full_gpl.out.pal and b/test/gfx/full_gpl.out.pal differ diff --git a/test/gfx/full_gpl.png b/test/gfx/full_gpl.png index a7b2c255..de5a5849 100644 Binary files a/test/gfx/full_gpl.png and b/test/gfx/full_gpl.png differ diff --git a/test/gfx/full_psp.out.pal b/test/gfx/full_psp.out.pal index 45edb6b8..820ff240 100644 Binary files a/test/gfx/full_psp.out.pal and b/test/gfx/full_psp.out.pal differ diff --git a/test/gfx/full_psp.png b/test/gfx/full_psp.png index a7b2c255..de5a5849 100644 Binary files a/test/gfx/full_psp.png and b/test/gfx/full_psp.png differ diff --git a/test/gfx/interlaced.out.pal b/test/gfx/interlaced.out.pal index 557777fc..8cdc1c73 100644 Binary files a/test/gfx/interlaced.out.pal and b/test/gfx/interlaced.out.pal differ diff --git a/test/gfx/randtilegen.cpp b/test/gfx/randtilegen.cpp index e4965abc..089de824 100644 --- a/test/gfx/randtilegen.cpp +++ b/test/gfx/randtilegen.cpp @@ -144,7 +144,7 @@ static void generate_palettes(uint16_t palettes[/* 60 */][4]) { * Expand a 5-bit color component to 8 bits with minimal bias */ static uint8_t _5to8(uint8_t five) { - return (five * 255 + 15) / 31; + return five << 3 | five >> 2; } // Can't mark as `const`, as the array type is otherwise not compatible (augh)