( imageFile: File, imageName: string )
| 75 | } |
| 76 | |
| 77 | async function loadFrustumBitmapFromFile( |
| 78 | imageFile: File, |
| 79 | imageName: string |
| 80 | ): Promise<ImageBitmap | null> { |
| 81 | const cached = getCachedFrustumBitmap(bitmapCache, imageName); |
| 82 | if (cached) return cached; |
| 83 | |
| 84 | const existingLoad = frustumBitmapLoads.get(imageName); |
| 85 | if (existingLoad) return existingLoad; |
| 86 | |
| 87 | const loadGeneration = frustumBitmapCacheGeneration; |
| 88 | const load = createImageBitmapWithTimeout(imageFile, FRUSTUM_BITMAP_DECODE_TIMEOUT) |
| 89 | .then((decodedBitmap) => resizeImageBitmapToMaxSizeWithTimeout( |
| 90 | decodedBitmap, |
| 91 | SIZE.frustumMaxSize, |
| 92 | FRUSTUM_BITMAP_DECODE_TIMEOUT |
| 93 | )) |
| 94 | .then((bitmap) => { |
| 95 | if (loadGeneration !== frustumBitmapCacheGeneration) { |
| 96 | bitmap.close(); |
| 97 | return null; |
| 98 | } |
| 99 | |
| 100 | bitmapCache.set(imageName, { bitmap, lastUsed: Date.now() }); |
| 101 | notifyFrustumTextureCacheChanged(); |
| 102 | return bitmap; |
| 103 | }) |
| 104 | .catch(() => null) |
| 105 | .finally(() => { |
| 106 | frustumBitmapLoads.delete(imageName); |
| 107 | }); |
| 108 | |
| 109 | frustumBitmapLoads.set(imageName, load); |
| 110 | return load; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Return a cached resized bitmap for image-plane texture creation. |
no test coverage detected