Skip to content

Commit 3658ed2

Browse files
committed
Bug fix: removed artifact when a partially covered pixel color was extrapolated between two supersample ranges.
1 parent 2f7fcfb commit 3658ed2

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

lib/rasterization/rasterizer.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ function rasterize(edgeTable, backColor) {
5959
edgeTable.sort();
6060

6161
var writer = new BitmapWriter(backColor, edgeTable.width, edgeTable.height);
62-
var superSampleBuffer = new SuperSampleBuffer(edgeTable.width, SAMPLES_PER_PIXEL_X);
62+
63+
// Allocate an extra slot in the super sample buffer to calculate the
64+
// color that will be forwarded until the next supersample range.
65+
var superSampleBuffer = new SuperSampleBuffer(edgeTable.width + 1, SAMPLES_PER_PIXEL_X);
6366

6467
var layers = [];
6568
var color = 0;
@@ -101,9 +104,14 @@ function rasterize(edgeTable, backColor) {
101104
color = subScanlineLayers.color;
102105
}
103106

104-
superSampleBuffer.add(color, superSampleRange.width);
107+
// Write an extra pixel that will contain the color that
108+
// will be forwarded until the next supersample range.
109+
superSampleBuffer.add(color, superSampleRange.width + 1);
105110
superSampleBuffer.rewind();
106111
} // /subpixel
112+
113+
// Get color to be forwarded
114+
color = superSampleBuffer.getColorAt(superSampleRange.width);
107115

108116
// Blend subpixels
109117
superSampleBuffer.writeTo(writer, superSampleRange.width);

lib/rasterization/superSampleBuffer.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,24 @@ SuperSampleBuffer.prototype.writeTo = function SuperSampleBuffer_writeTo(bitmapW
106106
}
107107
};
108108

109+
/**
110+
* Gets the average color for the pixel at a specified index in the buffer.
111+
* @param {number} index The index of the pixel whose average color will be calculated.
112+
* @returns {number} Average color.
113+
* @public
114+
*/
115+
SuperSampleBuffer.prototype.getColorAt = function SuperSampleBuffer_getColorAt(index) {
116+
var sampleCount = this._samples[index * 5 + IDX_COUNT],
117+
alphaSum = this._samples[index * 5 + IDX_A];
118+
return sampleCount && alphaSum ?
119+
colorUtils.from(
120+
Math.floor(alphaSum / sampleCount),
121+
Math.floor(this._samples[index * 5 + IDX_R] * 255 / alphaSum),
122+
Math.floor(this._samples[index * 5 + IDX_G] * 255 / alphaSum),
123+
Math.floor(this._samples[index * 5 + IDX_B] * 255 / alphaSum)
124+
) : 0;
125+
};
126+
109127
/**
110128
* Adds a color to the buffer up until the specified x index.
111129
* @param {number} color Color to write.

0 commit comments

Comments
 (0)