1.0.3 • Published 6 years ago

dcraw v1.0.3

Weekly downloads
16
License
GPL-2.0
Repository
github
Last release
6 years ago

dcraw.js

Convert RAW camera images using JavaScript (supported on Node.js and your Browser)

This project is a port of dcraw.c using Emscripten.

Install:

Node.js

npm install dcraw

Browser

<script src="https://cdn.jsdelivr.net/npm/dcraw"></script>

Usage

Read a RAW image file into a buffer (or Uint8Array in the browser, see browser example here)

const fs = require('fs');
const buf = fs.readFileSync('./example.CR2');
Get Image Metadata

Parse the file for metadata

const dcraw = require('dcraw');
dcraw(buf, { verbose: true, identify: true });

Result

>   Filename: raw_buf
    Timestamp: Thu Sep 21 07:17:42 2017
    Camera: Canon EOS 20D
    Owner: unknown
    ISO speed: 3200
    Shutter: 252.0 sec
    Aperture: f/inf
    Focal length: 0.0 mm
    Embedded ICC profile: no
    Number of raw images: 1
    Thumb size:  1536 x 1024
    Full size:   3596 x 2360
    Image size:  3522 x 2348
    Output size: 3522 x 2348
    Raw colors: 3
    Filter pattern: RG/GB
    Daylight multipliers: 2.098645 0.930145 1.180146
    Camera multipliers: 1021.000000 1015.000000 1018.000000 1015.000000
Convert to TIFF

Convert to TIFF file, and save to disk

const tiffFile = dcraw(buf, { exportAsTiff: true });
fs.writeFileSync('example.tiff', tiffFile)

Options

You may use the same options that dcraw supports by providing the flags directly, or you may use the following human friendly versions.

Example
// The following dcraw command, can be written two ways using dcraw.js
// dcraw -T -4 -E <filename>

// Both of these do the same thing
dcraw(buf, { T: true, 4: true, E: true });
dcraw(buf, { exportAsTiff: true, use16BitLinearMode: true, useExportMode: true });
Options List
OptionTypeDescription
verbosebooleanPrint verbose messages
identifybooleanIdentify files without decoding them (use with '-v' to identify files and show metadata)
extractThumbnailbooleanExtract embedded thumbnail image
useCameraWhiteBalancebooleanUse camera white balance, if possible
useAverageWhiteBalancebooleanAverage the whole image for white balance
whiteBalanceBoxx y w hAverage a grey box for white balance
useCustomWhiteBalancer g b gSet custom white balance
useEmbeddedColorMatrixbooleanUse/don't use an embedded color matrix
correctChromaticAberrationr bCorrect chromatic aberration
deadPixelFilebufferFix the dead pixels listed in this file
darkFrameFilebufferSubtract dark frame (16-bit raw PGM)
setDarknessLevelnumSet the darkness level
setSaturationLevelnumSet the saturation level
setWaveletThresholdnumSet threshold for wavelet denoising
setHighlightMode0-9Highlight mode (0=clip, 1=unclip, 2=blend, 3+=rebuild)
setFlipMode0-7Flip image (0=none, 3=180, 5=90CCW, 6=90CW)
setColorSpace0-6Output colorspace (raw,sRGB,Adobe,Wide,ProPhoto,XYZ,ACES)
setICCFromFilebufferApply output ICC profile from file
setICCFromCamerabufferApply camera ICC profile from file or "embed"
useDocumentModebooleanDocument mode (no color, no interpolation, no debayer)
useRawModebooleanDocument mode without scaling (totally raw)
useExportModebooleanDocument mode without cropping
setNoStretchModebooleanDon't stretch or rotate raw pixels
setNoAutoBrightnessModebooleanDon't automatically brighten the image
setBrightnessLevelnumAdjust brightness (default = 1.0)
setCustomGammaCurvep tsSet custom gamma curve (default = 2.222 4.5)
setInterpolationQuality0-3Set the interpolation quality
setHalfSizeModebooleanHalf-size color image (twice as fast as "-q 0")
setFourColorModebooleanInterpolate RGGB as four colors
setMedianFilternumApply a 3x3 median filter to R-G and B-G
setImageCount0..N-1Select one raw image or "all" from each file
use16BitModebooleanWrite 16-bit instead of 8-bit
use16BitLinearModebooleanLinear 16-bit, same as "-6 -W -g 1 1"
exportAsTiffbooleanWrite TIFF instead of PPM

Browser Example

You'll need to do a little bit of work to get a file buffer on the browser. There is a full example available here.

var reader = new FileReader();

reader.onload = function (e) {
    // Get the image file as a buffer
    var buf = new Uint8Array(e.currentTarget.result);

    // Get the RAW metadata
    const metadata = dcraw(buf, { verbose: true, identify: true });
};

reader.readAsArrayBuffer(file);
1.0.3

6 years ago

1.0.2

6 years ago

1.0.0

6 years ago