summarylogtreecommitdiffstats
path: root/hain01commits2dip-obj.patch
blob: d64aea37e0e1a57108ebf93515436535614e9908 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
--- backend/dip-obj.c
+++ backend/dip-obj.c
@@ -556,43 +556,72 @@
 }
 
 /*! \todo Add support for 16 bit color values (#816).
+	Added the commits of https://github.com/hean01/iscan/commit/147edc66ceddb34b5e0c8745a08ce6c96e7e02b5 and https://github.com/hean01/iscan/commit/575468d83bb70d928f5893c4c4b4ce7faa15e3d5 to support 16bit color.
  */
 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;
 
-  for (i = 0; i < size / 3; i++)
+    data = 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, 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);
+	uint16_t *r_buf, *g_buf, *b_buf;
+    uint16_t *data;
+	
+    data = (uint16_t *)buf->ptr;
+    while(data < buf->end)
+    {
+      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);
+    }
   }
 }