diff options
-rw-r--r-- | NEWS | 5 | ||||
-rw-r--r-- | meson.build | 2 | ||||
-rw-r--r-- | src/app-window.vala | 3 | ||||
-rw-r--r-- | src/scanner.vala | 54 |
4 files changed, 62 insertions, 2 deletions
@@ -1,3 +1,8 @@ +Overview of changes in simple-scan 3.36.2.1 + + * Revert the higher bit depth text scans changes - they aren't working with + PDF saving. + Overview of changes in simple-scan 3.36.2 * Use higher bit depth on text scans. diff --git a/meson.build b/meson.build index 08a5f45..e57eed5 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,5 @@ project ('simple-scan', ['vala', 'c'], - version: '3.36.2', + version: '3.36.2.1', license: 'GPLv3+', default_options: [ 'warning_level=1', diff --git a/src/app-window.vala b/src/app-window.vala index 0e25f8d..446353d 100644 --- a/src/app-window.vala +++ b/src/app-window.vala @@ -919,13 +919,14 @@ public class AppWindow : Gtk.ApplicationWindow { options.scan_mode = ScanMode.GRAY; options.dpi = preferences_dialog.get_text_dpi (); + options.depth = 2; } else { options.scan_mode = ScanMode.COLOR; options.dpi = preferences_dialog.get_photo_dpi (); + options.depth = 8; } - options.depth = 8; preferences_dialog.get_paper_size (out options.paper_width, out options.paper_height); options.brightness = brightness; options.contrast = contrast; diff --git a/src/scanner.vala b/src/scanner.vala index 67a0d96..29c729b 100644 --- a/src/scanner.vala +++ b/src/scanner.vala @@ -1333,6 +1333,10 @@ public class Scanner : Object info.width = parameters.pixels_per_line; info.height = parameters.lines; info.depth = parameters.depth; + /* Reduce bit depth if requested lower than received */ + // FIXME: This a hack and only works on 8 bit gray to 2 bit gray + if (parameters.depth == 8 && parameters.format == Sane.Frame.GRAY && job.depth == 2 && job.scan_mode == ScanMode.GRAY) + info.depth = job.depth; info.n_channels = parameters.format == Sane.Frame.GRAY ? 1 : 3; info.dpi = job.dpi; // FIXME: This is the requested DPI, not the actual DPI info.device = current_device; @@ -1472,6 +1476,56 @@ public class Scanner : Object n_used++; } + /* Reduce bit depth if requested lower than received */ + // FIXME: This a hack and only works on 8 bit gray to 2 bit gray + if (parameters.depth == 8 && parameters.format == Sane.Frame.GRAY && + job.depth == 2 && job.scan_mode == ScanMode.GRAY) + { + uchar block = 0; + var write_offset = 0; + var block_shift = 6; + for (var i = 0; i < line.n_lines; i++) + { + var offset = i * line.data_length; + for (var x = 0; x < line.width; x++) + { + var p = line.data[offset + x]; + + uchar sample; + if (p >= 192) + sample = 3; + else if (p >= 128) + sample = 2; + else if (p >= 64) + sample = 1; + else + sample = 0; + + block |= sample << block_shift; + if (block_shift == 0) + { + line.data[write_offset] = block; + write_offset++; + block = 0; + block_shift = 6; + } + else + block_shift -= 2; + } + + /* Finish each line on a byte boundary */ + if (block_shift != 6) + { + line.data[write_offset] = block; + write_offset++; + block = 0; + block_shift = 6; + } + } + + line.data_length = (line.width * 2 + 7) / 8; + } + notify_event (new NotifyGotLine (job.id, line)); } } |