From d1dfe2aeddfc7b9cf7edb3b5d8ed6d0734329202 Mon Sep 17 00:00:00 2001
From: Pascal de Bruijn <pmjdebruijn@pcode.nl>
Date: Sun, 23 Dec 2012 01:23:09 +0100
Subject: [PATCH 0001] exif.cc: replace raw dimensions with output
 dimensions

---
 src/common/exif.cc              |    8 +++++++-
 src/common/exif.h               |    2 +-
 src/common/imageio.c            |    2 +-
 src/control/jobs/control_jobs.c |    2 +-
 4 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/common/exif.cc b/src/common/exif.cc
index 4712788..a519acc 100644
--- a/src/common/exif.cc
+++ b/src/common/exif.cc
@@ -790,7 +790,7 @@ int dt_exif_write_blob(uint8_t *blob,uint32_t size, const char* path)
   return 1;
 }
 
-int dt_exif_read_blob(uint8_t *buf, const char* path, const int sRGB, const int imgid)
+int dt_exif_read_blob(uint8_t *buf, const char* path, const int sRGB, const int imgid, const int out_width, const int out_height)
 {
   try
   {
@@ -958,6 +958,12 @@ int dt_exif_read_blob(uint8_t *buf, const char* path, const int sRGB, const int
     else
       exifData["Exif.Photo.ColorSpace"] = uint16_t(0xFFFF); /* Uncalibrated */
 
+    /* Replace RAW dimension with output dimensions (for example after crop/scale) */
+    if (out_width > 0)
+      exifData["Exif.Photo.PixelXDimension"] = out_width;
+    if (out_height > 0)
+      exifData["Exif.Photo.PixelYDimension"] = out_height;
+
     exifData["Exif.Image.Software"] = PACKAGE_STRING;
 
     // TODO: find a nice place for the missing metadata (tags, publisher, colorlabels?). Additionally find out how to embed XMP data.
diff --git a/src/common/exif.h b/src/common/exif.h
index d8cdbea..8cb6463 100644
--- a/src/common/exif.h
+++ b/src/common/exif.h
@@ -34,7 +34,7 @@ extern "C"
   int dt_exif_read_from_blob(dt_image_t *img, uint8_t *blob, const int size);
 
   /** write exif to blob, return length in bytes. blob needs to be as large at 65535 bytes. sRGB should be true if sRGB colorspace is used as output. */
-  int dt_exif_read_blob(uint8_t *blob, const char* path, const int sRGB, const int imgid);
+  int dt_exif_read_blob(uint8_t *blob, const char* path, const int sRGB, const int imgid, const int out_width, const int out_height);
 
   /** write blob to file exif. merges with existing exif information.*/
   int dt_exif_write_blob(uint8_t *blob, uint32_t size, const char* path);
diff --git a/src/common/imageio.c b/src/common/imageio.c
index bc40788..aa001f2 100644
--- a/src/common/imageio.c
+++ b/src/common/imageio.c
@@ -657,7 +657,7 @@ int dt_imageio_export_with_flags(
     uint8_t exif_profile[65535]; // C++ alloc'ed buffer is uncool, so we waste some bits here.
     char pathname[1024];
     dt_image_full_path(imgid, pathname, 1024);
-    length = dt_exif_read_blob(exif_profile, pathname, sRGB, imgid);
+    length = dt_exif_read_blob(exif_profile, pathname, sRGB, imgid, processed_width, processed_height);
 
     res = format->write_image (format_params, filename, outbuf, exif_profile, length, imgid);
   }
diff --git a/src/control/jobs/control_jobs.c b/src/control/jobs/control_jobs.c
index dadcf23..9928ae5 100644
--- a/src/control/jobs/control_jobs.c
+++ b/src/control/jobs/control_jobs.c
@@ -507,7 +507,7 @@ int32_t dt_control_merge_hdr_job_run(dt_job_t *job)
   uint8_t exif[65535];
   char pathname[DT_MAX_PATH_LEN];
   dt_image_full_path(first_imgid, pathname, DT_MAX_PATH_LEN);
-  const int exif_len = dt_exif_read_blob(exif, pathname, 0, first_imgid);
+  const int exif_len = dt_exif_read_blob(exif, pathname, 0, first_imgid, 0, 0);
   char *c = pathname + strlen(pathname);
   while(*c != '.' && c > pathname) c--;
   g_strlcpy(c, "-hdr.dng", sizeof(pathname)-(c-pathname));
-- 
1.7.9.5

