simple-scan-team team mailing list archive
-
simple-scan-team team
-
Mailing list archive
-
Message #00837
[Merge] lp:~q3aiml/simple-scan/brightness-and-contrast-v2 into lp:simple-scan
Andy Clayton has proposed merging lp:~q3aiml/simple-scan/brightness-and-contrast-v2 into lp:simple-scan.
Requested reviews:
Robert Ancell (robert-ancell)
Related bugs:
Bug #669820 in Simple Scan: "Cannot set brightness or contrast"
https://bugs.launchpad.net/simple-scan/+bug/669820
For more details, see:
https://code.launchpad.net/~q3aiml/simple-scan/brightness-and-contrast-v2/+merge/123209
Implements brightness and contrast adjustments as described in LP: #669820. Includes fixes for the first review from back in 2011 plus the necessary rewrite to Vala and GTK3.
--
https://code.launchpad.net/~q3aiml/simple-scan/brightness-and-contrast-v2/+merge/123209
Your team Simple Scan Development Team is subscribed to branch lp:simple-scan.
=== modified file 'data/org.gnome.SimpleScan.gschema.xml.in'
--- data/org.gnome.SimpleScan.gschema.xml.in 2011-06-12 10:13:06 +0000
+++ data/org.gnome.SimpleScan.gschema.xml.in 2012-09-07 03:53:19 +0000
@@ -63,6 +63,16 @@
<_summary>Height of paper in tenths of a mm</_summary>
<_description>The height of the paper in tenths of a mm (or 0 for automatic paper detection).</_description>
</key>
+ <key name="brightness" type="i">
+ <default>0</default>
+ <_summary>Brightness of scan</_summary>
+ <_description>The brightness adjustment from -100 to 100 (0 being none).</_description>
+ </key>
+ <key name="contrast" type="i">
+ <default>0</default>
+ <_summary>Contrast of scan</_summary>
+ <_description>The contrast adjustment from -100 to 100 (0 being none).</_description>
+ </key>
<key name="page-dpi" type="i">
<default>72</default>
<_summary>Resolution of last scanned image</_summary>
=== modified file 'data/simple-scan.ui'
--- data/simple-scan.ui 2012-02-01 03:09:00 +0000
+++ data/simple-scan.ui 2012-09-07 03:53:19 +0000
@@ -676,7 +676,7 @@
<object class="GtkTable" id="table3">
<property name="visible">True</property>
<property name="border_width">5</property>
- <property name="n_rows">5</property>
+ <property name="n_rows">7</property>
<property name="n_columns">2</property>
<property name="column_spacing">6</property>
<property name="row_spacing">6</property>
@@ -818,6 +818,66 @@
<property name="y_options">GTK_FILL</property>
</packing>
</child>
+ <child>
+ <object class="GtkLabel" id="brightness_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes" comments="Label beside brightness scale">Brightness:</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">brightness_adjustment</property>
+ </object>
+ <packing>
+ <property name="top_attach">5</property>
+ <property name="bottom_attach">6</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkScale" id="brightness_scale">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="adjustment">brightness_adjustment</property>
+ <property name="draw_value">False</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">5</property>
+ <property name="bottom_attach">6</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="contrast_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes" comments="Label beside contrast scale">Contrast:</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">contrast_scale</property>
+ </object>
+ <packing>
+ <property name="top_attach">6</property>
+ <property name="bottom_attach">7</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkScale" id="contrast_scale">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="adjustment">contrast_adjustment</property>
+ <property name="draw_value">False</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">6</property>
+ <property name="bottom_attach">7</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="position">1</property>
@@ -954,4 +1014,16 @@
<column type="gchararray"/>
</columns>
</object>
+ <object class="GtkAdjustment" id="brightness_adjustment">
+ <property name="lower">-100</property>
+ <property name="upper">100</property>
+ <property name="step_increment">1</property>
+ <property name="page_increment">10</property>
+ </object>
+ <object class="GtkAdjustment" id="contrast_adjustment">
+ <property name="lower">-100</property>
+ <property name="upper">100</property>
+ <property name="step_increment">1</property>
+ <property name="page_increment">10</property>
+ </object>
</interface>
=== modified file 'src/scanner.vala'
--- src/scanner.vala 2012-07-12 08:48:35 +0000
+++ src/scanner.vala 2012-09-07 03:53:19 +0000
@@ -80,6 +80,8 @@
public ScanType type;
public int paper_width;
public int paper_height;
+ public int brightness;
+ public int contrast;
}
private class ScanJob
@@ -92,6 +94,8 @@
public ScanType type;
public int page_width;
public int page_height;
+ public int brightness;
+ public int contrast;
}
private class Request {}
@@ -378,6 +382,24 @@
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 */
@@ -1060,6 +1082,22 @@
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")
@@ -1488,9 +1526,10 @@
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 +1540,8 @@
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);
}
=== modified file 'src/ui.vala'
--- src/ui.vala 2012-08-25 09:05:02 +0000
+++ src/ui.vala 2012-09-07 03:53:19 +0000
@@ -51,11 +51,15 @@
private Gtk.ComboBox photo_dpi_combo;
private Gtk.ComboBox page_side_combo;
private Gtk.ComboBox paper_size_combo;
+ private Gtk.Scale brightness_scale;
+ private Gtk.Scale contrast_scale;
private Gtk.ListStore device_model;
private Gtk.ListStore text_dpi_model;
private Gtk.ListStore photo_dpi_model;
private Gtk.ListStore page_side_model;
private Gtk.ListStore paper_size_model;
+ private Gtk.Adjustment brightness_adjustment;
+ private Gtk.Adjustment contrast_adjustment;
private bool setting_devices;
private bool user_selected_device;
@@ -610,6 +614,16 @@
if (have_iter)
paper_size_combo.set_active_iter (iter);
}
+
+ private void set_brightness (int brightness)
+ {
+ brightness_adjustment.set_value (brightness);
+ }
+
+ private void set_contrast (int contrast)
+ {
+ contrast_adjustment.set_value (contrast);
+ }
private int get_text_dpi ()
{
@@ -658,6 +672,16 @@
return false;
}
+ private int get_brightness ()
+ {
+ return (int) brightness_adjustment.get_value ();
+ }
+
+ private int get_contrast ()
+ {
+ return (int) contrast_adjustment.get_value ();
+ }
+
private ScanOptions get_scan_options ()
{
var options = new ScanOptions ();
@@ -674,6 +698,8 @@
options.depth = 8;
}
get_paper_size (out options.paper_width, out options.paper_height);
+ options.brightness = get_brightness ();
+ options.contrast = get_contrast ();
return options;
}
@@ -1101,6 +1127,8 @@
settings.set_enum ("page-side", get_page_side ());
settings.set_int ("paper-width", paper_width);
settings.set_int ("paper-height", paper_height);
+ settings.set_int ("brightness", get_brightness ());
+ settings.set_int ("contrast", get_contrast ());
settings.set_int ("window-width", window_width);
settings.set_int ("window-height", window_height);
settings.set_boolean ("window-is-maximized", window_is_maximized);
@@ -1297,6 +1325,10 @@
page_side_model = (Gtk.ListStore) page_side_combo.get_model ();
paper_size_combo = (Gtk.ComboBox) builder.get_object ("paper_size_combo");
paper_size_model = (Gtk.ListStore) paper_size_combo.get_model ();
+ brightness_scale = (Gtk.Scale) builder.get_object ("brightness_scale");
+ brightness_adjustment = (Gtk.Adjustment) brightness_scale.get_adjustment ();
+ contrast_scale = (Gtk.Scale) builder.get_object ("contrast_scale");
+ contrast_adjustment = (Gtk.Adjustment) contrast_scale.get_adjustment ();
/* Add InfoBar (not supported in Glade) */
info_bar = new Gtk.InfoBar ();
@@ -1363,6 +1395,28 @@
var paper_height = settings.get_int ("paper-height");
set_paper_size (paper_width, paper_height);
+ {
+ var lower = brightness_adjustment.get_lower ();
+ var darker_label = "<small>%s</small>".printf (_("Darker"));
+ var upper = brightness_adjustment.get_upper ();
+ var lighter_label = "<small>%s</small>".printf (_("Lighter"));
+ brightness_scale.add_mark (lower, Gtk.PositionType.BOTTOM, darker_label);
+ brightness_scale.add_mark (0, Gtk.PositionType.BOTTOM, null);
+ brightness_scale.add_mark (upper, Gtk.PositionType.BOTTOM, lighter_label);
+ set_brightness (settings.get_int ("brightness"));
+ }
+
+ {
+ var lower = contrast_adjustment.get_lower ();
+ var less_label = "<small>%s</small>".printf (_("Less"));
+ var upper = contrast_adjustment.get_upper ();
+ var more_label = "<small>%s</small>".printf (_("More"));
+ contrast_scale.add_mark (lower, Gtk.PositionType.BOTTOM, less_label);
+ contrast_scale.add_mark (0, Gtk.PositionType.BOTTOM, null);
+ contrast_scale.add_mark (upper, Gtk.PositionType.BOTTOM, more_label);
+ set_contrast (settings.get_int ("contrast"));
+ }
+
var device = settings.get_string ("selected-device");
if (device != null)
{
Follow ups