Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef SkColorCubeFilter_opts_DEFINED | 5 #ifndef SkColorCubeFilter_opts_DEFINED |
| 6 #define SkColorCubeFilter_opts_DEFINED | 6 #define SkColorCubeFilter_opts_DEFINED |
| 7 | 7 |
| 8 #include "SkColor.h" | 8 #include "SkColor.h" |
| 9 #include "SkPMFloat.h" | 9 #include "SkNx.h" |
| 10 #include "SkUnPreMultiply.h" | 10 #include "SkUnPreMultiply.h" |
| 11 | 11 |
| 12 namespace SK_OPTS_NS { | 12 namespace SK_OPTS_NS { |
| 13 | 13 |
| 14 void color_cube_filter_span(const SkPMColor src[], | 14 void color_cube_filter_span(const SkPMColor src[], |
| 15 int count, | 15 int count, |
| 16 SkPMColor dst[], | 16 SkPMColor dst[], |
| 17 const int* colorToIndex[2], | 17 const int* colorToIndex[2], |
| 18 const SkScalar* colorToFactors[2], | 18 const SkScalar* colorToFactors[2], |
| 19 int dim, | 19 int dim, |
| 20 const SkColor* colorCube) { | 20 const SkColor* colorCube) { |
| 21 uint8_t* ptr_dst = reinterpret_cast<uint8_t*>(dst); | |
| 22 uint8_t r, g, b, a; | 21 uint8_t r, g, b, a; |
| 23 | 22 |
| 24 for (int i = 0; i < count; ++i) { | 23 for (int i = 0; i < count; ++i) { |
| 25 const SkPMColor input = src[i]; | 24 const SkPMColor input = src[i]; |
| 26 a = input >> SK_A32_SHIFT; | 25 a = input >> SK_A32_SHIFT; |
| 27 | 26 |
| 28 if (a != 255) { | 27 if (a != 255) { |
| 29 const SkColor source = SkUnPreMultiply::PMColorToColor(input); | 28 const SkColor source = SkUnPreMultiply::PMColorToColor(input); |
| 30 r = SkColorGetR(source); | 29 r = SkColorGetR(source); |
| 31 g = SkColorGetG(source); | 30 g = SkColorGetG(source); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 44 const Sk4f g0b0(g0*b0), | 43 const Sk4f g0b0(g0*b0), |
| 45 g0b1(g0*b1), | 44 g0b1(g0*b1), |
| 46 g1b0(g1*b0), | 45 g1b0(g1*b0), |
| 47 g1b1(g1*b1); | 46 g1b1(g1*b1); |
| 48 | 47 |
| 49 const int i00 = (colorToIndex[0][g] + colorToIndex[0][b] * dim) * dim; | 48 const int i00 = (colorToIndex[0][g] + colorToIndex[0][b] * dim) * dim; |
| 50 const int i01 = (colorToIndex[0][g] + colorToIndex[1][b] * dim) * dim; | 49 const int i01 = (colorToIndex[0][g] + colorToIndex[1][b] * dim) * dim; |
| 51 const int i10 = (colorToIndex[1][g] + colorToIndex[0][b] * dim) * dim; | 50 const int i10 = (colorToIndex[1][g] + colorToIndex[0][b] * dim) * dim; |
| 52 const int i11 = (colorToIndex[1][g] + colorToIndex[1][b] * dim) * dim; | 51 const int i11 = (colorToIndex[1][g] + colorToIndex[1][b] * dim) * dim; |
| 53 | 52 |
| 54 SkPMFloat color(0,0,0,0); | 53 Sk4f color(0,0,0,0); |
| 55 | |
| 56 for (int x = 0; x < 2; ++x) { | 54 for (int x = 0; x < 2; ++x) { |
| 57 const int ix = colorToIndex[x][r]; | 55 const int ix = colorToIndex[x][r]; |
| 58 | 56 |
| 59 const SkColor lutColor00 = colorCube[ix + i00]; | 57 const SkColor lutColor00 = colorCube[ix + i00]; |
| 60 const SkColor lutColor01 = colorCube[ix + i01]; | 58 const SkColor lutColor01 = colorCube[ix + i01]; |
| 61 const SkColor lutColor10 = colorCube[ix + i10]; | 59 const SkColor lutColor10 = colorCube[ix + i10]; |
| 62 const SkColor lutColor11 = colorCube[ix + i11]; | 60 const SkColor lutColor11 = colorCube[ix + i11]; |
| 63 | 61 |
| 64 Sk4f sum = SkPMFloat::FromOpaqueColor(lutColor00) * g0b0; | 62 Sk4f sum = Sk4f::FromBytes((const uint8_t*)&lutColor00) * g0b0; |
| 65 sum = sum + SkPMFloat::FromOpaqueColor(lutColor01) * g0b1; | 63 sum = sum + Sk4f::FromBytes((const uint8_t*)&lutColor01) * g0b1; |
| 66 sum = sum + SkPMFloat::FromOpaqueColor(lutColor10) * g1b0; | 64 sum = sum + Sk4f::FromBytes((const uint8_t*)&lutColor10) * g1b0; |
| 67 sum = sum + SkPMFloat::FromOpaqueColor(lutColor11) * g1b1; | 65 sum = sum + Sk4f::FromBytes((const uint8_t*)&lutColor11) * g1b1; |
| 68 | |
| 69 color = color + sum * Sk4f((float)colorToFactors[x][r]); | 66 color = color + sum * Sk4f((float)colorToFactors[x][r]); |
| 70 } | 67 } |
| 71 | |
| 72 if (a != 255) { | 68 if (a != 255) { |
| 73 color = color * Sk4f(a * 1.0f/255); | 69 color = color * Sk4f(a * (1.0f/255)); |
| 74 } | 70 } |
| 75 | 71 |
| 76 dst[i] = color.round(); | 72 // color is BGRA (SkColor order), dst is SkPMColor order, so may need to swap R+B. |
| 77 | 73 #if defined(SK_PMCOLOR_IS_RGBA) |
|
Noel Gordon
2015/09/01 04:00:05
round() clamped as well. Dose the new CL clamp?
| |
| 78 ptr_dst[SK_A32_SHIFT / 8] = a; | 74 color = Sk4f(color.kth<2>(), color.kth<1>(), color.kth<0>(), color.kth<3 >()); |
| 79 ptr_dst += 4; | 75 #endif |
| 76 uint8_t* dstBytes = (uint8_t*)(dst+i); | |
| 77 color.toBytes(dstBytes); | |
| 78 dstBytes[SK_A32_SHIFT/8] = a; | |
| 80 } | 79 } |
| 81 } | 80 } |
| 82 | 81 |
| 83 } // namespace SK_OPTS NS | 82 } // namespace SK_OPTS NS |
| 84 | 83 |
| 85 #endif // SkColorCubeFilter_opts_DEFINED | 84 #endif // SkColorCubeFilter_opts_DEFINED |
| OLD | NEW |