Chromium Code Reviews| Index: src/core/SkColorSpace.cpp |
| diff --git a/src/core/SkColorSpace.cpp b/src/core/SkColorSpace.cpp |
| index bf99b474a21f4c5e9da72056f07413f48bcfe26f..71c9f6d854fb523b35587d743032661f31006334 100644 |
| --- a/src/core/SkColorSpace.cpp |
| +++ b/src/core/SkColorSpace.cpp |
| @@ -427,6 +427,10 @@ bool load_gammas(SkGammaCurve* gammas, uint32_t numGammas, const uint8_t* src, s |
| // The table entry is the gamma (with a bias of 256). |
| uint16_t value = read_big_endian_short((const uint8_t*) table); |
| gammas[i].fValue = value / 256.0f; |
| + if (0.0f == gammas[i].fValue) { |
| + SkColorSpacePrintf("Cannot have zero gamma value"); |
| + return false; |
| + } |
| SkColorSpacePrintf("gamma %d %g\n", value, gammas[i].fValue); |
| break; |
| } |
| @@ -517,6 +521,10 @@ bool load_gammas(SkGammaCurve* gammas, uint32_t numGammas, const uint8_t* src, s |
| // Y = 0 otherwise |
| g = SkFixedToFloat(read_big_endian_int(src + 12)); |
| a = SkFixedToFloat(read_big_endian_int(src + 16)); |
| + if (0.0f == a) { |
| + return false; |
| + } |
| + |
| b = SkFixedToFloat(read_big_endian_int(src + 20)); |
| d = -b / a; |
| break; |
| @@ -532,6 +540,10 @@ bool load_gammas(SkGammaCurve* gammas, uint32_t numGammas, const uint8_t* src, s |
| // Y = c otherwise |
| g = SkFixedToFloat(read_big_endian_int(src + 12)); |
| a = SkFixedToFloat(read_big_endian_int(src + 16)); |
| + if (0.0f == a) { |
| + return false; |
| + } |
| + |
| b = SkFixedToFloat(read_big_endian_int(src + 20)); |
| c = SkFixedToFloat(read_big_endian_int(src + 24)); |
| d = -b / a; |
| @@ -586,6 +598,24 @@ bool load_gammas(SkGammaCurve* gammas, uint32_t numGammas, const uint8_t* src, s |
| color_space_almost_equal(2.4000f, g)) { |
| gammas[i].fValue = 2.2f; |
| } else { |
| + // Fail on invalid gammas. |
| + if (d <= 0.0f) { |
| + // Y = (aX + b)^g + c for always |
| + if (0.0f == a || 0.0f == g) { |
| + SkColorSpacePrintf("Constant gamma function is nonsense"); |
| + return false; |
| + } |
| + } else if (d >= 1.0f) { |
| + // Y = eX + f for always |
| + if (0.0f == e) { |
| + SkColorSpacePrintf("Constant gamma function is nonsense"); |
|
scroggo
2016/06/06 17:13:54
It might help to differentiate these print stateme
msarett
2016/06/06 17:25:05
Done.
|
| + return false; |
| + } |
| + } else if ((0.0f == a || 0.0f == g) && 0.0f == e) { |
| + SkColorSpacePrintf("Constant gamma function is nonsense"); |
| + return false; |
| + } |
| + |
| gammas[i].fG = g; |
| gammas[i].fA = a; |
| gammas[i].fB = b; |
| @@ -603,6 +633,9 @@ bool load_gammas(SkGammaCurve* gammas, uint32_t numGammas, const uint8_t* src, s |
| return false; |
| } |
| + // Ensure that we have successfully read a gamma representation. |
| + SkASSERT(gammas[i].isValue() || gammas[i].isTable() || gammas[i].isParametric()); |
| + |
| // Adjust src and len if there is another gamma curve to load. |
| if (i != numGammas - 1) { |
| // Each curve is padded to 4-byte alignment. |