1 2 /* 3 * Copyright 2006 The Android Open Source Project 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9 10 #include "SkCoreBlitters.h" 11 12 SkA1_Blitter::SkA1_Blitter(const SkBitmap& device, const SkPaint& paint) 13 : INHERITED(device) { 14 fSrcA = paint.getAlpha(); 15 } 16 17 void SkA1_Blitter::blitH(int x, int y, int width) { 18 SkASSERT(x >= 0 && y >= 0 && 19 (unsigned)(x + width) <= (unsigned)fDevice.width()); 20 21 if (fSrcA <= 0x7F) { 22 return; 23 } 24 uint8_t* dst = fDevice.getAddr1(x, y); 25 int right = x + width; 26 27 int left_mask = 0xFF >> (x & 7); 28 int rite_mask = 0xFF << (8 - (right & 7)); 29 int full_runs = (right >> 3) - ((x + 7) >> 3); 30 31 // check for empty right mask, so we don't read off the end 32 // (or go slower than we need to) 33 if (rite_mask == 0) { 34 SkASSERT(full_runs >= 0); 35 full_runs -= 1; 36 rite_mask = 0xFF; 37 } 38 if (left_mask == 0xFF) { 39 full_runs -= 1; 40 } 41 if (full_runs < 0) { 42 SkASSERT((left_mask & rite_mask) != 0); 43 *dst |= (left_mask & rite_mask); 44 } else { 45 *dst++ |= left_mask; 46 memset(dst, 0xFF, full_runs); 47 dst += full_runs; 48 *dst |= rite_mask; 49 } 50 } 51 52