1
/* libs/graphics/sgl/SkAlphaRuns.cpp
3
** Copyright 2006, The Android Open Source Project
5
** Licensed under the Apache License, Version 2.0 (the "License");
6
** you may not use this file except in compliance with the License.
7
** You may obtain a copy of the License at
9
** http://www.apache.org/licenses/LICENSE-2.0
11
** Unless required by applicable law or agreed to in writing, software
12
** distributed under the License is distributed on an "AS IS" BASIS,
13
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
** See the License for the specific language governing permissions and
15
** limitations under the License.
18
#include "SkAntiRun.h"
20
void SkAlphaRuns::reset(int width)
24
fRuns[0] = SkToS16(width);
28
SkDEBUGCODE(fWidth = width;)
29
SkDEBUGCODE(this->validate();)
32
void SkAlphaRuns::Break(int16_t runs[], uint8_t alpha[], int x, int count)
34
SkASSERT(count > 0 && x >= 0);
36
// SkAlphaRuns::BreakAt(runs, alpha, x);
37
// SkAlphaRuns::BreakAt(&runs[x], &alpha[x], count);
39
int16_t* next_runs = runs + x;
40
uint8_t* next_alpha = alpha + x;
51
runs[x] = SkToS16(n - x);
72
runs[x] = SkToS16(n - x);
84
void SkAlphaRuns::add(int x, U8CPU startAlpha, int middleCount, U8CPU stopAlpha, U8CPU maxValue)
86
SkASSERT(middleCount >= 0);
87
SkASSERT(x >= 0 && x + (startAlpha != 0) + middleCount + (stopAlpha != 0) <= fWidth);
89
int16_t* runs = fRuns;
90
uint8_t* alpha = fAlpha;
94
SkAlphaRuns::Break(runs, alpha, x, 1);
95
/* I should be able to just add alpha[x] + startAlpha.
96
However, if the trailing edge of the previous span and the leading
97
edge of the current span round to the same super-sampled x value,
98
I might overflow to 256 with this add, hence the funny subtract (crud).
100
unsigned tmp = alpha[x] + startAlpha;
101
SkASSERT(tmp <= 256);
102
alpha[x] = SkToU8(tmp - (tmp >> 8)); // was (tmp >> 7), but that seems wrong if we're trying to catch 256
107
SkDEBUGCODE(this->validate();)
111
SkAlphaRuns::Break(runs, alpha, x, middleCount);
116
alpha[0] = SkToU8(alpha[0] + maxValue);
118
SkASSERT(n <= middleCount);
122
} while (middleCount > 0);
123
SkDEBUGCODE(this->validate();)
127
SkAlphaRuns::Break(runs, alpha, x, 1);
128
alpha[x] = SkToU8(alpha[x] + stopAlpha);
129
SkDEBUGCODE(this->validate();)
134
void SkAlphaRuns::assertValid(int y, int maxStep) const
136
int max = (y + 1) * maxStep - (y == maxStep - 1);
138
const int16_t* runs = fRuns;
139
const uint8_t* alpha = fAlpha;
143
SkASSERT(*alpha <= max);
149
void SkAlphaRuns::dump() const
151
const int16_t* runs = fRuns;
152
const uint8_t* alpha = fAlpha;
159
SkDebugf(" %02x", *alpha);
168
void SkAlphaRuns::validate() const
170
SkASSERT(fWidth > 0);
173
const int16_t* runs = fRuns;
179
SkASSERT(count <= fWidth);
182
SkASSERT(count == fWidth);