-
Notifications
You must be signed in to change notification settings - Fork 86
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
Add multiple format image files for copyToTexture,image_file cases #4135
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -626,7 +626,7 @@ const kFourColorsInfo = { | |
}, | ||
} as const; | ||
|
||
export const kImageInfo = makeTable({ | ||
export const kEXIFImageInfo = makeTable({ | ||
table: { | ||
'four-colors.jpg': kFourColorsInfo, | ||
'four-colors-rotate-90-cw.jpg': kFourColorsInfo, | ||
|
@@ -635,9 +635,25 @@ export const kImageInfo = makeTable({ | |
}, | ||
} as const); | ||
|
||
export const kImageInfo = makeTable({ | ||
table: { | ||
'four-colors.jpg': kFourColorsInfo, | ||
'four-colors.png': kFourColorsInfo, | ||
'four-colors.bmp': kFourColorsInfo, | ||
'four-colors.webp': kFourColorsInfo, | ||
'four-colors.gif': kFourColorsInfo, | ||
'four-colors.avif': kFourColorsInfo, | ||
Comment on lines
+643
to
+645
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just a note, I checked caniuse and it seems to say firefox and safari support webp and avif, so that's probably safe. Still would be worth checking that firefox and ideally safari will load all of these image files, if you haven't (just as standalone images; don't need to worry about whether their webgpu implementation supports them yet) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Firefox stable(134.0) : All image files are supported. |
||
'four-colors.ico': kFourColorsInfo, | ||
'four-colors.svg': kFourColorsInfo, | ||
}, | ||
} as const); | ||
|
||
type ImageName = keyof typeof kImageInfo; | ||
export const kImageNames: readonly ImageName[] = keysOf(kImageInfo); | ||
|
||
type EXIFImageName = keyof typeof kEXIFImageInfo; | ||
export const kEXIFImageNames: readonly EXIFImageName[] = keysOf(kEXIFImageInfo); | ||
|
||
type ObjectTypeFromFile = (typeof kObjectTypeFromFiles)[number]; | ||
export const kObjectTypeFromFiles = [ | ||
'ImageBitmap-from-Blob', | ||
|
@@ -649,12 +665,12 @@ export const kObjectTypeFromFiles = [ | |
* Load image file(e.g. *.jpg) from ImageBitmap, blob or HTMLImageElement. And | ||
* convert the result to valid source that GPUCopyExternalImageSource supported. | ||
*/ | ||
export async function GetSourceFromImageFile( | ||
export async function GetSourceFromEXIFImageFile( | ||
test: GPUTest, | ||
imageName: ImageName, | ||
exifImageName: EXIFImageName, | ||
objectTypeFromFile: ObjectTypeFromFile | ||
): Promise<ImageBitmap | HTMLImageElement> { | ||
const imageUrl = getResourcePath(imageName); | ||
const imageUrl = getResourcePath(exifImageName); | ||
|
||
switch (objectTypeFromFile) { | ||
case 'ImageBitmap-from-Blob': { | ||
|
@@ -689,3 +705,44 @@ export async function GetSourceFromImageFile( | |
} | ||
} | ||
} | ||
|
||
/** | ||
* Create HTMLImageElement and load image file and waits for it to be loaded. | ||
* Returns a promise which resolves after `callback` (which may be async) completes. | ||
* | ||
* @param imageName An valid imageName in kkImageInfo table . | ||
* @param callback Function to call when HTMLImageElement is loaded. | ||
* | ||
*/ | ||
export function loadImageFileAndRun( | ||
test: GPUTest, | ||
imageName: ImageName, | ||
callback: (image: HTMLImageElement) => unknown | Promise<unknown> | ||
kainino0x marked this conversation as resolved.
Show resolved
Hide resolved
|
||
): Promise<void> { | ||
return raceWithRejectOnTimeout( | ||
new Promise((resolve, reject) => { | ||
const callbackAndResolve = (image: HTMLImageElement) => | ||
void (async () => { | ||
try { | ||
await callback(image); | ||
resolve(); | ||
} catch (ex) { | ||
reject(ex); | ||
} | ||
})(); | ||
// 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.' | ||
); | ||
} | ||
const image = new Image(); | ||
image.src = getResourcePath(imageName); | ||
image.onload = () => { | ||
callbackAndResolve(image); | ||
}; | ||
}), | ||
2000, | ||
'Video never became ready' | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect that webp and avif also support EXIF. Not sure about any others. Possibly worth testing in a followup?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, webp indeed support EXIF. AVIF support EXIF but browser(chrome) choose to ignore that part and using
irot
instead. However, I still invesitigate how to modifyirot
for avif file.P.S. I ref to this article https://zpl.fi/exif-orientation-in-different-formats/ and did some experiment locally.