Tizen 2.1 base
[platform/upstream/hplip.git] / scan / sane / common.h
1 /************************************************************************************\
2
3   common.h - common code for scl, pml and soap backends
4
5   (c) 2001-2006 Copyright Hewlett-Packard Development Company, LP
6
7   Permission is hereby granted, free of charge, to any person obtaining a copy 
8   of this software and associated documentation files (the "Software"), to deal 
9   in the Software without restriction, including without limitation the rights 
10   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 
11   of the Software, and to permit persons to whom the Software is furnished to do 
12   so, subject to the following conditions:
13
14   The above copyright notice and this permission notice shall be included in all
15   copies or substantial portions of the Software.
16
17   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
18   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 
19   FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 
20   COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 
21   IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
22   WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
24   Contributing Authors: David Paschal, Don Welch, David Suffield, Sarbeswar Meher 
25
26 \************************************************************************************/
27
28 #ifndef _COMMON_H
29 #define _COMMON_H
30
31 #include <syslog.h>
32
33 // Uncomment the following line to get verbose debugging output
34 //#define HPAIO_DEBUG
35
36 #define _STRINGIZE(x) #x
37 #define STRINGIZE(x) _STRINGIZE(x)
38
39 #define BUG(args...) {syslog(LOG_ERR, __FILE__ " " STRINGIZE(__LINE__) ": " args); DBG(2, __FILE__ " " STRINGIZE(__LINE__) ": " args);}
40 #define BUG_DUMP(data, size) bugdump((data), (size))
41 #define BUG_SZ(args...) {syslog(LOG_ERR, args); DBG(2, args);}
42
43 #define DBG_DUMP(data, size) sysdump((data), (size))
44 #if 1
45    #define DBG6(args...) DBG(6, __FILE__ " " STRINGIZE(__LINE__) ": " args)
46    #define DBG8(args...) DBG(8, __FILE__ " " STRINGIZE(__LINE__) ": " args)
47    #define DBG_SZ(args...) DBG(6, args)
48 #else
49    #define DBG6(args...) syslog(LOG_INFO, __FILE__ " " STRINGIZE(__LINE__) ": " args)
50    #define DBG8(args...) syslog(LOG_INFO, __FILE__ " " STRINGIZE(__LINE__) ": " args)
51    #define DBG_SZ(args...) syslog(LOG_INFO, args)
52 #endif
53
54 #define BACKEND_NAME hpaio
55
56 #define BREAKPOINT __asm( "int3" )
57
58 #define OK 1
59 #define ERROR 0
60 #define MAX_LIST_SIZE 32
61 #define EXCEPTION_TIMEOUT 45 /* seconds */
62
63 #define STR_COMPRESSION_NONE  SANE_I18N("None")
64 #define STR_COMPRESSION_MH  SANE_I18N("MH")
65 #define STR_COMPRESSION_MR  SANE_I18N("MR")
66 #define STR_COMPRESSION_MMR SANE_I18N("MMR")
67 #define STR_COMPRESSION_JPEG  SANE_I18N("JPEG")
68
69 #define STR_ADF_MODE_AUTO SANE_I18N("Auto")
70 #define STR_ADF_MODE_FLATBED  SANE_I18N("Flatbed")
71 #define STR_ADF_MODE_ADF  SANE_I18N("ADF")
72 #define STR_ADF_MODE_CAMERA  SANE_I18N("Camera")
73
74 #define STR_TITLE_ADVANCED SANE_I18N("Advanced")
75
76 #define STR_NAME_COMPRESSION "compression"
77 #define STR_TITLE_COMPRESSION SANE_I18N("Compression")
78 #define STR_DESC_COMPRESSION SANE_I18N("Selects the scanner compression method for faster scans, possibly at the expense of image quality.")
79
80 #define STR_NAME_JPEG_QUALITY "jpeg-quality"
81 #define STR_TITLE_JPEG_QUALITY SANE_I18N("JPEG compression factor")
82 #define STR_DESC_JPEG_QUALITY SANE_I18N("Sets the scanner JPEG compression factor. Larger numbers mean better compression, " \
83                                                            "and smaller numbers mean better image quality.")
84
85 #define STR_NAME_BATCH_SCAN "batch-scan"
86 #define STR_TITLE_BATCH_SCAN SANE_I18N("Batch scan")
87 #define STR_DESC_BATCH_SCAN SANE_I18N("Enables continuous scanning with automatic document feeder (ADF).")
88
89 #define STR_NAME_DUPLEX "duplex"
90 #define STR_TITLE_DUPLEX SANE_I18N("Duplex")
91 #define STR_DESC_DUPLEX SANE_I18N("Enables scanning on both sides of the page.")
92
93 #define STR_TITLE_GEOMETRY SANE_I18N("Geometry")
94
95 #define STR_NAME_LENGTH_MEASUREMENT "length-measurement"
96 #define STR_TITLE_LENGTH_MEASUREMENT SANE_I18N("Length measurement")
97 #define STR_DESC_LENGTH_MEASUREMENT SANE_I18N("Selects how the scanned image length is measured and " \
98                                    "reported, which is impossible to know in advance for scrollfed scans.")
99
100 #define STR_LENGTH_MEASUREMENT_UNKNOWN    SANE_I18N("Unknown")
101 #define STR_LENGTH_MEASUREMENT_UNLIMITED  SANE_I18N("Unlimited")
102 #define STR_LENGTH_MEASUREMENT_APPROXIMATE  SANE_I18N("Approximate")
103 #define STR_LENGTH_MEASUREMENT_PADDED   SANE_I18N("Padded")
104 #define STR_LENGTH_MEASUREMENT_EXACT    SANE_I18N("Exact")
105 #define STR_UNKNOWN  SANE_I18N("???")
106
107 #define MIN_JPEG_COMPRESSION_FACTOR 0
108 #define MAX_JPEG_COMPRESSION_FACTOR 100
109 /* To prevent "2252" asserts on OfficeJet 600 series: */
110 #define SAFER_JPEG_COMPRESSION_FACTOR 10
111
112 #define BEND_GET_SHORT(s) (((s)[0]<<8)|((s)[1]))
113 #define BEND_GET_LONG(s) (((s)[0]<<24)|((s)[1]<<16)|((s)[2]<<8)|((s)[3]))
114 #define BEND_SET_SHORT(s,x) ((s)[0]=((x)>>8)&0xFF,(s)[1]=(x)&0xFF)
115 #define BEND_SET_LONG(s,x) ((s)[0]=((x)>>24)&0xFF,(s)[1]=((x)>>16)&0xFF,(s)[2]=((x)>>8)&0xFF,(s)[3]=(x)&0xFF)
116 #define LEND_GET_SHORT(s) (((s)[1]<<8)|((s)[0]))
117 #define LEND_GET_LONG(s) (((s)[3]<<24)|((s)[2]<<16)|((s)[1]<<8)|((s)[0]))
118 #define LEND_SET_SHORT(s,x) ((s)[1]=((x)>>8)&0xFF,(s)[0]=(x)&0xFF)
119 #define LEND_SET_LONG(s,x) ((s)[3]=((x)>>24)&0xFF,(s)[2]=((x)>>16)&0xFF,(s)[1]=((x)>>8)&0xFF,(s)[0]=(x)&0xFF)
120
121 #define GEOMETRY_OPTION_TYPE    SANE_TYPE_FIXED
122 #define MILLIMETER_SHIFT_FACTOR   SANE_FIXED_SCALE_SHIFT
123
124 #define DECIPOINTS_PER_INCH     720
125 #define DEVPIXELS_PER_INCH      300
126 #define MILLIMETERS_PER_10_INCHES   254
127 #define INCHES_PER_254_MILLIMETERS  10
128
129 #define BYTES_PER_LINE(pixelsPerLine,bitsPerPixel) \
130     ((((pixelsPerLine)*(bitsPerPixel))+7)/8)
131
132 #define INCHES_TO_MILLIMETERS(inches) \
133     DivideAndShift(__LINE__, \
134     (inches), \
135     MILLIMETERS_PER_10_INCHES, \
136     INCHES_PER_254_MILLIMETERS, \
137     MILLIMETER_SHIFT_FACTOR)
138
139 #define DECIPIXELS_TO_MILLIMETERS(decipixels) \
140     DivideAndShift(__LINE__, \
141     (decipixels), \
142     MILLIMETERS_PER_10_INCHES, \
143     INCHES_PER_254_MILLIMETERS*hpaio->decipixelsPerInch, \
144     MILLIMETER_SHIFT_FACTOR)
145
146 #define MILLIMETERS_TO_DECIPIXELS(millimeters) \
147     DivideAndShift(__LINE__, \
148     (millimeters), \
149     INCHES_PER_254_MILLIMETERS*hpaio->decipixelsPerInch, \
150     MILLIMETERS_PER_10_INCHES, \
151     -MILLIMETER_SHIFT_FACTOR)
152
153 #define PIXELS_TO_MILLIMETERS(pixels,pixelsPerInch) \
154     DivideAndShift(__LINE__, \
155     (pixels), \
156     MILLIMETERS_PER_10_INCHES, \
157     (pixelsPerInch)*INCHES_PER_254_MILLIMETERS, \
158     MILLIMETER_SHIFT_FACTOR)
159
160 #define MILLIMETERS_TO_PIXELS(millimeters,pixelsPerInch) \
161     DivideAndShift(__LINE__, \
162     (millimeters), \
163     INCHES_PER_254_MILLIMETERS*(pixelsPerInch), \
164     MILLIMETERS_PER_10_INCHES, \
165     -MILLIMETER_SHIFT_FACTOR)
166
167 #define ADD_XFORM(x) \
168   do { \
169     pXform->eXform=x; \
170     pXform++; \
171   } while(0)
172
173 int __attribute__ ((visibility ("hidden"))) bug(const char *fmt, ...);
174 void __attribute__ ((visibility ("hidden"))) sysdump(const void *data, int size);
175 void __attribute__ ((visibility ("hidden"))) bugdump(const void *data, int size);
176 char __attribute__ ((visibility ("hidden"))) *psnprintf(char *buf, int bufSize, const char *fmt, ...);
177 unsigned long __attribute__ ((visibility ("hidden"))) DivideAndShift(int line, unsigned long numerator1, unsigned long numerator2,
178                               unsigned long denominator, int shift);
179 void __attribute__ ((visibility ("hidden"))) NumListClear( int * list );
180 int __attribute__ ((visibility ("hidden"))) NumListIsInList( int * list, int n );
181 int __attribute__ ((visibility ("hidden"))) NumListAdd( int * list, int n );
182 int __attribute__ ((visibility ("hidden"))) NumListGetCount( int * list );
183 int __attribute__ ((visibility ("hidden"))) NumListGetFirst( int * list );
184 void __attribute__ ((visibility ("hidden"))) StrListClear( const char ** list );
185 int __attribute__ ((visibility ("hidden"))) StrListIsInList( const char ** list, char * s );
186 int __attribute__ ((visibility ("hidden"))) StrListAdd( const char ** list, char * s );
187 char* __attribute__ ((visibility ("hidden"))) itoa(int value, char* str, int radix);
188 #endif