gfx/skia/trunk/src/core/SkBitmapProcState_procs.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/core/SkBitmapProcState_procs.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,343 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2011 Google Inc.
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +
    1.12 +// Define NAME_WRAP(x) before including this header to perform name-wrapping
    1.13 +// E.g. for ARM NEON, defined it as 'x ## _neon' to ensure all important
    1.14 +// identifiers have a _neon suffix.
    1.15 +#ifndef NAME_WRAP
    1.16 +#error "Please define NAME_WRAP() before including this file"
    1.17 +#endif
    1.18 +
    1.19 +// returns expanded * 5bits
    1.20 +static inline uint32_t Filter_565_Expanded(unsigned x, unsigned y,
    1.21 +                                           uint32_t a00, uint32_t a01,
    1.22 +                                           uint32_t a10, uint32_t a11) {
    1.23 +    SkASSERT((unsigned)x <= 0xF);
    1.24 +    SkASSERT((unsigned)y <= 0xF);
    1.25 +
    1.26 +    a00 = SkExpand_rgb_16(a00);
    1.27 +    a01 = SkExpand_rgb_16(a01);
    1.28 +    a10 = SkExpand_rgb_16(a10);
    1.29 +    a11 = SkExpand_rgb_16(a11);
    1.30 +
    1.31 +    int xy = x * y >> 3;
    1.32 +    return  a00 * (32 - 2*y - 2*x + xy) +
    1.33 +            a01 * (2*x - xy) +
    1.34 +            a10 * (2*y - xy) +
    1.35 +            a11 * xy;
    1.36 +}
    1.37 +
    1.38 +// turn an expanded 565 * 5bits into SkPMColor
    1.39 +// g:11 | r:10 | x:1 | b:10
    1.40 +static inline SkPMColor SkExpanded_565_To_PMColor(uint32_t c) {
    1.41 +    unsigned r = (c >> 13) & 0xFF;
    1.42 +    unsigned g = (c >> 24);
    1.43 +    unsigned b = (c >> 2) & 0xFF;
    1.44 +    return SkPackARGB32(0xFF, r, g, b);
    1.45 +}
    1.46 +
    1.47 +// returns answer in SkPMColor format
    1.48 +static inline SkPMColor Filter_4444_D32(unsigned x, unsigned y,
    1.49 +                                        uint32_t a00, uint32_t a01,
    1.50 +                                        uint32_t a10, uint32_t a11) {
    1.51 +    SkASSERT((unsigned)x <= 0xF);
    1.52 +    SkASSERT((unsigned)y <= 0xF);
    1.53 +
    1.54 +    a00 = SkExpand_4444(a00);
    1.55 +    a01 = SkExpand_4444(a01);
    1.56 +    a10 = SkExpand_4444(a10);
    1.57 +    a11 = SkExpand_4444(a11);
    1.58 +
    1.59 +    int xy = x * y >> 4;
    1.60 +    uint32_t result =   a00 * (16 - y - x + xy) +
    1.61 +                        a01 * (x - xy) +
    1.62 +                        a10 * (y - xy) +
    1.63 +                        a11 * xy;
    1.64 +
    1.65 +    return SkCompact_8888(result);
    1.66 +}
    1.67 +
    1.68 +static inline U8CPU Filter_8(unsigned x, unsigned y,
    1.69 +                             U8CPU a00, U8CPU a01,
    1.70 +                             U8CPU a10, U8CPU a11) {
    1.71 +    SkASSERT((unsigned)x <= 0xF);
    1.72 +    SkASSERT((unsigned)y <= 0xF);
    1.73 +
    1.74 +    int xy = x * y;
    1.75 +    unsigned result =   a00 * (256 - 16*y - 16*x + xy) +
    1.76 +                        a01 * (16*x - xy) +
    1.77 +                        a10 * (16*y - xy) +
    1.78 +                        a11 * xy;
    1.79 +
    1.80 +    return result >> 8;
    1.81 +}
    1.82 +
    1.83 +/*****************************************************************************
    1.84 + *
    1.85 + *  D32 functions
    1.86 + *
    1.87 + */
    1.88 +
    1.89 +// SRC == 8888
    1.90 +
    1.91 +#define FILTER_PROC(x, y, a, b, c, d, dst)   NAME_WRAP(Filter_32_opaque)(x, y, a, b, c, d, dst)
    1.92 +
    1.93 +#define MAKENAME(suffix)        NAME_WRAP(S32_opaque_D32 ## suffix)
    1.94 +#define DSTSIZE                 32
    1.95 +#define SRCTYPE                 SkPMColor
    1.96 +#define CHECKSTATE(state)       SkASSERT(state.fBitmap->config() == SkBitmap::kARGB_8888_Config); \
    1.97 +                                SkASSERT(state.fAlphaScale == 256)
    1.98 +#define RETURNDST(src)          src
    1.99 +#define SRC_TO_FILTER(src)      src
   1.100 +#include "SkBitmapProcState_sample.h"
   1.101 +
   1.102 +#undef FILTER_PROC
   1.103 +#define FILTER_PROC(x, y, a, b, c, d, dst)   NAME_WRAP(Filter_32_alpha)(x, y, a, b, c, d, dst, alphaScale)
   1.104 +
   1.105 +#define MAKENAME(suffix)        NAME_WRAP(S32_alpha_D32 ## suffix)
   1.106 +#define DSTSIZE                 32
   1.107 +#define SRCTYPE                 SkPMColor
   1.108 +#define CHECKSTATE(state)       SkASSERT(state.fBitmap->config() == SkBitmap::kARGB_8888_Config); \
   1.109 +                                SkASSERT(state.fAlphaScale < 256)
   1.110 +#define PREAMBLE(state)         unsigned alphaScale = state.fAlphaScale
   1.111 +#define RETURNDST(src)          SkAlphaMulQ(src, alphaScale)
   1.112 +#define SRC_TO_FILTER(src)      src
   1.113 +#include "SkBitmapProcState_sample.h"
   1.114 +
   1.115 +// SRC == 565
   1.116 +
   1.117 +#undef FILTER_PROC
   1.118 +#define FILTER_PROC(x, y, a, b, c, d, dst) \
   1.119 +    do {                                                        \
   1.120 +        uint32_t tmp = Filter_565_Expanded(x, y, a, b, c, d);   \
   1.121 +        *(dst) = SkExpanded_565_To_PMColor(tmp);                \
   1.122 +    } while (0)
   1.123 +
   1.124 +#define MAKENAME(suffix)        NAME_WRAP(S16_opaque_D32 ## suffix)
   1.125 +#define DSTSIZE                 32
   1.126 +#define SRCTYPE                 uint16_t
   1.127 +#define CHECKSTATE(state)       SkASSERT(state.fBitmap->config() == SkBitmap::kRGB_565_Config); \
   1.128 +                                SkASSERT(state.fAlphaScale == 256)
   1.129 +#define RETURNDST(src)          SkPixel16ToPixel32(src)
   1.130 +#define SRC_TO_FILTER(src)      src
   1.131 +#include "SkBitmapProcState_sample.h"
   1.132 +
   1.133 +#undef FILTER_PROC
   1.134 +#define FILTER_PROC(x, y, a, b, c, d, dst) \
   1.135 +    do {                                                                    \
   1.136 +        uint32_t tmp = Filter_565_Expanded(x, y, a, b, c, d);               \
   1.137 +        *(dst) = SkAlphaMulQ(SkExpanded_565_To_PMColor(tmp), alphaScale);   \
   1.138 +    } while (0)
   1.139 +
   1.140 +#define MAKENAME(suffix)        NAME_WRAP(S16_alpha_D32 ## suffix)
   1.141 +#define DSTSIZE                 32
   1.142 +#define SRCTYPE                 uint16_t
   1.143 +#define CHECKSTATE(state)       SkASSERT(state.fBitmap->config() == SkBitmap::kRGB_565_Config); \
   1.144 +                                SkASSERT(state.fAlphaScale < 256)
   1.145 +#define PREAMBLE(state)         unsigned alphaScale = state.fAlphaScale
   1.146 +#define RETURNDST(src)          SkAlphaMulQ(SkPixel16ToPixel32(src), alphaScale)
   1.147 +#define SRC_TO_FILTER(src)      src
   1.148 +#include "SkBitmapProcState_sample.h"
   1.149 +
   1.150 +// SRC == Index8
   1.151 +
   1.152 +#undef FILTER_PROC
   1.153 +#define FILTER_PROC(x, y, a, b, c, d, dst)   NAME_WRAP(Filter_32_opaque)(x, y, a, b, c, d, dst)
   1.154 +
   1.155 +#define MAKENAME(suffix)        NAME_WRAP(SI8_opaque_D32 ## suffix)
   1.156 +#define DSTSIZE                 32
   1.157 +#define SRCTYPE                 uint8_t
   1.158 +#define CHECKSTATE(state)       SkASSERT(state.fBitmap->config() == SkBitmap::kIndex8_Config); \
   1.159 +                                SkASSERT(state.fAlphaScale == 256)
   1.160 +#define PREAMBLE(state)         const SkPMColor* SK_RESTRICT table = state.fBitmap->getColorTable()->lockColors()
   1.161 +#define RETURNDST(src)          table[src]
   1.162 +#define SRC_TO_FILTER(src)      table[src]
   1.163 +#define POSTAMBLE(state)        state.fBitmap->getColorTable()->unlockColors()
   1.164 +#include "SkBitmapProcState_sample.h"
   1.165 +
   1.166 +#undef FILTER_PROC
   1.167 +#define FILTER_PROC(x, y, a, b, c, d, dst)   NAME_WRAP(Filter_32_alpha)(x, y, a, b, c, d, dst, alphaScale)
   1.168 +
   1.169 +#define MAKENAME(suffix)        NAME_WRAP(SI8_alpha_D32 ## suffix)
   1.170 +#define DSTSIZE                 32
   1.171 +#define SRCTYPE                 uint8_t
   1.172 +#define CHECKSTATE(state)       SkASSERT(state.fBitmap->config() == SkBitmap::kIndex8_Config); \
   1.173 +                                SkASSERT(state.fAlphaScale < 256)
   1.174 +#define PREAMBLE(state)         unsigned alphaScale = state.fAlphaScale; \
   1.175 +                                const SkPMColor* SK_RESTRICT table = state.fBitmap->getColorTable()->lockColors()
   1.176 +#define RETURNDST(src)          SkAlphaMulQ(table[src], alphaScale)
   1.177 +#define SRC_TO_FILTER(src)      table[src]
   1.178 +#define POSTAMBLE(state)        state.fBitmap->getColorTable()->unlockColors()
   1.179 +#include "SkBitmapProcState_sample.h"
   1.180 +
   1.181 +// SRC == 4444
   1.182 +
   1.183 +#undef FILTER_PROC
   1.184 +#define FILTER_PROC(x, y, a, b, c, d, dst)  *(dst) = Filter_4444_D32(x, y, a, b, c, d)
   1.185 +
   1.186 +#define MAKENAME(suffix)        NAME_WRAP(S4444_opaque_D32 ## suffix)
   1.187 +#define DSTSIZE                 32
   1.188 +#define SRCTYPE                 SkPMColor16
   1.189 +#define CHECKSTATE(state)       SkASSERT(state.fBitmap->config() == SkBitmap::kARGB_4444_Config); \
   1.190 +                                SkASSERT(state.fAlphaScale == 256)
   1.191 +#define RETURNDST(src)          SkPixel4444ToPixel32(src)
   1.192 +#define SRC_TO_FILTER(src)      src
   1.193 +#include "SkBitmapProcState_sample.h"
   1.194 +
   1.195 +#undef FILTER_PROC
   1.196 +#define FILTER_PROC(x, y, a, b, c, d, dst)  \
   1.197 +    do {                                                    \
   1.198 +        uint32_t tmp = Filter_4444_D32(x, y, a, b, c, d);   \
   1.199 +        *(dst) = SkAlphaMulQ(tmp, alphaScale);              \
   1.200 +    } while (0)
   1.201 +
   1.202 +#define MAKENAME(suffix)        NAME_WRAP(S4444_alpha_D32 ## suffix)
   1.203 +#define DSTSIZE                 32
   1.204 +#define SRCTYPE                 SkPMColor16
   1.205 +#define CHECKSTATE(state)       SkASSERT(state.fBitmap->config() == SkBitmap::kARGB_4444_Config); \
   1.206 +                                SkASSERT(state.fAlphaScale < 256)
   1.207 +#define PREAMBLE(state)         unsigned alphaScale = state.fAlphaScale
   1.208 +#define RETURNDST(src)          SkAlphaMulQ(SkPixel4444ToPixel32(src), alphaScale)
   1.209 +#define SRC_TO_FILTER(src)      src
   1.210 +#include "SkBitmapProcState_sample.h"
   1.211 +
   1.212 +// SRC == A8
   1.213 +
   1.214 +#undef FILTER_PROC
   1.215 +#define FILTER_PROC(x, y, a, b, c, d, dst) \
   1.216 +    do {                                                        \
   1.217 +        unsigned tmp = Filter_8(x, y, a, b, c, d);              \
   1.218 +        *(dst) = SkAlphaMulQ(pmColor, SkAlpha255To256(tmp));    \
   1.219 +    } while (0)
   1.220 +
   1.221 +#define MAKENAME(suffix)        NAME_WRAP(SA8_alpha_D32 ## suffix)
   1.222 +#define DSTSIZE                 32
   1.223 +#define SRCTYPE                 uint8_t
   1.224 +#define CHECKSTATE(state)       SkASSERT(state.fBitmap->config() == SkBitmap::kA8_Config);
   1.225 +#define PREAMBLE(state)         const SkPMColor pmColor = state.fPaintPMColor;
   1.226 +#define RETURNDST(src)          SkAlphaMulQ(pmColor, SkAlpha255To256(src))
   1.227 +#define SRC_TO_FILTER(src)      src
   1.228 +#include "SkBitmapProcState_sample.h"
   1.229 +
   1.230 +/*****************************************************************************
   1.231 + *
   1.232 + *  D16 functions
   1.233 + *
   1.234 + */
   1.235 +
   1.236 +// SRC == 8888
   1.237 +
   1.238 +#undef FILTER_PROC
   1.239 +#define FILTER_PROC(x, y, a, b, c, d, dst) \
   1.240 +    do {                                                \
   1.241 +        SkPMColor dstColor;                             \
   1.242 +        NAME_WRAP(Filter_32_opaque)(x, y, a, b, c, d, &dstColor);  \
   1.243 +        (*dst) = SkPixel32ToPixel16(dstColor);          \
   1.244 +    } while (0)
   1.245 +
   1.246 +#define MAKENAME(suffix)        NAME_WRAP(S32_D16 ## suffix)
   1.247 +#define DSTSIZE                 16
   1.248 +#define SRCTYPE                 SkPMColor
   1.249 +#define CHECKSTATE(state)       SkASSERT(state.fBitmap->config() == SkBitmap::kARGB_8888_Config); \
   1.250 +                                SkASSERT(state.fBitmap->isOpaque())
   1.251 +#define RETURNDST(src)          SkPixel32ToPixel16(src)
   1.252 +#define SRC_TO_FILTER(src)      src
   1.253 +#include "SkBitmapProcState_sample.h"
   1.254 +
   1.255 +// SRC == 565
   1.256 +
   1.257 +#undef FILTER_PROC
   1.258 +#define FILTER_PROC(x, y, a, b, c, d, dst) \
   1.259 +    do {                                                        \
   1.260 +        uint32_t tmp = Filter_565_Expanded(x, y, a, b, c, d);   \
   1.261 +        *(dst) = SkCompact_rgb_16((tmp) >> 5);                  \
   1.262 +    } while (0)
   1.263 +
   1.264 +#define MAKENAME(suffix)        NAME_WRAP(S16_D16 ## suffix)
   1.265 +#define DSTSIZE                 16
   1.266 +#define SRCTYPE                 uint16_t
   1.267 +#define CHECKSTATE(state)       SkASSERT(state.fBitmap->config() == SkBitmap::kRGB_565_Config)
   1.268 +#define RETURNDST(src)          src
   1.269 +#define SRC_TO_FILTER(src)      src
   1.270 +#include "SkBitmapProcState_sample.h"
   1.271 +
   1.272 +// SRC == Index8
   1.273 +
   1.274 +#undef FILTER_PROC
   1.275 +#define FILTER_PROC(x, y, a, b, c, d, dst) \
   1.276 +    do {                                                        \
   1.277 +        uint32_t tmp = Filter_565_Expanded(x, y, a, b, c, d);   \
   1.278 +        *(dst) = SkCompact_rgb_16((tmp) >> 5);                  \
   1.279 +    } while (0)
   1.280 +
   1.281 +#define MAKENAME(suffix)        NAME_WRAP(SI8_D16 ## suffix)
   1.282 +#define DSTSIZE                 16
   1.283 +#define SRCTYPE                 uint8_t
   1.284 +#define CHECKSTATE(state)       SkASSERT(state.fBitmap->config() == SkBitmap::kIndex8_Config); \
   1.285 +                                SkASSERT(state.fBitmap->isOpaque())
   1.286 +#define PREAMBLE(state)         const uint16_t* SK_RESTRICT table = state.fBitmap->getColorTable()->lock16BitCache()
   1.287 +#define RETURNDST(src)          table[src]
   1.288 +#define SRC_TO_FILTER(src)      table[src]
   1.289 +#define POSTAMBLE(state)        state.fBitmap->getColorTable()->unlock16BitCache()
   1.290 +#include "SkBitmapProcState_sample.h"
   1.291 +
   1.292 +///////////////////////////////////////////////////////////////////////////////
   1.293 +
   1.294 +#undef FILTER_PROC
   1.295 +#define FILTER_PROC(x, y, a, b, c, d, dst) \
   1.296 +    do {                                                        \
   1.297 +        uint32_t tmp = Filter_565_Expanded(x, y, a, b, c, d);   \
   1.298 +        *(dst) = SkCompact_rgb_16((tmp) >> 5);                  \
   1.299 +    } while (0)
   1.300 +
   1.301 +
   1.302 +// clamp
   1.303 +
   1.304 +#define TILEX_PROCF(fx, max)    SkClampMax((fx) >> 16, max)
   1.305 +#define TILEY_PROCF(fy, max)    SkClampMax((fy) >> 16, max)
   1.306 +#define TILEX_LOW_BITS(fx, max) (((fx) >> 12) & 0xF)
   1.307 +#define TILEY_LOW_BITS(fy, max) (((fy) >> 12) & 0xF)
   1.308 +
   1.309 +#define MAKENAME(suffix)        NAME_WRAP(Clamp_S16_D16 ## suffix)
   1.310 +#define SRCTYPE                 uint16_t
   1.311 +#define DSTTYPE                 uint16_t
   1.312 +#define CHECKSTATE(state)       SkASSERT(state.fBitmap->config() == SkBitmap::kRGB_565_Config)
   1.313 +#define SRC_TO_FILTER(src)      src
   1.314 +#include "SkBitmapProcState_shaderproc.h"
   1.315 +
   1.316 +
   1.317 +#define TILEX_PROCF(fx, max)    (((fx) & 0xFFFF) * ((max) + 1) >> 16)
   1.318 +#define TILEY_PROCF(fy, max)    (((fy) & 0xFFFF) * ((max) + 1) >> 16)
   1.319 +#define TILEX_LOW_BITS(fx, max) ((((fx) & 0xFFFF) * ((max) + 1) >> 12) & 0xF)
   1.320 +#define TILEY_LOW_BITS(fy, max) ((((fy) & 0xFFFF) * ((max) + 1) >> 12) & 0xF)
   1.321 +
   1.322 +#define MAKENAME(suffix)        NAME_WRAP(Repeat_S16_D16 ## suffix)
   1.323 +#define SRCTYPE                 uint16_t
   1.324 +#define DSTTYPE                 uint16_t
   1.325 +#define CHECKSTATE(state)       SkASSERT(state.fBitmap->config() == SkBitmap::kRGB_565_Config)
   1.326 +#define SRC_TO_FILTER(src)      src
   1.327 +#include "SkBitmapProcState_shaderproc.h"
   1.328 +
   1.329 +
   1.330 +#define TILEX_PROCF(fx, max)    SkClampMax((fx) >> 16, max)
   1.331 +#define TILEY_PROCF(fy, max)    SkClampMax((fy) >> 16, max)
   1.332 +#define TILEX_LOW_BITS(fx, max) (((fx) >> 12) & 0xF)
   1.333 +#define TILEY_LOW_BITS(fy, max) (((fy) >> 12) & 0xF)
   1.334 +
   1.335 +#undef FILTER_PROC
   1.336 +#define FILTER_PROC(x, y, a, b, c, d, dst)   NAME_WRAP(Filter_32_opaque)(x, y, a, b, c, d, dst)
   1.337 +#define MAKENAME(suffix)        NAME_WRAP(Clamp_SI8_opaque_D32 ## suffix)
   1.338 +#define SRCTYPE                 uint8_t
   1.339 +#define DSTTYPE                 uint32_t
   1.340 +#define CHECKSTATE(state)       SkASSERT(state.fBitmap->config() == SkBitmap::kIndex8_Config)
   1.341 +#define PREAMBLE(state)         const SkPMColor* SK_RESTRICT table = state.fBitmap->getColorTable()->lockColors()
   1.342 +#define SRC_TO_FILTER(src)      table[src]
   1.343 +#define POSTAMBLE(state)        state.fBitmap->getColorTable()->unlockColors()
   1.344 +#include "SkBitmapProcState_shaderproc.h"
   1.345 +
   1.346 +#undef NAME_WRAP

mercurial