blob: 72d7a0c88192b153dbd1f6413261950dba1af8e0 [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#ifndef SkAntiRun_DEFINED
11#define SkAntiRun_DEFINED
12
13#include "SkBlitter.h"
14
reed@android.com8a1c16f2008-12-17 15:59:43 +000015class SkAlphaRuns {
16public:
17 int16_t* fRuns;
18 uint8_t* fAlpha;
19
mike@reedtribe.orgd11f0e02011-04-09 19:39:25 +000020 bool empty() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +000021 SkASSERT(fRuns[0] > 0);
22 return fAlpha[0] == 0 && fRuns[fRuns[0]] == 0;
23 }
mike@reedtribe.orgd11f0e02011-04-09 19:39:25 +000024
reed@android.com8a1c16f2008-12-17 15:59:43 +000025 void reset(int width);
reed@google.comfa57ae72011-05-31 19:18:02 +000026
27 /**
28 * Returns the offsetX value that should be passed on the next call,
29 * assuming we're on the same scanline. If the caller is switching
30 * scanlines, then offsetX should be 0 when this is called.
31 */
32 int add(int x, U8CPU startAlpha, int middleCount, U8CPU stopAlpha,
33 U8CPU maxValue, int offsetX);
34
reed@android.com8a1c16f2008-12-17 15:59:43 +000035 SkDEBUGCODE(void assertValid(int y, int maxStep) const;)
36 SkDEBUGCODE(void dump() const;)
37
38 static void Break(int16_t runs[], uint8_t alpha[], int x, int count);
mike@reedtribe.orgd11f0e02011-04-09 19:39:25 +000039
40 static void BreakAt(int16_t runs[], uint8_t alpha[], int x) {
41 while (x > 0) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000042 int n = runs[0];
43 SkASSERT(n > 0);
44
mike@reedtribe.orgd11f0e02011-04-09 19:39:25 +000045 if (x < n) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000046 alpha[x] = alpha[0];
47 runs[0] = SkToS16(x);
48 runs[x] = SkToS16(n - x);
49 break;
50 }
51 runs += n;
52 alpha += n;
53 x -= n;
54 }
55 }
56
57private:
58 SkDEBUGCODE(int fWidth;)
59 SkDEBUGCODE(void validate() const;)
60};
61
62#endif
63