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" |
11 #include "SkFloatingPoint.h" | 11 #include "SkFloatingPoint.h" |
12 #include "SkMaskGamma.h" | 12 #include "SkMaskGamma.h" |
13 | 13 |
14 class SkLinearColorSpaceLuminance : public SkColorSpaceLuminance { | 14 class SkLinearColorSpaceLuminance : public SkColorSpaceLuminance { |
15 SkScalar toLuma(SkScalar SkDEBUGCODE(gamma), SkScalar luminance) const SK_OV
ERRIDE { | 15 SkScalar toLuma(SkScalar SkDEBUGCODE(gamma), SkScalar luminance) const overr
ide { |
16 SkASSERT(SK_Scalar1 == gamma); | 16 SkASSERT(SK_Scalar1 == gamma); |
17 return luminance; | 17 return luminance; |
18 } | 18 } |
19 SkScalar fromLuma(SkScalar SkDEBUGCODE(gamma), SkScalar luma) const SK_OVERR
IDE { | 19 SkScalar fromLuma(SkScalar SkDEBUGCODE(gamma), SkScalar luma) const override
{ |
20 SkASSERT(SK_Scalar1 == gamma); | 20 SkASSERT(SK_Scalar1 == gamma); |
21 return luma; | 21 return luma; |
22 } | 22 } |
23 }; | 23 }; |
24 | 24 |
25 class SkGammaColorSpaceLuminance : public SkColorSpaceLuminance { | 25 class SkGammaColorSpaceLuminance : public SkColorSpaceLuminance { |
26 SkScalar toLuma(SkScalar gamma, SkScalar luminance) const SK_OVERRIDE { | 26 SkScalar toLuma(SkScalar gamma, SkScalar luminance) const override { |
27 return SkScalarPow(luminance, gamma); | 27 return SkScalarPow(luminance, gamma); |
28 } | 28 } |
29 SkScalar fromLuma(SkScalar gamma, SkScalar luma) const SK_OVERRIDE { | 29 SkScalar fromLuma(SkScalar gamma, SkScalar luma) const 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 SkScalar toLuma(SkScalar SkDEBUGCODE(gamma), SkScalar luminance) const SK_OV
ERRIDE { | 35 SkScalar toLuma(SkScalar SkDEBUGCODE(gamma), SkScalar luminance) const overr
ide { |
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 <= 0.04045f) { | 39 if (luminance <= 0.04045f) { |
40 return luminance / 12.92f; | 40 return luminance / 12.92f; |
41 } | 41 } |
42 return SkScalarPow((luminance + 0.055f) / 1.055f, | 42 return SkScalarPow((luminance + 0.055f) / 1.055f, |
43 2.4f); | 43 2.4f); |
44 } | 44 } |
45 SkScalar fromLuma(SkScalar SkDEBUGCODE(gamma), SkScalar luma) const SK_OVERR
IDE { | 45 SkScalar fromLuma(SkScalar SkDEBUGCODE(gamma), SkScalar luma) const 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 <= 0.0031308f) { | 49 if (luma <= 0.0031308f) { |
50 return luma * 12.92f; | 50 return luma * 12.92f; |
51 } | 51 } |
52 return 1.055f * SkScalarPow(luma, SkScalarInvert(2.4f)) | 52 return 1.055f * SkScalarPow(luma, SkScalarInvert(2.4f)) |
53 - 0.055f; | 53 - 0.055f; |
54 } | 54 } |
55 }; | 55 }; |
(...skipping 59 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 |