Line data Source code
1 : /*
2 : * Copyright 2006 The Android Open Source Project
3 : *
4 : * Use of this source code is governed by a BSD-style license that can be
5 : * found in the LICENSE file.
6 : */
7 :
8 :
9 : #include "SkBitmap.h"
10 : #include "SkMask.h"
11 :
12 : #ifndef ClearLow3Bits_DEFINED
13 : #define ClearLow3Bits_DEFINED
14 : #define ClearLow3Bits(x) ((unsigned)(x) >> 3 << 3)
15 : #endif
16 :
17 : /*
18 : SK_BLITBWMASK_NAME name of function(const SkBitmap& bitmap, const SkMask& mask, const SkIRect& clip, SK_BLITBWMASK_ARGS)
19 : SK_BLITBWMASK_ARGS list of additional arguments to SK_BLITBWMASK_NAME, beginning with a comma
20 : SK_BLITBWMASK_BLIT8 name of function(U8CPU byteMask, SK_BLITBWMASK_DEVTYPE* dst, int x, int y)
21 : SK_BLITBWMASK_GETADDR either writable_addr[8,16,32]
22 : SK_BLITBWMASK_DEVTYPE either U32 or U16 or U8
23 : */
24 :
25 0 : static void SK_BLITBWMASK_NAME(const SkPixmap& dst, const SkMask& srcMask,
26 : const SkIRect& clip SK_BLITBWMASK_ARGS) {
27 0 : SkASSERT(clip.fRight <= srcMask.fBounds.fRight);
28 :
29 0 : int cx = clip.fLeft;
30 0 : int cy = clip.fTop;
31 0 : int maskLeft = srcMask.fBounds.fLeft;
32 0 : unsigned mask_rowBytes = srcMask.fRowBytes;
33 0 : size_t bitmap_rowBytes = dst.rowBytes();
34 0 : unsigned height = clip.height();
35 :
36 0 : SkASSERT(mask_rowBytes != 0);
37 0 : SkASSERT(bitmap_rowBytes != 0);
38 0 : SkASSERT(height != 0);
39 :
40 0 : const uint8_t* bits = srcMask.getAddr1(cx, cy);
41 0 : SK_BLITBWMASK_DEVTYPE* device = dst.SK_BLITBWMASK_GETADDR(cx, cy);
42 :
43 0 : if (cx == maskLeft && clip.fRight == srcMask.fBounds.fRight)
44 : {
45 0 : do {
46 0 : SK_BLITBWMASK_DEVTYPE* dst = device;
47 0 : unsigned rb = mask_rowBytes;
48 0 : do {
49 0 : U8CPU mask = *bits++;
50 0 : SK_BLITBWMASK_BLIT8(mask, dst);
51 0 : dst += 8;
52 : } while (--rb != 0);
53 0 : device = (SK_BLITBWMASK_DEVTYPE*)((char*)device + bitmap_rowBytes);
54 0 : } while (--height != 0);
55 : }
56 : else
57 : {
58 0 : int left_edge = cx - maskLeft;
59 0 : SkASSERT(left_edge >= 0);
60 0 : int rite_edge = clip.fRight - maskLeft;
61 0 : SkASSERT(rite_edge > left_edge);
62 :
63 0 : int left_mask = 0xFF >> (left_edge & 7);
64 0 : int rite_mask = 0xFF << (8 - (rite_edge & 7));
65 0 : rite_mask &= 0xFF; // only want low-8 bits of mask
66 0 : int full_runs = (rite_edge >> 3) - ((left_edge + 7) >> 3);
67 :
68 : // check for empty right mask, so we don't read off the end (or go slower than we need to)
69 0 : if (rite_mask == 0)
70 : {
71 0 : SkASSERT(full_runs >= 0);
72 0 : full_runs -= 1;
73 0 : rite_mask = 0xFF;
74 : }
75 0 : if (left_mask == 0xFF)
76 0 : full_runs -= 1;
77 :
78 : // back up manually so we can keep in sync with our byte-aligned src
79 : // and not trigger an assert from the getAddr## function
80 0 : device -= left_edge & 7;
81 :
82 0 : if (full_runs < 0)
83 : {
84 0 : left_mask &= rite_mask;
85 0 : SkASSERT(left_mask != 0);
86 0 : do {
87 0 : U8CPU mask = *bits & left_mask;
88 0 : SK_BLITBWMASK_BLIT8(mask, device);
89 0 : bits += mask_rowBytes;
90 0 : device = (SK_BLITBWMASK_DEVTYPE*)((char*)device + bitmap_rowBytes);
91 : } while (--height != 0);
92 : }
93 : else
94 : {
95 0 : do {
96 0 : int runs = full_runs;
97 0 : SK_BLITBWMASK_DEVTYPE* dst = device;
98 0 : const uint8_t* b = bits;
99 : U8CPU mask;
100 :
101 0 : mask = *b++ & left_mask;
102 0 : SK_BLITBWMASK_BLIT8(mask, dst);
103 0 : dst += 8;
104 :
105 0 : while (--runs >= 0)
106 : {
107 0 : mask = *b++;
108 0 : SK_BLITBWMASK_BLIT8(mask, dst);
109 0 : dst += 8;
110 : }
111 :
112 0 : mask = *b & rite_mask;
113 0 : SK_BLITBWMASK_BLIT8(mask, dst);
114 :
115 0 : bits += mask_rowBytes;
116 0 : device = (SK_BLITBWMASK_DEVTYPE*)((char*)device + bitmap_rowBytes);
117 : } while (--height != 0);
118 : }
119 : }
120 0 : }
121 :
122 : #undef SK_BLITBWMASK_NAME
123 : #undef SK_BLITBWMASK_ARGS
124 : #undef SK_BLITBWMASK_BLIT8
125 : #undef SK_BLITBWMASK_GETADDR
126 : #undef SK_BLITBWMASK_DEVTYPE
127 : #undef SK_BLITBWMASK_DOROWSETUP
|