Currently only compressed files from Nikon Z7 are decoded correctly.
This first patch adds support for 12-bit uncompressed files. Still working on support for 14-bit uncompressed files.
diff --git a/rtengine/dcraw.cc b/rtengine/dcraw.cc
index bd9fa4b47..030946416 100644
--- a/rtengine/dcraw.cc
+++ b/rtengine/dcraw.cc
@@ -6692,6 +6692,9 @@ void CLASS apply_tiff()
load_raw = &CLASS unpacked_load_raw;
load_flags = 4;
order = 0x4d4d;
+ } else if ((raw_width * raw_height * 2 * tiff_bps) / 16 == tiff_ifd[raw].bytes) {
+ // 12 bit uncompressed from Nikon Z7
+ load_raw = &CLASS packed_load_raw;
} else
load_raw = &CLASS nikon_load_raw; break;
case 65535:
I forgot to mention that you can find Nikon Z7 files on raw.pixls.us. Just search for nikon z
@heckflosse
Ingo
I tested , works fine, but the rawfile is mediocre :)
Jacques
@Desmis Jacques, thanks for testing. For the 14-bit uncompressed file I have no solution atm :(
@heckflosse
Other raws files from Z7
https://www.imaging-resource.com/news/2018/09/14/nikon-z7-first-shots-lab-sample-images-with-a-final-production-camera
Currently I've no solution for Nikon Z7 uncompressed 14-bit files. I managed to decode them geometrically correct (correct width and height). But still the colours are far off (not caused by matrix, but caused by something else). I can add the code for correct width and height, so we don't have to think about that in future again. Then I would like to commit and move this issue from 5.5 to 5.6 milestone.
Any objections?
@heckflosse
Ingo
No objections :)
14-bit uncompressed should now be supported by libraw:
https://github.com/LibRaw/LibRaw/blob/9e0bf8e225695d68d89cbe605136ea66e0ce17bf/src/libraw_cxx.cpp#L1909
Here's a patch for porting libraw's code.
diff --git a/rtengine/dcraw.cc b/rtengine/dcraw.cc
--- a/rtengine/dcraw.cc
+++ b/rtengine/dcraw.cc
@@ -6804,13 +6804,15 @@
} else if ((raw_width * 2 * tiff_bps / 16 + 8) * raw_height == tiff_ifd[raw].bytes) {
// 14 bit uncompressed from Nikon Z7, still wrong
// each line has 8 padding byte.
- row_padding = 8;
- load_raw = &CLASS packed_load_raw;
+ //row_padding = 8;
+ //load_raw = &CLASS packed_load_raw;
+ load_raw = &CLASS nikon_14bit_load_raw;
} else if ((raw_width * 2 * tiff_bps / 16 + 12) * raw_height == tiff_ifd[raw].bytes) {
// 14 bit uncompressed from Nikon Z6, still wrong
// each line has 12 padding byte.
- row_padding = 12;
- load_raw = &CLASS packed_load_raw;
+ // row_padding = 12;
+ // load_raw = &CLASS packed_load_raw;
+ load_raw = &CLASS nikon_14bit_load_raw;
} else
load_raw = &CLASS nikon_load_raw; break;
case 65535:
@@ -10612,6 +10614,48 @@
#include "fujicompressed.cc"
+//-----------------------------------------------------------------------------
+/* Taken from LibRaw
+
+LibRaw is free software; you can redistribute it and/or modify
+it under the terms of the one of two licenses as you choose:
+1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1
+ (See file LICENSE.LGPL provided in LibRaw distribution archive for details).
+2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
+ (See file LICENSE.CDDL provided in LibRaw distribution archive for details).
+ */
+
+namespace {
+
+inline void unpack7bytesto4x16_nikon(unsigned char *src, unsigned short *dest)
+{
+ dest[3] = (src[6] << 6) | (src[5] >> 2);
+ dest[2] = ((src[5] & 0x3) << 12) | (src[4] << 4) | (src[3] >> 4);
+ dest[1] = (src[3] & 0xf) << 10 | (src[2] << 2) | (src[1] >> 6);
+ dest[0] = ((src[1] & 0x3f) << 8) | src[0];
+}
+
+} // namespace
+
+void CLASS nikon_14bit_load_raw()
+{
+ const unsigned linelen = (unsigned)(ceilf((float)(raw_width * 7 / 4) / 16.0)) * 16; // 14512; // S.raw_width * 7 / 4;
+ const unsigned pitch = raw_width; //S.raw_pitch ? S.raw_pitch / 2 : S.raw_width;
+ unsigned char *buf = (unsigned char *)malloc(linelen);
+ merror(buf, "nikon_14bit_load_raw()");
+ for (int row = 0; row < raw_height; row++)
+ {
+ unsigned bytesread = fread(buf, 1, linelen, ifp);
+ unsigned short *dest = &raw_image[pitch * row];
+ //swab32arr((unsigned *)buf, bytesread / 4);
+ for (int sp = 0, dp = 0; dp < pitch - 3 && sp < linelen - 6 && sp < bytesread - 6; sp += 7, dp += 4)
+ unpack7bytesto4x16_nikon(buf + sp, dest + dp);
+ }
+ free(buf);
+}
+
+//-----------------------------------------------------------------------------
+
/* RT: Delete from here */
/*RT*/#undef SQR
/*RT*/#undef MAX
diff --git a/rtengine/dcraw.h b/rtengine/dcraw.h
--- a/rtengine/dcraw.h
+++ b/rtengine/dcraw.h
@@ -517,6 +517,8 @@
}
}
+void nikon_14bit_load_raw(); // ported from LibRaw
+
};
patch included in W64 nightly builds https://keybase.pub/gaaned92/RTW64NightlyBuilds/
Not tested by me.
@agriggio as the 5.6 feature-freeze is in 2-4 weeks, ok to commit the patch to get more testing?
All Nikon Z 7 raw file types from RPU open fine.
Most helpful comment
All Nikon Z 7 raw file types from RPU open fine.