libgimpcolor: use gimp_color_profile_get_format() in GimpColorTransform

and use babl to convert between profiles if possible. With the default
BABL_TOLERANCE this is about 5 times faster than lcms on my test image.

Using babl can be disabled by setting GIMP_COLOR_TRANSFORM_DISABLE_BABL.
This commit is contained in:
Michael Natterer 2017-09-02 20:32:50 +02:00
parent d092ee9102
commit 4cfeb53d09
1 changed files with 73 additions and 7 deletions

View File

@ -69,9 +69,11 @@ struct _GimpColorTransformPrivate
{ {
GimpColorProfile *src_profile; GimpColorProfile *src_profile;
const Babl *src_format; const Babl *src_format;
const Babl *src_space_format;
GimpColorProfile *dest_profile; GimpColorProfile *dest_profile;
const Babl *dest_format; const Babl *dest_format;
const Babl *dest_space_format;
cmsHTRANSFORM transform; cmsHTRANSFORM transform;
}; };
@ -198,6 +200,7 @@ gimp_color_transform_new (GimpColorProfile *src_profile,
cmsHPROFILE dest_lcms; cmsHPROFILE dest_lcms;
cmsUInt32Number lcms_src_format; cmsUInt32Number lcms_src_format;
cmsUInt32Number lcms_dest_format; cmsUInt32Number lcms_dest_format;
GError *error = NULL;
g_return_val_if_fail (GIMP_IS_COLOR_PROFILE (src_profile), NULL); g_return_val_if_fail (GIMP_IS_COLOR_PROFILE (src_profile), NULL);
g_return_val_if_fail (src_format != NULL, NULL); g_return_val_if_fail (src_format != NULL, NULL);
@ -211,14 +214,50 @@ gimp_color_transform_new (GimpColorProfile *src_profile,
priv = transform->priv; priv = transform->priv;
src_lcms = gimp_color_profile_get_lcms_profile (src_profile); priv->src_space_format = gimp_color_profile_get_format (src_profile,
dest_lcms = gimp_color_profile_get_lcms_profile (dest_profile); src_format,
&error);
if (! priv->src_space_format)
{
g_printerr ("%s: error making format: %s\n",
G_STRFUNC, error->message);
g_clear_error (&error);
}
priv->dest_space_format = gimp_color_profile_get_format (dest_profile,
dest_format,
&error);
if (! priv->dest_space_format)
{
g_printerr ("%s: error making format: %s\n",
G_STRFUNC, error->message);
g_clear_error (&error);
}
if (! g_getenv ("GIMP_COLOR_TRANSFORM_DISABLE_BABL") &&
priv->src_space_format && priv->dest_space_format)
{
priv->src_format = src_format;
priv->dest_format = dest_format;
g_printerr ("%s: using babl for '%s' -> '%s'\n",
G_STRFUNC,
gimp_color_profile_get_label (src_profile),
gimp_color_profile_get_label (dest_profile));
return transform;
}
priv->src_space_format = NULL;
priv->dest_space_format = NULL;
priv->src_format = gimp_color_profile_get_lcms_format (src_format, priv->src_format = gimp_color_profile_get_lcms_format (src_format,
&lcms_src_format); &lcms_src_format);
priv->dest_format = gimp_color_profile_get_lcms_format (dest_format, priv->dest_format = gimp_color_profile_get_lcms_format (dest_format,
&lcms_dest_format); &lcms_dest_format);
src_lcms = gimp_color_profile_get_lcms_profile (src_profile);
dest_lcms = gimp_color_profile_get_lcms_profile (dest_profile);
lcms_error_clear (); lcms_error_clear ();
priv->transform = cmsCreateTransform (src_lcms, lcms_src_format, priv->transform = cmsCreateTransform (src_lcms, lcms_src_format,
@ -387,7 +426,16 @@ gimp_color_transform_process_pixels (GimpColorTransform *transform,
dest = dest_pixels; dest = dest_pixels;
} }
if (priv->transform)
{
cmsDoTransform (priv->transform, src, dest, length); cmsDoTransform (priv->transform, src, dest, length);
}
else
{
babl_process (babl_fish (priv->src_space_format,
priv->dest_space_format),
src, dest, length);
}
if (src_format != priv->src_format) if (src_format != priv->src_format)
{ {
@ -457,9 +505,18 @@ gimp_color_transform_process_buffer (GimpColorTransform *transform,
GEGL_ABYSS_NONE); GEGL_ABYSS_NONE);
while (gegl_buffer_iterator_next (iter)) while (gegl_buffer_iterator_next (iter))
{
if (priv->transform)
{ {
cmsDoTransform (priv->transform, cmsDoTransform (priv->transform,
iter->data[0], iter->data[1], iter->length); iter->data[0], iter->data[1], iter->length);
}
else
{
babl_process (babl_fish (priv->src_space_format,
priv->dest_space_format),
iter->data[0], iter->data[1], iter->length);
}
done_pixels += iter->roi[0].width * iter->roi[0].height; done_pixels += iter->roi[0].width * iter->roi[0].height;
@ -476,9 +533,18 @@ gimp_color_transform_process_buffer (GimpColorTransform *transform,
GEGL_ABYSS_NONE); GEGL_ABYSS_NONE);
while (gegl_buffer_iterator_next (iter)) while (gegl_buffer_iterator_next (iter))
{
if (priv->transform)
{ {
cmsDoTransform (priv->transform, cmsDoTransform (priv->transform,
iter->data[0], iter->data[0], iter->length); iter->data[0], iter->data[0], iter->length);
}
else
{
babl_process (babl_fish (priv->src_space_format,
priv->dest_space_format),
iter->data[0], iter->data[0], iter->length);
}
done_pixels += iter->roi[0].width * iter->roi[0].height; done_pixels += iter->roi[0].width * iter->roi[0].height;