blob: 391d04bb1f9efda86b79c08febdf628dd8b72919 [file] [log] [blame]
Hal Canary87515122019-03-15 14:22:51 -04001// 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 Kleinc0bd9f92019-04-23 12:05:21 -05003#include "tools/fiddle/examples.h"
Hal Canary87515122019-03-15 14:22:51 -04004// HASH=bc9c7ea424d10bbcd1e5a88770d4794e
Hal Canarya7181e7c2019-03-18 16:06:34 -04005REG_FIDDLE(Alpha_Constants_a, 256, 128, false, 1) {
Hal Canary87515122019-03-15 14:22:51 -04006void 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 Reed34a0c972021-01-25 17:49:32 -050034 canvas->drawImage(SkImage::MakeRasterCopy(pixmap), 0, 0);
Hal Canary87515122019-03-15 14:22:51 -040035}
36} // END FIDDLE