Commit a0321d2a authored by Aaron Muir Hamilton's avatar Aaron Muir Hamilton Committed by Olaf Meeuwissen

Include physical resolution (pHYs section) in PNG output.

parent 469dc738
......@@ -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
......@@ -1650,7 +1658,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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment