[Plug-in] Color management of preview area


(Carmelo Dr Raw) #1

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: https://www.dropbox.com/s/xfo6okeqhx4kv5u/gimp-2.9.5-20160906.glibc2.15-x86_64.AppImage?dl=0

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

(Mica) #2

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


(Carmelo Dr Raw) #3

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!


#4

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


#5

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!


(David Tschumperlé) #6

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


(David Tschumperlé) #7

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 ?


(David Tschumperlé) #8

@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 ?


(Carmelo Dr Raw) #9

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:

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?


(David Tschumperlé) #10

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


(Carmelo Dr Raw) #11

Can you post the compilation errors you are getting? Maybe the fix is simple…


(David Tschumperlé) #12

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 ?