Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix buffer offset/size calculations in rotate/processor.ts #458

Merged
merged 1 commit into from
Feb 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/codecs/rotate/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export async function rotate(

// Number of wasm memory pages (á 64KiB) needed to store the image twice.
const bytesPerImage = data.width * data.height * 4;
const numPagesNeeded = Math.ceil(bytesPerImage * 2 / (64 * 1024) + 4);
const numPagesNeeded = Math.ceil((bytesPerImage * 2 + 4) / (64 * 1024));
// Only count full pages, just to be safe.
const numPagesAvailable = Math.floor(instance.exports.memory.buffer.byteLength / (64 * 1024));
const additionalPagesToAllocate = numPagesNeeded - numPagesAvailable;
Expand All @@ -20,13 +20,13 @@ export async function rotate(
instance.exports.memory.grow(additionalPagesToAllocate);
}
const view = new Uint8ClampedArray(instance.exports.memory.buffer);
view.set(data.data);
view.set(data.data, 4);

instance.exports.rotate(data.width, data.height, opts.rotate);

const flipDimensions = opts.rotate % 180 !== 0;
return new ImageData(
view.slice(bytesPerImage, bytesPerImage * 2),
view.slice(bytesPerImage + 4, bytesPerImage * 2 + 4),
flipDimensions ? data.height : data.width,
flipDimensions ? data.width : data.height,
);
Expand Down