180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/*
380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2011 Google Inc.
480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be
680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file.
780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkMathPriv.h"
1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SCALE_FILTER_NAME       MAKENAME(_filter_DX_shaderproc)
1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// Can't be static in the general case because some of these implementations
1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// will be defined and referenced in different object files.
1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SCALE_FILTER_NAME(const SkBitmapProcState& s, int x, int y,
1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                       DSTTYPE* SK_RESTRICT colors, int count);
1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SCALE_FILTER_NAME(const SkBitmapProcState& s, int x, int y,
1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                       DSTTYPE* SK_RESTRICT colors, int count) {
2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkASSERT((s.fInvType & ~(SkMatrix::kTranslate_Mask |
2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                             SkMatrix::kScale_Mask)) == 0);
2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkASSERT(s.fInvKy == 0);
2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkASSERT(count > 0 && colors != NULL);
2458190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger    SkASSERT(s.fFilterLevel != SkPaint::kNone_FilterLevel);
2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkDEBUGCODE(CHECKSTATE(s);)
2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    const unsigned maxX = s.fBitmap->width() - 1;
2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    const SkFixed oneX = s.fFilterOneX;
2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    const SkFixed dx = s.fInvSx;
3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkFixed fx;
3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    const SRCTYPE* SK_RESTRICT row0;
3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    const SRCTYPE* SK_RESTRICT row1;
3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    unsigned subY;
3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    {
3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        SkPoint pt;
3758190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger        s.fInvProc(s.fInvMatrix, SkIntToScalar(x) + SK_ScalarHalf,
3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                   SkIntToScalar(y) + SK_ScalarHalf, &pt);
3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        SkFixed fy = SkScalarToFixed(pt.fY) - (s.fFilterOneY >> 1);
4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        const unsigned maxY = s.fBitmap->height() - 1;
4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        // compute our two Y values up front
4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        subY = TILEY_LOW_BITS(fy, maxY);
4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        int y0 = TILEY_PROCF(fy, maxY);
4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        int y1 = TILEY_PROCF((fy + s.fFilterOneY), maxY);
4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        const char* SK_RESTRICT srcAddr = (const char*)s.fBitmap->getPixels();
47096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger        size_t rb = s.fBitmap->rowBytes();
4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        row0 = (const SRCTYPE*)(srcAddr + y0 * rb);
4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        row1 = (const SRCTYPE*)(srcAddr + y1 * rb);
5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        // now initialize fx
5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fx = SkScalarToFixed(pt.fX) - (oneX >> 1);
5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifdef PREAMBLE
5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    PREAMBLE(s);
5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif
5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    do {
5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        unsigned subX = TILEX_LOW_BITS(fx, maxX);
6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        unsigned x0 = TILEX_PROCF(fx, maxX);
6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        unsigned x1 = TILEX_PROCF((fx + oneX), maxX);
6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        FILTER_PROC(subX, subY,
6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                    SRC_TO_FILTER(row0[x0]),
6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                    SRC_TO_FILTER(row0[x1]),
6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                    SRC_TO_FILTER(row1[x0]),
6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                    SRC_TO_FILTER(row1[x1]),
6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                    colors);
6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        colors += 1;
7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fx += dx;
7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    } while (--count != 0);
7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifdef POSTAMBLE
7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    POSTAMBLE(s);
7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif
7780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
7880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
7980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru///////////////////////////////////////////////////////////////////////////////
8080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
8180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#undef TILEX_PROCF
8280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#undef TILEY_PROCF
8380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#undef TILEX_LOW_BITS
8480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#undef TILEY_LOW_BITS
8580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#undef MAKENAME
8680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#undef SRCTYPE
8780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#undef DSTTYPE
8880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#undef CHECKSTATE
8980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#undef SRC_TO_FILTER
9080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#undef FILTER_TO_DST
9180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#undef PREAMBLE
9280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#undef POSTAMBLE
9380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
9480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#undef SCALE_FILTER_NAME
95