---
 frontend/scanimage.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/frontend/scanimage.c b/frontend/scanimage.c
index 77c2288..432c2ea 100644
--- a/frontend/scanimage.c
+++ b/frontend/scanimage.c
@@ -1165,9 +1165,12 @@ write_pnm_header (SANE_Frame format, int width, int 
height, int depth, FILE *ofp
 
 #ifdef HAVE_LIBPNG
 static void
-write_png_header (SANE_Frame format, int width, int height, int depth, FILE 
*ofp, png_structp* png_ptr, png_infop* info_ptr)
+write_png_header (SANE_Frame format, int width, int height, int depth, int 
dpi, FILE *ofp, png_structp* png_ptr, png_infop* info_ptr)
 {
   int color_type;
+  /* PNG does not have imperial reference units, so we must convert to metric. 
*/
+  /* There are nominally 39.3700787401575 inches in a meter. */
+  const double pixels_per_meter = dpi * 39.3700787401575;
 
   *png_ptr = png_create_write_struct
        (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
@@ -1200,6 +1203,10 @@ write_png_header (SANE_Frame format, int width, int 
height, int depth, FILE *ofp
     depth, color_type, PNG_INTERLACE_NONE,
     PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
 
+  png_set_pHYs(*png_ptr, *info_ptr,
+    pixels_per_meter, pixels_per_meter,
+    PNG_RESOLUTION_METER);
+
   png_write_info(*png_ptr, *info_ptr);
 }
 #endif
@@ -1379,7 +1386,8 @@ scan_it (FILE *ofp)
 #ifdef HAVE_LIBPNG
                  case OUTPUT_PNG:
                    write_png_header (parm.format, parm.pixels_per_line,
-                                     parm.lines, parm.depth, ofp, &png_ptr, 
&info_ptr);
+                                     parm.lines, parm.depth, resolution_value,
+                                     ofp, &png_ptr, &info_ptr);
                    break;
 #endif
 #ifdef HAVE_LIBJPEG
@@ -1635,7 +1643,8 @@ scan_it (FILE *ofp)
 #ifdef HAVE_LIBPNG
       case OUTPUT_PNG:
        write_png_header (parm.format, parm.pixels_per_line,
-                          image.height, parm.depth, ofp, &png_ptr, &info_ptr);
+                         image.height, parm.depth, resolution_value,
+                         ofp, &png_ptr, &info_ptr);
       break;
 #endif
 #ifdef HAVE_LIBJPEG
-- 
1.8.3.1


-- 
sane-devel mailing list: [email protected]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/sane-devel
Unsubscribe: Send mail with subject "unsubscribe your_password"
             to [email protected]

Reply via email to