OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkColorMatrixFilter.h" | 8 #include "SkColorMatrixFilter.h" |
9 | 9 |
10 static SkScalar byte_to_scale(U8CPU byte) { | 10 static SkScalar byte_to_scale(U8CPU byte) { |
11 if (0xFF == byte) { | 11 if (0xFF == byte) { |
12 // want to get this exact | 12 // want to get this exact |
13 return 1; | 13 return 1; |
14 } else { | 14 } else { |
15 return byte * 0.00392156862745f; | 15 return byte * 0.00392156862745f; |
16 } | 16 } |
17 } | 17 } |
18 | 18 |
19 SkColorFilter* SkColorMatrixFilter::CreateLightingFilter(SkColor mul, SkColor ad
d) { | 19 sk_sp<SkColorFilter> SkColorMatrixFilter::MakeLightingFilter(SkColor mul, SkColo
r add) { |
20 SkColorMatrix matrix; | 20 SkColorMatrix matrix; |
21 matrix.setScale(byte_to_scale(SkColorGetR(mul)), | 21 matrix.setScale(byte_to_scale(SkColorGetR(mul)), |
22 byte_to_scale(SkColorGetG(mul)), | 22 byte_to_scale(SkColorGetG(mul)), |
23 byte_to_scale(SkColorGetB(mul)), | 23 byte_to_scale(SkColorGetB(mul)), |
24 1); | 24 1); |
25 matrix.postTranslate(SkIntToScalar(SkColorGetR(add)), | 25 matrix.postTranslate(SkIntToScalar(SkColorGetR(add)), |
26 SkIntToScalar(SkColorGetG(add)), | 26 SkIntToScalar(SkColorGetG(add)), |
27 SkIntToScalar(SkColorGetB(add)), | 27 SkIntToScalar(SkColorGetB(add)), |
28 0); | 28 0); |
29 return SkColorMatrixFilter::Create(matrix); | 29 return SkColorFilter::MakeMatrixFilterRowMajor255(matrix.fMat); |
30 } | 30 } |
OLD | NEW |