gfx/skia/trunk/src/core/SkBitmapProcState_shaderproc.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright 2011 Google Inc.
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8
michael@0 9 #include "SkMathPriv.h"
michael@0 10
michael@0 11 #define SCALE_FILTER_NAME MAKENAME(_filter_DX_shaderproc)
michael@0 12
michael@0 13 // Can't be static in the general case because some of these implementations
michael@0 14 // will be defined and referenced in different object files.
michael@0 15 void SCALE_FILTER_NAME(const SkBitmapProcState& s, int x, int y,
michael@0 16 DSTTYPE* SK_RESTRICT colors, int count);
michael@0 17
michael@0 18 void SCALE_FILTER_NAME(const SkBitmapProcState& s, int x, int y,
michael@0 19 DSTTYPE* SK_RESTRICT colors, int count) {
michael@0 20 SkASSERT((s.fInvType & ~(SkMatrix::kTranslate_Mask |
michael@0 21 SkMatrix::kScale_Mask)) == 0);
michael@0 22 SkASSERT(s.fInvKy == 0);
michael@0 23 SkASSERT(count > 0 && colors != NULL);
michael@0 24 SkASSERT(s.fFilterLevel != SkPaint::kNone_FilterLevel);
michael@0 25 SkDEBUGCODE(CHECKSTATE(s);)
michael@0 26
michael@0 27 const unsigned maxX = s.fBitmap->width() - 1;
michael@0 28 const SkFixed oneX = s.fFilterOneX;
michael@0 29 const SkFixed dx = s.fInvSx;
michael@0 30 SkFixed fx;
michael@0 31 const SRCTYPE* SK_RESTRICT row0;
michael@0 32 const SRCTYPE* SK_RESTRICT row1;
michael@0 33 unsigned subY;
michael@0 34
michael@0 35 {
michael@0 36 SkPoint pt;
michael@0 37 s.fInvProc(s.fInvMatrix, SkIntToScalar(x) + SK_ScalarHalf,
michael@0 38 SkIntToScalar(y) + SK_ScalarHalf, &pt);
michael@0 39 SkFixed fy = SkScalarToFixed(pt.fY) - (s.fFilterOneY >> 1);
michael@0 40 const unsigned maxY = s.fBitmap->height() - 1;
michael@0 41 // compute our two Y values up front
michael@0 42 subY = TILEY_LOW_BITS(fy, maxY);
michael@0 43 int y0 = TILEY_PROCF(fy, maxY);
michael@0 44 int y1 = TILEY_PROCF((fy + s.fFilterOneY), maxY);
michael@0 45
michael@0 46 const char* SK_RESTRICT srcAddr = (const char*)s.fBitmap->getPixels();
michael@0 47 size_t rb = s.fBitmap->rowBytes();
michael@0 48 row0 = (const SRCTYPE*)(srcAddr + y0 * rb);
michael@0 49 row1 = (const SRCTYPE*)(srcAddr + y1 * rb);
michael@0 50 // now initialize fx
michael@0 51 fx = SkScalarToFixed(pt.fX) - (oneX >> 1);
michael@0 52 }
michael@0 53
michael@0 54 #ifdef PREAMBLE
michael@0 55 PREAMBLE(s);
michael@0 56 #endif
michael@0 57
michael@0 58 do {
michael@0 59 unsigned subX = TILEX_LOW_BITS(fx, maxX);
michael@0 60 unsigned x0 = TILEX_PROCF(fx, maxX);
michael@0 61 unsigned x1 = TILEX_PROCF((fx + oneX), maxX);
michael@0 62
michael@0 63 FILTER_PROC(subX, subY,
michael@0 64 SRC_TO_FILTER(row0[x0]),
michael@0 65 SRC_TO_FILTER(row0[x1]),
michael@0 66 SRC_TO_FILTER(row1[x0]),
michael@0 67 SRC_TO_FILTER(row1[x1]),
michael@0 68 colors);
michael@0 69 colors += 1;
michael@0 70
michael@0 71 fx += dx;
michael@0 72 } while (--count != 0);
michael@0 73
michael@0 74 #ifdef POSTAMBLE
michael@0 75 POSTAMBLE(s);
michael@0 76 #endif
michael@0 77 }
michael@0 78
michael@0 79 ///////////////////////////////////////////////////////////////////////////////
michael@0 80
michael@0 81 #undef TILEX_PROCF
michael@0 82 #undef TILEY_PROCF
michael@0 83 #undef TILEX_LOW_BITS
michael@0 84 #undef TILEY_LOW_BITS
michael@0 85 #undef MAKENAME
michael@0 86 #undef SRCTYPE
michael@0 87 #undef DSTTYPE
michael@0 88 #undef CHECKSTATE
michael@0 89 #undef SRC_TO_FILTER
michael@0 90 #undef FILTER_TO_DST
michael@0 91 #undef PREAMBLE
michael@0 92 #undef POSTAMBLE
michael@0 93
michael@0 94 #undef SCALE_FILTER_NAME

mercurial