In Indexed-Color Mode, pixels can suddenly change opacity across versions
Submitted by James Koppel
Created attachment 371654 Exhibits bug in backwards direction
Prior to 2014, pixels in indexed color mode could not be semitransparent, but they could still be serialized in XCF files with an opacity
Bug, forward direction:
- In GIMP 2.8.22 or previous, create an image in indexed color mode. Set opacity to 0.6, and draw. It will appear completely opaque.
- Open file in GIMP 2.10 or other modern version. ---- Expected behavior: Image will appear the same as in GIMP 2.8.22 ---- Actual behavior: Drawn pixels will now be semitransparent
Bug, backwards direction:
- In GIMP 2.10 or other post-2014 version, create an image in indexed color mode. Set the mode of every layer to "Dissolve." Set opacity to 0.6 and draw. It will appear semitransparent.
- Open file in GIMP 2.8.22 or previous ---- Expected result: Either it will display the same as drawn, or GIMP 2.8.22 will give an error that it can't open the file ---- Actual result: GIMP 2.8.22 opens the file, but displays all pixels as completely opaque.
Note: Setting the layer's mode to DISSOLVE is necessary so that GIMP will save the XCF as version 0. Anything else will cause it to save as version 9 or newer, hiding the bug. See the gimp_image_get_xcf_version function for explanation.
I've attached a file displaying this bug in the backwards direction. I tested between GIMP 2.8.22 on Mac (the newest available for Mac, AFAICT), and GIMP 2.10.0 on a Windows VM.
I found this bug while writing a case study about the GIMP codebase for a software design course. I suspected this bug might happen after reading the below comment from xcf.txt. It did indeed happen.
"In images that use the indexed color model, GIMP does not support partial transparency and interprets alpha values from 0 to 127 as fully transparent and values from 128 to 255 as fully opaque. This behavior may change in future versions of GIMP. TODO: has already changed?"
Attachment 371654, "Exhibits bug in backwards direction":