Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkSRGB.h" | 8 #include "SkSRGB.h" |
| 9 #include "SkTypes.h" | 9 #include "SkTypes.h" |
| 10 #include "Test.h" | 10 #include "Test.h" |
| 11 #include <math.h> | 11 #include <math.h> |
| 12 | 12 |
| 13 static uint8_t linear_to_srgb(float l) { | 13 static uint8_t linear_to_srgb(float l) { |
| 14 // Round float to int, truncate that to uint8_t. | 14 return (uint8_t)sk_linear_to_srgb(Sk4f{l})[0]; |
| 15 return (uint8_t)Sk4f_round( sk_linear_to_srgb(Sk4f{l}) )[0]; | |
| 16 } | 15 } |
| 17 | 16 |
| 18 DEF_TEST(sk_linear_to_srgb, r) { | 17 DEF_TEST(sk_linear_to_srgb, r) { |
| 19 // Should map 0 -> 0 and 1 -> 1. | 18 // All bytes should round trip. |
| 20 REPORTER_ASSERT(r, 0 == linear_to_srgb(0.0f)); | 19 for (int i = 0; i < 256; i++) { |
| 21 REPORTER_ASSERT(r, 255 == linear_to_srgb(1.0f)); | 20 int actual = linear_to_srgb(sk_linear_from_srgb[i]); |
| 21 if (i != actual) { | |
| 22 ERRORF(r, "%d -> %d\n", i, actual); | |
| 23 } | |
| 24 } | |
| 22 | 25 |
| 23 // Should be monotonic between 0 and 1. | 26 // Should be (mostly) monotonic between 0 and 1. |
| 24 // We don't bother checking denorm values. | |
| 25 int tolerated_regressions = 0; | 27 int tolerated_regressions = 0; |
| 26 #if defined(SK_ARM_HAS_NEON) | 28 #if defined(SK_ARM_HAS_NEON) |
| 27 // Values around 0.166016 are usually 72 but drop briefly (41 floats) down t o 71. | 29 // TODO: still needed? more needed? |
|
msarett
2016/07/20 18:43:11
Update this comment.
| |
| 28 tolerated_regressions = 1; | 30 tolerated_regressions = 1; |
| 29 #endif | 31 #endif |
| 32 | |
| 30 uint8_t prev = 0; | 33 uint8_t prev = 0; |
| 31 for (float f = FLT_MIN; f <= 1.0f; ) { | 34 for (float f = FLT_MIN; f <= 1.0f; ) { // We don't bother checking denorm v alues. |
|
msarett
2016/07/20 18:43:11
Why not? Should we?
| |
| 32 uint8_t srgb = linear_to_srgb(f); | 35 uint8_t srgb = linear_to_srgb(f); |
| 33 | 36 |
| 34 REPORTER_ASSERT(r, srgb >= prev || tolerated_regressions > 0); | 37 REPORTER_ASSERT(r, srgb >= prev || tolerated_regressions > 0); |
| 35 if (srgb < prev) { tolerated_regressions--; } | 38 if (srgb < prev) { tolerated_regressions--; } |
| 36 prev = srgb; | 39 prev = srgb; |
| 37 | 40 |
| 38 union { float flt; uint32_t bits; } pun = { f }; | 41 union { float flt; uint32_t bits; } pun = { f }; |
| 39 pun.bits++; | 42 pun.bits++; |
| 40 f = pun.flt; | 43 f = pun.flt; |
| 41 } | 44 } |
| 42 } | 45 } |
| OLD | NEW |