From 616648663587c89d5ef085f095caf977857ccb90 Mon Sep 17 00:00:00 2001 From: Rok Mandeljc Date: Thu, 5 Oct 2023 13:38:32 +0200 Subject: [PATCH] PngBuilder: fix switch from 4-bit to 8-bit palette The switch from 4-bit to 8-bit palette should happen when number of colors exceeds 16. --- src/BigGustave/PngBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BigGustave/PngBuilder.cs b/src/BigGustave/PngBuilder.cs index 923eb4b..53727b3 100644 --- a/src/BigGustave/PngBuilder.cs +++ b/src/BigGustave/PngBuilder.cs @@ -287,7 +287,7 @@ public void Save(Stream outputStream, SaveOptions options = null) if (!hasTooManyColorsForPalette && !hasAlphaChannel) { var paletteColors = colorCounts.OrderByDescending(x => x.Value).Select(x => x.Key).ToList(); - bitDepth = paletteColors.Count >= 128 ? 8 : 4; + bitDepth = paletteColors.Count > 16 ? 8 : 4; var samplesPerByte = bitDepth == 8 ? 1 : 2; var applyShift = samplesPerByte == 2;