• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_b, 256, 128, false, 1) {
draw(SkCanvas * canvas)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 < source.height(); ++y) {
12         for (int x = 0; x < source.width(); ++x) {
13             SkPMColor pixel = srcPixels[y * source.width() + x];
14             const SkColor color = SkUnPreMultiply::PMColorToColor(pixel);
15             if (SkColorGetA(color) == SK_AlphaOPAQUE) {
16                 srcPixels[y * source.width() + x] = SK_ColorGREEN;
17             }
18         }
19     }
20     canvas->drawImage(SkImages::RasterFromPixmapCopy(pixmap), 0, 0);
21 }
22 }  // END FIDDLE
23