SkAlphaRuns.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright 2006 The Android Open Source Project
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "include/private/SkTo.h"
  8. #include "src/core/SkAntiRun.h"
  9. #include "src/core/SkUtils.h"
  10. void SkAlphaRuns::reset(int width) {
  11. SkASSERT(width > 0);
  12. #ifdef SK_DEBUG
  13. sk_memset16((uint16_t*)fRuns, (uint16_t)(-42), width);
  14. #endif
  15. fRuns[0] = SkToS16(width);
  16. fRuns[width] = 0;
  17. fAlpha[0] = 0;
  18. SkDEBUGCODE(fWidth = width;)
  19. SkDEBUGCODE(this->validate();)
  20. }
  21. #ifdef SK_DEBUG
  22. void SkAlphaRuns::assertValid(int y, int maxStep) const {
  23. int max = (y + 1) * maxStep - (y == maxStep - 1);
  24. const int16_t* runs = fRuns;
  25. const uint8_t* alpha = fAlpha;
  26. while (*runs) {
  27. SkASSERT(*alpha <= max);
  28. alpha += *runs;
  29. runs += *runs;
  30. }
  31. }
  32. void SkAlphaRuns::dump() const {
  33. const int16_t* runs = fRuns;
  34. const uint8_t* alpha = fAlpha;
  35. SkDebugf("Runs");
  36. while (*runs) {
  37. int n = *runs;
  38. SkDebugf(" %02x", *alpha);
  39. if (n > 1) {
  40. SkDebugf(",%d", n);
  41. }
  42. alpha += n;
  43. runs += n;
  44. }
  45. SkDebugf("\n");
  46. }
  47. void SkAlphaRuns::validate() const {
  48. SkASSERT(fWidth > 0);
  49. int count = 0;
  50. const int16_t* runs = fRuns;
  51. while (*runs) {
  52. SkASSERT(*runs > 0);
  53. count += *runs;
  54. SkASSERT(count <= fWidth);
  55. runs += *runs;
  56. }
  57. SkASSERT(count == fWidth);
  58. }
  59. #endif