GIMP custom function question

Hi all I have a tricky question, although it may not be tricky for an expert.

The input :
an image into GIMP
Processing :
convert the image into an array of eg 40 x 50 “tiles” which are averaged to the colour of the underlying image pixels - think of a mosaic;
Convert those mosaic tiles to a preset palette corresponding to a set eg 32 copic alcohol markers ( any palette will do);
Print out a text file row by row of the tile grid reference and it’s corresponding palette colour;
The output:
The output is the text file or markup file for creating a hand painted copy of the mosaic

I have no idea if GIMP can do this natively, or whether I need to look into programming a module for this.

Perhaps someone can advise whether it’s possible using the built in functionality of the gimp and if not, what I need to do to get such a system to work.

Thanks in advance

Convert the image into an array of eg 40 x 50 “tiles” which are averaged to the colour of the underlying image pixels - think of a mosaic;

Filters > Blur > Pixellize

Convert those mosaic tiles to a preset palette corresponding to a set eg 32 copic alcohol markers ( any palette will do);

Image > Mode > Indexed and you provide a palette

Print out a text file row by row of the tile grid reference and it’s corresponding palette colour;

Why do you need all the pixels then? Let’s go back to the start. So starting with this:

image

Convert the image into an array of eg 40 x 50 “tiles” which are averaged to the colour of the underlying image pixels - think of a mosaic;

Image > Scale image to 40x50 pixels using the Linear interpolation

image

Convert those mosaic tiles to a preset palette corresponding to a set eg 32 copic alcohol markers ( any palette will do);

Image > Mode > Indexed and you provide a palette

image (here with 12 colors)

The output is the text file or markup file for creating a hand painted copy of the mosaic

You can export as C header, that gives you the color map and the color indexes of the pixels:

/*  GIMP header image file format (INDEXED): /tmp/MS-760-Paris.h  */

static unsigned int width = 60;
static unsigned int height = 38;

/*  Call this macro repeatedly.  After each use, the pixel data can be extracted  */

#define HEADER_PIXEL(data,pixel) {\
pixel[0] = header_data_cmap[(unsigned char)data[0]][0]; \
pixel[1] = header_data_cmap[(unsigned char)data[0]][1]; \
pixel[2] = header_data_cmap[(unsigned char)data[0]][2]; \
data ++; }

static unsigned char header_data_cmap[256][3] = {
	{ 45, 45, 43},
	{ 42, 59, 84},
	{ 83, 85, 85},
	{ 55, 98,157},
	{ 77,102,144},
	{100,113,144},
	{115,113,114},
	{137,145,161},
	{145,145,147},
	{180,141,114},
	{168,170,173},
	{200,202,202},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255},
	{255,255,255}
	};
static unsigned char header_data[] = {
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,4,7,7,11,11,11,11,
	10,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,4,3,3,4,7,10,10,10,10,10,6,2,1,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,7,7,7,10,8,8,10,10,11,11,10,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,5,8,8,10,10,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10,10,10,10,10,10,
	10,11,10,3,3,3,3,3,4,5,5,5,5,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,10,10,10,10,10,5,3,3,3,3,3,
	3,3,3,3,3,3,3,3,5,10,8,8,10,10,10,10,
	10,10,10,7,7,8,8,9,9,10,9,9,10,6,4,5,
	5,5,5,5,5,5,4,3,3,3,3,3,
	3,3,3,3,3,7,10,8,10,10,10,4,3,3,3,3,
	3,3,3,3,3,3,3,3,4,8,8,8,10,10,10,10,
	11,8,10,11,11,11,11,6,2,10,1,2,6,10,6,10,
	11,11,11,11,11,11,11,7,4,3,3,3,
	3,3,3,3,3,5,10,8,8,10,10,10,3,3,3,3,
	3,3,3,3,3,3,3,3,3,8,8,8,8,8,8,10,
	11,11,11,11,11,10,11,0,0,6,2,2,0,8,6,8,
	11,11,11,11,11,11,10,6,4,3,3,3,
	3,3,3,3,4,5,8,8,8,10,10,10,2,4,3,3,
	3,3,3,3,3,3,3,3,4,6,8,8,8,10,10,10,
	8,8,8,8,6,6,6,10,0,0,0,0,0,2,2,6,
	11,10,8,8,6,2,2,4,3,3,3,3,
	3,3,3,3,4,0,6,10,10,10,10,11,0,2,5,4,
	3,3,4,5,5,7,10,10,10,11,10,10,10,8,6,6,
	2,2,2,2,2,2,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,1,1,3,3,3,3,3,3,
	3,3,3,3,3,1,0,8,10,10,10,10,0,0,0,2,
	6,8,10,11,11,11,11,11,11,11,10,8,8,6,2,2,
	2,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0,
	0,1,1,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,1,2,10,10,10,10,6,6,8,10,
	11,11,10,10,10,10,8,9,6,9,6,6,6,6,6,2,
	2,2,6,8,10,11,11,11,0,0,0,0,0,1,4,3,
	3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,1,8,10,10,11,8,8,8,6,
	0,2,2,0,0,2,2,6,6,8,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3,3,3,3,3,3,
	7,8,8,8,8,8,6,10,10,10,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	5,8,10,8,6,8,8,8,10,10,4,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,5,8,8,6,6,8,8,10,10,7,5,5,7,7,3,
	3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,7,10,8,8,8,8,10,10,11,11,11,11,10,4,
	3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,4,8,8,8,8,8,8,6,2,2,1,4,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,4,7,6,6,2,1,1,1,1,4,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,4,7,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
	3,3,3,3,3,3,3,3,3,3,3,3
	};

I don’t know what the purpose of this is, but the weirdest Gimp script I wrote translates an image to the instructions for a Brother knitting machine and that made me a star in knitting circles of the Midwest several years ago :slight_smile:

2 Likes

Thanks very much, it will take me a while to go through and figure this out, and I might have more questions as I go!

Ok so I think I follow everything here, but I have a couple more questions.

How do you produce the text header file from the Gimp? I looked at the export command but couldn’t find that option.

I assume the list of triplets with eg 255,255,255 is the RGB formula for the actual colours, and the list of numbers is a pixel by pixel index to the ordered array of colours?

Bump.

How do you produce the text header file from the Gimp? I looked at the export command but couldn’t find that option.

It is just the the “C header” format is actually a text file, not a binary thing. Try it.

I assume the list of triplets with eg 255,255,255 is the RGB formula for the actual colours, and the list of numbers is a pixel by pixel index to the ordered array of colours?

Yes,

  • The header_data_cmap variable is very likely the colour map (always 255 colors, even of many are unused here)
  • The header_data variable is the pixels, where the value is the index in header_data_cmap of the pixel color. The difficulty is that is is not nicely laid out in lines that correspond to image lines, from what I can see the data is a single-dimension vector, so you have to use the width and height variables to split it.
1 Like

Thanks again, I had no idea gimp could produce header files just by exporting in format filename.h.