mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
fix(ext/web): properly handle Blob
case for createImageBitmap
(#23518)
fixes https://github.com/denoland/deno/issues/22649
This commit is contained in:
parent
cbb78e138f
commit
e7a2317f5a
4 changed files with 16 additions and 2 deletions
|
@ -238,7 +238,9 @@ function createImageBitmap(
|
|||
"InvalidStateError",
|
||||
);
|
||||
}
|
||||
const { data: imageData, width, height } = op_image_decode_png(data);
|
||||
const { data: imageData, width, height } = op_image_decode_png(
|
||||
new Uint8Array(data),
|
||||
);
|
||||
const processedImage = processImage(
|
||||
imageData,
|
||||
width,
|
||||
|
|
|
@ -130,7 +130,8 @@ fn op_image_decode_png(#[buffer] buf: &[u8]) -> Result<DecodedPng, AnyError> {
|
|||
)));
|
||||
}
|
||||
|
||||
let mut png_data = Vec::with_capacity(png.total_bytes() as usize);
|
||||
// read_image will assert that the buffer is the correct size, so we need to fill it with zeros
|
||||
let mut png_data = vec![0_u8; png.total_bytes() as usize];
|
||||
|
||||
png.read_image(&mut png_data)?;
|
||||
|
||||
|
|
BIN
tests/testdata/image/1x1-white.png
vendored
Normal file
BIN
tests/testdata/image/1x1-white.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 109 B |
|
@ -90,3 +90,14 @@ Deno.test(async function imageBitmapFlipY() {
|
|||
1, 0, 0, 1, 2, 0, 0, 1, 3, 0, 0, 1,
|
||||
]));
|
||||
});
|
||||
|
||||
Deno.test(async function imageBitmapFromBlob() {
|
||||
const path = "tests/testdata/image/1x1-white.png";
|
||||
const imageData = new Blob([await Deno.readFile(path)], {
|
||||
type: "image/png",
|
||||
});
|
||||
const imageBitmap = await createImageBitmap(imageData);
|
||||
// @ts-ignore: Deno[Deno.internal].core allowed
|
||||
// deno-fmt-ignore
|
||||
assertEquals(Deno[Deno.internal].getBitmapData(imageBitmap), new Uint8Array([255,255,255,255]));
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue