1941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com/*
2941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com * Copyright 2012 Google Inc.
3941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com *
4941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com * Use of this source code is governed by a BSD-style license that can be
5941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com * found in the LICENSE file.
6941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com */
7941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com
8941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com#include "SkStippleMaskFilter.h"
90bd80fa01bba2b3f0f49937fcb17928c74bde5a6robertphillips@google.com#include "SkString.h"
10941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com
11941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.combool SkStippleMaskFilter::filterMask(SkMask* dst,
12941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com                                     const SkMask& src,
13941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com                                     const SkMatrix& matrix,
1430711b764be6bbb58caa30a0ac5d1474c894efe7reed@google.com                                     SkIPoint* margin) const {
15941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com
16941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com    if (src.fFormat != SkMask::kA8_Format) {
17941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com        return false;
18941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com    }
19941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com
20941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com    dst->fBounds = src.fBounds;
21941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com    dst->fRowBytes = dst->fBounds.width();
22941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com    dst->fFormat = SkMask::kA8_Format;
23941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com    dst->fImage = NULL;
24941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com
25941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com    if (NULL != src.fImage) {
26941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com        size_t dstSize = dst->computeImageSize();
27941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com        if (0 == dstSize) {
28941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com            return false;   // too big to allocate, abort
29941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com        }
30941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com
31941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com        dst->fImage = SkMask::AllocImage(dstSize);
32941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com
33941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com        uint8_t* srcScanLine = src.fImage;
34941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com        uint8_t* scanline = dst->fImage;
35941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com
36941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com        for (int y = 0; y < src.fBounds.height(); ++y) {
37941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com            for (int x = 0; x < src.fBounds.width(); ++x) {
38941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com                scanline[x] = srcScanLine[x] && ((x+y) & 0x1) ? 0xFF : 0x00;
39941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com            }
40941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com            scanline += dst->fRowBytes;
41941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com            srcScanLine += src.fRowBytes;
42941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com        }
43941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com    }
44941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com
45941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com    return true;
46941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com}
470bd80fa01bba2b3f0f49937fcb17928c74bde5a6robertphillips@google.com
480f10f7bf1fb43ca6346dc220a076773b1f19a367commit-bot@chromium.org#ifndef SK_IGNORE_TO_STRING
490bd80fa01bba2b3f0f49937fcb17928c74bde5a6robertphillips@google.comvoid SkStippleMaskFilter::toString(SkString* str) const {
500bd80fa01bba2b3f0f49937fcb17928c74bde5a6robertphillips@google.com    str->append("SkStippleMaskFilter: ()");
510bd80fa01bba2b3f0f49937fcb17928c74bde5a6robertphillips@google.com}
520bd80fa01bba2b3f0f49937fcb17928c74bde5a6robertphillips@google.com#endif
53