OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkMath.h" | 9 #include "SkMath.h" |
10 #include "SkMathPriv.h" | 10 #include "SkMathPriv.h" |
11 | 11 |
| 12 #define SCALE_NOFILTER_NAME MAKENAME(_nofilter_scale) |
12 #define SCALE_FILTER_NAME MAKENAME(_filter_scale) | 13 #define SCALE_FILTER_NAME MAKENAME(_filter_scale) |
| 14 #define AFFINE_NOFILTER_NAME MAKENAME(_nofilter_affine) |
13 #define AFFINE_FILTER_NAME MAKENAME(_filter_affine) | 15 #define AFFINE_FILTER_NAME MAKENAME(_filter_affine) |
| 16 #define PERSP_NOFILTER_NAME MAKENAME(_nofilter_persp) |
14 #define PERSP_FILTER_NAME MAKENAME(_filter_persp) | 17 #define PERSP_FILTER_NAME MAKENAME(_filter_persp) |
15 | 18 |
16 #define PACK_FILTER_X_NAME MAKENAME(_pack_filter_x) | 19 #define PACK_FILTER_X_NAME MAKENAME(_pack_filter_x) |
17 #define PACK_FILTER_Y_NAME MAKENAME(_pack_filter_y) | 20 #define PACK_FILTER_Y_NAME MAKENAME(_pack_filter_y) |
18 | 21 |
19 #ifndef PREAMBLE | 22 #ifndef PREAMBLE |
20 #define PREAMBLE(state) | 23 #define PREAMBLE(state) |
21 #define PREAMBLE_PARAM_X | 24 #define PREAMBLE_PARAM_X |
22 #define PREAMBLE_PARAM_Y | 25 #define PREAMBLE_PARAM_Y |
23 #define PREAMBLE_ARG_X | 26 #define PREAMBLE_ARG_X |
24 #define PREAMBLE_ARG_Y | 27 #define PREAMBLE_ARG_Y |
25 #endif | 28 #endif |
26 | 29 |
27 // declare functions externally to suppress warnings. | 30 // declare functions externally to suppress warnings. |
| 31 void SCALE_NOFILTER_NAME(const SkBitmapProcState& s, |
| 32 uint32_t xy[], int count, int x, int y); |
| 33 void AFFINE_NOFILTER_NAME(const SkBitmapProcState& s, |
| 34 uint32_t xy[], int count, int x, int y); |
| 35 void PERSP_NOFILTER_NAME(const SkBitmapProcState& s, |
| 36 uint32_t* SK_RESTRICT xy, |
| 37 int count, int x, int y); |
28 void SCALE_FILTER_NAME(const SkBitmapProcState& s, | 38 void SCALE_FILTER_NAME(const SkBitmapProcState& s, |
29 uint32_t xy[], int count, int x, int y); | 39 uint32_t xy[], int count, int x, int y); |
30 void AFFINE_FILTER_NAME(const SkBitmapProcState& s, | 40 void AFFINE_FILTER_NAME(const SkBitmapProcState& s, |
31 uint32_t xy[], int count, int x, int y); | 41 uint32_t xy[], int count, int x, int y); |
32 void PERSP_FILTER_NAME(const SkBitmapProcState& s, | 42 void PERSP_FILTER_NAME(const SkBitmapProcState& s, |
33 uint32_t* SK_RESTRICT xy, int count, | 43 uint32_t* SK_RESTRICT xy, int count, |
34 int x, int y); | 44 int x, int y); |
35 | 45 |
| 46 void SCALE_NOFILTER_NAME(const SkBitmapProcState& s, |
| 47 uint32_t xy[], int count, int x, int y) { |
| 48 SkASSERT((s.fInvType & ~(SkMatrix::kTranslate_Mask | |
| 49 SkMatrix::kScale_Mask)) == 0); |
| 50 |
| 51 PREAMBLE(s); |
| 52 // we store y, x, x, x, x, x |
| 53 |
| 54 const unsigned maxX = s.fBitmap->width() - 1; |
| 55 SkFractionalInt fx; |
| 56 { |
| 57 SkPoint pt; |
| 58 s.fInvProc(s.fInvMatrix, SkIntToScalar(x) + SK_ScalarHalf, |
| 59 SkIntToScalar(y) + SK_ScalarHalf, &pt); |
| 60 fx = SkScalarToFractionalInt(pt.fY); |
| 61 const unsigned maxY = s.fBitmap->height() - 1; |
| 62 *xy++ = TILEY_PROCF(SkFractionalIntToFixed(fx), maxY); |
| 63 fx = SkScalarToFractionalInt(pt.fX); |
| 64 } |
| 65 |
| 66 if (0 == maxX) { |
| 67 // all of the following X values must be 0 |
| 68 memset(xy, 0, count * sizeof(uint16_t)); |
| 69 return; |
| 70 } |
| 71 |
| 72 const SkFractionalInt dx = s.fInvSxFractionalInt; |
| 73 |
| 74 #ifdef CHECK_FOR_DECAL |
| 75 if (can_truncate_to_fixed_for_decal(fx, dx, count, maxX)) { |
| 76 decal_nofilter_scale(xy, SkFractionalIntToFixed(fx), |
| 77 SkFractionalIntToFixed(dx), count); |
| 78 } else |
| 79 #endif |
| 80 { |
| 81 int i; |
| 82 for (i = (count >> 2); i > 0; --i) { |
| 83 unsigned a, b; |
| 84 a = TILEX_PROCF(SkFractionalIntToFixed(fx), maxX); fx += dx; |
| 85 b = TILEX_PROCF(SkFractionalIntToFixed(fx), maxX); fx += dx; |
| 86 #ifdef SK_CPU_BENDIAN |
| 87 *xy++ = (a << 16) | b; |
| 88 #else |
| 89 *xy++ = (b << 16) | a; |
| 90 #endif |
| 91 a = TILEX_PROCF(SkFractionalIntToFixed(fx), maxX); fx += dx; |
| 92 b = TILEX_PROCF(SkFractionalIntToFixed(fx), maxX); fx += dx; |
| 93 #ifdef SK_CPU_BENDIAN |
| 94 *xy++ = (a << 16) | b; |
| 95 #else |
| 96 *xy++ = (b << 16) | a; |
| 97 #endif |
| 98 } |
| 99 uint16_t* xx = (uint16_t*)xy; |
| 100 for (i = (count & 3); i > 0; --i) { |
| 101 *xx++ = TILEX_PROCF(SkFractionalIntToFixed(fx), maxX); fx += dx; |
| 102 } |
| 103 } |
| 104 } |
| 105 |
| 106 // note: we could special-case on a matrix which is skewed in X but not Y. |
| 107 // this would require a more general setup thatn SCALE does, but could use |
| 108 // SCALE's inner loop that only looks at dx |
| 109 |
| 110 void AFFINE_NOFILTER_NAME(const SkBitmapProcState& s, |
| 111 uint32_t xy[], int count, int x, int y) { |
| 112 SkASSERT(s.fInvType & SkMatrix::kAffine_Mask); |
| 113 SkASSERT((s.fInvType & ~(SkMatrix::kTranslate_Mask | |
| 114 SkMatrix::kScale_Mask | |
| 115 SkMatrix::kAffine_Mask)) == 0); |
| 116 |
| 117 PREAMBLE(s); |
| 118 SkPoint srcPt; |
| 119 s.fInvProc(s.fInvMatrix, |
| 120 SkIntToScalar(x) + SK_ScalarHalf, |
| 121 SkIntToScalar(y) + SK_ScalarHalf, &srcPt); |
| 122 |
| 123 SkFractionalInt fx = SkScalarToFractionalInt(srcPt.fX); |
| 124 SkFractionalInt fy = SkScalarToFractionalInt(srcPt.fY); |
| 125 SkFractionalInt dx = s.fInvSxFractionalInt; |
| 126 SkFractionalInt dy = s.fInvKyFractionalInt; |
| 127 int maxX = s.fBitmap->width() - 1; |
| 128 int maxY = s.fBitmap->height() - 1; |
| 129 |
| 130 for (int i = count; i > 0; --i) { |
| 131 *xy++ = (TILEY_PROCF(SkFractionalIntToFixed(fy), maxY) << 16) | |
| 132 TILEX_PROCF(SkFractionalIntToFixed(fx), maxX); |
| 133 fx += dx; fy += dy; |
| 134 } |
| 135 } |
| 136 |
| 137 void PERSP_NOFILTER_NAME(const SkBitmapProcState& s, |
| 138 uint32_t* SK_RESTRICT xy, |
| 139 int count, int x, int y) { |
| 140 SkASSERT(s.fInvType & SkMatrix::kPerspective_Mask); |
| 141 |
| 142 PREAMBLE(s); |
| 143 int maxX = s.fBitmap->width() - 1; |
| 144 int maxY = s.fBitmap->height() - 1; |
| 145 |
| 146 SkPerspIter iter(s.fInvMatrix, |
| 147 SkIntToScalar(x) + SK_ScalarHalf, |
| 148 SkIntToScalar(y) + SK_ScalarHalf, count); |
| 149 |
| 150 while ((count = iter.next()) != 0) { |
| 151 const SkFixed* SK_RESTRICT srcXY = iter.getXY(); |
| 152 while (--count >= 0) { |
| 153 *xy++ = (TILEY_PROCF(srcXY[1], maxY) << 16) | |
| 154 TILEX_PROCF(srcXY[0], maxX); |
| 155 srcXY += 2; |
| 156 } |
| 157 } |
| 158 } |
| 159 |
| 160 ////////////////////////////////////////////////////////////////////////////// |
| 161 |
36 static inline uint32_t PACK_FILTER_Y_NAME(SkFixed f, unsigned max, | 162 static inline uint32_t PACK_FILTER_Y_NAME(SkFixed f, unsigned max, |
37 SkFixed one PREAMBLE_PARAM_Y) { | 163 SkFixed one PREAMBLE_PARAM_Y) { |
38 unsigned i = TILEY_PROCF(f, max); | 164 unsigned i = TILEY_PROCF(f, max); |
39 i = (i << 4) | TILEY_LOW_BITS(f, max); | 165 i = (i << 4) | TILEY_LOW_BITS(f, max); |
40 return (i << 14) | (TILEY_PROCF((f + one), max)); | 166 return (i << 14) | (TILEY_PROCF((f + one), max)); |
41 } | 167 } |
42 | 168 |
43 static inline uint32_t PACK_FILTER_X_NAME(SkFixed f, unsigned max, | 169 static inline uint32_t PACK_FILTER_X_NAME(SkFixed f, unsigned max, |
44 SkFixed one PREAMBLE_PARAM_X) { | 170 SkFixed one PREAMBLE_PARAM_X) { |
45 unsigned i = TILEX_PROCF(f, max); | 171 unsigned i = TILEX_PROCF(f, max); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 do { | 263 do { |
138 *xy++ = PACK_FILTER_Y_NAME(srcXY[1] - (oneY >> 1), maxY, | 264 *xy++ = PACK_FILTER_Y_NAME(srcXY[1] - (oneY >> 1), maxY, |
139 oneY PREAMBLE_ARG_Y); | 265 oneY PREAMBLE_ARG_Y); |
140 *xy++ = PACK_FILTER_X_NAME(srcXY[0] - (oneX >> 1), maxX, | 266 *xy++ = PACK_FILTER_X_NAME(srcXY[0] - (oneX >> 1), maxX, |
141 oneX PREAMBLE_ARG_X); | 267 oneX PREAMBLE_ARG_X); |
142 srcXY += 2; | 268 srcXY += 2; |
143 } while (--count != 0); | 269 } while (--count != 0); |
144 } | 270 } |
145 } | 271 } |
146 | 272 |
| 273 static SkBitmapProcState::MatrixProc MAKENAME(_Procs)[] = { |
| 274 SCALE_NOFILTER_NAME, |
| 275 SCALE_FILTER_NAME, |
| 276 AFFINE_NOFILTER_NAME, |
| 277 AFFINE_FILTER_NAME, |
| 278 PERSP_NOFILTER_NAME, |
| 279 PERSP_FILTER_NAME |
| 280 }; |
| 281 |
147 #undef MAKENAME | 282 #undef MAKENAME |
148 #undef TILEX_PROCF | 283 #undef TILEX_PROCF |
149 #undef TILEY_PROCF | 284 #undef TILEY_PROCF |
150 #ifdef CHECK_FOR_DECAL | 285 #ifdef CHECK_FOR_DECAL |
151 #undef CHECK_FOR_DECAL | 286 #undef CHECK_FOR_DECAL |
152 #endif | 287 #endif |
153 | 288 |
| 289 #undef SCALE_NOFILTER_NAME |
154 #undef SCALE_FILTER_NAME | 290 #undef SCALE_FILTER_NAME |
| 291 #undef AFFINE_NOFILTER_NAME |
155 #undef AFFINE_FILTER_NAME | 292 #undef AFFINE_FILTER_NAME |
| 293 #undef PERSP_NOFILTER_NAME |
156 #undef PERSP_FILTER_NAME | 294 #undef PERSP_FILTER_NAME |
157 | 295 |
158 #undef PREAMBLE | 296 #undef PREAMBLE |
159 #undef PREAMBLE_PARAM_X | 297 #undef PREAMBLE_PARAM_X |
160 #undef PREAMBLE_PARAM_Y | 298 #undef PREAMBLE_PARAM_Y |
161 #undef PREAMBLE_ARG_X | 299 #undef PREAMBLE_ARG_X |
162 #undef PREAMBLE_ARG_Y | 300 #undef PREAMBLE_ARG_Y |
163 | 301 |
164 #undef TILEX_LOW_BITS | 302 #undef TILEX_LOW_BITS |
165 #undef TILEY_LOW_BITS | 303 #undef TILEY_LOW_BITS |
OLD | NEW |