GNOME Bugzilla – Bug 765176
ICC profile conversions between grayscale and RGB images
Last modified: 2016-05-23 08:22:44 UTC
GIMP now has the ability to color manage grayscale and RGB images, but not the ability to do ICC profile conversions between grayscale and RGB images. It would be very convenient to be able to do ICC profile conversions between RGB and grayscale images.
What can easily be done is to at least convert from the RGB/grayscale profile to the builtin grayscale/RGB profile. I don't know if converting to anything else is worth the effort, is there a good use case?
(In reply to Michael Natterer from comment #1) > What can easily be done is to at least convert from the RGB/grayscale > profile to the builtin grayscale/RGB profile. I don't know if converting > to anything else is worth the effort, is there a good use case? I think you mean conversions between built-in sRGB and a grayscale profile with the sRGB TRC? One use case not covered by the above is as follows: 1. decompose to LAB (grayscale), 2. assign a grayscale profile with the LAB-L TRC (in the interim before such is assigned automatically of course!) 3. drag the grayscale layers from the LAB layer stack over to the RGB layer stack, which might be in an RGB color space other than the built-in sRGB color space. Another use case is opening a grayscale image from disk - which might not have the sRGB TRC - and converting it to a user-chosen RGB profile, which might not be the built-in sRGB color space. But this is not likely to be a very common use case. Even though "anyRGB to anyGrayscale" and vice versa would be useful, users do have workarounds available. So maybe "any to any" is a low priority item.
What I meant: without hacking up a dialog to pick the destination profile, we can easily have: - DND between anything - anyRGB to builtin grayscale - anyGrayscale to builtin sRGB
(In reply to Michael Natterer from comment #3) > What I meant: without hacking up a dialog to pick the destination > profile, we can easily have: > > - DND between anything > - anyRGB to builtin grayscale > - anyGrayscale to builtin sRGB I'm not sure what "DND" means. Do you mean first convert from anyGrayscale to sRGB, and then from sRGB to anyRGB? and also vice versa, first convert from anyRGB to sRGB, and then from sRGB to anyGrayscale? Is the very first step to convert from whatever precision to double, then make the two-step ICC profile conversion, then convert from double to whatever precision? Or am I totally misunderstanding what you are saying?
DND means drag-and-drop.
I found only this little thing, when converting the entire image to/from grayscale via Image -> Mode: commit 39682266440b33adedad70e48c2d8bb7fb8c245c Author: Michael Natterer <mitch@gimp.org> Date: Wed Apr 20 04:20:58 2016 +0100 Bug 765176 - ICC profile conversions between grayscale and RGB images gimp_image_convert_type(): call gimp_drawable_convert_type() with convert_profile = TRUE. app/core/gimpimage-convert-type.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) Other than that, everything seems to be implemented properly already. Do you know of a case that doesn't work? (minus the LAB thing because we don't attach the right profile yet).
(In reply to Michael Natterer from comment #6) > I found only this little thing, when converting the entire > image to/from grayscale via Image -> Mode: > > commit 39682266440b33adedad70e48c2d8bb7fb8c245c > Author: Michael Natterer <mitch@gimp.org> > Date: Wed Apr 20 04:20:58 2016 +0100 > > Bug 765176 - ICC profile conversions between grayscale and RGB images > > gimp_image_convert_type(): call gimp_drawable_convert_type() with > convert_profile = TRUE. > > app/core/gimpimage-convert-type.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > Other than that, everything seems to be implemented properly already. > Do you know of a case that doesn't work? (minus the LAB thing because > we don't attach the right profile yet). Mitch, my apologies - I managed to conflate several trains of thought and so this bug report is unnecessary/has the wrong subject line/shouldn't have been filed, take your pick. Here's an untangling: Currently conversions between grayscale and RGB are possible and correct. But the required procedure seems not obvious and not user-friendly. And it doesn't allow for extension to include CMYK or other possible color space models (LAB/XYZ/etc) that GIMP might support in the future. Let's say a user opens a grayscale image from disk and wants to convert the image to a user-chosen RGB profile. There are two ways to do this: 1. The less obvious way is to: 1a. Open the grayscale image from disk. 1b. Create a new RGB XCF layer stack of the same size. 1c. Assign the destination RGB ICC profile to the newly created RGB image. 1d. Drag the grayscale image layer over to the new RGB XCF layer stack. As far as I can tell, drag and drop works perfectly for all grayscale and RGB profiles (for GIMP updated today). 2. When converting a grayscale image to an RGB image, this is what many users might expect to do: 2a. Open the grayscale image from disk. 2b. Do "Image/Color Management/Convert to Color Profile" 2c. Select the destination RGB ICC profile. 2d. Click on "Convert" and the conversion is done. 3. This is what's really required: 3a. Open the grayscale image from disk. 3b. Do "Image/Mode" and change the Mode from Grayscale to RGB. 3c. Do "Image/Color Management/Convert to Color profile" 3d. Select the destination RGB ICC profile. 3e. Click on "Convert", and finally the image has been converted to the desired RGB ICC RGB color space profile. The above procedure is only one step longer than what many users might intuitively expect. But that "one extra step" isn't obvious and at least to me feels cumbersome. So here are some proposed changes for consideration: 1. When the user chooses "Image/Color Management/Convert to Color Profile", if the user chooses a grayscale destination profile for an RGB image or vice versa, do the required "Mode" (actually "color model") change behind the scenes instead of requiring that the user change the "Mode" before converting to the destination ICC profile. 2. In the UI, rename "Image/Mode" to something like "Image/Color Model/" with the current options being RGB and Grayscale. 3. In the UI, change "Image/Color Management/Convert to Color Profile" to "Image/Color Management/Convert to ICC Color Profile" in anticipation of the day when GIMP supports additional ways of managing color, specifically OCIO.
Thanks, that confirms my look at the code, and we could close this as FIXED since I did a small fix above, however you make good points: 1. I think that's not the right way and probably more confusing than helpful. We need to do something similar in the "Mode" menu anyway, resulting in one "proper" way, and one way that shortcuts to the same result. That's weird. Instead, we should probably not even list unsuitable profiles in the "Convert to / Assign color profile" dialogs. And, Mode -> RGB and Mode -> Grayscale should be changed to do the following: - If the image has a built-in default profile assigned, just convert to the new color model's built-in profile - Otherwise, tell the user there is a profile, and pop up the profile conversion dialog for choosing a target profile, of course containing the default builtin option, resulting in this workflow: 3a. Open the grayscale image from disk. 3b. Do "Image/Mode/RGB" 3c. If the grayscale had a profile, select the destination RGB profile. 3d. Click on "Convert" and the conversion is done. Which is exactly the canonical way of converting to RGB/Grayscale, plus an optional dialog, much like the "Convert to indedex" one, so not unexpected. 2. That's a very good suggestion, "Mode" could be just about anything, it's meaningless and it was never a good name. I guess "Color Model" is way better. 3. That's really future stuff, I haven't even heard of OCIO :) Let's rename things when we get there. Let's use this bug for tracking that dialog that needs to be added, to be shown from whatever menu entry we decide.
Fixed in master by this pile of commits, please test :) Leaving open for the remaining stuff in comment 8. commit 182da6d2e9eea41b279cbea9a89c00181157ddac Author: Michael Natterer <mitch@gimp.org> Date: Sat Apr 30 18:34:15 2016 +0200 Bug 765176 - ICC profile conversions between grayscale and RGB images When converting between RGB and GRAY and the image has a profile, invoke the convert profile dialog with the newly added image type conversion feature. app/actions/image-commands.c | 51 ++++++++++++++-------- app/dialogs/color-profile-dialog.c | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 155 insertions(+), 27 deletions(-) commit 12f9aa9bd27f3f78d762897108e3c316bd3c0ebc Author: Michael Natterer <mitch@gimp.org> Date: Sat Apr 30 17:48:07 2016 +0200 Bug 765176 - ICC profile conversions between grayscale and RGB images Add a dest_profile parameter to gimp_image_convert_type() so a profile can be chosen when converting between RGB and GRAY. Has no GUI yet. app/actions/image-commands.c | 2 +- app/core/gimpimage-convert-type.c | 37 ++++++++++++++++++++++++++----------- app/core/gimpimage-convert-type.h | 1 + app/pdb/image-convert-cmds.c | 8 ++++---- libgimp/gimpimageconvert_pdb.c | 7 +++---- tools/pdbgen/pdb/image_convert.pdb | 11 +++++------ 6 files changed, 40 insertions(+), 26 deletions(-) commit 33adec2a3eaaec8569b34a49ff68d50ce87b0a56 Author: Michael Natterer <mitch@gimp.org> Date: Sat Apr 30 17:39:02 2016 +0200 app: add gimp_image_validate_color_profile_by_format() which checks if a color profile is suited for pixels of a Babl format. app/core/gimpimage-color-profile.c | 79 +++++++++++++++++++++++++++++++++++--------------------- app/core/gimpimage-color-profile.h | 6 +++++ 2 files changed, 55 insertions(+), 30 deletions(-) commit 1cf04cc4b98af3f5df87ffd5bffcbb2f3a7843ec Author: Michael Natterer <mitch@gimp.org> Date: Fri Apr 29 12:53:43 2016 +0200 app: prepare the color profile dialog for doing RGB <-> GRAY conversion Get rid of individual constructors for assign and convert, instead have one constructor that takes a dialog type enum. No new features yet in this commit. app/actions/image-commands.c | 18 +++-- app/dialogs/color-profile-dialog.c | 217 ++++++++++++++++++++++++++----------------------------- app/dialogs/color-profile-dialog.h | 21 ++++-- 3 files changed, 127 insertions(+), 129 deletions(-) commit ef8b802032b5d36be4ef0046d8329e9411a860ad Author: Michael Natterer <mitch@gimp.org> Date: Fri Apr 29 10:34:03 2016 +0200 app: move indexed conversion to gimpimage-convert-indexed.[ch] It's so much code and takes so many additional parameters over RGB and GRAY conversion, it got its own place and function now. app/actions/image-commands.c | 4 +- app/core/Makefile.am | 2 + app/core/gimpimage-convert-indexed.c | 4473 ++++++++++++++++++++++++++++++++++++++++++++++++++++ app/core/gimpimage-convert-indexed.h | 41 + app/core/gimpimage-convert-type.c | 4452 +-------------------------------------------------- app/core/gimpimage-convert-type.h | 25 +- app/dialogs/convert-type-dialog.c | 21 +- app/pdb/image-convert-cmds.c | 21 +- po/POTFILES.in | 1 + tools/pdbgen/pdb/image_convert.pdb | 21 +- 10 files changed, 4584 insertions(+), 4477 deletions(-) commit 4086932e8d575d6317ba2962c7c5769eb69987d9 Author: Michael Natterer <mitch@gimp.org> Date: Fri Apr 29 10:32:29 2016 +0200 app: tiny and completely irrelevant stylistic cleanup app/core/gimpimage-convert-precision.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) commit ef4ab94a1258929a9e365b8494d4d5e829df3636 Author: Michael Natterer <mitch@gimp.org> Date: Fri Apr 29 00:42:42 2016 +0200 app: change GimpDrawable::convert_type() to take a target profile instead of just a boolean "convert_profile". This takes the logic to figure the right target profile out of gimp_layer_convert_type(), it can't possibly know everything about how to convert anyway, and having the logic in the callers conveniently splits it up and distributes its parts to the places they belong. This commit should cause no behavor change and is just preparation for fixing bug 765176. app/core/gimpchannel.c | 6 +-- app/core/gimpdrawable.c | 14 +++---- app/core/gimpdrawable.h | 4 +- app/core/gimpgrouplayer.c | 7 ++-- app/core/gimpimage-convert-precision.c | 60 ++++++++++++++++++----------- app/core/gimpimage-convert-type.c | 25 ++++++++---- app/core/gimplayer.c | 105 +++++++++------------------------------------------ app/core/gimplayermask.c | 6 +-- app/core/gimpselection.c | 6 +-- app/text/gimptextlayer.c | 6 +-- app/text/gimptextundo.c | 2 +- 11 files changed, 98 insertions(+), 143 deletions(-)
I'm not sure what all to test. But color space conversion of a grayscale image from one grayscale profile to another does seem to work. And converting to a grayscale profile with the gamma=1.8 TRC, followed by converting to RGB, also works. What doesn't work was having the grayscale image at linear precision, converting it to a grayscale profile with for example the gamma=1.8 TRC, and then converting the image to perceptual precision, as the conversion to perceptual precision assumes the TRC is gamma=1.0, not gamma=1.8 or some other nonlinear TRC). But this isn't specifically a grayscale issue as the same thing happens with RGB images. Should I file a bug report? I can do some more "grayscale" testing tomorrow AM in case I missed something just now.
(In reply to Michael Natterer from comment #8) > > And, Mode -> RGB and Mode -> Grayscale should be changed to do the > following: > > - If the image has a built-in default profile assigned, just convert > to the new color model's built-in profile > > - Otherwise, tell the user there is a profile, and pop up the > profile conversion dialog for choosing a target profile, of course > containing the default builtin option, resulting in this workflow: > > 3a. Open the grayscale image from disk. > 3b. Do "Image/Mode/RGB" > 3c. If the grayscale had a profile, select the destination RGB profile. > 3d. Click on "Convert" and the conversion is done. > > Which is exactly the canonical way of converting to RGB/Grayscale, > plus an optional dialog, much like the "Convert to indedex" one, > so not unexpected. I'm not sure what "canonical way" means. Will the proposed "go through a mode change" approach work for "future GIMP" that allows to convert between Grayscale, RGB, CMYK, and maybe also LAB/XYZ or other color models? From the point of view of LCMS, the image Y/RGB/CMYK/etc values are converted to XYZ or LAB, depending on the connection space specified in the source color space, and then to the destination color space. From the point of view of GIMP, of course a lot of things need to change to get the image from one color model to another.
(In reply to Elle Stone from comment #10) > I'm not sure what all to test. But color space conversion of a grayscale > image from one grayscale profile to another does seem to work. And > converting to a grayscale profile with the gamma=1.8 TRC, followed by > converting to RGB, also works. That has worked before. > What doesn't work was having the grayscale image at linear precision, > converting it to a grayscale profile with for example the gamma=1.8 TRC, and > then converting the image to perceptual precision, as the conversion to > perceptual precision assumes the TRC is gamma=1.0, not gamma=1.8 or some > other nonlinear TRC). But this isn't specifically a grayscale issue as the > same thing happens with RGB images. Should I file a bug report? No need for a bug, This is simply the very same babl limitation we are talking about all the time. What's new is only that you can now specify a profile to convert to when saying mode -> RGB or mode -> gray.
Also, you can now drop or copy layers between rgb and gray images and the profiles are respected.
Hmm, I think this bug is fixed. Am I missing something?
Last minute testing, everthing looks fine.
Thanks :)