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=bc9c7ea424d10bbcd1e5a88770d4794e |
Hal Canary | a7181e7c | 2019-03-18 16:06:34 -0400 | [diff] [blame] | 5 | REG_FIDDLE(Alpha_Constants_a, 256, 128, false, 1) { |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 6 | void draw(SkCanvas* canvas) { |
| 7 | std::vector<int32_t> srcPixels; |
| 8 | srcPixels.resize(source.height() * source.rowBytes()); |
| 9 | SkPixmap pixmap(SkImageInfo::MakeN32Premul(source.width(), source.height()), |
| 10 | &srcPixels.front(), source.rowBytes()); |
| 11 | source.readPixels(pixmap, 0, 0); |
| 12 | for (int y = 0; y < 16; ++y) { |
| 13 | for (int x = 0; x < 16; ++x) { |
| 14 | int32_t* blockStart = &srcPixels.front() + y * source.width() * 16 + x * 16; |
| 15 | size_t transparentCount = 0; |
| 16 | for (int fillY = 0; fillY < source.height() / 16; ++fillY) { |
| 17 | for (int fillX = 0; fillX < source.width() / 16; ++fillX) { |
| 18 | const SkColor color = SkUnPreMultiply::PMColorToColor(blockStart[fillX]); |
| 19 | transparentCount += SkColorGetA(color) == SK_AlphaTRANSPARENT; |
| 20 | } |
| 21 | blockStart += source.width(); |
| 22 | } |
| 23 | if (transparentCount > 200) { |
| 24 | blockStart = &srcPixels.front() + y * source.width() * 16 + x * 16; |
| 25 | for (int fillY = 0; fillY < source.height() / 16; ++fillY) { |
| 26 | for (int fillX = 0; fillX < source.width() / 16; ++fillX) { |
| 27 | blockStart[fillX] = SK_ColorRED; |
| 28 | } |
| 29 | blockStart += source.width(); |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | } |
Mike Reed | 34a0c97 | 2021-01-25 17:49:32 -0500 | [diff] [blame] | 34 | canvas->drawImage(SkImage::MakeRasterCopy(pixmap), 0, 0); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 35 | } |
| 36 | } // END FIDDLE |