xref: /third_party/skia/docs/examples/dither1.cpp (revision cb93a386)
1// Copyright 2020 Google LLC.
2// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3#include "tools/fiddle/examples.h"
4REG_FIDDLE(dither1, 256, 100, false, 0) {
5void draw(SkCanvas* canvas) {
6    SkBitmap bm16;
7    bm16.allocPixels(SkImageInfo::Make(32, 32, kRGB_565_SkColorType, kOpaque_SkAlphaType));
8    SkCanvas c16(bm16);
9    SkPaint colorPaint;
10    for (auto dither : {false, true}) {
11        colorPaint.setDither(dither);
12        for (auto colors : {0xFF333333, 0xFF666666, 0xFF999999, 0xFFCCCCCC}) {
13            for (auto mask : {0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 0xFFFFFFFF}) {
14                colorPaint.setColor(colors & mask);
15                c16.drawRect({0, 0, 8, 4}, colorPaint);
16                c16.translate(8, 0);
17            }
18            c16.translate(-32, 4);
19        }
20    }
21    canvas->scale(8, 8);
22    canvas->drawImage(bm16.asImage(), 0, 0);
23}
24
25}  // END FIDDLE
26