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