michael@0: michael@0: /* michael@0: * Copyright 2006 The Android Open Source Project 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: michael@0: #include "SkBitmap.h" michael@0: #include "SkMask.h" michael@0: michael@0: #ifndef ClearLow3Bits_DEFINED michael@0: #define ClearLow3Bits_DEFINED michael@0: #define ClearLow3Bits(x) ((unsigned)(x) >> 3 << 3) michael@0: #endif michael@0: michael@0: /* michael@0: SK_BLITBWMASK_NAME name of function(const SkBitmap& bitmap, const SkMask& mask, const SkIRect& clip, SK_BLITBWMASK_ARGS) michael@0: SK_BLITBWMASK_ARGS list of additional arguments to SK_BLITBWMASK_NAME, beginning with a comma michael@0: SK_BLITBWMASK_BLIT8 name of function(U8CPU byteMask, SK_BLITBWMASK_DEVTYPE* dst, int x, int y) michael@0: SK_BLITBWMASK_GETADDR either getAddr32 or getAddr16 or getAddr8 michael@0: SK_BLITBWMASK_DEVTYPE either U32 or U16 or U8 michael@0: */ michael@0: michael@0: static void SK_BLITBWMASK_NAME(const SkBitmap& bitmap, const SkMask& srcMask, const SkIRect& clip SK_BLITBWMASK_ARGS) michael@0: { michael@0: SkASSERT(clip.fRight <= srcMask.fBounds.fRight); michael@0: michael@0: int cx = clip.fLeft; michael@0: int cy = clip.fTop; michael@0: int maskLeft = srcMask.fBounds.fLeft; michael@0: unsigned mask_rowBytes = srcMask.fRowBytes; michael@0: size_t bitmap_rowBytes = bitmap.rowBytes(); michael@0: unsigned height = clip.height(); michael@0: michael@0: SkASSERT(mask_rowBytes != 0); michael@0: SkASSERT(bitmap_rowBytes != 0); michael@0: SkASSERT(height != 0); michael@0: michael@0: const uint8_t* bits = srcMask.getAddr1(cx, cy); michael@0: SK_BLITBWMASK_DEVTYPE* device = bitmap.SK_BLITBWMASK_GETADDR(cx, cy); michael@0: michael@0: if (cx == maskLeft && clip.fRight == srcMask.fBounds.fRight) michael@0: { michael@0: do { michael@0: SK_BLITBWMASK_DEVTYPE* dst = device; michael@0: unsigned rb = mask_rowBytes; michael@0: do { michael@0: U8CPU mask = *bits++; michael@0: SK_BLITBWMASK_BLIT8(mask, dst); michael@0: dst += 8; michael@0: } while (--rb != 0); michael@0: device = (SK_BLITBWMASK_DEVTYPE*)((char*)device + bitmap_rowBytes); michael@0: } while (--height != 0); michael@0: } michael@0: else michael@0: { michael@0: int left_edge = cx - maskLeft; michael@0: SkASSERT(left_edge >= 0); michael@0: int rite_edge = clip.fRight - maskLeft; michael@0: SkASSERT(rite_edge > left_edge); michael@0: michael@0: int left_mask = 0xFF >> (left_edge & 7); michael@0: int rite_mask = 0xFF << (8 - (rite_edge & 7)); michael@0: rite_mask &= 0xFF; // only want low-8 bits of mask michael@0: int full_runs = (rite_edge >> 3) - ((left_edge + 7) >> 3); michael@0: michael@0: // check for empty right mask, so we don't read off the end (or go slower than we need to) michael@0: if (rite_mask == 0) michael@0: { michael@0: SkASSERT(full_runs >= 0); michael@0: full_runs -= 1; michael@0: rite_mask = 0xFF; michael@0: } michael@0: if (left_mask == 0xFF) michael@0: full_runs -= 1; michael@0: michael@0: // back up manually so we can keep in sync with our byte-aligned src michael@0: // and not trigger an assert from the getAddr## function michael@0: device -= left_edge & 7; michael@0: michael@0: if (full_runs < 0) michael@0: { michael@0: left_mask &= rite_mask; michael@0: SkASSERT(left_mask != 0); michael@0: do { michael@0: U8CPU mask = *bits & left_mask; michael@0: SK_BLITBWMASK_BLIT8(mask, device); michael@0: bits += mask_rowBytes; michael@0: device = (SK_BLITBWMASK_DEVTYPE*)((char*)device + bitmap_rowBytes); michael@0: } while (--height != 0); michael@0: } michael@0: else michael@0: { michael@0: do { michael@0: int runs = full_runs; michael@0: SK_BLITBWMASK_DEVTYPE* dst = device; michael@0: const uint8_t* b = bits; michael@0: U8CPU mask; michael@0: michael@0: mask = *b++ & left_mask; michael@0: SK_BLITBWMASK_BLIT8(mask, dst); michael@0: dst += 8; michael@0: michael@0: while (--runs >= 0) michael@0: { michael@0: mask = *b++; michael@0: SK_BLITBWMASK_BLIT8(mask, dst); michael@0: dst += 8; michael@0: } michael@0: michael@0: mask = *b & rite_mask; michael@0: SK_BLITBWMASK_BLIT8(mask, dst); michael@0: michael@0: bits += mask_rowBytes; michael@0: device = (SK_BLITBWMASK_DEVTYPE*)((char*)device + bitmap_rowBytes); michael@0: } while (--height != 0); michael@0: } michael@0: } michael@0: } michael@0: michael@0: #undef SK_BLITBWMASK_NAME michael@0: #undef SK_BLITBWMASK_ARGS michael@0: #undef SK_BLITBWMASK_BLIT8 michael@0: #undef SK_BLITBWMASK_GETADDR michael@0: #undef SK_BLITBWMASK_DEVTYPE michael@0: #undef SK_BLITBWMASK_DOROWSETUP