Expand description
§OxiGDAL WASM - WebAssembly Bindings for Browser-based Geospatial Processing
This crate provides comprehensive WebAssembly bindings for OxiGDAL, enabling high-performance browser-based geospatial data processing with a focus on Cloud Optimized GeoTIFF (COG) visualization and manipulation.
§Features
§Core Capabilities
- COG Viewing: Efficient viewing of Cloud Optimized GeoTIFFs
- Tile Management: Advanced tile caching and pyramid management
- Progressive Rendering: Smooth progressive loading with adaptive quality
- Image Processing: Color manipulation, contrast enhancement, filters
- Performance Profiling: Built-in profiling and bottleneck detection
- Worker Pool: Parallel tile loading using Web Workers
- Streaming: Adaptive tile streaming with bandwidth estimation
§Advanced Features
- Compression: Multiple compression algorithms for bandwidth reduction
- Color Operations: Extensive color space conversions and palettes
- TypeScript Bindings: Auto-generated TypeScript definitions
- Error Handling: Comprehensive error types and recovery
- Viewport Management: Advanced viewport transformations and history
§Architecture
The crate is organized into several modules:
bindings: TypeScript type definitions and documentation generationcanvas: Image processing, resampling, and canvas rendering utilitiescolor: Advanced color manipulation, palettes, and color correctioncompression: Tile compression algorithms (RLE, Delta, Huffman, LZ77)error: Comprehensive error types for all operationsfetch: HTTP fetching with retry logic and parallel requestsprofiler: Performance profiling and bottleneck detectionrendering: Canvas rendering, double buffering, and progressive renderingstreaming: Adaptive tile streaming with bandwidth managementtile: Tile coordinate systems, caching, and pyramid managementworker: Web Worker pool for parallel processing
§Basic Usage Example (JavaScript)
import init, { WasmCogViewer } from '@cooljapan/oxigdal';
async function viewCog(url) {
// Initialize the WASM module
await init();
// Create a viewer instance
const viewer = new WasmCogViewer();
// Open a COG file
await viewer.open(url);
// Get image metadata
console.log(`Image size: ${viewer.width()}x${viewer.height()}`);
console.log(`Tile size: ${viewer.tile_width()}x${viewer.tile_height()}`);
console.log(`Bands: ${viewer.band_count()}`);
console.log(`Overviews: ${viewer.overview_count()}`);
// Read a tile as ImageData for canvas rendering
const imageData = await viewer.read_tile_as_image_data(0, 0, 0);
// Render to canvas
const canvas = document.getElementById('map-canvas');
const ctx = canvas.getContext('2d');
ctx.putImageData(imageData, 0, 0);
}§Advanced Usage Example (JavaScript)
import init, {
AdvancedCogViewer,
WasmImageProcessor,
WasmColorPalette,
WasmProfiler,
WasmTileCache
} from '@cooljapan/oxigdal';
async function advancedProcessing() {
await init();
// Create an advanced viewer with caching
const viewer = new AdvancedCogViewer();
await viewer.open('https://example.com/image.tif', 100); // 100MB cache
// Setup profiling
const profiler = new WasmProfiler();
profiler.startTimer('tile_load');
// Load and process a tile
const imageData = await viewer.readTileAsImageData(0, 0, 0);
profiler.stopTimer('tile_load');
// Apply color palette
const palette = WasmColorPalette.createViridis();
const imageBytes = new Uint8Array(imageData.data.buffer);
palette.applyToGrayscale(imageBytes);
// Apply image processing
WasmImageProcessor.linearStretch(imageBytes, imageData.width, imageData.height);
// Get cache statistics
const cacheStats = viewer.getCacheStats();
console.log('Cache hit rate:', JSON.parse(cacheStats).hit_count);
// Get profiling statistics
const profStats = profiler.getAllStats();
console.log('Performance:', profStats);
}§Progressive Loading Example (JavaScript)
async function progressiveLoad(url, canvas) {
const viewer = new AdvancedCogViewer();
await viewer.open(url, 100);
// Start with low quality for quick feedback
viewer.setViewportSize(canvas.width, canvas.height);
viewer.fitToImage();
const ctx = canvas.getContext('2d');
// Load visible tiles progressively
const viewport = JSON.parse(viewer.getViewport());
for (let level = viewer.overview_count(); level >= 0; level--) {
// Load tiles at this level
const imageData = await viewer.readTileAsImageData(level, 0, 0);
ctx.putImageData(imageData, 0, 0);
// Allow UI updates
await new Promise(resolve => setTimeout(resolve, 0));
}
}§Performance Considerations
§Memory Management
- The tile cache automatically evicts old tiles using LRU strategy
- Configure cache size based on available memory
- Use compression to reduce memory footprint
§Network Optimization
- HTTP range requests are used for partial file reads
- Retry logic handles network failures gracefully
- Parallel requests improve throughput
- Adaptive streaming adjusts quality based on bandwidth
§Rendering Performance
- Double buffering prevents flickering
- Progressive rendering provides quick feedback
- Web Workers enable parallel tile processing
- Canvas operations are optimized for WASM
§Error Handling
All operations return Result types that can be converted to JavaScript
exceptions. Errors are categorized by type:
FetchError: Network and HTTP errorsCanvasError: Canvas and rendering errorsWorkerError: Web Worker errorsTileCacheError: Cache management errorsJsInteropError: JavaScript interop errors
try {
await viewer.open(url);
} catch (error) {
if (error.message.includes('HTTP 404')) {
console.error('File not found');
} else if (error.message.includes('CORS')) {
console.error('Cross-origin request blocked');
} else {
console.error('Unknown error:', error);
}
}§Browser Compatibility
This crate requires:
- WebAssembly support
- Fetch API with range request support
- Canvas API
- Web Workers (optional, for parallel processing)
- Performance API (optional, for profiling)
Supported browsers:
- Chrome 57+
- Firefox 52+
- Safari 11+
- Edge 16+
§Building for Production
# Optimize for size
wasm-pack build --target web --release -- --features optimize-size
# Optimize for speed
wasm-pack build --target web --release -- --features optimize-speed
# Generate TypeScript definitions
wasm-pack build --target bundler --release§License
This crate is part of the OxiGDAL project and follows the same licensing terms.
Modules§
- component
- WASM Component Model bindings for OxiGDAL.
- wasm_
memory - WASM linear-memory management utilities.
Structs§
- Advanced
CogViewer - Advanced COG viewer with comprehensive tile management and caching
- Animation
- Basic animation state
- Animation
Manager - Animation frame manager
- Animation
Stats - Animation statistics
- Bandwidth
Estimator - Bandwidth estimator
- Batch
Tile Loader - Batch tile loader for efficient multi-tile loading
- Bottleneck
- Bottleneck information
- Bottleneck
Detector - Bottleneck detector
- Cache
Stats - Cache statistics
- Cached
Tile - Cached tile data
- Canvas
Buffer - Canvas buffer for double buffering
- Canvas
Renderer - Canvas renderer with double buffering and progressive rendering
- Channel
Histogram Json - JSON-serializable representation of a single channel histogram
- Channel
Ops - Color channel operations
- Color
Correction Matrix - Color correction matrix
- Color
Palette - Color palette
- Color
Quantizer - Color quantization
- Color
Temperature - Color temperature adjustment
- Compression
Benchmark - Compression benchmark
- Compression
Selector - Compression selector for automatic algorithm selection
- Compression
Stats - Compression statistics
- Counter
Stats - Counter statistics
- Custom
BinHistogram Json - JSON-serializable representation of a custom bin range histogram
- Delta
Compressor - Delta encoding compression
- DocGenerator
- Documentation generator
- Enhanced
Fetch Backend - Enhanced fetch backend with retry logic and statistics
- Fetch
Backend - HTTP fetch backend using browser’s fetch API
- Fetch
Stats - Fetch statistics
- Frame
Rate Stats - Frame rate statistics
- Frame
Rate Tracker - Frame rate tracker
- GeoJson
Exporter - GeoJSON export utilities
- Gradient
Generator - Color gradient generator
- Histogram
- Image histogram
- Histogram
Json - JSON-serializable representation of the full histogram
- Hsv
- Color in HSV color space
- Huffman
Compressor - Simplified Huffman encoding
- Image
Processor - Image processing utilities
- Image
Stats - Image statistics
- Importance
Calculator - Tile importance calculator
- Lz77
Compressor - LZ77-style compression
- Memory
Monitor - Memory monitor
- Memory
Snapshot - Memory snapshot
- Memory
Stats - Memory statistics
- Multi
Resolution Streamer - Multi-resolution tile streamer
- Palette
Entry - Color palette entry
- PanAnimation
- Animation for panning the viewport
- Pending
Job - Pending job information
- Performance
Counter - Performance counter
- Pool
Stats - Worker pool statistics
- Prefetch
Scheduler - Prefetch scheduler
- Prioritized
Request - Prioritized fetch request
- Profiler
- Performance profiler
- Profiler
Summary - Profiler summary
- Progressive
Loader - Progressive loader for prioritized tile loading
- Progressive
Render Stats - Progressive rendering statistics
- Progressive
Renderer - Progressive rendering manager
- Quality
Adapter - Quality adapter for dynamic quality adjustment based on bandwidth
- Request
Queue - Request queue with priority management
- Resampler
- Image resampler
- Retry
Config - Retry configuration
- Rgb
- Color in RGB color space
- RleCompressor
- Run-length encoding compression
- Spring
Animation - Spring animation using physics simulation
- Stream
Buffer - Stream buffer for managing loaded tiles
- Stream
Buffer Stats - Stream buffer statistics
- Streaming
Stats - Streaming statistics
- Tile
Bounds - Tile bounds in the pyramid
- Tile
Cache - LRU tile cache
- Tile
Compressor - Unified compression interface
- Tile
Coord - Tile coordinate in a pyramid
- Tile
Prefetcher - Tile prefetcher
- Tile
Pyramid - Tile pyramid metadata
- Tile
Streamer - Progressive tile streamer
- TsClass
- Class definition
- TsFunction
- Function signature
- TsInterface
- Interface definition
- TsModule
- Module definition
- TsParameter
- Function parameter
- TsType
Alias - Type alias definition
- Viewport
- Viewport for managing the visible area of the image
- Viewport
History - Viewport history for undo/redo
- Viewport
State - Viewport state with transformation and bounds
- Viewport
Transform - Viewport transformation matrix
- Wasm
CogViewer - WASM-compatible COG (Cloud Optimized GeoTIFF) viewer
- Wasm
Color Palette - WASM bindings for color operations
- Wasm
Image Processor - WASM bindings for canvas operations
- Wasm
Profiler - WASM bindings for profiler
- Wasm
Tile Cache - WASM bindings for tile management
- Wasm
Worker Pool - WASM bindings for worker pool (for demonstration/testing)
- White
Balance - White balance adjustment
- Worker
Info - Worker information
- Worker
JobRequest - Worker job request
- Worker
JobResponse - Worker job response
- Worker
Pool - Worker pool for parallel tile loading
- YCbCr
- Color in YCbCr color space
- Zoom
Animation - Animation for zooming the viewport
Enums§
- Canvas
Error - Canvas rendering errors
- Compression
Algorithm - Compression algorithm
- Contrast
Method - Contrast enhancement methods
- Easing
- Easing function types
- Fetch
Error - Fetch-related errors
- JobStatus
- Job status
- JsInterop
Error - JavaScript interop errors
- Load
Strategy - Load strategy for streaming
- Prefetch
Strategy - Prefetching strategy
- Render
Quality - Rendering quality levels
- Request
Priority - Request priority
- Resample
Method - Resampling methods
- Streaming
Quality - Streaming quality level
- Tile
Cache Error - Tile cache errors
- TsType
- TypeScript type representation
- Wasm
Error - Comprehensive WASM error types
- Worker
Error - Web Worker errors
- Worker
Request Type - Worker request types
- Worker
Response Type - Worker response types
Traits§
- Easing
Function - Trait for applying easing functions
Functions§
- create_
oxigdal_ wasm_ docs - Creates the standard OxiGDAL WASM bindings documentation
- init
- Initialize the WASM module with better error handling
- is_
tiff_ url - Checks if the given URL points to a TIFF file by reading the header
- version
- Version information
Type Aliases§
- JobId
- Unique job identifier
- Wasm
Result - Result type for WASM operations