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