1141cc406Sopenharmony_ci/* @file plustek-pp_image.c
2141cc406Sopenharmony_ci * @brief functions to convert scanner data into image data
3141cc406Sopenharmony_ci *
4141cc406Sopenharmony_ci * based on sources acquired from Plustek Inc.
5141cc406Sopenharmony_ci * Copyright (C) 1998 Plustek Inc.
6141cc406Sopenharmony_ci * Copyright (C) 2000-2013 Gerhard Jaeger <gerhard@gjaeger.de>
7141cc406Sopenharmony_ci * also based on the work done by Rick Bronson
8141cc406Sopenharmony_ci *
9141cc406Sopenharmony_ci * History:
10141cc406Sopenharmony_ci * - 0.30 - initial version
11141cc406Sopenharmony_ci * - 0.31 - no changes
12141cc406Sopenharmony_ci * - 0.32 - no changes
13141cc406Sopenharmony_ci * - 0.33 - no changes
14141cc406Sopenharmony_ci * - 0.34 - reactivated code in imageP96WaitLineData() to recover from
15141cc406Sopenharmony_ci *          losing data
16141cc406Sopenharmony_ci * - 0.35 - no changes
17141cc406Sopenharmony_ci * - 0.36 - removed comment
18141cc406Sopenharmony_ci *        - added wDither exchange to imageP9xSetupScanSettings
19141cc406Sopenharmony_ci *        - added fnHalftoneDirect1 which provides dithering by using random
20141cc406Sopenharmony_ci *          thresholds
21141cc406Sopenharmony_ci *        - removed the swapping behaviour for model OP_600 in
22141cc406Sopenharmony_ci *          fnP96ColorDirect() according to the Primax 4800 Direct tests
23141cc406Sopenharmony_ci *        - changes, due to define renaming
24141cc406Sopenharmony_ci *        - removed _ASIC_96001 specific stuff to invert colors
25141cc406Sopenharmony_ci * - 0.37 - removed // comments
26141cc406Sopenharmony_ci *        - corrected output of 12bit/pixel
27141cc406Sopenharmony_ci * - 0.38 - added P12 stuff
28141cc406Sopenharmony_ci *        - renamed WaitLineData functions to ReadOneImageLine
29141cc406Sopenharmony_ci * - 0.39 - fixed a problem in imageP98003ReadOneImageLine, that causes
30141cc406Sopenharmony_ci *          these I/O timeouts...
31141cc406Sopenharmony_ci * - 0.40 - no changes
32141cc406Sopenharmony_ci * - 0.41 - no changes
33141cc406Sopenharmony_ci * - 0.42 - fixed a problem for the 12bit modes for ASIC9800x based devices
34141cc406Sopenharmony_ci *        - changed include names
35141cc406Sopenharmony_ci * - 0.43 - removed floating point stuff
36141cc406Sopenharmony_ci *        - cleanup
37141cc406Sopenharmony_ci * - 0.44 - fix format string issues, as Long types default to int32_t
38141cc406Sopenharmony_ci *          now
39141cc406Sopenharmony_ci * .
40141cc406Sopenharmony_ci * <hr>
41141cc406Sopenharmony_ci * This file is part of the SANE package.
42141cc406Sopenharmony_ci *
43141cc406Sopenharmony_ci * This program is free software; you can redistribute it and/or
44141cc406Sopenharmony_ci * modify it under the terms of the GNU General Public License as
45141cc406Sopenharmony_ci * published by the Free Software Foundation; either version 2 of the
46141cc406Sopenharmony_ci * License, or (at your option) any later version.
47141cc406Sopenharmony_ci *
48141cc406Sopenharmony_ci * This program is distributed in the hope that it will be useful, but
49141cc406Sopenharmony_ci * WITHOUT ANY WARRANTY; without even the implied warranty of
50141cc406Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
51141cc406Sopenharmony_ci * General Public License for more details.
52141cc406Sopenharmony_ci *
53141cc406Sopenharmony_ci * You should have received a copy of the GNU General Public License
54141cc406Sopenharmony_ci * along with this program.  If not, see <https://www.gnu.org/licenses/>.
55141cc406Sopenharmony_ci *
56141cc406Sopenharmony_ci * As a special exception, the authors of SANE give permission for
57141cc406Sopenharmony_ci * additional uses of the libraries contained in this release of SANE.
58141cc406Sopenharmony_ci *
59141cc406Sopenharmony_ci * The exception is that, if you link a SANE library with other files
60141cc406Sopenharmony_ci * to produce an executable, this does not by itself cause the
61141cc406Sopenharmony_ci * resulting executable to be covered by the GNU General Public
62141cc406Sopenharmony_ci * License.  Your use of that executable is in no way restricted on
63141cc406Sopenharmony_ci * account of linking the SANE library code into it.
64141cc406Sopenharmony_ci *
65141cc406Sopenharmony_ci * This exception does not, however, invalidate any other reasons why
66141cc406Sopenharmony_ci * the executable file might be covered by the GNU General Public
67141cc406Sopenharmony_ci * License.
68141cc406Sopenharmony_ci *
69141cc406Sopenharmony_ci * If you submit changes to SANE to the maintainers to be included in
70141cc406Sopenharmony_ci * a subsequent release, you agree by submitting the changes that
71141cc406Sopenharmony_ci * those changes may be distributed with this exception intact.
72141cc406Sopenharmony_ci *
73141cc406Sopenharmony_ci * If you write modifications of your own for SANE, it is your choice
74141cc406Sopenharmony_ci * whether to permit this exception to apply to your modifications.
75141cc406Sopenharmony_ci * If you do not wish that, delete this exception notice.
76141cc406Sopenharmony_ci * <hr>
77141cc406Sopenharmony_ci */
78141cc406Sopenharmony_ci#include "plustek-pp_scan.h"
79141cc406Sopenharmony_ci
80141cc406Sopenharmony_ci/************************ local definitions **********************************/
81141cc406Sopenharmony_ci
82141cc406Sopenharmony_ci#define _LINE_TIMEOUT   (_SECOND * 5 )      /* max 5 second per line !  */
83141cc406Sopenharmony_ci
84141cc406Sopenharmony_ci/*************************** local vars **************************************/
85141cc406Sopenharmony_ci
86141cc406Sopenharmony_cistatic UShort wPreviewScanned = 0;
87141cc406Sopenharmony_ci
88141cc406Sopenharmony_cistatic ExpXStepDef posScan[5] = {{128, 8}, {96, 12},
89141cc406Sopenharmony_ci                                 {96, 24}, {96, 48}, {96, 96}};
90141cc406Sopenharmony_cistatic ExpXStepDef negScan[5] = {{128, 8}, {96, 12},
91141cc406Sopenharmony_ci                                 {96, 24}, {96, 48}, {96, 96}};
92141cc406Sopenharmony_ci
93141cc406Sopenharmony_cistatic ExpXStepDef nmlScan[4][5] = {
94141cc406Sopenharmony_ci    {{160, 10}, {96, 12},  {96, 24},  {96, 48},  {96, 96}},     /* EPP */
95141cc406Sopenharmony_ci    {{160, 10}, {128, 16}, {128, 32}, {192, 96}, {192, 96}},    /* SPP */
96141cc406Sopenharmony_ci    {{160, 10}, {96, 12},  {96, 24},  {160, 80}, {160, 160}},   /* BPP */
97141cc406Sopenharmony_ci    {{160, 10}, {96, 12},  {96, 24},  {96, 48},  {96, 96}}      /* ECP */
98141cc406Sopenharmony_ci};
99141cc406Sopenharmony_ci
100141cc406Sopenharmony_cistatic ThreshDef xferSpeed[4] = {
101141cc406Sopenharmony_ci    {0, 3200, 2500}, {0, 1200, 800}, {0, 800, 1250}, {0, 3200, 2500}
102141cc406Sopenharmony_ci};
103141cc406Sopenharmony_ci
104141cc406Sopenharmony_ci/*************************** local functions *********************************/
105141cc406Sopenharmony_ci
106141cc406Sopenharmony_ci/** return the correct DPI-value
107141cc406Sopenharmony_ci * The ASIC 96001/3 models are limited to an optical resolution of 300 Dpi
108141cc406Sopenharmony_ci * so it´s necessary to scale in X and Y direction (see scale.c)!
109141cc406Sopenharmony_ci */
110141cc406Sopenharmony_cistatic UShort imageGetPhysDPI( pScanData ps, pImgDef pImgInf, Bool fDpiX )
111141cc406Sopenharmony_ci{
112141cc406Sopenharmony_ci	if( _IS_ASIC98(ps->sCaps.AsicID)) {
113141cc406Sopenharmony_ci
114141cc406Sopenharmony_ci	    if (fDpiX) {
115141cc406Sopenharmony_ci
116141cc406Sopenharmony_ci			if (pImgInf->xyDpi.x > ps->LensInf.rDpiX.wPhyMax)
117141cc406Sopenharmony_ci	    		return ps->LensInf.rDpiX.wPhyMax;
118141cc406Sopenharmony_ci			else
119141cc406Sopenharmony_ci	    		return pImgInf->xyDpi.x;
120141cc406Sopenharmony_ci
121141cc406Sopenharmony_ci	    } else {
122141cc406Sopenharmony_ci			if (pImgInf->xyDpi.y > ps->LensInf.rDpiY.wPhyMax)
123141cc406Sopenharmony_ci	    		return ps->LensInf.rDpiY.wPhyMax;
124141cc406Sopenharmony_ci			else
125141cc406Sopenharmony_ci	    		return pImgInf->xyDpi.y;
126141cc406Sopenharmony_ci	    }
127141cc406Sopenharmony_ci	} else {
128141cc406Sopenharmony_ci
129141cc406Sopenharmony_ci	    if (fDpiX) {
130141cc406Sopenharmony_ci
131141cc406Sopenharmony_ci			if (pImgInf->wDataType >= COLOR_TRUE24) {
132141cc406Sopenharmony_ci	    		if (pImgInf->xyDpi.x > ps->LensInf.rDpiX.wPhyMax)
133141cc406Sopenharmony_ci					return ps->LensInf.rDpiX.wPhyMax;
134141cc406Sopenharmony_ci			    else
135141cc406Sopenharmony_ci					return pImgInf->xyDpi.x;
136141cc406Sopenharmony_ci			} else {
137141cc406Sopenharmony_ci	    		if (pImgInf->xyDpi.x > (ps->LensInf.rDpiX.wPhyMax * 2))
138141cc406Sopenharmony_ci					return (ps->LensInf.rDpiX.wPhyMax * 2);
139141cc406Sopenharmony_ci			    else
140141cc406Sopenharmony_ci					return pImgInf->xyDpi.x;
141141cc406Sopenharmony_ci			}
142141cc406Sopenharmony_ci    	} else {
143141cc406Sopenharmony_ci
144141cc406Sopenharmony_ci			if (pImgInf->wDataType >= COLOR_TRUE24 ) {
145141cc406Sopenharmony_ci	    		if (pImgInf->xyDpi.y > (ps->LensInf.rDpiY.wPhyMax / 2))
146141cc406Sopenharmony_ci					return (ps->LensInf.rDpiY.wPhyMax / 2);
147141cc406Sopenharmony_ci			    else
148141cc406Sopenharmony_ci					return pImgInf->xyDpi.y;
149141cc406Sopenharmony_ci			} else {
150141cc406Sopenharmony_ci	    		if (pImgInf->xyDpi.y > ps->LensInf.rDpiY.wPhyMax)
151141cc406Sopenharmony_ci					return ps->LensInf.rDpiY.wPhyMax;
152141cc406Sopenharmony_ci			    else
153141cc406Sopenharmony_ci					return pImgInf->xyDpi.y;
154141cc406Sopenharmony_ci			}
155141cc406Sopenharmony_ci	    }
156141cc406Sopenharmony_ci	}
157141cc406Sopenharmony_ci}
158141cc406Sopenharmony_ci
159141cc406Sopenharmony_ci/*****************************************************************************
160141cc406Sopenharmony_ci *			Sampling stuff for ASIC 98003      						         *
161141cc406Sopenharmony_ci *****************************************************************************/
162141cc406Sopenharmony_ci
163141cc406Sopenharmony_cistatic Bool fnEveryLines( pScanData ps )
164141cc406Sopenharmony_ci{
165141cc406Sopenharmony_ci	_VAR_NOT_USED( ps );
166141cc406Sopenharmony_ci    return _TRUE;
167141cc406Sopenharmony_ci}
168141cc406Sopenharmony_ci
169141cc406Sopenharmony_cistatic Bool fnSampleLines( pScanData ps )
170141cc406Sopenharmony_ci{
171141cc406Sopenharmony_ci    ps->DataInf.wYSum += ps->DataInf.xyAppDpi.y;
172141cc406Sopenharmony_ci
173141cc406Sopenharmony_ci    if( ps->DataInf.wYSum >= ps->DataInf.xyPhyDpi.y ) {
174141cc406Sopenharmony_ci
175141cc406Sopenharmony_ci        ps->DataInf.wYSum -= ps->DataInf.xyPhyDpi.y;
176141cc406Sopenharmony_ci    	return	_TRUE;
177141cc406Sopenharmony_ci    }
178141cc406Sopenharmony_ci
179141cc406Sopenharmony_ci	return _FALSE;
180141cc406Sopenharmony_ci}
181141cc406Sopenharmony_ci
182141cc406Sopenharmony_cistatic Bool fnSamplePreview( pScanData ps )
183141cc406Sopenharmony_ci{
184141cc406Sopenharmony_ci    ps->DataInf.wYSum += wPreviewScanned;
185141cc406Sopenharmony_ci    if( ps->DataInf.wYSum >= 150 ) {
186141cc406Sopenharmony_ci
187141cc406Sopenharmony_ci        ps->DataInf.wYSum -= 150;
188141cc406Sopenharmony_ci    	return	_TRUE;
189141cc406Sopenharmony_ci    }
190141cc406Sopenharmony_ci
191141cc406Sopenharmony_ci	return _FALSE;
192141cc406Sopenharmony_ci}
193141cc406Sopenharmony_ci
194141cc406Sopenharmony_ci/*****************************************************************************
195141cc406Sopenharmony_ci *			Data Processing Routines			     						 *
196141cc406Sopenharmony_ci *****************************************************************************/
197141cc406Sopenharmony_ci
198141cc406Sopenharmony_cistatic Bool fnReadToDriver( pScanData ps )
199141cc406Sopenharmony_ci{
200141cc406Sopenharmony_ci    ps->AsicReg.RD_ModeControl = _ModeFifoBSel;
201141cc406Sopenharmony_ci    IOReadScannerImageData( ps, ps->Scan.BufPut.blue.bp,
202141cc406Sopenharmony_ci							ps->DataInf.dwAsicBytesPerPlane );
203141cc406Sopenharmony_ci
204141cc406Sopenharmony_ci	ps->AsicReg.RD_ModeControl = _ModeFifoGSel;
205141cc406Sopenharmony_ci    IOReadScannerImageData( ps, ps->Scan.BufPut.green.bp,
206141cc406Sopenharmony_ci							ps->DataInf.dwAsicBytesPerPlane );
207141cc406Sopenharmony_ci
208141cc406Sopenharmony_ci    if( ps->Scan.gd_gk.wGreenKeep )
209141cc406Sopenharmony_ci		ps->Scan.gd_gk.wGreenKeep--;
210141cc406Sopenharmony_ci    else {
211141cc406Sopenharmony_ci		ps->Scan.BufPut.green.bp += ps->DataInf.dwAsicBytesPerPlane;
212141cc406Sopenharmony_ci
213141cc406Sopenharmony_ci		if( ps->Scan.BufPut.green.bp >= ps->Scan.BufEnd.green.bp )
214141cc406Sopenharmony_ci		    ps->Scan.BufPut.green.bp = ps->Scan.BufBegin.green.bp;
215141cc406Sopenharmony_ci    }
216141cc406Sopenharmony_ci
217141cc406Sopenharmony_ci    ps->AsicReg.RD_ModeControl = _ModeFifoRSel;
218141cc406Sopenharmony_ci    IOReadScannerImageData( ps, ps->Scan.BufPut.red.bp,
219141cc406Sopenharmony_ci							ps->DataInf.dwAsicBytesPerPlane );
220141cc406Sopenharmony_ci
221141cc406Sopenharmony_ci    ps->Scan.BufPut.red.bp += ps->DataInf.dwAsicBytesPerPlane;
222141cc406Sopenharmony_ci    if( ps->Scan.BufPut.red.bp >= ps->Scan.BufEnd.red.bp )
223141cc406Sopenharmony_ci		ps->Scan.BufPut.red.bp = ps->Scan.BufBegin.red.bp;
224141cc406Sopenharmony_ci
225141cc406Sopenharmony_ci    if( ps->Scan.bd_rk.wRedKeep ) {
226141cc406Sopenharmony_ci		ps->Scan.bd_rk.wRedKeep--;
227141cc406Sopenharmony_ci		return _FALSE;
228141cc406Sopenharmony_ci
229141cc406Sopenharmony_ci    } else {
230141cc406Sopenharmony_ci
231141cc406Sopenharmony_ci		ps->Scan.BufData.green.bp = ps->Scan.BufGet.green.bp;
232141cc406Sopenharmony_ci
233141cc406Sopenharmony_ci		if( ps->DataInf.dwScanFlag & SCANDEF_ColorBGROrder ) {
234141cc406Sopenharmony_ci		    ps->Scan.BufData.red.bp  = ps->Scan.BufGet.blue.bp;
235141cc406Sopenharmony_ci		    ps->Scan.BufData.blue.bp = ps->Scan.BufGet.red.bp;
236141cc406Sopenharmony_ci		} else {
237141cc406Sopenharmony_ci		    ps->Scan.BufData.red.bp = ps->Scan.BufGet.red.bp;
238141cc406Sopenharmony_ci		    ps->Scan.BufData.blue.bp = ps->Scan.BufGet.blue.bp;
239141cc406Sopenharmony_ci		}
240141cc406Sopenharmony_ci
241141cc406Sopenharmony_ci		ps->Scan.BufGet.red.bp   += ps->DataInf.dwAsicBytesPerPlane;
242141cc406Sopenharmony_ci		ps->Scan.BufGet.green.bp += ps->DataInf.dwAsicBytesPerPlane;
243141cc406Sopenharmony_ci
244141cc406Sopenharmony_ci		if( ps->Scan.BufGet.red.bp >= ps->Scan.BufEnd.red.bp )
245141cc406Sopenharmony_ci		    ps->Scan.BufGet.red.bp = ps->Scan.BufBegin.red.bp;
246141cc406Sopenharmony_ci
247141cc406Sopenharmony_ci		if( ps->Scan.BufGet.green.bp >= ps->Scan.BufEnd.green.bp )
248141cc406Sopenharmony_ci		    ps->Scan.BufGet.green.bp = ps->Scan.BufBegin.green.bp;
249141cc406Sopenharmony_ci
250141cc406Sopenharmony_ci		return _TRUE;
251141cc406Sopenharmony_ci    }
252141cc406Sopenharmony_ci}
253141cc406Sopenharmony_ci
254141cc406Sopenharmony_cistatic Bool fnReadOutScanner( pScanData ps )
255141cc406Sopenharmony_ci{
256141cc406Sopenharmony_ci    if( ps->Scan.bd_rk.wBlueDiscard ) {
257141cc406Sopenharmony_ci
258141cc406Sopenharmony_ci        ps->Scan.bd_rk.wBlueDiscard--;
259141cc406Sopenharmony_ci    	ps->AsicReg.RD_ModeControl = _ModeFifoBSel;
260141cc406Sopenharmony_ci
261141cc406Sopenharmony_ci	    IOReadScannerImageData( ps, ps->Bufs.b1.pReadBuf,
262141cc406Sopenharmony_ci                                    ps->DataInf.dwAsicBytesPerPlane );
263141cc406Sopenharmony_ci
264141cc406Sopenharmony_ci    	if( ps->Scan.gd_gk.wGreenDiscard ) {
265141cc406Sopenharmony_ci            ps->Scan.gd_gk.wGreenDiscard--;
266141cc406Sopenharmony_ci
267141cc406Sopenharmony_ci	        ps->AsicReg.RD_ModeControl = _ModeFifoGSel;
268141cc406Sopenharmony_ci    	    IOReadScannerImageData( ps, ps->Bufs.b1.pReadBuf,
269141cc406Sopenharmony_ci                                        ps->DataInf.dwAsicBytesPerPlane);
270141cc406Sopenharmony_ci    	}
271141cc406Sopenharmony_ci	    return _FALSE;
272141cc406Sopenharmony_ci
273141cc406Sopenharmony_ci    } else {
274141cc406Sopenharmony_ci        IOReadColorData( ps, ps->Bufs.b1.pReadBuf,
275141cc406Sopenharmony_ci                             ps->DataInf.dwAsicBytesPerPlane );
276141cc406Sopenharmony_ci	    return _TRUE;
277141cc406Sopenharmony_ci    }
278141cc406Sopenharmony_ci}
279141cc406Sopenharmony_ci
280141cc406Sopenharmony_ci/** Interpolates the gray data by using averaged the continuous pixels
281141cc406Sopenharmony_ci */
282141cc406Sopenharmony_cistatic void fnP96GrayDirect( pScanData ps, pVoid pBuf, pVoid pImg, ULong bl )
283141cc406Sopenharmony_ci{
284141cc406Sopenharmony_ci	pUChar src, dest;
285141cc406Sopenharmony_ci
286141cc406Sopenharmony_ci	src  = (pUChar)pImg;
287141cc406Sopenharmony_ci	dest = (pUChar)pBuf;
288141cc406Sopenharmony_ci
289141cc406Sopenharmony_ci    for (; bl; bl--, src++, dest++ )
290141cc406Sopenharmony_ci		*dest = ps->pbMapRed [*src];
291141cc406Sopenharmony_ci}
292141cc406Sopenharmony_ci
293141cc406Sopenharmony_ci/** This routine used in the condition:
294141cc406Sopenharmony_ci * 1) The data type is B/W or GrayScale.
295141cc406Sopenharmony_ci * 2) The required horizontal resolution doesn't exceed the optic spec.
296141cc406Sopenharmony_ci * 3) The required vertical resolution exceeds the optic spec.
297141cc406Sopenharmony_ci * So, the vertcal lines have to average with previous line to smooth the
298141cc406Sopenharmony_ci * image.
299141cc406Sopenharmony_ci */
300141cc406Sopenharmony_cistatic void fnDataDirect( pScanData ps, pVoid pBuf, pVoid pImg, ULong bl )
301141cc406Sopenharmony_ci{
302141cc406Sopenharmony_ci	_VAR_NOT_USED( ps );
303141cc406Sopenharmony_ci	memcpy( pBuf, pImg, bl );
304141cc406Sopenharmony_ci}
305141cc406Sopenharmony_ci
306141cc406Sopenharmony_ci/** According to dither matrix to convert the input gray scale data into
307141cc406Sopenharmony_ci * one-bit data.
308141cc406Sopenharmony_ci */
309141cc406Sopenharmony_cistatic void fnHalftoneDirect0( pScanData ps, pVoid pb, pVoid pImg, ULong bL )
310141cc406Sopenharmony_ci{
311141cc406Sopenharmony_ci	pUChar pDither, src, dest;
312141cc406Sopenharmony_ci	ULong  dw;
313141cc406Sopenharmony_ci
314141cc406Sopenharmony_ci	src  = (pUChar)pImg;
315141cc406Sopenharmony_ci	dest = (pUChar)pb;
316141cc406Sopenharmony_ci
317141cc406Sopenharmony_ci	pDither = &ps->a_bDitherPattern[ps->dwDitherIndex];
318141cc406Sopenharmony_ci
319141cc406Sopenharmony_ci    for( ; bL; bL--, dest++, pDither -= 8 ) {
320141cc406Sopenharmony_ci
321141cc406Sopenharmony_ci		for( dw = 8; dw; dw--, src++, pDither++ ) {
322141cc406Sopenharmony_ci
323141cc406Sopenharmony_ci		    if( *src < *pDither ) {
324141cc406Sopenharmony_ci				*dest = (*dest << 1) | 0x01;
325141cc406Sopenharmony_ci			} else {
326141cc406Sopenharmony_ci				*dest <<= 1;
327141cc406Sopenharmony_ci			}
328141cc406Sopenharmony_ci		}
329141cc406Sopenharmony_ci	}
330141cc406Sopenharmony_ci	ps->dwDitherIndex = (ps->dwDitherIndex + 8) & 0x3f;
331141cc406Sopenharmony_ci}
332141cc406Sopenharmony_ci
333141cc406Sopenharmony_ci/** use random generator to make halftoning
334141cc406Sopenharmony_ci */
335141cc406Sopenharmony_cistatic void fnHalftoneDirect1( pScanData ps, pVoid pb, pVoid pImg, ULong bL )
336141cc406Sopenharmony_ci{
337141cc406Sopenharmony_ci	pUChar src, dest;
338141cc406Sopenharmony_ci    UChar  threshold;
339141cc406Sopenharmony_ci    ULong  dw;
340141cc406Sopenharmony_ci
341141cc406Sopenharmony_ci	_VAR_NOT_USED( ps );
342141cc406Sopenharmony_ci	src  = (pUChar)pImg;
343141cc406Sopenharmony_ci	dest = (pUChar)pb;
344141cc406Sopenharmony_ci
345141cc406Sopenharmony_ci	for (; bL; bL--, dest++ ) {
346141cc406Sopenharmony_ci
347141cc406Sopenharmony_ci		for (dw = 8; dw; dw--, src++ ) {
348141cc406Sopenharmony_ci
349141cc406Sopenharmony_ci		    threshold = (UChar)MiscLongRand();
350141cc406Sopenharmony_ci
351141cc406Sopenharmony_ci		    if (*src < threshold ) {
352141cc406Sopenharmony_ci				*dest = (*dest << 1) | 0x01;
353141cc406Sopenharmony_ci			} else {
354141cc406Sopenharmony_ci				*dest <<= 1;
355141cc406Sopenharmony_ci			}
356141cc406Sopenharmony_ci		}
357141cc406Sopenharmony_ci	}
358141cc406Sopenharmony_ci}
359141cc406Sopenharmony_ci
360141cc406Sopenharmony_ci/** Merges the color planes to pixels style without enlarge operation.
361141cc406Sopenharmony_ci */
362141cc406Sopenharmony_cistatic void fnP98ColorDirect( pScanData ps, pVoid pb, pVoid pImg, ULong bL )
363141cc406Sopenharmony_ci{
364141cc406Sopenharmony_ci	pUChar      src;
365141cc406Sopenharmony_ci	pRGBByteDef dest;
366141cc406Sopenharmony_ci
367141cc406Sopenharmony_ci	src  = (pUChar)pImg;
368141cc406Sopenharmony_ci	dest = (pRGBByteDef)pb;
369141cc406Sopenharmony_ci
370141cc406Sopenharmony_ci	for ( bL = ps->DataInf.dwAsicPixelsPerPlane; bL; bL--, src++, dest++) {
371141cc406Sopenharmony_ci
372141cc406Sopenharmony_ci		dest->Red   = *src;
373141cc406Sopenharmony_ci		dest->Green = src[ps->DataInf.dwAsicPixelsPerPlane];
374141cc406Sopenharmony_ci		dest->Blue  = src[ps->DataInf.dwAsicPixelsPerPlane*2];
375141cc406Sopenharmony_ci	}
376141cc406Sopenharmony_ci}
377141cc406Sopenharmony_ci
378141cc406Sopenharmony_cistatic void fnP96ColorDirect( pScanData ps, pVoid pb, pVoid pImg, ULong bL )
379141cc406Sopenharmony_ci{
380141cc406Sopenharmony_ci	pUChar      src;
381141cc406Sopenharmony_ci	pRGBByteDef dest;
382141cc406Sopenharmony_ci
383141cc406Sopenharmony_ci	src  = (pUChar)pImg;
384141cc406Sopenharmony_ci	dest = (pRGBByteDef)pb;
385141cc406Sopenharmony_ci
386141cc406Sopenharmony_ci	for ( bL = ps->DataInf.dwAsicPixelsPerPlane; bL; bL--, dest++, src++) {
387141cc406Sopenharmony_ci
388141cc406Sopenharmony_ci			dest->Red  =ps->pbMapRed[*src];
389141cc406Sopenharmony_ci			dest->Green=ps->pbMapGreen[src[ps->DataInf.dwAsicPixelsPerPlane]];
390141cc406Sopenharmony_ci			dest->Blue =ps->pbMapBlue[src[ps->DataInf.dwAsicPixelsPerPlane*2]];
391141cc406Sopenharmony_ci    }
392141cc406Sopenharmony_ci}
393141cc406Sopenharmony_ci
394141cc406Sopenharmony_ci/** Merges the color planes to pixels style without enlarge operation.
395141cc406Sopenharmony_ci * The scanner returns the pixel data in Motorola-Format, so we have to swap
396141cc406Sopenharmony_ci */
397141cc406Sopenharmony_cistatic void fnP98Color48( pScanData ps, pVoid pb, pVoid pImg, ULong bL )
398141cc406Sopenharmony_ci{
399141cc406Sopenharmony_ci	pUShort       src;
400141cc406Sopenharmony_ci	pRGBUShortDef dest;
401141cc406Sopenharmony_ci
402141cc406Sopenharmony_ci	register ULong i;
403141cc406Sopenharmony_ci
404141cc406Sopenharmony_ci	_VAR_NOT_USED( bL );
405141cc406Sopenharmony_ci	src  = (pUShort)pImg;
406141cc406Sopenharmony_ci	dest = (pRGBUShortDef)pb;
407141cc406Sopenharmony_ci
408141cc406Sopenharmony_ci	for ( i = ps->DataInf.dwAsicPixelsPerPlane; i;	i--, src++, dest++) {
409141cc406Sopenharmony_ci
410141cc406Sopenharmony_ci		dest->Red   = *src;
411141cc406Sopenharmony_ci		dest->Green = src[ps->DataInf.dwAsicPixelsPerPlane];
412141cc406Sopenharmony_ci		dest->Blue  = src[ps->DataInf.dwAsicPixelsPerPlane * 2];
413141cc406Sopenharmony_ci    }
414141cc406Sopenharmony_ci}
415141cc406Sopenharmony_ci
416141cc406Sopenharmony_ci/** prepare for scanning
417141cc406Sopenharmony_ci */
418141cc406Sopenharmony_cistatic int imageP98SetupScanSettings( pScanData ps, pScanInfo pInf )
419141cc406Sopenharmony_ci{
420141cc406Sopenharmony_ci	UShort brightness;
421141cc406Sopenharmony_ci
422141cc406Sopenharmony_ci	DBG( DBG_LOW, "imageP98SetupScanSettings()\n" );
423141cc406Sopenharmony_ci
424141cc406Sopenharmony_ci    ps->DataInf.dwScanFlag = pInf->ImgDef.dwFlag;
425141cc406Sopenharmony_ci    ps->DataInf.dwVxdFlag  = 0;
426141cc406Sopenharmony_ci    ps->DataInf.crImage    = pInf->ImgDef.crArea;
427141cc406Sopenharmony_ci
428141cc406Sopenharmony_ci    /* AdjustOriginXByLens
429141cc406Sopenharmony_ci     * [NOTE]
430141cc406Sopenharmony_ci     *	Here we just simply adjust it to double (600 DPI is two times of
431141cc406Sopenharmony_ci     *	300 DPI), but if this model is a multi-lens scanner, we should adjust
432141cc406Sopenharmony_ci     *	it according to different lens.
433141cc406Sopenharmony_ci	 */
434141cc406Sopenharmony_ci    ps->DataInf.crImage.x <<= 1;
435141cc406Sopenharmony_ci
436141cc406Sopenharmony_ci    ps->DataInf.xyAppDpi 	 = pInf->ImgDef.xyDpi;
437141cc406Sopenharmony_ci    ps->DataInf.siBrightness = pInf->siBrightness;
438141cc406Sopenharmony_ci    ps->DataInf.wDither      = pInf->wDither;
439141cc406Sopenharmony_ci    ps->DataInf.wAppDataType = pInf->ImgDef.wDataType;
440141cc406Sopenharmony_ci
441141cc406Sopenharmony_ci    ps->GetImageInfo( ps, &pInf->ImgDef );
442141cc406Sopenharmony_ci
443141cc406Sopenharmony_ci    if (ps->DataInf.dwVxdFlag & _VF_DATATOUSERBUFFER) {
444141cc406Sopenharmony_ci		ps->Scan.DataProcess = fnDataDirect;
445141cc406Sopenharmony_ci	}
446141cc406Sopenharmony_ci    if (ps->DataInf.dwScanFlag & SCANDEF_BmpStyle) {
447141cc406Sopenharmony_ci		ps->Scan.lBufferAdjust = -(Long)ps->DataInf.dwAppBytesPerLine;
448141cc406Sopenharmony_ci	} else {
449141cc406Sopenharmony_ci		ps->Scan.lBufferAdjust = (Long)ps->DataInf.dwAppBytesPerLine;
450141cc406Sopenharmony_ci	}
451141cc406Sopenharmony_ci
452141cc406Sopenharmony_ci	DBG( DBG_LOW, "Scan settings:\n" );
453141cc406Sopenharmony_ci	DBG( DBG_LOW, "ImageInfo: (x=%u,y=%u,dx=%u,dy=%u)\n",
454141cc406Sopenharmony_ci			 ps->DataInf.crImage.x,  ps->DataInf.crImage.y,
455141cc406Sopenharmony_ci			 ps->DataInf.crImage.cx, ps->DataInf.crImage.cy );
456141cc406Sopenharmony_ci
457141cc406Sopenharmony_ci    /*
458141cc406Sopenharmony_ci	 * SetBwBrightness
459141cc406Sopenharmony_ci     * [NOTE]
460141cc406Sopenharmony_ci     *
461141cc406Sopenharmony_ci     *	 0                   _DEF_BW_THRESHOLD					   255
462141cc406Sopenharmony_ci     *	 +-------------------------+--------------------------------+
463141cc406Sopenharmony_ci     *	 |<------- Black --------->|<----------- White ------------>|
464141cc406Sopenharmony_ci     *	 So, if user wish to make image darker, the threshold value should be
465141cc406Sopenharmony_ci     *	 higher than _defBwThreshold, otherwise it should lower than the
466141cc406Sopenharmony_ci     *	 _DefBwThreshold.
467141cc406Sopenharmony_ci     *	 Darker = _DefBwThreshold + White * Input / 127;
468141cc406Sopenharmony_ci     *		  Input < 0, and White = 255 - _DefBwThreshold, so
469141cc406Sopenharmony_ci     *		= _DefBwThreshold - (255 - _DefBwThreshold) * Input / 127;
470141cc406Sopenharmony_ci     *	 The brighter is the same idea.
471141cc406Sopenharmony_ci	 *
472141cc406Sopenharmony_ci 	 * CHECK: it seems that the brightness only works for the binary mode !
473141cc406Sopenharmony_ci	 */
474141cc406Sopenharmony_ci	if( ps->DataInf.wPhyDataType != COLOR_BW ) {/* if not line art 			*/
475141cc406Sopenharmony_ci		ps->wBrightness = pInf->siBrightness;   /* use internal tables for 	*/
476141cc406Sopenharmony_ci		ps->wContrast   = pInf->siContrast;		/* brightness and contrast	*/
477141cc406Sopenharmony_ci
478141cc406Sopenharmony_ci		pInf->siBrightness = 0;				/* don't use asic for threshold */
479141cc406Sopenharmony_ci    }
480141cc406Sopenharmony_ci
481141cc406Sopenharmony_ci/* CHECK: We have now two methods for setting the brightness...
482141cc406Sopenharmony_ci*/
483141cc406Sopenharmony_ci	DBG( DBG_LOW, "brightness = %i\n", pInf->siBrightness );
484141cc406Sopenharmony_ci
485141cc406Sopenharmony_ci    if (ps->DataInf.siBrightness < 0) {
486141cc406Sopenharmony_ci		brightness = (UShort)(_DEF_BW_THRESHOLD -
487141cc406Sopenharmony_ci			       (255 - _DEF_BW_THRESHOLD) * ps->DataInf.siBrightness /127);
488141cc406Sopenharmony_ci	} else {
489141cc406Sopenharmony_ci		brightness = (UShort)(_DEF_BW_THRESHOLD -
490141cc406Sopenharmony_ci					       _DEF_BW_THRESHOLD * ps->DataInf.siBrightness /127);
491141cc406Sopenharmony_ci	}
492141cc406Sopenharmony_ci    ps->AsicReg.RD_ThresholdControl = brightness;
493141cc406Sopenharmony_ci
494141cc406Sopenharmony_ci	DBG( DBG_LOW, "1. brightness = %i\n", brightness );
495141cc406Sopenharmony_ci
496141cc406Sopenharmony_ci    if( ps->DataInf.siBrightness >= 0 ) {
497141cc406Sopenharmony_ci	    brightness = (short)((long)(-(255 - _DEF_BW_THRESHOLD) *
498141cc406Sopenharmony_ci						 ps->DataInf.siBrightness) / 127 + _DEF_BW_THRESHOLD);
499141cc406Sopenharmony_ci	} else {
500141cc406Sopenharmony_ci	    brightness = (short)((long)(_DEF_BW_THRESHOLD *
501141cc406Sopenharmony_ci 						  ps->DataInf.siBrightness) / 127 + _DEF_BW_THRESHOLD);
502141cc406Sopenharmony_ci	}
503141cc406Sopenharmony_ci
504141cc406Sopenharmony_ci	brightness = (brightness ^ 0xff) & 0xff;
505141cc406Sopenharmony_ci
506141cc406Sopenharmony_ci	if( _ASIC_IS_98003 == ps->sCaps.AsicID ) {
507141cc406Sopenharmony_ci	    ps->AsicReg.RD_ThresholdControl = brightness;
508141cc406Sopenharmony_ci		DBG( DBG_LOW, "2. brightness = %i\n", brightness );
509141cc406Sopenharmony_ci	}
510141cc406Sopenharmony_ci
511141cc406Sopenharmony_ci	ps->DataInf.pCurrentBuffer = ps->pScanBuffer1;
512141cc406Sopenharmony_ci
513141cc406Sopenharmony_ci	return _OK;
514141cc406Sopenharmony_ci}
515141cc406Sopenharmony_ci
516141cc406Sopenharmony_ci/**
517141cc406Sopenharmony_ci */
518141cc406Sopenharmony_cistatic void imageP98DoCopyBuffer( pScanData ps, pUChar pImage )
519141cc406Sopenharmony_ci{
520141cc406Sopenharmony_ci	memcpy( ps->pFilterBuf, pImage, ps->DataInf.dwAsicBytesPerPlane );
521141cc406Sopenharmony_ci
522141cc406Sopenharmony_ci	ps->pFilterBuf += 5120;
523141cc406Sopenharmony_ci    if (ps->pFilterBuf >= ps->pEndBuf)
524141cc406Sopenharmony_ci		ps->pFilterBuf = ps->pProcessingBuf;
525141cc406Sopenharmony_ci}
526141cc406Sopenharmony_ci
527141cc406Sopenharmony_ci/**
528141cc406Sopenharmony_ci */
529141cc406Sopenharmony_cistatic Bool imageP98CopyToFilterBuffer( pScanData ps, pUChar pImage )
530141cc406Sopenharmony_ci{
531141cc406Sopenharmony_ci    if (ps->fDoFilter) {
532141cc406Sopenharmony_ci
533141cc406Sopenharmony_ci		if (ps->fFilterFirstLine) {
534141cc406Sopenharmony_ci
535141cc406Sopenharmony_ci		    imageP98DoCopyBuffer( ps, pImage );
536141cc406Sopenharmony_ci		    imageP98DoCopyBuffer( ps, pImage );
537141cc406Sopenharmony_ci		    ps->dwLinesFilter--;
538141cc406Sopenharmony_ci		    return _FALSE;
539141cc406Sopenharmony_ci	} else {
540141cc406Sopenharmony_ci
541141cc406Sopenharmony_ci		    imageP98DoCopyBuffer( ps, pImage );
542141cc406Sopenharmony_ci		    if ((ps->dwLinesFilter--) == 0)
543141cc406Sopenharmony_ci				imageP98DoCopyBuffer( ps, pImage);
544141cc406Sopenharmony_ci		}
545141cc406Sopenharmony_ci    }
546141cc406Sopenharmony_ci    return _TRUE;
547141cc406Sopenharmony_ci}
548141cc406Sopenharmony_ci
549141cc406Sopenharmony_ci/**
550141cc406Sopenharmony_ci */
551141cc406Sopenharmony_cistatic void imageP98UnSharpCompare( pScanData ps, Byte Center,
552141cc406Sopenharmony_ci                                    Byte Neighbour, pLong pdwNewValue )
553141cc406Sopenharmony_ci{
554141cc406Sopenharmony_ci    Byte b;
555141cc406Sopenharmony_ci
556141cc406Sopenharmony_ci    b = (Center >= Neighbour) ? Center - Neighbour : Neighbour - Center ;
557141cc406Sopenharmony_ci
558141cc406Sopenharmony_ci    if (b > ps->bOffsetFilter) {
559141cc406Sopenharmony_ci
560141cc406Sopenharmony_ci		*pdwNewValue -= (Long)Neighbour;
561141cc406Sopenharmony_ci		ps->dwDivFilter--;
562141cc406Sopenharmony_ci    }
563141cc406Sopenharmony_ci}
564141cc406Sopenharmony_ci
565141cc406Sopenharmony_ci/**
566141cc406Sopenharmony_ci */
567141cc406Sopenharmony_cistatic void imageP98DoFilter( pScanData ps, pUChar pPut )
568141cc406Sopenharmony_ci{
569141cc406Sopenharmony_ci	ULong dw;
570141cc406Sopenharmony_ci    Long  dwNewValue;
571141cc406Sopenharmony_ci
572141cc406Sopenharmony_ci    if (ps->fDoFilter && (ps->DataInf.xyAppDpi.x) >= 600UL) {
573141cc406Sopenharmony_ci
574141cc406Sopenharmony_ci		/* DoUnsharpMask(); */
575141cc406Sopenharmony_ci		for (dw = 0; dw < ps->DataInf.dwAsicBytesPerPlane - 2; dw++, pPut++) {
576141cc406Sopenharmony_ci
577141cc406Sopenharmony_ci			ps->dwDivFilter = ps->dwMul;
578141cc406Sopenharmony_ci
579141cc406Sopenharmony_ci		    dwNewValue = ((ULong)ps->pGet2[dw+1]) * ps->dwMul;
580141cc406Sopenharmony_ci			imageP98UnSharpCompare( ps, ps->pGet2[dw+1], ps->pGet1[dw], &dwNewValue);
581141cc406Sopenharmony_ci			imageP98UnSharpCompare( ps, ps->pGet2[dw+1], ps->pGet1[dw+1], &dwNewValue);
582141cc406Sopenharmony_ci			imageP98UnSharpCompare( ps, ps->pGet2[dw+1], ps->pGet1[dw+2], &dwNewValue);
583141cc406Sopenharmony_ci			imageP98UnSharpCompare( ps, ps->pGet2[dw+1], ps->pGet2[dw], &dwNewValue);
584141cc406Sopenharmony_ci			imageP98UnSharpCompare( ps, ps->pGet2[dw+1], ps->pGet2[dw+2], &dwNewValue);
585141cc406Sopenharmony_ci			imageP98UnSharpCompare( ps, ps->pGet2[dw+1], ps->pGet3[dw], &dwNewValue);
586141cc406Sopenharmony_ci			imageP98UnSharpCompare( ps, ps->pGet2[dw+1], ps->pGet3[dw+1], &dwNewValue);
587141cc406Sopenharmony_ci			imageP98UnSharpCompare( ps, ps->pGet2[dw+1], ps->pGet3[dw+2], &dwNewValue);
588141cc406Sopenharmony_ci
589141cc406Sopenharmony_ci    	    if( dwNewValue > 0 ) {
590141cc406Sopenharmony_ci				if((dwNewValue /= ps->dwDivFilter) < 255) {
591141cc406Sopenharmony_ci		    		*pPut = (Byte) dwNewValue;
592141cc406Sopenharmony_ci				} else {
593141cc406Sopenharmony_ci				    *pPut = 255;
594141cc406Sopenharmony_ci				}
595141cc406Sopenharmony_ci		    } else {
596141cc406Sopenharmony_ci				*pPut = 0;
597141cc406Sopenharmony_ci			}
598141cc406Sopenharmony_ci		}
599141cc406Sopenharmony_ci		pPut = ps->pGet1;
600141cc406Sopenharmony_ci		ps->pGet1 = ps->pGet2;
601141cc406Sopenharmony_ci		ps->pGet2 = ps->pGet3;
602141cc406Sopenharmony_ci		ps->pGet3 = pPut;
603141cc406Sopenharmony_ci    }
604141cc406Sopenharmony_ci}
605141cc406Sopenharmony_ci
606141cc406Sopenharmony_ci/**
607141cc406Sopenharmony_ci */
608141cc406Sopenharmony_cistatic Bool imageP98DataIsReady( pScanData ps )
609141cc406Sopenharmony_ci{
610141cc406Sopenharmony_ci	Byte b;
611141cc406Sopenharmony_ci
612141cc406Sopenharmony_ci	ps->Scan.fMotorBackward = _FALSE;
613141cc406Sopenharmony_ci	ps->bMoveDataOutFlag    = _DataAfterRefreshState;
614141cc406Sopenharmony_ci
615141cc406Sopenharmony_ci    b = (ps->DataInf.wPhyDataType >= COLOR_TRUE24) ?
616141cc406Sopenharmony_ci	                                      _BLUE_DATA_READY : _GREEN_DATA_READY;
617141cc406Sopenharmony_ci    while( _TRUE ) {
618141cc406Sopenharmony_ci
619141cc406Sopenharmony_ci		ps->dwColorRunIndex ++;
620141cc406Sopenharmony_ci
621141cc406Sopenharmony_ci		if(ps->pColorRunTable[ps->dwColorRunIndex] & b)
622141cc406Sopenharmony_ci	    	break;
623141cc406Sopenharmony_ci    }
624141cc406Sopenharmony_ci
625141cc406Sopenharmony_ci    if (b == _GREEN_DATA_READY) {
626141cc406Sopenharmony_ci
627141cc406Sopenharmony_ci		ps->AsicReg.RD_ModeControl = _ModeFifoGSel;
628141cc406Sopenharmony_ci		IOReadScannerImageData( ps, ps->DataInf.pCurrentBuffer,
629141cc406Sopenharmony_ci			 	    		        ps->DataInf.dwAsicBytesPerPlane );
630141cc406Sopenharmony_ci
631141cc406Sopenharmony_ci		imageP98CopyToFilterBuffer( ps, ps->DataInf.pCurrentBuffer );
632141cc406Sopenharmony_ci    } else  {
633141cc406Sopenharmony_ci
634141cc406Sopenharmony_ci		/* ReadColorImageData() */
635141cc406Sopenharmony_ci		if( ps->DataInf.dwScanFlag & SCANDEF_ColorBGROrder ) {
636141cc406Sopenharmony_ci
637141cc406Sopenharmony_ci			ps->AsicReg.RD_ModeControl = _ModeFifoRSel;
638141cc406Sopenharmony_ci			IOReadScannerImageData( ps, ps->pScanBuffer1 +
639141cc406Sopenharmony_ci				         			    ps->DataInf.dwAsicBytesPerPlane * 2,
640141cc406Sopenharmony_ci									    ps->DataInf.dwAsicBytesPerPlane );
641141cc406Sopenharmony_ci
642141cc406Sopenharmony_ci			ps->AsicReg.RD_ModeControl = _ModeFifoGSel;
643141cc406Sopenharmony_ci			IOReadScannerImageData( ps, ps->pScanBuffer1 +
644141cc406Sopenharmony_ci										ps->DataInf.dwAsicBytesPerPlane,
645141cc406Sopenharmony_ci										ps->DataInf.dwAsicBytesPerPlane );
646141cc406Sopenharmony_ci
647141cc406Sopenharmony_ci			ps->AsicReg.RD_ModeControl = _ModeFifoBSel;
648141cc406Sopenharmony_ci			IOReadScannerImageData( ps, ps->pScanBuffer1,
649141cc406Sopenharmony_ci				 					    ps->DataInf.dwAsicBytesPerPlane );
650141cc406Sopenharmony_ci		} else {
651141cc406Sopenharmony_ci
652141cc406Sopenharmony_ci            IOReadColorData( ps, ps->pScanBuffer1,
653141cc406Sopenharmony_ci                                 ps->DataInf.dwAsicBytesPerPlane );
654141cc406Sopenharmony_ci		}
655141cc406Sopenharmony_ci    }
656141cc406Sopenharmony_ci
657141cc406Sopenharmony_ci	if (ps->fFilterFirstLine) {
658141cc406Sopenharmony_ci		ps->fFilterFirstLine = _FALSE;
659141cc406Sopenharmony_ci	    return _TRUE;
660141cc406Sopenharmony_ci	}
661141cc406Sopenharmony_ci
662141cc406Sopenharmony_ci	imageP98DoFilter( ps, ps->DataInf.pCurrentBuffer );
663141cc406Sopenharmony_ci
664141cc406Sopenharmony_ci    (*ps->Scan.DataProcess)( ps, ps->Scan.bp.pMonoBuf,
665141cc406Sopenharmony_ci                             ps->DataInf.pCurrentBuffer,
666141cc406Sopenharmony_ci                             ps->DataInf.dwAppPhyBytesPerLine );
667141cc406Sopenharmony_ci
668141cc406Sopenharmony_ci    return _TRUE;
669141cc406Sopenharmony_ci}
670141cc406Sopenharmony_ci
671141cc406Sopenharmony_ci/** here we wait for one data-line
672141cc406Sopenharmony_ci */
673141cc406Sopenharmony_cistatic Bool imageP98001ReadOneImageLine( pScanData ps )
674141cc406Sopenharmony_ci{
675141cc406Sopenharmony_ci	ULong    dwFifoCounter;
676141cc406Sopenharmony_ci	TimerDef timer;
677141cc406Sopenharmony_ci
678141cc406Sopenharmony_ci	MiscStartTimer( &timer, _LINE_TIMEOUT );
679141cc406Sopenharmony_ci    do {
680141cc406Sopenharmony_ci
681141cc406Sopenharmony_ci		ps->Scan.bNowScanState = IOGetScanState( ps, _FALSE );
682141cc406Sopenharmony_ci		dwFifoCounter = IOReadFifoLength( ps );
683141cc406Sopenharmony_ci
684141cc406Sopenharmony_ci		if (!(ps->Scan.bNowScanState & _SCANSTATE_STOP) &&
685141cc406Sopenharmony_ci								    (dwFifoCounter < ps->dwMaxReadFifoData)) {
686141cc406Sopenharmony_ci
687141cc406Sopenharmony_ci		    if( ps->Scan.bOldScanState != ps->Scan.bNowScanState )
688141cc406Sopenharmony_ci				ps->UpdateDataCurrentReadLine( ps );
689141cc406Sopenharmony_ci
690141cc406Sopenharmony_ci		    if( dwFifoCounter >= ps->Scan.dwMinReadFifo )
691141cc406Sopenharmony_ci				return imageP98DataIsReady( ps );
692141cc406Sopenharmony_ci
693141cc406Sopenharmony_ci		} else {	/* ScanStateIsStop */
694141cc406Sopenharmony_ci
695141cc406Sopenharmony_ci		    if (dwFifoCounter >= ps->dwSizeMustProcess)
696141cc406Sopenharmony_ci				return imageP98DataIsReady( ps );
697141cc406Sopenharmony_ci
698141cc406Sopenharmony_ci			ps->UpdateDataCurrentReadLine( ps );
699141cc406Sopenharmony_ci
700141cc406Sopenharmony_ci		    if( dwFifoCounter >= ps->Scan.dwMinReadFifo )
701141cc406Sopenharmony_ci				return imageP98DataIsReady( ps );
702141cc406Sopenharmony_ci		}
703141cc406Sopenharmony_ci
704141cc406Sopenharmony_ci		_DODELAY(10);			     /* delay 10 ms */
705141cc406Sopenharmony_ci
706141cc406Sopenharmony_ci    } while (!MiscCheckTimer( &timer ));
707141cc406Sopenharmony_ci
708141cc406Sopenharmony_ci	DBG( DBG_HIGH, "Timeout - Scanner malfunction !!\n" );
709141cc406Sopenharmony_ci	MotorToHomePosition(ps);
710141cc406Sopenharmony_ci
711141cc406Sopenharmony_ci	/* timed out, scanner malfunction */
712141cc406Sopenharmony_ci    return _FALSE;
713141cc406Sopenharmony_ci}
714141cc406Sopenharmony_ci
715141cc406Sopenharmony_ci/** calculate the image properties according to the scanmode
716141cc406Sopenharmony_ci */
717141cc406Sopenharmony_cistatic void imageP98GetInfo( pScanData ps, pImgDef pImgInf )
718141cc406Sopenharmony_ci{
719141cc406Sopenharmony_ci	DBG( DBG_LOW, "imageP98GetInfo()\n" );
720141cc406Sopenharmony_ci
721141cc406Sopenharmony_ci	ps->DataInf.xyPhyDpi.x = imageGetPhysDPI( ps, pImgInf, _TRUE  );
722141cc406Sopenharmony_ci	ps->DataInf.xyPhyDpi.y = imageGetPhysDPI( ps, pImgInf, _FALSE );
723141cc406Sopenharmony_ci
724141cc406Sopenharmony_ci	DBG( DBG_LOW, "xyPhyDpi.x = %u, xyPhyDpi.y = %u\n",
725141cc406Sopenharmony_ci		 ps->DataInf.xyPhyDpi.x, ps->DataInf.xyPhyDpi.y );
726141cc406Sopenharmony_ci
727141cc406Sopenharmony_ci	DBG( DBG_LOW, "crArea.x = %u, crArea.y = %u\n",
728141cc406Sopenharmony_ci		 pImgInf->crArea.x, pImgInf->crArea.y );
729141cc406Sopenharmony_ci
730141cc406Sopenharmony_ci	DBG( DBG_LOW, "crArea.cx = %u, crArea.cy = %u\n",
731141cc406Sopenharmony_ci		 pImgInf->crArea.cx, pImgInf->crArea.cy );
732141cc406Sopenharmony_ci
733141cc406Sopenharmony_ci	ps->DataInf.XYRatio = 1000 * ps->DataInf.xyPhyDpi.y/ps->DataInf.xyPhyDpi.x;
734141cc406Sopenharmony_ci	DBG( DBG_LOW, "xyDpi.x = %u, xyDpi.y = %u, XYRatio = %u\n",
735141cc406Sopenharmony_ci	               pImgInf->xyDpi.x, pImgInf->xyDpi.y, ps->DataInf.XYRatio );
736141cc406Sopenharmony_ci
737141cc406Sopenharmony_ci	ps->DataInf.dwAppLinesPerArea = (ULong)pImgInf->crArea.cy *
738141cc406Sopenharmony_ci									  pImgInf->xyDpi.y / _MEASURE_BASE;
739141cc406Sopenharmony_ci
740141cc406Sopenharmony_ci    ps->DataInf.dwAppPixelsPerLine = (ULong)pImgInf->crArea.cx *
741141cc406Sopenharmony_ci									   pImgInf->xyDpi.x / _MEASURE_BASE;
742141cc406Sopenharmony_ci
743141cc406Sopenharmony_ci	ps->DataInf.dwPhysBytesPerLine = (ULong)pImgInf->crArea.cx *
744141cc406Sopenharmony_ci									   ps->DataInf.xyPhyDpi.x / _MEASURE_BASE;
745141cc406Sopenharmony_ci
746141cc406Sopenharmony_ci    if( pImgInf->wDataType <= COLOR_HALFTONE ) {
747141cc406Sopenharmony_ci		ps->DataInf.dwAsicPixelsPerPlane = (ps->DataInf.dwAppPixelsPerLine+7UL)&
748141cc406Sopenharmony_ci											 0xfffffff8UL;
749141cc406Sopenharmony_ci		ps->DataInf.dwAppPhyBytesPerLine =
750141cc406Sopenharmony_ci		ps->DataInf.dwAppBytesPerLine 	 =
751141cc406Sopenharmony_ci		ps->DataInf.dwAsicBytesPerLine   =
752141cc406Sopenharmony_ci		ps->DataInf.dwAsicBytesPerPlane  = ps->DataInf.dwAsicPixelsPerPlane>>3;
753141cc406Sopenharmony_ci    } else {
754141cc406Sopenharmony_ci		ps->DataInf.dwAsicBytesPerPlane  =
755141cc406Sopenharmony_ci		ps->DataInf.dwAsicPixelsPerPlane = ps->DataInf.dwAppPixelsPerLine;
756141cc406Sopenharmony_ci	}
757141cc406Sopenharmony_ci
758141cc406Sopenharmony_ci    if( COLOR_TRUE48 == pImgInf->wDataType ) {
759141cc406Sopenharmony_ci		ps->DataInf.dwAsicBytesPerPlane *= 2;
760141cc406Sopenharmony_ci	}
761141cc406Sopenharmony_ci
762141cc406Sopenharmony_ci    switch( pImgInf->wDataType ) {
763141cc406Sopenharmony_ci
764141cc406Sopenharmony_ci	case COLOR_BW:
765141cc406Sopenharmony_ci	    ps->DataInf.dwVxdFlag |= _VF_DATATOUSERBUFFER;
766141cc406Sopenharmony_ci	    ps->DataInf.wPhyDataType = COLOR_BW;
767141cc406Sopenharmony_ci        ps->Shade.bIntermediate  = _ScanMode_Mono;
768141cc406Sopenharmony_ci	    break;
769141cc406Sopenharmony_ci
770141cc406Sopenharmony_ci	case COLOR_HALFTONE:
771141cc406Sopenharmony_ci		if( ps->DataInf.wDither == 2 ) {
772141cc406Sopenharmony_ci            ps->Scan.DataProcess = fnHalftoneDirect1;
773141cc406Sopenharmony_ci		} else {
774141cc406Sopenharmony_ci            ps->Scan.DataProcess = fnHalftoneDirect0;
775141cc406Sopenharmony_ci		}
776141cc406Sopenharmony_ci/*
777141cc406Sopenharmony_ci * CHANGE: it seems, that we have to use the same settings as for 256GRAY
778141cc406Sopenharmony_ci */
779141cc406Sopenharmony_ci		ps->DataInf.dwAsicBytesPerPlane =
780141cc406Sopenharmony_ci		ps->DataInf.dwAsicPixelsPerPlane = ps->DataInf.dwAppPixelsPerLine;
781141cc406Sopenharmony_ci	    ps->DataInf.wPhyDataType = COLOR_256GRAY;
782141cc406Sopenharmony_ci        ps->Shade.bIntermediate  = _ScanMode_Mono;
783141cc406Sopenharmony_ci	    break;
784141cc406Sopenharmony_ci
785141cc406Sopenharmony_ci	case COLOR_256GRAY:
786141cc406Sopenharmony_ci	    ps->DataInf.dwVxdFlag |= _VF_DATATOUSERBUFFER;
787141cc406Sopenharmony_ci	    ps->DataInf.dwAsicBytesPerLine =
788141cc406Sopenharmony_ci	    ps->DataInf.dwAppPhyBytesPerLine = ps->DataInf.dwAppPixelsPerLine;
789141cc406Sopenharmony_ci	    ps->DataInf.wPhyDataType = COLOR_256GRAY;
790141cc406Sopenharmony_ci        ps->Shade.bIntermediate  = _ScanMode_Mono;
791141cc406Sopenharmony_ci	    break;
792141cc406Sopenharmony_ci
793141cc406Sopenharmony_ci	case COLOR_TRUE24:
794141cc406Sopenharmony_ci        ps->Scan.DataProcess = fnP98ColorDirect;
795141cc406Sopenharmony_ci	    ps->DataInf.dwAsicBytesPerLine =
796141cc406Sopenharmony_ci	    ps->DataInf.dwAppPhyBytesPerLine = ps->DataInf.dwAppPixelsPerLine * 3;
797141cc406Sopenharmony_ci	    ps->DataInf.wPhyDataType = COLOR_TRUE24;
798141cc406Sopenharmony_ci        ps->Shade.bIntermediate  = _ScanMode_Color;
799141cc406Sopenharmony_ci	    break;
800141cc406Sopenharmony_ci
801141cc406Sopenharmony_ci	case COLOR_TRUE48:
802141cc406Sopenharmony_ci        ps->Scan.DataProcess = fnP98Color48;
803141cc406Sopenharmony_ci	    ps->DataInf.dwAsicBytesPerLine =
804141cc406Sopenharmony_ci	    ps->DataInf.dwAppPhyBytesPerLine = ps->DataInf.dwAppPixelsPerLine * 6;
805141cc406Sopenharmony_ci	    ps->DataInf.wPhyDataType = COLOR_TRUE48;
806141cc406Sopenharmony_ci        ps->Shade.bIntermediate  = _ScanMode_Color;
807141cc406Sopenharmony_ci	    break;
808141cc406Sopenharmony_ci
809141cc406Sopenharmony_ci    }
810141cc406Sopenharmony_ci
811141cc406Sopenharmony_ci    if (pImgInf->dwFlag & SCANDEF_BoundaryDWORD) {
812141cc406Sopenharmony_ci		ps->DataInf.dwAppBytesPerLine = (ps->DataInf.dwAppPhyBytesPerLine + 3) &
813141cc406Sopenharmony_ci									      0xfffffffc;
814141cc406Sopenharmony_ci	} else {
815141cc406Sopenharmony_ci		if (pImgInf->dwFlag & SCANDEF_BoundaryWORD) {
816141cc406Sopenharmony_ci		    ps->DataInf.dwAppBytesPerLine = (ps->DataInf.dwAppPhyBytesPerLine + 1) &
817141cc406Sopenharmony_ci											  0xfffffffe;
818141cc406Sopenharmony_ci		} else {
819141cc406Sopenharmony_ci		    ps->DataInf.dwAppBytesPerLine = ps->DataInf.dwAppPhyBytesPerLine;
820141cc406Sopenharmony_ci		}
821141cc406Sopenharmony_ci	}
822141cc406Sopenharmony_ci
823141cc406Sopenharmony_ci	DBG( DBG_LOW, "AppLinesPerArea    = %u\n", ps->DataInf.dwAppLinesPerArea    );
824141cc406Sopenharmony_ci	DBG( DBG_LOW, "AppPixelsPerLine   = %u\n", ps->DataInf.dwAppPixelsPerLine   );
825141cc406Sopenharmony_ci	DBG( DBG_LOW, "AppPhyBytesPerLine = %u\n", ps->DataInf.dwAppPhyBytesPerLine );
826141cc406Sopenharmony_ci	DBG( DBG_LOW, "AppBytesPerLine    = %u\n", ps->DataInf.dwAppBytesPerLine    );
827141cc406Sopenharmony_ci	DBG( DBG_LOW, "AsicPixelsPerPlane = %u\n", ps->DataInf.dwAsicPixelsPerPlane );
828141cc406Sopenharmony_ci	DBG( DBG_LOW, "AsicBytesPerPlane  = %u\n", ps->DataInf.dwAsicBytesPerPlane  );
829141cc406Sopenharmony_ci	DBG( DBG_LOW, "AsicBytesPerLine   = %u\n", ps->DataInf.dwAsicBytesPerLine   );
830141cc406Sopenharmony_ci	DBG( DBG_LOW, "Physical Bytes     = %u\n", ps->DataInf.dwPhysBytesPerLine   );
831141cc406Sopenharmony_ci}
832141cc406Sopenharmony_ci
833141cc406Sopenharmony_ci/**
834141cc406Sopenharmony_ci */
835141cc406Sopenharmony_cistatic void imageP96GetInfo( pScanData ps, pImgDef pImgInf )
836141cc406Sopenharmony_ci{
837141cc406Sopenharmony_ci	DBG( DBG_LOW, "imageP96GetInfo()\n" );
838141cc406Sopenharmony_ci
839141cc406Sopenharmony_ci	ps->DataInf.xyPhyDpi.x = imageGetPhysDPI( ps, pImgInf, _TRUE  );
840141cc406Sopenharmony_ci	ps->DataInf.xyPhyDpi.y = imageGetPhysDPI( ps, pImgInf, _FALSE );
841141cc406Sopenharmony_ci
842141cc406Sopenharmony_ci	DBG( DBG_LOW, "xyPhyDpi.x = %u, xyPhyDpi.y = %u\n",
843141cc406Sopenharmony_ci		 ps->DataInf.xyPhyDpi.x, ps->DataInf.xyPhyDpi.y );
844141cc406Sopenharmony_ci
845141cc406Sopenharmony_ci	DBG( DBG_LOW, "crArea.x = %u, crArea.y = %u\n",
846141cc406Sopenharmony_ci		 pImgInf->crArea.x, pImgInf->crArea.y );
847141cc406Sopenharmony_ci
848141cc406Sopenharmony_ci	DBG( DBG_LOW, "crArea.cx = %u, crArea.cy = %u\n",
849141cc406Sopenharmony_ci		 pImgInf->crArea.cx, pImgInf->crArea.cy );
850141cc406Sopenharmony_ci
851141cc406Sopenharmony_ci	ps->DataInf.XYRatio = 1000 * ps->DataInf.xyPhyDpi.y/ps->DataInf.xyPhyDpi.x;
852141cc406Sopenharmony_ci	DBG( DBG_LOW, "xyDpi.x = %u, xyDpi.y = %u, XYRatio = %u\n",
853141cc406Sopenharmony_ci	               pImgInf->xyDpi.x, pImgInf->xyDpi.y, ps->DataInf.XYRatio );
854141cc406Sopenharmony_ci
855141cc406Sopenharmony_ci	ps->DataInf.dwAppLinesPerArea = (ULong)pImgInf->crArea.cy *
856141cc406Sopenharmony_ci					  					   pImgInf->xyDpi.y / _MEASURE_BASE;
857141cc406Sopenharmony_ci    ps->DataInf.dwAsicBytesPerPlane  =
858141cc406Sopenharmony_ci	ps->DataInf.dwAsicPixelsPerPlane = (ULong)ps->DataInf.xyPhyDpi.x *
859141cc406Sopenharmony_ci				 					       pImgInf->crArea.cx / _MEASURE_BASE;
860141cc406Sopenharmony_ci
861141cc406Sopenharmony_ci    ps->DataInf.dwAppPixelsPerLine = (ULong)pImgInf->crArea.cx *
862141cc406Sopenharmony_ci										    pImgInf->xyDpi.x / _MEASURE_BASE;
863141cc406Sopenharmony_ci
864141cc406Sopenharmony_ci	ps->DataInf.dwPhysBytesPerLine = (ULong)pImgInf->crArea.cx *
865141cc406Sopenharmony_ci									   ps->DataInf.xyPhyDpi.x / _MEASURE_BASE;
866141cc406Sopenharmony_ci
867141cc406Sopenharmony_ci    ps->DataInf.wPhyDataType = ps->DataInf.wAppDataType;
868141cc406Sopenharmony_ci
869141cc406Sopenharmony_ci    switch( pImgInf->wDataType ) {
870141cc406Sopenharmony_ci
871141cc406Sopenharmony_ci	case COLOR_BW:
872141cc406Sopenharmony_ci	    ps->DataInf.dwAsicBytesPerPlane =
873141cc406Sopenharmony_ci								 (ps->DataInf.dwAsicPixelsPerPlane + 7) >> 3;
874141cc406Sopenharmony_ci	    ps->DataInf.dwAppPhyBytesPerLine =
875141cc406Sopenharmony_ci									 (ps->DataInf.dwAppPixelsPerLine + 7) >> 3;
876141cc406Sopenharmony_ci	    ps->DataInf.dwVxdFlag |= _VF_DATATOUSERBUFFER;
877141cc406Sopenharmony_ci        ps->Scan.DataProcess = fnDataDirect;
878141cc406Sopenharmony_ci	    break;
879141cc406Sopenharmony_ci
880141cc406Sopenharmony_ci	case COLOR_HALFTONE:
881141cc406Sopenharmony_ci	    ps->DataInf.dwAppPhyBytesPerLine =
882141cc406Sopenharmony_ci								 (ps->DataInf.dwAsicPixelsPerPlane + 7) >> 3;
883141cc406Sopenharmony_ci		if( ps->DataInf.wDither == 2 ) {
884141cc406Sopenharmony_ci            ps->Scan.DataProcess = fnHalftoneDirect1;
885141cc406Sopenharmony_ci		} else {
886141cc406Sopenharmony_ci            ps->Scan.DataProcess = fnHalftoneDirect0;
887141cc406Sopenharmony_ci		}
888141cc406Sopenharmony_ci	    ps->DataInf.wPhyDataType = COLOR_256GRAY;
889141cc406Sopenharmony_ci	    break;
890141cc406Sopenharmony_ci
891141cc406Sopenharmony_ci	case COLOR_256GRAY:
892141cc406Sopenharmony_ci	    ps->DataInf.dwAppPhyBytesPerLine = ps->DataInf.dwAppPixelsPerLine;
893141cc406Sopenharmony_ci        ps->Scan.DataProcess = fnP96GrayDirect;
894141cc406Sopenharmony_ci	    break;
895141cc406Sopenharmony_ci
896141cc406Sopenharmony_ci	case COLOR_TRUE24:
897141cc406Sopenharmony_ci#ifdef _A3I_EN
898141cc406Sopenharmony_ci        ps->Scan.DataProcess = fnP98ColorDirect;
899141cc406Sopenharmony_ci#else
900141cc406Sopenharmony_ci        ps->Scan.DataProcess = fnP96ColorDirect;
901141cc406Sopenharmony_ci#endif
902141cc406Sopenharmony_ci	    ps->DataInf.dwAppPhyBytesPerLine = ps->DataInf.dwAppPixelsPerLine * 3;
903141cc406Sopenharmony_ci    }
904141cc406Sopenharmony_ci
905141cc406Sopenharmony_ci    if( pImgInf->dwFlag & SCANDEF_BoundaryDWORD ) {
906141cc406Sopenharmony_ci		ps->DataInf.dwAppBytesPerLine =
907141cc406Sopenharmony_ci							(ps->DataInf.dwAppPhyBytesPerLine + 3) & 0xfffffffc;
908141cc406Sopenharmony_ci	} else {
909141cc406Sopenharmony_ci		if ( pImgInf->dwFlag & SCANDEF_BoundaryWORD ) {
910141cc406Sopenharmony_ci		    ps->DataInf.dwAppBytesPerLine =
911141cc406Sopenharmony_ci							(ps->DataInf.dwAppPhyBytesPerLine + 1) & 0xfffffffe;
912141cc406Sopenharmony_ci		} else {
913141cc406Sopenharmony_ci	    	ps->DataInf.dwAppBytesPerLine = ps->DataInf.dwAppPhyBytesPerLine;
914141cc406Sopenharmony_ci		}
915141cc406Sopenharmony_ci	}
916141cc406Sopenharmony_ci
917141cc406Sopenharmony_ci    if (ps->DataInf.wPhyDataType == COLOR_TRUE24)
918141cc406Sopenharmony_ci		ps->DataInf.dwAsicBytesPerLine = ps->DataInf.dwAsicBytesPerPlane * 3;
919141cc406Sopenharmony_ci    else
920141cc406Sopenharmony_ci		ps->DataInf.dwAsicBytesPerLine = ps->DataInf.dwAsicBytesPerPlane;
921141cc406Sopenharmony_ci
922141cc406Sopenharmony_ci/* WORK: AsicBytesPerLine only used for ASIC_98001 based scanners - try to remove
923141cc406Sopenharmony_ci**		 that, also try to remove redundant info
924141cc406Sopenharmony_ci*/
925141cc406Sopenharmony_ci	DBG( DBG_LOW, "AppLinesPerArea    = %u\n", ps->DataInf.dwAppLinesPerArea    );
926141cc406Sopenharmony_ci	DBG( DBG_LOW, "AppPixelsPerLine   = %u\n", ps->DataInf.dwAppPixelsPerLine   );
927141cc406Sopenharmony_ci	DBG( DBG_LOW, "AppPhyBytesPerLine = %u\n", ps->DataInf.dwAppPhyBytesPerLine );
928141cc406Sopenharmony_ci	DBG( DBG_LOW, "AppBytesPerLine    = %u\n", ps->DataInf.dwAppBytesPerLine    );
929141cc406Sopenharmony_ci	DBG( DBG_LOW, "AsicPixelsPerPlane = %u\n", ps->DataInf.dwAsicPixelsPerPlane );
930141cc406Sopenharmony_ci	DBG( DBG_LOW, "AsicBytesPerPlane  = %u\n", ps->DataInf.dwAsicBytesPerPlane  );
931141cc406Sopenharmony_ci	DBG( DBG_LOW, "AsicBytesPerLine   = %u\n", ps->DataInf.dwAsicBytesPerLine   );
932141cc406Sopenharmony_ci	DBG( DBG_LOW, "Physical Bytes     = %u\n", ps->DataInf.dwPhysBytesPerLine   );
933141cc406Sopenharmony_ci}
934141cc406Sopenharmony_ci
935141cc406Sopenharmony_ci/** here we wait for one data-line
936141cc406Sopenharmony_ci */
937141cc406Sopenharmony_cistatic Bool imageP96ReadOneImageLine( pScanData ps )
938141cc406Sopenharmony_ci{
939141cc406Sopenharmony_ci    Bool     result = _FALSE;
940141cc406Sopenharmony_ci	Byte	 bData, bFifoCount;
941141cc406Sopenharmony_ci    TimerDef timer;
942141cc406Sopenharmony_ci
943141cc406Sopenharmony_ci	MiscStartTimer( &timer, _LINE_TIMEOUT);
944141cc406Sopenharmony_ci    do {
945141cc406Sopenharmony_ci
946141cc406Sopenharmony_ci		bFifoCount = IODataRegisterFromScanner( ps, ps->RegFifoOffset );
947141cc406Sopenharmony_ci
948141cc406Sopenharmony_ci/* CHECK ps->bMoveDataOutFlag will never be set to _DataFromStopState !!!*/
949141cc406Sopenharmony_ci#if 1
950141cc406Sopenharmony_ci		if ((bFifoCount < ps->bMinReadFifo) &&
951141cc406Sopenharmony_ci					            (ps->bMoveDataOutFlag == _DataFromStopState)) {
952141cc406Sopenharmony_ci
953141cc406Sopenharmony_ci		    bData = IOGetScanState( ps, _FALSE);
954141cc406Sopenharmony_ci
955141cc406Sopenharmony_ci		    if (!(bData & _SCANSTATE_STOP)) {
956141cc406Sopenharmony_ci				if (bData < ps->bCurrentLineCount)
957141cc406Sopenharmony_ci				    bData += _NUMBER_OF_SCANSTEPS;
958141cc406Sopenharmony_ci				if ((bData - ps->bCurrentLineCount) < _SCANSTATE_BYTES)
959141cc406Sopenharmony_ci				    continue;
960141cc406Sopenharmony_ci		    }
961141cc406Sopenharmony_ci
962141cc406Sopenharmony_ci		    ps->bMoveDataOutFlag = _DataAfterRefreshState;
963141cc406Sopenharmony_ci		}
964141cc406Sopenharmony_ci#endif
965141cc406Sopenharmony_ci
966141cc406Sopenharmony_ci/*
967141cc406Sopenharmony_ci// HEINER:A3I
968141cc406Sopenharmony_ci//		if( ps->bMoveDataOutFlag != _DataFromStopState )
969141cc406Sopenharmony_ci//	    	ps->UpdateDataCurrentReadLine( ps );
970141cc406Sopenharmony_ci*/
971141cc406Sopenharmony_ci		if( bFifoCount >= ps->bMinReadFifo ) {
972141cc406Sopenharmony_ci
973141cc406Sopenharmony_ci		    /* data is ready */
974141cc406Sopenharmony_ci		    for (; !(*ps->pCurrentColorRunTable &
975141cc406Sopenharmony_ci				(ps->RedDataReady | ps->GreenDataReady | _BLUE_DATA_READY));
976141cc406Sopenharmony_ci												 ps->pCurrentColorRunTable++);
977141cc406Sopenharmony_ci
978141cc406Sopenharmony_ci#ifdef DEBUG
979141cc406Sopenharmony_ci			if( ps->pCurrentColorRunTable >
980141cc406Sopenharmony_ci							(ps->pColorRunTable+ps->BufferForColorRunTable))
981141cc406Sopenharmony_ci				DBG( DBG_LOW, "WARNING: pCurrentColorRunTab>pColorRunTable\n");
982141cc406Sopenharmony_ci#endif
983141cc406Sopenharmony_ci
984141cc406Sopenharmony_ci		    if (ps->DataInf.wPhyDataType == COLOR_TRUE24) {
985141cc406Sopenharmony_ci
986141cc406Sopenharmony_ci				/* read color planes (either R/G/B or R/B/G sequence that
987141cc406Sopenharmony_ci				 * depends on COLOR CCD, see below
988141cc406Sopenharmony_ci				 */
989141cc406Sopenharmony_ci				if (*ps->pCurrentColorRunTable & ps->b1stColor) {
990141cc406Sopenharmony_ci				    *ps->pCurrentColorRunTable &= ps->b1stMask;
991141cc406Sopenharmony_ci				    IOReadScannerImageData (ps, ps->pPutBufR,
992141cc406Sopenharmony_ci						  					    ps->DataInf.dwAsicBytesPerPlane);
993141cc406Sopenharmony_ci				    ps->pPutBufR += ps->BufferSizePerModel;
994141cc406Sopenharmony_ci					if (ps->pPutBufR == ps->pEndBufR)
995141cc406Sopenharmony_ci						ps->pPutBufR = ps->pPrescan16;
996141cc406Sopenharmony_ci				} else
997141cc406Sopenharmony_ci					if (*ps->pCurrentColorRunTable & ps->b2ndColor) {
998141cc406Sopenharmony_ci						*ps->pCurrentColorRunTable &= ps->b2ndMask;
999141cc406Sopenharmony_ci						IOReadScannerImageData( ps, ps->pPutBufG,
1000141cc406Sopenharmony_ci										        ps->DataInf.dwAsicBytesPerPlane);
1001141cc406Sopenharmony_ci						ps->pPutBufG += ps->BufferSizePerModel;
1002141cc406Sopenharmony_ci						if (ps->pPutBufG == ps->pEndBufG)
1003141cc406Sopenharmony_ci						    ps->pPutBufG = ps->pPrescan8;
1004141cc406Sopenharmony_ci		    	} else {
1005141cc406Sopenharmony_ci					*ps->pCurrentColorRunTable &= ps->b3rdMask;
1006141cc406Sopenharmony_ci					ps->pCurrentColorRunTable++;    /* processed this step */
1007141cc406Sopenharmony_ci
1008141cc406Sopenharmony_ci					/* according to CCD type & image placement method to
1009141cc406Sopenharmony_ci					 * read third color into corresponding location.
1010141cc406Sopenharmony_ci					 * SONY CCD: Red, Green and Blue.
1011141cc406Sopenharmony_ci					 * TOSHIBA CCD: Red, Blue and Green.
1012141cc406Sopenharmony_ci					 * SCANDEF_BmpStyle: Blue, Green and Red, Otherwise
1013141cc406Sopenharmony_ci					 *  Red, Green and Blue.
1014141cc406Sopenharmony_ci					 */
1015141cc406Sopenharmony_ci					if (ps->b3rdColor & ps->GreenDataReady) {
1016141cc406Sopenharmony_ci					    /* Green always in middle */
1017141cc406Sopenharmony_ci					    IOReadScannerImageData (ps,
1018141cc406Sopenharmony_ci                                                 ps->DataInf.pCurrentBuffer +
1019141cc406Sopenharmony_ci											  ps->DataInf.dwAsicBytesPerPlane,
1020141cc406Sopenharmony_ci											  ps->DataInf.dwAsicBytesPerPlane);
1021141cc406Sopenharmony_ci					} else {
1022141cc406Sopenharmony_ci					    /* Blue depends the request style from caller */
1023141cc406Sopenharmony_ci					    if (ps->DataInf.dwScanFlag & SCANDEF_BmpStyle) {
1024141cc406Sopenharmony_ci							/* BMP style, blue is the first one */
1025141cc406Sopenharmony_ci							IOReadScannerImageData (ps,
1026141cc406Sopenharmony_ci                                                   ps->DataInf.pCurrentBuffer,
1027141cc406Sopenharmony_ci											  ps->DataInf.dwAsicBytesPerPlane);
1028141cc406Sopenharmony_ci						} else {
1029141cc406Sopenharmony_ci							/* Blue is the last one */
1030141cc406Sopenharmony_ci							IOReadScannerImageData (ps, ps->DataInf.pCurrentBuffer +
1031141cc406Sopenharmony_ci											ps->DataInf.dwAsicBytesPerPlane * 2,
1032141cc406Sopenharmony_ci											  ps->DataInf.dwAsicBytesPerPlane);
1033141cc406Sopenharmony_ci						}
1034141cc406Sopenharmony_ci					}
1035141cc406Sopenharmony_ci
1036141cc406Sopenharmony_ci					/* reassemble 3 color lines for separated RGB value */
1037141cc406Sopenharmony_ci    				if (ps->DataInf.dwScanFlag & SCANDEF_BmpStyle) {
1038141cc406Sopenharmony_ci					    /* BMP style, red is last one */
1039141cc406Sopenharmony_ci					    memcpy( ps->DataInf.pCurrentBuffer +
1040141cc406Sopenharmony_ci								ps->DataInf.dwAsicBytesPerPlane * 2,
1041141cc406Sopenharmony_ci								ps->pGetBufR, ps->DataInf.dwAsicBytesPerPlane);
1042141cc406Sopenharmony_ci					} else {
1043141cc406Sopenharmony_ci					    /* Red is first one */
1044141cc406Sopenharmony_ci					    memcpy( ps->DataInf.pCurrentBuffer,
1045141cc406Sopenharmony_ci		 					    ps->pGetBufR, ps->DataInf.dwAsicBytesPerPlane );
1046141cc406Sopenharmony_ci					}
1047141cc406Sopenharmony_ci
1048141cc406Sopenharmony_ci					if (ps->b2ndColor & ps->GreenDataReady) {
1049141cc406Sopenharmony_ci					    /* Green always in middle */
1050141cc406Sopenharmony_ci						memcpy( ps->DataInf.pCurrentBuffer +
1051141cc406Sopenharmony_ci							   ps->DataInf.dwAsicBytesPerPlane,
1052141cc406Sopenharmony_ci							   ps->pGetBufG, ps->DataInf.dwAsicBytesPerPlane);
1053141cc406Sopenharmony_ci					} else {
1054141cc406Sopenharmony_ci				    	/* Blue depends the request style from caller */
1055141cc406Sopenharmony_ci					    if (ps->DataInf.dwScanFlag & SCANDEF_BmpStyle) {
1056141cc406Sopenharmony_ci							/* BMP style, blue is the first one */
1057141cc406Sopenharmony_ci							memcpy( ps->DataInf.pCurrentBuffer,
1058141cc406Sopenharmony_ci							        ps->pGetBufG,
1059141cc406Sopenharmony_ci							        ps->DataInf.dwAsicBytesPerPlane);
1060141cc406Sopenharmony_ci						} else {
1061141cc406Sopenharmony_ci							/* BMP style, blue is the last one */
1062141cc406Sopenharmony_ci							memcpy( ps->DataInf.pCurrentBuffer +
1063141cc406Sopenharmony_ci							        ps->DataInf.dwAsicBytesPerPlane * 2,
1064141cc406Sopenharmony_ci							        ps->pGetBufG,
1065141cc406Sopenharmony_ci							        ps->DataInf.dwAsicBytesPerPlane );
1066141cc406Sopenharmony_ci						}
1067141cc406Sopenharmony_ci					}
1068141cc406Sopenharmony_ci
1069141cc406Sopenharmony_ci					/* Adjust the get pointers */
1070141cc406Sopenharmony_ci					ps->pGetBufR += ps->BufferSizePerModel;
1071141cc406Sopenharmony_ci					ps->pGetBufG += ps->BufferSizePerModel;
1072141cc406Sopenharmony_ci					if (ps->pGetBufR == ps->pEndBufR)
1073141cc406Sopenharmony_ci					    ps->pGetBufR = ps->pPrescan16;
1074141cc406Sopenharmony_ci
1075141cc406Sopenharmony_ci					if (ps->pGetBufG == ps->pEndBufG)
1076141cc406Sopenharmony_ci					    ps->pGetBufG = ps->pPrescan8;
1077141cc406Sopenharmony_ci
1078141cc406Sopenharmony_ci    				result = _TRUE; /* Line data in buffer */
1079141cc406Sopenharmony_ci                    break;
1080141cc406Sopenharmony_ci			    }
1081141cc406Sopenharmony_ci
1082141cc406Sopenharmony_ci				/* reset timer for new 10-second interval */
1083141cc406Sopenharmony_ci				MiscStartTimer( &timer, (10 * _SECOND));
1084141cc406Sopenharmony_ci
1085141cc406Sopenharmony_ci		    } else  {
1086141cc406Sopenharmony_ci				/* Gray Image */
1087141cc406Sopenharmony_ci				*ps->pCurrentColorRunTable &= 0xf0; /* leave high nibble for debug  */
1088141cc406Sopenharmony_ci				ps->pCurrentColorRunTable++;		/* this step has been processed */
1089141cc406Sopenharmony_ci				IOReadScannerImageData( ps, ps->DataInf.pCurrentBuffer,
1090141cc406Sopenharmony_ci									        ps->DataInf.dwAsicBytesPerPlane );
1091141cc406Sopenharmony_ci
1092141cc406Sopenharmony_ci				result = _TRUE;
1093141cc406Sopenharmony_ci                break;
1094141cc406Sopenharmony_ci		    }
1095141cc406Sopenharmony_ci		}
1096141cc406Sopenharmony_ci
1097141cc406Sopenharmony_ci/* HEINER:A3I */
1098141cc406Sopenharmony_ci		if( ps->bMoveDataOutFlag != _DataFromStopState )
1099141cc406Sopenharmony_ci	    	ps->UpdateDataCurrentReadLine( ps );
1100141cc406Sopenharmony_ci
1101141cc406Sopenharmony_ci    } while (!MiscCheckTimer( &timer));
1102141cc406Sopenharmony_ci
1103141cc406Sopenharmony_ci    if( _TRUE == result ) {
1104141cc406Sopenharmony_ci        (*ps->Scan.DataProcess)( ps, ps->Scan.bp.pMonoBuf,
1105141cc406Sopenharmony_ci                                 ps->DataInf.pCurrentBuffer,
1106141cc406Sopenharmony_ci                                 ps->DataInf.dwAppPhyBytesPerLine );
1107141cc406Sopenharmony_ci        return _TRUE;
1108141cc406Sopenharmony_ci    }
1109141cc406Sopenharmony_ci
1110141cc406Sopenharmony_ci	DBG( DBG_HIGH, "Timeout - Scanner malfunction !!\n" );
1111141cc406Sopenharmony_ci	MotorToHomePosition(ps);
1112141cc406Sopenharmony_ci
1113141cc406Sopenharmony_ci    return _FALSE;
1114141cc406Sopenharmony_ci}
1115141cc406Sopenharmony_ci
1116141cc406Sopenharmony_ci/** prepare for scanning
1117141cc406Sopenharmony_ci */
1118141cc406Sopenharmony_cistatic int imageP96SetupScanSettings( pScanData ps, pScanInfo pInf )
1119141cc406Sopenharmony_ci{
1120141cc406Sopenharmony_ci	DBG( DBG_LOW, "imageSetupP96ScanSettings()\n" );
1121141cc406Sopenharmony_ci
1122141cc406Sopenharmony_ci	ps->DataInf.dwVxdFlag = 0;
1123141cc406Sopenharmony_ci	if (pInf->ImgDef.dwFlag & SCANDEF_BuildBwMap)
1124141cc406Sopenharmony_ci		ps->DataInf.dwVxdFlag |= _VF_BUILDMAP;
1125141cc406Sopenharmony_ci
1126141cc406Sopenharmony_ci    ps->DataInf.dwScanFlag = pInf->ImgDef.dwFlag;
1127141cc406Sopenharmony_ci
1128141cc406Sopenharmony_ci    ps->DataInf.crImage = pInf->ImgDef.crArea;
1129141cc406Sopenharmony_ci
1130141cc406Sopenharmony_ci	/* scale according to DPI */
1131141cc406Sopenharmony_ci    ps->DataInf.crImage.x  *= ps->PhysicalDpi / _MEASURE_BASE;
1132141cc406Sopenharmony_ci    ps->DataInf.crImage.cx *= ps->PhysicalDpi / _MEASURE_BASE;
1133141cc406Sopenharmony_ci
1134141cc406Sopenharmony_ci    if( ps->DataInf.dwScanFlag & SCANDEF_TPA ) {
1135141cc406Sopenharmony_ci		ps->DataInf.crImage.x += _Transparency48OriginOffsetX;
1136141cc406Sopenharmony_ci		ps->DataInf.crImage.y += _Transparency48OriginOffsetY;
1137141cc406Sopenharmony_ci    }
1138141cc406Sopenharmony_ci
1139141cc406Sopenharmony_ci    ps->DataInf.xyAppDpi     = pInf->ImgDef.xyDpi;
1140141cc406Sopenharmony_ci    ps->DataInf.wAppDataType = pInf->ImgDef.wDataType;
1141141cc406Sopenharmony_ci    ps->DataInf.wDither      = pInf->wDither;
1142141cc406Sopenharmony_ci
1143141cc406Sopenharmony_ci    ps->GetImageInfo( ps, &pInf->ImgDef );
1144141cc406Sopenharmony_ci
1145141cc406Sopenharmony_ci	/* try to get brightness to work */
1146141cc406Sopenharmony_ci	if (ps->DataInf.wPhyDataType != COLOR_BW) { /* if not line art 			*/
1147141cc406Sopenharmony_ci		ps->wBrightness = pInf->siBrightness;   /* use internal tables for 	*/
1148141cc406Sopenharmony_ci		ps->wContrast   = pInf->siContrast;		/* brightness and contrast	*/
1149141cc406Sopenharmony_ci
1150141cc406Sopenharmony_ci		pInf->siBrightness = 0;				/* don't use asic for threshold */
1151141cc406Sopenharmony_ci    }
1152141cc406Sopenharmony_ci    ps->DataInf.siBrightness = pInf->siBrightness;
1153141cc406Sopenharmony_ci
1154141cc406Sopenharmony_ci    if (ps->DataInf.dwScanFlag & SCANDEF_BmpStyle)
1155141cc406Sopenharmony_ci		ps->Scan.lBufferAdjust = -(Long)ps->DataInf.dwAppBytesPerLine;
1156141cc406Sopenharmony_ci    else
1157141cc406Sopenharmony_ci		ps->Scan.lBufferAdjust = (Long)ps->DataInf.dwAppBytesPerLine;
1158141cc406Sopenharmony_ci
1159141cc406Sopenharmony_ci    if (ps->DataInf.siBrightness < 0)
1160141cc406Sopenharmony_ci		ps->DataInf.siBrightness = 255 - (_DEF_BW_THRESHOLD *
1161141cc406Sopenharmony_ci							ps->DataInf.siBrightness / 127 + _DEF_BW_THRESHOLD);
1162141cc406Sopenharmony_ci    else
1163141cc406Sopenharmony_ci		ps->DataInf.siBrightness = 255 - ((255 - _DEF_BW_THRESHOLD) *
1164141cc406Sopenharmony_ci							 ps->DataInf.siBrightness / 127 + _DEF_BW_THRESHOLD);
1165141cc406Sopenharmony_ci
1166141cc406Sopenharmony_ci    ps->AsicReg.RD_ThresholdControl = (Byte)ps->DataInf.siBrightness;
1167141cc406Sopenharmony_ci
1168141cc406Sopenharmony_ci    ps->DataInf.pCurrentBuffer = ps->pScanBuffer1;
1169141cc406Sopenharmony_ci
1170141cc406Sopenharmony_ci	return _OK;
1171141cc406Sopenharmony_ci}
1172141cc406Sopenharmony_ci
1173141cc406Sopenharmony_ci/**
1174141cc406Sopenharmony_ci */
1175141cc406Sopenharmony_cistatic Bool imageP98003DataIsReady( pScanData ps )
1176141cc406Sopenharmony_ci{
1177141cc406Sopenharmony_ci	pUChar pb;
1178141cc406Sopenharmony_ci
1179141cc406Sopenharmony_ci    if( ps->Scan.bDiscardAll ) {
1180141cc406Sopenharmony_ci    	ps->Scan.bDiscardAll--;
1181141cc406Sopenharmony_ci
1182141cc406Sopenharmony_ci    	if( ps->DataInf.wPhyDataType <= COLOR_256GRAY ) {
1183141cc406Sopenharmony_ci    	    ps->AsicReg.RD_ModeControl = _ModeFifoGSel;
1184141cc406Sopenharmony_ci    	    IOReadScannerImageData( ps, ps->Bufs.b1.pReadBuf,
1185141cc406Sopenharmony_ci                                        ps->DataInf.dwAsicBytesPerPlane );
1186141cc406Sopenharmony_ci    	} else {
1187141cc406Sopenharmony_ci            IOReadColorData( ps, ps->Bufs.b1.pReadBuf,
1188141cc406Sopenharmony_ci                                 ps->DataInf.dwAsicBytesPerPlane );
1189141cc406Sopenharmony_ci        }
1190141cc406Sopenharmony_ci	    return _FALSE;
1191141cc406Sopenharmony_ci    }
1192141cc406Sopenharmony_ci
1193141cc406Sopenharmony_ci   	if( ps->DataInf.wPhyDataType <= COLOR_256GRAY ) {
1194141cc406Sopenharmony_ci
1195141cc406Sopenharmony_ci    	ps->AsicReg.RD_ModeControl = _ModeFifoGSel;
1196141cc406Sopenharmony_ci		pb = ps->Scan.bp.pMonoBuf;
1197141cc406Sopenharmony_ci
1198141cc406Sopenharmony_ci		/* use a larger buffer during halftone reads...*/
1199141cc406Sopenharmony_ci		if( ps->DataInf.wAppDataType == COLOR_HALFTONE )
1200141cc406Sopenharmony_ci			pb = ps->Scan.BufPut.red.bp;
1201141cc406Sopenharmony_ci
1202141cc406Sopenharmony_ci	    IOReadScannerImageData( ps, pb, ps->DataInf.dwAsicBytesPerPlane );
1203141cc406Sopenharmony_ci
1204141cc406Sopenharmony_ci    } else {
1205141cc406Sopenharmony_ci    	if( !ps->Scan.DataRead( ps )) {
1206141cc406Sopenharmony_ci    	    return _FALSE;
1207141cc406Sopenharmony_ci        }
1208141cc406Sopenharmony_ci    }
1209141cc406Sopenharmony_ci
1210141cc406Sopenharmony_ci    if( ps->Scan.DoSample( ps )) {
1211141cc406Sopenharmony_ci
1212141cc406Sopenharmony_ci    	if( ps->Scan.dwLinesToRead == 1 &&
1213141cc406Sopenharmony_ci           !(IOGetScanState( ps, _TRUE ) & _SCANSTATE_STOP))
1214141cc406Sopenharmony_ci	        IORegisterToScanner( ps, ps->RegRefreshScanState );
1215141cc406Sopenharmony_ci
1216141cc406Sopenharmony_ci		/* direct is done here without copying...*/
1217141cc406Sopenharmony_ci    	if( fnDataDirect != ps->Scan.DataProcess ) {
1218141cc406Sopenharmony_ci			(*ps->Scan.DataProcess)(ps, (pVoid)(ps->Scan.bp.pMonoBuf ),
1219141cc406Sopenharmony_ci                                        (pVoid)(ps->Scan.BufPut.red.bp),
1220141cc406Sopenharmony_ci                                        ps->DataInf.dwAppPhyBytesPerLine);
1221141cc406Sopenharmony_ci		}
1222141cc406Sopenharmony_ci    	return _TRUE;
1223141cc406Sopenharmony_ci    }
1224141cc406Sopenharmony_ci
1225141cc406Sopenharmony_ci    return _FALSE;
1226141cc406Sopenharmony_ci}
1227141cc406Sopenharmony_ci
1228141cc406Sopenharmony_ci/**
1229141cc406Sopenharmony_ci */
1230141cc406Sopenharmony_cistatic Bool imageP98003ReadOneImageLine( pScanData ps )
1231141cc406Sopenharmony_ci{
1232141cc406Sopenharmony_ci    Byte     b, state;
1233141cc406Sopenharmony_ci	TimerDef timer, t2;
1234141cc406Sopenharmony_ci
1235141cc406Sopenharmony_ci	MiscStartTimer( &timer, _LINE_TIMEOUT );
1236141cc406Sopenharmony_ci	MiscStartTimer( &t2, _SECOND*2 );
1237141cc406Sopenharmony_ci    do {
1238141cc406Sopenharmony_ci
1239141cc406Sopenharmony_ci        state = IOGetScanState( ps, _TRUE );
1240141cc406Sopenharmony_ci        ps->Scan.bNowScanState = (state & _SCANSTATE_MASK);
1241141cc406Sopenharmony_ci
1242141cc406Sopenharmony_ci    	if( state & _SCANSTATE_STOP ) {
1243141cc406Sopenharmony_ci
1244141cc406Sopenharmony_ci	        MotorP98003ModuleForwardBackward( ps );
1245141cc406Sopenharmony_ci
1246141cc406Sopenharmony_ci    	    if( IOReadFifoLength( ps ) >= ps->Scan.dwMinReadFifo )
1247141cc406Sopenharmony_ci	        	if( imageP98003DataIsReady( ps ))
1248141cc406Sopenharmony_ci		            return _TRUE;
1249141cc406Sopenharmony_ci    	} else {
1250141cc406Sopenharmony_ci
1251141cc406Sopenharmony_ci    	    ps->Scan.bModuleState = _MotorInNormalState;
1252141cc406Sopenharmony_ci    	    b = ps->Scan.bNowScanState - ps->Scan.bOldScanState;
1253141cc406Sopenharmony_ci
1254141cc406Sopenharmony_ci    	    if((char) b < 0)
1255141cc406Sopenharmony_ci        		b += _NUMBER_OF_SCANSTEPS;
1256141cc406Sopenharmony_ci
1257141cc406Sopenharmony_ci    	    if( b >= ps->Scan.bRefresh ) {
1258141cc406Sopenharmony_ci        		IORegisterToScanner( ps, ps->RegRefreshScanState );
1259141cc406Sopenharmony_ci
1260141cc406Sopenharmony_ci                ps->Scan.bOldScanState = IOGetScanState( ps, _TRUE );
1261141cc406Sopenharmony_ci                ps->Scan.bOldScanState &= _SCANSTATE_MASK;
1262141cc406Sopenharmony_ci    	    }
1263141cc406Sopenharmony_ci
1264141cc406Sopenharmony_ci	        if( IOReadFifoLength( ps ) >= ps->Scan.dwMaxReadFifo ) {
1265141cc406Sopenharmony_ci            	if( imageP98003DataIsReady( ps ))
1266141cc406Sopenharmony_ci	                return _TRUE;
1267141cc406Sopenharmony_ci    	    } else {
1268141cc406Sopenharmony_ci
1269141cc406Sopenharmony_ci        	    b = ps->Scan.bNowScanState - ps->Scan.bOldScanState;
1270141cc406Sopenharmony_ci
1271141cc406Sopenharmony_ci    	        if((char) b < 0)
1272141cc406Sopenharmony_ci        	    	b += _NUMBER_OF_SCANSTEPS;
1273141cc406Sopenharmony_ci
1274141cc406Sopenharmony_ci        	    if( b >= ps->Scan.bRefresh ) {
1275141cc406Sopenharmony_ci            		IORegisterToScanner( ps, ps->RegRefreshScanState );
1276141cc406Sopenharmony_ci
1277141cc406Sopenharmony_ci                    ps->Scan.bOldScanState = IOGetScanState( ps, _TRUE );
1278141cc406Sopenharmony_ci                    ps->Scan.bOldScanState &= _SCANSTATE_MASK;
1279141cc406Sopenharmony_ci        	    }
1280141cc406Sopenharmony_ci
1281141cc406Sopenharmony_ci        	    if( IOReadFifoLength( ps ) >= ps->Scan.dwMinReadFifo ) {
1282141cc406Sopenharmony_ci                	if( imageP98003DataIsReady( ps ))
1283141cc406Sopenharmony_ci	                    return _TRUE;
1284141cc406Sopenharmony_ci                }
1285141cc406Sopenharmony_ci        	}
1286141cc406Sopenharmony_ci        }
1287141cc406Sopenharmony_ci		_DODELAY(5);			     /* delay 5 ms */
1288141cc406Sopenharmony_ci
1289141cc406Sopenharmony_ci    } while( !MiscCheckTimer( &timer ));
1290141cc406Sopenharmony_ci
1291141cc406Sopenharmony_ci	DBG( DBG_HIGH,
1292141cc406Sopenharmony_ci	"Timeout - Scanner malfunction !!\n" );
1293141cc406Sopenharmony_ci	MotorToHomePosition(ps);
1294141cc406Sopenharmony_ci
1295141cc406Sopenharmony_ci	/* timed out, scanner malfunction */
1296141cc406Sopenharmony_ci    return _FALSE;
1297141cc406Sopenharmony_ci}
1298141cc406Sopenharmony_ci
1299141cc406Sopenharmony_ci/**
1300141cc406Sopenharmony_ci */
1301141cc406Sopenharmony_cistatic void imageP98003SetupScanStateVariables( pScanData ps, ULong index )
1302141cc406Sopenharmony_ci{
1303141cc406Sopenharmony_ci    DataType var;
1304141cc406Sopenharmony_ci
1305141cc406Sopenharmony_ci    ps->Scan.dpiIdx = index;
1306141cc406Sopenharmony_ci
1307141cc406Sopenharmony_ci    if(!(ps->DataInf.dwScanFlag & SCANDEF_TPA)) {
1308141cc406Sopenharmony_ci
1309141cc406Sopenharmony_ci        if(((ps->IO.portMode == _PORT_BIDI) ||
1310141cc406Sopenharmony_ci            (ps->IO.portMode == _PORT_SPP)) &&
1311141cc406Sopenharmony_ci            (ps->DataInf.wPhyDataType > COLOR_TRUE24) &&
1312141cc406Sopenharmony_ci                                             (ps->DataInf.xyAppDpi.y >= 600)) {
1313141cc406Sopenharmony_ci
1314141cc406Sopenharmony_ci       		ps->Shade.wExposure = nmlScan[ps->IO.portMode][index].exposureTime;
1315141cc406Sopenharmony_ci	        ps->Shade.wXStep    = nmlScan[ps->IO.portMode][index].xStepTime;
1316141cc406Sopenharmony_ci   	    } else {
1317141cc406Sopenharmony_ci		    ps->Shade.wExposure = nmlScan[_PORT_EPP][index].exposureTime;
1318141cc406Sopenharmony_ci    		ps->Shade.wXStep    = nmlScan[_PORT_EPP][index].xStepTime;
1319141cc406Sopenharmony_ci	    }
1320141cc406Sopenharmony_ci
1321141cc406Sopenharmony_ci	    if( ps->Shade.bIntermediate & _ScanMode_AverageOut ) {
1322141cc406Sopenharmony_ci    	    ps->Shade.wExposure >>= 1;
1323141cc406Sopenharmony_ci	        ps->Shade.wXStep    >>= 1;
1324141cc406Sopenharmony_ci    	}
1325141cc406Sopenharmony_ci    } else {
1326141cc406Sopenharmony_ci    	if( ps->DataInf.dwScanFlag & SCANDEF_Transparency ) {
1327141cc406Sopenharmony_ci    	    ps->Shade.wExposure = posScan[index].exposureTime;
1328141cc406Sopenharmony_ci	        ps->Shade.wXStep    = posScan[index].xStepTime;
1329141cc406Sopenharmony_ci    	} else {
1330141cc406Sopenharmony_ci    	    ps->Shade.wExposure = ps->Scan.negScan[index].exposureTime;
1331141cc406Sopenharmony_ci	        ps->Shade.wXStep    = ps->Scan.negScan[index].xStepTime;
1332141cc406Sopenharmony_ci    	}
1333141cc406Sopenharmony_ci    }
1334141cc406Sopenharmony_ci
1335141cc406Sopenharmony_ci    ps->Scan.dwInterlace = 0;
1336141cc406Sopenharmony_ci    ps->Scan.dwInterval  = 1;
1337141cc406Sopenharmony_ci
1338141cc406Sopenharmony_ci    if( ps->DataInf.wPhyDataType == COLOR_BW )
1339141cc406Sopenharmony_ci	    var.dwValue = xferSpeed[ps->IO.portMode].thresholdBW;
1340141cc406Sopenharmony_ci	else {
1341141cc406Sopenharmony_ci        if( ps->DataInf.wPhyDataType == COLOR_256GRAY )
1342141cc406Sopenharmony_ci    		var.dwValue = xferSpeed[ps->IO.portMode].thresholdGray;
1343141cc406Sopenharmony_ci	    else
1344141cc406Sopenharmony_ci		    var.dwValue = xferSpeed[ps->IO.portMode].thresholdColor;
1345141cc406Sopenharmony_ci    }
1346141cc406Sopenharmony_ci
1347141cc406Sopenharmony_ci    /* for small size/descreen */
1348141cc406Sopenharmony_ci    if((ps->DataInf.xyAppDpi.y >= 300) && var.dwValue &&
1349141cc406Sopenharmony_ci       (ps->DataInf.dwAsicBytesPerPlane <= var.dwValue)) {
1350141cc406Sopenharmony_ci    	ps->Scan.dwInterval <<= 1;
1351141cc406Sopenharmony_ci    }
1352141cc406Sopenharmony_ci
1353141cc406Sopenharmony_ci    if( var.dwValue && ps->DataInf.dwAsicBytesPerPlane > var.dwValue ) {
1354141cc406Sopenharmony_ci    	if((var.dwValue << 1) > ps->DataInf.dwAsicBytesPerPlane)
1355141cc406Sopenharmony_ci	        ps->Scan.dwInterval <<= 1;
1356141cc406Sopenharmony_ci    	else
1357141cc406Sopenharmony_ci        	if((var.dwValue << 2) > ps->DataInf.dwAsicBytesPerPlane)
1358141cc406Sopenharmony_ci		        ps->Scan.dwInterval <<= 2;
1359141cc406Sopenharmony_ci    	    else
1360141cc406Sopenharmony_ci	        	ps->Scan.dwInterval <<= 3;
1361141cc406Sopenharmony_ci    }
1362141cc406Sopenharmony_ci
1363141cc406Sopenharmony_ci    /* 48 bit/600 dpi/Bpp mode will scan failed */
1364141cc406Sopenharmony_ci    if(((ps->IO.portMode == _PORT_BIDI) ||
1365141cc406Sopenharmony_ci        (ps->IO.portMode == _PORT_SPP)) &&
1366141cc406Sopenharmony_ci        (ps->DataInf.wPhyDataType > COLOR_TRUE24) &&
1367141cc406Sopenharmony_ci                                             (ps->DataInf.xyAppDpi.y >= 600)) {
1368141cc406Sopenharmony_ci    	ps->Scan.dwInterval <<= 1;
1369141cc406Sopenharmony_ci    }
1370141cc406Sopenharmony_ci
1371141cc406Sopenharmony_ci    if( ps->DataInf.wPhyDataType >= COLOR_TRUE24 ) {
1372141cc406Sopenharmony_ci
1373141cc406Sopenharmony_ci    	if( ps->DataInf.xyPhyDpi.y > 75U ) {
1374141cc406Sopenharmony_ci    	    if( ps->Device.f0_8_16 ) {
1375141cc406Sopenharmony_ci	        	ps->Scan.gd_gk.wGreenDiscard = ps->DataInf.xyPhyDpi.y / 75U;
1376141cc406Sopenharmony_ci    	    } else {
1377141cc406Sopenharmony_ci	        	ps->Scan.gd_gk.wGreenDiscard = ps->DataInf.xyPhyDpi.y / 150U;
1378141cc406Sopenharmony_ci	        }
1379141cc406Sopenharmony_ci    	} else {
1380141cc406Sopenharmony_ci           	ps->Scan.gd_gk.wGreenDiscard = 1;
1381141cc406Sopenharmony_ci		}
1382141cc406Sopenharmony_ci
1383141cc406Sopenharmony_ci       	ps->Scan.bd_rk.wBlueDiscard = ps->Scan.gd_gk.wGreenDiscard << 1;
1384141cc406Sopenharmony_ci    } else {
1385141cc406Sopenharmony_ci       	ps->Scan.bd_rk.wBlueDiscard = ps->Scan.gd_gk.wGreenDiscard = 0;
1386141cc406Sopenharmony_ci    }
1387141cc406Sopenharmony_ci}
1388141cc406Sopenharmony_ci
1389141cc406Sopenharmony_ci/** PrepareScanningVariables() !!!
1390141cc406Sopenharmony_ci */
1391141cc406Sopenharmony_cistatic int imageP98003SetupScanSettings( pScanData ps, pScanInfo pInf )
1392141cc406Sopenharmony_ci{
1393141cc406Sopenharmony_ci	DBG( DBG_LOW, "imageP98003SetupScanSettings()\n" );
1394141cc406Sopenharmony_ci
1395141cc406Sopenharmony_ci    /* call the one for ASIC 98001 first */
1396141cc406Sopenharmony_ci    imageP98SetupScanSettings( ps, pInf );
1397141cc406Sopenharmony_ci
1398141cc406Sopenharmony_ci    if( !(ps->DataInf.dwScanFlag & SCANDEF_TPA )) {
1399141cc406Sopenharmony_ci
1400141cc406Sopenharmony_ci        ps->Scan.dwScanOrigin = ps->Device.lUpNormal * 4 + _RFT_SCANNING_ORG;
1401141cc406Sopenharmony_ci
1402141cc406Sopenharmony_ci    } else if( ps->DataInf.dwScanFlag & SCANDEF_Transparency) {
1403141cc406Sopenharmony_ci
1404141cc406Sopenharmony_ci	    ps->Scan.dwScanOrigin = ps->Device.lUpPositive * 4 +
1405141cc406Sopenharmony_ci            							   _POS_SCANNING_ORG;
1406141cc406Sopenharmony_ci	} else {
1407141cc406Sopenharmony_ci	    ps->Scan.dwScanOrigin = ps->Device.lUpNegative * 4 +
1408141cc406Sopenharmony_ci            							   _NEG_SCANNING_ORG;
1409141cc406Sopenharmony_ci    }
1410141cc406Sopenharmony_ci    ps->Scan.dwScanOrigin += ps->Device.dwModelOriginY;
1411141cc406Sopenharmony_ci
1412141cc406Sopenharmony_ci    /* ------- Setup CCD Offset variables ------- */
1413141cc406Sopenharmony_ci    if( ps->DataInf.xyAppDpi.y <= 75 ) {
1414141cc406Sopenharmony_ci
1415141cc406Sopenharmony_ci    	if( ps->DataInf.dwVxdFlag & _VF_PREVIEW ) {
1416141cc406Sopenharmony_ci
1417141cc406Sopenharmony_ci            ps->Scan.bDiscardAll   = 0;
1418141cc406Sopenharmony_ci    	    ps->DataInf.xyPhyDpi.y = 150;
1419141cc406Sopenharmony_ci            ps->Shade.bIntermediate |= _ScanMode_AverageOut;
1420141cc406Sopenharmony_ci    	    imageP98003SetupScanStateVariables( ps, 1 );
1421141cc406Sopenharmony_ci	        ps->Scan.gd_gk.wGreenDiscard = 0;
1422141cc406Sopenharmony_ci
1423141cc406Sopenharmony_ci	        if( ps->DataInf.xyAppDpi.y >= 38 )
1424141cc406Sopenharmony_ci        		ps->Scan.bd_rk.wBlueDiscard = 1;
1425141cc406Sopenharmony_ci	        else
1426141cc406Sopenharmony_ci        		ps->Scan.bd_rk.wBlueDiscard = 0;
1427141cc406Sopenharmony_ci
1428141cc406Sopenharmony_ci	        if( ps->DataInf.wPhyDataType >= COLOR_256GRAY ) {
1429141cc406Sopenharmony_ci        		ps->Shade.wXStep    = 6;
1430141cc406Sopenharmony_ci		        ps->Shade.wExposure = 8 * ps->Shade.wXStep;
1431141cc406Sopenharmony_ci    	    }
1432141cc406Sopenharmony_ci	    } else {
1433141cc406Sopenharmony_ci    	    if(!(ps->DataInf.dwScanFlag & SCANDEF_TPA) &&
1434141cc406Sopenharmony_ci                (ps->DataInf.xyAppDpi.y <= 50) &&
1435141cc406Sopenharmony_ci				(ps->DataInf.wPhyDataType >= COLOR_TRUE24)) {
1436141cc406Sopenharmony_ci        		ps->Shade.bIntermediate |= _ScanMode_AverageOut;
1437141cc406Sopenharmony_ci            }
1438141cc406Sopenharmony_ci
1439141cc406Sopenharmony_ci    	    if((ps->DataInf.wPhyDataType<COLOR_TRUE24) || ps->Device.f0_8_16 ||
1440141cc406Sopenharmony_ci           			         (ps->Shade.bIntermediate & _ScanMode_AverageOut)) {
1441141cc406Sopenharmony_ci
1442141cc406Sopenharmony_ci        		ps->Scan.bDiscardAll   = 1;
1443141cc406Sopenharmony_ci        		ps->DataInf.xyPhyDpi.y = 75;
1444141cc406Sopenharmony_ci		        imageP98003SetupScanStateVariables( ps, 0 );
1445141cc406Sopenharmony_ci    	    } else {
1446141cc406Sopenharmony_ci        		ps->Scan.bDiscardAll   = 2;
1447141cc406Sopenharmony_ci        		ps->DataInf.xyPhyDpi.y = 150;
1448141cc406Sopenharmony_ci		        imageP98003SetupScanStateVariables( ps, 1 );
1449141cc406Sopenharmony_ci    	    }
1450141cc406Sopenharmony_ci    	}
1451141cc406Sopenharmony_ci    } else {
1452141cc406Sopenharmony_ci    	if( ps->DataInf.xyAppDpi.y <= 150 ) {
1453141cc406Sopenharmony_ci
1454141cc406Sopenharmony_ci    	    ps->Scan.bDiscardAll   = 2;
1455141cc406Sopenharmony_ci	        ps->DataInf.xyPhyDpi.y = 150;
1456141cc406Sopenharmony_ci	        imageP98003SetupScanStateVariables( ps, 1 );
1457141cc406Sopenharmony_ci
1458141cc406Sopenharmony_ci    	} else if( ps->DataInf.xyAppDpi.y <= 300 ) {
1459141cc406Sopenharmony_ci
1460141cc406Sopenharmony_ci    	    ps->Scan.bDiscardAll   = 4;
1461141cc406Sopenharmony_ci	        ps->DataInf.xyPhyDpi.y = 300;
1462141cc406Sopenharmony_ci	        imageP98003SetupScanStateVariables( ps, 2 );
1463141cc406Sopenharmony_ci
1464141cc406Sopenharmony_ci	    } else if( ps->DataInf.xyAppDpi.y <= 600 ) {
1465141cc406Sopenharmony_ci
1466141cc406Sopenharmony_ci    	    ps->Scan.bDiscardAll   = 8;
1467141cc406Sopenharmony_ci	        ps->DataInf.xyPhyDpi.y = 600;
1468141cc406Sopenharmony_ci            imageP98003SetupScanStateVariables( ps, 3 );
1469141cc406Sopenharmony_ci
1470141cc406Sopenharmony_ci		} else {
1471141cc406Sopenharmony_ci
1472141cc406Sopenharmony_ci    	    ps->Scan.bDiscardAll   = 16;
1473141cc406Sopenharmony_ci	        ps->DataInf.xyPhyDpi.y = 1200;
1474141cc406Sopenharmony_ci	        imageP98003SetupScanStateVariables( ps, 4 );
1475141cc406Sopenharmony_ci		}
1476141cc406Sopenharmony_ci    }
1477141cc406Sopenharmony_ci
1478141cc406Sopenharmony_ci    /* ------- Lines have to sample or not? ------- */
1479141cc406Sopenharmony_ci    if( ps->DataInf.xyAppDpi.y == ps->DataInf.xyPhyDpi.y ) {
1480141cc406Sopenharmony_ci		DBG( DBG_LOW, "Sample every line\n" );
1481141cc406Sopenharmony_ci    	ps->Scan.DoSample = fnEveryLines;
1482141cc406Sopenharmony_ci    } else {
1483141cc406Sopenharmony_ci    	if( ps->DataInf.dwVxdFlag & _VF_PREVIEW ) {
1484141cc406Sopenharmony_ci
1485141cc406Sopenharmony_ci			DBG( DBG_LOW, "Sample preview\n" );
1486141cc406Sopenharmony_ci            ps->Scan.DoSample = fnSamplePreview;
1487141cc406Sopenharmony_ci	        ps->DataInf.wYSum = 150;
1488141cc406Sopenharmony_ci
1489141cc406Sopenharmony_ci	        if( ps->DataInf.xyAppDpi.y >= 38 )
1490141cc406Sopenharmony_ci        		wPreviewScanned = ps->DataInf.xyAppDpi.y * 2;
1491141cc406Sopenharmony_ci    	    else if( ps->DataInf.xyAppDpi.y >= 19 )
1492141cc406Sopenharmony_ci		            wPreviewScanned = ps->DataInf.xyAppDpi.y * 4;
1493141cc406Sopenharmony_ci        		else
1494141cc406Sopenharmony_ci            		wPreviewScanned = ps->DataInf.xyAppDpi.y * 8;
1495141cc406Sopenharmony_ci    	} else {
1496141cc406Sopenharmony_ci
1497141cc406Sopenharmony_ci			DBG( DBG_LOW, "Sample lines (%u - %u)...\n",
1498141cc406Sopenharmony_ci						  ps->DataInf.xyPhyDpi.y, ps->DataInf.xyAppDpi.y );
1499141cc406Sopenharmony_ci            ps->Scan.DoSample = fnSampleLines;
1500141cc406Sopenharmony_ci	        ps->DataInf.wYSum = ps->DataInf.xyPhyDpi.y - ps->DataInf.xyAppDpi.y;
1501141cc406Sopenharmony_ci    	}
1502141cc406Sopenharmony_ci    }
1503141cc406Sopenharmony_ci
1504141cc406Sopenharmony_ci    /*
1505141cc406Sopenharmony_ci     * now assign the buffer pointers for image acquisition
1506141cc406Sopenharmony_ci     */
1507141cc406Sopenharmony_ci	ps->Scan.p48BitBuf.pb = NULL;
1508141cc406Sopenharmony_ci
1509141cc406Sopenharmony_ci    if( ps->DataInf.wPhyDataType >= COLOR_TRUE24 ) {
1510141cc406Sopenharmony_ci
1511141cc406Sopenharmony_ci        ULong r,g,b;
1512141cc406Sopenharmony_ci
1513141cc406Sopenharmony_ci        r = (ULong)_SIZE_REDFIFO /
1514141cc406Sopenharmony_ci			ps->DataInf.dwAsicBytesPerPlane - ps->Scan.bd_rk.wRedKeep;
1515141cc406Sopenharmony_ci        g = (ULong)_SIZE_GREENFIFO /
1516141cc406Sopenharmony_ci			ps->DataInf.dwAsicBytesPerPlane - ps->Scan.gd_gk.wGreenKeep;
1517141cc406Sopenharmony_ci
1518141cc406Sopenharmony_ci    	if((int)r < 16 || (int)g < 16) {
1519141cc406Sopenharmony_ci
1520141cc406Sopenharmony_ci    	    b = (ULong)(ps->Scan.bd_rk.wRedKeep +
1521141cc406Sopenharmony_ci						ps->Scan.gd_gk.wGreenKeep + 2U) *
1522141cc406Sopenharmony_ci			            ps->DataInf.dwAsicBytesPerPlane;
1523141cc406Sopenharmony_ci
1524141cc406Sopenharmony_ci			DBG( DBG_LOW, "48Bit buffer request: len=%u bytes, available=%u\n",
1525141cc406Sopenharmony_ci						  b, ps->TotalBufferRequire );
1526141cc406Sopenharmony_ci
1527141cc406Sopenharmony_ci			if( b > ps->TotalBufferRequire )
1528141cc406Sopenharmony_ci				return _E_NORESOURCE;
1529141cc406Sopenharmony_ci
1530141cc406Sopenharmony_ci			ps->Scan.p48BitBuf.pb = ps->Bufs.b1.pReadBuf;
1531141cc406Sopenharmony_ci		}
1532141cc406Sopenharmony_ci    }
1533141cc406Sopenharmony_ci
1534141cc406Sopenharmony_ci    if( ps->Scan.p48BitBuf.pb ){
1535141cc406Sopenharmony_ci    	ps->Scan.DataRead          = fnReadToDriver;
1536141cc406Sopenharmony_ci	    ps->Scan.BufGet.red.bp     =
1537141cc406Sopenharmony_ci    	ps->Scan.BufPut.red.bp     =
1538141cc406Sopenharmony_ci	    ps->Scan.BufBegin.red.bp   = ps->Scan.p48BitBuf.pb;
1539141cc406Sopenharmony_ci    	ps->Scan.BufEnd.red.bp     =
1540141cc406Sopenharmony_ci	    ps->Scan.BufBegin.green.bp =
1541141cc406Sopenharmony_ci    	ps->Scan.BufGet.green.bp   =
1542141cc406Sopenharmony_ci	    ps->Scan.BufPut.green.bp   = ps->Scan.p48BitBuf.pb +
1543141cc406Sopenharmony_ci	                			     ps->DataInf.dwAsicBytesPerLine *
1544141cc406Sopenharmony_ci                                     (ps->Scan.bd_rk.wRedKeep + 1U);
1545141cc406Sopenharmony_ci
1546141cc406Sopenharmony_ci    	ps->Scan.BufEnd.green.bp = ps->Scan.BufBegin.green.bp +
1547141cc406Sopenharmony_ci	                			   ps->DataInf.dwAsicBytesPerLine *
1548141cc406Sopenharmony_ci                				   (ps->Scan.gd_gk.wGreenKeep + 1U);
1549141cc406Sopenharmony_ci        ps->Scan.BufPut.blue.bp =
1550141cc406Sopenharmony_ci    	ps->Scan.BufGet.blue.bp = ps->Bufs.b1.pReadBuf +
1551141cc406Sopenharmony_ci                                  ps->DataInf.dwAsicBytesPerLine * 2;
1552141cc406Sopenharmony_ci    } else {
1553141cc406Sopenharmony_ci    	ps->Scan.DataRead         = fnReadOutScanner;
1554141cc406Sopenharmony_ci    	ps->Scan.BufPut.red.bp    = ps->Bufs.b1.pReadBuf;
1555141cc406Sopenharmony_ci    	ps->Scan.BufData.green.bp =
1556141cc406Sopenharmony_ci	    ps->Scan.BufPut.green.bp  = ps->Scan.BufPut.red.bp +
1557141cc406Sopenharmony_ci                			        ps->DataInf.dwAsicBytesPerLine;
1558141cc406Sopenharmony_ci    	ps->Scan.BufPut.blue.bp   = ps->Scan.BufPut.green.bp +
1559141cc406Sopenharmony_ci                			        ps->DataInf.dwAsicBytesPerLine;
1560141cc406Sopenharmony_ci
1561141cc406Sopenharmony_ci        if( ps->DataInf.dwScanFlag & SCANDEF_ColorBGROrder ) {
1562141cc406Sopenharmony_ci    	    ps->Scan.BufData.red.bp  = ps->Scan.BufPut.blue.bp;
1563141cc406Sopenharmony_ci	        ps->Scan.BufData.blue.bp = ps->Scan.BufPut.red.bp;
1564141cc406Sopenharmony_ci    	} else {
1565141cc406Sopenharmony_ci    	    ps->Scan.BufData.red.bp  = ps->Scan.BufPut.red.bp;
1566141cc406Sopenharmony_ci	        ps->Scan.BufData.blue.bp = ps->Scan.BufPut.blue.bp;
1567141cc406Sopenharmony_ci    	}
1568141cc406Sopenharmony_ci    }
1569141cc406Sopenharmony_ci
1570141cc406Sopenharmony_ci/* CHECK: maybe remove this stuff */
1571141cc406Sopenharmony_ci	if( ps->DataInf.dwScanFlag & SCANDEF_Transparency) {
1572141cc406Sopenharmony_ci	    posScan[1].exposureTime = 96;
1573141cc406Sopenharmony_ci	    posScan[1].xStepTime    = 12;
1574141cc406Sopenharmony_ci	    posScan[2].exposureTime = 96;
1575141cc406Sopenharmony_ci	    posScan[2].xStepTime    = 24;
1576141cc406Sopenharmony_ci	    posScan[3].exposureTime = 96;
1577141cc406Sopenharmony_ci	    posScan[3].xStepTime    = 48;
1578141cc406Sopenharmony_ci	    posScan[4].exposureTime = 96;
1579141cc406Sopenharmony_ci	    posScan[4].xStepTime    = 96;
1580141cc406Sopenharmony_ci
1581141cc406Sopenharmony_ci	    /* Reset shading Exposure Time & xStep Time */
1582141cc406Sopenharmony_ci	    ps->Shade.wExposure = posScan[ps->Scan.dpiIdx].exposureTime;
1583141cc406Sopenharmony_ci	    ps->Shade.wXStep    = posScan[ps->Scan.dpiIdx].xStepTime;
1584141cc406Sopenharmony_ci	}
1585141cc406Sopenharmony_ci	else if( ps->DataInf.dwScanFlag & SCANDEF_Negative) {
1586141cc406Sopenharmony_ci        ps->Scan.negScan[1].exposureTime = 96;
1587141cc406Sopenharmony_ci        ps->Scan.negScan[1].xStepTime    = 12;
1588141cc406Sopenharmony_ci        ps->Scan.negScan[2].exposureTime = 96;
1589141cc406Sopenharmony_ci        ps->Scan.negScan[2].xStepTime    = 24;
1590141cc406Sopenharmony_ci        ps->Scan.negScan[3].exposureTime = 96;
1591141cc406Sopenharmony_ci        ps->Scan.negScan[3].xStepTime    = 48;
1592141cc406Sopenharmony_ci        ps->Scan.negScan[4].exposureTime = 96;
1593141cc406Sopenharmony_ci        ps->Scan.negScan[4].xStepTime    = 96;
1594141cc406Sopenharmony_ci
1595141cc406Sopenharmony_ci	    /* Reset shading Exposure Time & xStep Time */
1596141cc406Sopenharmony_ci    	ps->Shade.wExposure = ps->Scan.negScan[ps->Scan.dpiIdx].exposureTime;
1597141cc406Sopenharmony_ci		ps->Shade.wXStep    = ps->Scan.negScan[ps->Scan.dpiIdx].xStepTime;
1598141cc406Sopenharmony_ci    }
1599141cc406Sopenharmony_ci
1600141cc406Sopenharmony_ci	return _OK;
1601141cc406Sopenharmony_ci}
1602141cc406Sopenharmony_ci
1603141cc406Sopenharmony_ci/************************ exported functions *********************************/
1604141cc406Sopenharmony_ci
1605141cc406Sopenharmony_ci/**
1606141cc406Sopenharmony_ci */
1607141cc406Sopenharmony_ci_LOC int ImageInitialize( pScanData ps )
1608141cc406Sopenharmony_ci{
1609141cc406Sopenharmony_ci	DBG( DBG_HIGH, "ImageInitialize()\n" );
1610141cc406Sopenharmony_ci
1611141cc406Sopenharmony_ci	if( NULL == ps )
1612141cc406Sopenharmony_ci		return _E_NULLPTR;
1613141cc406Sopenharmony_ci
1614141cc406Sopenharmony_ci    ps->Scan.dpiIdx  = 0;
1615141cc406Sopenharmony_ci    ps->Scan.negScan = negScan;
1616141cc406Sopenharmony_ci
1617141cc406Sopenharmony_ci	/*
1618141cc406Sopenharmony_ci	 * depending on the asic, we set some functions
1619141cc406Sopenharmony_ci	 */
1620141cc406Sopenharmony_ci	if( _ASIC_IS_98001 == ps->sCaps.AsicID ) {
1621141cc406Sopenharmony_ci
1622141cc406Sopenharmony_ci		ps->GetImageInfo 	  = imageP98GetInfo;
1623141cc406Sopenharmony_ci		ps->SetupScanSettings = imageP98SetupScanSettings;
1624141cc406Sopenharmony_ci		ps->ReadOneImageLine  = imageP98001ReadOneImageLine;
1625141cc406Sopenharmony_ci
1626141cc406Sopenharmony_ci    } else if( _ASIC_IS_98003 == ps->sCaps.AsicID ) {
1627141cc406Sopenharmony_ci
1628141cc406Sopenharmony_ci		ps->GetImageInfo 	  = imageP98GetInfo;
1629141cc406Sopenharmony_ci		ps->SetupScanSettings = imageP98003SetupScanSettings;
1630141cc406Sopenharmony_ci		ps->ReadOneImageLine  = imageP98003ReadOneImageLine;
1631141cc406Sopenharmony_ci
1632141cc406Sopenharmony_ci	} else if( _IS_ASIC96(ps->sCaps.AsicID)) {
1633141cc406Sopenharmony_ci
1634141cc406Sopenharmony_ci		ps->GetImageInfo 	  = imageP96GetInfo;
1635141cc406Sopenharmony_ci		ps->SetupScanSettings = imageP96SetupScanSettings;
1636141cc406Sopenharmony_ci		ps->ReadOneImageLine  = imageP96ReadOneImageLine;
1637141cc406Sopenharmony_ci
1638141cc406Sopenharmony_ci	} else {
1639141cc406Sopenharmony_ci
1640141cc406Sopenharmony_ci		DBG( DBG_HIGH , "NOT SUPPORTED ASIC !!!\n" );
1641141cc406Sopenharmony_ci		return _E_NOSUPP;
1642141cc406Sopenharmony_ci	}
1643141cc406Sopenharmony_ci	return _OK;
1644141cc406Sopenharmony_ci}
1645141cc406Sopenharmony_ci
1646141cc406Sopenharmony_ci/* END PLUSTEK-PP_IMAGE.C ...................................................*/
1647