From 2d71d20a62ca8f6989d86db58ce64c7a862675dd Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Sat, 5 Oct 2013 15:28:26 +0100 Subject: Imported Upstream version 3.10.0 --- src/scanner.vala | 81 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 70 insertions(+), 11 deletions(-) (limited to 'src/scanner.vala') diff --git a/src/scanner.vala b/src/scanner.vala index 722f308..4233337 100644 --- a/src/scanner.vala +++ b/src/scanner.vala @@ -80,6 +80,8 @@ public class ScanOptions public ScanType type; public int paper_width; public int paper_height; + public int brightness; + public int contrast; } private class ScanJob @@ -92,6 +94,8 @@ private class ScanJob public ScanType type; public int page_width; public int page_height; + public int brightness; + public int contrast; } private class Request {} @@ -207,7 +211,7 @@ public class Scanner private static Scanner scanner_object = null; /* Thread communicating with SANE */ - private unowned Thread thread; + private Thread thread; /* Queue of requests from main thread */ private AsyncQueue request_queue; @@ -340,7 +344,7 @@ public class Scanner return; } - List devices = null; + var devices = new List (); for (var i = 0; device_list[i] != null; i++) { debug ("Device: name=\"%s\" vendor=\"%s\" model=\"%s\" type=\"%s\"", @@ -378,6 +382,25 @@ public class Scanner notify (new NotifyUpdateDevices ((owned) devices)); } + private int scale_int (int source_min, int source_max, Sane.OptionDescriptor option, int value) + { + var v = value; + + return_val_if_fail (option.type == Sane.ValueType.INT, value); + + if (option.constraint_type == Sane.ConstraintType.RANGE && option.range.max != option.range.min) + { + v -= source_min; + v *= (int) (option.range.max - option.range.min); + v /= (source_max - source_min); + v += (int) option.range.min; + debug ("scale_int: scaling %d [min: %d, max: %d] to %d [min: %d, max: %d]", + value, source_min, source_max, v, (int) option.range.min, (int) option.range.max); + } + + return v; + } + private bool set_default_option (Sane.Handle handle, Sane.OptionDescriptor option, Sane.Int option_index) { /* Check if supports automatic option */ @@ -841,6 +864,11 @@ public class Scanner { /* Pick source */ option = get_option_by_name (handle, Sane.NAME_SCAN_SOURCE, out index); + if (option == null) + { + debug ("SCAN_SOURCE not available, trying alternative \"doc-source\""); + option = get_option_by_name (handle, "doc-source", out index); /* Samsung unified driver. LP: #892915 */ + } if (option != null) { string[] flatbed_sources = @@ -860,7 +888,8 @@ public class Scanner Sane.I18N ("Automatic Document Feeder"), "ADF", "Automatic Document Feeder(left aligned)", /* Seen in the proprietary brother3 driver */ - "Automatic Document Feeder(centrally aligned)" /* Seen in the proprietary brother3 driver */ + "Automatic Document Feeder(centrally aligned)", /* Seen in the proprietary brother3 driver */ + "ADF Simplex" /* Samsung unified driver. LP: # 892915 */ }; string[] adf_front_sources = @@ -878,7 +907,9 @@ public class Scanner string[] adf_duplex_sources = { "ADF Duplex", - Sane.I18N ("ADF Duplex") + Sane.I18N ("ADF Duplex"), + "ADF Duplex - Long-Edge Binding", /* Samsung unified driver. LP: # 892915 */ + "ADF Duplex - Short-Edge Binding" }; switch (job.type) @@ -915,7 +946,8 @@ public class Scanner { Sane.VALUE_SCAN_MODE_COLOR, "Color", - "24bit Color" /* Seen in the proprietary brother3 driver */ + "24bit Color", /* Seen in the proprietary brother3 driver */ + "Color - 16 Million Colors" /* Samsung unified driver. LP: 892915 */ }; string[] gray_scan_modes = { @@ -923,7 +955,8 @@ public class Scanner "Gray", "Grayscale", Sane.I18N ("Grayscale"), - "True Gray" /* Seen in the proprietary brother3 driver */ + "True Gray", /* Seen in the proprietary brother3 driver */ + "Grayscale - 256 Levels" /* Samsung unified driver. LP: 892915 */ }; string[] lineart_scan_modes = { @@ -940,7 +973,9 @@ public class Scanner "Gray", "Grayscale", Sane.I18N ("Grayscale"), - "True Gray" /* Seen in the proprietary brother3 driver */ + "True Gray", /* Seen in the proprietary brother3 driver */ + "Black and White - Line Art", /* Samsung unified driver. LP: 892915 */ + "Black and White - Halftone" }; switch (job.scan_mode) @@ -1060,6 +1095,24 @@ public class Scanner set_int_option (handle, option, index, job.page_height / 10, null); } } + option = get_option_by_name (handle, Sane.NAME_BRIGHTNESS, out index); + if (option != null) + { + if (job.brightness != 0) + { + var brightness = scale_int (-100, 100, option, job.brightness); + set_int_option (handle, option, index, brightness, null); + } + } + option = get_option_by_name (handle, Sane.NAME_CONTRAST, out index); + if (option != null) + { + if (job.contrast != 0) + { + var contrast = scale_int (-100, 100, option, job.contrast); + set_int_option (handle, option, index, contrast, null); + } + } /* Test scanner options (hoping will not effect other scanners...) */ if (current_device == "test") @@ -1428,7 +1481,7 @@ public class Scanner { try { - thread = Thread.create (scan_thread, true); + thread = new Thread.try ("scan-thread", scan_thread); } catch (Error e) { @@ -1488,9 +1541,10 @@ public class Scanner public void scan (string? device, ScanOptions options) { - debug ("Scanner.scan (\"%s\", dpi=%d, scan_mode=%s, depth=%d, type=%s, paper_width=%d, paper_height=%d)", + debug ("Scanner.scan (\"%s\", dpi=%d, scan_mode=%s, depth=%d, type=%s, paper_width=%d, paper_height=%d, brightness=%d, contrast=%d)", device != null ? device : "(null)", options.dpi, get_scan_mode_string (options.scan_mode), options.depth, - get_scan_type_string (options.type), options.paper_width, options.paper_height); + get_scan_type_string (options.type), options.paper_width, options.paper_height, + options.brightness, options.contrast); var request = new RequestStartScan (); request.job = new ScanJob (); request.job.id = job_id++; @@ -1501,6 +1555,8 @@ public class Scanner request.job.type = options.type; request.job.page_width = options.paper_width; request.job.page_height = options.paper_height; + request.job.brightness = options.brightness; + request.job.contrast = options.contrast; request_queue.push (request); } @@ -1517,8 +1573,11 @@ public class Scanner request_queue.push (new RequestQuit ()); if (thread != null) + { thread.join (); - + thread = null; + } + Sane.exit (); debug ("sane_exit ()"); } -- cgit v1.2.3