1 /*
2 * Copyright (C) 2006-2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef SkFilter_DEFINED
18 #define SkFilter_DEFINED
19
20 #include "SkMath.h"
21 #include "SkFixed.h"
22
23 typedef unsigned (*SkFilterProc)(unsigned x00, unsigned x01,
24 unsigned x10, unsigned x11);
25
26 const SkFilterProc* SkGetBilinearFilterProcTable();
27
SkGetBilinearFilterProc(const SkFilterProc * table,SkFixed x,SkFixed y)28 inline SkFilterProc SkGetBilinearFilterProc(const SkFilterProc* table,
29 SkFixed x, SkFixed y)
30 {
31 SkASSERT(table);
32
33 // convert to dot 2
34 x = (unsigned)(x << 16) >> 30;
35 y = (unsigned)(y << 16) >> 30;
36 return table[(y << 2) | x];
37 }
38
SkGetBilinearFilterProc22(const SkFilterProc * table,unsigned x,unsigned y)39 inline SkFilterProc SkGetBilinearFilterProc22(const SkFilterProc* table,
40 unsigned x, unsigned y)
41 {
42 SkASSERT(table);
43
44 // extract low 2 bits
45 x = x << 30 >> 30;
46 y = y << 30 >> 30;
47 return table[(y << 2) | x];
48 }
49
SkGetBilinearFilterProc22Row(const SkFilterProc * table,unsigned y)50 inline const SkFilterProc* SkGetBilinearFilterProc22Row(const SkFilterProc* table,
51 unsigned y)
52 {
53 SkASSERT(table);
54 // extract low 2 bits and shift up 2
55 return &table[y << 30 >> 28];
56 }
57
SkGetBilinearFilterProc22RowProc(const SkFilterProc * row,unsigned x)58 inline SkFilterProc SkGetBilinearFilterProc22RowProc(const SkFilterProc* row,
59 unsigned x)
60 {
61 SkASSERT(row);
62 // extract low 2 bits
63 return row[x << 30 >> 30];
64 }
65
66 ///////////////////////////////////////////////////////////////////////////////
67
68 typedef unsigned (*SkFilter32Proc)(uint32_t x00, uint32_t x01,
69 uint32_t x10, uint32_t x11);
70
71 const SkFilter32Proc* SkGetFilter32ProcTable();
72
SkGetFilter32Proc22(const SkFilter32Proc * table,unsigned x,unsigned y)73 inline SkFilter32Proc SkGetFilter32Proc22(const SkFilter32Proc* table,
74 unsigned x, unsigned y)
75 {
76 SkASSERT(table);
77
78 // extract low 2 bits
79 x = x << 30 >> 30;
80 y = y << 30 >> 30;
81 return table[(y << 2) | x];
82 }
83
SkGetFilter32Proc22Row(const SkFilter32Proc * table,unsigned y)84 inline const SkFilter32Proc* SkGetFilter32Proc22Row(const SkFilter32Proc* table,
85 unsigned y)
86 {
87 SkASSERT(table);
88 // extract low 2 bits and shift up 2
89 return &table[y << 30 >> 28];
90 }
91
SkGetFilter32Proc22RowProc(const SkFilter32Proc * row,unsigned x)92 inline SkFilter32Proc SkGetFilter32Proc22RowProc(const SkFilter32Proc* row,
93 unsigned x)
94 {
95 SkASSERT(row);
96 // extract low 2 bits
97 return row[x << 30 >> 30];
98 }
99
100 ///////////////////////////////////////////////////////////////////////////////
101
102 /** Special version of SkFilterProc. This takes the address of 4 ints, and combines them a byte at a
103 time. AABBCCDD.
104 */
105 typedef uint32_t (*SkFilterPtrProc)(const uint32_t*, const uint32_t*, const uint32_t*, const uint32_t*);
106
107 const SkFilterPtrProc* SkGetBilinearFilterPtrProcTable();
SkGetBilinearFilterPtrProc(const SkFilterPtrProc * table,SkFixed x,SkFixed y)108 inline SkFilterPtrProc SkGetBilinearFilterPtrProc(const SkFilterPtrProc* table, SkFixed x, SkFixed y)
109 {
110 SkASSERT(table);
111
112 // convert to dot 2
113 x = (unsigned)(x << 16) >> 30;
114 y = (unsigned)(y << 16) >> 30;
115 return table[(y << 2) | x];
116 }
117
118 /** Given a Y value, return a subset of the proc table for that value.
119 Pass this to SkGetBilinearFilterPtrXProc with the corresponding X value to get the
120 correct proc.
121 */
SkGetBilinearFilterPtrProcYTable(const SkFilterPtrProc * table,SkFixed y)122 inline const SkFilterPtrProc* SkGetBilinearFilterPtrProcYTable(const SkFilterPtrProc* table, SkFixed y)
123 {
124 SkASSERT(table);
125
126 y = (unsigned)(y << 16) >> 30;
127 return table + (y << 2);
128 }
129
130 /** Given a subtable returned by SkGetBilinearFilterPtrProcYTable(), return the proc for the
131 specified X value.
132 */
SkGetBilinearFilterPtrXProc(const SkFilterPtrProc * table,SkFixed x)133 inline SkFilterPtrProc SkGetBilinearFilterPtrXProc(const SkFilterPtrProc* table, SkFixed x)
134 {
135 SkASSERT(table);
136
137 // convert to dot 2
138 x = (unsigned)(x << 16) >> 30;
139 return table[x];
140 }
141
142 #endif
143
144
145