1 /* xsane -- a graphical (X11, gtk) scanner-oriented SANE frontend
2 
3    xsane-preview.h
4 
5    Oliver Rauch <Oliver.Rauch@rauch-domain.de>
6    Copyright (C) 1998-2007 Oliver Rauch
7    This file is part of the XSANE package.
8 
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13 
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18 
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
22 
23 /* ------------------------------------------------------------------------------------------------------ */
24 
25 #ifndef xsanepreview_h
26 #define xsanepreview_h
27 
28 /* ------------------------------------------------------------------------------------------------------ */
29 
30 #include <sys/types.h>
31 #include <sane/sane.h>
32 #include "xsane-batch-scan.h"
33 
34 #define SELECTION_RANGE_IN  4
35 #define SELECTION_RANGE_OUT 8
36 #define XSANE_CURSOR_PREVIEW GDK_LEFT_PTR
37 
38 /* ------------------------------------------------------------------------------------------------------ */
39 
40 enum
41 {
42   MODE_NORMAL,
43   MODE_PIPETTE_WHITE,
44   MODE_PIPETTE_GRAY,
45   MODE_PIPETTE_BLACK,
46   MODE_AUTORAISE_SCAN_AREA,
47   MODE_ZOOM_IN
48 };
49 
50 /* ------------------------------------------------------------------------------------------------------ */
51 
52 #if 0
53 typedef struct Batch_selection
54 {
55   float coordinate[4]; /* batch selection coordinate (device coord) */
56   struct Batch_selection *next;
57 } Batch_selection;
58 #endif
59 
60 typedef struct
61 {
62   int active;
63   float coordinate[4]; /* selection coordinate (device coord) */
64 } Tselection;
65 
66 /* ------------------------------------------------------------------------------------------------------ */
67 
68 typedef struct
69 {
70   int mode;
71   int calibration;
72   int startimage;
73 
74   int cursornr;
75 
76   guint hold_timer;
77 
78   char *filename[3];		/* filenames for preview level 0,1,2 */
79 
80   SANE_Value_Type surface_type;
81   SANE_Unit surface_unit;
82   float orig_scanner_surface[4];/* the scanner defined corners of the scanner surface (device coords) */
83   float image_surface[4];	/* the corners of the surface (device coords) of the scanned image */
84   float max_scanner_surface[4];	/* rotated corners of the scanner surface (window coords) */
85   float preset_surface[4];	/* the corners of the reduced (by user) surface (window coords) */
86   float scanner_surface[4];	/* the user defined corners of the scanner surface (window coords) */
87   float surface[4];		/* the corners of the selected surface (window coords) */
88   float old_surface[4];		/* the corners of the old selected surface (window coords) */
89   float aspect;			/* the aspect ratio of the scan surface */
90 
91   float maximum_output_width;	/* maximum output width (photocopy) */
92   float maximum_output_height;	/* maximum output height (photocopy) */
93   int paper_orientation;	/* orientation of the paper (photocopy) */
94   int block_update_maximum_output_size_clipping; /* do not clip maximum output size */
95 
96   int index_xmin, index_xmax, index_ymin, index_ymax; /* index numbers in dependance of p->rotation */
97 
98   int saved_dpi_valid;
99   int saved_dpi_x_valid;
100   int saved_dpi_y_valid;
101   SANE_Word saved_dpi;
102   SANE_Word saved_dpi_x;
103   SANE_Word saved_dpi_y;
104   int saved_coord_valid[4];
105   SANE_Word saved_coord[4];
106   int saved_custom_gamma_valid;
107   SANE_Word saved_custom_gamma;
108   int saved_bit_depth_valid;
109   SANE_Word saved_bit_depth;
110   int saved_scanmode_valid;
111   char saved_scanmode[64]; /* I hope that is enough or we will get segaults or strange effects */
112 
113     /* desired/user-selected preview-window size: */
114   int preview_width;		/* used with for displaying the preview image */
115   int preview_height;		/* used height for displaying the preview image */
116   int preview_window_width;	/* width of the preview window */
117   int preview_window_height;	/* height of the preview window */
118   u_char *preview_row;
119 
120   int scanning;
121   int read_offset_16;
122   char last_offset_16_byte;
123   int scan_incomplete;
124   int invalid;
125   int preview_channels;
126   time_t image_last_time_updated;
127   gint input_tag;
128   SANE_Parameters params;
129   int image_offset;
130   int image_x;
131   int image_y;
132   int image_width;		/* width of preview image in pixels */
133   int image_height;		/* height of preview image in pixel lines */
134   int rotation;			/* rotation: 0=0, 1=90, 2=180, 3=270 degree, 4-7= rotation + mirror in x direction */
135   int gamma_functions_interruptable; /* bit that defines if gamma function can be interrupted */
136   guint16 *image_data_raw;	/* 3 * image_width * image_height bytes * 2 */
137   u_char *image_data_enh;	/* 3 * image_width * image_height bytes */
138 
139   GdkGC *gc_selection;
140   GdkGC *gc_selection_maximum;
141   int selection_drag;
142   int selection_drag_edge;
143   int selection_xpos;
144   int selection_ypos;
145   int selection_xedge;
146   int selection_yedge;
147   float ratio;
148 
149   Tselection selection;				/* selected area to scan */
150   Tselection previous_selection;		/* previous ... */
151   Tselection selection_maximum;			/* maximum selection size (photocopy) */
152   Tselection previous_selection_maximum;	/* previous ... */
153 
154   int show_selection;
155 
156 #ifdef HAVE_LIBLCMS
157   int cms_enable;
158   int cms_proofing;
159   int cms_proofing_intent;
160   int cms_gamut_check;
161 #endif
162 
163 #if 0
164   Batch_selection *batch_selection;
165 #endif
166 
167   GtkWidget *top;		/* top-level widget */
168   GtkWidget *unit_label;
169   GtkWidget *hruler;
170   GtkWidget *vruler;
171   GtkWidget *viewport;
172   GtkWidget *window;		/* the preview window */
173   GtkWidget *start;		/* the start button */
174   GtkWidget *cancel;		/* the cancel button */
175   GtkWidget *zoom;		/* the zoom */
176 
177   GtkWidget *menu_box;		/* the bottom menu box */
178   GtkWidget *button_box;	/* the bottom button box */
179   GtkWidget *add_batch;		/* add batch button */
180   GtkWidget *pipette_white;	/* pipette white button */
181   GtkWidget *pipette_gray;	/* pipette gray button */
182   GtkWidget *pipette_black;	/* pipette black button */
183   GtkWidget *zoom_not;		/* zoom not button */
184   GtkWidget *zoom_out;		/* zoom out button */
185   GtkWidget *zoom_in;		/* zoom in button */
186   GtkWidget *zoom_area;		/* zoom area button */
187   GtkWidget *zoom_undo;		/* zoom undo button */
188   GtkWidget *full_area;		/* select full scan area */
189   GtkWidget *autoraise;		/* autoraise scan area */
190   GtkWidget *autoselect;	/* autoselect scan area */
191   GtkWidget *preset_area_option_menu;	/* menu for selection of preview area */
192   GtkWidget *rotation_option_menu;	/* menu for selection of rotation */
193   GtkWidget *ratio_option_menu;	/* menu for selection of ratio */
194   GtkWidget *scanning_pixmap;	/* pixmap that shows preview is in scanning progress */
195   GtkWidget *valid_pixmap;	/* pixmap that shows preview is valid */
196   GtkWidget *invalid_pixmap;	/* pixmap that shows preview is invalid */
197   GtkWidget *incomplete_pixmap;	/* pixmap that shows preview is incomplete */
198   GtkWidget *rgb_label;		/* label to show RGB values */
199 }
200 Preview;
201 
202 /* ------------------------------------------------------------------------------------------------------ */
203 
204 extern Preview *preview_new(void);   /* Create a new preview based on the info in DIALOG.  */
205 extern void preview_generate_preview_filenames(Preview *p); /* create new preview filenames */
206 
207 extern void preview_gamma_correction(Preview *p, int gamma_input_bits,
208                                      u_char *gamma_red, u_char *gamma_green, u_char *gamma_blue,
209                                      u_char *gamma_red_hist, u_char *gamma_green_hist, u_char *gamma_blue_hist,
210                                      u_char *medium_gamma_red_hist, u_char *medium_gamma_green_hist, u_char *medium_gamma_blue_hist);
211 
212 extern void preview_update_surface(Preview *p, int surface_changed);   /* params changed: update preview */
213 
214 extern void preview_scan(Preview *p);			     /* Acquire a preview image and display it.  */
215 
216 extern void preview_destroy(Preview *p);					  /* Destroy a preview.  */
217 
218 extern void preview_calculate_raw_histogram(Preview *p, SANE_Int *count_raw, SANE_Int *count_raw_red, SANE_Int *count_raw_green, SANE_Int *count_raw_blue);
219 extern void preview_calculate_enh_histogram(Preview *p, SANE_Int *count, SANE_Int *count_red, SANE_Int *count_green, SANE_Int *count_blue);
220 
221 extern void preview_area_resize(Preview *p);					/* redraw preview rulers */
222 extern void preview_set_maximum_output_size(Preview *p, float width, float height, int paper_orientation); /* set maximum outut size */
223 extern void preview_select_full_preview_area(Preview *p);
224 extern void preview_display_valid(Preview *p);
225 extern void preview_create_batch_icon(Preview *p, Batch_Scan_Parameters *parameters);
226 
227 /* ------------------------------------------------------------------------------------------------------ */
228 
229 #endif /* preview_h */
230