Nicolas Pena | f752039 | 2017-08-10 16:36:56 -0400 | [diff] [blame] | 1 | diff --git a/third_party/lcms/src/cmsopt.c b/third_party/lcms/src/cmsopt.c |
Nicolas Pena | 0bd8472 | 2017-08-14 10:36:01 -0400 | [diff] [blame] | 2 | index e4a7e4521..23aa54402 100644 |
Nicolas Pena | f752039 | 2017-08-10 16:36:56 -0400 | [diff] [blame] | 3 | --- a/third_party/lcms/src/cmsopt.c |
| 4 | +++ b/third_party/lcms/src/cmsopt.c |
Nicolas Pena | 0bd8472 | 2017-08-14 10:36:01 -0400 | [diff] [blame] | 5 | @@ -1546,7 +1546,7 @@ void MatShaperEval16(register const cmsUInt16Number In[], |
kcwu | 31559c9 | 2016-12-07 17:34:58 -0800 | [diff] [blame] | 6 | |
| 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 Pena | 0bd8472 | 2017-08-14 10:36:01 -0400 | [diff] [blame] | 14 | @@ -1555,14 +1555,17 @@ void FillFirstShaper(cmsS1Fixed14Number* Table, cmsToneCurve* Curve) |
kcwu | 31559c9 | 2016-12-07 17:34:58 -0800 | [diff] [blame] | 15 | |
| 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 Pena | 0bd8472 | 2017-08-14 10:36:01 -0400 | [diff] [blame] | 33 | @@ -1571,6 +1574,8 @@ void FillSecondShaper(cmsUInt16Number* Table, cmsToneCurve* Curve, cmsBool Is8Bi |
kcwu | 31559c9 | 2016-12-07 17:34:58 -0800 | [diff] [blame] | 34 | |
| 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 Pena | 0bd8472 | 2017-08-14 10:36:01 -0400 | [diff] [blame] | 42 | @@ -1585,6 +1590,7 @@ void FillSecondShaper(cmsUInt16Number* Table, cmsToneCurve* Curve, cmsBool Is8Bi |
kcwu | 31559c9 | 2016-12-07 17:34:58 -0800 | [diff] [blame] | 43 | } |
| 44 | else Table[i] = _cmsQuickSaturateWord(Val * 65535.0); |
| 45 | } |
| 46 | + return TRUE; |
| 47 | } |
| 48 | |
| 49 | // Compute the matrix-shaper structure |
Nicolas Pena | 0bd8472 | 2017-08-14 10:36:01 -0400 | [diff] [blame] | 50 | @@ -1602,13 +1608,19 @@ cmsBool SetMatShaper(cmsPipeline* Dest, cmsToneCurve* Curve1[3], cmsMAT3* Mat, c |
kcwu | 31559c9 | 2016-12-07 17:34:58 -0800 | [diff] [blame] | 51 | 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 Pena | 0bd8472 | 2017-08-14 10:36:01 -0400 | [diff] [blame] | 76 | @@ -1634,6 +1646,9 @@ cmsBool SetMatShaper(cmsPipeline* Dest, cmsToneCurve* Curve1[3], cmsMAT3* Mat, c |
kcwu | 31559c9 | 2016-12-07 17:34:58 -0800 | [diff] [blame] | 77 | // Fill function pointers |
| 78 | _cmsPipelineSetOptimizationParameters(Dest, MatShaperEval16, (void*) p, FreeMatShaper, DupMatShaper); |
| 79 | return TRUE; |
Nicolas Pena | 0bd8472 | 2017-08-14 10:36:01 -0400 | [diff] [blame] | 80 | + Error: |
| 81 | + _cmsFree(Dest->ContextID, p); |
| 82 | + return FALSE; |
kcwu | 31559c9 | 2016-12-07 17:34:58 -0800 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | // 8 bits on input allows matrix-shaper boot up to 25 Mpixels per second on RGB. That's fast! |
Nicolas Pena | 0bd8472 | 2017-08-14 10:36:01 -0400 | [diff] [blame] | 86 | @@ -1746,7 +1761,8 @@ cmsBool OptimizeMatrixShaper(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt3 |
kcwu | 31559c9 | 2016-12-07 17:34:58 -0800 | [diff] [blame] | 87 | *dwFlags |= cmsFLAGS_NOCACHE; |
| 88 | |
| 89 | // Setup the optimizarion routines |
Nicolas Pena | 0bd8472 | 2017-08-14 10:36:01 -0400 | [diff] [blame] | 90 | - SetMatShaper(Dest, mpeC1 ->TheCurves, &res, (cmsVEC3*) Offset, mpeC2->TheCurves, OutputFormat); |
| 91 | + if (!SetMatShaper(Dest, mpeC1 ->TheCurves, &res, (cmsVEC3*) Offset, mpeC2->TheCurves, OutputFormat)) |
kcwu | 31559c9 | 2016-12-07 17:34:58 -0800 | [diff] [blame] | 92 | + goto Error; |
| 93 | } |
| 94 | |
| 95 | cmsPipelineFree(Src); |