MCPcopy Create free account
hub / github.com/ColmapView/Colmapview.github.io / loadFrustumBitmapFromFile

Function loadFrustumBitmapFromFile

src/hooks/useFrustumTexture.ts:77–111  ·  view source on GitHub ↗
(
  imageFile: File,
  imageName: string
)

Source from the content-addressed store, hash-verified

75}
76
77async 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.

Callers 4

prefetchFrustumTexturesFunction · 0.85
prioritizeFrustumTextureFunction · 0.85
useFrustumTextureFunction · 0.85

Calls 7

getCachedFrustumBitmapFunction · 0.90
getMethod · 0.80
deleteMethod · 0.80
closeMethod · 0.65

Tested by

no test coverage detected