[gimp] libgimpcolor: add gimp_color_transform_can_gegl_copy()
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] libgimpcolor: add gimp_color_transform_can_gegl_copy()
- Date: Thu, 26 May 2016 21:15:16 +0000 (UTC)
commit ca349f88cd09c1cca2a5808847b0f2ba04f444c8
Author: Michael Natterer <mitch gimp org>
Date: Thu May 26 23:11:24 2016 +0200
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.
app/gegl/gimp-gegl-loops.c | 44 ----------------------------
libgimpcolor/gimpcolor.def | 1 +
libgimpcolor/gimpcolortransform.c | 58 ++++++++++++++++++++++++++++++++++++-
libgimpcolor/gimpcolortransform.h | 3 ++
4 files changed, 61 insertions(+), 45 deletions(-)
---
diff --git a/app/gegl/gimp-gegl-loops.c b/app/gegl/gimp-gegl-loops.c
index 9275e4c..2110bc4 100644
--- a/app/gegl/gimp-gegl-loops.c
+++ b/app/gegl/gimp-gegl-loops.c
@@ -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);
diff --git a/libgimpcolor/gimpcolor.def b/libgimpcolor/gimpcolor.def
index 24ab7f8..9c7cf94 100644
--- a/libgimpcolor/gimpcolor.def
+++ b/libgimpcolor/gimpcolor.def
@@ -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
diff --git a/libgimpcolor/gimpcolortransform.c b/libgimpcolor/gimpcolortransform.c
index 310e5f4..6d81075 100644
--- a/libgimpcolor/gimpcolortransform.c
+++ b/libgimpcolor/gimpcolortransform.c
@@ -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;
+}
diff --git a/libgimpcolor/gimpcolortransform.h b/libgimpcolor/gimpcolortransform.h
index cb6bee0..aaa9d76 100644
--- a/libgimpcolor/gimpcolortransform.h
+++ b/libgimpcolor/gimpcolortransform.h
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]