Bring back palette optimization

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2022-02-03 16:09:43 +01:00
parent fbd462a6ee
commit 6716b21a4a

View File

@ -123,10 +123,14 @@ final class AdaptivePalette implements Palette {
if (currentPalette instanceof FlexiblePalette flexiblePalette) { if (currentPalette instanceof FlexiblePalette flexiblePalette) {
final int count = flexiblePalette.count(); final int count = flexiblePalette.count();
if (count == 0) { if (count == 0) {
currentPalette = new FilledPalette(dimension, 0); return (this.palette = new FilledPalette(dimension, 0));
this.palette = currentPalette; } else if (count == flexiblePalette.maxSize()) {
var palette = flexiblePalette.paletteToValueList;
if (palette.size() == 2 && palette.getInt(0) == 0) {
// first element is air, second should be the value the palette is filled with
return (this.palette = new FilledPalette(dimension, palette.getInt(1)));
}
} }
// TODO optimize the case where the palette is filled with a single value
} }
return currentPalette; return currentPalette;
} }