blob: aa2c7a368f1fd985bef2c5d2756238befbb1cd3d [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 }
34 SkBitmap bitmap;
35 bitmap.installPixels(pixmap);
36 canvas->drawBitmap(bitmap, 0, 0);
37}
38} // END FIDDLE