1 /************************************************************************************\
3 common.h - common code for scl, pml and soap backends
5 (c) 2001-2006 Copyright Hewlett-Packard Development Company, LP
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:
14 The above copyright notice and this permission notice shall be included in all
15 copies or substantial portions of the Software.
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.
24 Contributing Authors: David Paschal, Don Welch, David Suffield, Sarbeswar Meher
26 \************************************************************************************/
33 // Uncomment the following line to get verbose debugging output
36 #define _STRINGIZE(x) #x
37 #define STRINGIZE(x) _STRINGIZE(x)
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);}
43 #define DBG_DUMP(data, size) sysdump((data), (size))
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)
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)
54 #define BACKEND_NAME hpaio
56 #define BREAKPOINT __asm( "int3" )
60 #define MAX_LIST_SIZE 32
61 #define EXCEPTION_TIMEOUT 45 /* seconds */
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")
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")
74 #define STR_TITLE_ADVANCED SANE_I18N("Advanced")
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.")
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.")
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).")
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.")
93 #define STR_TITLE_GEOMETRY SANE_I18N("Geometry")
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.")
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("???")
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
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)
121 #define GEOMETRY_OPTION_TYPE SANE_TYPE_FIXED
122 #define MILLIMETER_SHIFT_FACTOR SANE_FIXED_SCALE_SHIFT
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
129 #define BYTES_PER_LINE(pixelsPerLine,bitsPerPixel) \
130 ((((pixelsPerLine)*(bitsPerPixel))+7)/8)
132 #define INCHES_TO_MILLIMETERS(inches) \
133 DivideAndShift(__LINE__, \
135 MILLIMETERS_PER_10_INCHES, \
136 INCHES_PER_254_MILLIMETERS, \
137 MILLIMETER_SHIFT_FACTOR)
139 #define DECIPIXELS_TO_MILLIMETERS(decipixels) \
140 DivideAndShift(__LINE__, \
142 MILLIMETERS_PER_10_INCHES, \
143 INCHES_PER_254_MILLIMETERS*hpaio->decipixelsPerInch, \
144 MILLIMETER_SHIFT_FACTOR)
146 #define MILLIMETERS_TO_DECIPIXELS(millimeters) \
147 DivideAndShift(__LINE__, \
149 INCHES_PER_254_MILLIMETERS*hpaio->decipixelsPerInch, \
150 MILLIMETERS_PER_10_INCHES, \
151 -MILLIMETER_SHIFT_FACTOR)
153 #define PIXELS_TO_MILLIMETERS(pixels,pixelsPerInch) \
154 DivideAndShift(__LINE__, \
156 MILLIMETERS_PER_10_INCHES, \
157 (pixelsPerInch)*INCHES_PER_254_MILLIMETERS, \
158 MILLIMETER_SHIFT_FACTOR)
160 #define MILLIMETERS_TO_PIXELS(millimeters,pixelsPerInch) \
161 DivideAndShift(__LINE__, \
163 INCHES_PER_254_MILLIMETERS*(pixelsPerInch), \
164 MILLIMETERS_PER_10_INCHES, \
165 -MILLIMETER_SHIFT_FACTOR)
167 #define ADD_XFORM(x) \
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);