← Back to team overview

simple-scan-team team mailing list archive

[Merge] lp:~victor-mireyev/simple-scan/484616 into lp:simple-scan

 

Victor Mireyev has proposed merging lp:~victor-mireyev/simple-scan/484616 into lp:simple-scan.

Requested reviews:
  Robert Ancell (robert-ancell)
Related bugs:
  Bug #484616 in Simple Scan: "Density information not present in bitmap formats"
  https://bugs.launchpad.net/simple-scan/+bug/484616

For more details, see:
https://code.launchpad.net/~victor-mireyev/simple-scan/484616/+merge/167359

Save DPI with JPEG
-- 
https://code.launchpad.net/~victor-mireyev/simple-scan/484616/+merge/167359
Your team Simple Scan Development Team is subscribed to branch lp:simple-scan.
=== modified file 'src/book.vala'
--- src/book.vala	2013-05-27 22:18:27 +0000
+++ src/book.vala	2013-06-04 18:10:37 +0000
@@ -9,6 +9,13 @@
  * license.
  */
 
+enum DensityUnit
+{
+    NO_UNITS,
+    PIXELS_PER_INCH,
+    PIXELS_PER_CENTIMETER
+}
+
 public class Book
 {
     private List<Page> pages;
@@ -183,7 +190,7 @@
     private static bool jpeg_empty_cb (JPEG.Compress info) { return true; }
     private static void jpeg_term_cb (JPEG.Compress info) {}
 
-    private uint8[] compress_jpeg (Gdk.Pixbuf image, out size_t n_written)
+    public static uint8[] compress_jpeg (Gdk.Pixbuf image, int? density = null)
     {
         var info = JPEG.Compress ();
         var jerr = JPEG.ErrorManager ();
@@ -198,6 +205,15 @@
         info.in_color_space = JPEG.ColorSpace.RGB; /* TODO: JCS_GRAYSCALE? */
         info.set_defaults ();
 
+        info.set_quality (90);        
+        if (density != null)
+        {
+            uint8 unit = DensityUnit.PIXELS_PER_INCH;
+            info.density_unit = unit;
+            info.X_density = (uint16) density;
+            info.Y_density = (uint16) density;
+        }
+
         var max_length = info.image_width * info.image_height * info.input_components;
         var data = new uint8[max_length];
         dest_mgr.next_output_byte = data;
@@ -216,8 +232,8 @@
             info.write_scanlines (row, 1);
         }
         info.finish_compress ();
-        n_written = max_length - dest_mgr.free_in_buffer;
-        data.resize ((int) n_written);
+        int n_written = max_length - dest_mgr.free_in_buffer;
+        data.resize (n_written);
 
         return data;
     }
@@ -414,9 +430,8 @@
                 /* Try if JPEG compression is better */
                 if (depth > 1)
                 {
-                    size_t jpeg_length;
-                    var jpeg_data = compress_jpeg (image, out jpeg_length);
-                    if (jpeg_length < compressed_data.length)
+                    var jpeg_data = compress_jpeg (image);
+                    if (jpeg_data.length < compressed_data.length)
                     {
                         filter = "DCTDecode";
                         data = jpeg_data;

=== modified file 'src/jpeglib.vapi'
--- src/jpeglib.vapi	2011-06-12 04:55:11 +0000
+++ src/jpeglib.vapi	2013-06-04 18:10:37 +0000
@@ -22,6 +22,11 @@
         public int input_components;
         public ColorSpace in_color_space;
         public ErrorManager* err;
+        
+        public uint8 density_unit;
+        public uint16 X_density;
+        public uint16 Y_density;
+        public void set_quality (int quality, bool force_baseline = true);
 
         public void create_compress ();
         public void set_defaults ();

=== modified file 'src/page.vala'
--- src/page.vala	2013-05-19 21:55:27 +0000
+++ src/page.vala	2013-06-04 18:10:37 +0000
@@ -704,10 +704,8 @@
 
         if (strcmp (type, "jpeg") == 0)
         {
-            /* ICC profile is awaiting review in gtk2+ bugzilla */
-            string[] keys = { "quality", /* "icc-profile", */ null };
-            string[] values = { "90", /* icc_profile_data, */ null };
-            writer.save (image, "jpeg", keys, values);
+            var data = Book.compress_jpeg (image, this.get_dpi ());
+            stream.write_all (data, null, null);
         }
         else if (strcmp (type, "png") == 0)
         {


Follow ups