[Bf-blender-cvs] [2c463a82500] master: ImBuf: use more accurate DPI/PPM conversion

Campbell Barton noreply at git.blender.org
Thu Jun 11 07:06:57 CEST 2020


Commit: 2c463a82500e4ada715a4a0a8a00c0eb00dceb79
Author: Campbell Barton
Date:   Thu Jun 11 14:56:09 2020 +1000
Branches: master
https://developer.blender.org/rB2c463a82500e4ada715a4a0a8a00c0eb00dceb79

ImBuf: use more accurate DPI/PPM conversion

Use 0.0254 for conversion as 39.3700787 isn't exactly 1/0.0254
and can't be written as a round float/double.

===================================================================

M	source/blender/imbuf/IMB_imbuf_types.h
M	source/blender/imbuf/intern/openexr/openexr_api.cpp

===================================================================

diff --git a/source/blender/imbuf/IMB_imbuf_types.h b/source/blender/imbuf/IMB_imbuf_types.h
index 4a5f8cc1bfe..ddc8394264a 100644
--- a/source/blender/imbuf/IMB_imbuf_types.h
+++ b/source/blender/imbuf/IMB_imbuf_types.h
@@ -209,7 +209,7 @@ typedef struct ImBuf {
    */
   float *rect_float;
 
-  /* resolution - pixels per meter */
+  /** Resolution in pixels per meter. Multiply by `0.0254` for DPI. */
   double ppm[2];
 
   /* tiled pixel storage */
diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp
index 882808cbc14..0555d213b3f 100644
--- a/source/blender/imbuf/intern/openexr/openexr_api.cpp
+++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp
@@ -390,7 +390,8 @@ static void openexr_header_metadata(Header *header, struct ImBuf *ibuf)
   }
 
   if (ibuf->ppm[0] > 0.0) {
-    addXDensity(*header, ibuf->ppm[0] / 39.3700787); /* 1 meter = 39.3700787 inches */
+    /* Convert meters to inches. */
+    addXDensity(*header, ibuf->ppm[0] * 0.0254);
   }
 }
 
@@ -1920,7 +1921,8 @@ struct ImBuf *imb_load_openexr(const unsigned char *mem,
       ibuf->flags |= exr_is_half_float(*file) ? IB_halffloat : 0;
 
       if (hasXDensity(file->header(0))) {
-        ibuf->ppm[0] = xDensity(file->header(0)) * 39.3700787f;
+        /* Convert inches to meters. */
+        ibuf->ppm[0] = (double)xDensity(file->header(0)) / 0.0254;
         ibuf->ppm[1] = ibuf->ppm[0] * (double)file->header(0).pixelAspectRatio();
       }



More information about the Bf-blender-cvs mailing list