summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2020-05-26 20:12:10 +0200
committerJörg Frings-Fürst <debian@jff.email>2020-05-26 20:12:10 +0200
commit7d56e505d4c0213867640cfc53345324a9e3c9e7 (patch)
tree42c0abf1a3cca07f54c4eea9cf45983e840683e8 /src
parentb83216ded28de014bf2c543df8519dbc984deb59 (diff)
parent3a91d1ee11d4ea173fa1247059b7036056c12bd0 (diff)
Merge branch 'feature/upstream' into develop
Diffstat (limited to 'src')
-rw-r--r--src/app-window.vala3
-rw-r--r--src/scanner.vala54
2 files changed, 56 insertions, 1 deletions
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));
}
}