1 /*
2    SANE EPSON backend
3    Copyright (C) 2001, 2005, 2008  SEIKO EPSON Corporation
4 
5    Date         Author      Reason
6    06/01/2001   N.Sasaki    New
7 
8    This file is part of the `iscan' program.
9 
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 2 of the License, or
13    (at your option) any later version.
14 
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19 
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 
24    As a special exception, the copyright holders give permission
25    to link the code of this program with the esmod library and
26    distribute linked combinations including the two.  You must obey
27    the GNU General Public License in all respects for all of the
28    code used other then esmod.
29 */
30 
31 #include <config.h>
32 
33 #include "gettext.h"
34 #define  _(msg_id)	gettext (msg_id)
35 
36 /*------------------------------------------------------------*/
37 #include <gtk/gtk.h>
38 #include <stdio.h>
39 #include <string.h>
40 
41 /*------------------------------------------------------------*/
42 #include "pisa_view_manager.h"
43 #include "pisa_image_controls.h"
44 #include "pisa_tool.h"
45 #include "pisa_error.h"
46 #include "pisa_structs.h"
47 #include "pisa_default_val.h"
48 
49 /*------------------------------------------------------------*/
50 static void value_changed ( GtkAdjustment * adjust, gpointer data );
51 
52 /*------------------------------------------------------------*/
53 #define ID_SCALE_GAMMA		0x0001
54 #define ID_SCALE_HIGHLIGHT	0x0002
55 #define ID_SCALE_SHADOW		0x0003
56 #define ID_SCALE_THRESHOLD	0x0004
57 
58 scale_items g_scale_gamma = { ID_SCALE_GAMMA, 0, 0,
59 			      ( GtkSignalFunc * ) value_changed,
60 			      DEFGAMMA,
61 			      MINGAMMA,
62 			      MAXGAMMA,
63 			      LINEGAMMA,
64 			      PAGEGAMMA };
65 scale_items g_scale_highlight = { ID_SCALE_HIGHLIGHT, 0, 0,
66 				  ( GtkSignalFunc * ) value_changed,
67 				  DEFHIGHLIGHT,
68 				  MINHIGHLIGHT,
69 				  MAXHIGHLIGHT,
70 				  LINEHIGHLIGHT,
71 				  PAGEHIGHLIGHT };
72 scale_items g_scale_shadow = { ID_SCALE_SHADOW, 0, 0,
73 			       ( GtkSignalFunc * ) value_changed,
74 			       DEFSHADOW,
75 			       MINSHADOW,
76 			       MAXSHADOW,
77 			       LINESHADOW,
78 			       PAGESHADOW };
79 scale_items g_scale_threshold = { ID_SCALE_THRESHOLD, 0, 0,
80 				  ( GtkSignalFunc * ) value_changed,
81 				  DEFTHRESHOLD,
82 				  MINTHRESHOLD,
83 				  MAXTHRESHOLD,
84 				  LINETHRESHOLD,
85 				  PAGETHRESHOLD };
86 
87 /*------------------------------------------------------------*/
value_changed(GtkAdjustment * adjust,gpointer data)88 static void value_changed ( GtkAdjustment * adjust, gpointer data )
89 {
90   long		id;
91   long		val;
92   int		change;
93   marquee	* marq;
94 
95   id = * ( long * ) data;
96   change = 1;
97   marq = & g_view_manager->get_marquee ();
98 
99   switch ( id )
100     {
101     case ID_SCALE_GAMMA:
102       val = ( long ) ( adjust->value * 100 );
103       if ( marq->gamma == val )
104 	change = 0;
105       else
106 	marq->gamma = val;
107       break;
108 
109     case ID_SCALE_HIGHLIGHT:
110       val = ( long ) ( adjust->value );
111       if ( marq->highlight == val )
112 	change = 0;
113       else
114 	marq->highlight = val;
115       break;
116 
117     case ID_SCALE_SHADOW:
118       val = ( long ) ( adjust->value );
119       if ( marq->shadow == val )
120 	change = 0;
121       else
122 	marq->shadow = val;
123       break;
124 
125     case ID_SCALE_THRESHOLD:
126       val = ( long ) ( adjust->value );
127       if ( marq->threshold == val )
128 	change = 0;
129       else
130 	marq->threshold = val;
131       break;
132     }
133 
134   if ( change )
135     {
136       ::g_view_manager->update_lut ( );
137       preview_window *prev_cls =
138 	(preview_window *) ::g_view_manager->get_window_cls (ID_WINDOW_PREV);
139 
140       prev_cls->update_img ( );
141     }
142 }
143 
144 /*------------------------------------------------------------*/
create_window(GtkWidget * parent)145 GtkWidget * image_controls::create_window ( GtkWidget * parent )
146 {
147   GtkWidget	* frame;
148   GtkWidget	* widget;
149 
150   parent = parent;
151 
152   frame = ::gtk_frame_new ( _( "Image Controls" ) );
153   ::gtk_container_border_width ( GTK_CONTAINER ( frame ), 5 );
154 
155   widget = create_controls ( );
156   ::gtk_container_add ( GTK_CONTAINER ( frame ), widget );
157   ::gtk_widget_show ( widget );
158 
159   return frame;
160 }
161 
162 /*------------------------------------------------------------*/
sensitive(int is_prev_img)163 void image_controls::sensitive ( int is_prev_img )
164 {
165   marquee	* marq;
166   gboolean	enable_color, enable_bw;
167 
168   marq = & g_view_manager->get_marquee ();
169 
170   // update value
171   ::gtk_adjustment_set_value ( ::g_scale_gamma.adjust, marq->gamma / 100.0f );
172   ::gtk_adjustment_set_value ( ::g_scale_highlight.adjust, marq->highlight );
173   ::gtk_adjustment_set_value ( ::g_scale_shadow.adjust, marq->shadow );
174   ::gtk_adjustment_set_value ( ::g_scale_threshold.adjust, marq->threshold );
175 
176   // grayout
177   if ( is_prev_img
178        && g_view_manager->get_settings ().imgtype.pixeltype != PISA_PT_BW )
179     enable_color = TRUE;
180   else
181     enable_color = FALSE;
182 
183   if ( is_prev_img
184        && g_view_manager->get_settings ().imgtype.pixeltype == PISA_PT_BW )
185     enable_bw = TRUE;
186   else
187     enable_bw = FALSE;
188 
189   ::gtk_widget_set_sensitive ( ::g_scale_gamma.widget, enable_color );
190   ::gtk_widget_set_sensitive ( ::g_scale_highlight.widget, enable_color );
191   ::gtk_widget_set_sensitive ( ::g_scale_shadow.widget, enable_color );
192   ::gtk_widget_set_sensitive ( ::g_scale_threshold.widget, enable_bw );
193 }
194 
195 /*------------------------------------------------------------*/
create_controls(void)196 GtkWidget * image_controls::create_controls ( void )
197 {
198   GtkWidget	* table;
199   GtkWidget	* label;
200   GtkWidget	* scale;
201 
202   table = ::gtk_table_new ( 4, 2, FALSE );
203   ::gtk_container_border_width ( GTK_CONTAINER ( table ), 5 );
204   ::gtk_table_set_row_spacings ( GTK_TABLE ( table ), 3 );
205   ::gtk_table_set_col_spacings ( GTK_TABLE ( table ), 5 );
206 
207   // gamma
208   label = ::gtk_label_new ( _( "Gamma:" ) );
209   ::gtk_misc_set_alignment ( GTK_MISC ( label ), 1.0, 0.5 );
210   ::gtk_table_attach ( GTK_TABLE ( table ), label, 0, 1, 0, 1,
211 		       GTK_FILL, GTK_FILL, 0, 0 );
212   ::gtk_widget_show ( label );
213 
214   scale = ::pisa_create_scale ( & ::g_scale_gamma );
215   ::gtk_widget_set_usize ( scale, 200, -1 );
216   ::gtk_scale_set_digits ( GTK_SCALE ( scale ), 2 );
217   ::gtk_range_set_update_policy ( GTK_RANGE ( scale ), GTK_UPDATE_DELAYED );
218   ::gtk_table_attach ( GTK_TABLE ( table ), scale, 1, 2, 0, 1,
219 		       GTK_FILL, GTK_FILL, 0, 0 );
220   ::gtk_widget_show ( scale );
221 
222   // highlight
223   label = ::gtk_label_new ( _( "Highlight:" ) );
224   ::gtk_misc_set_alignment ( GTK_MISC ( label ), 1.0, 0.5 );
225   ::gtk_table_attach ( GTK_TABLE ( table ), label, 0, 1, 1, 2,
226 		       GTK_FILL, GTK_FILL, 0, 0 );
227   ::gtk_widget_show ( label );
228 
229   scale = ::pisa_create_scale ( & ::g_scale_highlight );
230   ::gtk_widget_set_usize ( scale, 200, -1 );
231   ::gtk_scale_set_digits ( GTK_SCALE ( scale ), 0 );
232   ::gtk_range_set_update_policy ( GTK_RANGE ( scale ), GTK_UPDATE_DELAYED );
233   ::gtk_table_attach ( GTK_TABLE ( table ), scale, 1, 2, 1, 2,
234 		       GTK_FILL, GTK_FILL, 0, 0 );
235   ::gtk_widget_show ( scale );
236 
237   // shadow
238   label = ::gtk_label_new ( _( "Shadow:" ) );
239   ::gtk_misc_set_alignment ( GTK_MISC ( label ), 1.0, 0.5 );
240   ::gtk_table_attach ( GTK_TABLE ( table ), label, 0, 1, 2, 3,
241 		       GTK_FILL, GTK_FILL, 0, 0 );
242   ::gtk_widget_show ( label );
243 
244   scale = pisa_create_scale ( & ::g_scale_shadow );
245   ::gtk_widget_set_usize ( scale, 200, -1 );
246   ::gtk_scale_set_digits ( GTK_SCALE ( scale ), 0 );
247   ::gtk_range_set_update_policy ( GTK_RANGE ( scale ), GTK_UPDATE_DELAYED );
248   ::gtk_table_attach ( GTK_TABLE ( table ), scale, 1, 2, 2, 3,
249 		       GTK_FILL, GTK_FILL, 0, 0 );
250   ::gtk_widget_show ( scale );
251 
252   // threshold
253   label = ::gtk_label_new ( _( "Threshold:" ) );
254   ::gtk_misc_set_alignment ( GTK_MISC ( label ), 1.0, 0.5 );
255   ::gtk_table_attach ( GTK_TABLE ( table ), label, 0, 1, 3, 4,
256 		       GTK_FILL, GTK_FILL, 0, 0 );
257   ::gtk_widget_show ( label );
258 
259   scale = pisa_create_scale ( & ::g_scale_threshold );
260   ::gtk_widget_set_usize ( scale, 200, -1 );
261   ::gtk_scale_set_digits ( GTK_SCALE ( scale ), 0 );
262   ::gtk_range_set_update_policy ( GTK_RANGE ( scale ), GTK_UPDATE_DELAYED );
263   ::gtk_table_attach ( GTK_TABLE ( table ), scale, 1, 2, 3, 4,
264 		       GTK_FILL, GTK_FILL, 0, 0 );
265   ::gtk_widget_show ( scale );
266 
267   return table;
268 }
269