OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkTypes.h" | 8 #include "SkTypes.h" |
9 | 9 |
10 #include "SkColor.h" | 10 #include "SkColor.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 virtual SkScalar fromLuma(SkScalar gamma, SkScalar luma) const SK_OVERRIDE { | 29 virtual SkScalar fromLuma(SkScalar gamma, SkScalar luma) const SK_OVERRIDE { |
30 return SkScalarPow(luma, SkScalarInvert(gamma)); | 30 return SkScalarPow(luma, SkScalarInvert(gamma)); |
31 } | 31 } |
32 }; | 32 }; |
33 | 33 |
34 class SkSRGBColorSpaceLuminance : public SkColorSpaceLuminance { | 34 class SkSRGBColorSpaceLuminance : public SkColorSpaceLuminance { |
35 virtual SkScalar toLuma(SkScalar SkDEBUGCODE(gamma), SkScalar luminance) con
st SK_OVERRIDE { | 35 virtual SkScalar toLuma(SkScalar SkDEBUGCODE(gamma), SkScalar luminance) con
st SK_OVERRIDE { |
36 SkASSERT(0 == gamma); | 36 SkASSERT(0 == gamma); |
37 //The magic numbers are derived from the sRGB specification. | 37 //The magic numbers are derived from the sRGB specification. |
38 //See http://www.color.org/chardata/rgb/srgb.xalter . | 38 //See http://www.color.org/chardata/rgb/srgb.xalter . |
39 if (luminance <= SkFloatToScalar(0.04045f)) { | 39 if (luminance <= 0.04045f) { |
40 return luminance / SkFloatToScalar(12.92f); | 40 return luminance / 12.92f; |
41 } | 41 } |
42 return SkScalarPow((luminance + SkFloatToScalar(0.055f)) / SkFloatToScal
ar(1.055f), | 42 return SkScalarPow((luminance + 0.055f) / 1.055f, |
43 SkFloatToScalar(2.4f)); | 43 2.4f); |
44 } | 44 } |
45 virtual SkScalar fromLuma(SkScalar SkDEBUGCODE(gamma), SkScalar luma) const
SK_OVERRIDE { | 45 virtual SkScalar fromLuma(SkScalar SkDEBUGCODE(gamma), SkScalar luma) const
SK_OVERRIDE { |
46 SkASSERT(0 == gamma); | 46 SkASSERT(0 == gamma); |
47 //The magic numbers are derived from the sRGB specification. | 47 //The magic numbers are derived from the sRGB specification. |
48 //See http://www.color.org/chardata/rgb/srgb.xalter . | 48 //See http://www.color.org/chardata/rgb/srgb.xalter . |
49 if (luma <= SkFloatToScalar(0.0031308f)) { | 49 if (luma <= 0.0031308f) { |
50 return luma * SkFloatToScalar(12.92f); | 50 return luma * 12.92f; |
51 } | 51 } |
52 return SkFloatToScalar(1.055f) * SkScalarPow(luma, SkScalarInvert(SkFloa
tToScalar(2.4f))) | 52 return 1.055f * SkScalarPow(luma, SkScalarInvert(2.4f)) |
53 - SkFloatToScalar(0.055f); | 53 - 0.055f; |
54 } | 54 } |
55 }; | 55 }; |
56 | 56 |
57 /*static*/ const SkColorSpaceLuminance& SkColorSpaceLuminance::Fetch(SkScalar ga
mma) { | 57 /*static*/ const SkColorSpaceLuminance& SkColorSpaceLuminance::Fetch(SkScalar ga
mma) { |
58 static SkLinearColorSpaceLuminance gSkLinearColorSpaceLuminance; | 58 static SkLinearColorSpaceLuminance gSkLinearColorSpaceLuminance; |
59 static SkGammaColorSpaceLuminance gSkGammaColorSpaceLuminance; | 59 static SkGammaColorSpaceLuminance gSkGammaColorSpaceLuminance; |
60 static SkSRGBColorSpaceLuminance gSkSRGBColorSpaceLuminance; | 60 static SkSRGBColorSpaceLuminance gSkSRGBColorSpaceLuminance; |
61 | 61 |
62 if (0 == gamma) { | 62 if (0 == gamma) { |
63 return gSkSRGBColorSpaceLuminance; | 63 return gSkSRGBColorSpaceLuminance; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 float out = dstConvert.fromLuma(dstGamma, linOut); | 115 float out = dstConvert.fromLuma(dstGamma, linOut); |
116 | 116 |
117 //Undo what the blit blend will do. | 117 //Undo what the blit blend will do. |
118 float result = (out - dst) / (src - dst); | 118 float result = (out - dst) / (src - dst); |
119 SkASSERT(sk_float_round2int(255.0f * result) <= 255); | 119 SkASSERT(sk_float_round2int(255.0f * result) <= 255); |
120 | 120 |
121 table[i] = SkToU8(sk_float_round2int(255.0f * result)); | 121 table[i] = SkToU8(sk_float_round2int(255.0f * result)); |
122 } | 122 } |
123 } | 123 } |
124 } | 124 } |
OLD | NEW |