Merge lp:~q3aiml/simple-scan/brightness-and-contrast-v2 into lp:~simple-scan-team/simple-scan/trunk

Proposed by Andy Clayton
Status: Merged
Merged at revision: 600
Proposed branch: lp:~q3aiml/simple-scan/brightness-and-contrast-v2
Merge into: lp:~simple-scan-team/simple-scan/trunk
Diff against target: 321 lines (+180/-3)
4 files modified
data/org.gnome.SimpleScan.gschema.xml.in (+10/-0)
data/simple-scan.ui (+73/-1)
src/scanner.vala (+43/-2)
src/ui.vala (+54/-0)
To merge this branch: bzr merge lp:~q3aiml/simple-scan/brightness-and-contrast-v2
Reviewer Review Type Date Requested Status
Robert Ancell Approve
Review via email: mp+123209@code.launchpad.net

Description of the change

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.

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

Thanks Andy.

Patch is really good, I have merge it in for 3.7 with some minor whitespace changes.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/org.gnome.SimpleScan.gschema.xml.in'
2--- data/org.gnome.SimpleScan.gschema.xml.in 2011-06-12 10:13:06 +0000
3+++ data/org.gnome.SimpleScan.gschema.xml.in 2012-09-07 03:55:23 +0000
4@@ -63,6 +63,16 @@
5 <_summary>Height of paper in tenths of a mm</_summary>
6 <_description>The height of the paper in tenths of a mm (or 0 for automatic paper detection).</_description>
7 </key>
8+ <key name="brightness" type="i">
9+ <default>0</default>
10+ <_summary>Brightness of scan</_summary>
11+ <_description>The brightness adjustment from -100 to 100 (0 being none).</_description>
12+ </key>
13+ <key name="contrast" type="i">
14+ <default>0</default>
15+ <_summary>Contrast of scan</_summary>
16+ <_description>The contrast adjustment from -100 to 100 (0 being none).</_description>
17+ </key>
18 <key name="page-dpi" type="i">
19 <default>72</default>
20 <_summary>Resolution of last scanned image</_summary>
21
22=== modified file 'data/simple-scan.ui'
23--- data/simple-scan.ui 2012-02-01 03:09:00 +0000
24+++ data/simple-scan.ui 2012-09-07 03:55:23 +0000
25@@ -676,7 +676,7 @@
26 <object class="GtkTable" id="table3">
27 <property name="visible">True</property>
28 <property name="border_width">5</property>
29- <property name="n_rows">5</property>
30+ <property name="n_rows">7</property>
31 <property name="n_columns">2</property>
32 <property name="column_spacing">6</property>
33 <property name="row_spacing">6</property>
34@@ -818,6 +818,66 @@
35 <property name="y_options">GTK_FILL</property>
36 </packing>
37 </child>
38+ <child>
39+ <object class="GtkLabel" id="brightness_label">
40+ <property name="visible">True</property>
41+ <property name="can_focus">False</property>
42+ <property name="xalign">0</property>
43+ <property name="label" translatable="yes" comments="Label beside brightness scale">Brightness:</property>
44+ <property name="use_underline">True</property>
45+ <property name="mnemonic_widget">brightness_adjustment</property>
46+ </object>
47+ <packing>
48+ <property name="top_attach">5</property>
49+ <property name="bottom_attach">6</property>
50+ <property name="x_options">GTK_FILL</property>
51+ <property name="y_options">GTK_FILL</property>
52+ </packing>
53+ </child>
54+ <child>
55+ <object class="GtkScale" id="brightness_scale">
56+ <property name="visible">True</property>
57+ <property name="can_focus">True</property>
58+ <property name="adjustment">brightness_adjustment</property>
59+ <property name="draw_value">False</property>
60+ </object>
61+ <packing>
62+ <property name="left_attach">1</property>
63+ <property name="right_attach">2</property>
64+ <property name="top_attach">5</property>
65+ <property name="bottom_attach">6</property>
66+ </packing>
67+ </child>
68+ <child>
69+ <object class="GtkLabel" id="contrast_label">
70+ <property name="visible">True</property>
71+ <property name="can_focus">False</property>
72+ <property name="xalign">0</property>
73+ <property name="label" translatable="yes" comments="Label beside contrast scale">Contrast:</property>
74+ <property name="use_underline">True</property>
75+ <property name="mnemonic_widget">contrast_scale</property>
76+ </object>
77+ <packing>
78+ <property name="top_attach">6</property>
79+ <property name="bottom_attach">7</property>
80+ <property name="x_options">GTK_FILL</property>
81+ <property name="y_options">GTK_FILL</property>
82+ </packing>
83+ </child>
84+ <child>
85+ <object class="GtkScale" id="contrast_scale">
86+ <property name="visible">True</property>
87+ <property name="can_focus">True</property>
88+ <property name="adjustment">contrast_adjustment</property>
89+ <property name="draw_value">False</property>
90+ </object>
91+ <packing>
92+ <property name="left_attach">1</property>
93+ <property name="right_attach">2</property>
94+ <property name="top_attach">6</property>
95+ <property name="bottom_attach">7</property>
96+ </packing>
97+ </child>
98 </object>
99 <packing>
100 <property name="position">1</property>
101@@ -954,4 +1014,16 @@
102 <column type="gchararray"/>
103 </columns>
104 </object>
105+ <object class="GtkAdjustment" id="brightness_adjustment">
106+ <property name="lower">-100</property>
107+ <property name="upper">100</property>
108+ <property name="step_increment">1</property>
109+ <property name="page_increment">10</property>
110+ </object>
111+ <object class="GtkAdjustment" id="contrast_adjustment">
112+ <property name="lower">-100</property>
113+ <property name="upper">100</property>
114+ <property name="step_increment">1</property>
115+ <property name="page_increment">10</property>
116+ </object>
117 </interface>
118
119=== modified file 'src/scanner.vala'
120--- src/scanner.vala 2012-07-12 08:48:35 +0000
121+++ src/scanner.vala 2012-09-07 03:55:23 +0000
122@@ -80,6 +80,8 @@
123 public ScanType type;
124 public int paper_width;
125 public int paper_height;
126+ public int brightness;
127+ public int contrast;
128 }
129
130 private class ScanJob
131@@ -92,6 +94,8 @@
132 public ScanType type;
133 public int page_width;
134 public int page_height;
135+ public int brightness;
136+ public int contrast;
137 }
138
139 private class Request {}
140@@ -378,6 +382,24 @@
141 notify (new NotifyUpdateDevices ((owned) devices));
142 }
143
144+ private int scale_int (int source_min, int source_max, Sane.OptionDescriptor option, int value)
145+ {
146+ var v = value;
147+
148+ return_val_if_fail (option.type == Sane.ValueType.INT, value);
149+
150+ if (option.constraint_type == Sane.ConstraintType.RANGE && option.range.max != option.range.min) {
151+ v -= source_min;
152+ v *= (int) (option.range.max - option.range.min);
153+ v /= (source_max - source_min);
154+ v += (int) option.range.min;
155+ debug ("scale_int: scaling %d [min: %d, max: %d] to %d [min: %d, max: %d]",
156+ value, source_min, source_max, v, (int) option.range.min, (int) option.range.max);
157+ }
158+
159+ return v;
160+ }
161+
162 private bool set_default_option (Sane.Handle handle, Sane.OptionDescriptor option, Sane.Int option_index)
163 {
164 /* Check if supports automatic option */
165@@ -1060,6 +1082,22 @@
166 set_int_option (handle, option, index, job.page_height / 10, null);
167 }
168 }
169+ option = get_option_by_name (handle, Sane.NAME_BRIGHTNESS, out index);
170+ if (option != null)
171+ {
172+ if (job.brightness != 0) {
173+ var brightness = scale_int (-100, 100, option, job.brightness);
174+ set_int_option (handle, option, index, brightness, null);
175+ }
176+ }
177+ option = get_option_by_name (handle, Sane.NAME_CONTRAST, out index);
178+ if (option != null)
179+ {
180+ if (job.contrast != 0) {
181+ var contrast = scale_int (-100, 100, option, job.contrast);
182+ set_int_option (handle, option, index, contrast, null);
183+ }
184+ }
185
186 /* Test scanner options (hoping will not effect other scanners...) */
187 if (current_device == "test")
188@@ -1488,9 +1526,10 @@
189
190 public void scan (string? device, ScanOptions options)
191 {
192- debug ("Scanner.scan (\"%s\", dpi=%d, scan_mode=%s, depth=%d, type=%s, paper_width=%d, paper_height=%d)",
193+ debug ("Scanner.scan (\"%s\", dpi=%d, scan_mode=%s, depth=%d, type=%s, paper_width=%d, paper_height=%d, brightness=%d, contrast=%d)",
194 device != null ? device : "(null)", options.dpi, get_scan_mode_string (options.scan_mode), options.depth,
195- get_scan_type_string (options.type), options.paper_width, options.paper_height);
196+ get_scan_type_string (options.type), options.paper_width, options.paper_height,
197+ options.brightness, options.contrast);
198 var request = new RequestStartScan ();
199 request.job = new ScanJob ();
200 request.job.id = job_id++;
201@@ -1501,6 +1540,8 @@
202 request.job.type = options.type;
203 request.job.page_width = options.paper_width;
204 request.job.page_height = options.paper_height;
205+ request.job.brightness = options.brightness;
206+ request.job.contrast = options.contrast;
207 request_queue.push (request);
208 }
209
210
211=== modified file 'src/ui.vala'
212--- src/ui.vala 2012-08-25 09:05:02 +0000
213+++ src/ui.vala 2012-09-07 03:55:23 +0000
214@@ -51,11 +51,15 @@
215 private Gtk.ComboBox photo_dpi_combo;
216 private Gtk.ComboBox page_side_combo;
217 private Gtk.ComboBox paper_size_combo;
218+ private Gtk.Scale brightness_scale;
219+ private Gtk.Scale contrast_scale;
220 private Gtk.ListStore device_model;
221 private Gtk.ListStore text_dpi_model;
222 private Gtk.ListStore photo_dpi_model;
223 private Gtk.ListStore page_side_model;
224 private Gtk.ListStore paper_size_model;
225+ private Gtk.Adjustment brightness_adjustment;
226+ private Gtk.Adjustment contrast_adjustment;
227 private bool setting_devices;
228 private bool user_selected_device;
229
230@@ -610,6 +614,16 @@
231 if (have_iter)
232 paper_size_combo.set_active_iter (iter);
233 }
234+
235+ private void set_brightness (int brightness)
236+ {
237+ brightness_adjustment.set_value (brightness);
238+ }
239+
240+ private void set_contrast (int contrast)
241+ {
242+ contrast_adjustment.set_value (contrast);
243+ }
244
245 private int get_text_dpi ()
246 {
247@@ -658,6 +672,16 @@
248 return false;
249 }
250
251+ private int get_brightness ()
252+ {
253+ return (int) brightness_adjustment.get_value ();
254+ }
255+
256+ private int get_contrast ()
257+ {
258+ return (int) contrast_adjustment.get_value ();
259+ }
260+
261 private ScanOptions get_scan_options ()
262 {
263 var options = new ScanOptions ();
264@@ -674,6 +698,8 @@
265 options.depth = 8;
266 }
267 get_paper_size (out options.paper_width, out options.paper_height);
268+ options.brightness = get_brightness ();
269+ options.contrast = get_contrast ();
270
271 return options;
272 }
273@@ -1101,6 +1127,8 @@
274 settings.set_enum ("page-side", get_page_side ());
275 settings.set_int ("paper-width", paper_width);
276 settings.set_int ("paper-height", paper_height);
277+ settings.set_int ("brightness", get_brightness ());
278+ settings.set_int ("contrast", get_contrast ());
279 settings.set_int ("window-width", window_width);
280 settings.set_int ("window-height", window_height);
281 settings.set_boolean ("window-is-maximized", window_is_maximized);
282@@ -1297,6 +1325,10 @@
283 page_side_model = (Gtk.ListStore) page_side_combo.get_model ();
284 paper_size_combo = (Gtk.ComboBox) builder.get_object ("paper_size_combo");
285 paper_size_model = (Gtk.ListStore) paper_size_combo.get_model ();
286+ brightness_scale = (Gtk.Scale) builder.get_object ("brightness_scale");
287+ brightness_adjustment = (Gtk.Adjustment) brightness_scale.get_adjustment ();
288+ contrast_scale = (Gtk.Scale) builder.get_object ("contrast_scale");
289+ contrast_adjustment = (Gtk.Adjustment) contrast_scale.get_adjustment ();
290
291 /* Add InfoBar (not supported in Glade) */
292 info_bar = new Gtk.InfoBar ();
293@@ -1363,6 +1395,28 @@
294 var paper_height = settings.get_int ("paper-height");
295 set_paper_size (paper_width, paper_height);
296
297+ {
298+ var lower = brightness_adjustment.get_lower ();
299+ var darker_label = "<small>%s</small>".printf (_("Darker"));
300+ var upper = brightness_adjustment.get_upper ();
301+ var lighter_label = "<small>%s</small>".printf (_("Lighter"));
302+ brightness_scale.add_mark (lower, Gtk.PositionType.BOTTOM, darker_label);
303+ brightness_scale.add_mark (0, Gtk.PositionType.BOTTOM, null);
304+ brightness_scale.add_mark (upper, Gtk.PositionType.BOTTOM, lighter_label);
305+ set_brightness (settings.get_int ("brightness"));
306+ }
307+
308+ {
309+ var lower = contrast_adjustment.get_lower ();
310+ var less_label = "<small>%s</small>".printf (_("Less"));
311+ var upper = contrast_adjustment.get_upper ();
312+ var more_label = "<small>%s</small>".printf (_("More"));
313+ contrast_scale.add_mark (lower, Gtk.PositionType.BOTTOM, less_label);
314+ contrast_scale.add_mark (0, Gtk.PositionType.BOTTOM, null);
315+ contrast_scale.add_mark (upper, Gtk.PositionType.BOTTOM, more_label);
316+ set_contrast (settings.get_int ("contrast"));
317+ }
318+
319 var device = settings.get_string ("selected-device");
320 if (device != null)
321 {

Subscribers

People subscribed via source and target branches