Skip to content

Commit 2a5b9b5

Browse files
Rangi42ISSOtm
andauthored
Fix two RGBGFX bugs (#1671)
* Fix two RGBGFX bugs * Fix clang-format idempotence * Update src/gfx/rgba.cpp Co-authored-by: Eldred Habert <[email protected]> --------- Co-authored-by: Eldred Habert <[email protected]>
1 parent a728437 commit 2a5b9b5

19 files changed

+14
-10
lines changed

src/gfx/pal_spec.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,7 @@ static std::optional<U> parseDec(std::string const &str, size_t &n) {
231231
return std::optional<U>{value};
232232
}
233233

234-
static std::optional<Rgba>
235-
parseColor(std::string const &str, size_t &n, uint16_t i) {
234+
static std::optional<Rgba> parseColor(std::string const &str, size_t &n, uint16_t i) {
236235
std::optional<uint8_t> r = parseDec<uint8_t>(str, n);
237236
if (!r) {
238237
error("Failed to parse color #%d (\"%s\"): invalid red component", i + 1, str.c_str());
@@ -602,10 +601,9 @@ void parseExternalPalSpec(char const *arg) {
602601
std::tuple{"GBC", &parseGBCFile, std::ios::binary},
603602
};
604603

605-
auto iter =
606-
std::find_if(RANGE(parsers), [&arg, &ptr](auto const &parser) {
607-
return strncasecmp(arg, std::get<0>(parser), ptr - arg) == 0;
608-
});
604+
auto iter = std::find_if(RANGE(parsers), [&arg, &ptr](auto const &parser) {
605+
return strncasecmp(arg, std::get<0>(parser), ptr - arg) == 0;
606+
});
609607
if (iter == parsers.end()) {
610608
error(
611609
"Unknown external palette format \"%.*s\"",

src/gfx/process.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,9 +604,9 @@ static std::tuple<DefaultInitVec<size_t>, std::vector<Palette>>
604604
// Convert the palette spec to actual palettes
605605
std::vector<Palette> palettes(options.palSpec.size());
606606
for (auto [spec, pal] : zip(options.palSpec, palettes)) {
607-
for (size_t i = 0; i < options.nbColorsPerPal && (!spec[i] || spec[i]->isOpaque()); ++i) {
607+
for (size_t i = 0; i < options.nbColorsPerPal; ++i) {
608608
// If the spec has a gap, there's no need to copy anything.
609-
if (spec[i]) {
609+
if (spec[i].has_value() && !spec[i]->isTransparent()) {
610610
pal[i] = spec[i]->cgbColor();
611611
}
612612
}

src/gfx/rgba.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ uint16_t Rgba::cgbColor() const {
5858

5959
uint8_t Rgba::grayIndex() const {
6060
assume(isGray());
61-
// Convert from [0; 256[ to [0; maxOpaqueColors[
62-
return static_cast<uint16_t>(255 - red) * options.maxOpaqueColors() / 256;
61+
// Convert from 0..<256 to hasTransparentPixels..<nbColorsPerPal
62+
// Note that `maxOpaqueColors()` already takes `hasTransparentPixels` into account
63+
return (255 - red) * options.maxOpaqueColors() / 256 + options.hasTransparentPixels;
6364
}

test/gfx/alpha_embedded.err

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
error: Failed to fit tile colors [$1527, $15cc, $1ab4] in specified palettes
2+
note: The following palette was specified:
3+
[$1ab4, $15cc]
4+
Conversion aborted after 1 error

test/gfx/alpha_embedded.flags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-c embedded

test/gfx/alpha_embedded.png

279 Bytes
Loading

test/gfx/alpha_grayscale.out.2bpp

32 Bytes
Binary file not shown.

test/gfx/alpha_grayscale.out.pal

8 Bytes
Binary file not shown.

test/gfx/alpha_grayscale.out.palmap

2 Bytes
Binary file not shown.

test/gfx/alpha_grayscale.out.tilemap

2 Bytes
Binary file not shown.

test/gfx/alpha_grayscale.png

128 Bytes
Loading

test/gfx/alpha_rgb.out.2bpp

32 Bytes
Binary file not shown.

test/gfx/alpha_rgb.out.pal

16 Bytes
Binary file not shown.

test/gfx/alpha_rgb.out.palmap

2 Bytes
Binary file not shown.

test/gfx/alpha_rgb.out.tilemap

2 Bytes
Binary file not shown.

test/gfx/alpha_rgb.png

128 Bytes
Loading

test/gfx/font_nums.out.2bpp

160 Bytes
Binary file not shown.

test/gfx/font_nums.out.pal

8 Bytes
Binary file not shown.

test/gfx/font_nums.png

312 Bytes
Loading

0 commit comments

Comments
 (0)