gnome-scan r724 - in trunk: . modules/gsane
- From: bersace svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-scan r724 - in trunk: . modules/gsane
- Date: Sat, 20 Dec 2008 20:24:53 +0000 (UTC)
Author: bersace
Date: Sat Dec 20 20:24:52 2008
New Revision: 724
URL: http://svn.gnome.org/viewvc/gnome-scan?rev=724&view=rev
Log:
Fix RGB u16 three-pass processing.
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 20:24:52 2008
@@ -20,23 +20,30 @@
*/
#include "gsane-processor.h"
+#include <string.h>
typedef void (*GSaneProcessorFunc) (GSaneProcessor *self, guchar *buf, guint buf_len);
struct _GSaneProcessorPrivate {
const SANE_Parameters *params;
+ /* bytes per pixel in one frame (not final pixel stride). It
+ is a sample stride for one sample frame. May be < 1 for
+ depth < 8bit */
gdouble bytes_per_pixel;
+ /* output format of processor */
+ Babl* format;
+ /* target buffer */
+ GeglBuffer *buffer;
+ /* rect representing the current buffer being processed. Might
+ make sense to add a param instead ? */
+ volatile GeglRectangle rect;
/* total 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 */
+ /* offset of a sample in bytes for three-pass acquisition */
guint sample_offset;
- /* output format of processor */
- Babl* format;
- GeglBuffer *buffer;
- volatile GeglRectangle rect;
- /* processor function */
+ /* pointer to the processor function */
GSaneProcessorFunc process;
};
@@ -65,11 +72,20 @@
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;
+ guchar *buf3 = g_new0(guchar, self->priv->frame_count*buf_len);
+ guint i, pix_count;
+ guint src_pos, dest_pos;
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];
+ /* number of pixels in buf */
+ pix_count = buf_len / self->priv->bytes_per_pixel;
+ /* copy pixel per pixel from buf to buf3 */
+ for (i = 0; i < pix_count; i++) {
+ /* pos of pixel i in buf */
+ src_pos = i * self->priv->bytes_per_pixel;
+ /* pos of pixel i in buf3 */
+ dest_pos = i * self->priv->format->format.bytes_per_pixel + self->priv->sample_offset;
+ memcpy(buf3+dest_pos, buf+src_pos, self->priv->bytes_per_pixel);
+ }
gegl_buffer_set(self->priv->buffer, &roi, self->priv->format, buf3, GEGL_AUTO_ROWSTRIDE);
g_free(buf3);
}
@@ -144,6 +160,8 @@
return babl_format(name);
}
+/* Return the offset in pixel stride of the samples acquired in
+ current frame.*/
static guint
gsane_processor_get_sample_offset(GSaneProcessor *self)
{
@@ -151,14 +169,16 @@
case SANE_FRAME_RED:
return 0;
case SANE_FRAME_GREEN:
- return 1;
+ return self->priv->bytes_per_pixel;
case SANE_FRAME_BLUE:
- return 2;
+ return 2 * self->priv->bytes_per_pixel;
default:
return 0;
}
}
+/* Initialize acquisition of one image. Returns the buffer initialized
+ with right format and extent. */
GeglBuffer*
gsane_processor_prepare_image(GSaneProcessor *self, SANE_Parameters* params, guint frame_count)
{
@@ -173,7 +193,7 @@
self->priv->params = params;
self->priv->frame_count = frame_count;
- self->priv->bytes_per_pixel = (gdouble)params->bytes_per_line/(gdouble)params->pixels_per_line;
+ self->priv->bytes_per_pixel = (gdouble)params->bytes_per_line / (gdouble)params->pixels_per_line;
self->priv->process = gsane_processor_get_func(self);
g_return_val_if_fail(self->priv->process, NULL);
@@ -233,7 +253,6 @@
}
/* 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_processed+= bytes_processed;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]