blob: 37b1a5705ce126f63ed14eab55395b08ca092ec2 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2006 The Android Open Source Project
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
reed@android.com8a1c16f2008-12-17 15:59:43 +00009
10#include "SkAntiRun.h"
reed@google.comfa57ae72011-05-31 19:18:02 +000011#include "SkUtils.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000012
mike@reedtribe.orgd11f0e02011-04-09 19:39:25 +000013void SkAlphaRuns::reset(int width) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000014 SkASSERT(width > 0);
15
reed@google.comfa57ae72011-05-31 19:18:02 +000016#ifdef SK_DEBUG
17 sk_memset16((uint16_t*)fRuns, (uint16_t)(-42), width);
18#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +000019 fRuns[0] = SkToS16(width);
20 fRuns[width] = 0;
21 fAlpha[0] = 0;
22
23 SkDEBUGCODE(fWidth = width;)
24 SkDEBUGCODE(this->validate();)
25}
26
reed@android.com8a1c16f2008-12-17 15:59:43 +000027#ifdef SK_DEBUG
mike@reedtribe.orgd11f0e02011-04-09 19:39:25 +000028 void SkAlphaRuns::assertValid(int y, int maxStep) const {
reed@android.com8a1c16f2008-12-17 15:59:43 +000029 int max = (y + 1) * maxStep - (y == maxStep - 1);
30
31 const int16_t* runs = fRuns;
32 const uint8_t* alpha = fAlpha;
33
mike@reedtribe.orgd11f0e02011-04-09 19:39:25 +000034 while (*runs) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000035 SkASSERT(*alpha <= max);
36 alpha += *runs;
37 runs += *runs;
38 }
39 }
40
mike@reedtribe.orgd11f0e02011-04-09 19:39:25 +000041 void SkAlphaRuns::dump() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +000042 const int16_t* runs = fRuns;
43 const uint8_t* alpha = fAlpha;
44
45 SkDebugf("Runs");
mike@reedtribe.orgd11f0e02011-04-09 19:39:25 +000046 while (*runs) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000047 int n = *runs;
48
49 SkDebugf(" %02x", *alpha);
mike@reedtribe.orgd11f0e02011-04-09 19:39:25 +000050 if (n > 1) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000051 SkDebugf(",%d", n);
mike@reedtribe.orgd11f0e02011-04-09 19:39:25 +000052 }
reed@android.com8a1c16f2008-12-17 15:59:43 +000053 alpha += n;
54 runs += n;
55 }
56 SkDebugf("\n");
57 }
58
mike@reedtribe.orgd11f0e02011-04-09 19:39:25 +000059 void SkAlphaRuns::validate() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +000060 SkASSERT(fWidth > 0);
61
62 int count = 0;
63 const int16_t* runs = fRuns;
64
mike@reedtribe.orgd11f0e02011-04-09 19:39:25 +000065 while (*runs) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000066 SkASSERT(*runs > 0);
67 count += *runs;
68 SkASSERT(count <= fWidth);
69 runs += *runs;
70 }
71 SkASSERT(count == fWidth);
72 }
73#endif