Post Reply 

Indexed palette of exact colors?

Sep 7, 2014, 14:07 (This post was last modified: Sep 7, 2014 14:13 by chupo_cro.)
Post: #1
Question Indexed palette of exact colors?
I am new to GIMP and looking for a way to complete the specific task regarding importing the image data into microcontroller environment - which requires the following steps:
  1. Creating the image composed of exactly 8 colors.
  2. Choosing the desired 8 bit color index for the each used color.
  3. Exporting the image as C header file.
So the exported data for 4x2 px image should look something like:
static char header_data[] = {
That would be if the color indexes are (for the example) as follows:
0 --> 0xff
1 --> 0x57
2 --> 0xa2
3 --> 0xc5
4 --> 0x4a
5 --> 0x7f
6 --> 0x12
7 --> 0x00

Of course, there could be multiple pixels of the same color in the C header image data:
static char header_data[] = {

I don't need step-by-step instructions - just a few hints would suffice.

The OS is Windows XP and I had to install GIMP 2.6.12 because of some problems with SP3 (2.8.x runs on SP3 only).

Find all posts by this user
Quote this message in a reply
Sep 7, 2014, 14:42
Post: #2
RE: Indexed palette of exact colors?
(Sep 7, 2014 14:22)ofnuts Wrote:  1) you can create a pallete (using Gimp palette editor) or even create one by hand (plain text file)

2) you can edit your image using colors from the palette (there is a tab in the color selector that corresponds to the active palette)

3) When you change your image to color-indexed, you can specify a palette as the color map. AFAIK (but I didn't check thoroughly) the order of colors in the palette is preserved in the colormap.

Many operations generate intermediate colors, so you may have to keep the image color-indexed at all times (this disables many things that could lead to color alteration).

Thank you very much for the info! Later at night I'll try to go thru these steps and then write the results.

Have a nice day

Find all posts by this user
Quote this message in a reply
Sep 8, 2014, 03:34
Post: #3
Smile RE: Indexed palette of exact colors?
Success!! :-) I created a test palette of 8 colors and a test 4x2 px picture. Then I used every color from the palette to paint one pixel, converted the image to indexed mode, exported as C header file - and everything was as expected.

Since I need color indexes greater than 0x07 (one of them even has to be 0xff) I edited the .gpl file with the text editor so it now contains all 256 indexes (of which only 8 are used to compose the image) and the indexes 0x00 to 0x07 are rearanged according to the target specifications.

After some more time I realized I could have rearanged the indexes using the GIMP's Colormap dialog, however having the palette with already arranged indexes seems to be better solution - because I can now compose a new image by just using the preset palette (no need to afterwards rearange the colors with Colormap dialog).

Thank you again for your help!

Do you by any chance know if there is a way to switch the hex instead of decimal output mode for the static char header_data[] array data when exporting an image as C header file?

Find all posts by this user
Quote this message in a reply
Sep 8, 2014, 11:08
Post: #4
RE: Indexed palette of exact colors?
(Sep 8, 2014 07:08)ofnuts Wrote:  Not I now of, but I don't see much point in this, this data is really going from Gimp to your compiler, if you want to edit it, use Gimp Smile

Otherwise, insert the data in a small piece of C code that will print it out in hex...

Yes, that is true. However I already have a Perl script which manipulates the array data (expected to be in 'ox' hex representation) so the option to switch the output to the hex mode would save me some time.

I can, hovewer, modify the script to parse the data in decimal representation, or even manipulate the data on the fly - when generating the binary output (in that case the easy readable format of the final result would be lost).

The final result is BTW some kind of RLE compressed binary. Each byte contains the color index (the upper 3 bits) and the count (the lower 5 bits). During the compression the initial color indexes are remapped to 0x00 - 0x07 range, to fit into 3 bit representation.

Find all posts by this user
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Import palette from another image jllopezpino 1 133 Mar 20, 2019 09:18
Last Post: paynekj
  Make every image exact same size nibla 2 363 Jan 21, 2019 07:47
Last Post: Manju
Question Saving to a gif format and choosing the color palette SpongeBob 0 463 Dec 13, 2017 19:13
Last Post: SpongeBob
  Background Colors Don't Match rkulp 5 917 Aug 9, 2014 17:04
Last Post: iForStyle007
Smile Wrong colors... mlegs 6 940 Jul 22, 2014 18:28
Last Post: rich2005

Forum Jump:

GIMP ForumPortalArchiveContactTermsRSS