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:
Code:
static char header_data[] = {
    0xa2,0x7f,0x00,0x57,
    0x4a,0xff,0xc5,0x12
    };
That would be if the color indexes are (for the example) as follows:
Code:
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:
Code:
static char header_data[] = {
    0xa2,0xa2,0xff,0xff,
    0xa2,0xa2,0xff,0xff
    };

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

Note:
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).

Chupo_cro
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

Chupo_cro
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!

ps
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?

Chupo_cro
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.

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


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Background Colors Don't Match rkulp 5 314 Aug 9, 2014 17:04
Last Post: iForStyle007
Smile Wrong colors... mlegs 6 427 Jul 22, 2014 18:28
Last Post: rich2005
  Turn a certain color into nearby colors jubinell 4 318 May 28, 2014 00:45
Last Post: iForStyle007
  Why is GIMP changing colors when exporting to GIF? nabziF 6 663 May 9, 2014 07:10
Last Post: iForStyle007
  half of the menu items greyed out (not indexed mode error) roiikkata 12 1,865 Apr 8, 2014 21:43
Last Post: roiikkata

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS