Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 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. |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 3 | #include "tools/fiddle/examples.h" |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 4 | // HASH=76d4d4a7931a48495e4d5f54e073be53 |
Hal Canary | a7181e7c | 2019-03-18 16:06:34 -0400 | [diff] [blame] | 5 | REG_FIDDLE(Dither_b, 256, 256, false, 0) { |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 6 | void draw(SkCanvas* canvas) { |
| 7 | canvas->clear(0); |
| 8 | SkBitmap bm32; |
| 9 | bm32.allocPixels(SkImageInfo::Make(20, 10, kN32_SkColorType, kPremul_SkAlphaType)); |
| 10 | SkCanvas c32(bm32); |
| 11 | SkPoint points[] = {{0, 0}, {20, 0}}; |
| 12 | SkColor colors[] = {0xFF334455, 0xFF662211 }; |
| 13 | SkPaint paint; |
| 14 | paint.setShader(SkGradientShader::MakeLinear( |
| 15 | points, colors, nullptr, SK_ARRAY_COUNT(colors), |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 16 | SkTileMode::kClamp)); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 17 | paint.setDither(true); |
Mike Reed | e1f72f9 | 2021-01-27 17:09:40 -0500 | [diff] [blame] | 18 | auto img = bm32.asImage(); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 19 | c32.drawPaint(paint); |
| 20 | canvas->scale(12, 12); |
Mike Reed | e1f72f9 | 2021-01-27 17:09:40 -0500 | [diff] [blame] | 21 | canvas->drawImage(img, 0, 0); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 22 | paint.setBlendMode(SkBlendMode::kPlus); |
Mike Reed | b339d05 | 2021-01-28 11:20:41 -0500 | [diff] [blame] | 23 | SkSamplingOptions sampling; |
| 24 | canvas->drawImage(img, 0, 11, sampling, &paint); |
| 25 | canvas->drawImage(img, 0, 11, sampling, &paint); |
| 26 | canvas->drawImage(img, 0, 11, sampling, &paint); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 27 | } |
| 28 | } // END FIDDLE |