-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: lanczos throwing when destination dimensions are not round (#50)
* fix: lanczos throwing when destination dimensions are not round Images over `MAX_WIDTH` that don't scale to a rounded width or height were causing lanczos to blow up with `RangeError: byte length of Uint32Array should be a multiple of 4` This change ensures that the target dimensions are rounded and the resulting target `Uint32Array` has a length that is a multiple of 4 * chore: add changeset --------- Co-authored-by: Jack Works <5390719+Jack-Works@users.noreply.github.com>
- Loading branch information
1 parent
f27b915
commit 40d94ae
Showing
3 changed files
with
29 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@masknet/stego-js': patch | ||
--- | ||
|
||
fix: lanczos throwing when destination dimensions are not round |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { expect, test, vi } from 'vitest' | ||
import { preprocessImage } from '../src/utils/image.js' | ||
import { MAX_WIDTH } from '../src/constant.js' | ||
|
||
test('preprocessImage rounds the dimensions of the scaled image', async () => { | ||
const getScaled = vi.fn().mockImplementation((width, height) => ({ | ||
height, | ||
width, | ||
colorSpace: 'srgb', | ||
data: new Uint8ClampedArray(width * height * 4), | ||
})) | ||
preprocessImage( | ||
{ | ||
width: 1980, | ||
height: 1024, | ||
colorSpace: 'srgb', | ||
data: new Uint8ClampedArray(1980 * 1024 * 4), | ||
}, | ||
getScaled, | ||
) | ||
|
||
expect(getScaled).toHaveBeenCalledWith(MAX_WIDTH, 1014) | ||
}) |