Skip to content

Commit

Permalink
Improved / better clip bounds handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bourgesl committed Feb 9, 2014
1 parent 01fb04c commit a1e37c3
Show file tree
Hide file tree
Showing 9 changed files with 253 additions and 111 deletions.
4 changes: 3 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
<groupId>org.marlin</groupId>
<artifactId>marlin</artifactId>
<packaging>jar</packaging>
<version>0.3.1</version>
<version>0.4</version>
<name>Marlin software rasterizer</name>

<url>https://github.com/bourgesl/marlin-renderer</url>

<description>
A pure Java renderer, derived from OpenJDK Pisces
</description>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/marlin/pisces/Curve.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ int infPoints(float[] pts, int off) {
// perpendicular. This happens when g(t) = f'(t)*f''(t) == 0 (where
// * is a dot product). Unfortunately, we have to solve a cubic.
private int perpendiculardfddf(float[] pts, int off) {
assert pts.length >= off + 4;
// assert pts.length >= off + 4;

// these are the coefficients of some multiple of g(t) (not g(t),
// because the roots of a polynomial are not changed after multiplication
Expand All @@ -152,7 +152,7 @@ private int perpendiculardfddf(float[] pts, int off) {
// problem for what we're trying to do (draw a nice looking curve).
int rootsOfROCMinusW(float[] roots, int off, final float w, final float err) {
// no OOB exception, because by now off<=6, and roots.length >= 10
assert off <= 6 && roots.length >= 10;
// assert off <= 6 && roots.length >= 10;
int ret = off;
int numPerpdfddf = perpendiculardfddf(roots, off);
float t0 = 0, ft0 = ROCsq(t0) - w*w;
Expand Down Expand Up @@ -250,7 +250,7 @@ private float ROCsq(final float t) {
Iterator<Integer> breakPtsAtTs(final float[] pts, final int type,
final float[] Ts, final int numTs)
{
assert pts.length >= 2*type && numTs <= Ts.length;
// assert pts.length >= 2*type && numTs <= Ts.length;

// initialize shared iterator:
iterator.init(pts, type, Ts, numTs);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/marlin/pisces/Helpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ static int filterOutNotInAB(float[] nums, final int off, final int len,
}

static float polyLineLength(float[] poly, final int off, final int nCoords) {
assert nCoords % 2 == 0 && poly.length >= off + nCoords : "";
// assert nCoords % 2 == 0 && poly.length >= off + nCoords : "";
float acc = 0;
for (int i = off + 2; i < off + nCoords; i += 2) {
acc += linelen(poly[i], poly[i+1], poly[i-2], poly[i-1]);
Expand Down
40 changes: 26 additions & 14 deletions src/main/java/org/marlin/pisces/PiscesCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ final class PiscesCache implements PiscesConst {
}

void init(int minx, int miny, int maxx, int maxy) {
assert maxy >= miny && maxx >= minx;
// assert maxy >= miny && maxx >= minx;
bboxX0 = minx;
bboxY0 = miny;
bboxX1 = maxx;
bboxY1 = maxy;

// the ceiling of (maxy - miny + 1) / TILE_SIZE;
int nxTiles = (maxx - minx + TILE_SIZE) >> TILE_SIZE_LG;
final int nxTiles = (maxx - minx + TILE_SIZE) >> TILE_SIZE_LG;

if (nxTiles > INITIAL_ARRAY) {
touchedTile = rdrCtx.getIntArray(nxTiles);
Expand Down Expand Up @@ -179,6 +179,13 @@ void copyAARow(final int[] alphaRow, final int y, final int px0, final int px1)
if (doMonitors) {
rdrCtx.mon_rdr_emitRow.start();
}

/* skip useless pixels above boundary */
final int px_bbox1 = Math.min(px1, bboxX1);

if (doLogBounds) {
PiscesUtils.logInfo("row = [" + px0 + " ... " + px_bbox1 + " ("+px1+") [ for y=" + y);
}

final int row = y - bboxY0;

Expand All @@ -189,20 +196,21 @@ void copyAARow(final int[] alphaRow, final int y, final int px0, final int px1)
// update row data:
int[] _rowAAChunk = rowAAChunk;
// ensure rowAAChunk capacity:
if (_rowAAChunk.length < pos + 2 + (px1 - px0)) {
rowAAChunk = _rowAAChunk = rdrCtx.widenDirtyIntArray(_rowAAChunk, pos, 2 + (px1 - px0));
if (_rowAAChunk.length < pos + 2 + (px_bbox1 - px0)) {
rowAAChunk = _rowAAChunk = rdrCtx.widenDirtyIntArray(_rowAAChunk, pos, 2 + (px_bbox1 - px0));
}
if (doStats) {
this.rdrCtx.stat_cache_rowAARLE.add(2 + px1 - px0);
this.rdrCtx.stat_cache_rowAARLE.add(2 + px_bbox1 - px0);
}
// rowAA contains (x0 x1)(alpha values for range[x0; x1[)
_rowAAChunk[pos ] = px0; // first pixel inclusive
_rowAAChunk[pos + 1] = px1; // last pixel exclusive
_rowAAChunk[pos ] = px0; // first pixel inclusive
_rowAAChunk[pos + 1] = px_bbox1; // last pixel exclusive

final int from = px0 - bboxX0; // first pixel inclusive
final int to = px1 - bboxX0; // last pixel exclusive
final int from = px0 - bboxX0; // first pixel inclusive
final int to = px_bbox1 - bboxX0; // last pixel exclusive

final int[] touchedLine = touchedTile;
final int _TILE_SIZE_LG = TILE_SIZE_LG;

// fix offset in rowAAChunk:
final int off = pos + 2 - from;
Expand All @@ -216,26 +224,30 @@ void copyAARow(final int[] alphaRow, final int y, final int px0, final int px1)

if (val != 0) {
// update touchedTile
touchedLine[x >> TILE_SIZE_LG] += val;
touchedLine[x >> _TILE_SIZE_LG] += val;
}
}

// update current position:
rowAAChunkPos = pos + 2 + px1 - px0;
rowAAChunkPos = pos + 2 + px_bbox1 - px0;

// update tile used marks:
int tx = from >> TILE_SIZE_LG; // inclusive
int tx = from >> _TILE_SIZE_LG; // inclusive
if (tx < tileMin) {
tileMin = tx;
}

tx = ((to - 1) >> TILE_SIZE_LG) + 1; // exclusive (+1 to be sure)
tx = ((to - 1) >> _TILE_SIZE_LG) + 1; // exclusive (+1 to be sure)
if (tx > tileMax) {
tileMax = tx;
}

if (doLogBounds) {
PiscesUtils.logInfo("clear = [" + from + " ... " + to + "[");
}

// Clear alpha row for reuse:
IntArrayCache.fill(alphaRow, from, to, 0);
IntArrayCache.fill(alphaRow, from, px1 - bboxX0, 0);

if (doMonitors) {
rdrCtx.mon_rdr_emitRow.stop();
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/org/marlin/pisces/PiscesConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ interface PiscesConst {
/** enable JUL logger */
static final boolean useJUL = false;

/** enable development mode */
static final boolean doDev = false;

/** do checks */
static final boolean doChecks = false;

/* disable when algorithm / code is stable */
static final boolean DO_AA_RANGE_CHECK = false;

Expand All @@ -53,8 +59,6 @@ interface PiscesConst {
static final boolean useDumpThread = false;
/** stat dump interval (ms) */
static final long statDump = 5000L;
/** do checks */
static final boolean doChecks = false;
/** do clean dirty array */
static final boolean doCleanDirty = false;

Expand All @@ -66,6 +70,9 @@ interface PiscesConst {
/** enable / disable stroker.drawRoundCap() (diagnostic only) */
static final boolean doDrawRoundCaps = true;

/** flag to enable logs related bounds checks */
static final boolean doLogBounds = false;

/* Initial Array sizing (initial context capacity) ~ 512K to 1 Mb */

/** 2048 pixel (width x height) for initial capacity */
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/marlin/pisces/PiscesTileGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ public void getAlpha(final byte tile[], final int offset, final int rowstride) {
y1 = cache.bboxY1;
}

if (doLogBounds) {
PiscesUtils.logInfo("getAlpha = [" + x0 + " ... " + x1 + "[ [" + y0 + " ... " + y1 + "[");
}

final int skipRowPixels = (rowstride - (x1 - x0));

// LBO: hack to process tile line [0 - 32[
Expand Down
Loading

0 comments on commit a1e37c3

Please sign in to comment.