Elle's babl crashes with non-RGB formats

Hi
I’m writing a plugin to work with Gimp CCE and whenever I try to do a conversion involving non-RGB babl formats (like “CIE Lab float”) the program crashes with a segfault. Since it’s the CCE version, it’s linked with Elle’s modified babl (GitHub - ellelstone/babl: This version of babl has been modified for use with GIMP-CCE (https://github.com/ellelstone/gimp):). I then ran a simple conversion test that is bundled with babl and it also crashed like the plugin. When I linked this same test to babl’s master branch, it worked without problems. It seems there is a null pointer being passed to the babl_get_user_data function when we try to create a non-RGB babl_format. I’m attaching the test and the backtrace generated when it crashed. Could someone help me to figure out what’s happening with this version of babl?

Thanks!

backtrace.txt (1.7 KB)
rgb_to_lab_u8.zip (1.0 KB)

@Elle might be able to help you!

Does your code retrieve/specify colorant info to feed to babl? Most cce code retrieves the image colorants. But eg gimp/plug-ins/common/compose.c at master · ellelstone/gimp · GitHub specifies sRGB colorants as I haven’t written code to allow user-specified colorants such as from an ICC profile from disk.

cce is an interim project to fill a temporary gap in default gimp functionality. cce is currently one xcf version behind default gimp 2.9, and I don’t know if/when i’ll be able to update cce (strained wrist, currently typing with one hand). It would be better to write a default gimp plug-in.

1 Like

Hi, Elle
My code indeed didn’t feed the colorants to babl. That was the mistake. What is the recommended way to get the image colorants? Or should I hardcode this info like in the compose plugin?

I really loved your version of Gimp. I plan to use it until the official version gets all of the cce functionality. As this plugin is only for personal use I prefer to make it work with Gimp CCE. I’m completely new to Gimp’s code and learned it’s plugin API just few days ago but I may help you with some simple tasks to update cce.

I hope you wrist gets better soon!

Thanks!

Since @Elle has an hard time to write, I can give you some assistance to retrieve the gimp working color space, and from there the colorants… if that’s what you need.

Just give me a couple of hours.

@caiosouza

Here is how to get the ICC profile associated to the GIMP image:

and

Once you have the profile, here is how to retrieve the colorants from a matrix ICC profile:

Hope this will help you! Otherwise just post more questions, I will try to answer as quickly as possible…

2 Likes

Thank you very much, @Elle and @Carmelo_DrRaw!
Now I have babl correctly initialized. Here is the code I’m using (without any error checking!) in case someone else needs it in the future.

/* Currently used profile */
GimpColorProfile *profile = gimp_image_get_effective_color_profile(image_id);

colorant_data = g_new(double, 9);
if (gimp_color_profile_is_rgb(profile)) {
    /* Retrieve colorants from the RGB profile */
    gpointer lcms_profile = gimp_color_profile_get_lcms_profile(profile);

    cmsCIEXYZ *red = (cmsCIEXYZ*)cmsReadTag(lcms_profile, cmsSigRedColorantTag);
    cmsCIEXYZ *green = (cmsCIEXYZ*)cmsReadTag(lcms_profile, cmsSigGreenColorantTag);
    cmsCIEXYZ *blue = (cmsCIEXYZ*)cmsReadTag(lcms_profile, cmsSigBlueColorantTag);

    colorant_data[0] = red->X;
    colorant_data[1] = red->Y;
    colorant_data[2] = red->Z;
    colorant_data[3] = green->X;
    colorant_data[4] = green->Y;
    colorant_data[5] = green->Z;
    colorant_data[6] = blue->X;
    colorant_data[7] = blue->Y;
    colorant_data[8] = blue->Z;
} else {
    /* Assign colorants for grayscale images */
    colorant_data[0] = 0.43603516;
    colorant_data[1] = 0.22248840;
    colorant_data[2] = 0.01391602;
    colorant_data[3] = 0.38511658;
    colorant_data[4] = 0.71690369;
    colorant_data[5] = 0.09706116;
    colorant_data[6] = 0.14305115;
    colorant_data[7] = 0.06060791;
    colorant_data[8] = 0.71392822;
}

colorant_babl = babl_format("RGB float");
babl_set_user_data(colorant_babl, colorant_data);
2 Likes

@Carmelo_DrRaw - thanks much! for the code hints. @caiosouza - thanks much! for posting your code - looks excellent!