Add new comment

Getting all available data and still get the right active area from DNG

Hello, I have a DNG file that specifies DefaultCropOrigin and DefaultCropSize in its metadata. Using libraw I'd like to get all the sensor data available in the DNG file while still retaining informations about the default crop, so that the extra data doesn't get trimmed at this point.
I've patched dcraw_common.cpp to read the default crop info, but I'm still unable to get the result I want.

For reference this is my patch, though at this point I'm not sure this is the right way to do it:

diff --git a/internal/dcraw_common.cpp b/internal/dcraw_common.cpp
index 35af338..8b7e2c9 100644
--- a/internal/dcraw_common.cpp
+++ b/internal/dcraw_common.cpp
@@ -10216,6 +10216,8 @@ int CLASS parse_tiff_ifd (int base)
#ifndef LIBRAW_LIBRARY_BUILD
FILE *sfp;
#endif
+ int def_crop_x = 0, def_crop_y = 0;
+ int def_crop_width = 0, def_crop_height = 0;

if (tiff_nifds >= sizeof tiff_ifd / sizeof tiff_ifd[0])
return 1;
@@ -11090,6 +11092,15 @@ guess_cfa_pc:
if(pixel_aspect > 0.995 && pixel_aspect < 1.005)
pixel_aspect = 1.0;
break;
+
+ case 50719: /* DefaultCropOrigin */
+ def_crop_x = getint(type);
+ def_crop_y = getint(type);
+ break;
+ case 50720: /* DefaultCropSize */
+ def_crop_width = getint(type);
+ def_crop_height = getint(type);
+ break;
#ifdef LIBRAW_LIBRARY_BUILD
case 50778:
imgdata.color.dng_color[0].illuminant = get2();
@@ -11247,6 +11258,14 @@ guess_cfa_pc:
}
fseek (ifp, save, SEEK_SET);
}
+ top_margin += def_crop_y;
+ left_margin += def_crop_x;
+ if (def_crop_width) {
+ width = def_crop_width;
+ }
+ if (def_crop_height) {
+ height = def_crop_height;
+ }
if (sony_length && sony_length < 10240000 && (buf = (unsigned *) malloc(sony_length))) {
fseek (ifp, sony_offset, SEEK_SET);
fread (buf, sony_length, 1, ifp);

Following the explanation here, https://www.libraw.org/comment/3177#comment-3177 setting width and height like that causes the internal data array to be of the cropped size, thus in my code (oiiotool from openimageio really) I get black borders around the active area and the original data is lost. How should I go about preserving the original data and still be able to retrieve the active area size?

Forums: