• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
Filter_565_Expanded(unsigned x,unsigned y,uint32_t a00,uint32_t a01,uint32_t a10,uint32_t a11)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);
21 
22     a00 = SkExpand_rgb_16(a00);
23     a01 = SkExpand_rgb_16(a01);
24     a10 = SkExpand_rgb_16(a10);
25     a11 = SkExpand_rgb_16(a11);
26 
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
SkExpanded_565_To_PMColor(uint32_t c)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
Filter_4444_D32(unsigned x,unsigned y,uint32_t a00,uint32_t a01,uint32_t a10,uint32_t a11)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);
49 
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 
Filter_8(unsigned x,unsigned y,U8CPU a00,U8CPU a01,U8CPU a10,U8CPU a11)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);
69 
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;
75 
76     return result >> 8;
77 }
78 
79 // SRC == 8888
80 
81 #define FILTER_PROC(x, y, a, b, c, d, dst)   NAME_WRAP(Filter_32_opaque)(x, y, a, b, c, d, dst)
82 
83 #define MAKENAME(suffix)        NAME_WRAP(S32_opaque_D32 ## suffix)
84 #define SRCTYPE                 SkPMColor
85 #define CHECKSTATE(state)       SkASSERT(4 == state.fPixmap.info().bytesPerPixel()); \
86                                 SkASSERT(state.fAlphaScale == 256)
87 #define RETURNDST(src)          src
88 #define SRC_TO_FILTER(src)      src
89 #include "SkBitmapProcState_sample.h"
90 
91 #undef FILTER_PROC
92 #define FILTER_PROC(x, y, a, b, c, d, dst)   NAME_WRAP(Filter_32_alpha)(x, y, a, b, c, d, dst, alphaScale)
93 
94 #define MAKENAME(suffix)        NAME_WRAP(S32_alpha_D32 ## suffix)
95 #define SRCTYPE                 SkPMColor
96 #define CHECKSTATE(state)       SkASSERT(4 == state.fPixmap.info().bytesPerPixel()); \
97                                 SkASSERT(state.fAlphaScale < 256)
98 #define PREAMBLE(state)         unsigned alphaScale = state.fAlphaScale
99 #define RETURNDST(src)          SkAlphaMulQ(src, alphaScale)
100 #define SRC_TO_FILTER(src)      src
101 #include "SkBitmapProcState_sample.h"
102 
103 #undef NAME_WRAP
104