michael@0: michael@0: /* michael@0: * Copyright 2011 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #include "SkMathPriv.h" michael@0: michael@0: #define SCALE_FILTER_NAME MAKENAME(_filter_DX_shaderproc) michael@0: michael@0: // Can't be static in the general case because some of these implementations michael@0: // will be defined and referenced in different object files. michael@0: void SCALE_FILTER_NAME(const SkBitmapProcState& s, int x, int y, michael@0: DSTTYPE* SK_RESTRICT colors, int count); michael@0: michael@0: void SCALE_FILTER_NAME(const SkBitmapProcState& s, int x, int y, michael@0: DSTTYPE* SK_RESTRICT colors, int count) { michael@0: SkASSERT((s.fInvType & ~(SkMatrix::kTranslate_Mask | michael@0: SkMatrix::kScale_Mask)) == 0); michael@0: SkASSERT(s.fInvKy == 0); michael@0: SkASSERT(count > 0 && colors != NULL); michael@0: SkASSERT(s.fFilterLevel != SkPaint::kNone_FilterLevel); michael@0: SkDEBUGCODE(CHECKSTATE(s);) michael@0: michael@0: const unsigned maxX = s.fBitmap->width() - 1; michael@0: const SkFixed oneX = s.fFilterOneX; michael@0: const SkFixed dx = s.fInvSx; michael@0: SkFixed fx; michael@0: const SRCTYPE* SK_RESTRICT row0; michael@0: const SRCTYPE* SK_RESTRICT row1; michael@0: unsigned subY; michael@0: michael@0: { michael@0: SkPoint pt; michael@0: s.fInvProc(s.fInvMatrix, SkIntToScalar(x) + SK_ScalarHalf, michael@0: SkIntToScalar(y) + SK_ScalarHalf, &pt); michael@0: SkFixed fy = SkScalarToFixed(pt.fY) - (s.fFilterOneY >> 1); michael@0: const unsigned maxY = s.fBitmap->height() - 1; michael@0: // compute our two Y values up front michael@0: subY = TILEY_LOW_BITS(fy, maxY); michael@0: int y0 = TILEY_PROCF(fy, maxY); michael@0: int y1 = TILEY_PROCF((fy + s.fFilterOneY), maxY); michael@0: michael@0: const char* SK_RESTRICT srcAddr = (const char*)s.fBitmap->getPixels(); michael@0: size_t rb = s.fBitmap->rowBytes(); michael@0: row0 = (const SRCTYPE*)(srcAddr + y0 * rb); michael@0: row1 = (const SRCTYPE*)(srcAddr + y1 * rb); michael@0: // now initialize fx michael@0: fx = SkScalarToFixed(pt.fX) - (oneX >> 1); michael@0: } michael@0: michael@0: #ifdef PREAMBLE michael@0: PREAMBLE(s); michael@0: #endif michael@0: michael@0: do { michael@0: unsigned subX = TILEX_LOW_BITS(fx, maxX); michael@0: unsigned x0 = TILEX_PROCF(fx, maxX); michael@0: unsigned x1 = TILEX_PROCF((fx + oneX), maxX); michael@0: michael@0: FILTER_PROC(subX, subY, michael@0: SRC_TO_FILTER(row0[x0]), michael@0: SRC_TO_FILTER(row0[x1]), michael@0: SRC_TO_FILTER(row1[x0]), michael@0: SRC_TO_FILTER(row1[x1]), michael@0: colors); michael@0: colors += 1; michael@0: michael@0: fx += dx; michael@0: } while (--count != 0); michael@0: michael@0: #ifdef POSTAMBLE michael@0: POSTAMBLE(s); michael@0: #endif michael@0: } michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: #undef TILEX_PROCF michael@0: #undef TILEY_PROCF michael@0: #undef TILEX_LOW_BITS michael@0: #undef TILEY_LOW_BITS michael@0: #undef MAKENAME michael@0: #undef SRCTYPE michael@0: #undef DSTTYPE michael@0: #undef CHECKSTATE michael@0: #undef SRC_TO_FILTER michael@0: #undef FILTER_TO_DST michael@0: #undef PREAMBLE michael@0: #undef POSTAMBLE michael@0: michael@0: #undef SCALE_FILTER_NAME