michael@0: michael@0: /* michael@0: * Copyright 2006 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #include "SkAntiRun.h" michael@0: #include "SkUtils.h" michael@0: michael@0: void SkAlphaRuns::reset(int width) { michael@0: SkASSERT(width > 0); michael@0: michael@0: #ifdef SK_DEBUG michael@0: sk_memset16((uint16_t*)fRuns, (uint16_t)(-42), width); michael@0: #endif michael@0: fRuns[0] = SkToS16(width); michael@0: fRuns[width] = 0; michael@0: fAlpha[0] = 0; michael@0: michael@0: SkDEBUGCODE(fWidth = width;) michael@0: SkDEBUGCODE(this->validate();) michael@0: } michael@0: michael@0: #ifdef SK_DEBUG michael@0: void SkAlphaRuns::assertValid(int y, int maxStep) const { michael@0: int max = (y + 1) * maxStep - (y == maxStep - 1); michael@0: michael@0: const int16_t* runs = fRuns; michael@0: const uint8_t* alpha = fAlpha; michael@0: michael@0: while (*runs) { michael@0: SkASSERT(*alpha <= max); michael@0: alpha += *runs; michael@0: runs += *runs; michael@0: } michael@0: } michael@0: michael@0: void SkAlphaRuns::dump() const { michael@0: const int16_t* runs = fRuns; michael@0: const uint8_t* alpha = fAlpha; michael@0: michael@0: SkDebugf("Runs"); michael@0: while (*runs) { michael@0: int n = *runs; michael@0: michael@0: SkDebugf(" %02x", *alpha); michael@0: if (n > 1) { michael@0: SkDebugf(",%d", n); michael@0: } michael@0: alpha += n; michael@0: runs += n; michael@0: } michael@0: SkDebugf("\n"); michael@0: } michael@0: michael@0: void SkAlphaRuns::validate() const { michael@0: SkASSERT(fWidth > 0); michael@0: michael@0: int count = 0; michael@0: const int16_t* runs = fRuns; michael@0: michael@0: while (*runs) { michael@0: SkASSERT(*runs > 0); michael@0: count += *runs; michael@0: SkASSERT(count <= fWidth); michael@0: runs += *runs; michael@0: } michael@0: SkASSERT(count == fWidth); michael@0: } michael@0: #endif