[Plug-in] Color management of preview area

I did some good progress with the color management of the preview area for the GIMP plug-in.

The patched code in this gist adds a

convert_to_display()

function that is called at this point in the code:

convert_to_display(computed_preview);
calibrate_image(computed_preview,sp,true);
convert_image2uchar(computed_preview);
computed_preview.channel(0);

The code seems to work fine, but it would be great if somebody else could test it. For this, I have prepared a special version of the GIMP AppImage with the patched gmic plug-in: Dropbox - gimp-2.9.5-20160906.glibc2.15-x86_64.AppImage - Simplify your life

What remains to be done:

  • color-manage the preview image when no filter is selected
  • automatically track display profile changes when the window is moved to a different monitor
3 Likes

You are a champion! Can you recommend some test cases?

The differences are more evident if you try to open an image in some wide-gamut color space (pro photo, rec.2020, ACEScgā€¦).

Also, try to change the monitor profile and see if the previews in gimp and gmic match.

In gmic, you need to select a filter to activate the color management (Iā€™ll see with @David_Tschumperle how to solve this little issue). For example, you can select ā€œColor ā†’ basic adjustmentsā€ with all the sliders at zero.

And guess what? You can download the new appimage side-by-side with the previous one, and run alternatively one or the other to check the differencesā€¦ a very convenient way to test new features!

If you need an obvious test profile you can use this one.

1 Like

Just briefly tried this, you are definitely on a roll @Carmelo_DrRaw!

Seems to work well, once you choose a filter. Thatā€™s pretty much all you need IMO. Sure fine-tune stuff, but definitely recommendable now.

EDIT: Oh, and I notice the appimage lost 3mb from the previous one, so double bonus!

Great work!

1 Like

Hello @Carmelo_DrRaw, that looks really great ! Thanks for the effort !
Iā€™ll sent you a message to discuss some details :slight_smile:

1 Like

OK, some news. I got the patch from @Carmelo_DrRaw, and started to work on a clean integration into the Gā€™MIC plug-in source code. Iā€™ve also managed to make the preview display the color-corrected version of the image when no filters are selected. The current GimpPreview widget of the GIMP API is a bit wonky, so this was not a cakewalk. There are probably some bugs remaining, but the code is already available in the current git master, so you are welcome to try compiling it and test it.
Maybe Andrea will have some time to include this version in his AppImage ?

1 Like

@Carmelo_DrRaw, we would be really interested by any hints to make our new Qt-based plug-in color-managed as well for GIMP 2.9. I donā€™t get how to modify the code youā€™ve done for the GTK-based plug-in, to make it work with the Qt-based plug-in.

Basically, what we have is a float* RGB (or RGBA) buffer, and weā€™d like to modify it in-place to apply the GIMP color profile to the pixels it contains.

Any idea how to do that ?

Hi David! Sorry for answering late, but Iā€™m buried under a huge pile of workā€¦

The relevant lines of code in the GTK plug-in are here:

https://github.com/dtschump/gmic/blob/master/src/gmic_gimp_gtk.cpp#L1812

Basically one gets the icc transform from sRGB to the display profile via

gimp_image_get_color_transform_from_srgb_double(gimp_item_get_image(image_id))

and then apples the transform to a buffer of floating-point data:

gimp_color_transform_process_pixels(transform,fmt,corrected,fmt,corrected,corrected.height()*corrected.depth());

Is this what you need? Could you point me to the lines of code in the QT plug-in where you would like to introduce the color transform?

Hi Andrea,
The problem indeed is that those lines do not compile :frowning:
it was a try Iā€™ve made, but without any success.

Can you post the compilation errors you are getting? Maybe the fix is simpleā€¦

Yes, here they are :

> g++ -o gmic_gimp_gtk gmic_gimp_gtk.cpp gmic_gimp_gtk.o -Dgmic_gui `gimptool-2.0 --cflags` `gimptool-2.0 --libs` -Dgmic_build -Dcimg_use_zlib  -Dgmic_prerelease=\"170428\"  -std=c++11 -pedantic -Wall -Wextra -Wfatal-errors -Dcimg_use_vt100 -Dcimg_use_abort -Dgmic_is_parallel -Dcimg_use_fftw3  -Dcimg_use_curl  -Dcimg_use_png -I/usr/include/libpng12 -Dcimg_use_rng -DGIMP_DISABLE_DEPRECATED -fopenmp -Dcimg_use_openmp -Dcimg_display=1 -Dcimg_appname=\"gmic\"    -lz  -L/usr/lib -lm -lpthread -lfftw3 -lfftw3_threads -lcurl -lpng12 -lgomp -lX11 -lpthread 
> gmic_gimp_gtk.cpp: In function ā€˜cimg_library::CImg<T>& apply_icc(cimg_library::CImg<T>&)ā€™:
> gmic_gimp_gtk.cpp:1812:118: error: there are no arguments to ā€˜gimp_image_get_color_transform_from_srgb_doubleā€™ that depend on a template parameter, so a declaration of ā€˜gimp_image_get_color_transform_from_srgb_doubleā€™ must be available [-fpermissive]
>    GimpColorTransform *const transform = gimp_image_get_color_transform_from_srgb_double(gimp_item_get_image(image_id));

It looks like the function is not recognized. Maybe I should include an additional header for having that ?