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

CopyEI2T: Cases To Cover Rotated Images #4111

Merged
merged 13 commits into from
Jan 7, 2025
2 changes: 1 addition & 1 deletion src/webgpu/web_platform/copyToTexture/image_file.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ g.test('from_orientation_metadata_file')
const kColorFormat = 'rgba8unorm';

// Load image file.
const source = await GetSourceFromImageFile(imageName, objectTypeFromFile);
const source = await GetSourceFromImageFile(t, imageName, objectTypeFromFile);
const width = source.width;
const height = source.height;

Expand Down
16 changes: 15 additions & 1 deletion src/webgpu/web_platform/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -650,24 +650,38 @@ export const kObjectTypeFromFiles = [
* convert the result to valid source that GPUCopyExternalImageSource supported.
*/
export async function GetSourceFromImageFile(
test: GPUTest,
imageName: ImageName,
objectTypeFromFile: ObjectTypeFromFile
): Promise<ImageBitmap | HTMLImageElement> {
const imageUrl = getResourcePath(imageName);

switch (objectTypeFromFile) {
case 'ImageBitmap-from-Blob': {
// MAINTENANCE_TODO: resource folder path when using service worker is not correct. Return
kainino0x marked this conversation as resolved.
Show resolved Hide resolved
// the correct path to load resource in correct place.
// The wrong path: /out/webgpu/webworker/web_platform/copyToTexture/resources
if (globalThis.constructor.name === 'ServiceWorkerGlobalScope') {
test.skip('Try to load image resource from serivce worker but the path is not correct.');
}
// Load image file through fetch.
const response = await fetch(imageUrl);
return createImageBitmap(await response.blob());
}
case 'ImageBitmap-from-Image':
case 'Image': {
// Skip test if HTMLImageElement is not available, e.g. in worker.
if (typeof HTMLImageElement === 'undefined') {
test.skip(
'Try to use HTMLImage do image file decoding but HTMLImageElement not available.'
);
}

// Load image file through HTMLImageElement.
const image = new Image();
image.src = imageUrl;
await raceWithRejectOnTimeout(image.decode(), 5000, 'decode image timeout');
if (objectTypeFromFile === 'Image') {
await raceWithRejectOnTimeout(image.decode(), 5000, 'decode image timeout');
return image;
}

Expand Down