Pointing out a tiny error somehow got me to do a complete overhaul of the bmp import plug-in for gimp. :o) I’m almost done and the last thing that irks me is undefined pixels in RLE bmps. (It is a feature of RLE compressed bmps to be able to skip any number of pixels and thus leave them undefined).
Currently, those undefined pixels are set to zero, which means they are indistinguishable from pixels that actually have a zero value, meaning that information is lost on import.
The obvious solution would be to make those undefined pixels transparent. And that’s where I need some help with adding an alpha channel during import. We don’t know beforehand if a file contains undefined pixels. Only when stumbling on undefined pixels somewhere in the middle of importing the image do we learn that an alpha channel is needed.
(The brute force way of always adding an alpha channel to RLE imports works nicely, but will be a nuisance with RLE files that have no undefined pixels, e.g. when getting a warning about alpha channel on re-export even though there is no visible transparency).
At the start of importing, the following functions are called:
gimp_image_new_with_precision()
gimp_layer_new()
← (no) alpha channel is specified here
gimp_image_insert_layer()
gimp_drawable_get_buffer()
Then, during import, image data is chunkwise fed to
gegl_buffer_set()
Now, with the image partially loaded after a couple calls to gegl_buffer_set()
, how do I go about adding an alpha channel to the layer? How far do I have to roll back, what gets updated automatically? Is the buffer from gimp_drawable_get_buffer()
still good, or do I need to unref / get a new one?
Thanks
Rupert