blob: 3d22da4bafb6d571dd10c188a2493d8562d04545 [file] [log] [blame]
reed@google.com69d05552011-05-24 12:14:28 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@google.com69d05552011-05-24 12:14:28 +00006 */
7
tomhudson@google.com889bd8b2011-09-27 17:38:17 +00008#include "SkMath.h"
reed@google.com4b163ed2012-08-07 21:35:13 +00009#include "SkMathPriv.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000010
reed@android.com8a1c16f2008-12-17 15:59:43 +000011#define SCALE_FILTER_NAME MAKENAME(_filter_scale)
reed@android.com8a1c16f2008-12-17 15:59:43 +000012
13#define PACK_FILTER_X_NAME MAKENAME(_pack_filter_x)
14#define PACK_FILTER_Y_NAME MAKENAME(_pack_filter_y)
15
16#ifndef PREAMBLE
17 #define PREAMBLE(state)
18 #define PREAMBLE_PARAM_X
19 #define PREAMBLE_PARAM_Y
20 #define PREAMBLE_ARG_X
21 #define PREAMBLE_ARG_Y
22#endif
23
caryclark@google.com803eceb2012-06-06 12:09:34 +000024// declare functions externally to suppress warnings.
caryclark@google.com803eceb2012-06-06 12:09:34 +000025void SCALE_FILTER_NAME(const SkBitmapProcState& s,
26 uint32_t xy[], int count, int x, int y);
caryclark@google.com803eceb2012-06-06 12:09:34 +000027
reed@android.com8a1c16f2008-12-17 15:59:43 +000028static inline uint32_t PACK_FILTER_Y_NAME(SkFixed f, unsigned max,
29 SkFixed one PREAMBLE_PARAM_Y) {
30 unsigned i = TILEY_PROCF(f, max);
Florin Malitad1c550e2016-12-19 10:55:41 -050031 i = (i << 4) | EXTRACT_LOW_BITS(f, max);
reed@android.com8a1c16f2008-12-17 15:59:43 +000032 return (i << 14) | (TILEY_PROCF((f + one), max));
33}
34
35static inline uint32_t PACK_FILTER_X_NAME(SkFixed f, unsigned max,
36 SkFixed one PREAMBLE_PARAM_X) {
37 unsigned i = TILEX_PROCF(f, max);
Florin Malitad1c550e2016-12-19 10:55:41 -050038 i = (i << 4) | EXTRACT_LOW_BITS(f, max);
reed@android.com8a1c16f2008-12-17 15:59:43 +000039 return (i << 14) | (TILEX_PROCF((f + one), max));
40}
41
senorblanco@chromium.orgdc7de742009-11-30 20:00:29 +000042void SCALE_FILTER_NAME(const SkBitmapProcState& s,
reed@android.com8a1c16f2008-12-17 15:59:43 +000043 uint32_t xy[], int count, int x, int y) {
44 SkASSERT((s.fInvType & ~(SkMatrix::kTranslate_Mask |
45 SkMatrix::kScale_Mask)) == 0);
46 SkASSERT(s.fInvKy == 0);
47
48 PREAMBLE(s);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000049
reedad7ae6c2015-06-04 14:12:25 -070050 const unsigned maxX = s.fPixmap.width() - 1;
reed@android.com8a1c16f2008-12-17 15:59:43 +000051 const SkFixed one = s.fFilterOneX;
reed@google.com411215a2012-03-08 20:13:46 +000052 const SkFractionalInt dx = s.fInvSxFractionalInt;
53 SkFractionalInt fx;
reed@android.com8a1c16f2008-12-17 15:59:43 +000054
55 {
fmalita2404f032016-02-03 05:44:21 -080056 const SkBitmapProcStateAutoMapper mapper(s, x, y);
fmalitabe5cfa92016-02-03 10:21:33 -080057 const SkFixed fy = mapper.fixedY();
reedad7ae6c2015-06-04 14:12:25 -070058 const unsigned maxY = s.fPixmap.height() - 1;
reed@android.com8a1c16f2008-12-17 15:59:43 +000059 // compute our two Y values up front
60 *xy++ = PACK_FILTER_Y_NAME(fy, maxY, s.fFilterOneY PREAMBLE_ARG_Y);
61 // now initialize fx
fmalitabe5cfa92016-02-03 10:21:33 -080062 fx = mapper.fractionalIntX();
reed@android.com8a1c16f2008-12-17 15:59:43 +000063 }
64
65#ifdef CHECK_FOR_DECAL
Florin Malita99537372017-01-04 13:01:55 -050066 const SkFixed fixedFx = SkFractionalIntToFixed(fx);
67 const SkFixed fixedDx = SkFractionalIntToFixed(dx);
68 if (can_truncate_to_fixed_for_decal(fixedFx, fixedDx, count, maxX)) {
69 decal_filter_scale(xy, fixedFx, fixedDx, count);
reed@android.com8a1c16f2008-12-17 15:59:43 +000070 } else
71#endif
72 {
73 do {
reed@google.com411215a2012-03-08 20:13:46 +000074 SkFixed fixedFx = SkFractionalIntToFixed(fx);
75 *xy++ = PACK_FILTER_X_NAME(fixedFx, maxX, one PREAMBLE_ARG_X);
reed@android.com8a1c16f2008-12-17 15:59:43 +000076 fx += dx;
77 } while (--count != 0);
78 }
79}
80
reed@android.com8a1c16f2008-12-17 15:59:43 +000081#undef MAKENAME
82#undef TILEX_PROCF
83#undef TILEY_PROCF
84#ifdef CHECK_FOR_DECAL
85 #undef CHECK_FOR_DECAL
86#endif
87
reed@android.com8a1c16f2008-12-17 15:59:43 +000088#undef SCALE_FILTER_NAME
reed@android.com8a1c16f2008-12-17 15:59:43 +000089
90#undef PREAMBLE
91#undef PREAMBLE_PARAM_X
92#undef PREAMBLE_PARAM_Y
93#undef PREAMBLE_ARG_X
94#undef PREAMBLE_ARG_Y
95
Florin Malitad1c550e2016-12-19 10:55:41 -050096#undef EXTRACT_LOW_BITS