gnome-scan r720 - in trunk: . modules/gsane



Author: bersace
Date: Sat Dec 20 18:11:25 2008
New Revision: 720
URL: http://svn.gnome.org/viewvc/gnome-scan?rev=720&view=rev

Log:
Fixed processing of arbitrary sized chunk.

Modified:
   trunk/ChangeLog
   trunk/modules/gsane/gsane-processor.c

Modified: trunk/modules/gsane/gsane-processor.c
==============================================================================
--- trunk/modules/gsane/gsane-processor.c	(original)
+++ trunk/modules/gsane/gsane-processor.c	Sat Dec 20 18:11:25 2008
@@ -27,7 +27,7 @@
 	const SANE_Parameters *params;
 	gdouble bytes_per_pixel;
 	/* total bytes read*/
-	volatile guint bytes_read;
+	volatile guint bytes_processed;
 	/* total number of frame to acquire to get the entire image */
 	guint frame_count;
 	/* offset of a sample in bytes */
@@ -48,6 +48,59 @@
 }
 
 
+static void
+gsane_processor_process_void(GSaneProcessor *self, guchar *buf, guint buf_len)
+{
+}
+
+/* process Y or RGB 8/16 bit into â 8/16 bit. */
+static void
+gsane_processor_process_8bit(GSaneProcessor *self, guchar *buf, guint buf_len)
+{
+	GeglRectangle roi = self->priv->rect;
+	gegl_buffer_set (self->priv->buffer, &roi, self->priv->format, buf, GEGL_AUTO_ROWSTRIDE);
+}
+
+static void
+gsane_processor_process_three_pass_8bit(GSaneProcessor *self, guchar *buf, guint buf_len)
+{
+	GeglRectangle roi = self->priv->rect;
+	guchar *buf3 = g_new0(guchar, 3*buf_len);
+	guint i;
+	gegl_buffer_get(self->priv->buffer, 1.0, &roi, self->priv->format, buf3, GEGL_AUTO_ROWSTRIDE);
+	for (i = 0; i < buf_len; i++)
+		buf3[3*i+self->priv->sample_offset] = buf[i];
+	gegl_buffer_set(self->priv->buffer, &roi, self->priv->format, buf3, GEGL_AUTO_ROWSTRIDE);
+	g_free(buf3);
+}
+
+static GSaneProcessorFunc
+gsane_processor_get_func(GSaneProcessor *self)
+{
+	GSaneProcessorFunc func = gsane_processor_process_void;
+	switch(self->priv->params->format) {
+	case SANE_FRAME_RGB:
+	case SANE_FRAME_GRAY:
+		if (self->priv->params->depth%8 == 0)
+			func = gsane_processor_process_8bit;
+		else
+			g_warning("Unsupported %dbit frame format.", self->priv->params->depth);
+		break;
+	case SANE_FRAME_RED:
+	case SANE_FRAME_GREEN:
+	case SANE_FRAME_BLUE:
+		if (self->priv->params->depth%8 == 0)
+			func = gsane_processor_process_three_pass_8bit;
+		else
+			g_warning("Unsupported %dbit three-pass frame format", self->priv->params->depth);
+		break;
+	default:
+		g_warning("Unsupported SANE frame format.");
+		break;
+	}
+	return func;
+}
+
 static const gchar*
 gsane_processor_get_babl_color_model(GSaneProcessor *self)
 {
@@ -91,19 +144,6 @@
 	return babl_format(name);
 }
 
-static void
-gsane_processor_process_void(GSaneProcessor *self, guchar *buf, guint buf_len)
-{
-}
-
-/* process Y or RGB 8/16 bit into â 8/16 bit. */
-static void
-gsane_processor_process_8bit(GSaneProcessor *self, guchar *buf, guint buf_len)
-{
-	GeglRectangle roi = self->priv->rect;
-	gegl_buffer_set (self->priv->buffer, &roi, self->priv->format, buf, GEGL_AUTO_ROWSTRIDE);
-}
-
 static guint
 gsane_processor_get_sample_offset(GSaneProcessor *self)
 {
@@ -119,46 +159,6 @@
 	}
 }
 
-static void
-gsane_processor_process_three_pass_8bit(GSaneProcessor *self, guchar *buf, guint buf_len)
-{
-	GeglRectangle roi = self->priv->rect;
-	guchar *buf3 = g_new0(guchar, 3*buf_len);
-	guint i;
-	gegl_buffer_get(self->priv->buffer, 1.0, &roi, self->priv->format, buf3, GEGL_AUTO_ROWSTRIDE);
-	for (i = 0; i < buf_len; i++)
-		buf3[3*i+self->priv->sample_offset] = buf[i];
-	gegl_buffer_set(self->priv->buffer, &roi, self->priv->format, buf3, GEGL_AUTO_ROWSTRIDE);
-	g_free(buf3);
-}
-
-static GSaneProcessorFunc
-gsane_processor_get_func(GSaneProcessor *self)
-{
-	GSaneProcessorFunc func = gsane_processor_process_void;
-	switch(self->priv->params->format) {
-	case SANE_FRAME_RGB:
-	case SANE_FRAME_GRAY:
-		if (self->priv->params->depth%8 == 0)
-			func = gsane_processor_process_8bit;
-		else
-			g_warning("Unsupported %dbit frame format.", self->priv->params->depth);
-		break;
-	case SANE_FRAME_RED:
-	case SANE_FRAME_GREEN:
-	case SANE_FRAME_BLUE:
-		if (self->priv->params->depth%8 == 0)
-			func = gsane_processor_process_three_pass_8bit;
-		else
-			g_warning("Unsupported %dbit three-pass frame format", self->priv->params->depth);
-		break;
-	default:
-		g_warning("Unsupported SANE frame format.");
-		break;
-	}
-	return func;
-}
-
 GeglBuffer*
 gsane_processor_prepare_image(GSaneProcessor *self, SANE_Parameters* params, guint frame_count)
 {
@@ -184,7 +184,7 @@
 gsane_processor_prepare_frame(GSaneProcessor *self, SANE_Parameters* params)
 {
 	self->priv->params = params;
-	self->priv->bytes_read = 0;
+	self->priv->bytes_processed = 0;
 	self->priv->sample_offset = gsane_processor_get_sample_offset(self);
 	switch(params->format) {
 	case SANE_FRAME_GRAY:
@@ -214,10 +214,11 @@
 	g_return_if_fail(self->priv->process);
 	guchar* next_buf = NULL;
 	guint next_buf_len = 0;
+	guint bytes_processed = buf_len;
 
 	/* define the rect corresponding buf */
-	self->priv->rect.y = self->priv->bytes_read / self->priv->params->bytes_per_line;
-	self->priv->rect.x = self->priv->bytes_read % self->priv->params->bytes_per_line;
+	self->priv->rect.y = self->priv->bytes_processed / self->priv->params->bytes_per_line;
+	self->priv->rect.x = self->priv->bytes_processed % self->priv->params->bytes_per_line;
 	guint pixel_to_end_of_line = self->priv->params->pixels_per_line - self->priv->rect.x;
 	guint pixels_in_buf = (gdouble)buf_len / self->priv->bytes_per_pixel;
 	self->priv->rect.width = MIN (pixels_in_buf - self->priv->rect.x, pixel_to_end_of_line);
@@ -229,9 +230,9 @@
 		self->priv->rect.height = 1;
 		if (pixels_in_buf > self->priv->rect.width) {
 			/* recursion for the rest (will start at x=0) */
-			guint processed_bytes = self->priv->rect.width * self->priv->bytes_per_pixel;
-			next_buf = buf + processed_bytes;
-			next_buf_len = buf_len - processed_bytes;
+			bytes_processed = self->priv->rect.width * self->priv->bytes_per_pixel;
+			next_buf_len = buf_len - bytes_processed;
+			next_buf = buf + bytes_processed;
 		}
 	}
 	else {
@@ -240,9 +241,9 @@
 		guint last_line_length = pixels_in_buf % self->priv->rect.width;
 		if (last_line_length > 0) {
 			/* the last line needs recursion */
-			guint left_bytes = last_line_length * self->priv->bytes_per_pixel;
-			next_buf = buf + buf_len - left_bytes;
-			next_buf_len = left_bytes;
+			next_buf_len = last_line_length * self->priv->bytes_per_pixel;
+			bytes_processed = buf_len - next_buf_len;
+			next_buf = buf + bytes_processed;
 		}
 	}
 
@@ -255,11 +256,11 @@
 	/* process */
 	g_debug("Processing %dx%d+%d+%d", self->priv->rect.width, self->priv->rect.height, self->priv->rect.x, self->priv->rect.y);
 	self->priv->process(self, buf, buf_len);
-	self->priv->bytes_read+= buf_len;
+	self->priv->bytes_processed+= bytes_processed;
 
 	/* recurse for next roi */
 	if (next_buf && next_buf_len)
-		gsane_processor_process(self, next_buf, buf_len);
+		gsane_processor_process(self, next_buf, next_buf_len);
 }
 
 void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]