Alpha_Constants_a.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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=bc9c7ea424d10bbcd1e5a88770d4794e
  5. REG_FIDDLE(Alpha_Constants_a, 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 < 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