• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2   Copyright (C) 2001 Bertrik Sikken (bertrik@zonnet.nl)
3 
4   This program is free software; you can redistribute it and/or
5   modify it under the terms of the GNU General Public License
6   as published by the Free Software Foundation; either version 2
7   of the License, or (at your option) any later version.
8 
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   GNU General Public License for more details.
13 
14   You should have received a copy of the GNU General Public License
15   along with this program.  If not, see <https://www.gnu.org/licenses/>.
16 */
17 
18 /*
19     Core NIASH chip functions.
20 */
21 
22 
23 #ifndef _NIASH_CORE_H_
24 #define _NIASH_CORE_H_
25 
26 #include <unistd.h>
27 
28 #include "niash_xfer.h"		/* for EScannerModel */
29 
30 #define HP3300C_RIGHT  330
31 #define HP3300C_TOP    452
32 #define HP3300C_BOTTOM (HP3300C_TOP + 14200UL)
33 
34 #define HW_PIXELS   5300	/* number of pixels supported by hardware */
35 #define HW_DPI      600		/* horizontal resolution of hardware */
36 #define HW_LPI      1200	/* vertical resolution of hardware */
37 
38 #define BYTES_PER_PIXEL 3
39 
40 typedef struct
41 {
42   int iXferHandle;		/* handle used for data transfer to HW */
43   int iTopLeftX;		/* in mm */
44   int iTopLeftY;		/* in mm */
45   int iSensorSkew;		/* in units of 1/1200 inch */
46   int iSkipLines;		/* lines of garbage to skip */
47   SANE_Bool fReg07;		/* NIASH00019 */
48   SANE_Bool fGamma16;		/* if TRUE, gamma entries are 16 bit */
49   int iExpTime;
50   SANE_Bool iReversedHead;	/* Head is reversed */
51   int iBufferSize;		/* Size of internal scan buffer */
52   EScannerModel eModel;
53 } THWParams;
54 
55 
56 typedef struct
57 {
58   int iDpi;			/* horizontal resolution */
59   int iLpi;			/* vertical resolution */
60   int iTop;			/* in HW coordinates */
61   int iLeft;			/* in HW coordinates */
62   int iWidth;			/* pixels */
63   int iHeight;			/* lines */
64   int iBottom;
65 
66   int fCalib;			/* if TRUE, disable backtracking? */
67 } TScanParams;
68 
69 
70 typedef struct
71 {
72   unsigned char *pabXferBuf;	/* transfer buffer */
73   int iCurLine;			/* current line in the transfer buffer */
74   int iBytesPerLine;		/* unsigned chars in one scan line */
75   int iLinesPerXferBuf;		/* number of lines held in the transfer buffer */
76   int iLinesLeft;		/* transfer (down) counter for pabXFerBuf */
77   int iSaneBytesPerLine;	/* how many unsigned chars to be read by SANE per line */
78   int iScaleDownDpi;		/* factors used to emulate lower resolutions */
79   int iScaleDownLpi;		/* than those offered by hardware */
80   int iSkipLines;		/* line to skip at the start of scan */
81   int iWidth;			/* number of pixels expected by SANE */
82   unsigned char *pabCircBuf;	/* circular buffer */
83   int iLinesPerCircBuf;		/* lines held in the circular buffer */
84   int iRedLine, iGrnLine,	/* start indices for the color information */
85     iBluLine;			/* in the circular buffer */
86   unsigned char *pabLineBuf;	/* buffer used to pass data to SANE */
87 } TDataPipe;
88 
89 
90 STATIC int NiashOpen (THWParams * pHWParams, const char *pszName);
91 STATIC void NiashClose (THWParams * pHWParams);
92 
93 /* more sof. method that also returns the values of the white (RGB) value */
94 STATIC SANE_Bool SimpleCalibExt (THWParams * pHWPar,
95 				 unsigned char *pabCalibTable,
96 				 unsigned char *pabCalWhite);
97 
98 STATIC SANE_Bool GetLamp (THWParams * pHWParams, SANE_Bool * pfLampIsOn);
99 STATIC SANE_Bool SetLamp (THWParams * pHWParams, SANE_Bool fLampOn);
100 
101 STATIC SANE_Bool InitScan (TScanParams * pParams, THWParams * pHWParams);
102 STATIC void FinishScan (THWParams * pHWParams);
103 
104 STATIC void CalcGamma (unsigned char *pabTable, double Gamma);
105 STATIC void WriteGammaCalibTable (unsigned char *pabGammaR,
106 				  unsigned char *pabGammaG,
107 				  unsigned char *pabGammaB,
108 				  unsigned char *pabCalibTable, int iGain,
109 				  int iOffset, THWParams * pHWPar);
110 
111 /* set -1 for iHeight to disable all checks on buffer transfers */
112 /* iWidth is in pixels of SANE */
113 /* iHeight is lines in scanner resolution */
114 STATIC void CircBufferInit (int iHandle, TDataPipe * p,
115 			    int iWidth, int iHeight,
116 			    int iMisAlignment, SANE_Bool iReversedHead,
117 			    int iScaleDownDpi, int iScaleDownLpi);
118 
119 /* returns false, when trying to read after end of buffer */
120 STATIC SANE_Bool CircBufferGetLine (int iHandle, TDataPipe * p,
121 				    unsigned char *pabLine,
122 				    SANE_Bool iReversedHead);
123 
124 /* returns false, when trying to read after end of buffer
125    if fReturn==SANE_TRUE, the head will return automatically on an end of scan */
126 
127 STATIC SANE_Bool
128 CircBufferGetLineEx (int iHandle, TDataPipe * p, unsigned char *pabLine,
129 		     SANE_Bool iReversedHead, SANE_Bool fReturn);
130 
131 STATIC void CircBufferExit (TDataPipe * p);
132 
133 #endif /* _NIASH_CORE_H_ */
134