Skip to content

Commit 09eb08c

Browse files
authored
Merge pull request #20 from lampmaker/claude/width-height-minification-y28tr1
Extend pack table to dictionary keys via computed keys
2 parents 1dbe4fc + 9b2b650 commit 09eb08c

4 files changed

Lines changed: 136 additions & 18 deletions

File tree

dist/tinywebgpu.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/tinywebgpu.tiny.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tinywebgpu.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,8 @@ ${main}
706706
width = fit(canvas.clientWidth, canvas.width), height = fit(canvas.clientHeight, canvas.height),
707707
changed = canvas.width !== width || canvas.height !== height,
708708
changed && (canvas.width = width, canvas.height = height),
709-
{ width, height, changed }),
709+
// sz spells the width/height keys once for the whole library — reuse it here too.
710+
{ ...sz(width, height), changed }),
710711
} : {}),
711712

712713
...(F_SHOW ? {
@@ -760,7 +761,10 @@ ${main}
760761
if (!/^(rgba|bgra)8unorm(-srgb)?$/.test(tex.format))
761762
err(19, MSG && `save: needs an 8-bit RGBA texture, got '${tex.format}'. Render it into an rgba8unorm target first.`);
762763
let [width, height] = texWH(tex, opts);
763-
let px = await S.readTexture(tex, { x: opts.x, y: opts.y, width, height, mipLevel: opts.mipLevel, Ctor: U8 });
764+
// readTexture derives the same x/y/width/height/mipLevel defaults from `opts` itself;
765+
// save's extra keys (type, quality, download) are ignored there, and Ctor spread last
766+
// always wins, so the pixels come back as bytes whatever the caller passed.
767+
let px = await S.readTexture(tex, { ...opts, Ctor: U8 });
764768
// ImageData is RGBA; the canvas format is BGRA on most platforms, so swap the ends.
765769
if (tex.format.startsWith('bgra'))
766770
for (let i = 0; i < px.length; i += 4) { let b = px[i]; px[i] = px[i + 2]; px[i + 2] = b; }

0 commit comments

Comments
 (0)