fix(raw): match LibRaw on RAF and unpacked NEF layouts; drop frame copies

Cross-checking synthetic files with LibRaw's dcraw_emu showed it reads
uncompressed RAF samples as little-endian words and unpacked data under
the Nikon compression tag as big-endian words shifted left by four; the
readers and test writers now do the same (CR2, lossless NEF, ARW2 and
PEF already decoded identically, ~86 dB). The default crop and the
final orientation step no longer copy a full frame when they change
nothing, lowering the 24 MP peak by two frame copies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-02 11:43:45 +00:00
1 parent 0f3fbfdad4
commit bcf0510a8e
6 files changed
+72 -43

No files matched your search

+4 -3
View File
@@ -140,8 +140,9 @@ internal static class NativeRaw
}
}
/// <summary>Uncompressed raw payloads: 16-bit words (either byte order) or MSB-first packed samples (TIFF convention).</summary>
internal sealed class PlainRawLoader(long offset, long length, int width, int height, int bits, bool words, bool littleEndian) : RawLoader
/// <summary>Uncompressed raw payloads: 16-bit words (either byte order, optionally holding the value shifted left by
/// <paramref name="shift"/> bits) or MSB-first packed samples (TIFF convention).</summary>
internal sealed class PlainRawLoader(long offset, long length, int width, int height, int bits, bool words, bool littleEndian, int shift = 0) : RawLoader
{
public override RawSamples Load(Stream stream, int maxDegreeOfParallelism, CancellationToken cancellationToken)
{
@@ -157,7 +158,7 @@ internal sealed class PlainRawLoader(long offset, long length, int width, int he
if (words)
{
for (var x = 0; x < width; x++)
dst[x] = (ushort)((littleEndian ? row[2 * x] | row[2 * x + 1] << 8 : row[2 * x] << 8 | row[2 * x + 1]) & mask);
dst[x] = (ushort)((littleEndian ? row[2 * x] | row[2 * x + 1] << 8 : row[2 * x] << 8 | row[2 * x + 1]) >> shift & mask);
return;
}
long bit = 0;