WebGL's gl.readPixels returns rows in bottom-up order (y=0 at the
bottom of the framebuffer); a Canvas2D ImageData expects top-down
(y=0 at the top). This routine swaps rows in-place by row-block
copy. It does not change RGBA component order — only the row order.
The output is Uint8ClampedArray because that's what ImageData
requires; clamping is a no-op here since the input is already
Uint8 (no values outside [0, 255]).
Flip a row-major RGBA pixel buffer vertically.
WebGL's
gl.readPixelsreturns rows in bottom-up order (y=0 at the bottom of the framebuffer); aCanvas2D ImageDataexpects top-down (y=0 at the top). This routine swaps rows in-place by row-block copy. It does not change RGBA component order — only the row order.The output is
Uint8ClampedArraybecause that's whatImageDatarequires; clamping is a no-op here since the input is already Uint8 (no values outside [0, 255]).