Alpha_Constants_b.cpp 1.0 KB

12345678910111213141516171819202122232425
  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. // HASH=0424f67ebc2858e8fd04ae3367b115ff
  5. REG_FIDDLE(Alpha_Constants_b, 256, 128, false, 1) {
  6. void 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 < source.height(); ++y) {
  13. for (int x = 0; x < source.width(); ++x) {
  14. SkPMColor pixel = srcPixels[y * source.width() + x];
  15. const SkColor color = SkUnPreMultiply::PMColorToColor(pixel);
  16. if (SkColorGetA(color) == SK_AlphaOPAQUE) {
  17. srcPixels[y * source.width() + x] = SK_ColorGREEN;
  18. }
  19. }
  20. }
  21. SkBitmap bitmap;
  22. bitmap.installPixels(pixmap);
  23. canvas->drawBitmap(bitmap, 0, 0);
  24. }
  25. } // END FIDDLE