GNOME Bugzilla – Bug 109078
gimp-curves-* pdb can't be applied to gray alpha but can be applied to alpha in alpha-less RGB drawables
Last modified: 2004-01-13 11:52:15 UTC
When using gimp-curves-spline or gimp-curves-explicit with the alpha channel of a grayscale image, the PDB fails. How to reproduce: 1. Create a grayscale image. 2. Add alpha channel or create a new layer. 3. Open the script-fu console and enter: (gimp-image-get-active-layer <image-number>) 4. With the returned layer number, execute: (gimp-curves-spline <layer-number> ALPHA-LUT 4 (hexstr->bytes "007fff7f")) (will signal an error) On the other hand, if step (2) is omitted and (1) is replaced with 1a. Create an RGB image. then no error is returned. The problem lies in the sanity check done by colors.pdb, and applies also to the HEAD branch. Patch follows.
Sorry, for some reason I can't upload it as an attachment. Here's the patch: diff -ur gimp-1.2.4pre-orig/tools/pdbgen/pdb/color.pdb gimp-1.2.4pre/tools/pdbgen/pdb/color.pdb --- gimp-1.2.4pre-orig/tools/pdbgen/pdb/color.pdb Tue Apr 16 22:19:22 2002 +++ gimp-1.2.4pre/tools/pdbgen/pdb/color.pdb Mon Mar 24 04:15:11 2003 @@ -342,7 +342,9 @@ code => <<'CODE' { if (gimp_drawable_is_indexed (drawable) || (num_points & 1) || - (gimp_drawable_is_gray (drawable) && channel != GRAY_LUT)) + (!gimp_drawable_has_alpha (drawable) && channel == ALPHA_LUT) || + (gimp_drawable_is_gray (drawable) && channel != GRAY_LUT + && channel != ALPHA_LUT)) success = FALSE; else { @@ -363,8 +365,8 @@ cd.curve_type[i] = SMOOTH; cd.drawable = drawable; - cd.channel = channel; cd.color = gimp_drawable_is_rgb (drawable); + cd.channel = (cd.color || channel != ALPHA_LUT) ? channel : 2; for (j = 0; j < num_points / 2; j++) { @@ -424,7 +426,9 @@ code => <<'CODE' { if (gimp_drawable_is_indexed (drawable) || (num_bytes != 256) || - (gimp_drawable_is_gray (drawable) && channel != GRAY_LUT)) + (!gimp_drawable_has_alpha (drawable) && channel == ALPHA_LUT) || + (gimp_drawable_is_gray (drawable) && channel != GRAY_LUT + && channel != ALPHA_LUT)) success = FALSE; else { @@ -433,8 +437,8 @@ cd.curve[i][j] = j; cd.drawable = drawable; - cd.channel = channel; cd.color = gimp_drawable_is_rgb (drawable); + cd.channel = (cd.color || channel != ALPHA_LUT) ? channel : 2; for (j = 0; j < 256; j++) cd.curve[cd.channel][j] = curve[j];
I can confirm that the code in question is wrong in several places we can not accept the patch as it is. There is no reason to set the channel variable to 2 in case of gray images since 2 would be GREEN_LUT. We need to investigate further and come up with a clean patch.
We should at least fix this in 1.3.
Changing milestone on a bunch of bugs to 2.0 - none of these could be considered a blocker for a pre-release, IMHO. Many of these have patches or someone working on them, but they're not urgent. Dave.
Fixed in CVS: 2004-01-13 Michael Natterer <mitch@gimp.org> * app/base/gimphistogram.[ch]: renamed gimp_histogram_nchannels() to gimp_histogram_n_channels(). * app/core/gimpdrawable-histogram.c: removed silly double negation logic. Cleanup. * app/widgets/gimphistogrameditor.c * app/widgets/gimphistogramview.c: adjust the GimpHistogramChannel for GRAYA images to make sure we pick alpha from the right slot. * app/tools/gimpcurvestool.c * app/tools/gimplevelstool.c: removed the same hack here and call gimp_histogram_view_set_channel() with the correct enum value. * tools/pdbgen/pdb/color.pdb (levels, curves, histogram): fiddle with enum values here too so GRAY* drawables produce the correct results. Fixed precondition checks and set "success" in a uniform way all over the place. Use gimp_drawable_calculate_histogram() instead of duplicating its code here. (started with a patch from Pedro Gimeno. Fixes bug #109078) * app/pdb/color_cmds.c: regenerated.