mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-15 10:09:45 +00:00
Switch to 8 byte offset
This commit is contained in:
@@ -22,8 +22,8 @@ fn rotate(width: usize, height: usize, _rotate: usize) {
|
|||||||
let in_b: &mut [u32];
|
let in_b: &mut [u32];
|
||||||
let out_b: &mut [u32];
|
let out_b: &mut [u32];
|
||||||
unsafe {
|
unsafe {
|
||||||
in_b = from_raw_parts_mut::<u32>(4 as *mut u32, num_pixels);
|
in_b = from_raw_parts_mut::<u32>(8 as *mut u32, num_pixels);
|
||||||
out_b = from_raw_parts_mut::<u32>((num_pixels * 4 + 4) as *mut u32, num_pixels);
|
out_b = from_raw_parts_mut::<u32>((num_pixels * 4 + 8) as *mut u32, num_pixels);
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_width = height;
|
let new_width = height;
|
||||||
|
|||||||
Binary file not shown.
@@ -11,7 +11,7 @@ export async function rotate(
|
|||||||
|
|
||||||
// Number of wasm memory pages (á 64KiB) needed to store the image twice.
|
// Number of wasm memory pages (á 64KiB) needed to store the image twice.
|
||||||
const bytesPerImage = data.width * data.height * 4;
|
const bytesPerImage = data.width * data.height * 4;
|
||||||
const numPagesNeeded = Math.ceil((bytesPerImage * 2 + 4) / (64 * 1024));
|
const numPagesNeeded = Math.ceil((bytesPerImage * 2 + 8) / (64 * 1024));
|
||||||
// Only count full pages, just to be safe.
|
// Only count full pages, just to be safe.
|
||||||
const numPagesAvailable = Math.floor(instance.exports.memory.buffer.byteLength / (64 * 1024));
|
const numPagesAvailable = Math.floor(instance.exports.memory.buffer.byteLength / (64 * 1024));
|
||||||
const additionalPagesToAllocate = numPagesNeeded - numPagesAvailable;
|
const additionalPagesToAllocate = numPagesNeeded - numPagesAvailable;
|
||||||
@@ -20,13 +20,13 @@ export async function rotate(
|
|||||||
instance.exports.memory.grow(additionalPagesToAllocate);
|
instance.exports.memory.grow(additionalPagesToAllocate);
|
||||||
}
|
}
|
||||||
const view = new Uint8ClampedArray(instance.exports.memory.buffer);
|
const view = new Uint8ClampedArray(instance.exports.memory.buffer);
|
||||||
view.set(data.data, 4);
|
view.set(data.data, 8);
|
||||||
|
|
||||||
instance.exports.rotate(data.width, data.height, opts.rotate);
|
instance.exports.rotate(data.width, data.height, opts.rotate);
|
||||||
|
|
||||||
const flipDimensions = opts.rotate % 180 !== 0;
|
const flipDimensions = opts.rotate % 180 !== 0;
|
||||||
return new ImageData(
|
return new ImageData(
|
||||||
view.slice(bytesPerImage + 4, bytesPerImage * 2 + 4),
|
view.slice(bytesPerImage + 8, bytesPerImage * 2 + 8),
|
||||||
flipDimensions ? data.height : data.width,
|
flipDimensions ? data.height : data.width,
|
||||||
flipDimensions ? data.width : data.height,
|
flipDimensions ? data.width : data.height,
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user