Skip to content

Commit

Permalink
Add C64 color reduction palette
Browse files Browse the repository at this point in the history
New feature
  • Loading branch information
mcraiha committed Jun 6, 2022
1 parent 1e06fc4 commit 64803bc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGE-LOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
25 changes: 25 additions & 0 deletions ColorReductions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,31 @@ public static void TrueColorBytesToCGABytes(in byte[] input, ref byte[] output)
output = FindNearestColor(input, fullCGAColors);
}

private static readonly List<byte[]> c64Colors = new List<byte[]>()
{
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<byte[]> allowedColors)
{
int index = 0;
Expand Down
5 changes: 4 additions & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public enum ColorReductionMethod
None,
TrueColorToWebSafe,
TrueColorToFullCGA,
TrueColorToFullEGA
TrueColorToFullEGA,
TrueColorToFullC64
}

public enum OutputFormat
Expand Down Expand Up @@ -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()),
};

Expand All @@ -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()
Expand Down

0 comments on commit 64803bc

Please sign in to comment.