Skip to content

The Original Tool

botrx555 edited this page Jul 14, 2026 · 1 revision

The Original Tool

m8raw2dng2 is a clean-room reimplementation of Arvid Kuehl's m8raw2dng v1.20. This page records what the original tool does, established by decoding its constant pool and by running both tools on real Leica M8 diagnostic frames and comparing the output byte for byte. These facts are what Fidelity is measured against; the raw disassembly tables (constant pool, function map, tag maps) and the full verification scoreboard are on Binary Internals.

Provenance: the M8's uncompressed-RAW diagnostic mode was first surfaced on the Leica User Forum by romanvail, and the un-coded-lens aperture-estimation lineage traces to Sandy McGuffog's formula, which the original uses. See Credits and References.

The binary

property value
file m8raw2dng.exe, 141,824 bytes, PE32 (MSVC 2010)
build date 2014-02-21
copyright (C) 2013 Arvid Kuehl
homepage m8raw2dng.de

What it produces

The original's DNG is a raw passthrough: the image data equals the source RAW pixels exactly (verified original_DNG - RAW = 0, zero differing pixels, at ISO 160 / 320 / 640 / 1250 / 2500). It applies no black subtraction, no darkfield, and no defect repair during a normal conversion, and writes no BlackLevel tag on a bare conversion (observed across nine DNGs).

Under -b, however, the original does write a BlackLevel tag, and it is ISO-scaled: base_black x gain, with base_black a fixed 92 (scene independent), so 92 / 368 / 1472 at ISO 160 / 640 / 2500 (an explicit -b 500 scales likewise, to 8000 at ISO 2500). The tag is written but the pixels are never touched, and it becomes 0 when -b consumes an adjacent .BIA. m8raw2dng2's plain -b is instead a flat 92 at every ISO; it gain-scales BlackLevel only under -s. So the two tools agree under -s -b and on a bare -v (no tag), and diverge under plain -b at high ISO.

The container is a 16-bit linear DNG carrying the M8's colour: 47 IFD0 tags and 21 EXIF tags, the MakerNote copied verbatim, WhiteLevel 16383, DPI 300, crop factor 1.33 (FocalLengthIn35mmFilm = round(focal * 1.33)), and the M8 colour matrices under calibration illuminants 17 (Standard Light A) and 21 (D65). The raw CFA sits in IFD0 (the layout m8raw2dng2's default -p reproduces).

FNumber

The original's FNumber is a compressed estimate derived from the light meter, not a passthrough of the JPG's ApproximateFNumber and not a lens-database lookup. It is encoded as n / 65536. It compresses heavily toward the narrow end - a true f/16 is written as roughly f/7.75, about two stops under - and the compression grows with true aperture:

real aperture original writes error
f/2.0 ~f/2.12 0.17 stop
f/5.6 ~f/4.90 0.39 stop
f/16.0 ~f/7.75 2.09 stop

The original's exact estimator is not in the binary (a full constant scan finds no matching coefficient) and has not been decoded; m8raw2dng2's --mimic-fnumber reproduces it to about 0.2 stop with a two-parameter fit. m8raw2dng2's default meter path recovers the aperture more accurately (0.17 / 0.10 / 0.51 stop over the same frames); -A supplies an exact value. See The Math for the recovery formula.

Darkfield and sensor database (-sd)

The original's darkfield is a per-column LevelCorrection derived from a dark frame's column statistics: LevelCorrection[c] = colmean[c] - T, where T is a per-frame level scalar. T is not a fixed fraction - across a 16-frame dark corpus it drifts from 74.3 to 81.5 (an effective factor of 0.807 to 0.885), uncorrelated with brightness and unpredicted by the frame statistics tested (the exact routine is deterministic in the binary but has not been decoded). (A single frame landed at about 0.8333, which an earlier pass mistook for a fixed "5/6" factor; it is not.) It zeroes or suppresses outlier (defect) columns rather than repairing them. The sensdb it writes uses LevelCorrection = %f with six decimals, CRLF line endings, under a numeric section header.

m8raw2dng2's darkfield is the same additive per-column shape but with a fixed, deterministic target T = 0.8406 * mean(colmean) (calibrated to the ISO-160 reference) rather than the original's drifting per-frame T. The per-column shapes agree closely (correlation ~0.955, offset-removed MAD ~0.011); the residual level gap is the deliberate fixed-versus-drifting factor difference. m8raw2dng2 also repairs defect columns instead of zeroing them - a deliberate, more-accurate divergence, opt-in behind -s.

.BIA dark reference

A .BIA is a full-frame 16-bit dark reference stored in the identical M8 diagnostic-RAW container (same 21,049,052-byte size, same header, same stride). It is a full 2-D frame, not a per-column vector, and is distinct from the source RAW. The original writes .BIA files for long exposures; it does not auto-subtract an adjacent .BIA during a normal conversion. (m8raw2dng2 does auto-subtract a same-stem .BIA as a bias frame - an opt-in divergence.)

Geometry

RAW is 3968 x 2646 (54-sample header, body at stride 3976); the DNG is 3964 x 2642 with DefaultCropOrigin (2, 2). See File Formats for the full container layout.

The standard-M8-DNG input mode

Besides RAW+JPG pairs, the original has a second input mode: it reads a genuine in-camera standard M8 DNG (3920 x 2638, 8-bit) to fix its lens, EXIF and sensor issues. This is why the binary carries two width constants - 3968 for the RAW mode and 3920 for the standard-DNG mode; both are real. On this path the aperture is read directly from the DNG's EXIF (no estimation happens), and -l applies lens EXIF from lensdb. The mode is gated: feeding it a RAW+JPG-derived DNG (the tool's own output) returns Error #0019: File was created from RAW+JPG or is not a Leica M8 DNG; it accepts only genuine 8-bit in-camera M8 DNGs. On this path -sd is refused ("Darkfield estimation not possible from DNG file"), since a finished in-camera DNG carries no raw darkfield to measure. Confirmed on a real STD_M8.DNG (uncoded Summicron-C 40mm at f/2.8), which reads as 3920 x 2638, 8-bit.

m8raw2dng2 targets the RAW+JPG workflow and does not reprocess finished in-camera DNGs; the two tools overlap on the RAW path, not this one.

The original's flags

The complete original flag set is -i -o -v -r -p -b[val] -c -l[6bit] -s -sd -st. -c is a real flag (the v1.20 usage banner omits it, but it works - it swaps to the M9 colour matrices and renames Model to "M8RAW Digital Camera", pixels unchanged). Everything else in m8raw2dng2 (-A, --calibrate-fnumber, --no-crop, --legacy-preview, and the rest) is a m8raw2dng2 addition that the original silently ignores. The official droplets default to -b -p -v -r -c (Windows) and -v -r -b -p (Mac). The -st sensor-test and manual defect-line workflow is covered in Databases.

Relationship to m8raw2dng2

m8raw2dng2 is a superset: a bare -v conversion reproduces the original's raw passthrough exactly - pixels and tags identical, the estimated FNumber the only difference - and the accurate sensor corrections (-b, -s, .BIA, aperture recovery) layer on top, each opt-in. No special mode is needed for parity: omit -s and any adjacent .BIA (-b only adds a tag), and use -A for an exact aperture. The per-invocation detail is in Fidelity.

Clone this wiki locally