blob: 37f57c1fa8b5c68bdfd6f6aea15bae0ca875a21d [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
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
reed@android.com8a1c16f2008-12-17 15:59:43 +00008
9#include "SkAntiRun.h"
reed@google.comfa57ae72011-05-31 19:18:02 +000010#include "SkUtils.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000011
mike@reedtribe.orgd11f0e02011-04-09 19:39:25 +000012void SkAlphaRuns::reset(int width) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000013 SkASSERT(width > 0);
14
reed@google.comfa57ae72011-05-31 19:18:02 +000015#ifdef SK_DEBUG
16 sk_memset16((uint16_t*)fRuns, (uint16_t)(-42), width);
17#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +000018 fRuns[0] = SkToS16(width);
19 fRuns[width] = 0;
20 fAlpha[0] = 0;
21
22 SkDEBUGCODE(fWidth = width;)
23 SkDEBUGCODE(this->validate();)
24}
25
reed@android.com8a1c16f2008-12-17 15:59:43 +000026#ifdef SK_DEBUG
mike@reedtribe.orgd11f0e02011-04-09 19:39:25 +000027 void SkAlphaRuns::assertValid(int y, int maxStep) const {
reed@android.com8a1c16f2008-12-17 15:59:43 +000028 int max = (y + 1) * maxStep - (y == maxStep - 1);
29
30 const int16_t* runs = fRuns;
31 const uint8_t* alpha = fAlpha;
32
mike@reedtribe.orgd11f0e02011-04-09 19:39:25 +000033 while (*runs) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000034 SkASSERT(*alpha <= max);
35 alpha += *runs;
36 runs += *runs;
37 }
38 }
39
mike@reedtribe.orgd11f0e02011-04-09 19:39:25 +000040 void SkAlphaRuns::dump() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +000041 const int16_t* runs = fRuns;
42 const uint8_t* alpha = fAlpha;
43
44 SkDebugf("Runs");
mike@reedtribe.orgd11f0e02011-04-09 19:39:25 +000045 while (*runs) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000046 int n = *runs;
47
48 SkDebugf(" %02x", *alpha);
mike@reedtribe.orgd11f0e02011-04-09 19:39:25 +000049 if (n > 1) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000050 SkDebugf(",%d", n);
mike@reedtribe.orgd11f0e02011-04-09 19:39:25 +000051 }
reed@android.com8a1c16f2008-12-17 15:59:43 +000052 alpha += n;
53 runs += n;
54 }
55 SkDebugf("\n");
56 }
57
mike@reedtribe.orgd11f0e02011-04-09 19:39:25 +000058 void SkAlphaRuns::validate() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +000059 SkASSERT(fWidth > 0);
60
61 int count = 0;
62 const int16_t* runs = fRuns;
63
mike@reedtribe.orgd11f0e02011-04-09 19:39:25 +000064 while (*runs) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000065 SkASSERT(*runs > 0);
66 count += *runs;
67 SkASSERT(count <= fWidth);
68 runs += *runs;
69 }
70 SkASSERT(count == fWidth);
71 }
72#endif