Upload the 16-bit sidecar unflipped so it matches the JPEG proxy.
Chrome ignores UNPACK_FLIP_Y_WEBGL for ImageBitmap uploads, so the JPEG proxy lands in the texture top-down while the parser pre-flipped the sidecar rows. The picture jumped upside down a few seconds after load, when the sidecar replaced the proxy. The parser now keeps the PNG's row order. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
@@ -1437,6 +1437,9 @@ export class Renderer {
|
||||
this.srcW = bitmap.width;
|
||||
this.srcH = bitmap.height;
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.srcTex);
|
||||
// The flag is honoured for the ArrayBufferView sidecar but ignored for the
|
||||
// ImageBitmap proxy, so the sidecar arrives already in the proxy's row order
|
||||
// and must be uploaded unflipped.
|
||||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
||||
const usable = hdr && hdr.width === bitmap.width && hdr.height === bitmap.height ? hdr : null;
|
||||
let half = false;
|
||||
|
||||
@@ -149,7 +149,7 @@ describe('parsePreview16', () => {
|
||||
expect(Array.from(parsed!.rgba.slice(4, 8))).toEqual([0x3c00, 0, 0x3800, 0x3c00]);
|
||||
});
|
||||
|
||||
it('flips the rows so upload needs no UNPACK_FLIP_Y', async () => {
|
||||
it('keeps the PNG row order so the sidecar matches the JPEG texture', async () => {
|
||||
const parsed = await parsePreview16(
|
||||
encodePng16(
|
||||
[
|
||||
@@ -161,9 +161,11 @@ describe('parsePreview16', () => {
|
||||
),
|
||||
);
|
||||
expect(parsed).not.toBeNull();
|
||||
// Row 0 of the returned buffer is the last image row.
|
||||
expect(parsed!.rgba[0]).toBe(0);
|
||||
expect(parsed!.rgba[4]).toBe(0x3c00);
|
||||
// Chrome ignores UNPACK_FLIP_Y_WEBGL for ImageBitmap uploads, so the JPEG
|
||||
// proxy is top-down in the texture. Flipping here put the 16-bit sidecar
|
||||
// upside down once it replaced the proxy a few seconds after load.
|
||||
expect(parsed!.rgba[0]).toBe(0x3c00);
|
||||
expect(parsed!.rgba[4]).toBe(0);
|
||||
});
|
||||
|
||||
it('reads the camera matrix out of the sidecar text chunk', async () => {
|
||||
|
||||
@@ -8,14 +8,16 @@
|
||||
* always optional.
|
||||
*
|
||||
* The parser only accepts what the encoder writes (16-bit, non-interlaced,
|
||||
* RGB or RGBA) and returns the samples as half-float RGBA with the rows already
|
||||
* flipped, because `UNPACK_FLIP_Y_WEBGL` is ignored for ArrayBufferView uploads.
|
||||
* RGB or RGBA) and returns the samples as half-float RGBA in the PNG's own
|
||||
* top-down row order. That is the order the JPEG proxy already lands in: an
|
||||
* ImageBitmap upload ignores `UNPACK_FLIP_Y_WEBGL`, so the sidecar has to match
|
||||
* it row for row or the picture jumps upside down when it swaps in.
|
||||
*/
|
||||
|
||||
export interface Preview16 {
|
||||
width: number;
|
||||
height: number;
|
||||
/** RGBA half-float, rows bottom-up, ready for `texImage2D` without a flip. */
|
||||
/** RGBA half-float, top-down like the proxy, ready for `texImage2D` unflipped. */
|
||||
rgba: Uint16Array;
|
||||
/**
|
||||
* Camera-to-sRGB matrix, row major, when the samples are camera native.
|
||||
@@ -195,8 +197,9 @@ export async function parsePreview16(buffer: ArrayBuffer): Promise<Preview16 | n
|
||||
const rgba = new Uint16Array(width * height * 4);
|
||||
const opaque = table[65535];
|
||||
let out = 0;
|
||||
for (let y = height - 1; y >= 0; y--) {
|
||||
// Bottom-up: the texture upload cannot flip an ArrayBufferView.
|
||||
for (let y = 0; y < height; y++) {
|
||||
// Top-down: the JPEG texture is uploaded from an ImageBitmap, which ignores
|
||||
// UNPACK_FLIP_Y_WEBGL, so both sources must hand the GPU the same row order.
|
||||
let src = y * (stride + 1) + 1;
|
||||
for (let x = 0; x < width; x++) {
|
||||
rgba[out++] = table[(raw[src] << 8) | raw[src + 1]];
|
||||
|
||||
Reference in New Issue
Block a user