Skip to content

Commit

Permalink
PALETTE: identify 6 bit palettes automatically and scale them accordi…
Browse files Browse the repository at this point in the history
…ngly

fixes issue #519
  • Loading branch information
mgerhardy committed Sep 15, 2024
1 parent f45f27a commit 29da205
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/modules/palette/private/RGBPalette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ bool RGBPalette::load(const core::String &filename, io::SeekableReadStream &stre
palette.setColor(i, color);
}
palette.setSize(PaletteMaxColors);

int maxColor = 0;
for (int i = 0; i < PaletteMaxColors; ++i) {
const core::RGBA rgba = palette.color(i);
maxColor = core_max(rgba.r, maxColor);
maxColor = core_max(rgba.g, maxColor);
maxColor = core_max(rgba.b, maxColor);
}
const bool is6Bit = maxColor <= 63;
if (is6Bit) {
const float scale = (255.0f / 63.0f);
for (int i = 0; i < PaletteMaxColors; ++i) {
core::RGBA rgba = palette.color(i);
rgba.r = (float)rgba.r * scale;
rgba.g = (float)rgba.g * scale;
rgba.b = (float)rgba.b * scale;
palette.setColor(i, rgba);
}
}

return true;
}

Expand All @@ -40,4 +60,4 @@ bool RGBPalette::save(const palette::Palette &palette, const core::String &filen
return true;
}

} // namespace voxel
} // namespace palette

0 comments on commit 29da205

Please sign in to comment.