mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Implement grayscale DMG palette specs (#1709)
This commit is contained in:
@@ -58,7 +58,15 @@ uint16_t Rgba::cgbColor() const {
|
||||
|
||||
uint8_t Rgba::grayIndex() const {
|
||||
assume(isGray());
|
||||
// Convert from 0..<256 to hasTransparentPixels..<nbColorsPerPal
|
||||
// 2bpp shades are inverted from RGB PNG; %00 = white, %11 = black
|
||||
uint8_t gray = 255 - red;
|
||||
if (options.palSpecType == Options::DMG) {
|
||||
assume(!options.hasTransparentPixels);
|
||||
// Reduce gray shade from 0..<256 to 0..<4, then map to color index,
|
||||
// then reduce to 0..<nbColorsPerPal
|
||||
return options.dmgColors[gray * 4 / 256] * options.nbColorsPerPal / 4;
|
||||
}
|
||||
// Reduce gray shade from 0..<256 to hasTransparentPixels..<nbColorsPerPal
|
||||
// Note that `maxOpaqueColors()` already takes `hasTransparentPixels` into account
|
||||
return (255 - red) * options.maxOpaqueColors() / 256 + options.hasTransparentPixels;
|
||||
return gray * options.maxOpaqueColors() / 256 + options.hasTransparentPixels;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user