GNOME Bugzilla – Bug 680453
unused colors are automatically removed from palette for indexed image upon loading
Last modified: 2018-05-24 13:16:40 UTC
found this while modding the classic game UFO: Enemy Unknown. I have a number of indexed-palette gif files, all using the same basic palette. However, when I open a file that doesn't actively use all of the colors, the palette shown by the "palette editor" dockable dialog only shows those used colors. ALL images do contain the full palette (confirmed in other image editors), but the GIMP automatically removes the unused colors from the active palette. (So if you try to copy parts of other images of the same batch, which use the same palette, into the current image, the colors end up black unless by chance they are also used in the current image.) While palette reduction may make sense in some applications, it is definitely wrong in these indexed images. you are trying to work in a fixed "palette space", and all images need to retain the full palette in order to decently work with them.
There is no code that would remove unused palette entries, can you attach an example image where this happens to you?
Created attachment 219722 [details] original image file and re-saved gimp version, with corresponding palettes
I've added an example. The original image used is a 256-color-indexed-palette image named "handob_000_0.gif". I opened the original image with irfanview and saved the palette file as "handob_000_0.pal" next I opened the file in the GIMP. as before, when I open the palette editor, it shows only the used colors instead of the full palette. (perhaps this is actually an issue with loading palette information from indexed-palette gif files?) I then re-saved the file as "handob_000_0 - resaved.xcf" and without re-loading it also exported it as "handob_000_0 - resaved, exported.gif". I opened the latter in irfanview and saved the palette file as "handob_000_0 - resaved.exported.pal". all the mentioned files are contained in the .zip above. The palette files clearly show that somewhere, probably on loading the file in the GIMP, the unused colors have been dropped.
some further testing: apparently, the palette is truncated from the end. I created a test image that used the first 13 or 14 colors as well as a few from the end of the palette (but none of those in between), saved it, re-opened it and all colors from 0 to the last used color were still there. I then deleted the image content that used the "late" colors, saved and re-opened and the palette was reduced to the first 13 or 14 colors. maybe this helps to find the problem?
Created attachment 220928 [details] [review] file-gif-load.patch In the plugin file-gif-load, there are counted the colors used in the gif-image. If there is a colormap, the plugin sets the size of the colormap to the highest index of used colors. When the used colors are sorted in the colormap, which is the case most often, then the resulting colormap is actually much smaller, than expected. I propose a patch, which sets the resulting colormap to the size of the gif standard colormap. The not used colors in the colormap are black.
Well that patch doesn't address the issue that is described in the comment right above the line you change.
Hartmut, any comment?
Comment on attachment 220928 [details] [review] file-gif-load.patch See comment 6
I tend to agree. There is no reason not to import the entire palette, even if some colors are not used. Something to easily change for any 2.10 release.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gimp/issues/414.