Merge lp:~soliloque/simple-scan/remove_ps_tiff into lp:~simple-scan-team/simple-scan/trunk

Proposed by soliloque
Status: Merged
Merged at revision: 964
Proposed branch: lp:~soliloque/simple-scan/remove_ps_tiff
Merge into: lp:~simple-scan-team/simple-scan/trunk
Diff against target: 113 lines (+3/-47)
3 files modified
src/book.vala (+0/-32)
src/page.vala (+0/-8)
src/ui.vala (+3/-7)
To merge this branch: bzr merge lp:~soliloque/simple-scan/remove_ps_tiff
Reviewer Review Type Date Requested Status
Robert Ancell Approve
Review via email: mp+322607@code.launchpad.net

Commit message

Remove code for ps and tiff support

Description of the change

The file chooser dialog offers three format for saving files: PNG, JPEG, and PDF. I consider this is the right thing to do as it covers pretty much every use cases: PDF for having all images in a single file, JPEG for having compact files at the price of using lossy compression, and PNG for retaining all scanned pixels, maybe for further editing with another software.

Double-clicking a page in simple-scan will open it with an image viewer. However, this feature wasn't following what the file chooser dialog does as it saves the image in the TIFF format. For this feature to be in line with the file chooser dialog, I changed the image format used from TIFF to PNG. TIFF offers nothing over PNG for what Simple-Scan does anyway and PNG is more widely supported than TIFF at this time. This make the code for supporting TIFF file format useless.

There is also code for supporting PostScript file format. This format doesn't offer anything over PDF -- PDF is in fact better as it supports icc profiles. Furthermore, PDF is vastly more widely supported than PDF. As simple-scan doesn't use or offer to save in PostScript, this code isn't useful too.

So, to summarize, this merge would remove the code -- and the need to maintain that code -- supporting PostScript and TIFF file formats without removing any feature or usefulness to Simple-Scan.

To post a comment you must log in.
Revision history for this message
Robert Ancell (robert-ancell) wrote :

I like less code. :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/book.vala'
--- src/book.vala 2017-03-29 09:40:01 +0000
+++ src/book.vala 2017-04-16 11:22:38 +0000
@@ -165,34 +165,6 @@
165 }165 }
166 }166 }
167167
168 private void save_ps_pdf_surface (Cairo.Surface surface, Gdk.Pixbuf image, double dpi)
169 {
170 var context = new Cairo.Context (surface);
171 context.scale (72.0 / dpi, 72.0 / dpi);
172 Gdk.cairo_set_source_pixbuf (context, image, 0, 0);
173 context.get_source ().set_filter (Cairo.Filter.BEST);
174 context.paint ();
175 }
176
177 private void save_ps (File file) throws Error
178 {
179 var stream = file.replace (null, false, FileCreateFlags.NONE, null);
180 var writer = new PsWriter (stream);
181 var surface = writer.surface;
182
183 for (var i = 0; i < n_pages; i++)
184 {
185 var page = get_page (i);
186 var image = page.get_image (true);
187 var width = image.width * 72.0 / page.dpi;
188 var height = image.height * 72.0 / page.dpi;
189 surface.set_size (width, height);
190 save_ps_pdf_surface (surface, image, page.dpi);
191 surface.show_page ();
192 saving (i);
193 }
194 }
195
196 private uint8[]? compress_zlib (uint8[] data)168 private uint8[]? compress_zlib (uint8[] data)
197 {169 {
198 var stream = ZLib.DeflateStream (ZLib.Level.BEST_COMPRESSION);170 var stream = ZLib.DeflateStream (ZLib.Level.BEST_COMPRESSION);
@@ -598,12 +570,8 @@
598 {570 {
599 case "jpeg":571 case "jpeg":
600 case "png":572 case "png":
601 case "tiff":
602 save_multi_file (type, quality, file);573 save_multi_file (type, quality, file);
603 break;574 break;
604 case "ps":
605 save_ps (file);
606 break;
607 case "pdf":575 case "pdf":
608 save_pdf (file, quality);576 save_pdf (file, quality);
609 break;577 break;
610578
=== modified file 'src/page.vala'
--- src/page.vala 2015-09-13 21:35:37 +0000
+++ src/page.vala 2017-04-16 11:22:38 +0000
@@ -676,14 +676,6 @@
676 keys[2] = null;676 keys[2] = null;
677 writer.save (image, "png", keys, values);677 writer.save (image, "png", keys, values);
678 }678 }
679 else if (strcmp (type, "tiff") == 0)
680 {
681 string[] keys = { "x-dpi", "y-dpi", "compression", "icc-profile", null };
682 string[] values = { "%d".printf (dpi), "%d".printf (dpi), "8" /* Deflate compression */, icc_profile_data, null };
683 if (icc_profile_data == null)
684 keys[3] = null;
685 writer.save (image, "tiff", keys, values);
686 }
687 else679 else
688 throw new FileError.INVAL ("Unknown file type: %s".printf (type));680 throw new FileError.INVAL ("Unknown file type: %s".printf (type));
689 }681 }
690682
=== modified file 'src/ui.vala'
--- src/ui.vala 2017-04-12 04:34:42 +0000
+++ src/ui.vala 2017-04-16 11:22:38 +0000
@@ -615,7 +615,7 @@
615 /* Check the file(s) don't already exist */615 /* Check the file(s) don't already exist */
616 var files = new List<File> ();616 var files = new List<File> ();
617 var format = uri_to_format (uri);617 var format = uri_to_format (uri);
618 if (format == "jpeg" || format == "png" || format == "tiff")618 if (format == "jpeg" || format == "png")
619 {619 {
620 for (var j = 0; j < book.n_pages; j++)620 for (var j = 0; j < book.n_pages; j++)
621 files.append (book.make_indexed_file (uri, j));621 files.append (book.make_indexed_file (uri, j));
@@ -663,12 +663,8 @@
663 var uri_lower = uri.down ();663 var uri_lower = uri.down ();
664 if (uri_lower.has_suffix (".pdf"))664 if (uri_lower.has_suffix (".pdf"))
665 return "pdf";665 return "pdf";
666 else if (uri_lower.has_suffix (".ps"))
667 return "ps";
668 else if (uri_lower.has_suffix (".png"))666 else if (uri_lower.has_suffix (".png"))
669 return "png";667 return "png";
670 else if (uri_lower.has_suffix (".tif") || uri_lower.has_suffix (".tiff"))
671 return "tiff";
672 else668 else
673 return "jpeg";669 return "jpeg";
674 }670 }
@@ -1041,14 +1037,14 @@
10411037
1042 private void show_page_cb (BookView view, Page page)1038 private void show_page_cb (BookView view, Page page)
1043 {1039 {
1044 var path = get_temporary_filename ("scanned-page", "tiff");1040 var path = get_temporary_filename ("scanned-page", "png");
1045 if (path == null)1041 if (path == null)
1046 return;1042 return;
1047 var file = File.new_for_path (path);1043 var file = File.new_for_path (path);
10481044
1049 try1045 try
1050 {1046 {
1051 page.save ("tiff", quality, file);1047 page.save ("png", quality, file);
1052 }1048 }
1053 catch (Error e)1049 catch (Error e)
1054 {1050 {

Subscribers

People subscribed via source and target branches