summaryrefslogtreecommitdiff
path: root/src/xsane.h
blob: b54ee509df37a4b2ea0048adbe2ffa7c752297ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
/* xsane -- a graphical (X11, gtk) scanner-oriented SANE frontend

   xsane.h

   Oliver Rauch <Oliver.Rauch@rauch-domain.de>
   Copyright (C) 1998-2005 Oliver Rauch
   This file is part of the XSANE package.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */ 

/* ---------------------------------------------------------------------------------------------------------------------- */

#ifndef XSANE_H
#define XSANE_H

/* ---------------------------------------------------------------------------------------------------------------------- */

/* needed for most of the xsane sources: */

#ifdef _AIX
# include <lalloca.h>
#endif

#if defined(__hpux) || defined(__sgi)
# include <alloca.h>
#endif

#include <assert.h>
#include <errno.h>
#include <memory.h>
#include <pwd.h>
#include <fcntl.h>
#include <getopt.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <getopt.h>
#include <time.h>

/* OS/2 want sys/types before sys/stat */
#include <sys/types.h>
#include <sys/stat.h>

#include <locale.h>

#include <sane/sane.h>
#include <sane/saneopts.h>
#include "xsaneopts.h"

#include "../include/config.h"
#include "../include/sanei_signal.h"

#include <gdk/gdkkeysyms.h>
#include <gdk/gdk.h>
#include <gtk/gtk.h>

/* ---------------------------------------------------------------------------------------------------------------------- */

#if 0
#define DEF_GTK_ACCEL_LOCKED 0
#else
#define DEF_GTK_ACCEL_LOCKED GTK_ACCEL_LOCKED
#endif

/* ---------------------------------------------------------------------------------------------------------------------- */

/* #define XSANE_TEST */
/* #define SUPPORT_RGBA */
/* #define HAVE_WORKING_GTK_GAMMACURVE */

/* ---------------------------------------------------------------------------------------------------------------------- */

#define XSANE_VERSION		"0.97"
#define XSANE_AUTHOR		"Oliver Rauch"
#define XSANE_COPYRIGHT		"Oliver Rauch"
#define XSANE_DATE		"1998-2005"
#define XSANE_EMAIL		"Oliver.Rauch@xsane.org"
#define XSANE_HOMEPAGE		"http://www.xsane.org"
#define XSANE_COPYRIGHT_TXT	XSANE_DATE " " XSANE_COPYRIGHT

/* ---------------------------------------------------------------------------------------------------------------------- */

#define XSANE_DEBUG_ENVIRONMENT	"XSANE_DEBUG"

#define XSANE_DEFAULT_UMASK		0007
#define XSANE_HOLD_TIME			200
#define XSANE_CONTINUOUS_HOLD_TIME	10
#define XSANE_DEFAULT_DEVICE		"SANE_DEFAULT_DEVICE"
#define XSANE_3PASS_BUFFER_RGB_SIZE	1024

#ifdef HAVE_WINDOWS_H
# define BUGGY_GDK_INPUT_EXCEPTION
# define _WIN32
#endif

#ifdef HAVE_LIBPNG
#ifdef HAVE_LIBZ
# define XSANE_DEFAULT_MAILTYPE XSANE_FILETYPE_PNG
# define XSANE_ACTIVATE_MAIL
#endif
#endif

#ifndef XSANE_DEFAULT_MAILTYPE
#ifdef HAVE_LIBJPEG
# define XSANE_DEFAULT_MAILTYPE XSANE_FILETYPE_JPEG
# define XSANE_ACTIVATE_MAIL
#endif
#endif

#ifndef XSANE_DEFAULT_MAILTYPE
#ifdef HAVE_LIBTIFF
# define XSANE_DEFAULT_MAILTYPE XSANE_FILETYPE_TIFF
# define XSANE_ACTIVATE_MAIL
#endif
#endif

#ifndef XSANE_DEFAULT_MAILTYPE
# define XSANE_DEFAULT_MAILTYPE XSANE_FILETYPE_PNM
#endif


/* ---------------------------------------------------------------------------------------------------------------------- */

#ifndef SLASH
# ifdef _WIN32
#  define SLASH '\\'
# elif defined(HAVE_OS2_H)
#  define SLASH '\\'
# else
#  define SLASH '/'
# endif
#endif

/* *** NOT USED IN THE MOMENT. MAY BE USED LATER *** */
/* ************************************************* */
#ifndef XSANE_FIXED_HOME_DIR
# ifdef _WIN32
#  define XSANE_FIXED_HOME_DIR c:\\SANE-Images
# elif defined(HAVE_OS2_H)
#  define XSANE_FIXED_HOME_DIR c:\\SANE-Images
# else
#  define XSANE_FIXED_HOME_DIR /tmp
# endif
#endif

/* *** FIXED_APPDATA_DIR is used when the environment variable *** */
/* *** ENVIRONMENT_APPDATA_DIR_NAME does not exist. It is used *** */
/* *** to store the configuration files of xsane.              *** */
/* *************************************************************** */
#ifndef XSANE_FIXED_APPDATA_DIR
# ifdef _WIN32
#  define XSANE_FIXED_APPDATA_DIR c:\\SANE
# elif defined(HAVE_OS2_H)
#  define XSANE_FIXED_APPDATA_DIR c:\\SANE
# else
#  define XSANE_FIXED_APPDATA_DIR /tmp
# endif
#endif

/* *** NOT USED IN THE MOMENT. MAY BE USED LATER *** */
/* ************************************************* */
#ifndef ENVIRONMENT_HOME_DIR_NAME
# ifdef _WIN32
#  define ENVIRONMENT_HOME_DIR_NAME HOME
# elif defined(HAVE_OS2_H)
#  define ENVIRONMENT_HOME_DIR_NAME HOME
# else
#  define ENVIRONMENT_HOME_DIR_NAME HOME
# endif
#endif

/* *** ENVIRONMENT_APPDATA_DIR_NAME is used to store the       *** */
/* *** configuration files of xsane.                           *** */
/* *************************************************************** */
#ifndef ENVIRONMENT_APPDATA_DIR_NAME
# ifdef _WIN32
#  define ENVIRONMENT_APPDATA_DIR_NAME APPDATA
# elif defined(HAVE_OS2_H)
#  define ENVIRONMENT_APPDATA_DIR_NAME HOME
# else
#  define ENVIRONMENT_APPDATA_DIR_NAME HOME
# endif
#endif

/* *** NOT USED IN THE MOMENT. MAY BE USED LATER *** */
/* ************************************************* */
#ifndef ENVIRONMENT_SYSTEMROOT_DIR_NAME
# ifdef _WIN32
/* SYSTEMROOT is used on WIN2K and WINXP */
#  define ENVIRONMENT_SYSTEMROOT_DIR_NAME_1 SYSTEMROOT
#  define ENVIRONMENT_SYSTEMROOT_DIR_NAME_2 WINDIR
/* WINDIR is used on WIN98 and WINME */
# elif defined(HAVE_OS2_H)
#  define ENVIRONMENT_SYSTEMROOT_DIR_NAME_1 NONE
#  define ENVIRONMENT_SYSTEMROOT_DIR_NAME_2 NONE
# else
#  define ENVIRONMENT_SYSTEMROOT_DIR_NAME_1 NONE
#  define ENVIRONMENT_SYSTEMROOT_DIR_NAME_2 NONE
# endif
#endif

#ifndef ENVIRONMENT_TEMP_DIR_NAME
# define ENVIRONMENT_TEMP_DIR_NAME TMP
#endif

#ifndef ENVIRONMENT_BROWSER_NAME
# define ENVIRONMENT_BROWSER_NAME BROWSER
#endif

/* *** DEFAULT_BROWSER is used when environment variable       *** */
/* *** BROWSER is not defined at first startup of xsane.       *** */
/* *************************************************************** */
#ifndef DEFAULT_BROWSER
# ifdef _WIN32
#  define DEFAULT_BROWSER "iexplore.exe"
# elif defined(HAVE_OS2_H)
#  define DEFAULT_BROWSER "netscape"
# else
#  define DEFAULT_BROWSER "netscape"
# endif
#endif

/* ---------------------------------------------------------------------------------------------------------------------- */

#include "xsane-text.h"
#include "xsane-fixedtext.h"
#include "xsane-icons.h"
#include "xsane-viewer.h"

/* ---------------------------------------------------------------------------------------------------------------------- */

#if GTK_MAJOR_VERSION == 2
# define HAVE_GTK2
# ifndef _WIN32
#  define USE_GTK2_WINDOW_GET_POSITION
# endif
#endif

#ifdef HAVE_GTK2
# define HAVE_GTK_TEXT_VIEW_H
# define DEF_GTK_MENU_ACCEL_VISIBLE GTK_ACCEL_VISIBLE
#else /* we don't have gtk+-2.0 */
# include "xsane-gtk-1_x-compat.h"
#endif

/* ---------------------------------------------------------------------------------------------------------------------- */

#ifdef ENABLE_NLS
#    include <libintl.h>
#    define _(String) gettext (String)
#    ifdef gettext_noop
#        define N_(String) gettext_noop (String)
#    else
#        define N_(String) (String)
#    endif
#else
/* Stubs that do something close enough.  */
#    define textdomain(String) (String)
#    define gettext(String) (String)
#    define dgettext(Domain,Message) (Message)
#    define dcgettext(Domain,Message,Type) (Message)
#    define bindtextdomain(Domain,Directory) (Domain)
#    define _(String) (String)
#    define N_(String) (String)
#endif

/* ---------------------------------------------------------------------------------------------------------------------- */

#ifdef HAVE_OS2_H
# define strcasecmp stricmp
#endif

/* ---------------------------------------------------------------------------------------------------------------------- */

enum
{
  XSANE_PATH_LOCAL_SANE = 0,
  XSANE_PATH_SYSTEM,
  XSANE_PATH_TMP
};

/* ---------------------------------------------------------------------------------------------------------------------- */

typedef struct
{
  char *name;
  float xoffset;
  float yoffset;
  float width;
  float height;
} pref_default_preset_area_t;

/* ---------------------------------------------------------------------------------------------------------------------- */

typedef struct
  {
    /* The option number of the well-known options.  Each of these may
       be -1 in case the backend doesn't define the respective option.  */
    int scanmode;
    int scansource;
    int preview;
    int dpi;
    int dpi_x;
    int dpi_y;
    int coord[4];
    int gamma_vector;
    int gamma_vector_r;
    int gamma_vector_g;
    int gamma_vector_b;
    int bit_depth;
    int threshold;
    int highlight;
    int highlight_r;
    int highlight_g;
    int highlight_b;
    int shadow;
    int shadow_r;
    int shadow_g;
    int shadow_b;
    int batch_scan_start;
    int batch_scan_loop;
    int batch_scan_end;
    int batch_scan_next_tl_y;
  }
WellKnownOptions;

/* ---------------------------------------------------------------------------------------------------------------------- */

typedef struct
  {
    gchar *label;
    struct DialogElement *elem;
    gint index;
  }
MenuItem;

/* ---------------------------------------------------------------------------------------------------------------------- */

typedef struct DialogElement
  {
    GtkWidget *widget;
    GtkWidget *widget2;
    GtkObject *data;
    int menu_size;		/* # of items in menu (if any) */
    MenuItem *menu;
  }
DialogElement;

/* ---------------------------------------------------------------------------------------------------------------------- */

typedef struct Image_info
  {
    int image_width;
    int image_height;

    int depth;
    int colors;

    double resolution_x;
    double resolution_y;

    double gamma;
    double gamma_red;
    double gamma_green;
    double gamma_blue;

    double brightness;
    double brightness_red;
    double brightness_green;
    double brightness_blue;

    double contrast;
    double contrast_red;
    double contrast_green;
    double contrast_blue;

    double threshold;

    int reduce_to_lineart;
  }
Image_info;

/* ---------------------------------------------------------------------------------------------------------------------- */
#include "xsane-preferences.h"
#include "xsane-preview.h"

/* ---------------------------------------------------------------------------------------------------------------------- */

#ifdef HAVE_ANY_GIMP
# include <libgimp/gimp.h>

# ifdef HAVE_GIMP_2
#     define GIMP_HAVE_RESOLUTION_INFO
# else
#  ifdef HAVE_LIBGIMP_GIMPFEATURES_H
#   include <libgimp/gimpfeatures.h>
#  else
#   define GIMP_CHECK_VERSION(major, minor, micro) 0
#  endif /* HAVE_LIBGIMP_GIMPFEATURES_H */
# endif

# ifdef GIMP_CHECK_VERSION
#  if GIMP_CHECK_VERSION(1,1,25)
/* ok, we have the gimp-1.2 or gimp-2.0 interface */
#  else
/* we have the gimp-1.0 interface and need the compatibility header file */
#   include "xsane-gimp-1_0-compat.h" 
#  endif
# else
/* we have the gimp-1.0 interface and need the compatibility header file */
#  include "xsane-gimp-1_0-compat.h" 
# endif

  extern GimpPlugInInfo PLUG_IN_INFO; /* needed for win32 */

#endif /* HAVE_ANY_GIMP */

/* ---------------------------------------------------------------------------------------------------------------------- */

enum { XSANE_VIEWER, XSANE_SAVE, XSANE_COPY, XSANE_FAX, XSANE_MAIL };
enum { XSANE_LINEART_STANDARD, XSANE_LINEART_XSANE, XSANE_LINEART_GRAYSCALE };

/* ---------------------------------------------------------------------------------------------------------------------- */

extern void xsane_pref_save(void);
extern void xsane_interface(int argc, char **argv);
extern void xsane_fax_project_save(void);
extern void xsane_mail_project_save(void);
extern void xsane_batch_scan_add(void);

/* ---------------------------------------------------------------------------------------------------------------------- */

#ifndef PATH_MAX
# define PATH_MAX	1024
#endif

/* ---------------------------------------------------------------------------------------------------------------------- */
#ifndef TEMP_PATH
# define TEMP_PATH		/tmp/
#endif

#define OUT_FILENAME     	"out.pnm"
#define PRINTERNAME	  	"new printer"
#define PRINTERCOMMAND  	"lpr"
#define PRINTERCOPYNUMBEROPTION "-#"
#define FAXPROJECT 	    	"faxproject"
#define FAXCOMMAND 	 	"sendfax"
#define FAXRECEIVEROPT		"-d"
#define FAXPOSTSCRIPTOPT	""
#define FAXNORMALOPT		"-l"
#define FAXFINEOPT		"-m"
#define FAXVIEWER 	 	"gv"
#define FAXCONVERTPSTOPNM  	"gs -dNOPAUSE -dBATCH -q -r204 -sDEVICE=pnm -sOutputFile="
#define MAILPROJECT 	    	"mailproject"
#define MAILCOMMAND 	 	"sendmail"
#define MAILVIEWER 	 	"xv"
#define OCRCOMMAND 	 	"gocr"
#define OCRINPUTFILEOPT	 	"-i"
#define OCROUTPUTFILEOPT	"-o"
#define OCROUTFDOPT		"-x"
#define OCRPROGRESSKEY		""
#define BROWSER_NETSCAPE	"netscape"

#define XSANE_MEDIUM_CALIB_BRIGHTNESS_MIN	-1000.0
#define XSANE_MEDIUM_CALIB_BRIGHTNESS_MAX	 1000.0
#define XSANE_MEDIUM_CALIB_CONTRAST_MIN	 	-1000.0
#define XSANE_MEDIUM_CALIB_CONTRAST_MAX	 	 1000.0

#define XSANE_BRIGHTNESS_MIN	-100.0
#define XSANE_BRIGHTNESS_MAX	 100.0
#define XSANE_CONTRAST_GRAY_MIN	-100.0
#define XSANE_CONTRAST_MIN	-100.0
#define XSANE_CONTRAST_MAX	 100.0

#define XSANE_GAMMA_MIN		0.3
#define XSANE_GAMMA_MAX		3.0

#define HIST_WIDTH		256
#define HIST_HEIGHT		100
#define XSANE_SHELL_WIDTH	296
#define XSANE_SHELL_HEIGHT	451
#define XSANE_SHELL_POS_X	1
#define XSANE_SHELL_POS_Y	50
#define XSANE_HISTOGRAM_POS_X	280
#define XSANE_HISTOGRAM_POS_Y	50
#define XSANE_GAMMA_POS_X	280
#define XSANE_GAMMA_POS_Y	420
#define XSANE_BATCH_POS_X	480
#define XSANE_BATCH_POS_Y	420
#define XSANE_STD_OPTIONS_POS_X	1
#define XSANE_STD_OPTIONS_POS_Y	400
#define XSANE_ADV_OPTIONS_POS_X	280
#define XSANE_ADV_OPTIONS_POS_Y	420
#define XSANE_PREVIEW_POS_X	560
#define XSANE_PREVIEW_POS_Y	50
#define XSANE_PREVIEW_WIDTH	100
#define XSANE_PREVIEW_HEIGHT	100

#define XSANE_SLIDER_ACTIVE	0
#define XSANE_SLIDER_INACTIVE	4
#define XSANE_SLIDER_WIDTH	260
#define XSANE_SLIDER_HEIGHT	10
#define XSANE_SLIDER_OFFSET	2
#define XSANE_SLIDER_EVENTS	GDK_EXPOSURE_MASK | GDK_ENTER_NOTIFY_MASK | \
				GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | \
				GDK_BUTTON1_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK
#define INF			5.0e9
#define MM_PER_INCH		25.4

/* ---------------------------------------------------------------------------------------------------------------------- */

#define STRINGIFY1(x)   #x
#define STRINGIFY(x)    STRINGIFY1(x)

#define NELEMS(a)       ((int)(sizeof (a) / sizeof (a[0])))

/* ---------------------------------------------------------------------------------------------------------------------- */

enum
{
 XSANE_UNKNOWN, XSANE_PNM, XSANE_JPEG, XSANE_PNG, XSANE_PS, XSANE_TIFF, XSANE_RGBA,
 XSANE_RAW16, XSANE_PNM16, XSANE_TEXT
};
 
/* ---------------------------------------------------------------------------------------------------------------------- */

enum
{
 XSANE_STANDALONE, XSANE_GIMP_EXTENSION
};

/* ---------------------------------------------------------------------------------------------------------------------- */

typedef struct XsanePixmap
{
  GtkWidget *frame;
  GdkPixmap *pixmap;
  GtkWidget *pixmapwid;
} XsanePixmap;

/* ---------------------------------------------------------------------------------------------------------------------- */

typedef struct XsaneSlider
{
  int position[3];
  double value[3];
  double min, max;
  int active;
  GtkWidget *preview;
  int r, g, b;
} XsaneSlider;

/* ---------------------------------------------------------------------------------------------------------------------- */

typedef struct XsaneChildprocess
{
  pid_t pid;
  struct XsaneChildprocess *next;
} XsaneChildprocess;

/* ---------------------------------------------------------------------------------------------------------------------- */

typedef struct Xsane
{
    SANE_Int sane_backend_versioncode;
    char *backend;
    char *backend_translation;
    char *device_set_filename;
    char *output_filename;
    char *dummy_filename;

    SANE_Int sensitivity;

    GtkWidget *xsane_window;
    GtkWidget *standard_window;
    GtkWidget *advanced_window;
    GtkWidget *gamma_window;
    GtkWidget *xsane_hbox;
    GtkWidget *standard_hbox;
    GtkWidget *advanced_hbox;
    GtkWidget *xsanemode_widget;

    GtkAccelGroup *accelerator_group;
    GtkTooltips *tooltips;
    GdkColor tooltips_fg;
    GdkColor tooltips_bg;

    SANE_Handle *dev;
    const char *dev_name;
    WellKnownOptions well_known;
    int num_elements;
    DialogElement *element;
    u_int rebuild : 1;
    int pixelcolor;
    int scanning;
    int reading_data;
    int cancel_scan;

    int batch_scan_load_default_list;	/* load default list at program startup flag */
    int batch_loop; /* is set when batch scanning and not last scan */
    int batch_scan_use_stored_scanmode;
    int batch_scan_use_stored_resolution;
    int batch_scan_use_stored_bit_depth;
    SANE_Status status_of_last_scan;

/* free gamma curve widgets */
    GtkWidget *gamma_curve_gray;
    GtkWidget *gamma_curve_red;
    GtkWidget *gamma_curve_green;
    GtkWidget *gamma_curve_blue;

/* previous global stand alone varaibales */
    const char   *prog_name;      /* name of this program, normally "xsane" */
    const char   *device_text;      /* name of the selected device */
    GtkWidget    *choose_device_dialog;      /* the widget of the device selection dialog */
    const SANE_Device **devlist;      /* the list of available devices */
    int          selected_dev;        /* the selected device */
    int          num_of_devs;
    int          back_gtk_message_dialog_active;


    /* dialogs */
    GtkWidget *shell;
    GtkWidget *menubar;
    GtkWidget *standard_options_shell;
    GtkWidget *advanced_options_shell;
    GtkWidget *main_dialog_scrolled;
    GtkWidget *histogram_dialog;
    GtkWidget *gamma_dialog;

    GtkWidget *batch_scan_dialog;
    GtkWidget *batch_scan_button_box;
    GtkWidget *batch_scan_action_box;
    GtkWidget *batch_scan_list;
    GtkAdjustment *batch_scan_vadjustment;

    GtkWidget *fax_dialog;
    GtkWidget *fax_list;
    GtkWidget *fax_project_box;
    GtkWidget *fax_project_exists;
    GtkWidget *fax_project_not_exists;
    GtkWidget *fax_project_entry;
    GtkWidget *fax_project_entry_box;
    GtkWidget *fax_receiver_entry;
    GtkProgressBar *fax_progress_bar;

    GtkWidget *mail_dialog;
    GtkWidget *mail_list;
    GtkWidget *mail_project_box;
    GtkWidget *mail_project_exists;
    GtkWidget *mail_project_not_exists;
    GtkWidget *mail_project_entry;
    GtkWidget *mail_project_entry_box;
    GtkWidget *mail_receiver_entry;
    GtkWidget *mail_subject_entry;
    GtkWidget *mail_text_widget;
    GtkWidget *mail_html_mode_widget;
    GtkProgressBar *mail_progress_bar;

    GdkPixmap *window_icon_pixmap;
    GdkBitmap *window_icon_mask;        

    GtkWidget *hruler;
    GtkWidget *vruler;
    GtkWidget *info_label;
    GtkObject *start_button;
    GtkObject *cancel_button;
    GtkSignalFunc cancel_callback;
    Viewer    *viewer_list;
    Preview   *preview;
    int preview_gamma_size;
    int mode;
    int medium_nr;

    int main_window_fixed;
    int mode_selection;

#ifndef USE_GTK2_WINDOW_GET_POSITION
    int get_deskrelative_origin;
#endif

    /* various scanning related state: */
    SANE_Int depth;
    size_t num_bytes;
    size_t bytes_read;
    int read_offset_16;
    char last_offset_16_byte;
    int  lineart_to_grayscale_x;
    GtkProgressBar *progress_bar;
    int input_tag;
    SANE_Parameters param;
    int adf_page_counter;
    int scan_rotation;

    /* for standalone mode: */
    GtkWidget *filename_entry;
    GtkWidget *filetype_option_menu;

    /* saving and transformation values: */
    FILE *out;
    int xsane_mode;
    int xsane_output_format;
    long header_size;
    int expand_lineart_to_grayscale;
    int reduce_16bit_to_8bit;

    /* histogram window */
    struct XsanePixmap histogram_raw;
    struct XsanePixmap histogram_enh;

    struct XsaneSlider slider_gray;
    struct XsaneSlider slider_red;
    struct XsaneSlider slider_green;
    struct XsaneSlider slider_blue;
    guint  batch_scan_gamma_timer; /* has to be guint */
    guint  slider_timer; /* has to be guint */
    int    slider_timer_restart;

    double auto_white;
    double auto_gray;
    double auto_black;
    double auto_white_red;
    double auto_gray_red;
    double auto_black_red;
    double auto_white_green;
    double auto_gray_green;
    double auto_black_green;
    double auto_white_blue;
    double auto_gray_blue;
    double auto_black_blue;

    int histogram_red;
    int histogram_green;
    int histogram_blue;
    int histogram_int;
    int histogram_lines;
    int histogram_log;

    int no_preview_medium_gamma; /* disable preview medium gamma */
    int medium_calibration; /* enable calibration mode for medium */
    int brightness_min;
    int brightness_max;
    int contrast_gray_min;
    int contrast_min;
    int contrast_max;

    /* colors */
    GdkGC *gc_red;
    GdkGC *gc_green;
    GdkGC *gc_blue;
    GdkGC *gc_black;
    GdkGC *gc_trans;
    GdkGC *gc_backg;
    GdkColor *bg_trans;

    int copy_number;
    double zoom;
    double zoom_x;
    double zoom_y;
    double resolution;
    double resolution_x;
    double resolution_y;

    GtkWidget *medium_widget;
    GtkWidget *length_unit_mm;
    GtkWidget *length_unit_cm;
    GtkWidget *length_unit_in;
    GtkWidget *update_policy_continu;
    GtkWidget *update_policy_discont;
    GtkWidget *update_policy_delayed;
    GtkWidget *show_preview_widget;
    GtkWidget *show_histogram_widget;
    GtkWidget *show_gamma_widget;
    GtkWidget *show_batch_scan_widget;
    GtkWidget *show_standard_options_widget;
    GtkWidget *show_advanced_options_widget;
    GtkWidget *show_resolution_list_widget;
    GtkObject *zoom_widget;
    GtkObject *gamma_widget;
    GtkObject *gamma_red_widget;
    GtkObject *gamma_green_widget;
    GtkObject *gamma_blue_widget;
    GtkObject *brightness_widget;
    GtkObject *brightness_red_widget;
    GtkObject *brightness_green_widget;
    GtkObject *brightness_blue_widget;
    GtkObject *contrast_widget;
    GtkObject *contrast_red_widget;
    GtkObject *contrast_green_widget;
    GtkObject *contrast_blue_widget;
    GtkObject *threshold_widget;

    SANE_Int xsane_colors;
    SANE_Bool scanner_gamma_color;
    SANE_Bool scanner_gamma_gray;

    int mail_project_save;
    int mail_html_mode;

    GtkWidget *outputfilename_entry;
    GtkWidget *copy_number_entry;

    gfloat *free_gamma_data, *free_gamma_data_red, *free_gamma_data_green, *free_gamma_data_blue;
    SANE_Int *gamma_data, *gamma_data_red, *gamma_data_green, *gamma_data_blue;
    u_char *preview_gamma_data_red, *preview_gamma_data_green, *preview_gamma_data_blue;
    u_char *histogram_gamma_data_red, *histogram_gamma_data_green, *histogram_gamma_data_blue;
    u_char *histogram_medium_gamma_data_red, *histogram_medium_gamma_data_green, *histogram_medium_gamma_data_blue;

    char *fax_status;
    char *fax_filename;
    char *fax_receiver;

    float mail_progress_val;
    int   mail_progress_size;
    int   mail_progress_bytes;
    char *mail_status;
    char *mail_filename;
    char *mail_receiver;
    char *mail_subject;

    int block_update_param;
    int block_enhancement_update;

    int broken_pipe; /* for printercommand pipe */

    int cancel_save;

/* -------------------------------------------------- */

/* device preferences: */

/* we have to use double and int here, gint or SANE_Word
   is not allowed because we need a defined size for
   rc_io-routintes that are based on double, int, ... */

    /* window position and geometry */
    int shell_posx;
    int shell_posy;
    int shell_height;
    int shell_width;
    int standard_options_shell_posx;
    int standard_options_shell_posy;
    int advanced_options_shell_posx;
    int advanced_options_shell_posy;
    int histogram_dialog_posx;
    int histogram_dialog_posy;
    int gamma_dialog_posx;
    int gamma_dialog_posy;
    int batch_dialog_posx;
    int batch_dialog_posy;
    int preview_dialog_posx;
    int preview_dialog_posy;
    int preview_dialog_width;
    int preview_dialog_height;

    double medium_gamma_gray;
    double medium_gamma_red;
    double medium_gamma_green;
    double medium_gamma_blue;

    double medium_shadow_gray;
    double medium_shadow_red;
    double medium_shadow_green;
    double medium_shadow_blue;

    double medium_highlight_gray;
    double medium_highlight_red;
    double medium_highlight_green;
    double medium_highlight_blue;

    int medium_negative;

    int medium_changed;

    double gamma;
    double gamma_red;
    double gamma_green;
    double gamma_blue;

    double brightness;
    double brightness_red;
    double brightness_green;
    double brightness_blue;

    double contrast;
    double contrast_red;
    double contrast_green;
    double contrast_blue;

    int lineart_mode;
    double threshold;
    double threshold_min;
    double threshold_max;
    double threshold_mul;
    double threshold_off;
    char *grayscale_scanmode;

    int enhancement_rgb_default;
    int negative;
    int show_preview;
    int print_filenames;
    int force_filename;
    char *external_filename;
    char *adf_scansource;

/* -------------------------------------------------- */

    int ipc_pipefd[2]; /* for inter process communication error messages */
    XsaneChildprocess *childprocess_list;

} Xsane;

extern struct Xsane xsane;

/* ---------------------------------------------------------------------------------------------------------------------- */

typedef struct XsaneSetup
{
  GtkWidget *printer_name_entry;
  GtkWidget *printer_command_entry;
  GtkWidget *printer_copy_number_option_entry;
  GtkWidget *printer_lineart_resolution_entry;
  GtkWidget *printer_grayscale_resolution_entry;
  GtkWidget *printer_color_resolution_entry;
  GtkWidget *printer_leftoffset_entry;
  GtkWidget *printer_bottomoffset_entry;
  GtkWidget *printer_gamma_entry;
  GtkWidget *printer_gamma_red_entry;
  GtkWidget *printer_gamma_green_entry;
  GtkWidget *printer_gamma_blue_entry;
  GtkWidget *printer_width_entry;
  GtkWidget *printer_height_entry;

  GtkWidget *jpeg_image_quality_scale;
  GtkWidget *pnm_image_compression_scale;
  GtkWidget *save_devprefs_at_exit_button;
  GtkWidget *overwrite_warning_button;
  GtkWidget *increase_filename_counter_button;
  GtkWidget *skip_existing_numbers_button;
  GtkWidget *save_pnm16_as_ascii_button;
  GtkWidget *reduce_16bit_to_8bit_button;

  GtkWidget *main_window_fixed_button;

  GtkWidget *preview_gamma_entry;
  GtkWidget *preview_gamma_red_entry;
  GtkWidget *preview_gamma_green_entry;
  GtkWidget *preview_gamma_blue_entry;
  GtkWidget *preview_lineart_mode_entry;
  GtkWidget *preview_grayscale_scanmode_widget;
  GtkWidget *preview_threshold_min_entry;
  GtkWidget *preview_threshold_max_entry;
  GtkWidget *preview_threshold_mul_entry;
  GtkWidget *preview_threshold_off_entry;
  GtkWidget *auto_enhance_gamma_button;
  GtkWidget *preselect_scanarea_button;
  GtkWidget *auto_correct_colors_button;
  GtkWidget *disable_gimp_preview_gamma_button;
  GtkWidget *preview_oversampling_entry;
  GtkWidget *preview_own_cmap_button;
  GtkWidget *browser_entry;

  GtkWidget *fax_command_entry;
  GtkWidget *fax_receiver_option_entry;
  GtkWidget *fax_postscript_option_entry;
  GtkWidget *fax_normal_option_entry;
  GtkWidget *fax_fine_option_entry;
  GtkWidget *fax_viewer_entry;
  GtkWidget *fax_width_entry;
  GtkWidget *fax_leftoffset_entry;
  GtkWidget *fax_bottomoffset_entry;
  GtkWidget *fax_height_entry;
  GtkWidget *tmp_path_entry;

  GtkWidget *mail_smtp_server_entry;
  GtkWidget *mail_smtp_port_entry;
  GtkWidget *mail_from_entry;
  GtkWidget *mail_reply_to_entry;
  GtkWidget *mail_pop3_authentification_entry;
  GtkWidget *mail_pop3_server_entry;
  GtkWidget *mail_pop3_port_entry;
  GtkWidget *mail_pop3_user_entry;
  GtkWidget *mail_pop3_pass_entry;
  GtkWidget *mail_viewer_entry;

  GtkWidget *ocr_command_entry;
  GtkWidget *ocr_inputfile_option_entry;
  GtkWidget *ocr_outputfile_option_entry;
  GtkWidget *ocr_use_gui_pipe_entry;
  GtkWidget *ocr_gui_outfd_option_entry;
  GtkWidget *ocr_progress_keyword_entry;

  int filename_counter_len;

  int tiff_compression16_nr;
  int tiff_compression8_nr;
  int tiff_compression1_nr;

  int show_range_mode;
  int lineart_mode;

  int image_permissions;
  int directory_permissions;

  int preview_pipette_range;

  char *grayscale_scanmode;
  char *adf_scansource;

} XsaneSetup;

extern struct XsaneSetup xsane_setup;

/* ---------------------------------------------------------------------------------------------------------------------- */

extern int DBG_LEVEL;

#ifdef __GNUC__
# define DBG(level, msg, args...)                \
  {                                              \
    if (DBG_LEVEL >= (level))                    \
    {                                            \
      fprintf (stderr, "[xsane] " msg, ##args);  \
      fflush(stderr);                            \
    }                                            \
  }
#else
  extern void xsane_debug_message(int level, const char *fmt, ...);
# define DBG xsane_debug_message
#endif

# define DBG_init()                                          \
  {                                                          \
   char *dbg_level_string = getenv(XSANE_DEBUG_ENVIRONMENT); \
                                                             \
    if (dbg_level_string)                                    \
    {                                                        \
      DBG_LEVEL = atoi(dbg_level_string);                    \
      DBG(1, "Setting debug level to %d\n", DBG_LEVEL);      \
    }                                                        \
  }

#define DBG_error0    0
#define DBG_error     1
#define DBG_warning   2
#define DBG_info      3
#define DBG_info2     4
#define DBG_proc      5
#define DBG_proc2     50
#define DBG_optdesc   70	/* xsane_get_option_descriptor */
#define DBG_proc3     100	/* for routines that are called very very often */
#define DBG_wire      100	/* rc_io_w routines */

/* ---------------------------------------------------------------------------------------------------------------------- */

#endif