@@ -7,10 +7,36 @@ import type { ExternalImageSource } from './texture.ts';
77export function getImageSourceDimensions (
88 source : ExternalImageSource ,
99) : { width : number ; height : number } {
10- if ( 'displayWidth' in source && 'displayHeight' in source ) {
11- return { width : source . displayWidth , height : source . displayHeight } ;
10+ // We used to do it this way but it fails on React Native (ImageBitmap is probably a proxy there)
11+ // if ('displayWidth' in source && 'displayHeight' in source) {
12+ // return { width: source.displayWidth, height: source.displayHeight };
13+ // }
14+
15+ const { videoWidth, videoHeight } = source as HTMLVideoElement ;
16+ if ( videoWidth && videoHeight ) {
17+ return { width : videoWidth , height : videoHeight } ;
1218 }
13- return { width : source . width as number , height : source . height as number } ;
19+
20+ const { naturalWidth, naturalHeight } = source as HTMLImageElement ;
21+ if ( naturalWidth && naturalHeight ) {
22+ return { width : naturalWidth , height : naturalHeight } ;
23+ }
24+
25+ const { codedWidth, codedHeight } = source as VideoFrame ;
26+ if ( codedWidth && codedHeight ) {
27+ return { width : codedWidth , height : codedHeight } ;
28+ }
29+
30+ const { width, height } = source as ImageBitmap || HTMLCanvasElement ||
31+ OffscreenCanvas || HTMLImageElement || ImageData ;
32+
33+ if ( ! width || ! height ) {
34+ throw new Error (
35+ 'Cannot determine dimensions of the provided image source.' ,
36+ ) ;
37+ }
38+
39+ return { width, height } ;
1440}
1541
1642type CachedResources = {
0 commit comments