### Install libraw-wasm via npm Source: https://github.com/ybouane/libraw-wasm/blob/main/readme.md Install the libraw-wasm package using npm. This is the required first step before using the library. ```bash npm install libraw-wasm ``` -------------------------------- ### Basic usage of LibRaw-Wasm API Source: https://github.com/ybouane/libraw-wasm/blob/main/readme.md Shows how to import LibRaw, open a RAW file, fetch metadata, get decoded image data, and retrieve raw sensor data. The imageData() call rejects on decoding failure, so wrap it in try/catch for untrusted files. The rawImageData() returns an object with raw_width, raw_height, width, height, top_margin, left_margin, and a Uint16Array data property. ```javascript import LibRaw from 'libraw-wasm'; const output = document.getElementById('output'); // Instantiate LibRaw const raw = new LibRaw(); // Open (decode) the RAW file await raw.open(new Uint8Array(fileBuffer), { /* settings */ }); // Fetch metadata const meta = await raw.metadata(/* fullOutput=false */); console.log('Metadata:', meta); output.innerText = JSON.stringify(meta, null, 4); // Fetch the decoded image data (RGB pixels). // imageData() rejects if decoding fails (e.g. a compression format this build // can't decode), so wrap it in try/catch when handling untrusted files. try { const imageData = await raw.imageData(); console.log('Image data:', imageData); console.log('Image data length:', imageData.data.length); } catch (err) { console.error('Failed to decode image:', err); } // Fetch the raw, undebayered sensor data (16-bit mosaic, no demosaicing) const rawImageData = await raw.rawImageData(); console.log('Raw sensor data:', rawImageData); // { raw_width, raw_height, width, height, top_margin, left_margin, data: Uint16Array } ``` -------------------------------- ### Load and decode RAW file with LibRaw WASM Source: https://github.com/ybouane/libraw-wasm/blob/main/example.html This snippet shows how to use the LibRaw WASM library to read a RAW file selected by the user, configure decoding options, and retrieve metadata and image data. It listens for file selection, reads the file as an ArrayBuffer, instantiates LibRaw, opens the file with various options, and logs the results. ```javascript import LibRaw from './index.js'; const fileInput = document.getElementById('file'); const output = document.getElementById('output'); // Listen for file selection fileInput.addEventListener('change', async (event) => { const file = event.target.files[0]; if (!file) return; try { // Read the RAW file into an ArrayBuffer const arrayBuffer = await file.arrayBuffer(); console.log(arrayBuffer); // Instantiate LibRaw const raw = new LibRaw(); // Open (decode) the RAW file await raw.open(new Uint8Array(arrayBuffer), { bright: 1.0, // -b : brightness threshold: 0.0, // -n : wavelet denoise threshold autoBrightThr: 0.01, // portion of clipped pixels for auto-brightening adjustMaximumThr: 0.75, // auto-adjust max if channel overflow above threshold expShift: 1.0, // exposure shift in linear scale (requires expCorrec=1) expPreser: 0.0, // preserve highlights when expShift>1 (0..1) halfSize: false, // -h : output at 1/2 size fourColorRgb: false, // -f : separate interpolation for two green channels highlight: 0, // -H : highlight mode (0..9) useAutoWb: false, // -a : auto white balance useCameraWb: false, // -w : camera's recorded WB useCameraMatrix: 1, // +M/-M : color profile usage (0=off,1=on if WB,3=always) outputColor: 1, // -o : output colorspace (0..8) (0=raw,1=sRGB,2=Adobe, etc.) outputBps: 8, // -4 : 8 or 16 bits per sample outputTiff: false, // -T : output TIFF if true, else PPM outputFlags: 0, // bitfield for custom output flags userFlip: -1, // -t : flip/rotate (0..7, default=-1 means use RAW value) userQual: 3, // -q : interpolation quality (0..12) userBlack: -1, // -k : user black level userCblack: [-1, -1, -1, -1], // per-channel black offsets userSat: 0, // -S : saturation level medPasses: 0, // -m : median filter passes noAutoBright: false, // -W : don't apply auto brightness useFujiRotate: -1, // -j : -1=use, 0=off, 1=on, for Fuji sensor rotation greenMatching: false, // fix green channel imbalance (not a dcraw key) dcbIterations: -1, // additional DCB passes (-1=off) dcbEnhanceFl: false, // enhance color fidelity in DCB fbddNoiserd: 0, // 0=off,1=light,2=full FBDD denoise expCorrec: false, // enable exposure correction (then expShift, expPreser apply) noAutoScale: false, // skip scale_colors (affects WB) noInterpolation: false, // skip demosaic entirely (outputs raw mosaic) greybox: null, // -A x y w h : rectangle (x,y,width,height) for WB calc cropbox: null, // Cropping rectangle (left, top, w, h) applied before rotation aber: null, // -C (red multiplier = aber[0], blue multiplier = aber[2]) gamm: null, // -g power toe_slope (1/power -> gamm[0], gamm[1] -> slope) userMul: null, // -r mul0 mul1 mul2 mul3 : user WB multipliers (r, g, b, g2) outputProfile: null, // -o : output ICC profile (if compiled w/ LCMS) cameraProfile: null, // -p or 'embed' : camera ICC profile badPixels: null, // -P : file with bad pixels map darkFrame: null, // -K : file with dark frame (16-bit PGM) }); // Fetch metadata const meta = await raw.metadata(true); console.log('Metadata:', meta); output.innerText = JSON.stringify(meta, null, 4); // Fetch the decoded image data (RGB pixels) const imageData = await raw.imageData(); console.log('Image data:', imageData); // If you want to interpret the data as a PPM (for example), // you could do something like convert to a text-based PPM or // place it in a . For now, we just log it. } catch (err) { console.error('Error processing RAW:', err); } }); ``` -------------------------------- ### libraw-wasm settings object Source: https://github.com/ybouane/libraw-wasm/blob/main/readme.md JavaScript object with all configurable processing options for libraw-wasm. Each property maps to a dcraw flag (e.g., bright to -b, threshold to -n). Defaults and valid ranges are shown in comments. Use this object to customize RAW decoding behavior. ```javascript { bright: 1.0, // -b : brightness threshold: 0.0, // -n : wavelet denoise threshold autoBrightThr: 0.01, // portion of clipped pixels for auto-brightening adjustMaximumThr: 0.75, // auto-adjust max if channel overflow above threshold expShift: 1.0, // exposure shift in linear scale (requires expCorrec=1) expPreser: 0.0, // preserve highlights when expShift>1 (0..1) halfSize: false, // -h : output at 1/2 size fourColorRgb: false, // -f : separate interpolation for two green channels highlight: 0, // -H : highlight mode (0..9) useAutoWb: false, // -a : auto white balance useCameraWb: false, // -w : camera's recorded WB useCameraMatrix: 1, // +M/-M : color profile usage (0=off,1=on if WB,3=always) outputColor: 1, // -o : output colorspace (0..8) (0=raw,1=sRGB,2=Adobe, etc.) outputBps: 8, // -4 : 8 or 16 bits per sample outputTiff: false, // -T : output TIFF if true, else PPM outputFlags: 0, // bitfield for custom output flags userFlip: -1, // -t : flip/rotate (0..7, default=-1 means use RAW value) userQual: 3, // -q : interpolation quality (0..12) userBlack: -1, // -k : user black level userCblack: [-1, -1, -1, -1], // per-channel black offsets userSat: 0, // -S : saturation level medPasses: 0, // -m : median filter passes noAutoBright: false, // -W : don't apply auto brightness useFujiRotate: -1, // -j : -1=use, 0=off, 1=on, for Fuji sensor rotation greenMatching: false, // fix green channel imbalance (not a dcraw key) dcbIterations: -1, // additional DCB passes (-1=off) dcbEnhanceFl: false, // enhance color fidelity in DCB fbddNoiserd: 0, // 0=off,1=light,2=full FBDD denoise expCorrec: false, // enable exposure correction (then expShift, expPreser apply) noAutoScale: false, // skip scale_colors (affects WB) noInterpolation: false, // skip demosaic entirely (outputs raw mosaic) greybox: null, // -A x y w h : rectangle (x,y,width,height) for WB calc cropbox: null, // Cropping rectangle (left, top, w, h) applied before rotation aber: null, // -C (red multiplier = aber[0], blue multiplier = aber[2]) gamm: null, // -g power toe_slope (1/power -> gamm[0], gamm[1] -> slope) userMul: null, // -r mul0 mul1 mul2 mul3 : user WB multipliers (r, g, b, g2) outputProfile: null, // -o : output ICC profile (if compiled w/ LCMS) cameraProfile: null, // -p or 'embed' : camera ICC profile badPixels: null, // -P : file with bad pixels map darkFrame: null, // -K : file with dark frame (16-bit PGM) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.