Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help Converting an Images Colors to the closest one in a palette
#1
Question 
So I am developing a video game which uses a built-in color palette similar to old MS-DOS games. Because of this, I need a program that will convert all the colors in an image to the closest color in a given color palette. Unfortunately, my game's color palette has more than 256 colors (around 2000), so I can't just convert all the images I want to turn into sprites to indexed mode. The best method I've found so far is to use the Select by Color Tool and manually convert every color in the image to match my palette. Does anyone know a way to convert images to a color palette instantly besides indexed mode?
Reply
#2
A 2K colors palette doesn't make much sense. Could it be just a low-resolution palette where colors are encoded on 11 bits, in which case it would just be a matter of rounding up the colors values?
Reply
#3
(08-16-2025, 05:03 PM)Ofnuts Wrote: A 2K colors palette doesn't make much sense. Could it be just a low-resolution palette where colors are encoded on 11 bits, in which case it would just be a matter of rounding up the colors values?

Unfortunately,  I really don't know what that means. I really hope I don't come off as rude or condescending but I genuinely have no clue.
Reply
#4
(08-16-2025, 05:25 PM)Aminivibrio Wrote:
(08-16-2025, 05:03 PM)Ofnuts Wrote: A 2K colors palette doesn't make much sense. Could it be just a low-resolution palette where colors are encoded on 11 bits, in which case it would just be a matter of rounding up the colors values?

Unfortunately,  I really don't know what that means. I really hope I don't come off as rude or condescending but I genuinely have no clue.

When the palette is 256 colors or less, you can encode a pixel on one byte (instead of 3).

When the palette has around 2K colors, you need at least 11 bits to specify a color in the palette. Since on a PC the bits come in indivisible groups of 8 (bytes) you will have to encode the image with two bytes per pixel (instead of the usual 3): not much savings for a lot of complexity.

There are a few encoding schemes where colors are stored in fewer than 8 bits. For instance, with 32 levels for red and blue (5 bits) and 64 for green (6 bits)(*), you can encode a pixel on 5+6+5=16 bits=2 bytes. This is as complex as above, but in the early days (PC with CGA/EGA) the hardware could use the encoding directly.

So, your 2K palette makes me wonder if the underlying rule is just that colors are encoded with fewer bits, in which case you wouldn't be using an arbitrary mapping but just a reduction of the number of color levels. And this would be what Colors > Dither does.

(*) because our eyes are mostly sensitive to green, and image brightness is mostly from the green channel
Reply
#5
https://www.adventuregamestudio.co.uk/fo...a-graphics
Reply
#6
(08-17-2025, 07:37 AM)Ofnuts Wrote:
(08-16-2025, 05:25 PM)Aminivibrio Wrote:
(08-16-2025, 05:03 PM)Ofnuts Wrote: A 2K colors palette doesn't make much sense. Could it be just a low-resolution palette where colors are encoded on 11 bits, in which case it would just be a matter of rounding up the colors values?

Unfortunately,  I really don't know what that means. I really hope I don't come off as rude or condescending but I genuinely have no clue.

When the palette is 256 colors or less, you can encode a pixel on one byte (instead of 3).

When the palette has around 2K colors, you need at least 11 bits to specify a color in the palette. Since on a PC the bits come in indivisible groups of 8 (bytes) you will have to encode the image with two bytes per pixel (instead of the usual 3): not much savings for a lot of complexity.

There are a few encoding schemes where colors are stored in fewer than 8 bits. For instance, with 32 levels for red and blue (5 bits) and 64 for green (6 bits)(*), you can encode a pixel on 5+6+5=16 bits=2 bytes. This is as complex as above, but in the early days (PC with CGA/EGA) the hardware could use the encoding directly.

So, your 2K palette makes me wonder if the underlying rule is just that colors are encoded with fewer bits, in which case you wouldn't be using an arbitrary mapping but just a reduction of the number of color levels. And this would be what Colors > Dither does.

(*) because our eyes are mostly sensitive to green, and image brightness is mostly from the green channel
Thank you so much dude. My current color palette is based off of color ramps (similar to the palettes in the image, the smaller one from Classic DOOM and the big one from the Steam version of Dwarf Fortress) but I will probably end up switching to something of this format

(08-17-2025, 08:37 AM)denzjos Wrote: https://www.adventuregamestudio.co.uk/fo...a-graphics

Thank you so much dude! I really appreciate you for helping with my computer difficulties.

I do have a question though, can you please explain to me how to run the program? I'm using WinRAR if that makes any difference


Attached Files Thumbnail(s)
   
Image(s)
   
Reply
#7
(08-17-2025, 01:47 PM)Aminivibrio Wrote:
(08-17-2025, 07:37 AM)Ofnuts Wrote:
(08-16-2025, 05:25 PM)Aminivibrio Wrote: Unfortunately,  I really don't know what that means. I really hope I don't come off as rude or condescending but I genuinely have no clue.

When the palette is 256 colors or less, you can encode a pixel on one byte (instead of 3).

When the palette has around 2K colors, you need at least 11 bits to specify a color in the palette. Since on a PC the bits come in indivisible groups of 8 (bytes) you will have to encode the image with two bytes per pixel (instead of the usual 3): not much savings for a lot of complexity.

There are a few encoding schemes where colors are stored in fewer than 8 bits. For instance, with 32 levels for red and blue (5 bits) and 64 for green (6 bits)(*), you can encode a pixel on 5+6+5=16 bits=2 bytes. This is as complex as above, but in the early days (PC with CGA/EGA) the hardware could use the encoding directly.

So, your 2K palette makes me wonder if the underlying rule is just that colors are encoded with fewer bits, in which case you wouldn't be using an arbitrary mapping but just a reduction of the number of color levels. And this would be what Colors > Dither does.

(*) because our eyes are mostly sensitive to green, and image brightness is mostly from the green channel
Thank you so much dude. My current color palette is based off of color ramps (similar to the palettes in the image, the smaller one from Classic DOOM and the big one from the Steam version of Dwarf Fortress) but I will probably end up switching to something of this format

(08-17-2025, 08:37 AM)denzjos Wrote: https://www.adventuregamestudio.co.uk/fo...a-graphics

Thank you so much dude! I really appreciate you for helping with my computer difficulties.

I do have a question though, can you please explain to me how to run the program? I'm using WinRAR if that makes any difference
After download use WinRAR to extract the files in a folder and the program is in folder : obj / Release / Pic2EGA.exe

   
Reply
#8
thanks!

Yo actually I don't know how to turn my palette into a JASC PAL file. I've tried using online file converter websites but when I try it says "Error loading this file. Make sure it is a JASC Palette."
Reply
#9
https://www.cyotek.com/cyotek-palette-editor

Some information :

A JASC palette, also known as a JASC-PAL palette, is a file format for storing color palettes, typically used in older versions of Jasc Software's Paint Shop Pro. These files are simple text files with a specific structure: "JASC-PAL" on the first line, "0100" on the second, the number of colors on the third, and then the RGB values for each color on subsequent lines. 
Here's how to create a JASC-PAL palette:
1. Understand the Format:
Header: The first line must be JASC-PAL.
Version: The second line is 0100.
Number of Colors: The third line specifies the number of colors in the palette (e.g., 256 for a full 256-color palette).
RGB Values: Each subsequent line contains three decimal numbers representing the Red, Green, and Blue components of a color, ranging from 0 to 255, separated by spaces. 
2. Choose your colors:
You'll need to determine the colors you want to include in your palette. You can do this by:
Selecting colors directly from an image using image editing software.
Choosing colors based on a color scheme you've designed.
Using a color palette generator.
Experimenting with different color combinations. 
3. Create the Palette File:
Using a Text Editor: Open a text editor (like Notepad on Windows, TextEdit on macOS). 
Write the Header: Type JASC-PAL on the first line.
Write the Version: Type 0100 on the second line.
Specify the Number of Colors: Type the number of colors in your palette on the third line (e.g., 16, 256, etc.). 
Add RGB Values: For each color in your palette, write a line with its RGB values, separated by spaces. For example: 255 0 0 for red, 0 255 0 for green, 0 0 255 for blue. 
Save the File: Save the file with a .pal or .jasc extension (e.g., my_palette.pal). 
Example:
Code

JASC-PAL
0100
3
255 0 0
0 255 0
0 0 255
This example creates a JASC palette with three colors: red, green, and blue. 
4. Using the Palette:
You can then load this file into applications that support JASC-PAL palettes, such as older versions of PaintShop Pro or other image editing software. 
Some tools like Cyotek Palette Editor can also be used to edit or create JASC-PAL palettes. 
You can also use the palette in applications like Liero, but keep in mind Liero uses 6-bit (64) color values, not 8-bit (256), so you may need to adjust the RGB values accordingly when saving the palette.
Reply


Forum Jump: