1cb93a386Sopenharmony_ci// Copyright 2019 Google LLC. 2cb93a386Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. 3cb93a386Sopenharmony_ci#include "tools/fiddle/examples.h" 4cb93a386Sopenharmony_ci// HASH=bc9c7ea424d10bbcd1e5a88770d4794e 5cb93a386Sopenharmony_ciREG_FIDDLE(Alpha_Constants_a, 256, 128, false, 1) { 6cb93a386Sopenharmony_civoid draw(SkCanvas* canvas) { 7cb93a386Sopenharmony_ci std::vector<int32_t> srcPixels; 8cb93a386Sopenharmony_ci srcPixels.resize(source.height() * source.rowBytes()); 9cb93a386Sopenharmony_ci SkPixmap pixmap(SkImageInfo::MakeN32Premul(source.width(), source.height()), 10cb93a386Sopenharmony_ci &srcPixels.front(), source.rowBytes()); 11cb93a386Sopenharmony_ci source.readPixels(pixmap, 0, 0); 12cb93a386Sopenharmony_ci for (int y = 0; y < 16; ++y) { 13cb93a386Sopenharmony_ci for (int x = 0; x < 16; ++x) { 14cb93a386Sopenharmony_ci int32_t* blockStart = &srcPixels.front() + y * source.width() * 16 + x * 16; 15cb93a386Sopenharmony_ci size_t transparentCount = 0; 16cb93a386Sopenharmony_ci for (int fillY = 0; fillY < source.height() / 16; ++fillY) { 17cb93a386Sopenharmony_ci for (int fillX = 0; fillX < source.width() / 16; ++fillX) { 18cb93a386Sopenharmony_ci const SkColor color = SkUnPreMultiply::PMColorToColor(blockStart[fillX]); 19cb93a386Sopenharmony_ci transparentCount += SkColorGetA(color) == SK_AlphaTRANSPARENT; 20cb93a386Sopenharmony_ci } 21cb93a386Sopenharmony_ci blockStart += source.width(); 22cb93a386Sopenharmony_ci } 23cb93a386Sopenharmony_ci if (transparentCount > 200) { 24cb93a386Sopenharmony_ci blockStart = &srcPixels.front() + y * source.width() * 16 + x * 16; 25cb93a386Sopenharmony_ci for (int fillY = 0; fillY < source.height() / 16; ++fillY) { 26cb93a386Sopenharmony_ci for (int fillX = 0; fillX < source.width() / 16; ++fillX) { 27cb93a386Sopenharmony_ci blockStart[fillX] = SK_ColorRED; 28cb93a386Sopenharmony_ci } 29cb93a386Sopenharmony_ci blockStart += source.width(); 30cb93a386Sopenharmony_ci } 31cb93a386Sopenharmony_ci } 32cb93a386Sopenharmony_ci } 33cb93a386Sopenharmony_ci } 34cb93a386Sopenharmony_ci canvas->drawImage(SkImage::MakeRasterCopy(pixmap), 0, 0); 35cb93a386Sopenharmony_ci} 36cb93a386Sopenharmony_ci} // END FIDDLE 37