digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | // Define NAME_WRAP(x) before including this header to perform name-wrapping |
| 9 | // E.g. for ARM NEON, defined it as 'x ## _neon' to ensure all important |
| 10 | // identifiers have a _neon suffix. |
| 11 | #ifndef NAME_WRAP |
| 12 | #error "Please define NAME_WRAP() before including this file" |
| 13 | #endif |
| 14 | |
| 15 | // returns expanded * 5bits |
| 16 | static inline uint32_t Filter_565_Expanded(unsigned x, unsigned y, |
| 17 | uint32_t a00, uint32_t a01, |
| 18 | uint32_t a10, uint32_t a11) { |
| 19 | SkASSERT((unsigned)x <= 0xF); |
| 20 | SkASSERT((unsigned)y <= 0xF); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 21 | |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 22 | a00 = SkExpand_rgb_16(a00); |
| 23 | a01 = SkExpand_rgb_16(a01); |
| 24 | a10 = SkExpand_rgb_16(a10); |
| 25 | a11 = SkExpand_rgb_16(a11); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 26 | |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 27 | int xy = x * y >> 3; |
| 28 | return a00 * (32 - 2*y - 2*x + xy) + |
| 29 | a01 * (2*x - xy) + |
| 30 | a10 * (2*y - xy) + |
| 31 | a11 * xy; |
| 32 | } |
| 33 | |
| 34 | // turn an expanded 565 * 5bits into SkPMColor |
| 35 | // g:11 | r:10 | x:1 | b:10 |
| 36 | static inline SkPMColor SkExpanded_565_To_PMColor(uint32_t c) { |
| 37 | unsigned r = (c >> 13) & 0xFF; |
| 38 | unsigned g = (c >> 24); |
| 39 | unsigned b = (c >> 2) & 0xFF; |
| 40 | return SkPackARGB32(0xFF, r, g, b); |
| 41 | } |
| 42 | |
| 43 | // returns answer in SkPMColor format |
| 44 | static inline SkPMColor Filter_4444_D32(unsigned x, unsigned y, |
| 45 | uint32_t a00, uint32_t a01, |
| 46 | uint32_t a10, uint32_t a11) { |
| 47 | SkASSERT((unsigned)x <= 0xF); |
| 48 | SkASSERT((unsigned)y <= 0xF); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 49 | |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 50 | a00 = SkExpand_4444(a00); |
| 51 | a01 = SkExpand_4444(a01); |
| 52 | a10 = SkExpand_4444(a10); |
| 53 | a11 = SkExpand_4444(a11); |
| 54 | |
| 55 | int xy = x * y >> 4; |
| 56 | uint32_t result = a00 * (16 - y - x + xy) + |
| 57 | a01 * (x - xy) + |
| 58 | a10 * (y - xy) + |
| 59 | a11 * xy; |
| 60 | |
| 61 | return SkCompact_8888(result); |
| 62 | } |
| 63 | |
| 64 | static inline U8CPU Filter_8(unsigned x, unsigned y, |
| 65 | U8CPU a00, U8CPU a01, |
| 66 | U8CPU a10, U8CPU a11) { |
| 67 | SkASSERT((unsigned)x <= 0xF); |
| 68 | SkASSERT((unsigned)y <= 0xF); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 69 | |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 70 | int xy = x * y; |
| 71 | unsigned result = a00 * (256 - 16*y - 16*x + xy) + |
| 72 | a01 * (16*x - xy) + |
| 73 | a10 * (16*y - xy) + |
| 74 | a11 * xy; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 75 | |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 76 | return result >> 8; |
| 77 | } |
| 78 | |
| 79 | /***************************************************************************** |
| 80 | * |
| 81 | * D32 functions |
| 82 | * |
| 83 | */ |
| 84 | |
| 85 | // SRC == 8888 |
| 86 | |
| 87 | #define FILTER_PROC(x, y, a, b, c, d, dst) NAME_WRAP(Filter_32_opaque)(x, y, a, b, c, d, dst) |
| 88 | |
| 89 | #define MAKENAME(suffix) NAME_WRAP(S32_opaque_D32 ## suffix) |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 90 | #define SRCTYPE SkPMColor |
reed | ad7ae6c | 2015-06-04 14:12:25 -0700 | [diff] [blame] | 91 | #define CHECKSTATE(state) SkASSERT(4 == state.fPixmap.info().bytesPerPixel()); \ |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 92 | SkASSERT(state.fAlphaScale == 256) |
| 93 | #define RETURNDST(src) src |
| 94 | #define SRC_TO_FILTER(src) src |
| 95 | #include "SkBitmapProcState_sample.h" |
| 96 | |
| 97 | #undef FILTER_PROC |
| 98 | #define FILTER_PROC(x, y, a, b, c, d, dst) NAME_WRAP(Filter_32_alpha)(x, y, a, b, c, d, dst, alphaScale) |
| 99 | |
| 100 | #define MAKENAME(suffix) NAME_WRAP(S32_alpha_D32 ## suffix) |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 101 | #define SRCTYPE SkPMColor |
reed | ad7ae6c | 2015-06-04 14:12:25 -0700 | [diff] [blame] | 102 | #define CHECKSTATE(state) SkASSERT(4 == state.fPixmap.info().bytesPerPixel()); \ |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 103 | SkASSERT(state.fAlphaScale < 256) |
| 104 | #define PREAMBLE(state) unsigned alphaScale = state.fAlphaScale |
| 105 | #define RETURNDST(src) SkAlphaMulQ(src, alphaScale) |
| 106 | #define SRC_TO_FILTER(src) src |
| 107 | #include "SkBitmapProcState_sample.h" |
| 108 | |
| 109 | // SRC == 565 |
| 110 | |
| 111 | #undef FILTER_PROC |
| 112 | #define FILTER_PROC(x, y, a, b, c, d, dst) \ |
| 113 | do { \ |
| 114 | uint32_t tmp = Filter_565_Expanded(x, y, a, b, c, d); \ |
| 115 | *(dst) = SkExpanded_565_To_PMColor(tmp); \ |
| 116 | } while (0) |
| 117 | |
| 118 | #define MAKENAME(suffix) NAME_WRAP(S16_opaque_D32 ## suffix) |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 119 | #define SRCTYPE uint16_t |
reed | ad7ae6c | 2015-06-04 14:12:25 -0700 | [diff] [blame] | 120 | #define CHECKSTATE(state) SkASSERT(kRGB_565_SkColorType == state.fPixmap.colorType()); \ |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 121 | SkASSERT(state.fAlphaScale == 256) |
| 122 | #define RETURNDST(src) SkPixel16ToPixel32(src) |
| 123 | #define SRC_TO_FILTER(src) src |
| 124 | #include "SkBitmapProcState_sample.h" |
| 125 | |
| 126 | #undef FILTER_PROC |
| 127 | #define FILTER_PROC(x, y, a, b, c, d, dst) \ |
| 128 | do { \ |
| 129 | uint32_t tmp = Filter_565_Expanded(x, y, a, b, c, d); \ |
| 130 | *(dst) = SkAlphaMulQ(SkExpanded_565_To_PMColor(tmp), alphaScale); \ |
| 131 | } while (0) |
| 132 | |
| 133 | #define MAKENAME(suffix) NAME_WRAP(S16_alpha_D32 ## suffix) |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 134 | #define SRCTYPE uint16_t |
reed | ad7ae6c | 2015-06-04 14:12:25 -0700 | [diff] [blame] | 135 | #define CHECKSTATE(state) SkASSERT(kRGB_565_SkColorType == state.fPixmap.colorType()); \ |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 136 | SkASSERT(state.fAlphaScale < 256) |
| 137 | #define PREAMBLE(state) unsigned alphaScale = state.fAlphaScale |
| 138 | #define RETURNDST(src) SkAlphaMulQ(SkPixel16ToPixel32(src), alphaScale) |
| 139 | #define SRC_TO_FILTER(src) src |
| 140 | #include "SkBitmapProcState_sample.h" |
| 141 | |
| 142 | // SRC == Index8 |
| 143 | |
| 144 | #undef FILTER_PROC |
| 145 | #define FILTER_PROC(x, y, a, b, c, d, dst) NAME_WRAP(Filter_32_opaque)(x, y, a, b, c, d, dst) |
| 146 | |
| 147 | #define MAKENAME(suffix) NAME_WRAP(SI8_opaque_D32 ## suffix) |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 148 | #define SRCTYPE uint8_t |
reed | ad7ae6c | 2015-06-04 14:12:25 -0700 | [diff] [blame] | 149 | #define CHECKSTATE(state) SkASSERT(kIndex_8_SkColorType == state.fPixmap.colorType()); \ |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 150 | SkASSERT(state.fAlphaScale == 256) |
reed | ad7ae6c | 2015-06-04 14:12:25 -0700 | [diff] [blame] | 151 | #define PREAMBLE(state) const SkPMColor* SK_RESTRICT table = state.fPixmap.ctable()->readColors() |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 152 | #define RETURNDST(src) table[src] |
| 153 | #define SRC_TO_FILTER(src) table[src] |
mtklein | 775b819 | 2014-12-02 09:11:25 -0800 | [diff] [blame] | 154 | #define POSTAMBLE(state) |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 155 | #include "SkBitmapProcState_sample.h" |
| 156 | |
| 157 | #undef FILTER_PROC |
| 158 | #define FILTER_PROC(x, y, a, b, c, d, dst) NAME_WRAP(Filter_32_alpha)(x, y, a, b, c, d, dst, alphaScale) |
| 159 | |
| 160 | #define MAKENAME(suffix) NAME_WRAP(SI8_alpha_D32 ## suffix) |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 161 | #define SRCTYPE uint8_t |
reed | ad7ae6c | 2015-06-04 14:12:25 -0700 | [diff] [blame] | 162 | #define CHECKSTATE(state) SkASSERT(kIndex_8_SkColorType == state.fPixmap.colorType()); \ |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 163 | SkASSERT(state.fAlphaScale < 256) |
| 164 | #define PREAMBLE(state) unsigned alphaScale = state.fAlphaScale; \ |
reed | ad7ae6c | 2015-06-04 14:12:25 -0700 | [diff] [blame] | 165 | const SkPMColor* SK_RESTRICT table = state.fPixmap.ctable()->readColors() |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 166 | #define RETURNDST(src) SkAlphaMulQ(table[src], alphaScale) |
| 167 | #define SRC_TO_FILTER(src) table[src] |
mtklein | 775b819 | 2014-12-02 09:11:25 -0800 | [diff] [blame] | 168 | #define POSTAMBLE(state) |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 169 | #include "SkBitmapProcState_sample.h" |
| 170 | |
| 171 | // SRC == 4444 |
| 172 | |
| 173 | #undef FILTER_PROC |
| 174 | #define FILTER_PROC(x, y, a, b, c, d, dst) *(dst) = Filter_4444_D32(x, y, a, b, c, d) |
| 175 | |
| 176 | #define MAKENAME(suffix) NAME_WRAP(S4444_opaque_D32 ## suffix) |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 177 | #define SRCTYPE SkPMColor16 |
reed | ad7ae6c | 2015-06-04 14:12:25 -0700 | [diff] [blame] | 178 | #define CHECKSTATE(state) SkASSERT(kARGB_4444_SkColorType == state.fPixmap.colorType()); \ |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 179 | SkASSERT(state.fAlphaScale == 256) |
| 180 | #define RETURNDST(src) SkPixel4444ToPixel32(src) |
| 181 | #define SRC_TO_FILTER(src) src |
| 182 | #include "SkBitmapProcState_sample.h" |
| 183 | |
| 184 | #undef FILTER_PROC |
| 185 | #define FILTER_PROC(x, y, a, b, c, d, dst) \ |
| 186 | do { \ |
| 187 | uint32_t tmp = Filter_4444_D32(x, y, a, b, c, d); \ |
| 188 | *(dst) = SkAlphaMulQ(tmp, alphaScale); \ |
| 189 | } while (0) |
| 190 | |
| 191 | #define MAKENAME(suffix) NAME_WRAP(S4444_alpha_D32 ## suffix) |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 192 | #define SRCTYPE SkPMColor16 |
reed | ad7ae6c | 2015-06-04 14:12:25 -0700 | [diff] [blame] | 193 | #define CHECKSTATE(state) SkASSERT(kARGB_4444_SkColorType == state.fPixmap.colorType()); \ |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 194 | SkASSERT(state.fAlphaScale < 256) |
| 195 | #define PREAMBLE(state) unsigned alphaScale = state.fAlphaScale |
| 196 | #define RETURNDST(src) SkAlphaMulQ(SkPixel4444ToPixel32(src), alphaScale) |
| 197 | #define SRC_TO_FILTER(src) src |
| 198 | #include "SkBitmapProcState_sample.h" |
| 199 | |
| 200 | // SRC == A8 |
| 201 | |
| 202 | #undef FILTER_PROC |
| 203 | #define FILTER_PROC(x, y, a, b, c, d, dst) \ |
| 204 | do { \ |
| 205 | unsigned tmp = Filter_8(x, y, a, b, c, d); \ |
| 206 | *(dst) = SkAlphaMulQ(pmColor, SkAlpha255To256(tmp)); \ |
| 207 | } while (0) |
| 208 | |
| 209 | #define MAKENAME(suffix) NAME_WRAP(SA8_alpha_D32 ## suffix) |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 210 | #define SRCTYPE uint8_t |
reed | ad7ae6c | 2015-06-04 14:12:25 -0700 | [diff] [blame] | 211 | #define CHECKSTATE(state) SkASSERT(kAlpha_8_SkColorType == state.fPixmap.colorType()); |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 212 | #define PREAMBLE(state) const SkPMColor pmColor = state.fPaintPMColor; |
| 213 | #define RETURNDST(src) SkAlphaMulQ(pmColor, SkAlpha255To256(src)) |
| 214 | #define SRC_TO_FILTER(src) src |
| 215 | #include "SkBitmapProcState_sample.h" |
| 216 | |
reed | 0c9b1a8 | 2015-03-17 17:44:06 -0700 | [diff] [blame] | 217 | // SRC == Gray8 |
| 218 | |
| 219 | #undef FILTER_PROC |
| 220 | #define FILTER_PROC(x, y, a, b, c, d, dst) \ |
| 221 | do { \ |
| 222 | unsigned tmp = Filter_8(x, y, a, b, c, d); \ |
| 223 | SkPMColor color = SkPackARGB32(0xFF, tmp, tmp, tmp); \ |
| 224 | *(dst) = SkAlphaMulQ(color, alphaScale); \ |
| 225 | } while (0) |
| 226 | |
| 227 | #define MAKENAME(suffix) NAME_WRAP(SG8_alpha_D32 ## suffix) |
reed | 0c9b1a8 | 2015-03-17 17:44:06 -0700 | [diff] [blame] | 228 | #define SRCTYPE uint8_t |
reed | ad7ae6c | 2015-06-04 14:12:25 -0700 | [diff] [blame] | 229 | #define CHECKSTATE(state) SkASSERT(kGray_8_SkColorType == state.fPixmap.colorType()); |
reed | 0c9b1a8 | 2015-03-17 17:44:06 -0700 | [diff] [blame] | 230 | #define PREAMBLE(state) unsigned alphaScale = state.fAlphaScale |
| 231 | #define RETURNDST(src) SkAlphaMulQ(SkPackARGB32(0xFF, src, src, src), alphaScale) |
| 232 | #define SRC_TO_FILTER(src) src |
| 233 | #include "SkBitmapProcState_sample.h" |
| 234 | |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 235 | |
Florin Malita | d1c550e | 2016-12-19 10:55:41 -0500 | [diff] [blame] | 236 | #define TILEX_PROCF(fx, max) SkClampMax((fx) >> 16, max) |
| 237 | #define TILEY_PROCF(fy, max) SkClampMax((fy) >> 16, max) |
| 238 | #define EXTRACT_LOW_BITS(v, max) (((v) >> 12) & 0xF) |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 239 | |
| 240 | #undef FILTER_PROC |
| 241 | #define FILTER_PROC(x, y, a, b, c, d, dst) NAME_WRAP(Filter_32_opaque)(x, y, a, b, c, d, dst) |
| 242 | #define MAKENAME(suffix) NAME_WRAP(Clamp_SI8_opaque_D32 ## suffix) |
| 243 | #define SRCTYPE uint8_t |
reed | ad7ae6c | 2015-06-04 14:12:25 -0700 | [diff] [blame] | 244 | #define CHECKSTATE(state) SkASSERT(kIndex_8_SkColorType == state.fPixmap.colorType()) |
| 245 | #define PREAMBLE(state) const SkPMColor* SK_RESTRICT table = state.fPixmap.ctable()->readColors() |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 246 | #define SRC_TO_FILTER(src) table[src] |
mtklein | 775b819 | 2014-12-02 09:11:25 -0800 | [diff] [blame] | 247 | #define POSTAMBLE(state) |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 248 | #include "SkBitmapProcState_shaderproc.h" |
| 249 | |
reed@google.com | e4ee35d | 2012-08-14 13:22:16 +0000 | [diff] [blame] | 250 | #undef NAME_WRAP |