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