From 64803bc23d1f25ac5144bd0d9a9f107363817cbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaarlo=20R=C3=A4ih=C3=A4?= Date: Mon, 6 Jun 2022 19:34:48 +0300 Subject: [PATCH] Add C64 color reduction palette New feature --- CHANGE-LOG.md | 3 +++ ColorReductions.cs | 25 +++++++++++++++++++++++++ Program.cs | 5 ++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/CHANGE-LOG.md b/CHANGE-LOG.md index 1295154..699cbaf 100644 --- a/CHANGE-LOG.md +++ b/CHANGE-LOG.md @@ -1,3 +1,6 @@ +## Version 1.0.5 (released 2021-11-11) +- Add C64 color reduction palette + ## Version 1.0.4 (released 2021-11-11) - Nuget release also for .NET 6 diff --git a/ColorReductions.cs b/ColorReductions.cs index 1fa9805..8f0f02f 100644 --- a/ColorReductions.cs +++ b/ColorReductions.cs @@ -46,6 +46,31 @@ public static void TrueColorBytesToCGABytes(in byte[] input, ref byte[] output) output = FindNearestColor(input, fullCGAColors); } + private static readonly List c64Colors = new List() + { + new byte[] { 0x00, 0x00, 0x00 }, // black + new byte[] { 0xFF, 0xFF, 0xFF }, // white + new byte[] { 0x88, 0x00, 0x00 }, // red + new byte[] { 0xAA, 0xFF, 0xEE }, // cyan + new byte[] { 0xCC, 0x44, 0xCC }, // violet / purple + new byte[] { 0x00, 0xCC, 0x55 }, // green + new byte[] { 0x00, 0x00, 0xAA }, // blue + new byte[] { 0xEE, 0xEE, 0x77 }, // yellow + new byte[] { 0xDD, 0x88, 0x55 }, // orange + new byte[] { 0x66, 0x44, 0x00 }, // brown + new byte[] { 0xFF, 0x77, 0x77 }, // light red + new byte[] { 0x33, 0x33, 0x33 }, // dark grey + new byte[] { 0x77, 0x77, 0x77 }, // grey + new byte[] { 0xAA, 0xFF, 0x66 }, // light green + new byte[] { 0x00, 0x88, 0xFF }, // light blue + new byte[] { 0xBB, 0xBB, 0xBB }, // light grey + }; + + public static void TrueColorBytesToC64Bytes(in byte[] input, ref byte[] output) + { + output = FindNearestColor(input, c64Colors); + } + private static byte[] FindNearestColor(byte[] actualColor, List allowedColors) { int index = 0; diff --git a/Program.cs b/Program.cs index 3542da1..3511331 100644 --- a/Program.cs +++ b/Program.cs @@ -26,7 +26,8 @@ public enum ColorReductionMethod None, TrueColorToWebSafe, TrueColorToFullCGA, - TrueColorToFullEGA + TrueColorToFullEGA, + TrueColorToFullC64 } public enum OutputFormat @@ -68,6 +69,7 @@ method switch ColorReductionMethod.TrueColorToWebSafe => ColorReductions.TrueColorBytesToWebSafeColorBytes, ColorReductionMethod.TrueColorToFullCGA => ColorReductions.TrueColorBytesToCGABytes, ColorReductionMethod.TrueColorToFullEGA => ColorReductions.TrueColorBytesToEGABytes, + ColorReductionMethod.TrueColorToFullC64 => ColorReductions.TrueColorBytesToC64Bytes, _ => throw new ArgumentException(message: "invalid color reduction", paramName: method.ToString()), }; @@ -90,6 +92,7 @@ method switch { ColorReductionMethod.TrueColorToWebSafe, "True colors to Web safe colors (216 different colors)" }, { ColorReductionMethod.TrueColorToFullCGA, "True colors to full palette CGA colors (16 different colors)" }, { ColorReductionMethod.TrueColorToFullEGA, "True colors to full palette EGA colors (64 different colors)" }, + { ColorReductionMethod.TrueColorToFullC64, "True colors to full palette C64 colors (16 different colors)" }, }; private static void PrintHelp()