Line 0
Link Here
|
|
|
1 |
/* |
2 |
Copyright (C) 2001 Bertrik Sikken (bertrik@zonnet.nl) |
3 |
|
4 |
This program is free software; you can redistribute it and/or |
5 |
modify it under the terms of the GNU General Public License |
6 |
as published by the Free Software Foundation; either version 2 |
7 |
of the License, or (at your option) any later version. |
8 |
|
9 |
This program is distributed in the hope that it will be useful, |
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
GNU General Public License for more details. |
13 |
|
14 |
You should have received a copy of the GNU General Public License |
15 |
along with this program; if not, write to the Free Software |
16 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
17 |
|
18 |
$Id: hp3300c.c,v 1.52 2003/03/24 19:14:46 bertrik Exp $ |
19 |
*/ |
20 |
|
21 |
/* |
22 |
Core HP3300c functions. |
23 |
*/ |
24 |
|
25 |
#include <stdio.h> /* fopen, fread, fwrite, fclose etc */ |
26 |
#include <stdarg.h> /* va_list for vfprintf */ |
27 |
#include <string.h> /* memcpy, memset */ |
28 |
#include <unistd.h> /* unlink */ |
29 |
#include <stdlib.h> /* malloc, free */ |
30 |
#include <math.h> /* exp, pow */ |
31 |
|
32 |
#include "mytypes.h" |
33 |
#include "hp3300c_xfer.h" |
34 |
|
35 |
#include "hp3300c.h" |
36 |
|
37 |
|
38 |
#ifndef MIN |
39 |
#define MIN(a,b) (((a) < (b)) ? (a) : (b)) |
40 |
#endif |
41 |
|
42 |
#ifndef MAX |
43 |
#define MAX(a,b) (((a) > (b)) ? (a) : (b)) |
44 |
#endif |
45 |
|
46 |
|
47 |
#define XFER_BUF_SIZE 0xF000 |
48 |
|
49 |
|
50 |
/* HP3400 firmware data */ |
51 |
static byte abData0000[] = { |
52 |
0xfe, 0x9f, 0x58, 0x1b, 0x00, 0x03, 0xa4, 0x02, 0x63, 0x02, 0x33, 0x02, 0x0d, 0x02, 0xf0, 0x01, |
53 |
0xd8, 0x01, 0xc5, 0x01, 0xb5, 0x01, 0xa8, 0x01, 0x9d, 0x01, 0x93, 0x01, 0x8b, 0x01, 0x84, 0x01, |
54 |
0x7e, 0x01, 0x79, 0x01, 0x74, 0x01, 0x70, 0x01, 0x6d, 0x01, 0x69, 0x01, 0x67, 0x01, 0x64, 0x01, |
55 |
0x62, 0x01, 0x60, 0x01, 0x5f, 0x01, 0x5d, 0x01, 0x5c, 0x01, 0x5b, 0x01, 0x5a, 0x01, 0x59, 0x01, |
56 |
0x58, 0x01, 0x57, 0x01, 0x57, 0x01, 0x56, 0x01, 0x56, 0x01, 0x55, 0x01, 0x55, 0x01, 0x54, 0x01, |
57 |
0x54, 0x01, 0x54, 0x01, 0x54, 0x01, 0x53, 0x01, 0x53, 0x01, 0x53, 0x01, 0x53, 0x01, 0x52, 0x81 }; |
58 |
/* 1st word : 0x9ffe = 40958, strip 15th bit: 0x1ffe = 8190 |
59 |
2nd word : 0x1b58 = 7000 -> coincidence ? |
60 |
other words: formula: y = 676 / (2 - exp(0.113 * (1-x)) ), where x = 0 for first entry |
61 |
*/ |
62 |
|
63 |
/* more HP3400 firmware data */ |
64 |
static byte abData0400[] = { |
65 |
0xa4, 0x82, 0x00, 0x80, 0xa4, 0x82, 0xaa, 0x02, 0xc0, 0x02, 0xe8, 0x02, 0x3e, 0x03, 0xc8, 0x03, |
66 |
0x58, 0x1b, 0xfe, 0x9f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
67 |
0x00, 0x00, 0x00, 0x00 }; |
68 |
|
69 |
|
70 |
|
71 |
/* utility function to show a hexdump of a buffer */ |
72 |
void DumpHex(byte *pabData, int iLen, int iWidth) |
73 |
{ |
74 |
int i; |
75 |
for (i = 0; i < iLen; i++) { |
76 |
if ((i % iWidth) == 0) { |
77 |
printf("\n%04X", i); |
78 |
} |
79 |
printf(" %02X", pabData[i]); |
80 |
} |
81 |
printf("\n"); |
82 |
} |
83 |
|
84 |
|
85 |
static void _ConvertMotorTable(byte *pabOld, byte *pabNew, int iSize, int iLpi) |
86 |
{ |
87 |
int iData, i, iBit15; |
88 |
|
89 |
for (i = 0; i < (iSize / 2); i++) { |
90 |
iData = pabOld[2*i + 0] + (pabOld[2*i + 1] << 8); |
91 |
iBit15 = (iData & 0x8000); |
92 |
iData = (iData & 0x7FFF); |
93 |
if (iData <= 0x400) { |
94 |
iData = iData * iLpi / 300; |
95 |
} |
96 |
if (iBit15 != 0) { |
97 |
iData |= 0x8000; |
98 |
} |
99 |
pabNew[2*i + 0] = iData & 255; |
100 |
pabNew[2*i + 1] = (iData >> 8) & 255; |
101 |
} |
102 |
} |
103 |
|
104 |
|
105 |
/************************************************************************* |
106 |
_ProbeRegisters |
107 |
=============== |
108 |
Tries to determine certain hardware properties. |
109 |
|
110 |
This is done by checking the writeability of some scanner registers. |
111 |
We cannot rely simply on the scanner model to contain a specific |
112 |
chip. The HP3300c for example uses one of at least three slightly |
113 |
different scanner ASICs (NIASH00012, NIASH00013 and NIASH00014). |
114 |
|
115 |
OUT pHWParams Hardware parameters, updated fields: |
116 |
fGamma16 TRUE if 16 bit gamma tables can be used |
117 |
fReg07 TRUE if reg07 is writeable |
118 |
iBufferSize Size of scanner's internal buffer |
119 |
|
120 |
Returns TRUE if a NIASH chipset was found. |
121 |
*************************************************************************/ |
122 |
static bool _ProbeRegisters(THWParams *pHWParams) |
123 |
{ |
124 |
byte bData1, bData2; |
125 |
int iHandle; |
126 |
|
127 |
iHandle = pHWParams->iXferHandle; |
128 |
|
129 |
DBG(DBG_MSG, "Probing scanner...\n"); |
130 |
|
131 |
/* check register 0x04 */ |
132 |
Hp3300cRegWrite (iHandle, 0x04, 0x55); |
133 |
Hp3300cRegRead (iHandle, 0x04, &bData1); |
134 |
Hp3300cRegWrite (iHandle, 0x04, 0xAA); |
135 |
Hp3300cRegRead (iHandle, 0x04, &bData2); |
136 |
Hp3300cRegWrite (iHandle, 0x04, 0x07); |
137 |
if ((bData1 != 0x55) || (bData2 != 0xAA)) { |
138 |
DBG(DBG_ERR, " No NIASH chipset found!\n"); |
139 |
return FALSE; |
140 |
} |
141 |
|
142 |
/* check writeability of register 3 bit 1 */ |
143 |
Hp3300cRegRead (iHandle, 0x03, &bData1); |
144 |
Hp3300cRegWrite (iHandle, 0x03, bData1 | 0x02); |
145 |
Hp3300cRegRead (iHandle, 0x03, &bData2); |
146 |
Hp3300cRegWrite (iHandle, 0x03, bData1); |
147 |
pHWParams->fGamma16 = ((bData2 & 0x02) != 0); |
148 |
DBG(DBG_MSG, " Gamma table entries are %d bit\n", pHWParams->fGamma16 ? 16 : 8); |
149 |
|
150 |
/* check register 0x07 */ |
151 |
Hp3300cRegRead (iHandle, 0x07, &bData1); |
152 |
Hp3300cRegWrite (iHandle, 0x07, 0x1C); |
153 |
Hp3300cRegRead (iHandle, 0x07, &bData2); |
154 |
Hp3300cRegWrite (iHandle, 0x07, bData1); |
155 |
pHWParams->fReg07 = (bData2 == 0x1C); |
156 |
|
157 |
if (!pHWParams->fGamma16) { |
158 |
/* internal scan buffer size is an educated guess, but seems to correlate |
159 |
well with the size calculated from several windows driver log files |
160 |
size = 128kB - 44088 bytes (space required for gamma/calibration table) |
161 |
*/ |
162 |
pHWParams->iBufferSize = 86984L; |
163 |
DBG(DBG_MSG, " NIASH version < 00014\n"); |
164 |
} |
165 |
else { |
166 |
pHWParams->iBufferSize = 0x60000L; |
167 |
if (!pHWParams->fReg07) { |
168 |
DBG(DBG_MSG, " NIASH version = 00014\n"); |
169 |
} |
170 |
else { |
171 |
DBG(DBG_MSG, " NIASH version > 00014\n"); |
172 |
} |
173 |
} |
174 |
|
175 |
return TRUE; |
176 |
} |
177 |
|
178 |
|
179 |
/* returns 0 on success, < 0 otherwise */ |
180 |
int Hp3300cOpen(THWParams *pHWParams, char *pszName) |
181 |
{ |
182 |
int iXferHandle; |
183 |
|
184 |
iXferHandle = Hp3300cXferOpen(pszName, &pHWParams->eModel); |
185 |
if (iXferHandle < 0) { |
186 |
DBG(DBG_ERR, "Hp3300cXferOpen failed for '%s'\n", pszName); |
187 |
return -1; |
188 |
} |
189 |
|
190 |
pHWParams->iXferHandle = iXferHandle; |
191 |
|
192 |
Hp3300cWakeup(pHWParams->iXferHandle); |
193 |
|
194 |
/* default HW params */ |
195 |
pHWParams->iSensorSkew = 8; |
196 |
pHWParams->iTopLeftX = 0; |
197 |
pHWParams->iTopLeftY = 3; |
198 |
pHWParams->fReg07 = FALSE; |
199 |
pHWParams->iSkipLines = 0; |
200 |
pHWParams->iExpTime = 5408; |
201 |
pHWParams->iReversedHead = TRUE; |
202 |
|
203 |
switch (pHWParams->eModel) { |
204 |
|
205 |
case eHp3300c: |
206 |
DBG(DBG_MSG, "Setting params for Hp3300\n"); |
207 |
pHWParams->iTopLeftX = 4; |
208 |
pHWParams->iTopLeftY = 11; |
209 |
pHWParams->iSkipLines = 14; |
210 |
break; |
211 |
|
212 |
case eHp3400c: case eHp4300c: |
213 |
DBG(DBG_MSG, "Setting params for Hp3400c/Hp4300c\n"); |
214 |
pHWParams->iTopLeftX = 2; |
215 |
pHWParams->iTopLeftY = 13; |
216 |
pHWParams->fReg07 = TRUE; |
217 |
break; |
218 |
|
219 |
case eAgfaTouch: |
220 |
DBG(DBG_MSG, "Setting params for AgfaTouch\n"); |
221 |
pHWParams->iReversedHead = FALSE; /* head not reversed on Agfa Touch */ |
222 |
pHWParams->iTopLeftX = 3; |
223 |
pHWParams->iTopLeftY = 10; |
224 |
pHWParams->iSkipLines = 7; |
225 |
break; |
226 |
|
227 |
case eUnknownModel: |
228 |
DBG(DBG_MSG, "Setting params for UnknownModel\n"); |
229 |
break; |
230 |
|
231 |
default: |
232 |
DBG(DBG_ERR, "ERROR: internal error! (%d)\n", (int)pHWParams->eModel); |
233 |
return -1; |
234 |
} |
235 |
|
236 |
/* autodetect some hardware properties */ |
237 |
if (!_ProbeRegisters(pHWParams)) { |
238 |
DBG(DBG_ERR, "_ProbeRegisters failed!\n"); |
239 |
return -1; |
240 |
} |
241 |
|
242 |
return 0; |
243 |
} |
244 |
|
245 |
|
246 |
void Hp3300cClose(THWParams *pHWPar) |
247 |
{ |
248 |
Hp3300cXferClose(pHWPar->iXferHandle); |
249 |
pHWPar->iXferHandle = 0; |
250 |
} |
251 |
|
252 |
|
253 |
static void WriteRegWord(int iHandle, byte bReg, word wData) |
254 |
{ |
255 |
Hp3300cRegWrite(iHandle, bReg, wData & 0xFF); |
256 |
Hp3300cRegWrite(iHandle, bReg + 1, (wData >> 8) & 0xFF); |
257 |
} |
258 |
|
259 |
|
260 |
/* calculate a 4096 byte gamma table */ |
261 |
void CalcGamma(byte *pabTable, double Gamma) |
262 |
{ |
263 |
int i, iData; |
264 |
|
265 |
/* fill gamma table */ |
266 |
for (i = 0; i < 4096; i++) { |
267 |
iData = floor(256.0 * pow(((double)i / 4096.0), 1.0 / Gamma)); |
268 |
pabTable[i] = iData; |
269 |
} |
270 |
} |
271 |
|
272 |
|
273 |
/* |
274 |
Hp3400WriteFw |
275 |
============= |
276 |
Writes data to scanners with a NIASH00019 chipset, e.g. |
277 |
gamma, calibration and motor control data. |
278 |
|
279 |
IN pabData pointer to firmware data |
280 |
iLen Size of firmware date (bytes) |
281 |
iAddr Scanner address to write to |
282 |
*/ |
283 |
static void Hp3400cWriteFW(int iXferHandle, byte *pabData, int iLen, int iAddr) |
284 |
{ |
285 |
iAddr--; |
286 |
Hp3300cRegWrite(iXferHandle, 0x21, iAddr & 0xFF); |
287 |
Hp3300cRegWrite(iXferHandle, 0x22, (iAddr >> 8) & 0xFF); |
288 |
Hp3300cRegWrite(iXferHandle, 0x23, (iAddr >> 16) & 0xFF); |
289 |
Hp3300cBulkWrite(iXferHandle, pabData, iLen); |
290 |
} |
291 |
|
292 |
|
293 |
/* Writes the gamma and offset/gain tables to the scanner. |
294 |
In case a calibration file exist, it will be used for offset/gain */ |
295 |
void WriteGammaCalibTable(byte *pabGammaR, byte *pabGammaG, byte *pabGammaB, |
296 |
byte *pabCalibTable, int iGain, int iOffset, THWParams *pHWPar) |
297 |
{ |
298 |
int i, j, k; |
299 |
static byte abGamma[60000]; |
300 |
int iData; |
301 |
int iHandle; |
302 |
|
303 |
iHandle = pHWPar->iXferHandle; |
304 |
|
305 |
j = 0; |
306 |
/* fill gamma table for red component */ |
307 |
/* pad entries with 0 for 16-bit gamma table */ |
308 |
for (i = 0; i < 4096; i++) { |
309 |
if (pHWPar->fGamma16) { |
310 |
abGamma[j++] = 0; |
311 |
} |
312 |
abGamma[j++] = pabGammaR[i]; |
313 |
} |
314 |
/* fill gamma table for green component */ |
315 |
for (i = 0; i < 4096; i++) { |
316 |
if (pHWPar->fGamma16) { |
317 |
abGamma[j++] = 0; |
318 |
} |
319 |
abGamma[j++] = pabGammaG[i]; |
320 |
} |
321 |
/* fill gamma table for blue component */ |
322 |
for (i = 0; i < 4096; i++) { |
323 |
if (pHWPar->fGamma16) { |
324 |
abGamma[j++] = 0; |
325 |
} |
326 |
abGamma[j++] = pabGammaB[i]; |
327 |
} |
328 |
|
329 |
if (pabCalibTable == NULL) { |
330 |
iData = (iGain << 6) + iOffset; |
331 |
for (i = 0; i < HW_PIXELS; i++) { |
332 |
for (k = 0; k < 3; k++) { |
333 |
abGamma[j++] = (iData) & 255; |
334 |
abGamma[j++] = (iData >> 8) & 255; |
335 |
} |
336 |
} |
337 |
} |
338 |
else { |
339 |
memcpy(&abGamma[j], pabCalibTable, HW_PIXELS * 6); |
340 |
j += HW_PIXELS * 6; |
341 |
} |
342 |
|
343 |
Hp3300cRegWrite(iHandle, 0x02, 0x80); |
344 |
Hp3300cRegWrite(iHandle, 0x03, 0x01); |
345 |
Hp3300cRegWrite(iHandle, 0x03, 0x11); |
346 |
Hp3300cRegWrite(iHandle, 0x02, 0x84); |
347 |
|
348 |
if (pHWPar->fReg07) { |
349 |
Hp3400cWriteFW(iHandle, abGamma, j, 0x2000); |
350 |
} |
351 |
else { |
352 |
Hp3300cBulkWrite(iHandle, abGamma, j); |
353 |
} |
354 |
|
355 |
Hp3300cRegWrite(iHandle, 0x02, 0x80); |
356 |
} |
357 |
|
358 |
|
359 |
static void WriteAFEReg(int iHandle, int iReg, int iData) |
360 |
{ |
361 |
Hp3300cRegWrite(iHandle, 0x25, iReg); |
362 |
Hp3300cRegWrite(iHandle, 0x26, iData); |
363 |
} |
364 |
|
365 |
|
366 |
/* setup the analog front-end -> coarse calibration */ |
367 |
static void WriteAFE(int iHandle) |
368 |
{ |
369 |
/* see WM8143 datasheet */ |
370 |
|
371 |
WriteAFEReg(iHandle, 0x04, 0x00); |
372 |
WriteAFEReg(iHandle, 0x03, 0x12); |
373 |
WriteAFEReg(iHandle, 0x02, 0x04); |
374 |
WriteAFEReg(iHandle, 0x05, 0x10); |
375 |
WriteAFEReg(iHandle, 0x01, 0x03); |
376 |
|
377 |
WriteAFEReg(iHandle, 0x20, 0xc0);/*c8*/ /* red offset */ |
378 |
WriteAFEReg(iHandle, 0x21, 0xc0);/*c8*/ /* green offset */ |
379 |
WriteAFEReg(iHandle, 0x22, 0xc0);/*d0*/ /* blue offset */ |
380 |
|
381 |
WriteAFEReg(iHandle, 0x28, 0x05);/*5*/ /* red gain */ |
382 |
WriteAFEReg(iHandle, 0x29, 0x03);/*3*/ /* green gain */ |
383 |
WriteAFEReg(iHandle, 0x2A, 0x04);/*4*/ /* blue gain */ |
384 |
} |
385 |
|
386 |
|
387 |
/* wait for the carriage to return */ |
388 |
static void WaitReadyBit(int iHandle) |
389 |
{ |
390 |
byte bData; |
391 |
|
392 |
do { |
393 |
Hp3300cRegRead(iHandle, 0x03, &bData); |
394 |
} while ((bData & 8) == 0); |
395 |
} |
396 |
|
397 |
|
398 |
/* |
399 |
Initialisation specific for NIASH00014 and lower chips |
400 |
*/ |
401 |
static void InitNiash00014(TScanParams *pParams, THWParams *pHWParams) |
402 |
{ |
403 |
int iHandle, iLpiCode; |
404 |
|
405 |
iHandle = pHWParams->iXferHandle; |
406 |
|
407 |
/* exposure time (in units 24/Fcrystal)? */ |
408 |
WriteRegWord(iHandle, 0x08, pHWParams->iExpTime - 1); |
409 |
|
410 |
/* width in pixels */ |
411 |
WriteRegWord(iHandle, 0x12, pParams->iWidth - 1); |
412 |
|
413 |
/* top */ |
414 |
WriteRegWord (iHandle, 0x17, pParams->iTop); |
415 |
WriteRegWord (iHandle, 0x19, pParams->iTop); |
416 |
|
417 |
/* time between stepper motor steps (in units of 24/Fcrystal)? */ |
418 |
iLpiCode = pParams->iLpi * pHWParams->iExpTime / 1200L; |
419 |
|
420 |
if (!pHWParams->fGamma16) { |
421 |
/* NIASH 00012 / 00013 init */ |
422 |
|
423 |
/* LPI specific settings */ |
424 |
if (pParams->iLpi < 600) { |
425 |
/* set halfres bit */ |
426 |
Hp3300cRegWrite(iHandle, 0x06, 0x01); |
427 |
/* double lpi code because of halfres bit */ |
428 |
iLpiCode *= 2; |
429 |
} |
430 |
else { |
431 |
/* clear halfres bit */ |
432 |
Hp3300cRegWrite(iHandle, 0x06, 0x00); |
433 |
/* add exptime to make it scan slower */ |
434 |
iLpiCode += pHWParams->iExpTime; |
435 |
} |
436 |
|
437 |
/* unknown setting */ |
438 |
WriteRegWord (iHandle, 0x27, 0x7FD2); |
439 |
WriteRegWord (iHandle, 0x29, 0x6421); |
440 |
|
441 |
} |
442 |
else { |
443 |
/* NIASH 00014 init */ |
444 |
|
445 |
/* halfres bit always cleared */ |
446 |
Hp3300cRegWrite(iHandle, 0x06, 0x00); |
447 |
|
448 |
/* LPI specific settings */ |
449 |
if (pParams->iLpi >= 600) { |
450 |
/* add exptime to make it scan slower */ |
451 |
iLpiCode += pHWParams->iExpTime; |
452 |
} |
453 |
|
454 |
/* unknown setting */ |
455 |
WriteRegWord (iHandle, 0x27, 0xc862);/*c862 */ |
456 |
WriteRegWord (iHandle, 0x29, 0xb853);/*b853 */ |
457 |
} |
458 |
|
459 |
/* LPI code */ |
460 |
WriteRegWord(iHandle, 0x0A, iLpiCode - 1); |
461 |
|
462 |
/* backtrack reversing speed */ |
463 |
Hp3300cRegWrite(iHandle, 0x1E, (iLpiCode - 1) / 32); |
464 |
} |
465 |
|
466 |
|
467 |
/* |
468 |
Initialisation specific for NIASH00019 chips |
469 |
*/ |
470 |
static void InitNiash00019(TScanParams *pParams, THWParams *pHWParams) |
471 |
{ |
472 |
int iHandle, iLpiCode; |
473 |
static byte abMotor[512]; |
474 |
|
475 |
|
476 |
iHandle = pHWParams->iXferHandle; |
477 |
|
478 |
/* exposure time (in units 24/Fcrystal)? */ |
479 |
WriteRegWord (iHandle, 0x08, pHWParams->iExpTime); |
480 |
|
481 |
/* width in pixels */ |
482 |
WriteRegWord (iHandle, 0x12, pParams->iWidth); |
483 |
|
484 |
/* ? */ |
485 |
WriteRegWord (iHandle, 0x27, 0xc862);/*c862 */ |
486 |
WriteRegWord (iHandle, 0x29, 0xb853);/*b853 */ |
487 |
|
488 |
/* specific handling of 150 dpi resolution */ |
489 |
if (pParams->iLpi == 150) { |
490 |
/* use 300 LPI but skip every other line */ |
491 |
pParams->iLpi = 300; |
492 |
Hp3300cRegWrite(iHandle, 0x06, 0x01); |
493 |
} |
494 |
else { |
495 |
Hp3300cRegWrite(iHandle, 0x06, 0x00); |
496 |
} |
497 |
|
498 |
/* DPI and position table */ |
499 |
Hp3300cRegWrite (iHandle, 0x07, 0x02); |
500 |
_ConvertMotorTable(abData0000, abMotor, sizeof(abData0000), pParams->iLpi); |
501 |
Hp3400cWriteFW(iHandle, abMotor, sizeof(abData0000), 0x000); |
502 |
_ConvertMotorTable(abData0400, abMotor, sizeof(abData0400), pParams->iLpi); |
503 |
Hp3400cWriteFW(iHandle, abMotor, sizeof(abData0400), 0x400); |
504 |
|
505 |
/* backtrack reversing speed */ |
506 |
iLpiCode = pParams->iLpi * pHWParams->iExpTime / 1200L; |
507 |
Hp3300cRegWrite(iHandle, 0x1E, (iLpiCode - 1) / 32); |
508 |
} |
509 |
|
510 |
|
511 |
/* |
512 |
Scanner initialisation common to all NIASH chips |
513 |
*/ |
514 |
static void InitNiashCommon(TScanParams *pParams, THWParams *pHWParams) |
515 |
{ |
516 |
int iWidthHW, iHandle, iMaxLevel; |
517 |
|
518 |
|
519 |
iHandle = pHWParams->iXferHandle; |
520 |
|
521 |
Hp3300cRegWrite (iHandle, 0x02, 0x80); |
522 |
Hp3300cRegWrite (iHandle, 0x03, 0x11); |
523 |
Hp3300cRegWrite (iHandle, 0x01, 0x8B); |
524 |
Hp3300cRegWrite (iHandle, 0x05, 0x01); |
525 |
|
526 |
/* dpi */ |
527 |
WriteRegWord (iHandle, 0x0C, pParams->iDpi); |
528 |
|
529 |
/* calculate width in units of HW resolution */ |
530 |
iWidthHW = pParams->iWidth * (HW_DPI / pParams->iDpi); |
531 |
|
532 |
/* set left and right limits */ |
533 |
if ( pHWParams->iReversedHead ) { |
534 |
/* head is reversed */ |
535 |
/* right */ |
536 |
WriteRegWord (iHandle, 0x0E, 3 * (HW_PIXELS - (pParams->iLeft + iWidthHW)) ); |
537 |
|
538 |
/* left */ |
539 |
WriteRegWord (iHandle, 0x10, 3 * (HW_PIXELS - pParams->iLeft) - 1); |
540 |
} else { |
541 |
/* head is not reversed */ |
542 |
/*left */ |
543 |
WriteRegWord (iHandle, 0x0E, 3 * pParams->iLeft); |
544 |
|
545 |
/* right */ |
546 |
WriteRegWord (iHandle, 0x10, 3 * (pParams->iLeft + iWidthHW) - 1); |
547 |
} |
548 |
|
549 |
/* bottom */ |
550 |
WriteRegWord (iHandle, 0x1B, pParams->iBottom); /* 0x393C); */ |
551 |
|
552 |
/* forward jogging speed */ |
553 |
Hp3300cRegWrite (iHandle, 0x1D, 0x60); |
554 |
|
555 |
/* backtrack reversing speed? */ |
556 |
Hp3300cRegWrite (iHandle, 0x2B, 0x15); |
557 |
|
558 |
/* backtrack distance */ |
559 |
if (pParams->iLpi < 600) { |
560 |
Hp3300cRegWrite(iHandle, 0x1F, 0x30); |
561 |
} |
562 |
else { |
563 |
Hp3300cRegWrite(iHandle, 0x1F, 0x18); |
564 |
} |
565 |
|
566 |
/* max buffer level before backtrace */ |
567 |
iMaxLevel = MIN(pHWParams->iBufferSize / pParams->iWidth, 250); |
568 |
Hp3300cRegWrite (iHandle, 0x14, iMaxLevel - 1); |
569 |
|
570 |
/* lamp PWM, max = 0x1ff? */ |
571 |
WriteRegWord (iHandle, 0x2C, 0x01FF); |
572 |
|
573 |
/* not needed? */ |
574 |
Hp3300cRegWrite (iHandle, 0x15, 0x90);/* 90 */ |
575 |
Hp3300cRegWrite (iHandle, 0x16, 0x70);/* 70 */ |
576 |
|
577 |
WriteAFE(iHandle); |
578 |
|
579 |
WaitReadyBit(iHandle); |
580 |
|
581 |
Hp3300cRegWrite (iHandle, 0x03, 0x05); |
582 |
|
583 |
Hp3300cRegWrite(iHandle, 0x02, pParams->fCalib ? 0x88 : 0xA8); |
584 |
} |
585 |
|
586 |
|
587 |
/* write registers */ |
588 |
bool InitScan(TScanParams *pParams, THWParams *pHWParams) |
589 |
{ |
590 |
int iHeight; |
591 |
int iExpTime; |
592 |
TScanParams Params; |
593 |
int iHandle; |
594 |
|
595 |
iHandle = pHWParams->iXferHandle; |
596 |
|
597 |
/* check validity of scanparameters */ |
598 |
switch (pParams->iDpi) { |
599 |
case 150: case 300: case 600: |
600 |
break; |
601 |
default: |
602 |
DBG(DBG_ERR, "Invalid dpi (%d)\n", pParams->iDpi); |
603 |
return FALSE; |
604 |
} |
605 |
|
606 |
iHeight = (pParams->iBottom - pParams->iTop + 1); |
607 |
if (iHeight <= 0) { |
608 |
DBG(DBG_ERR, "Invalid height (%d)\n", iHeight); |
609 |
return FALSE; |
610 |
} |
611 |
|
612 |
if (pParams->iWidth <= 0) { |
613 |
DBG(DBG_ERR, "Invalid width (%d)\n", pParams->iWidth); |
614 |
return FALSE; |
615 |
} |
616 |
|
617 |
switch (pParams->iLpi) { |
618 |
case 150: case 300: case 600: |
619 |
break; |
620 |
default: |
621 |
DBG(DBG_ERR, "Invalid lpi (%d)\n", pParams->iLpi); |
622 |
return FALSE; |
623 |
} |
624 |
|
625 |
/* exposure time (in units of 24/Fcrystal?), must be divisible by 8 !!! */ |
626 |
iExpTime = 5408; |
627 |
if ((iExpTime % 8) != 0) { |
628 |
DBG(DBG_ERR, "Invalid exposure time (%d)\n", iExpTime); |
629 |
return FALSE; |
630 |
} |
631 |
|
632 |
/* |
633 |
*** Done checking scan parameters validity *** |
634 |
*/ |
635 |
|
636 |
/* |
637 |
copy the parameters locally and make pParams point to the local copy |
638 |
*/ |
639 |
memcpy(&Params, pParams, sizeof(Params)); |
640 |
pParams = &Params; |
641 |
|
642 |
if (!pHWParams->fReg07) { |
643 |
/* init NIASH00014 and lower */ |
644 |
InitNiash00014(pParams, pHWParams); |
645 |
} |
646 |
else { |
647 |
/* init NIASH00019 */ |
648 |
InitNiash00019(pParams, pHWParams); |
649 |
} |
650 |
|
651 |
/* common NIASH init */ |
652 |
InitNiashCommon(pParams, pHWParams); |
653 |
|
654 |
return TRUE; |
655 |
} |
656 |
|
657 |
|
658 |
/************************************************************************/ |
659 |
|
660 |
static void XferBufferGetLine(int iHandle, TDataPipe *p, byte *pabLine) |
661 |
{ |
662 |
byte bData; |
663 |
|
664 |
/* time for a fresh read? */ |
665 |
if (p->iCurLine == 0) { |
666 |
/* DBG(DBG_MSG, "Reading buffer %d bytes\n", _iLinesPerXferBuf |
667 |
* _iBytesPerLine); */ |
668 |
Hp3300cRegRead(iHandle, 0x20, &bData); |
669 |
DBG(DBG_MSG, "buffer level = %3d, <reading %5d bytes>, ", |
670 |
(int)bData, p->iLinesPerXferBuf * p->iBytesPerLine); |
671 |
Hp3300cBulkRead(iHandle, p->pabXferBuf, p->iLinesPerXferBuf * p->iBytesPerLine); |
672 |
Hp3300cRegRead(iHandle, 0x20, &bData); |
673 |
DBG(DBG_MSG, "buffer level = %3d\r", bData); |
674 |
fflush(stdout); |
675 |
} |
676 |
/* copy one line */ |
677 |
if (pabLine != NULL) { |
678 |
memcpy(pabLine, &p->pabXferBuf[p->iCurLine * p->iBytesPerLine], p->iBytesPerLine); |
679 |
} |
680 |
/* advance pointer */ |
681 |
p->iCurLine = (p->iCurLine + 1) % p->iLinesPerXferBuf; |
682 |
} |
683 |
|
684 |
|
685 |
static void XferBufferInit(int iHandle, TDataPipe *p) |
686 |
{ |
687 |
int i; |
688 |
|
689 |
p->pabXferBuf = (byte *)malloc(XFER_BUF_SIZE); |
690 |
p->iCurLine = 0; |
691 |
|
692 |
/* skip garbage lines */ |
693 |
for (i = 0; i < p->iSkipLines; i++) { |
694 |
XferBufferGetLine(iHandle, p, NULL); |
695 |
} |
696 |
} |
697 |
|
698 |
|
699 |
static void XferBufferExit(TDataPipe *p) |
700 |
{ |
701 |
if (p->pabXferBuf != NULL) { |
702 |
free(p->pabXferBuf); |
703 |
p->pabXferBuf = NULL; |
704 |
} |
705 |
else { |
706 |
DBG(DBG_ERR, "XferBufExit: Xfer buffer not initialised!\n"); |
707 |
} |
708 |
} |
709 |
|
710 |
|
711 |
/* unscrambles a line: |
712 |
- combining the proper R, G and B lines and converting them to interpixel RGB |
713 |
- mirroring left to right |
714 |
*/ |
715 |
static void _UnscrambleLine(byte *pabLine, |
716 |
byte *pabRed, byte *pabGrn, byte *pabBlu, int iWidth, bool iReversedHead) |
717 |
{ |
718 |
int i, j; |
719 |
if (iReversedHead) { |
720 |
/* reversed */ |
721 |
for (i = 0; i < iWidth; i++) { |
722 |
j = (iWidth - i) * 3; |
723 |
pabLine[j - 3] = pabRed[i]; |
724 |
pabLine[j - 2] = pabGrn[i + iWidth]; |
725 |
pabLine[j - 1] = pabBlu[i + iWidth * 2]; |
726 |
} |
727 |
} else { |
728 |
/* not reversed */ |
729 |
for (i = 0; i < iWidth; i++) { |
730 |
pabLine[3 * i] = pabRed[i]; |
731 |
pabLine[3 * i + 1] = pabGrn[i + iWidth]; |
732 |
pabLine[3 * i + 2] = pabBlu[i + iWidth * 2]; |
733 |
} |
734 |
} |
735 |
} |
736 |
|
737 |
|
738 |
/* gets an unscrambled line from the circular buffer. the first couple of lines contain garbage */ |
739 |
void CircBufferGetLine(int iHandle, TDataPipe *p, byte *pabLine, bool iReversedHead) |
740 |
{ |
741 |
if (iReversedHead) { |
742 |
XferBufferGetLine(iHandle, p, &p->pabCircBuf[p->iRedLine * p->iBytesPerLine]); |
743 |
} else { |
744 |
XferBufferGetLine(iHandle, p, &p->pabCircBuf[p->iBluLine * p->iBytesPerLine]); |
745 |
} |
746 |
|
747 |
if (pabLine != NULL) { |
748 |
_UnscrambleLine(pabLine, |
749 |
&p->pabCircBuf[p->iRedLine * p->iBytesPerLine], |
750 |
&p->pabCircBuf[p->iGrnLine * p->iBytesPerLine], |
751 |
&p->pabCircBuf[p->iBluLine * p->iBytesPerLine], |
752 |
p->iBytesPerLine / 3, |
753 |
iReversedHead); |
754 |
} |
755 |
|
756 |
/* advance pointers */ |
757 |
p->iRedLine = (p->iRedLine + 1) % p->iLinesPerCircBuf; |
758 |
p->iGrnLine = (p->iGrnLine + 1) % p->iLinesPerCircBuf; |
759 |
p->iBluLine = (p->iBluLine + 1) % p->iLinesPerCircBuf; |
760 |
} |
761 |
|
762 |
|
763 |
void CircBufferInit(int iHandle, TDataPipe *p, int iBytesPerLine, int iMisAlignment, bool iReversedHead) |
764 |
{ |
765 |
int i; |
766 |
|
767 |
p->iBytesPerLine = iBytesPerLine; |
768 |
if (iMisAlignment == 0) { |
769 |
p->iLinesPerCircBuf = 1; |
770 |
} |
771 |
else { |
772 |
p->iLinesPerCircBuf = 3 * iMisAlignment; |
773 |
} |
774 |
|
775 |
DBG(DBG_MSG, "_iBytesPerLine = %d\n", p->iBytesPerLine); |
776 |
DBG(DBG_MSG, "_iLinesPerCircBuf = %d\n", p->iLinesPerCircBuf); |
777 |
p->pabCircBuf = (byte *)malloc(iBytesPerLine * p->iLinesPerCircBuf); |
778 |
if (p->pabCircBuf == NULL) { |
779 |
DBG(DBG_ERR, "Unable to allocate %d bytes for circular buffer\n", (int)(iBytesPerLine * p->iLinesPerCircBuf)); |
780 |
return; |
781 |
} |
782 |
DBG(DBG_MSG, "Allocated %d bytes for circular buffer\n", iBytesPerLine * p->iLinesPerCircBuf); |
783 |
|
784 |
if (iReversedHead) { |
785 |
p->iBluLine = 0; |
786 |
p->iGrnLine = iMisAlignment; |
787 |
p->iRedLine = iMisAlignment * 2; |
788 |
} else { |
789 |
p->iRedLine = 0; |
790 |
p->iGrnLine = iMisAlignment; |
791 |
p->iBluLine = iMisAlignment * 2; |
792 |
} |
793 |
|
794 |
p->iLinesPerXferBuf = XFER_BUF_SIZE / iBytesPerLine; |
795 |
DBG(DBG_MSG, "_iLinesPerXferBuf = %d\n", p->iLinesPerXferBuf); |
796 |
DBG(DBG_MSG, "Xfer block size = %d\n", p->iLinesPerXferBuf * p->iBytesPerLine); |
797 |
|
798 |
/* init transfer buffer */ |
799 |
XferBufferInit(iHandle, p); |
800 |
|
801 |
/* fill circular buffer */ |
802 |
for (i = 0; i < p->iLinesPerCircBuf; i++) { |
803 |
CircBufferGetLine(iHandle, p, NULL, iReversedHead); |
804 |
} |
805 |
} |
806 |
|
807 |
|
808 |
void CircBufferExit(TDataPipe *p) |
809 |
{ |
810 |
XferBufferExit(p); |
811 |
if (p->pabCircBuf != NULL) { |
812 |
DBG(DBG_MSG, "\n"); |
813 |
free(p->pabCircBuf); |
814 |
p->pabCircBuf = NULL; |
815 |
} |
816 |
else { |
817 |
DBG(DBG_ERR, "CircBufferExit: Circular buffer not initialised!\n"); |
818 |
} |
819 |
} |
820 |
|
821 |
|
822 |
/************************************************************************/ |
823 |
|
824 |
/************************************************************************* |
825 |
ScanLines |
826 |
========= |
827 |
Helper function to scan in an image and output the result to a file. |
828 |
|
829 |
IN pFile File to write image data to |
830 |
pParams User-defineable settings describing the image to be scanned |
831 |
pHWParams Scanner hardware settings |
832 |
|
833 |
*************************************************************************/ |
834 |
void ScanLines(FILE *pFile, TScanParams *pParams, THWParams *pHWParams) |
835 |
{ |
836 |
static byte abBuf[HW_PIXELS * 3]; |
837 |
int iBytesPerLine; |
838 |
int iHeight; |
839 |
int iHandle; |
840 |
bool iReversedHead; |
841 |
TDataPipe DataPipe; |
842 |
|
843 |
iHandle = pHWParams->iXferHandle; |
844 |
|
845 |
iHeight = pParams->iHeight; |
846 |
iBytesPerLine = pParams->iWidth * 3; |
847 |
DataPipe.iSkipLines = 0; |
848 |
iReversedHead = pHWParams->iReversedHead; |
849 |
|
850 |
if (InitScan(pParams, pHWParams)) { |
851 |
CircBufferInit(iHandle, &DataPipe, iBytesPerLine, pHWParams->iSensorSkew * pParams->iLpi / HW_LPI, iReversedHead); |
852 |
while (iHeight-- > 0) { |
853 |
CircBufferGetLine(iHandle, &DataPipe, abBuf, iReversedHead); |
854 |
fwrite(abBuf, 1, iBytesPerLine, pFile); |
855 |
} |
856 |
CircBufferExit(&DataPipe); |
857 |
} |
858 |
FinishScan(pHWParams); |
859 |
} |
860 |
|
861 |
|
862 |
static int _CalcAvg(byte *pabBuf, int n, int iStep) |
863 |
{ |
864 |
int i, j, x; |
865 |
|
866 |
for (i = j = x = 0; i < n; i++) { |
867 |
x += pabBuf[j]; |
868 |
j += iStep; |
869 |
} |
870 |
return (x / n); |
871 |
} |
872 |
|
873 |
|
874 |
/* converts white line data and black point data into a calibration table */ |
875 |
static void CreateCalibTable(byte *abWhite, byte bBlackR, byte bBlackG, |
876 |
byte bBlackB, int iReversedHead, byte *pabCalibTable) |
877 |
{ |
878 |
int i, j, iGain, iOffset, iData; |
879 |
byte *pabPixel; |
880 |
|
881 |
j = 0; |
882 |
for (i = 0; i < HW_PIXELS; i++) { |
883 |
if (iReversedHead) { |
884 |
pabPixel = &abWhite[(HW_PIXELS - i - 1) * 3]; |
885 |
} |
886 |
else { |
887 |
pabPixel = &abWhite[i * 3]; |
888 |
} |
889 |
/* red */ |
890 |
if (bBlackR > 16) bBlackR = 16 ; |
891 |
iGain = 65536 / MAX(1, pabPixel[0] - bBlackR); |
892 |
iOffset = bBlackR * 4; |
893 |
if (iOffset > 63) iOffset = 63 ; |
894 |
iData = (iGain << 6) + iOffset; |
895 |
pabCalibTable[j++] = (iData) & 255; |
896 |
pabCalibTable[j++] = (iData >> 8) & 255; |
897 |
/* green */ |
898 |
if (bBlackG > 16) bBlackG = 16 ; |
899 |
iGain = 65536 / MAX(1, pabPixel[1] - bBlackG); |
900 |
iOffset = bBlackG * 4; |
901 |
if (iOffset > 63) iOffset = 63 ; |
902 |
iData = (iGain << 6) + iOffset; |
903 |
pabCalibTable[j++] = (iData) & 255; |
904 |
pabCalibTable[j++] = (iData >> 8) & 255; |
905 |
/* blue */ |
906 |
if (bBlackB > 16) bBlackB = 16 ; |
907 |
iGain = 65536 / MAX(1, pabPixel[2] - bBlackB); |
908 |
iOffset = bBlackB * 4; |
909 |
if (iOffset > 63) iOffset = 63 ; |
910 |
iData = (iGain << 6) + iOffset; |
911 |
pabCalibTable[j++] = (iData) & 255; |
912 |
pabCalibTable[j++] = (iData >> 8) & 255; |
913 |
} |
914 |
} |
915 |
|
916 |
|
917 |
/************************************************************************* |
918 |
Lamp control functions |
919 |
*************************************************************************/ |
920 |
bool GetLamp(THWParams *pHWParams, bool *pfLampIsOn) |
921 |
{ |
922 |
byte bData; |
923 |
|
924 |
Hp3300cRegRead(pHWParams->iXferHandle, 0x03, &bData); |
925 |
*pfLampIsOn = ((bData & 0x01) != 0); |
926 |
return TRUE; |
927 |
} |
928 |
|
929 |
|
930 |
bool SetLamp(THWParams *pHWParams, bool fLampOn) |
931 |
{ |
932 |
byte bData; |
933 |
int iHandle; |
934 |
|
935 |
iHandle = pHWParams->iXferHandle; |
936 |
|
937 |
Hp3300cRegRead(iHandle, 0x03, &bData); |
938 |
if (fLampOn) { |
939 |
Hp3300cRegWrite(iHandle, 0x03, bData | 0x01); |
940 |
} |
941 |
else { |
942 |
Hp3300cRegWrite(iHandle, 0x03, bData & ~0x01); |
943 |
} |
944 |
return TRUE; |
945 |
} |
946 |
|
947 |
|
948 |
/************************************************************************* |
949 |
Experimental simple calibration |
950 |
|
951 |
Basic idea: |
952 |
* a strip starting at position 0 is scanned in |
953 |
* per-pixel white level is determined by average of first 4 lines |
954 |
* global black level is determined by minimum value of all lines |
955 |
*************************************************************************/ |
956 |
bool SimpleCalib(THWParams *pHWPar, byte *pabCalibTable) |
957 |
{ |
958 |
byte bMinR, bMinG, bMinB; |
959 |
TDataPipe DataPipe; |
960 |
TScanParams Params; |
961 |
byte abGamma[4096]; |
962 |
int i, j; |
963 |
static byte abBuf[HW_PIXELS * 3 * 71]; /* Carefull : see startWhite and endWhite below */ |
964 |
static byte abLine[HW_PIXELS * 3]; |
965 |
static byte abWhite[HW_PIXELS * 3]; |
966 |
byte *pabWhite; |
967 |
int iWhiteR, iWhiteG, iWhiteB; |
968 |
int iHandle; |
969 |
bool iReversedHead; |
970 |
int startWhiteY, endWhiteY ; |
971 |
int startBlackY, endBlackY ; |
972 |
int startBlackX, endBlackX ; |
973 |
|
974 |
iHandle = pHWPar->iXferHandle; |
975 |
iReversedHead = pHWPar->iReversedHead; |
976 |
|
977 |
DataPipe.iSkipLines = pHWPar->iSkipLines; |
978 |
|
979 |
Params.iDpi = HW_DPI; |
980 |
Params.iLpi = HW_DPI; |
981 |
if (iReversedHead) /* hp scanners */ |
982 |
Params.iTop = 60; |
983 |
else /* agfa scanners */ |
984 |
Params.iTop = 30 ; |
985 |
Params.iBottom = HP3300C_BOTTOM; |
986 |
Params.iLeft = 0; |
987 |
Params.iWidth = HW_PIXELS; |
988 |
Params.iHeight = 54; |
989 |
Params.fCalib = TRUE; |
990 |
|
991 |
/* write gamma table with neutral gain / offset */ |
992 |
CalcGamma(abGamma, 1.0); |
993 |
WriteGammaCalibTable(abGamma, abGamma, abGamma, NULL, 256, 0, pHWPar); |
994 |
|
995 |
if (!InitScan(&Params, pHWPar)) { |
996 |
return FALSE; |
997 |
} |
998 |
|
999 |
/* Definition of white and black areas */ |
1000 |
if (iReversedHead) { /* hp scanners */ |
1001 |
startWhiteY = 0 ; |
1002 |
endWhiteY = 15 ; |
1003 |
startBlackY = 16 ; |
1004 |
endBlackY = 135 ; |
1005 |
startBlackX = 0 ; |
1006 |
endBlackX = HW_PIXELS ; |
1007 |
} else { /* agfa scanners */ |
1008 |
startWhiteY = 0 ; |
1009 |
endWhiteY = 70 ; |
1010 |
startBlackY = 86 ; |
1011 |
endBlackY = 135 ; |
1012 |
startBlackX = 1666 ; |
1013 |
endBlackX = 3374 ; |
1014 |
} |
1015 |
|
1016 |
CircBufferInit(iHandle, &DataPipe, HW_PIXELS * 3, Params.iLpi / 150, iReversedHead); |
1017 |
/* white level */ |
1018 |
/* skip some lines */ |
1019 |
for (i = 0; i < startWhiteY; i++) { |
1020 |
CircBufferGetLine(iHandle, &DataPipe, abLine, iReversedHead); |
1021 |
} |
1022 |
/* Get white lines */ |
1023 |
for (i = 0; i < endWhiteY - startWhiteY + 1; i++) { |
1024 |
CircBufferGetLine(iHandle, &DataPipe, &abBuf[i * HW_PIXELS * 3], iReversedHead); |
1025 |
} |
1026 |
/* black level */ |
1027 |
bMinR = 255; bMinG = 255; bMinB = 255; |
1028 |
/* Skip some lines */ |
1029 |
for (i = 0; i < startBlackY; i++) { |
1030 |
CircBufferGetLine(iHandle, &DataPipe, abLine, iReversedHead); |
1031 |
} |
1032 |
for (i = 0; i < endBlackY - startBlackY + 1; i++) { |
1033 |
CircBufferGetLine(iHandle, &DataPipe, abLine, iReversedHead); |
1034 |
for (j = 0; j < endBlackX; j++) { |
1035 |
bMinR = MIN(abLine[j * 3 + 0], bMinR); |
1036 |
bMinG = MIN(abLine[j * 3 + 1], bMinG); |
1037 |
bMinB = MIN(abLine[j * 3 + 2], bMinB); |
1038 |
} |
1039 |
} |
1040 |
CircBufferExit(&DataPipe); |
1041 |
FinishScan(pHWPar); |
1042 |
|
1043 |
/* calc average white level */ |
1044 |
pabWhite = abBuf; |
1045 |
for (i = 0; i < HW_PIXELS; i++) { |
1046 |
abWhite[i * 3 + 0] = _CalcAvg(&pabWhite[i * 3 + 0], endWhiteY - startWhiteY + 1, HW_PIXELS * 3); |
1047 |
abWhite[i * 3 + 1] = _CalcAvg(&pabWhite[i * 3 + 1], endWhiteY - startWhiteY + 1, HW_PIXELS * 3); |
1048 |
abWhite[i * 3 + 2] = _CalcAvg(&pabWhite[i * 3 + 2], endWhiteY - startWhiteY + 1, HW_PIXELS * 3); |
1049 |
} |
1050 |
iWhiteR = _CalcAvg(&abWhite[0], HW_PIXELS, 3); |
1051 |
iWhiteG = _CalcAvg(&abWhite[1], HW_PIXELS, 3); |
1052 |
iWhiteB = _CalcAvg(&abWhite[2], HW_PIXELS, 3); |
1053 |
|
1054 |
DBG(DBG_MSG, "Black level (%d,%d,%d), White level (%d,%d,%d)\n", |
1055 |
(int)bMinR, (int)bMinG, (int)bMinB, iWhiteR, iWhiteG, iWhiteB); |
1056 |
|
1057 |
/* convert the white line and black point into a calibration table */ |
1058 |
CreateCalibTable(abWhite, bMinR, bMinG, bMinB, iReversedHead, |
1059 |
pabCalibTable); |
1060 |
|
1061 |
return TRUE; |
1062 |
} |
1063 |
|
1064 |
|
1065 |
/************************************************************************* |
1066 |
FinishScan |
1067 |
========== |
1068 |
Finishes the scan. Makes the scanner head move back to the home position. |
1069 |
|
1070 |
*************************************************************************/ |
1071 |
void FinishScan(THWParams *pHWParams) |
1072 |
{ |
1073 |
Hp3300cRegWrite(pHWParams->iXferHandle, 0x02, 0x80); |
1074 |
} |
1075 |
|
1076 |
|
1077 |
|