sw_engine: minor code clean up

This commit is contained in:
Hermet Park 2025-01-02 15:10:10 +09:00 committed by Hermet Park
parent 3c6d686795
commit 47524300bb
4 changed files with 21 additions and 41 deletions

View file

@ -46,6 +46,13 @@ struct SwPoint
{ {
SwCoord x, y; SwCoord x, y;
SwPoint& operator-=(const SwPoint& rhs)
{
x -= rhs.x;
y -= rhs.y;
return *this;
}
SwPoint& operator+=(const SwPoint& rhs) SwPoint& operator+=(const SwPoint& rhs)
{ {
x += rhs.x; x += rhs.x;

View file

@ -245,7 +245,6 @@ void mathSplitCubic(SwPoint* base)
void mathSplitLine(SwPoint* base) void mathSplitLine(SwPoint* base)
{ {
base[2] = base[1]; base[2] = base[1];
base[1].x = (base[0].x + base[1].x) >> 1; base[1].x = (base[0].x + base[1].x) >> 1;
base[1].y = (base[0].y + base[1].y) >> 1; base[1].y = (base[0].y + base[1].y) >> 1;
} }

View file

@ -306,7 +306,6 @@ static void _horizLine(RleWorker& rw, SwCoord x, SwCoord y, SwCoord area, SwCoor
/* compute the coverage line's coverage, depending on the outline fill rule */ /* compute the coverage line's coverage, depending on the outline fill rule */
/* the coverage percentage is area/(PIXEL_BITS*PIXEL_BITS*2) */ /* the coverage percentage is area/(PIXEL_BITS*PIXEL_BITS*2) */
auto coverage = static_cast<int>(area >> (PIXEL_BITS * 2 + 1 - 8)); //range 0 - 255 auto coverage = static_cast<int>(area >> (PIXEL_BITS * 2 + 1 - 8)); //range 0 - 255
if (coverage < 0) coverage = -coverage; if (coverage < 0) coverage = -coverage;
if (rw.outline->fillRule == FillRule::EvenOdd) { if (rw.outline->fillRule == FillRule::EvenOdd) {
@ -320,12 +319,8 @@ static void _horizLine(RleWorker& rw, SwCoord x, SwCoord y, SwCoord area, SwCoor
if (coverage == 0) return; if (coverage == 0) return;
//span has ushort coordinates. check limit overflow //span has ushort coordinates. check limit overflow
if (x >= SHRT_MAX) { if (x >= SHRT_MAX || y >= SHRT_MAX) {
TVGERR("SW_ENGINE", "X-coordinate overflow!"); TVGERR("SW_ENGINE", "XY-coordinate overflow!");
return;
}
if (y >= SHRT_MAX) {
TVGERR("SW_ENGINE", "Y-coordinate overflow!");
return; return;
} }
@ -342,7 +337,6 @@ static void _horizLine(RleWorker& rw, SwCoord x, SwCoord y, SwCoord area, SwCoor
if (x + aCount >= rw.cellMax.x) xOver -= (x + aCount - rw.cellMax.x); if (x + aCount >= rw.cellMax.x) xOver -= (x + aCount - rw.cellMax.x);
if (x < rw.cellMin.x) xOver -= (rw.cellMin.x - x); if (x < rw.cellMin.x) xOver -= (rw.cellMin.x - x);
//span->len += (aCount + xOver) - 1;
span->len += (aCount + xOver); span->len += (aCount + xOver);
return; return;
} }
@ -432,9 +426,7 @@ static bool _recordCell(RleWorker& rw)
{ {
if (rw.area | rw.cover) { if (rw.area | rw.cover) {
auto cell = _findCell(rw); auto cell = _findCell(rw);
if (!cell) return false;
if (cell == nullptr) return false;
cell->area += rw.area; cell->area += rw.area;
cell->cover += rw.cover; cell->cover += rw.cover;
} }
@ -457,17 +449,14 @@ static bool _setCell(RleWorker& rw, SwPoint pos)
/* All cells that are on the left of the clipping region go to the /* All cells that are on the left of the clipping region go to the
min_ex - 1 horizontal position. */ min_ex - 1 horizontal position. */
pos.x -= rw.cellMin.x; pos -= rw.cellMin;
pos.y -= rw.cellMin.y;
if (pos.x > rw.cellMax.x) pos.x = rw.cellMax.x; if (pos.x > rw.cellMax.x) pos.x = rw.cellMax.x;
//Are we moving to a different cell? //Are we moving to a different cell?
if (pos != rw.cellPos) { if (pos != rw.cellPos) {
//Record the current one if it is valid //Record the current one if it is valid
if (!rw.invalid) { if (!rw.invalid && !_recordCell(rw)) return false;
if (!_recordCell(rw)) return false;
}
} }
rw.area = 0; rw.area = 0;
@ -496,9 +485,7 @@ static bool _startCell(RleWorker& rw, SwPoint pos)
static bool _moveTo(RleWorker& rw, const SwPoint& to) static bool _moveTo(RleWorker& rw, const SwPoint& to)
{ {
//record current cell, if any */ //record current cell, if any */
if (!rw.invalid) { if (!rw.invalid && !_recordCell(rw)) return false;
if (!_recordCell(rw)) return false;
}
//start to a new position //start to a new position
if (!_startCell(rw, TRUNC(to))) return false; if (!_startCell(rw, TRUNC(to))) return false;
@ -511,10 +498,7 @@ static bool _moveTo(RleWorker& rw, const SwPoint& to)
static bool _lineTo(RleWorker& rw, const SwPoint& to) static bool _lineTo(RleWorker& rw, const SwPoint& to)
{ {
#define SW_UDIV(a, b) \ #define SW_UDIV(a, b) (SwCoord)(((unsigned long)(a) * (unsigned long)(b)) >> (sizeof(long) * CHAR_BIT - PIXEL_BITS))
static_cast<SwCoord>(((unsigned long)(a) * (unsigned long)(b)) >> \
(sizeof(long) * CHAR_BIT - PIXEL_BITS))
auto e1 = TRUNC(rw.pos); auto e1 = TRUNC(rw.pos);
auto e2 = TRUNC(to); auto e2 = TRUNC(to);
@ -627,7 +611,7 @@ static bool _lineTo(RleWorker& rw, const SwPoint& to)
} while(e1 != e2); } while(e1 != e2);
} }
f2 = {line[0].x - SUBPIXELS(e2.x), line[0].y - SUBPIXELS(e2.y)}; f2 = line[0] - SUBPIXELS(e2);
rw.cover += (f2.y - f1.y); rw.cover += (f2.y - f1.y);
rw.area += (f2.y - f1.y) * (f1.x + f2.x); rw.area += (f2.y - f1.y) * (f1.x + f2.x);
rw.pos = line[0]; rw.pos = line[0];
@ -744,20 +728,18 @@ static bool _decomposeOutline(RleWorker& rw)
} }
close: close:
if (!_lineTo(rw, start)) return false; if (!_lineTo(rw, start)) return false;
first = last + 1; first = last + 1;
} }
return true; return true;
} }
static int _genRle(RleWorker& rw) static bool _genRle(RleWorker& rw)
{ {
if (!_decomposeOutline(rw)) return -1; if (!_decomposeOutline(rw)) return false;
if (!rw.invalid) { if (!rw.invalid && !_recordCell(rw)) return false;
if (!_recordCell(rw)) return -1; return true;
}
return 0;
} }
@ -907,7 +889,6 @@ SwRle* rleRender(SwRle* rle, const SwOutline* outline, const SwBBox& renderRegio
auto min = rw.cellMin.y; auto min = rw.cellMin.y;
auto yMax = rw.cellMax.y; auto yMax = rw.cellMax.y;
SwCoord max; SwCoord max;
int ret;
for (int n = 0; n < bandCnt; ++n, min = max) { for (int n = 0; n < bandCnt; ++n, min = max) {
max = min + rw.bandSize; max = min + rw.bandSize;
@ -943,13 +924,10 @@ SwRle* rleRender(SwRle* rle, const SwOutline* outline, const SwBBox& renderRegio
rw.cellMax.y = band->max; rw.cellMax.y = band->max;
rw.cellYCnt = band->max - band->min; rw.cellYCnt = band->max - band->min;
ret = _genRle(rw); if (_genRle(rw)) {
if (ret == 0) {
_sweep(rw); _sweep(rw);
--band; --band;
continue; continue;
} else if (ret == 1) {
goto error;
} }
reduce_bands: reduce_bands:

View file

@ -597,14 +597,10 @@ static void _addCap(SwStroke& stroke, SwFixed angle, int32_t side)
delta += delta2 + stroke.center; delta += delta2 + stroke.center;
_borderLineTo(border, delta, false); _borderLineTo(border, delta, false);
} else if (stroke.cap == StrokeCap::Round) { } else if (stroke.cap == StrokeCap::Round) {
stroke.angleIn = angle; stroke.angleIn = angle;
stroke.angleOut = angle + SW_ANGLE_PI; stroke.angleOut = angle + SW_ANGLE_PI;
_arcTo(stroke, side); _arcTo(stroke, side);
return;
} else { //Butt } else { //Butt
auto rotate = SIDE_TO_ROTATE(side); auto rotate = SIDE_TO_ROTATE(side);
auto border = stroke.borders + side; auto border = stroke.borders + side;