Leon Scroggins III | 1252ec4 | 2017-01-11 12:59:43 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "tests/Test.h" |
Leon Scroggins III | 1252ec4 | 2017-01-11 12:59:43 -0500 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkColor.h" |
Leon Scroggins III | 1252ec4 | 2017-01-11 12:59:43 -0500 | [diff] [blame] | 11 | |
| 12 | DEF_TEST(ColorToHSVRoundTrip, reporter) { |
| 13 | SkScalar hsv[3]; |
| 14 | for (U8CPU r = 0; r <= 255; r++) { |
| 15 | for (U8CPU g = 0; g <= 255; g++) { |
| 16 | for (U8CPU b = 0; b <= 255; b++) { |
Cary Clark | 6cdb7d3 | 2018-04-24 14:47:16 -0400 | [diff] [blame] | 17 | SkColor color = SkColorSetRGB(r, g, b); |
Leon Scroggins III | 1252ec4 | 2017-01-11 12:59:43 -0500 | [diff] [blame] | 18 | SkColorToHSV(color, hsv); |
| 19 | SkColor result = SkHSVToColor(0xFF, hsv); |
| 20 | if (result != color) { |
| 21 | ERRORF(reporter, "HSV roundtrip mismatch!\n" |
| 22 | "\toriginal: %X\n" |
| 23 | "\tHSV: %f, %f, %f\n" |
| 24 | "\tresult: %X\n", |
| 25 | color, hsv[0], hsv[1], hsv[2], result); |
| 26 | } |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | } |