[Rawstudio-commit] r3008 - branches/rawstudio-ng-color/plugins/colorspace-transform

Klaus Post klauspost at gmail.com
Sat Jan 16 14:28:11 CET 2010


Author: post
Date: 2010-01-16 14:28:11 +0100 (Sat, 16 Jan 2010)
New Revision: 3008

Modified:
   branches/rawstudio-ng-color/plugins/colorspace-transform/colorspace_transform.c
Log:
Disallow inplace 16 bit conversion(not used anyway), instead allow transform to return without copying the image, if no transform is needed.

Modified: branches/rawstudio-ng-color/plugins/colorspace-transform/colorspace_transform.c
===================================================================
--- branches/rawstudio-ng-color/plugins/colorspace-transform/colorspace_transform.c	2010-01-16 13:15:43 UTC (rev 3007)
+++ branches/rawstudio-ng-color/plugins/colorspace-transform/colorspace_transform.c	2010-01-16 13:28:11 UTC (rev 3008)
@@ -50,7 +50,7 @@
 
 static RSFilterResponse *get_image(RSFilter *filter, const RSFilterRequest *request);
 static RSFilterResponse *get_image8(RSFilter *filter, const RSFilterRequest *request);
-static void convert_colorspace16(RSColorspaceTransform *colorspace_transform, RS_IMAGE16 *input_image, RS_IMAGE16 *output_image, RSColorSpace *input_space, RSColorSpace *output_space);
+static gboolean convert_colorspace16(RSColorspaceTransform *colorspace_transform, RS_IMAGE16 *input_image, RS_IMAGE16 *output_image, RSColorSpace *input_space, RSColorSpace *output_space);
 static void convert_colorspace8(RSColorspaceTransform *colorspace_transform, RS_IMAGE16 *input_image, GdkPixbuf *output_image, RSColorSpace *input_space, RSColorSpace *output_space);
 
 static RSFilterClass *rs_colorspace_transform_parent_class = NULL;
@@ -98,22 +98,29 @@
 	RSColorSpace *input_space = rs_filter_param_get_object_with_type(RS_FILTER_PARAM(previous_response), "colorspace", RS_TYPE_COLOR_SPACE);
 	RSColorSpace *output_space = rs_filter_param_get_object_with_type(RS_FILTER_PARAM(request), "colorspace", RS_TYPE_COLOR_SPACE);
 
-	response = rs_filter_response_clone(previous_response);
 
 	printf("\033[33m16 input_space: %s\033[0m\n", (input_space) ? G_OBJECT_TYPE_NAME(input_space) : "none");
 	printf("\033[33m16 output_space: %s\n\033[0m", (output_space) ? G_OBJECT_TYPE_NAME(output_space) : "none");
 	if (input_space && output_space)
 	{
-		g_object_unref(previous_response);
 		output = rs_image16_copy(input, FALSE);
 
-		convert_colorspace16(colorspace_transform, input, output, input_space, output_space);
-
-		rs_filter_response_set_image(response, output);
-		g_object_unref(output);
-		g_object_unref(input);
-
-		return response;
+		if (convert_colorspace16(colorspace_transform, input, output, input_space, output_space))
+		{
+			/* Image was converted */
+			response = rs_filter_response_clone(previous_response);
+			g_object_unref(previous_response);
+			rs_filter_response_set_image(response, output);
+			g_object_unref(output);
+			g_object_unref(input);
+			return response;
+		} else
+		{
+			/* No conversion was needed */
+			g_object_unref(input);
+			g_object_unref(output);
+			return previous_response;
+		}
 	}
 	else
 	{
@@ -247,36 +254,24 @@
 	}
 }
 
-static void
+static gboolean
 convert_colorspace16(RSColorspaceTransform *colorspace_transform, RS_IMAGE16 *input_image, RS_IMAGE16 *output_image, RSColorSpace *input_space, RSColorSpace *output_space)
 {
 	g_assert(RS_IS_IMAGE16(input_image));
-	g_assert(RS_IS_IMAGE16(output_image) || (output_image == NULL));
+	g_assert(RS_IS_IMAGE16(output_image));
 	g_assert(RS_IS_COLOR_SPACE(input_space));
 	g_assert(RS_IS_COLOR_SPACE(output_space));
 
-	/* Do the transformation inplace if needed */
-	if (output_image == NULL)
-		output_image = input_image;
+	/* If input/output-image doesn't differ, return no transformation needed */
+	if (input_space == output_space)
+		return FALSE;
 
-	/* If both input/output images and colorspace are the same, return immediately */
-	if ((input_image == output_image) && (input_space == output_space))
-		return;
-
 	/* A few sanity checks */
 	g_assert(input_image->w == output_image->w);
 	g_assert(input_image->h == output_image->h);
 
-	/* If input/output-image differ, but colorspace is the same, do a simple copy */
-	if (input_space == output_space)
-	{
-		/* FIXME: Do some sanity checking! */
-		/* FIXME: Don't assume images have same pitch! */
-		memcpy(output_image->pixels, input_image->pixels, input_image->rowstride*input_image->h*2);
-	}
-
 	/* If a CMS is needed, do the transformation using LCMS */
-	else if (RS_COLOR_SPACE_REQUIRES_CMS(input_space) || RS_COLOR_SPACE_REQUIRES_CMS(output_space))
+	if (RS_COLOR_SPACE_REQUIRES_CMS(input_space) || RS_COLOR_SPACE_REQUIRES_CMS(output_space))
 	{
 		const RSIccProfile *i, *o;
 
@@ -304,6 +299,7 @@
 			input_image->pixelsize,
 			&mat);
 	}
+	return TRUE;
 }
 
 static void
@@ -315,10 +311,8 @@
 	g_assert(RS_IS_COLOR_SPACE(output_space));
 
 	/* A few sanity checks */
-	if (input_image->w != gdk_pixbuf_get_width(output_image))
-		return;
-	if (input_image->h != gdk_pixbuf_get_height(output_image))
-		return;
+	g_assert(input_image->w == gdk_pixbuf_get_width(output_image));
+	g_assert(input_image->h == gdk_pixbuf_get_height(output_image));
 
 	/* If a CMS is needed, do the transformation using LCMS */
 	if (RS_COLOR_SPACE_REQUIRES_CMS(input_space) || RS_COLOR_SPACE_REQUIRES_CMS(output_space))




More information about the Rawstudio-commit mailing list