File 16-bit-support.patch of Package iscan
From 9afeb0460dcb491ac6cba43519b368ca6327255c Mon Sep 17 00:00:00 2001
From: Henrik Andersson <henrik.4e@gmail.com>
Date: Tue, 4 Dec 2012 08:29:05 +0100
Subject: [PATCH 1/2] Add support for 16 bit color values solves issue were a
16 bit scan abruptly stops such as with V600.
---
backend/dip-obj.c | 72 ++++++++++++++++++++++++++++++++---------------
1 file changed, 50 insertions(+), 22 deletions(-)
diff --git a/backend/dip-obj.c b/backend/dip-obj.c
index 021cb01..ce0d4ea 100644
--- a/backend/dip-obj.c
+++ b/backend/dip-obj.c
@@ -555,44 +555,72 @@ dip_change_GRB_to_RGB (const void *self, const buffer *buf)
return;
}
-/*! \todo Add support for 16 bit color values (#816).
- */
void
dip_apply_color_profile (const void *self, const buffer *buf,
const double profile[9])
{
SANE_Int i;
- SANE_Byte *r_buf, *g_buf, *b_buf;
double red, grn, blu;
- SANE_Byte *data;
SANE_Int size;
require (dip == self && buf && profile);
- require (8 == buf->ctx.depth);
+ require (buf->ctx.depth == 8 || buf->ctx.depth == 16);
if (SANE_FRAME_RGB != buf->ctx.format)
return;
- data = buf->ptr;
- size = buf->end - buf->ptr;
+ if (buf->ctx.depth == 8)
+ {
+ SANE_Byte *r_buf, *g_buf, *b_buf;
+ SANE_Byte *data;
+
+ data = buf->ptr;
+ size = buf->end - buf->ptr;
- for (i = 0; i < size / 3; i++)
+ for (i = 0; i < size / 3; i++)
+ {
+ r_buf = data;
+ g_buf = data + 1;
+ b_buf = data + 2;
+
+ red =
+ profile[0] * (*r_buf) + profile[1] * (*g_buf) + profile[2] * (*b_buf);
+ grn =
+ profile[3] * (*r_buf) + profile[4] * (*g_buf) + profile[5] * (*b_buf);
+ blu =
+ profile[6] * (*r_buf) + profile[7] * (*g_buf) + profile[8] * (*b_buf);
+
+ *data++ = clamp (red, 0, 255);
+ *data++ = clamp (grn, 0, 255);
+ *data++ = clamp (blu, 0, 255);
+ }
+ }
+ else if (buf->ctx.depth == 16)
{
- r_buf = data;
- g_buf = data + 1;
- b_buf = data + 2;
-
- red =
- profile[0] * (*r_buf) + profile[1] * (*g_buf) + profile[2] * (*b_buf);
- grn =
- profile[3] * (*r_buf) + profile[4] * (*g_buf) + profile[5] * (*b_buf);
- blu =
- profile[6] * (*r_buf) + profile[7] * (*g_buf) + profile[8] * (*b_buf);
-
- *data++ = clamp (red, 0, 255);
- *data++ = clamp (grn, 0, 255);
- *data++ = clamp (blu, 0, 255);
+ SANE_Word *r_buf, *g_buf, *b_buf;
+ SANE_Word *data;
+
+ data = (SANE_Word *)buf->ptr;
+ size = buf->end - buf->ptr;
+
+ for (i = 0; i < size / 3; i++)
+ {
+ r_buf = data;
+ g_buf = data + 1;
+ b_buf = data + 2;
+
+ red =
+ profile[0] * (*r_buf) + profile[1] * (*g_buf) + profile[2] * (*b_buf);
+ grn =
+ profile[3] * (*r_buf) + profile[4] * (*g_buf) + profile[5] * (*b_buf);
+ blu =
+ profile[6] * (*r_buf) + profile[7] * (*g_buf) + profile[8] * (*b_buf);
+
+ *data++ = clamp (red, 0, 65535);
+ *data++ = clamp (grn, 0, 65535);
+ *data++ = clamp (blu, 0, 65535);
+ }
}
}
--
2.50.1
From 007ca826a7b4e59d2706544ddd2a113ded3518c6 Mon Sep 17 00:00:00 2001
From: Henrik Andersson <hean01@users.sourceforge.net>
Date: Tue, 4 Dec 2012 22:14:55 +0100
Subject: [PATCH 2/2] Use a correct data size for 16bit data SANE_Word is int.
---
backend/dip-obj.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/backend/dip-obj.c b/backend/dip-obj.c
index ce0d4ea..cbbc1df 100644
--- a/backend/dip-obj.c
+++ b/backend/dip-obj.c
@@ -598,13 +598,11 @@ dip_apply_color_profile (const void *self, const buffer *buf,
}
else if (buf->ctx.depth == 16)
{
- SANE_Word *r_buf, *g_buf, *b_buf;
- SANE_Word *data;
+ uint16_t *r_buf, *g_buf, *b_buf;
+ uint16_t *data;
- data = (SANE_Word *)buf->ptr;
- size = buf->end - buf->ptr;
-
- for (i = 0; i < size / 3; i++)
+ data = (uint16_t *)buf->ptr;
+ while(data < buf->end)
{
r_buf = data;
g_buf = data + 1;
--
2.50.1