1- /*
2- * Copyright © 2025 Superstruct Ltd, New Zealand
3- * Licensed under libtiff license
4- *
5- * TypeScript Type Definitions for libtiff.wasm
6- * Direct C/C++ function bindings and type definitions ONLY
7- *
8- * CRITICAL: TypeScript provides ONLY thin bindings to native C/C++ functions
9- * ALL implementation logic remains in C/C++ - no JavaScript business logic
10- */
11-
12- /**
13- * Native WASM Module Interface
14- * Direct binding to Emscripten-compiled C/C++ functions
15- */
16- export interface LibTIFFWASM {
17- // Core WASM module properties
18- ready : Promise < LibTIFFWASM > ;
19- FS : any ; // Emscripten filesystem
20- HEAP8 : Int8Array ;
21- HEAP16 : Int16Array ;
22- HEAP32 : Int32Array ;
23- HEAPU8 : Uint8Array ;
24- HEAPU16 : Uint16Array ;
25- HEAPU32 : Uint32Array ;
26- HEAPF32 : Float32Array ;
27- HEAPF64 : Float64Array ;
28-
29- // Memory management (direct Emscripten bindings)
30- _malloc ( size : number ) : number ;
31- _free ( ptr : number ) : void ;
32- stackSave ( ) : number ;
33- stackRestore ( ptr : number ) : void ;
34- stackAlloc ( size : number ) : number ;
35-
36- // Emscripten runtime functions
37- cwrap ( ident : string , returnType : string , argTypes : string [ ] ) : Function ;
38- ccall ( ident : string , returnType : string , argTypes : string [ ] , args : any [ ] ) : any ;
39-
40- // Native C/C++ function bindings (ccall/cwrap wrappers)
41- libtiff_main_init ( ) : void ;
42- libtiff_webgpu_init ( ) : void ;
43- libtiff_simd_init ( ) : void ;
44-
45- // High-performance TIFF processing (native C implementation)
46- libtiff_create_from_rgba ( filename : string , rgba_data : number , width : number , height : number , compression : number ) : number ;
47- libtiff_read_to_rgba ( filename : string , width_ptr : number , height_ptr : number ) : number ;
48- libtiff_get_metadata_json ( filename : string ) : string ;
49- libtiff_batch_process ( filenames : number , count : number , operation : number ) : number ;
50-
51-
52- // Performance monitoring (native C implementation)
53- libtiff_get_performance_metrics ( ) : string ;
54- libtiff_detect_browser_capabilities ( ) : string ;
55- }
56-
57- /**
58- * TIFF Processing Configuration
59- * Direct mapping to native libtiff constants and enums
60- */
61- export interface TIFFConfig {
62- // Compression types (native libtiff constants)
63- readonly COMPRESSION_NONE : number ;
64- readonly COMPRESSION_CCITTRLE : number ;
65- readonly COMPRESSION_CCITTFAX3 : number ;
66- readonly COMPRESSION_CCITTFAX4 : number ;
67- readonly COMPRESSION_LZW : number ;
68- readonly COMPRESSION_OJPEG : number ;
69- readonly COMPRESSION_JPEG : number ;
70- readonly COMPRESSION_ADOBE_DEFLATE : number ;
71- readonly COMPRESSION_DEFLATE : number ;
72- readonly COMPRESSION_PACKBITS : number ;
73-
74- // Photometric interpretation (native libtiff constants)
75- readonly PHOTOMETRIC_MINISWHITE : number ;
76- readonly PHOTOMETRIC_MINISBLACK : number ;
77- readonly PHOTOMETRIC_RGB : number ;
78- readonly PHOTOMETRIC_PALETTE : number ;
79- readonly PHOTOMETRIC_MASK : number ;
80- readonly PHOTOMETRIC_SEPARATED : number ;
81- readonly PHOTOMETRIC_YCBCR : number ;
82- }
83-
841/**
85- * TIFF Metadata Structure
86- * Direct mapping to native TIFF directory entries
2+ * Type definitions for ${LIB_TITLE} WASM
873 */
88- export interface TIFFMetadata {
89- width : number ;
90- height : number ;
91- bitsPerSample : number [ ] ;
92- compression : number ;
93- photometric : number ;
94- samplesPerPixel : number ;
95- planarConfig : number ;
96- xResolution : number ;
97- yResolution : number ;
98- resolutionUnit : number ;
99- software ?: string ;
100- dateTime ?: string ;
101- artist ?: string ;
102- copyright ?: string ;
103- description ?: string ;
104- }
105-
1064
107- /**
108- * Performance Metrics
109- * Native C implementation provides all data
110- */
111- export interface PerformanceMetrics {
112- webgpu_utilization : number ; // GPU core usage percentage
113- simd_efficiency : number ; // SIMD instruction efficiency
114- memory_usage_mb : number ; // Current memory consumption
115- processing_speed_mpixels : number ; // Million pixels per second
116- threading_efficiency : number ; // Multi-threading utilization
5+ export interface $ { LIB_UPPER } Module {
6+ _malloc: ( size : number ) => number
7+ _free: ( ptr : number ) => void
8+ HEAPU8 : Uint8Array
9+ setValue: ( ptr : number , value : number , type : string ) => void
10+ getValue : ( ptr : number , type : string ) => number
11711}
11812
119- /**
120- * Browser Capability Detection
121- * Native C implementation checks all APIs
122- */
123- export interface BrowserCapabilities {
124- webgpu : boolean ; // WebGPU compute shader support
125- simd : boolean ; // WebAssembly SIMD support
126- threading : boolean ; // SharedArrayBuffer + Workers
127- shared_memory : boolean ; // SharedArrayBuffer support
128- audio_worklet : boolean ; // WebAudio low-latency support
129- offscreen_canvas : boolean ; // OffscreenCanvas support
130- web_codecs : boolean ; // WebCodecs API support
13+ export class $ { LIB_UPPER } Error extends Error {
14+ constructor ( message : string ) {
15+ super ( message )
16+ this . name = '${LIB_UPPER}Error'
17+ }
13118}
132-
133- /**
134- * Error Handling
135- * Native C error codes with TypeScript mapping
136- */
137- export enum TIFFError {
138- SUCCESS = 0 ,
139- FILE_NOT_FOUND = - 1 ,
140- INVALID_FORMAT = - 2 ,
141- MEMORY_ERROR = - 3 ,
142- COMPRESSION_ERROR = - 4 ,
143- WRITE_ERROR = - 5 ,
144- READ_ERROR = - 6 ,
145- WEBGPU_ERROR = - 7 ,
146- SIMD_ERROR = - 8
147- }
148-
149- /**
150- * Memory Management Helper Types
151- * For working with Emscripten heap memory
152- */
153- export interface WASMMemoryView {
154- ptr : number ; // Pointer to allocated memory
155- size : number ; // Size in bytes
156- view : Uint8Array ; // Typed array view
157- }
158-
159- /**
160- * File System Integration
161- * Emscripten filesystem operations
162- */
163- export interface WASMFileSystem {
164- writeFile ( filename : string , data : Uint8Array ) : void ;
165- readFile ( filename : string ) : Uint8Array ;
166- unlink ( filename : string ) : void ;
167- exists ( filename : string ) : boolean ;
168- mkdir ( dirname : string ) : void ;
169- rmdir ( dirname : string ) : void ;
170- }
0 commit comments