mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Fix two RGBGFX bugs (#1671)
* Fix two RGBGFX bugs * Fix clang-format idempotence * Update src/gfx/rgba.cpp Co-authored-by: Eldred Habert <me@eldred.fr> --------- Co-authored-by: Eldred Habert <me@eldred.fr>
This commit is contained in:
@@ -231,8 +231,7 @@ static std::optional<U> parseDec(std::string const &str, size_t &n) {
|
||||
return std::optional<U>{value};
|
||||
}
|
||||
|
||||
static std::optional<Rgba>
|
||||
parseColor(std::string const &str, size_t &n, uint16_t i) {
|
||||
static std::optional<Rgba> parseColor(std::string const &str, size_t &n, uint16_t i) {
|
||||
std::optional<uint8_t> r = parseDec<uint8_t>(str, n);
|
||||
if (!r) {
|
||||
error("Failed to parse color #%d (\"%s\"): invalid red component", i + 1, str.c_str());
|
||||
@@ -602,10 +601,9 @@ void parseExternalPalSpec(char const *arg) {
|
||||
std::tuple{"GBC", &parseGBCFile, std::ios::binary},
|
||||
};
|
||||
|
||||
auto iter =
|
||||
std::find_if(RANGE(parsers), [&arg, &ptr](auto const &parser) {
|
||||
return strncasecmp(arg, std::get<0>(parser), ptr - arg) == 0;
|
||||
});
|
||||
auto iter = std::find_if(RANGE(parsers), [&arg, &ptr](auto const &parser) {
|
||||
return strncasecmp(arg, std::get<0>(parser), ptr - arg) == 0;
|
||||
});
|
||||
if (iter == parsers.end()) {
|
||||
error(
|
||||
"Unknown external palette format \"%.*s\"",
|
||||
|
||||
@@ -604,9 +604,9 @@ static std::tuple<DefaultInitVec<size_t>, std::vector<Palette>>
|
||||
// Convert the palette spec to actual palettes
|
||||
std::vector<Palette> palettes(options.palSpec.size());
|
||||
for (auto [spec, pal] : zip(options.palSpec, palettes)) {
|
||||
for (size_t i = 0; i < options.nbColorsPerPal && (!spec[i] || spec[i]->isOpaque()); ++i) {
|
||||
for (size_t i = 0; i < options.nbColorsPerPal; ++i) {
|
||||
// If the spec has a gap, there's no need to copy anything.
|
||||
if (spec[i]) {
|
||||
if (spec[i].has_value() && !spec[i]->isTransparent()) {
|
||||
pal[i] = spec[i]->cgbColor();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ uint16_t Rgba::cgbColor() const {
|
||||
|
||||
uint8_t Rgba::grayIndex() const {
|
||||
assume(isGray());
|
||||
// Convert from [0; 256[ to [0; maxOpaqueColors[
|
||||
return static_cast<uint16_t>(255 - red) * options.maxOpaqueColors() / 256;
|
||||
// Convert from 0..<256 to hasTransparentPixels..<nbColorsPerPal
|
||||
// Note that `maxOpaqueColors()` already takes `hasTransparentPixels` into account
|
||||
return (255 - red) * options.maxOpaqueColors() / 256 + options.hasTransparentPixels;
|
||||
}
|
||||
|
||||
4
test/gfx/alpha_embedded.err
Normal file
4
test/gfx/alpha_embedded.err
Normal file
@@ -0,0 +1,4 @@
|
||||
error: Failed to fit tile colors [$1527, $15cc, $1ab4] in specified palettes
|
||||
note: The following palette was specified:
|
||||
[$1ab4, $15cc]
|
||||
Conversion aborted after 1 error
|
||||
1
test/gfx/alpha_embedded.flags
Normal file
1
test/gfx/alpha_embedded.flags
Normal file
@@ -0,0 +1 @@
|
||||
-c embedded
|
||||
BIN
test/gfx/alpha_embedded.png
Normal file
BIN
test/gfx/alpha_embedded.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 279 B |
BIN
test/gfx/alpha_grayscale.out.2bpp
Normal file
BIN
test/gfx/alpha_grayscale.out.2bpp
Normal file
Binary file not shown.
BIN
test/gfx/alpha_grayscale.out.pal
Normal file
BIN
test/gfx/alpha_grayscale.out.pal
Normal file
Binary file not shown.
BIN
test/gfx/alpha_grayscale.out.palmap
Normal file
BIN
test/gfx/alpha_grayscale.out.palmap
Normal file
Binary file not shown.
BIN
test/gfx/alpha_grayscale.out.tilemap
Normal file
BIN
test/gfx/alpha_grayscale.out.tilemap
Normal file
Binary file not shown.
BIN
test/gfx/alpha_grayscale.png
Normal file
BIN
test/gfx/alpha_grayscale.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 128 B |
BIN
test/gfx/alpha_rgb.out.2bpp
Normal file
BIN
test/gfx/alpha_rgb.out.2bpp
Normal file
Binary file not shown.
BIN
test/gfx/alpha_rgb.out.pal
Normal file
BIN
test/gfx/alpha_rgb.out.pal
Normal file
Binary file not shown.
BIN
test/gfx/alpha_rgb.out.palmap
Normal file
BIN
test/gfx/alpha_rgb.out.palmap
Normal file
Binary file not shown.
BIN
test/gfx/alpha_rgb.out.tilemap
Normal file
BIN
test/gfx/alpha_rgb.out.tilemap
Normal file
Binary file not shown.
BIN
test/gfx/alpha_rgb.png
Normal file
BIN
test/gfx/alpha_rgb.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 128 B |
BIN
test/gfx/font_nums.out.2bpp
Normal file
BIN
test/gfx/font_nums.out.2bpp
Normal file
Binary file not shown.
BIN
test/gfx/font_nums.out.pal
Normal file
BIN
test/gfx/font_nums.out.pal
Normal file
Binary file not shown.
BIN
test/gfx/font_nums.png
Normal file
BIN
test/gfx/font_nums.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 312 B |
Reference in New Issue
Block a user