After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 680453 - unused colors are automatically removed from palette for indexed image upon loading
unused colors are automatically removed from palette for indexed image upon l...
Status: RESOLVED OBSOLETE
Product: GIMP
Classification: Other
Component: Plugins
2.8.0
Other All
: Normal normal
: 2.10
Assigned To: GIMP Bugs
GIMP Bugs
Depends on:
Blocks:
 
 
Reported: 2012-07-23 14:30 UTC by moritzmielke
Modified: 2018-05-24 13:16 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
original image file and re-saved gimp version, with corresponding palettes (3.15 KB, application/octet-stream)
2012-07-27 08:18 UTC, moritzmielke
  Details
file-gif-load.patch (2.68 KB, patch)
2012-08-11 18:24 UTC, Hartmut Kuhse
needs-work Details | Review

Description moritzmielke 2012-07-23 14:30:37 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.
Comment 1 Michael Natterer 2012-07-26 15:28:29 UTC
There is no code that would remove unused palette entries, can you
attach an example image where this happens to you?
Comment 2 moritzmielke 2012-07-27 08:18:05 UTC
Created attachment 219722 [details]
original image file and re-saved gimp version, with corresponding palettes
Comment 3 moritzmielke 2012-07-27 08:24:11 UTC
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.
Comment 4 moritzmielke 2012-07-28 12:31:56 UTC
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?
Comment 5 Hartmut Kuhse 2012-08-11 18:24:57 UTC
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.
Comment 6 Michael Natterer 2012-12-05 23:06:46 UTC
Well that patch doesn't address the issue that is described in the
comment right above the line you change.
Comment 7 Michael Natterer 2013-01-19 17:34:08 UTC
Hartmut, any comment?
Comment 8 Michael Schumacher 2015-11-01 13:37:37 UTC
Comment on attachment 220928 [details] [review]
file-gif-load.patch

See comment 6
Comment 9 Michael Natterer 2018-01-02 23:00:16 UTC
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.
Comment 10 GNOME Infrastructure Team 2018-05-24 13:16:40 UTC
-- 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.