Skip to content

Commit

Permalink
Flip webgl-based canvas pixels before copying them to intermediary bu…
Browse files Browse the repository at this point in the history
…ffer
  • Loading branch information
Lauren Budorick committed Sep 14, 2017
1 parent 3634d94 commit 04e9a15
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/source/canvas_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ class CanvasSource extends ImageSource {
gl.readPixels(0, 0, this.width, this.height, gl.RGBA, gl.UNSIGNED_BYTE, data);
if (!this.secondaryContext) this.secondaryContext = window.document.createElement('canvas').getContext('2d');
const imageData = this.secondaryContext.createImageData(this.width, this.height);
imageData.data.set(data);
const flipped = new Uint8Array(this.width * this.height * 4);
for (let i = this.height - 1, j = 0; i >= 0; i--, j++) {
flipped.set(data.slice(i * this.width * 4, (i + 1) * this.width * 4), j * this.width * 4);
}
imageData.data.set(flipped);
return imageData;
}
}
Expand Down

0 comments on commit 04e9a15

Please sign in to comment.