summaryrefslogtreecommitdiff
path: root/backend/niash_core.h
blob: fc0adbda4eae814187004c8569bf83ee7bebdb17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
  Copyright (C) 2001 Bertrik Sikken (bertrik@zonnet.nl)

  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version 2
  of the License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

  $Id$
*/

/*
    Core NIASH chip functions.
*/


#ifndef _NIASH_CORE_H_
#define _NIASH_CORE_H_

#include <unistd.h>

#include "niash_xfer.h"		/* for EScannerModel */

#define HP3300C_RIGHT  330
#define HP3300C_TOP    452
#define HP3300C_BOTTOM (HP3300C_TOP + 14200UL)

#define HW_PIXELS   5300	/* number of pixels supported by hardware */
#define HW_DPI      600		/* horizontal resolution of hardware */
#define HW_LPI      1200	/* vertical resolution of hardware */

#define BYTES_PER_PIXEL 3

typedef struct
{
  int iXferHandle;		/* handle used for data transfer to HW */
  int iTopLeftX;		/* in mm */
  int iTopLeftY;		/* in mm */
  int iSensorSkew;		/* in units of 1/1200 inch */
  int iSkipLines;		/* lines of garbage to skip */
  SANE_Bool fReg07;		/* NIASH00019 */
  SANE_Bool fGamma16;		/* if TRUE, gamma entries are 16 bit */
  int iExpTime;
  SANE_Bool iReversedHead;	/* Head is reversed */
  int iBufferSize;		/* Size of internal scan buffer */
  EScannerModel eModel;
} THWParams;


typedef struct
{
  int iDpi;			/* horizontal resolution */
  int iLpi;			/* vertical resolution */
  int iTop;			/* in HW coordinates */
  int iLeft;			/* in HW coordinates */
  int iWidth;			/* pixels */
  int iHeight;			/* lines */
  int iBottom;

  int fCalib;			/* if TRUE, disable backtracking? */
} TScanParams;


typedef struct
{
  unsigned char *pabXferBuf;	/* transfer buffer */
  int iCurLine;			/* current line in the transfer buffer */
  int iBytesPerLine;		/* unsigned chars in one scan line */
  int iLinesPerXferBuf;		/* number of lines held in the transfer buffer */
  int iLinesLeft;		/* transfer (down) counter for pabXFerBuf */
  int iSaneBytesPerLine;	/* how many unsigned chars to be read by SANE per line */
  int iScaleDownDpi;		/* factors used to emulate lower resolutions */
  int iScaleDownLpi;		/* than those offered by hardware */
  int iSkipLines;		/* line to skip at the start of scan */
  int iWidth;			/* number of pixels expected by SANE */
  unsigned char *pabCircBuf;	/* circular buffer */
  int iLinesPerCircBuf;		/* lines held in the circular buffer */
  int iRedLine, iGrnLine,	/* start indices for the color information */
    iBluLine;			/* in the circular buffer */
  unsigned char *pabLineBuf;	/* buffer used to pass data to SANE */
} TDataPipe;


STATIC int NiashOpen (THWParams * pHWParams, const char *pszName);
STATIC void NiashClose (THWParams * pHWParams);

/* more sof. method that also returns the values of the white (RGB) value */
STATIC SANE_Bool SimpleCalibExt (THWParams * pHWPar,
				 unsigned char *pabCalibTable,
				 unsigned char *pabCalWhite);

STATIC SANE_Bool GetLamp (THWParams * pHWParams, SANE_Bool * pfLampIsOn);
STATIC SANE_Bool SetLamp (THWParams * pHWParams, SANE_Bool fLampOn);

STATIC SANE_Bool InitScan (TScanParams * pParams, THWParams * pHWParams);
STATIC void FinishScan (THWParams * pHWParams);

STATIC void CalcGamma (unsigned char *pabTable, double Gamma);
STATIC void WriteGammaCalibTable (unsigned char *pabGammaR,
				  unsigned char *pabGammaG,
				  unsigned char *pabGammaB,
				  unsigned char *pabCalibTable, int iGain,
				  int iOffset, THWParams * pHWPar);

/* set -1 for iHeight to disable all checks on buffer transfers */
/* iWidth is in pixels of SANE */
/* iHeight is lines in scanner resolution */
STATIC void CircBufferInit (int iHandle, TDataPipe * p,
			    int iWidth, int iHeight,
			    int iMisAlignment, SANE_Bool iReversedHead,
			    int iScaleDownDpi, int iScaleDownLpi);

/* returns false, when trying to read after end of buffer */
STATIC SANE_Bool CircBufferGetLine (int iHandle, TDataPipe * p,
				    unsigned char *pabLine,
				    SANE_Bool iReversedHead);

/* returns false, when trying to read after end of buffer
   if fReturn==SANE_TRUE, the head will return automatically on an end of scan */

STATIC SANE_Bool
CircBufferGetLineEx (int iHandle, TDataPipe * p, unsigned char *pabLine,
		     SANE_Bool iReversedHead, SANE_Bool fReturn);

STATIC void CircBufferExit (TDataPipe * p);

#endif /* _NIASH_CORE_H_ */