Skip to content

Commit bbb2f74

Browse files
committed
Bug fix: enforce signed colors when the color is written to the PNG data buffer (#2).
1 parent c72ee89 commit bbb2f74

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/png/pngEncoder.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ PngEncoder.prototype.writeTrueColorWithAlpha = function PngEncoder_writeTrueColo
7373

7474
for (var x = 0; x < width; canvasCursor++) {
7575
var count = colorRanges[canvasCursor * 2 + 0];
76-
var color = colorRanges[canvasCursor * 2 + 1];
76+
77+
// Use a bitwise operator to ensure the color is expressed as a signed 32-bit integer
78+
var color = colorRanges[canvasCursor * 2 + 1] & 0xffffffff;
7779

7880
for (var i = 0; i < count; i++) {
79-
buffer.writeUInt32BE(color, outputCursor, true);
81+
buffer.writeInt32BE(color, outputCursor);
8082
outputCursor += 4;
8183
}
8284

0 commit comments

Comments
 (0)