From 04e9a15242b558eacd4b428f0b72c01a036b733f Mon Sep 17 00:00:00 2001 From: Lauren Budorick Date: Thu, 14 Sep 2017 16:50:36 -0700 Subject: [PATCH] Flip webgl-based canvas pixels before copying them to intermediary buffer --- src/source/canvas_source.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/source/canvas_source.js b/src/source/canvas_source.js index ccb0ea890f6..8bec5480675 100644 --- a/src/source/canvas_source.js +++ b/src/source/canvas_source.js @@ -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; } }