mirror of
https://github.com/storytold/lightcraft.git
synced 2026-10-14 19:27:01 -04:00
Part of #535 (item 1). Stacked on #542 (SR2 black levels); supersedes its positional keystream tables. - White balance is WB_RGGBLevels (0x7313), the gains the camera applied: the raw IFD's plain copy when present, else the copy in the encrypted SR2SubIFD, which every ARW from the DSLR-A200 on carries (identical to the plain one on all 57 CC0 files that have both). The maker note's Tag2010 gains stay only as a last resort. - 14 bodies had no white balance and rendered green whenever the camera look was rejected (A450 ... A700, NEX-3/5/C3, SLT-A33/A35/A55, ILCE-6001, UMC-R10C). On others Tag2010 missed the applied gains by up to 100 % (ILCE-3500 at 5600 K: R -31 / B +101 % against the camera JPEG's neutral pixels, now +4 / +0 %; ILCE-7S on Shade -9 / +15 -> -1 / +1 %; SLT-A57 -25 / +26 -> -6 / -3 %). - New vendor/sr2.rs decrypts the whole SR2SubIFD, found black-box: exiftool -v5's decrypted dump as known plaintext gives the keystream (key 11 22 33 44, the same at every position in 126 CC0 ARWs from 97 bodies, 15 layouts); an exhaustive search over lag pairs found k[n] = k[n-63] ^ k[n-127] on 32-bit words, so the first 127 words generate the rest, matching all 126 files (5.2 MB of keystream). - The SR2 black level (0x7310) is now read through the same decryptor, replacing #542's head and per-position keystream tables: one SR2 decryption path. Identical results on all 131 Sony files (every value #542 decoded; the 51 it could not are the files' plain 0x7310). Unit tests pin the keystream against answers recorded without the generator: every byte #542 and #148 had recovered, the SHA-256 of the whole 62112-byte keystream recovered from the CC0 DSLR-A700 sample, and the encrypted WB_RGGBLevels of four CC0 files (one per layout) with the levels ExifTool decrypts. - Sweep (4f350c4 -> this): gains equal ExifTool's decrypted WB_RGGBLevels on all 100 decoded CC0 CFA files; on 83 files with >= 200 JPEG-neutral pixels, within 10 % of the camera's applied gains 71 -> 83, over 10 % 5 -> 0. Accepted fits unchanged (max 0.15 dE); forced fallback median dE 18.50 -> 18.06, neutral-area cast on the 22 changed files 8.8 -> 1.2. - Corpus test for five CC0 samples (A500, A33, A700, ILCE-3500 5600 K, ILCE-7S Shade; three added to RAW_SAMPLES); the pre-2017 test's gains move to WB_RGGBLevels (RX100 III, RX100, ILCE-7RM2: within 2.6 % of the old Tag2010 values in Auto). Synthetic tests for decryption, directory parsing, source precedence, black level through the full DNGPrivateData chain, and hostile input; #542's layout tests (incl. the A700 trap) now run through the decryptor. - Render cache version 25. Co-Authored-By: Claude Opus 5.5 <[email protected]>