blob: b2397d73f9c8fbd82c839fcc17e5b401592fd951 [file] [log] [blame]
Nicolas Penaf7520392017-08-10 16:36:56 -04001diff --git a/third_party/lcms/src/cmsopt.c b/third_party/lcms/src/cmsopt.c
Nicolas Pena0bd84722017-08-14 10:36:01 -04002index e4a7e4521..23aa54402 100644
Nicolas Penaf7520392017-08-10 16:36:56 -04003--- a/third_party/lcms/src/cmsopt.c
4+++ b/third_party/lcms/src/cmsopt.c
Nicolas Pena0bd84722017-08-14 10:36:01 -04005@@ -1546,7 +1546,7 @@ void MatShaperEval16(register const cmsUInt16Number In[],
kcwu31559c92016-12-07 17:34:58 -08006
7 // This table converts from 8 bits to 1.14 after applying the curve
8 static
9-void FillFirstShaper(cmsS1Fixed14Number* Table, cmsToneCurve* Curve)
10+cmsBool FillFirstShaper(cmsS1Fixed14Number* Table, cmsToneCurve* Curve)
11 {
12 int i;
13 cmsFloat32Number R, y;
Nicolas Pena0bd84722017-08-14 10:36:01 -040014@@ -1555,14 +1555,17 @@ void FillFirstShaper(cmsS1Fixed14Number* Table, cmsToneCurve* Curve)
kcwu31559c92016-12-07 17:34:58 -080015
16 R = (cmsFloat32Number) (i / 255.0);
17 y = cmsEvalToneCurveFloat(Curve, R);
18+ if (isinf(y))
19+ return FALSE;
20
21 Table[i] = DOUBLE_TO_1FIXED14(y);
22 }
23+ return TRUE;
24 }
25
26 // This table converts form 1.14 (being 0x4000 the last entry) to 8 bits after applying the curve
27 static
28-void FillSecondShaper(cmsUInt16Number* Table, cmsToneCurve* Curve, cmsBool Is8BitsOutput)
29+cmsBool FillSecondShaper(cmsUInt16Number* Table, cmsToneCurve* Curve, cmsBool Is8BitsOutput)
30 {
31 int i;
32 cmsFloat32Number R, Val;
Nicolas Pena0bd84722017-08-14 10:36:01 -040033@@ -1571,6 +1574,8 @@ void FillSecondShaper(cmsUInt16Number* Table, cmsToneCurve* Curve, cmsBool Is8Bi
kcwu31559c92016-12-07 17:34:58 -080034
35 R = (cmsFloat32Number) (i / 16384.0);
36 Val = cmsEvalToneCurveFloat(Curve, R); // Val comes 0..1.0
37+ if (isinf(Val))
38+ return FALSE;
39
40 if (Is8BitsOutput) {
41
Nicolas Pena0bd84722017-08-14 10:36:01 -040042@@ -1585,6 +1590,7 @@ void FillSecondShaper(cmsUInt16Number* Table, cmsToneCurve* Curve, cmsBool Is8Bi
kcwu31559c92016-12-07 17:34:58 -080043 }
44 else Table[i] = _cmsQuickSaturateWord(Val * 65535.0);
45 }
46+ return TRUE;
47 }
48
49 // Compute the matrix-shaper structure
Nicolas Pena0bd84722017-08-14 10:36:01 -040050@@ -1602,13 +1608,19 @@ cmsBool SetMatShaper(cmsPipeline* Dest, cmsToneCurve* Curve1[3], cmsMAT3* Mat, c
kcwu31559c92016-12-07 17:34:58 -080051 p -> ContextID = Dest -> ContextID;
52
53 // Precompute tables
54- FillFirstShaper(p ->Shaper1R, Curve1[0]);
55- FillFirstShaper(p ->Shaper1G, Curve1[1]);
56- FillFirstShaper(p ->Shaper1B, Curve1[2]);
57+ if (!FillFirstShaper(p ->Shaper1R, Curve1[0]))
58+ goto Error;
59+ if (!FillFirstShaper(p ->Shaper1G, Curve1[1]))
60+ goto Error;
61+ if (!FillFirstShaper(p ->Shaper1B, Curve1[2]))
62+ goto Error;
63
64- FillSecondShaper(p ->Shaper2R, Curve2[0], Is8Bits);
65- FillSecondShaper(p ->Shaper2G, Curve2[1], Is8Bits);
66- FillSecondShaper(p ->Shaper2B, Curve2[2], Is8Bits);
67+ if (!FillSecondShaper(p ->Shaper2R, Curve2[0], Is8Bits))
68+ goto Error;
69+ if (!FillSecondShaper(p ->Shaper2G, Curve2[1], Is8Bits))
70+ goto Error;
71+ if (!FillSecondShaper(p ->Shaper2B, Curve2[2], Is8Bits))
72+ goto Error;
73
74 // Convert matrix to nFixed14. Note that those values may take more than 16 bits as
75 for (i=0; i < 3; i++) {
Nicolas Pena0bd84722017-08-14 10:36:01 -040076@@ -1634,6 +1646,9 @@ cmsBool SetMatShaper(cmsPipeline* Dest, cmsToneCurve* Curve1[3], cmsMAT3* Mat, c
kcwu31559c92016-12-07 17:34:58 -080077 // Fill function pointers
78 _cmsPipelineSetOptimizationParameters(Dest, MatShaperEval16, (void*) p, FreeMatShaper, DupMatShaper);
79 return TRUE;
Nicolas Pena0bd84722017-08-14 10:36:01 -040080+ Error:
81+ _cmsFree(Dest->ContextID, p);
82+ return FALSE;
kcwu31559c92016-12-07 17:34:58 -080083 }
84
85 // 8 bits on input allows matrix-shaper boot up to 25 Mpixels per second on RGB. That's fast!
Nicolas Pena0bd84722017-08-14 10:36:01 -040086@@ -1746,7 +1761,8 @@ cmsBool OptimizeMatrixShaper(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt3
kcwu31559c92016-12-07 17:34:58 -080087 *dwFlags |= cmsFLAGS_NOCACHE;
88
89 // Setup the optimizarion routines
Nicolas Pena0bd84722017-08-14 10:36:01 -040090- SetMatShaper(Dest, mpeC1 ->TheCurves, &res, (cmsVEC3*) Offset, mpeC2->TheCurves, OutputFormat);
91+ if (!SetMatShaper(Dest, mpeC1 ->TheCurves, &res, (cmsVEC3*) Offset, mpeC2->TheCurves, OutputFormat))
kcwu31559c92016-12-07 17:34:58 -080092+ goto Error;
93 }
94
95 cmsPipelineFree(Src);