Tizen 2.1 base
[platform/upstream/hplip.git] / scan / sane / hpaio.h
1 /************************************************************************************\
2
3   hpaio.h - HP SANE backend for multi-function peripherals (libsane-hpaio)
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 
25
26 \************************************************************************************/
27
28 #if !defined( __HPAIO_H__ )
29 #define __HPAIO_H__
30
31 #include "sane.h"
32 #include "common.h"
33 #include "mfpdtf.h"
34 #include "hpip.h"
35 #include "scl.h"
36 #include "pml.h"
37
38 /************************************************************************************/
39
40 #define MAX_DEVICE 64     /* Max devices. */
41
42 #define LEN_BUFFER    17408         /* 16384 + 1024, clj28xx used 16396 */
43 #define LEN_DEVICE_ID_STRING  4096
44 #define LEN_STRING_OPTION_VALUE 20
45 #define LEN_MODEL_RESPONSE  20
46
47 #define PAD_VALUE_LINEART            0
48 #define PAD_VALUE_GRAYSCALE_COLOR    -1
49
50 enum hpaioOption_e { 
51     
52     OPTION_FIRST = 0,
53     OPTION_NUM_OPTIONS = 0,
54     
55     GROUP_SCAN_MODE,
56                     OPTION_SCAN_MODE,
57                     OPTION_SCAN_RESOLUTION,
58     GROUP_ADVANCED,
59                     OPTION_CONTRAST,
60                     OPTION_COMPRESSION,
61                     OPTION_JPEG_COMPRESSION_FACTOR,
62                     OPTION_BATCH_SCAN,
63                     OPTION_ADF_MODE, 
64                     OPTION_DUPLEX,
65
66     GROUP_GEOMETRY,
67                     OPTION_LENGTH_MEASUREMENT,
68                     OPTION_TL_X,
69                     OPTION_TL_Y,
70                     OPTION_BR_X,
71                     OPTION_BR_Y,
72
73     OPTION_LAST };
74
75 //#define STR_SCAN_MODE_LINEART "Lineart"
76 //#define STR_SCAN_MODE_GRAYSCALE "Grayscale"
77 //#define STR_SCAN_MODE_COLOR "Color"
78
79 enum hpaioScanMode_e { SCAN_MODE_FIRST = 0,
80                        SCAN_MODE_LINEART = 0,
81                        SCAN_MODE_GRAYSCALE,
82                        SCAN_MODE_COLOR,
83                        SCAN_MODE_LAST 
84                      };
85
86 #define COMPRESSION_NONE  0x01
87 #define COMPRESSION_MH    0x02
88 #define COMPRESSION_MR    0x04
89 #define COMPRESSION_MMR   0x08
90 #define COMPRESSION_JPEG  0x10
91
92 #define ADF_MODE_AUTO   0x01     /* flatbed or ADF */
93 #define ADF_MODE_FLATBED  0x02   /* flatbed only */
94 #define ADF_MODE_ADF    0x04     /* ADF only */
95
96 #define LENGTH_MEASUREMENT_UNKNOWN    0
97 #define LENGTH_MEASUREMENT_UNLIMITED    1
98 #define LENGTH_MEASUREMENT_APPROXIMATE    2
99 #define LENGTH_MEASUREMENT_PADDED   3
100 #define LENGTH_MEASUREMENT_EXACT    4
101
102 struct  hpaioScanner_s
103 {
104         char *tag;   /* handle identifier */
105         char deviceuri[128];
106         HPMUD_DEVICE deviceid;
107         HPMUD_CHANNEL scan_channelid;
108         HPMUD_CHANNEL cmd_channelid;
109         
110         struct hpaioScanner_s * prev;
111         struct hpaioScanner_s * next;
112
113         SANE_Device     saneDevice; /* "vendor", "model" dynamically allocated. */
114         SANE_Parameters prescanParameters;
115         SANE_Parameters scanParameters;
116         
117         struct PmlObject_s *    firstPmlObject;
118         struct PmlObject_s *    lastPmlObject;
119
120         enum { SCANNER_TYPE_SCL, SCANNER_TYPE_PML } scannerType;
121         int                     decipixelsPerInch;
122
123         /* These are bitfields of COMPRESSION_* values. */
124         int                     supportsScanMode[SCAN_MODE_LAST];
125         SANE_String_Const       scanModeList[MAX_LIST_SIZE];
126         enum hpaioScanMode_e    currentScanMode, effectiveScanMode;
127
128         SANE_Range              resolutionRange;
129         SANE_Int                resolutionList[MAX_LIST_SIZE];
130         SANE_Int                lineartResolutionList[MAX_LIST_SIZE];  /* 300 dpi. */
131         SANE_Int                currentResolution, effectiveResolution;
132
133         SANE_Range              contrastRange;
134         SANE_Int                defaultContrast, currentContrast;
135
136         SANE_String_Const       compressionList[MAX_LIST_SIZE];
137         int                     defaultCompression[SCAN_MODE_LAST];
138         SANE_Int                currentCompression;  /* One of the COMPRESSION_* values. */
139
140         SANE_Range              jpegCompressionFactorRange;
141         SANE_Int                defaultJpegCompressionFactor;
142         SANE_Int                currentJpegCompressionFactor;
143
144         SANE_Bool               currentBatchScan;
145         int                     beforeScan;
146         int                     alreadyPreAdvancedDocument;
147         int                     alreadyPostAdvancedDocument;
148         int                     noDocsConditionPending;
149
150         int                     supportedAdfModes;
151         SANE_String_Const       adfModeList[MAX_LIST_SIZE];
152         int                     currentAdfMode;
153         int                     currentPageNumber;
154
155         int                     supportsDuplex;
156         SANE_Bool               currentDuplex;
157         int                     currentSideNumber;
158
159         SANE_Int                currentLengthMeasurement;
160         SANE_String_Const       lengthMeasurementList[MAX_LIST_SIZE];
161
162         SANE_Range              tlxRange, tlyRange, brxRange, bryRange;
163         SANE_Fixed              currentTlx, currentTly, currentBrx, currentBry;
164         SANE_Fixed              effectiveTlx,
165                                 effectiveTly,
166                                 effectiveBrx,
167                                 effectiveBry;
168
169         SANE_Option_Descriptor  option[OPTION_LAST];
170
171         Mfpdtf_t                mfpdtf;
172         IP_HANDLE               hJob;
173         int                     fromDenali;
174         int                     preDenali;
175         int                     denali;
176         unsigned char           inBuffer[LEN_BUFFER];     /* mfpdtf block buffer */
177         int                     bufferOffset;
178         int                     bufferBytesRemaining;
179         int                     totalBytesRemaining;
180         int                     endOfData;
181         int BlockSize;                                    /* mfpdtf block size, including fixed header */
182         int BlockIndex;                                   /* record index in mfpdtf block */
183         int RecordSize;                                    /* record size, does not include header */
184         int RecordIndex;                                   /* data index in record */
185         int mfpdtf_done; 
186         int mfpdtf_timeout_cnt; 
187         int pml_timeout_cnt;                              /* pml done timeout count */ 
188         int pml_done;
189         int ip_done;
190         int page_done;
191         int upload_state;                                 /* last pml upload state */
192         int user_cancel;                                  /* user cancelled operation */
193
194         struct 
195         {
196                 char            compat1150[LEN_MODEL_RESPONSE + 1];
197                 char            compatPost1150[LEN_MODEL_RESPONSE + 1];
198                 int             compat;
199                 char            decipixelChar;
200
201                 int             minRes, maxRes;
202                 int             maxXExtent, maxYExtent;
203                 int             unloadAfterScan;
204                 int             flatbedCapability, adfCapability;
205                 int             minResAdf, maxResAdf;
206
207                 PmlObject_t     objSupportedFunctions;
208         } scl;
209
210         struct 
211         {
212                 PmlObject_t     objScannerStatus,
213                                 objResolutionRange,
214                                 objUploadTimeout,
215                                 objContrast,
216                                 objResolution,
217                                 objPixelDataType,
218                                 objCompression,
219                                 objCompressionFactor,
220                                 objUploadError,
221                                 objUploadState,
222                                 objAbcThresholds,
223                                 objSharpeningCoefficient,
224                                 objNeutralClipThresholds,
225                                 objToneMap,
226                                 objCopierReduction,
227                                 objScanToken,
228                                 objModularHardware;
229
230                 char            scanToken[ PML_MAX_VALUE_LEN ];
231                 char            zeroScanToken[ PML_MAX_VALUE_LEN ];
232                 int             lenScanToken;
233                 int             scanTokenIsSet;
234
235                 int             openFirst;
236                 int             dontResetBeforeNextNonBatchPage;
237                 int             startNextBatchPageEarly;
238                 int             flatbedCapability;
239
240                 int             alreadyRestarted;
241                 int             scanDone;
242                 int             previousUploadState;
243         } pml;
244 };
245
246 typedef struct hpaioScanner_s * hpaioScanner_t;
247 typedef struct hpaioScanner_s HPAIO_RECORD;
248
249 #define UNDEFINED_MODEL(hpaio) (!hpaio->saneDevice.model)
250
251 #define _SET_DEFAULT_MODEL(hpaio,s,len) \
252   do { \
253     if (UNDEFINED_MODEL(hpaio)) { \
254       hpaio->saneDevice.model=malloc(len+1); \
255       memcpy((char *)hpaio->saneDevice.model,s,len); \
256       ((char *)hpaio->saneDevice.model)[len]=0; \
257     } \
258   } while(0)
259 #define SET_DEFAULT_MODEL(hpaio,s) _SET_DEFAULT_MODEL(hpaio,s,strlen(s))
260
261 #define FIX_GEOMETRY(low,high,min,max) \
262   do { \
263     if (high<low) high=low; \
264     if (high==low) { \
265       if (high==max) { \
266         low--; \
267       } else { \
268         high++; \
269       } \
270     } \
271   } while(0)
272
273 SANE_Status __attribute__ ((visibility ("hidden"))) hpaioScannerToSaneStatus( hpaioScanner_t hpaio );
274 SANE_Status __attribute__ ((visibility ("hidden"))) hpaioScannerToSaneError( hpaioScanner_t hpaio );
275 void sane_hpaio_cancel(SANE_Handle handle);
276
277 #endif