feat: Add compressed image cache with WebP/JPEG compression #2464
+197
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR adds optional image compression to the Cornerstone3D cache, reducing memory usage by 10-20x for large datasets such as ultrasound cine loops and multi-frame studies.
Problem Statement
When loading large medical imaging studies (e.g., ultrasound with 500+ frames), the browser can run out of memory even with a large cache size configured. This limits the ability to prefetch entire studies for smooth cine playback.
Solution
Implement transparent image compression in the cache:
Key Features
API Changes
New Configuration Methods
New Type Definitions
CacheCompressionConfig- Configuration interfaceICachedImageextended withcompressedBlob,compressionQuality,isCompressedNew Utilities
compressImageToBlob()- Compress Cornerstone image to blobdecompressBlobToImage()- Decompress blob back to Cornerstone imageImplementation Details
Files Modified
packages/core/src/cache/cache.ts- Core cache logic with compressionpackages/core/src/cache/index.ts- Export compression utilitiespackages/core/src/types/ICachedImage.ts- Extended interfacepackages/core/src/types/ICache.ts- Added configuration typepackages/core/src/types/index.ts- Export new typesFiles Added
packages/core/src/cache/imageCompression.ts- Compression utilitiesTesting
Tested with:
Example Usage
Breaking Changes
None - feature is disabled by default and opt-in.
Performance Characteristics
Future Enhancements
Possible future improvements:
Checklist