mirror of
https://github.com/gbdev/rgbds.git
synced 2026-09-08 23:07:08 +00:00
Fix reversing images with fewer than 4 colors per palette
This commit is contained in:
+4
-3
@@ -216,12 +216,13 @@ void reverse() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
palettes.clear();
|
palettes.clear();
|
||||||
std::array<uint8_t, sizeof(uint16_t) * 4> buf; // 4 colors
|
std::array<uint8_t, sizeof(uint16_t) * 4> buf; // max 4 colors
|
||||||
|
assume(buf.size() >= sizeof(uint16_t) * options.nbColorsPerPal);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (size_t nbRead = file->sgetn(reinterpret_cast<char *>(buf.data()), buf.size());
|
if (size_t nbRead = file->sgetn(reinterpret_cast<char *>(buf.data()), buf.size());
|
||||||
nbRead == 0) {
|
nbRead == 0) {
|
||||||
break;
|
break;
|
||||||
} else if (nbRead != buf.size()) {
|
} else if (nbRead != sizeof(uint16_t) * options.nbColorsPerPal) {
|
||||||
fatal(
|
fatal(
|
||||||
"Palette data size (%zu) is not a multiple of %zu bytes\n",
|
"Palette data size (%zu) is not a multiple of %zu bytes\n",
|
||||||
palettes.size() * buf.size() + nbRead,
|
palettes.size() * buf.size() + nbRead,
|
||||||
@@ -599,7 +600,7 @@ void reverse() {
|
|||||||
if (Rgba const &pixel = *color; pngColorType == PNG_COLOR_TYPE_GRAY) {
|
if (Rgba const &pixel = *color; pngColorType == PNG_COLOR_TYPE_GRAY) {
|
||||||
gray = gray << pngDepth | (pixel.red & ((1 << pngDepth) - 1));
|
gray = gray << pngDepth | (pixel.red & ((1 << pngDepth) - 1));
|
||||||
} else if (pngColorType == PNG_COLOR_TYPE_PALETTE) {
|
} else if (pngColorType == PNG_COLOR_TYPE_PALETTE) {
|
||||||
*ptr++ = palOfs * 4 + colorID;
|
*ptr++ = palOfs * options.nbColorsPerPal + colorID;
|
||||||
} else {
|
} else {
|
||||||
*ptr++ = pixel.red;
|
*ptr++ = pixel.red;
|
||||||
*ptr++ = pixel.green;
|
*ptr++ = pixel.green;
|
||||||
|
|||||||
Binary file not shown.
@@ -0,0 +1,2 @@
|
|||||||
|
-s 2
|
||||||
|
-p reverse_small_palette.pal
|
||||||
Binary file not shown.
Reference in New Issue
Block a user