• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2008 The Android Open Source Project
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 
9 #ifndef SkFilter_DEFINED
10 #define SkFilter_DEFINED
11 
12 #include "SkMath.h"
13 #include "SkFixed.h"
14 
15 typedef unsigned (*SkFilterProc)(unsigned x00, unsigned x01,
16                                  unsigned x10, unsigned x11);
17 
18 const SkFilterProc* SkGetBilinearFilterProcTable();
19 
SkGetBilinearFilterProc(const SkFilterProc * table,SkFixed x,SkFixed y)20 inline SkFilterProc SkGetBilinearFilterProc(const SkFilterProc* table,
21                                             SkFixed x, SkFixed y)
22 {
23     SkASSERT(table);
24 
25     // convert to dot 2
26     x = (unsigned)(x << 16) >> 30;
27     y = (unsigned)(y << 16) >> 30;
28     return table[(y << 2) | x];
29 }
30 
SkGetBilinearFilterProc22(const SkFilterProc * table,unsigned x,unsigned y)31 inline SkFilterProc SkGetBilinearFilterProc22(const SkFilterProc* table,
32                                               unsigned x, unsigned y)
33 {
34     SkASSERT(table);
35 
36     // extract low 2 bits
37     x = x << 30 >> 30;
38     y = y << 30 >> 30;
39     return table[(y << 2) | x];
40 }
41 
SkGetBilinearFilterProc22Row(const SkFilterProc * table,unsigned y)42 inline const SkFilterProc* SkGetBilinearFilterProc22Row(const SkFilterProc* table,
43                                                         unsigned y)
44 {
45     SkASSERT(table);
46     // extract low 2 bits and shift up 2
47     return &table[y << 30 >> 28];
48 }
49 
SkGetBilinearFilterProc22RowProc(const SkFilterProc * row,unsigned x)50 inline SkFilterProc SkGetBilinearFilterProc22RowProc(const SkFilterProc* row,
51                                                      unsigned x)
52 {
53     SkASSERT(row);
54     // extract low 2 bits
55     return row[x << 30 >> 30];
56 }
57 
58 ///////////////////////////////////////////////////////////////////////////////
59 
60 typedef unsigned (*SkFilter32Proc)(uint32_t x00, uint32_t x01,
61                                    uint32_t x10, uint32_t x11);
62 
63 const SkFilter32Proc* SkGetFilter32ProcTable();
64 
SkGetFilter32Proc22(const SkFilter32Proc * table,unsigned x,unsigned y)65 inline SkFilter32Proc SkGetFilter32Proc22(const SkFilter32Proc* table,
66                                           unsigned x, unsigned y)
67 {
68     SkASSERT(table);
69 
70     // extract low 2 bits
71     x = x << 30 >> 30;
72     y = y << 30 >> 30;
73     return table[(y << 2) | x];
74 }
75 
SkGetFilter32Proc22Row(const SkFilter32Proc * table,unsigned y)76 inline const SkFilter32Proc* SkGetFilter32Proc22Row(const SkFilter32Proc* table,
77                                                     unsigned y)
78 {
79     SkASSERT(table);
80     // extract low 2 bits and shift up 2
81     return &table[y << 30 >> 28];
82 }
83 
SkGetFilter32Proc22RowProc(const SkFilter32Proc * row,unsigned x)84 inline SkFilter32Proc SkGetFilter32Proc22RowProc(const SkFilter32Proc* row,
85                                                  unsigned x)
86 {
87     SkASSERT(row);
88     // extract low 2 bits
89     return row[x << 30 >> 30];
90 }
91 
92 ///////////////////////////////////////////////////////////////////////////////
93 
94 /** Special version of SkFilterProc. This takes the address of 4 ints, and combines them a byte at a
95     time. AABBCCDD.
96 */
97 typedef uint32_t (*SkFilterPtrProc)(const uint32_t*, const uint32_t*, const uint32_t*, const uint32_t*);
98 
99 const SkFilterPtrProc* SkGetBilinearFilterPtrProcTable();
SkGetBilinearFilterPtrProc(const SkFilterPtrProc * table,SkFixed x,SkFixed y)100 inline SkFilterPtrProc SkGetBilinearFilterPtrProc(const SkFilterPtrProc* table, SkFixed x, SkFixed y)
101 {
102     SkASSERT(table);
103 
104     // convert to dot 2
105     x = (unsigned)(x << 16) >> 30;
106     y = (unsigned)(y << 16) >> 30;
107     return table[(y << 2) | x];
108 }
109 
110 /** Given a Y value, return a subset of the proc table for that value.
111     Pass this to SkGetBilinearFilterPtrXProc with the corresponding X value to get the
112     correct proc.
113 */
SkGetBilinearFilterPtrProcYTable(const SkFilterPtrProc * table,SkFixed y)114 inline const SkFilterPtrProc* SkGetBilinearFilterPtrProcYTable(const SkFilterPtrProc* table, SkFixed y)
115 {
116     SkASSERT(table);
117 
118     y = (unsigned)(y << 16) >> 30;
119     return table + (y << 2);
120 }
121 
122 /** Given a subtable returned by SkGetBilinearFilterPtrProcYTable(), return the proc for the
123     specified X value.
124 */
SkGetBilinearFilterPtrXProc(const SkFilterPtrProc * table,SkFixed x)125 inline SkFilterPtrProc SkGetBilinearFilterPtrXProc(const SkFilterPtrProc* table, SkFixed x)
126 {
127     SkASSERT(table);
128 
129     // convert to dot 2
130     x = (unsigned)(x << 16) >> 30;
131     return table[x];
132 }
133 
134 #endif
135