1 /*
2 Copyright 2011 Google Inc.
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
18 #define SCALE_FILTER_NAME MAKENAME(_filter_DX_shaderproc)
19
SCALE_FILTER_NAME(const SkBitmapProcState & s,int x,int y,DSTTYPE * SK_RESTRICT colors,int count)20 static void SCALE_FILTER_NAME(const SkBitmapProcState& s, int x, int y,
21 DSTTYPE* SK_RESTRICT colors, int count) {
22 SkASSERT((s.fInvType & ~(SkMatrix::kTranslate_Mask |
23 SkMatrix::kScale_Mask)) == 0);
24 SkASSERT(s.fInvKy == 0);
25 SkASSERT(count > 0 && colors != NULL);
26 SkASSERT(s.fDoFilter);
27 SkDEBUGCODE(CHECKSTATE(s);)
28
29 const unsigned maxX = s.fBitmap->width() - 1;
30 const SkFixed oneX = s.fFilterOneX;
31 const SkFixed dx = s.fInvSx;
32 SkFixed fx;
33 const SRCTYPE* SK_RESTRICT row0;
34 const SRCTYPE* SK_RESTRICT row1;
35 unsigned subY;
36
37 {
38 SkPoint pt;
39 s.fInvProc(*s.fInvMatrix, SkIntToScalar(x) + SK_ScalarHalf,
40 SkIntToScalar(y) + SK_ScalarHalf, &pt);
41 SkFixed fy = SkScalarToFixed(pt.fY) - (s.fFilterOneY >> 1);
42 const unsigned maxY = s.fBitmap->height() - 1;
43 // compute our two Y values up front
44 subY = TILEY_LOW_BITS(fy, maxY);
45 int y0 = TILEY_PROCF(fy, maxY);
46 int y1 = TILEY_PROCF((fy + s.fFilterOneY), maxY);
47
48 const char* SK_RESTRICT srcAddr = (const char*)s.fBitmap->getPixels();
49 unsigned rb = s.fBitmap->rowBytes();
50 row0 = (const SRCTYPE*)(srcAddr + y0 * rb);
51 row1 = (const SRCTYPE*)(srcAddr + y1 * rb);
52 // now initialize fx
53 fx = SkScalarToFixed(pt.fX) - (oneX >> 1);
54 }
55
56 #ifdef PREAMBLE
57 PREAMBLE(s);
58 #endif
59
60 do {
61 unsigned subX = TILEX_LOW_BITS(fx, maxX);
62 unsigned x0 = TILEX_PROCF(fx, maxX);
63 unsigned x1 = TILEX_PROCF((fx + oneX), maxX);
64
65 FILTER_PROC(subX, subY,
66 SRC_TO_FILTER(row0[x0]),
67 SRC_TO_FILTER(row0[x1]),
68 SRC_TO_FILTER(row1[x0]),
69 SRC_TO_FILTER(row1[x1]),
70 colors);
71 colors += 1;
72
73 fx += dx;
74 } while (--count != 0);
75
76 #ifdef POSTAMBLE
77 POSTAMBLE(s);
78 #endif
79 }
80
81 ///////////////////////////////////////////////////////////////////////////////
82
83 #undef TILEX_PROCF
84 #undef TILEY_PROCF
85 #undef TILEX_LOW_BITS
86 #undef TILEY_LOW_BITS
87 #undef MAKENAME
88 #undef SRCTYPE
89 #undef DSTTYPE
90 #undef CHECKSTATE
91 #undef SRC_TO_FILTER
92 #undef FILTER_TO_DST
93 #undef PREAMBLE
94 #undef POSTAMBLE
95
96 #undef SCALE_FILTER_NAME
97