Before you throw me out - I am aware of this answer, but it does not seem to work for me. It is also different in that the source of the image data in my case is a WebGL canvas - not an img node.
I am trying to put ImageData onto a canvas like so:
var c = document.createElement('canvas');
c.setAttribute('width', size.width);
c.setAttribute('height', size.height);
$('body').append(c)
// p contains a Uint8ClampedArray with imagedata coming from a WebGL canvas
var i = new ImageData(p, size.width, size.height);
var ctx = c.getContext('2d');
ctx.putImageData(i, 0, 0);
and then to flip it like so:
var d = document.createElement('canvas');
d.width = c.width; d.height = c.height;
d.getContext('2d').drawImage(c, 0, 0);
ctx.clearRect(0, 0, c.width, c.height);
ctx.scale(-1, 1);
ctx.translate(c.width, 0);
ctx.drawImage(d, 0, 0);
but this fails miserably.
The data comes from a WebGL canvas like this:
var gl = renderer.domElement.getContext("webgl")
var pixels = new Uint8Array(gl.drawingBufferWidth * gl.drawingBufferHeight * 4);
gl.readPixels(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
so I've considered low-level operations on the pixel array as a solution, but before I get into that I thought I'd ask.
I have a hunch that drawImage is insensitive to transforms, but that would be funny. Please please don't make me use toDataURL()