[sane-devel] [PATCH] Write density (resolution) JFIF header information with JPEG files.

Aaron Muir Hamilton aaron at correspondwith.me
Mon May 1 20:15:23 UTC 2017


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

diff --git a/frontend/scanimage.c b/frontend/scanimage.c
index ffb9f105..e5562815 100644
--- a/frontend/scanimage.c
+++ b/frontend/scanimage.c
@@ -1213,7 +1213,7 @@ write_png_header (SANE_Frame format, int width, int height, int depth, int dpi,
 
 #ifdef HAVE_LIBJPEG
 static void
-write_jpeg_header (SANE_Frame format, int width, int height, FILE *ofp, struct jpeg_compress_struct *cinfo, struct jpeg_error_mgr *jerr)
+write_jpeg_header (SANE_Frame format, int width, int height, int dpi, FILE *ofp, struct jpeg_compress_struct *cinfo, struct jpeg_error_mgr *jerr)
 {
   cinfo->err = jpeg_std_error(jerr);
   jpeg_create_compress(cinfo);
@@ -1238,6 +1238,11 @@ write_jpeg_header (SANE_Frame format, int width, int height, FILE *ofp, struct j
     }
 
   jpeg_set_defaults(cinfo);
+  /* jpeg_set_defaults overrides density, be careful. */
+  cinfo->density_unit = 1;   /* Inches */
+  cinfo->X_density = cinfo->Y_density = dpi;
+  cinfo->write_JFIF_header = TRUE;
+
   jpeg_set_quality(cinfo, 75, TRUE);
   jpeg_start_compress(cinfo, TRUE);
 }
@@ -1393,7 +1398,8 @@ scan_it (FILE *ofp)
 #ifdef HAVE_LIBJPEG
 		  case OUTPUT_JPEG:
 		    write_jpeg_header (parm.format, parm.pixels_per_line,
-				      parm.lines, ofp, &cinfo, &jerr);
+				       parm.lines, resolution_value,
+				       ofp, &cinfo, &jerr);
 		    break;
 #endif
 		  }
@@ -1665,7 +1671,8 @@ scan_it (FILE *ofp)
 #ifdef HAVE_LIBJPEG
       case OUTPUT_JPEG:
 	write_jpeg_header (parm.format, parm.pixels_per_line,
-	parm.lines, ofp, &cinfo, &jerr);
+			   parm.lines, resolution_value,
+			   ofp, &cinfo, &jerr);
       break;
 #endif
       }
-- 
2.12.2




More information about the sane-devel mailing list