Commit ca349f88 authored by Michael Natterer's avatar Michael Natterer 😴

libgimpcolor: add gimp_color_transform_can_gegl_copy()

Which takes two profiles and returns TRUE if converting between
them works correctly without a GimpColorTransform. Use it in
gimp_color_transform_new() to return a NULL transform if none
is needed. Took the code from gimp-gegl-loops.c.
parent 365f4e41
......@@ -661,42 +661,6 @@ gimp_gegl_index_to_mask (GeglBuffer *indexed_buffer,
}
}
static gboolean
gimp_color_profile_can_gegl_copy (GimpColorProfile *src_profile,
GimpColorProfile *dest_profile)
{
static GimpColorProfile *srgb_profile = NULL;
static GimpColorProfile *srgb_linear_profile = NULL;
static GimpColorProfile *gray_profile = NULL;
static GimpColorProfile *gray_linear_profile = NULL;
if (gimp_color_profile_is_equal (src_profile, dest_profile))
return TRUE;
if (! srgb_profile)
{
srgb_profile = gimp_color_profile_new_rgb_srgb ();
srgb_linear_profile = gimp_color_profile_new_rgb_srgb_linear ();
gray_profile = gimp_color_profile_new_d65_gray_srgb_trc ();
gray_linear_profile = gimp_color_profile_new_d65_gray_linear ();
}
if ((gimp_color_profile_is_equal (src_profile, srgb_profile) ||
gimp_color_profile_is_equal (src_profile, srgb_linear_profile) ||
gimp_color_profile_is_equal (src_profile, gray_profile) ||
gimp_color_profile_is_equal (src_profile, gray_linear_profile))
&&
(gimp_color_profile_is_equal (dest_profile, srgb_profile) ||
gimp_color_profile_is_equal (dest_profile, srgb_linear_profile) ||
gimp_color_profile_is_equal (dest_profile, gray_profile) ||
gimp_color_profile_is_equal (dest_profile, gray_linear_profile)))
{
return TRUE;
}
return FALSE;
}
void
gimp_gegl_convert_color_profile (GeglBuffer *src_buffer,
const GeglRectangle *src_rect,
......@@ -716,13 +680,6 @@ gimp_gegl_convert_color_profile (GeglBuffer *src_buffer,
src_format = gegl_buffer_get_format (src_buffer);
dest_format = gegl_buffer_get_format (dest_buffer);
if (gimp_color_profile_can_gegl_copy (src_profile, dest_profile))
{
gegl_buffer_copy (src_buffer, src_rect, GEGL_ABYSS_NONE,
dest_buffer, dest_rect);
return;
}
if (bpc)
flags |= GIMP_COLOR_TRANSFORM_FLAGS_BLACK_POINT_COMPENSATION;
......@@ -745,7 +702,6 @@ gimp_gegl_convert_color_profile (GeglBuffer *src_buffer,
}
else
{
/* FIXME: no idea if this ever happens */
gegl_buffer_copy (src_buffer, src_rect, GEGL_ABYSS_NONE,
dest_buffer, dest_rect);
......
......@@ -52,6 +52,7 @@ EXPORTS
gimp_color_profile_new_rgb_srgb_linear
gimp_color_profile_new_srgb_trc_from_color_profile
gimp_color_profile_save_to_file
gimp_color_transform_can_gegl_copy
gimp_color_transform_get_type
gimp_color_transform_new
gimp_color_transform_new_proofing
......
......@@ -155,7 +155,8 @@ gimp_color_transform_finalize (GObject *object)
*
* This function creates an color transform.
*
* Return value: the #GimpColorTransform, or %NULL.
* Return value: the #GimpColorTransform, or %NULL if no transform is needed
* to convert between pixels of @src_profile and @dest_profile.
*
* Since: 2.10
**/
......@@ -179,6 +180,9 @@ gimp_color_transform_new (GimpColorProfile *src_profile,
g_return_val_if_fail (GIMP_IS_COLOR_PROFILE (dest_profile), NULL);
g_return_val_if_fail (dest_format != NULL, NULL);
if (gimp_color_transform_can_gegl_copy (src_profile, dest_profile))
return NULL;
transform = g_object_new (GIMP_TYPE_COLOR_TRANSFORM, NULL);
priv = transform->priv;
......@@ -415,3 +419,55 @@ gimp_color_transform_process_buffer (GimpColorTransform *transform,
g_signal_emit (transform, gimp_color_transform_signals[PROGRESS], 0,
1.0);
}
/**
* gimp_color_transform_can_gegl_copy:
* @src_format: src profile
* @dest_format: dest profile
*
* This function checks if a GimpColorTransform is needed at all.
*
* Return value: %TRUE if pixels can be correctly converted between
* @src_profile and @dest_profile by simply using
* gegl_buffer_copy(), babl_process() or similar.
*
* Since: 2.10
**/
gboolean
gimp_color_transform_can_gegl_copy (GimpColorProfile *src_profile,
GimpColorProfile *dest_profile)
{
static GimpColorProfile *srgb_profile = NULL;
static GimpColorProfile *srgb_linear_profile = NULL;
static GimpColorProfile *gray_profile = NULL;
static GimpColorProfile *gray_linear_profile = NULL;
g_return_val_if_fail (GIMP_IS_COLOR_PROFILE (src_profile), FALSE);
g_return_val_if_fail (GIMP_IS_COLOR_PROFILE (dest_profile), FALSE);
if (gimp_color_profile_is_equal (src_profile, dest_profile))
return TRUE;
if (! srgb_profile)
{
srgb_profile = gimp_color_profile_new_rgb_srgb ();
srgb_linear_profile = gimp_color_profile_new_rgb_srgb_linear ();
gray_profile = gimp_color_profile_new_d65_gray_srgb_trc ();
gray_linear_profile = gimp_color_profile_new_d65_gray_linear ();
}
if ((gimp_color_profile_is_equal (src_profile, srgb_profile) ||
gimp_color_profile_is_equal (src_profile, srgb_linear_profile) ||
gimp_color_profile_is_equal (src_profile, gray_profile) ||
gimp_color_profile_is_equal (src_profile, gray_linear_profile))
&&
(gimp_color_profile_is_equal (dest_profile, srgb_profile) ||
gimp_color_profile_is_equal (dest_profile, srgb_linear_profile) ||
gimp_color_profile_is_equal (dest_profile, gray_profile) ||
gimp_color_profile_is_equal (dest_profile, gray_linear_profile)))
{
return TRUE;
}
return FALSE;
}
......@@ -106,6 +106,9 @@ void gimp_color_transform_process_buffer (GimpColorTransform *transfo
GeglBuffer *dest_buffer,
const GeglRectangle *dest_rect);
gboolean gimp_color_transform_can_gegl_copy (GimpColorProfile *src_profile,
GimpColorProfile *dest_profile);
G_END_DECLS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment