reed@android.com | 152f748 | 2009-08-07 19:14:34 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2009 The Android Open Source Project |
reed@android.com | 152f748 | 2009-08-07 19:14:34 +0000 | [diff] [blame] | 3 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@android.com | 152f748 | 2009-08-07 19:14:34 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 8 | |
Cary Clark | a4083c9 | 2017-09-15 11:59:23 -0400 | [diff] [blame] | 9 | #include "SkColorData.h" |
reed@android.com | 152f748 | 2009-08-07 19:14:34 +0000 | [diff] [blame] | 10 | |
reed@android.com | 879a252 | 2009-10-26 19:15:43 +0000 | [diff] [blame] | 11 | /* |
| 12 | Filter_32_opaque |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 13 | |
reed@android.com | 879a252 | 2009-10-26 19:15:43 +0000 | [diff] [blame] | 14 | There is no hard-n-fast rule that the filtering must produce |
| 15 | exact results for the color components, but if the 4 incoming colors are |
| 16 | all opaque, then the output color must also be opaque. Subsequent parts of |
| 17 | the drawing pipeline may rely on this (e.g. which blitrow proc to use). |
| 18 | */ |
| 19 | |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 20 | static inline void Filter_32_opaque(unsigned x, unsigned y, |
reed@android.com | 152f748 | 2009-08-07 19:14:34 +0000 | [diff] [blame] | 21 | SkPMColor a00, SkPMColor a01, |
| 22 | SkPMColor a10, SkPMColor a11, |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 23 | SkPMColor* dstColor) { |
reed@android.com | 152f748 | 2009-08-07 19:14:34 +0000 | [diff] [blame] | 24 | SkASSERT((unsigned)x <= 0xF); |
| 25 | SkASSERT((unsigned)y <= 0xF); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 26 | |
reed@android.com | 152f748 | 2009-08-07 19:14:34 +0000 | [diff] [blame] | 27 | int xy = x * y; |
commit-bot@chromium.org | f31fa24 | 2014-05-12 15:38:00 +0000 | [diff] [blame] | 28 | const uint32_t mask = 0xFF00FF; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 29 | |
reed@android.com | 152f748 | 2009-08-07 19:14:34 +0000 | [diff] [blame] | 30 | int scale = 256 - 16*y - 16*x + xy; |
| 31 | uint32_t lo = (a00 & mask) * scale; |
| 32 | uint32_t hi = ((a00 >> 8) & mask) * scale; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 33 | |
reed@android.com | 152f748 | 2009-08-07 19:14:34 +0000 | [diff] [blame] | 34 | scale = 16*x - xy; |
| 35 | lo += (a01 & mask) * scale; |
| 36 | hi += ((a01 >> 8) & mask) * scale; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 37 | |
reed@android.com | 152f748 | 2009-08-07 19:14:34 +0000 | [diff] [blame] | 38 | scale = 16*y - xy; |
| 39 | lo += (a10 & mask) * scale; |
| 40 | hi += ((a10 >> 8) & mask) * scale; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 41 | |
reed@android.com | 152f748 | 2009-08-07 19:14:34 +0000 | [diff] [blame] | 42 | lo += (a11 & mask) * xy; |
| 43 | hi += ((a11 >> 8) & mask) * xy; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 44 | |
reed@android.com | 152f748 | 2009-08-07 19:14:34 +0000 | [diff] [blame] | 45 | *dstColor = ((lo >> 8) & mask) | (hi & ~mask); |
| 46 | } |
| 47 | |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 48 | static inline void Filter_32_alpha(unsigned x, unsigned y, |
| 49 | SkPMColor a00, SkPMColor a01, |
| 50 | SkPMColor a10, SkPMColor a11, |
| 51 | SkPMColor* dstColor, |
| 52 | unsigned alphaScale) { |
reed@android.com | 152f748 | 2009-08-07 19:14:34 +0000 | [diff] [blame] | 53 | SkASSERT((unsigned)x <= 0xF); |
| 54 | SkASSERT((unsigned)y <= 0xF); |
| 55 | SkASSERT(alphaScale <= 256); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 56 | |
reed@android.com | 152f748 | 2009-08-07 19:14:34 +0000 | [diff] [blame] | 57 | int xy = x * y; |
commit-bot@chromium.org | f31fa24 | 2014-05-12 15:38:00 +0000 | [diff] [blame] | 58 | const uint32_t mask = 0xFF00FF; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 59 | |
reed@android.com | 152f748 | 2009-08-07 19:14:34 +0000 | [diff] [blame] | 60 | int scale = 256 - 16*y - 16*x + xy; |
| 61 | uint32_t lo = (a00 & mask) * scale; |
| 62 | uint32_t hi = ((a00 >> 8) & mask) * scale; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 63 | |
reed@android.com | 152f748 | 2009-08-07 19:14:34 +0000 | [diff] [blame] | 64 | scale = 16*x - xy; |
| 65 | lo += (a01 & mask) * scale; |
| 66 | hi += ((a01 >> 8) & mask) * scale; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 67 | |
reed@android.com | 152f748 | 2009-08-07 19:14:34 +0000 | [diff] [blame] | 68 | scale = 16*y - xy; |
| 69 | lo += (a10 & mask) * scale; |
| 70 | hi += ((a10 >> 8) & mask) * scale; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 71 | |
reed@android.com | 152f748 | 2009-08-07 19:14:34 +0000 | [diff] [blame] | 72 | lo += (a11 & mask) * xy; |
| 73 | hi += ((a11 >> 8) & mask) * xy; |
| 74 | |
| 75 | lo = ((lo >> 8) & mask) * alphaScale; |
| 76 | hi = ((hi >> 8) & mask) * alphaScale; |
| 77 | |
| 78 | *dstColor = ((lo >> 8) & mask) | (hi & ~mask); |
| 79 | } |
reed@android.com | 152f748 | 2009-08-07 19:14:34 +0000 | [diff] [blame] | 80 | |
robertphillips@google.com | 8b8bf4d | 2013-01-18 16:38:40 +0000 | [diff] [blame] | 81 | // Two color version, where we filter only along 1 axis |
| 82 | static inline void Filter_32_opaque(unsigned t, |
| 83 | SkPMColor color0, |
| 84 | SkPMColor color1, |
| 85 | SkPMColor* dstColor) { |
| 86 | SkASSERT((unsigned)t <= 0xF); |
| 87 | |
commit-bot@chromium.org | f31fa24 | 2014-05-12 15:38:00 +0000 | [diff] [blame] | 88 | const uint32_t mask = 0xFF00FF; |
robertphillips@google.com | 8b8bf4d | 2013-01-18 16:38:40 +0000 | [diff] [blame] | 89 | |
| 90 | int scale = 256 - 16*t; |
| 91 | uint32_t lo = (color0 & mask) * scale; |
| 92 | uint32_t hi = ((color0 >> 8) & mask) * scale; |
| 93 | |
| 94 | scale = 16*t; |
| 95 | lo += (color1 & mask) * scale; |
| 96 | hi += ((color1 >> 8) & mask) * scale; |
| 97 | |
| 98 | *dstColor = ((lo >> 8) & mask) | (hi & ~mask); |
| 99 | } |
| 100 | |
| 101 | // Two color version, where we filter only along 1 axis |
| 102 | static inline void Filter_32_alpha(unsigned t, |
| 103 | SkPMColor color0, |
| 104 | SkPMColor color1, |
| 105 | SkPMColor* dstColor, |
| 106 | unsigned alphaScale) { |
| 107 | SkASSERT((unsigned)t <= 0xF); |
| 108 | SkASSERT(alphaScale <= 256); |
| 109 | |
commit-bot@chromium.org | f31fa24 | 2014-05-12 15:38:00 +0000 | [diff] [blame] | 110 | const uint32_t mask = 0xFF00FF; |
robertphillips@google.com | 8b8bf4d | 2013-01-18 16:38:40 +0000 | [diff] [blame] | 111 | |
| 112 | int scale = 256 - 16*t; |
| 113 | uint32_t lo = (color0 & mask) * scale; |
| 114 | uint32_t hi = ((color0 >> 8) & mask) * scale; |
| 115 | |
| 116 | scale = 16*t; |
| 117 | lo += (color1 & mask) * scale; |
| 118 | hi += ((color1 >> 8) & mask) * scale; |
| 119 | |
| 120 | lo = ((lo >> 8) & mask) * alphaScale; |
| 121 | hi = ((hi >> 8) & mask) * alphaScale; |
| 122 | |
| 123 | *dstColor = ((lo >> 8) & mask) | (hi & ~mask); |
| 124 | } |