| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2009 The Android Open Source Project | 3 * Copyright 2009 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 "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| 11 | 11 |
| 12 /* | 12 /* |
| 13 Filter_32_opaque | 13 Filter_32_opaque |
| 14 | 14 |
| 15 There is no hard-n-fast rule that the filtering must produce | 15 There is no hard-n-fast rule that the filtering must produce |
| 16 exact results for the color components, but if the 4 incoming colors are | 16 exact results for the color components, but if the 4 incoming colors are |
| 17 all opaque, then the output color must also be opaque. Subsequent parts of | 17 all opaque, then the output color must also be opaque. Subsequent parts of |
| 18 the drawing pipeline may rely on this (e.g. which blitrow proc to use). | 18 the drawing pipeline may rely on this (e.g. which blitrow proc to use). |
| 19 */ | 19 */ |
| 20 | 20 |
| 21 static inline void Filter_32_opaque(unsigned x, unsigned y, | 21 static inline void Filter_32_opaque(unsigned x, unsigned y, |
| 22 SkPMColor a00, SkPMColor a01, | 22 SkPMColor a00, SkPMColor a01, |
| 23 SkPMColor a10, SkPMColor a11, | 23 SkPMColor a10, SkPMColor a11, |
| 24 SkPMColor* dstColor) { | 24 SkPMColor* dstColor) { |
| 25 SkASSERT((unsigned)x <= 0xF); | 25 SkASSERT((unsigned)x <= 0xF); |
| 26 SkASSERT((unsigned)y <= 0xF); | 26 SkASSERT((unsigned)y <= 0xF); |
| 27 | 27 |
| 28 int xy = x * y; | 28 int xy = x * y; |
| 29 static const uint32_t mask = gMask_00FF00FF; //0xFF00FF; | 29 const uint32_t mask = 0xFF00FF; |
| 30 | 30 |
| 31 int scale = 256 - 16*y - 16*x + xy; | 31 int scale = 256 - 16*y - 16*x + xy; |
| 32 uint32_t lo = (a00 & mask) * scale; | 32 uint32_t lo = (a00 & mask) * scale; |
| 33 uint32_t hi = ((a00 >> 8) & mask) * scale; | 33 uint32_t hi = ((a00 >> 8) & mask) * scale; |
| 34 | 34 |
| 35 scale = 16*x - xy; | 35 scale = 16*x - xy; |
| 36 lo += (a01 & mask) * scale; | 36 lo += (a01 & mask) * scale; |
| 37 hi += ((a01 >> 8) & mask) * scale; | 37 hi += ((a01 >> 8) & mask) * scale; |
| 38 | 38 |
| 39 scale = 16*y - xy; | 39 scale = 16*y - xy; |
| 40 lo += (a10 & mask) * scale; | 40 lo += (a10 & mask) * scale; |
| 41 hi += ((a10 >> 8) & mask) * scale; | 41 hi += ((a10 >> 8) & mask) * scale; |
| 42 | 42 |
| 43 lo += (a11 & mask) * xy; | 43 lo += (a11 & mask) * xy; |
| 44 hi += ((a11 >> 8) & mask) * xy; | 44 hi += ((a11 >> 8) & mask) * xy; |
| 45 | 45 |
| 46 *dstColor = ((lo >> 8) & mask) | (hi & ~mask); | 46 *dstColor = ((lo >> 8) & mask) | (hi & ~mask); |
| 47 } | 47 } |
| 48 | 48 |
| 49 static inline void Filter_32_alpha(unsigned x, unsigned y, | 49 static inline void Filter_32_alpha(unsigned x, unsigned y, |
| 50 SkPMColor a00, SkPMColor a01, | 50 SkPMColor a00, SkPMColor a01, |
| 51 SkPMColor a10, SkPMColor a11, | 51 SkPMColor a10, SkPMColor a11, |
| 52 SkPMColor* dstColor, | 52 SkPMColor* dstColor, |
| 53 unsigned alphaScale) { | 53 unsigned alphaScale) { |
| 54 SkASSERT((unsigned)x <= 0xF); | 54 SkASSERT((unsigned)x <= 0xF); |
| 55 SkASSERT((unsigned)y <= 0xF); | 55 SkASSERT((unsigned)y <= 0xF); |
| 56 SkASSERT(alphaScale <= 256); | 56 SkASSERT(alphaScale <= 256); |
| 57 | 57 |
| 58 int xy = x * y; | 58 int xy = x * y; |
| 59 static const uint32_t mask = gMask_00FF00FF; //0xFF00FF; | 59 const uint32_t mask = 0xFF00FF; |
| 60 | 60 |
| 61 int scale = 256 - 16*y - 16*x + xy; | 61 int scale = 256 - 16*y - 16*x + xy; |
| 62 uint32_t lo = (a00 & mask) * scale; | 62 uint32_t lo = (a00 & mask) * scale; |
| 63 uint32_t hi = ((a00 >> 8) & mask) * scale; | 63 uint32_t hi = ((a00 >> 8) & mask) * scale; |
| 64 | 64 |
| 65 scale = 16*x - xy; | 65 scale = 16*x - xy; |
| 66 lo += (a01 & mask) * scale; | 66 lo += (a01 & mask) * scale; |
| 67 hi += ((a01 >> 8) & mask) * scale; | 67 hi += ((a01 >> 8) & mask) * scale; |
| 68 | 68 |
| 69 scale = 16*y - xy; | 69 scale = 16*y - xy; |
| 70 lo += (a10 & mask) * scale; | 70 lo += (a10 & mask) * scale; |
| 71 hi += ((a10 >> 8) & mask) * scale; | 71 hi += ((a10 >> 8) & mask) * scale; |
| 72 | 72 |
| 73 lo += (a11 & mask) * xy; | 73 lo += (a11 & mask) * xy; |
| 74 hi += ((a11 >> 8) & mask) * xy; | 74 hi += ((a11 >> 8) & mask) * xy; |
| 75 | 75 |
| 76 lo = ((lo >> 8) & mask) * alphaScale; | 76 lo = ((lo >> 8) & mask) * alphaScale; |
| 77 hi = ((hi >> 8) & mask) * alphaScale; | 77 hi = ((hi >> 8) & mask) * alphaScale; |
| 78 | 78 |
| 79 *dstColor = ((lo >> 8) & mask) | (hi & ~mask); | 79 *dstColor = ((lo >> 8) & mask) | (hi & ~mask); |
| 80 } | 80 } |
| 81 | 81 |
| 82 // Two color version, where we filter only along 1 axis | 82 // Two color version, where we filter only along 1 axis |
| 83 static inline void Filter_32_opaque(unsigned t, | 83 static inline void Filter_32_opaque(unsigned t, |
| 84 SkPMColor color0, | 84 SkPMColor color0, |
| 85 SkPMColor color1, | 85 SkPMColor color1, |
| 86 SkPMColor* dstColor) { | 86 SkPMColor* dstColor) { |
| 87 SkASSERT((unsigned)t <= 0xF); | 87 SkASSERT((unsigned)t <= 0xF); |
| 88 | 88 |
| 89 static const uint32_t mask = gMask_00FF00FF; //0x00FF00FF; | 89 const uint32_t mask = 0xFF00FF; |
| 90 | 90 |
| 91 int scale = 256 - 16*t; | 91 int scale = 256 - 16*t; |
| 92 uint32_t lo = (color0 & mask) * scale; | 92 uint32_t lo = (color0 & mask) * scale; |
| 93 uint32_t hi = ((color0 >> 8) & mask) * scale; | 93 uint32_t hi = ((color0 >> 8) & mask) * scale; |
| 94 | 94 |
| 95 scale = 16*t; | 95 scale = 16*t; |
| 96 lo += (color1 & mask) * scale; | 96 lo += (color1 & mask) * scale; |
| 97 hi += ((color1 >> 8) & mask) * scale; | 97 hi += ((color1 >> 8) & mask) * scale; |
| 98 | 98 |
| 99 *dstColor = ((lo >> 8) & mask) | (hi & ~mask); | 99 *dstColor = ((lo >> 8) & mask) | (hi & ~mask); |
| 100 } | 100 } |
| 101 | 101 |
| 102 // Two color version, where we filter only along 1 axis | 102 // Two color version, where we filter only along 1 axis |
| 103 static inline void Filter_32_alpha(unsigned t, | 103 static inline void Filter_32_alpha(unsigned t, |
| 104 SkPMColor color0, | 104 SkPMColor color0, |
| 105 SkPMColor color1, | 105 SkPMColor color1, |
| 106 SkPMColor* dstColor, | 106 SkPMColor* dstColor, |
| 107 unsigned alphaScale) { | 107 unsigned alphaScale) { |
| 108 SkASSERT((unsigned)t <= 0xF); | 108 SkASSERT((unsigned)t <= 0xF); |
| 109 SkASSERT(alphaScale <= 256); | 109 SkASSERT(alphaScale <= 256); |
| 110 | 110 |
| 111 static const uint32_t mask = gMask_00FF00FF; //0x00FF00FF; | 111 const uint32_t mask = 0xFF00FF; |
| 112 | 112 |
| 113 int scale = 256 - 16*t; | 113 int scale = 256 - 16*t; |
| 114 uint32_t lo = (color0 & mask) * scale; | 114 uint32_t lo = (color0 & mask) * scale; |
| 115 uint32_t hi = ((color0 >> 8) & mask) * scale; | 115 uint32_t hi = ((color0 >> 8) & mask) * scale; |
| 116 | 116 |
| 117 scale = 16*t; | 117 scale = 16*t; |
| 118 lo += (color1 & mask) * scale; | 118 lo += (color1 & mask) * scale; |
| 119 hi += ((color1 >> 8) & mask) * scale; | 119 hi += ((color1 >> 8) & mask) * scale; |
| 120 | 120 |
| 121 lo = ((lo >> 8) & mask) * alphaScale; | 121 lo = ((lo >> 8) & mask) * alphaScale; |
| 122 hi = ((hi >> 8) & mask) * alphaScale; | 122 hi = ((hi >> 8) & mask) * alphaScale; |
| 123 | 123 |
| 124 *dstColor = ((lo >> 8) & mask) | (hi & ~mask); | 124 *dstColor = ((lo >> 8) & mask) | (hi & ~mask); |
| 125 } | 125 } |
| OLD | NEW |