summaryrefslogtreecommitdiff
path: root/external/libtiff/libtiff.16bitcielab.patch
blob: cecce9cd8402f0ccbf9729e697ff83057464b1fb (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
--- libtiff/tif_getimage.c	2021-03-05 13:01:43.000000000 +0000
+++ libtiff/tif_getimage.c	2022-05-22 14:05:56.320883484 +0100
@@ -194,7 +194,7 @@
                         }
 			break;
 		case PHOTOMETRIC_CIELAB:
-                        if ( td->td_samplesperpixel != 3 || colorchannels != 3 || td->td_bitspersample != 8 ) {
+                        if ( td->td_samplesperpixel != 3 || colorchannels != 3 || (td->td_bitspersample != 8 && td->td_bitspersample != 16) ) {
                                 sprintf(emsg,
                                         "Sorry, can not handle image with %s=%"PRIu16", %s=%d and %s=%"PRIu16,
                                         "Samples/pixel", td->td_samplesperpixel,
@@ -1784,7 +1784,7 @@
 /*
  * 8-bit packed CIE L*a*b 1976 samples => RGB
  */
-DECLAREContigPutFunc(putcontig8bitCIELab)
+DECLAREContigPutFunc(putcontig8bitCIELab8)
 {
 	float X, Y, Z;
 	uint32_t r, g, b;
@@ -1807,6 +1807,32 @@
 }
 
 /*
+ * 16-bit packed CIE L*a*b 1976 samples => RGB
+ */
+DECLAREContigPutFunc(putcontig8bitCIELab16)
+{
+	float X, Y, Z;
+	uint32_t r, g, b;
+        uint16_t *wp = (uint16_t *)pp;
+	(void) y;
+	fromskew = 3;
+	for( ; h > 0; --h) {
+		for (x = w; x > 0; --x) {
+			TIFFCIELabToXYZ(img->cielab,
+					wp[0] / 256,
+					wp[1] / 256,
+					wp[2] / 256,
+					&X, &Y, &Z);
+			TIFFXYZToRGB(img->cielab, X, Y, Z, &r, &g, &b);
+			*cp++ = PACK(r, g, b);
+			wp += 3;
+		}
+		cp += toskew;
+		wp += fromskew;
+	}
+}
+
+/*
  * YCbCr -> RGB conversion and packing routines.
  */
 
@@ -2395,7 +2421,11 @@
 		return NULL;
 	}
 
-	return putcontig8bitCIELab;
+	if (img->bitspersample == 8)
+		return putcontig8bitCIELab8;
+	else if (img->bitspersample == 16)
+		return putcontig8bitCIELab16;
+	return NULL;
 }
 
 /*
@@ -2777,7 +2807,7 @@
 			break;
 		case PHOTOMETRIC_CIELAB:
 			if (img->samplesperpixel == 3 && buildMap(img)) {
-				if (img->bitspersample == 8)
+				if (img->bitspersample == 8 || img->bitspersample == 16)
 					img->put.contig = initCIELabConversion(img);
 				break;
 			}