1 /************************************************************************************\ 2 3 common.h - common code for scl, pml and soap backends 4 5 (c) 2001-2006 Copyright HP 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 113 #define MULTIPICK_DISABLE 0 114 #define MULTIPICK_ENABLE 1 115 116 #define BEND_GET_SHORT(s) (((s)[0]<<8)|((s)[1])) 117 #define BEND_GET_LONG(s) (((s)[0]<<24)|((s)[1]<<16)|((s)[2]<<8)|((s)[3])) 118 #define BEND_SET_SHORT(s,x) ((s)[0]=((x)>>8)&0xFF,(s)[1]=(x)&0xFF) 119 #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) 120 #define LEND_GET_SHORT(s) (((s)[1]<<8)|((s)[0])) 121 #define LEND_GET_LONG(s) (((s)[3]<<24)|((s)[2]<<16)|((s)[1]<<8)|((s)[0])) 122 #define LEND_SET_SHORT(s,x) ((s)[1]=((x)>>8)&0xFF,(s)[0]=(x)&0xFF) 123 #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) 124 125 #define GEOMETRY_OPTION_TYPE SANE_TYPE_FIXED 126 #define MILLIMETER_SHIFT_FACTOR SANE_FIXED_SCALE_SHIFT 127 128 #define DECIPOINTS_PER_INCH 720 129 #define DEVPIXELS_PER_INCH 300 130 #define MILLIMETERS_PER_10_INCHES 254 131 #define INCHES_PER_254_MILLIMETERS 10 132 133 #define BYTES_PER_LINE(pixelsPerLine,bitsPerPixel) \ 134 ((((pixelsPerLine)*(bitsPerPixel))+7)/8) 135 136 #define INCHES_TO_MILLIMETERS(inches) \ 137 DivideAndShift(__LINE__, \ 138 (inches), \ 139 MILLIMETERS_PER_10_INCHES, \ 140 INCHES_PER_254_MILLIMETERS, \ 141 MILLIMETER_SHIFT_FACTOR) 142 143 #define DECIPIXELS_TO_MILLIMETERS(decipixels) \ 144 DivideAndShift(__LINE__, \ 145 (decipixels), \ 146 MILLIMETERS_PER_10_INCHES, \ 147 INCHES_PER_254_MILLIMETERS*hpaio->decipixelsPerInch, \ 148 MILLIMETER_SHIFT_FACTOR) 149 150 #define MILLIMETERS_TO_DECIPIXELS(millimeters) \ 151 DivideAndShift(__LINE__, \ 152 (millimeters), \ 153 INCHES_PER_254_MILLIMETERS*hpaio->decipixelsPerInch, \ 154 MILLIMETERS_PER_10_INCHES, \ 155 -MILLIMETER_SHIFT_FACTOR) 156 157 #define PIXELS_TO_MILLIMETERS(pixels,pixelsPerInch) \ 158 DivideAndShift(__LINE__, \ 159 (pixels), \ 160 MILLIMETERS_PER_10_INCHES, \ 161 (pixelsPerInch)*INCHES_PER_254_MILLIMETERS, \ 162 MILLIMETER_SHIFT_FACTOR) 163 164 #define MILLIMETERS_TO_PIXELS(millimeters,pixelsPerInch) \ 165 DivideAndShift(__LINE__, \ 166 (millimeters), \ 167 INCHES_PER_254_MILLIMETERS*(pixelsPerInch), \ 168 MILLIMETERS_PER_10_INCHES, \ 169 -MILLIMETER_SHIFT_FACTOR) 170 171 #define ADD_XFORM(x) \ 172 do { \ 173 pXform->eXform=x; \ 174 pXform++; \ 175 } while(0) 176 177 int __attribute__ ((visibility ("hidden"))) bug(const char *fmt, ...); 178 void __attribute__ ((visibility ("hidden"))) sysdump(const void *data, int size); 179 void __attribute__ ((visibility ("hidden"))) bugdump(const void *data, int size); 180 char __attribute__ ((visibility ("hidden"))) *psnprintf(char *buf, int bufSize, const char *fmt, ...); 181 unsigned long __attribute__ ((visibility ("hidden"))) DivideAndShift(int line, unsigned long numerator1, unsigned long numerator2, 182 unsigned long denominator, int shift); 183 void __attribute__ ((visibility ("hidden"))) NumListClear( int * list ); 184 int __attribute__ ((visibility ("hidden"))) NumListIsInList( int * list, int n ); 185 int __attribute__ ((visibility ("hidden"))) NumListAdd( int * list, int n ); 186 int __attribute__ ((visibility ("hidden"))) NumListGetCount( int * list ); 187 int __attribute__ ((visibility ("hidden"))) NumListGetFirst( int * list ); 188 void __attribute__ ((visibility ("hidden"))) StrListClear( const char ** list ); 189 int __attribute__ ((visibility ("hidden"))) StrListIsInList( const char ** list, char * s ); 190 int __attribute__ ((visibility ("hidden"))) StrListAdd( const char ** list, char * s ); 191 char* __attribute__ ((visibility ("hidden"))) itoa(int value, char* str, int radix); 192 #endif 193