1 // Copyright 2019 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"
4 REG_FIDDLE(Dither_b, 256, 256, false, 0) {
draw(SkCanvas * canvas)5 void draw(SkCanvas* canvas) {
6 canvas->clear(0);
7 SkBitmap bm32;
8 bm32.allocPixels(SkImageInfo::Make(20, 10, kN32_SkColorType, kPremul_SkAlphaType));
9 SkCanvas c32(bm32);
10 SkPoint points[] = {{0, 0}, {20, 0}};
11 SkColor colors[] = {0xFF334455, 0xFF662211 };
12 SkPaint paint;
13 paint.setShader(SkGradientShader::MakeLinear(
14 points, colors, nullptr, std::size(colors),
15 SkTileMode::kClamp));
16 paint.setDither(true);
17 auto img = bm32.asImage();
18 c32.drawPaint(paint);
19 canvas->scale(12, 12);
20 canvas->drawImage(img, 0, 0);
21 paint.setBlendMode(SkBlendMode::kPlus);
22 SkSamplingOptions sampling;
23 canvas->drawImage(img, 0, 11, sampling, &paint);
24 canvas->drawImage(img, 0, 11, sampling, &paint);
25 canvas->drawImage(img, 0, 11, sampling, &paint);
26 }
27 } // END FIDDLE
28