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:
@@ -984,7 +984,7 @@ Conventions worth knowing before changing code:
|
|||||||
| `src/lib/lensNames.test.ts` | EXIF lens-name normalisation, search variants and match scoring |
|
| `src/lib/lensNames.test.ts` | EXIF lens-name normalisation, search variants and match scoring |
|
||||||
| `src/lib/lensDefaults.test.ts` | Camera + lens default selection and rejection rules |
|
| `src/lib/lensDefaults.test.ts` | Camera + lens default selection and rejection rules |
|
||||||
| `src/lib/editSections.test.ts` | Selective settings copy and the ISO-aware auto-noise curve |
|
| `src/lib/editSections.test.ts` | Selective settings copy and the ISO-aware auto-noise curve |
|
||||||
| `src/lib/preview16.test.ts` | 16-bit PNG proxy parsing, row flip, half-float encoding and the camera matrix chunk |
|
| `src/lib/preview16.test.ts` | 16-bit PNG proxy parsing, row order, half-float encoding and the camera matrix chunk |
|
||||||
| `src/lib/dcp.test.ts` | DCP tag parsing and the camera matrix recipe against LibRaw's own values |
|
| `src/lib/dcp.test.ts` | DCP tag parsing and the camera matrix recipe against LibRaw's own values |
|
||||||
| `src/lib/softProof.test.ts` | ICC parsing (including counted lut16 tables), the printer round trip, gamut threshold, rendering-intent selection and CMYK profiles |
|
| `src/lib/softProof.test.ts` | ICC parsing (including counted lut16 tables), the printer round trip, gamut threshold, rendering-intent selection and CMYK profiles |
|
||||||
| `src/lib/dcpLibrary.test.ts` | Per-camera DCP library: validation, replacement, forgetting and camera matching |
|
| `src/lib/dcpLibrary.test.ts` | Per-camera DCP library: validation, replacement, forgetting and camera matching |
|
||||||
|
|||||||
@@ -1437,6 +1437,9 @@ export class Renderer {
|
|||||||
this.srcW = bitmap.width;
|
this.srcW = bitmap.width;
|
||||||
this.srcH = bitmap.height;
|
this.srcH = bitmap.height;
|
||||||
gl.bindTexture(gl.TEXTURE_2D, this.srcTex);
|
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);
|
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
||||||
const usable = hdr && hdr.width === bitmap.width && hdr.height === bitmap.height ? hdr : null;
|
const usable = hdr && hdr.width === bitmap.width && hdr.height === bitmap.height ? hdr : null;
|
||||||
let half = false;
|
let half = false;
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ describe('parsePreview16', () => {
|
|||||||
expect(Array.from(parsed!.rgba.slice(4, 8))).toEqual([0x3c00, 0, 0x3800, 0x3c00]);
|
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(
|
const parsed = await parsePreview16(
|
||||||
encodePng16(
|
encodePng16(
|
||||||
[
|
[
|
||||||
@@ -161,9 +161,11 @@ describe('parsePreview16', () => {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
expect(parsed).not.toBeNull();
|
expect(parsed).not.toBeNull();
|
||||||
// Row 0 of the returned buffer is the last image row.
|
// Chrome ignores UNPACK_FLIP_Y_WEBGL for ImageBitmap uploads, so the JPEG
|
||||||
expect(parsed!.rgba[0]).toBe(0);
|
// proxy is top-down in the texture. Flipping here put the 16-bit sidecar
|
||||||
expect(parsed!.rgba[4]).toBe(0x3c00);
|
// 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 () => {
|
it('reads the camera matrix out of the sidecar text chunk', async () => {
|
||||||
|
|||||||
@@ -8,14 +8,16 @@
|
|||||||
* always optional.
|
* always optional.
|
||||||
*
|
*
|
||||||
* The parser only accepts what the encoder writes (16-bit, non-interlaced,
|
* 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
|
* RGB or RGBA) and returns the samples as half-float RGBA in the PNG's own
|
||||||
* flipped, because `UNPACK_FLIP_Y_WEBGL` is ignored for ArrayBufferView uploads.
|
* 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 {
|
export interface Preview16 {
|
||||||
width: number;
|
width: number;
|
||||||
height: 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;
|
rgba: Uint16Array;
|
||||||
/**
|
/**
|
||||||
* Camera-to-sRGB matrix, row major, when the samples are camera native.
|
* 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 rgba = new Uint16Array(width * height * 4);
|
||||||
const opaque = table[65535];
|
const opaque = table[65535];
|
||||||
let out = 0;
|
let out = 0;
|
||||||
for (let y = height - 1; y >= 0; y--) {
|
for (let y = 0; y < height; y++) {
|
||||||
// Bottom-up: the texture upload cannot flip an ArrayBufferView.
|
// 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;
|
let src = y * (stride + 1) + 1;
|
||||||
for (let x = 0; x < width; x++) {
|
for (let x = 0; x < width; x++) {
|
||||||
rgba[out++] = table[(raw[src] << 8) | raw[src + 1]];
|
rgba[out++] = table[(raw[src] << 8) | raw[src + 1]];
|
||||||
|
|||||||
Reference in New Issue
Block a user