1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 13:00:36 -05:00

add unit test for imageOrientation

This commit is contained in:
Hajime-san 2024-10-02 18:55:17 +09:00
parent 3beb65b9f0
commit 829f523f89
3 changed files with 63 additions and 13 deletions

View file

@ -361,7 +361,17 @@ pub(super) fn op_create_image_bitmap(
let image = if image_orientation == ImageOrientation::FlipY {
image.flipv()
} else {
// TODO(Hajime-san): If the EXIF contains image orientation information, decode the image in the appropriate orientation.
// The image create is expected to release this feature soon.
// https://github.com/image-rs/image/blob/bd0f7451a367de7ae3d898dcf1e96e9d0a1c4fa1/CHANGES.md#version-0253
// https://github.com/image-rs/image/issues/1958
// https://github.com/image-rs/image/pull/2299
// https://github.com/image-rs/image/pull/2328
// if image_bitmap_source == ImageBitmapSource::Blob {
// image.apply_orientation()
// } else {
image
// }
};
// 9.

BIN
tests/testdata/image/squares_6.jpg vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

@ -1,6 +1,6 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assertEquals, assertRejects } from "./test_util.ts";
import { assertEquals, assertNotEquals, assertRejects } from "./test_util.ts";
const prefix = "tests/testdata/image";
@ -78,7 +78,8 @@ Deno.test(async function imageBitmapScale() {
]));
});
Deno.test(async function imageBitmapFlipY() {
Deno.test("imageOrientation", async (t) => {
await t.step('"ImageData" imageOrientation: "flipY"', async () => {
const data = generateNumberedData(9);
const imageData = new ImageData(data, 3, 3);
const imageBitmap = await createImageBitmap(imageData, {
@ -93,6 +94,45 @@ Deno.test(async function imageBitmapFlipY() {
]));
});
const imageData = new Blob(
[await Deno.readFile(`${prefix}/squares_6.jpg`)],
{ type: "image/jpeg" },
);
const WIDTH = 320;
const CHANNELS = 3;
const TARGET_PIXEL_X = 40;
const START = TARGET_PIXEL_X * WIDTH * CHANNELS;
const END = START + CHANNELS;
// reference:
// https://github.com/web-platform-tests/wpt/blob/a1f4bbf4c6e1a9a861a145a34cd097ea260b5a49/html/canvas/element/manual/imagebitmap/createImageBitmap-exif-orientation.html#L30
await t.step('"Blob" imageOrientation: "from-image"', async () => {
const imageBitmap = await createImageBitmap(imageData);
// @ts-ignore: Deno[Deno.internal].core allowed
const targetPixel = Deno[Deno.internal].getBitmapData(imageBitmap).slice(
START,
END,
);
// FIXME: When the implementation is fixed, fix this to assertEquals
// However, in the case of jpg images, numerical errors may occur.
assertNotEquals(targetPixel, new Uint8Array([255, 1, 0]));
});
// reference:
// https://github.com/web-platform-tests/wpt/blob/a1f4bbf4c6e1a9a861a145a34cd097ea260b5a49/html/canvas/element/manual/imagebitmap/createImageBitmap-exif-orientation.html#L55
await t.step('"Blob" imageOrientation: "flipY"', async () => {
const imageBitmap = await createImageBitmap(imageData, {
imageOrientation: "flipY",
});
// @ts-ignore: Deno[Deno.internal].core allowed
const targetPixel = Deno[Deno.internal].getBitmapData(imageBitmap).slice(
START,
END,
);
// FIXME: When the implementation is fixed, fix this to assertEquals
// However, in the case of jpg images, numerical errors may occur.
assertNotEquals(targetPixel, new Uint8Array([254, 128, 129]));
});
});
Deno.test("imageBitmapPremultiplyAlpha", async (t) => {
const imageData = new ImageData(
new Uint8ClampedArray([