Gimp-Forum.net
extend colormap in indexed pictures - Printable Version

+- Gimp-Forum.net (https://www.gimp-forum.net)
+-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP)
+--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP)
+---- Forum: Scripting questions (https://www.gimp-forum.net/Forum-Scripting-questions)
+---- Thread: extend colormap in indexed pictures (/Thread-extend-colormap-in-indexed-pictures)



extend colormap in indexed pictures - gizaha - 02-03-2019

Hello there. I have a problem that tortures me 2 days now. 
I want to extend the colormap at indexed pictures by one color with script fu.


;get colormap length from header
(set! colormap_length (car (gimp-image-get-colormap image)))     

;get colormap data from tail
(set! colormap (car (cdr (gimp-image-get-colormap image))))

;extend header
(set! colormap_length (+ colormap_length 3))      ;increaze by 3 bytes/1 color

;extend tail
;here, i want to make colormap:=colormap+"000000" thus extend the list

;set new colormap
(gimp-image-set-colormap image colormap_length colormap)

(Variables are defined ok)
I tried almost everythink while playing with let, set, list, cons car etc etc.
Thank you.


RE: extend colormap in indexed pictures - Ofnuts - 02-03-2019

I don't know how to do it in script-fu, but as far as I remember, you get the color map as a flat list of bytes which is 3x the number of colors and where RGB are three consecutive items in the list. So if you want to extend the map with black you have to add (0,0,0) at the end.

See invert-colormap-0.0.py for Python sample code.