epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 8 | |
| 9 | #include "SkAntiRun.h" |
reed@google.com | fa57ae7 | 2011-05-31 19:18:02 +0000 | [diff] [blame] | 10 | #include "SkUtils.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 11 | |
mike@reedtribe.org | d11f0e0 | 2011-04-09 19:39:25 +0000 | [diff] [blame] | 12 | void SkAlphaRuns::reset(int width) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 13 | SkASSERT(width > 0); |
| 14 | |
reed@google.com | fa57ae7 | 2011-05-31 19:18:02 +0000 | [diff] [blame] | 15 | #ifdef SK_DEBUG |
| 16 | sk_memset16((uint16_t*)fRuns, (uint16_t)(-42), width); |
| 17 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 18 | 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.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 26 | #ifdef SK_DEBUG |
mike@reedtribe.org | d11f0e0 | 2011-04-09 19:39:25 +0000 | [diff] [blame] | 27 | void SkAlphaRuns::assertValid(int y, int maxStep) const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 28 | int max = (y + 1) * maxStep - (y == maxStep - 1); |
| 29 | |
| 30 | const int16_t* runs = fRuns; |
| 31 | const uint8_t* alpha = fAlpha; |
| 32 | |
mike@reedtribe.org | d11f0e0 | 2011-04-09 19:39:25 +0000 | [diff] [blame] | 33 | while (*runs) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 34 | SkASSERT(*alpha <= max); |
| 35 | alpha += *runs; |
| 36 | runs += *runs; |
| 37 | } |
| 38 | } |
| 39 | |
mike@reedtribe.org | d11f0e0 | 2011-04-09 19:39:25 +0000 | [diff] [blame] | 40 | void SkAlphaRuns::dump() const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 41 | const int16_t* runs = fRuns; |
| 42 | const uint8_t* alpha = fAlpha; |
| 43 | |
| 44 | SkDebugf("Runs"); |
mike@reedtribe.org | d11f0e0 | 2011-04-09 19:39:25 +0000 | [diff] [blame] | 45 | while (*runs) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 46 | int n = *runs; |
| 47 | |
| 48 | SkDebugf(" %02x", *alpha); |
mike@reedtribe.org | d11f0e0 | 2011-04-09 19:39:25 +0000 | [diff] [blame] | 49 | if (n > 1) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 50 | SkDebugf(",%d", n); |
mike@reedtribe.org | d11f0e0 | 2011-04-09 19:39:25 +0000 | [diff] [blame] | 51 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 52 | alpha += n; |
| 53 | runs += n; |
| 54 | } |
| 55 | SkDebugf("\n"); |
| 56 | } |
| 57 | |
mike@reedtribe.org | d11f0e0 | 2011-04-09 19:39:25 +0000 | [diff] [blame] | 58 | void SkAlphaRuns::validate() const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 59 | SkASSERT(fWidth > 0); |
| 60 | |
| 61 | int count = 0; |
| 62 | const int16_t* runs = fRuns; |
| 63 | |
mike@reedtribe.org | d11f0e0 | 2011-04-09 19:39:25 +0000 | [diff] [blame] | 64 | while (*runs) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 65 | SkASSERT(*runs > 0); |
| 66 | count += *runs; |
| 67 | SkASSERT(count <= fWidth); |
| 68 | runs += *runs; |
| 69 | } |
| 70 | SkASSERT(count == fWidth); |
| 71 | } |
| 72 | #endif |