Stricter resize rule

This commit is contained in:
themode 2022-02-25 22:58:55 +01:00
parent 8839503767
commit 487fbcb5b9

View File

@ -126,11 +126,12 @@ final class AdaptivePalette implements Palette {
// Find all entries and compress the palette // Find all entries and compress the palette
IntSet entries = new IntOpenHashSet(flexiblePalette.paletteToValueList.size()); IntSet entries = new IntOpenHashSet(flexiblePalette.paletteToValueList.size());
flexiblePalette.getAll((x, y, z, value) -> entries.add(value)); flexiblePalette.getAll((x, y, z, value) -> entries.add(value));
final int currentBitsPerEntry = flexiblePalette.bitsPerEntry();
final int bitsPerEntry;
if (entries.size() == 1) { if (entries.size() == 1) {
return new FilledPalette(dimension, entries.iterator().nextInt()); return new FilledPalette(dimension, entries.iterator().nextInt());
} else if (flexiblePalette.bitsPerEntry() > defaultBitsPerEntry) { } else if (currentBitsPerEntry > defaultBitsPerEntry &&
final int bitsPerEntry = MathUtils.bitsToRepresent(entries.size() - 1); (bitsPerEntry = MathUtils.bitsToRepresent(entries.size() - 1)) < currentBitsPerEntry) {
assert bitsPerEntry < flexiblePalette.bitsPerEntry();
flexiblePalette.resize(bitsPerEntry); flexiblePalette.resize(bitsPerEntry);
return flexiblePalette; return flexiblePalette;
} }