OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkDrawColor.h" | 10 #include "SkDrawColor.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 static SkScalar RGB_to_HSV(SkColor color, HSV_Choice choice) { | 24 static SkScalar RGB_to_HSV(SkColor color, HSV_Choice choice) { |
25 SkScalar red = SkIntToScalar(SkColorGetR(color)); | 25 SkScalar red = SkIntToScalar(SkColorGetR(color)); |
26 SkScalar green = SkIntToScalar(SkColorGetG(color)); | 26 SkScalar green = SkIntToScalar(SkColorGetG(color)); |
27 SkScalar blue = SkIntToScalar(SkColorGetB(color)); | 27 SkScalar blue = SkIntToScalar(SkColorGetB(color)); |
28 SkScalar min = SkMinScalar(SkMinScalar(red, green), blue); | 28 SkScalar min = SkMinScalar(SkMinScalar(red, green), blue); |
29 SkScalar value = SkMaxScalar(SkMaxScalar(red, green), blue); | 29 SkScalar value = SkMaxScalar(SkMaxScalar(red, green), blue); |
30 if (choice == kGetValue) | 30 if (choice == kGetValue) |
31 return value/255; | 31 return value/255; |
32 SkScalar delta = value - min; | 32 SkScalar delta = value - min; |
33 SkScalar saturation = value == 0 ? 0 : delta / value; | 33 SkScalar saturation = value == 0 ? 0 : SkScalarDiv(delta, value); |
34 if (choice == kGetSaturation) | 34 if (choice == kGetSaturation) |
35 return saturation; | 35 return saturation; |
36 SkScalar hue; | 36 SkScalar hue; |
37 if (saturation == 0) | 37 if (saturation == 0) |
38 hue = 0; | 38 hue = 0; |
39 else { | 39 else { |
40 SkScalar part60 = 60 / delta; | 40 SkScalar part60 = SkScalarDiv(60 * SK_Scalar1, delta); |
41 if (red == value) { | 41 if (red == value) { |
42 hue = SkScalarMul(green - blue, part60); | 42 hue = SkScalarMul(green - blue, part60); |
43 if (hue < 0) | 43 if (hue < 0) |
44 hue += 360 * SK_Scalar1; | 44 hue += 360 * SK_Scalar1; |
45 } | 45 } |
46 else if (green == value) | 46 else if (green == value) |
47 hue = 120 * SK_Scalar1 + SkScalarMul(blue - red, part60); | 47 hue = 120 * SK_Scalar1 + SkScalarMul(blue - red, part60); |
48 else // blue == value | 48 else // blue == value |
49 hue = 240 * SK_Scalar1 + SkScalarMul(red - green, part60); | 49 hue = 240 * SK_Scalar1 + SkScalarMul(red - green, part60); |
50 } | 50 } |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 case SK_PROPERTY(value): | 256 case SK_PROPERTY(value): |
257 fValue = scalar;//RGB_to_HSV(color, kGetValue); | 257 fValue = scalar;//RGB_to_HSV(color, kGetValue); |
258 fDirty = true; | 258 fDirty = true; |
259 break; | 259 break; |
260 default: | 260 default: |
261 SkASSERT(0); | 261 SkASSERT(0); |
262 return false; | 262 return false; |
263 } | 263 } |
264 return true; | 264 return true; |
265 } | 265 } |
OLD | NEW |