aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/effects/SkStippleMaskFilter.cpp
blob: 434528ed91ff2c0136fee5831f1378c7865b1224 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
 * Copyright 2012 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SkStippleMaskFilter.h"


bool SkStippleMaskFilter::filterMask(SkMask* dst,
                                     const SkMask& src,
                                     const SkMatrix& matrix,
                                     SkIPoint* margin) {

    if (src.fFormat != SkMask::kA8_Format) {
        return false;
    }

    dst->fBounds = src.fBounds;
    dst->fRowBytes = dst->fBounds.width();
    dst->fFormat = SkMask::kA8_Format;
    dst->fImage = NULL;

    if (NULL != src.fImage) {
        size_t dstSize = dst->computeImageSize();
        if (0 == dstSize) {
            return false;   // too big to allocate, abort
        }

        dst->fImage = SkMask::AllocImage(dstSize);

        uint8_t* srcScanLine = src.fImage;
        uint8_t* scanline = dst->fImage;

        for (int y = 0; y < src.fBounds.height(); ++y) {
            for (int x = 0; x < src.fBounds.width(); ++x) {
                scanline[x] = srcScanLine[x] && ((x+y) & 0x1) ? 0xFF : 0x00;
            }
            scanline += dst->fRowBytes;
            srcScanLine += src.fRowBytes;
        }
    }

    return true;
}