1 #ifndef _HP5400_INTERNAL_H_ 2 #define _HP5400_INTERNAL_H_ 3 4 /* sane - Scanner Access Now Easy. 5 Copyright (C) 2020 Ralph Little <skelband@gmail.com> 6 (C) 2003 Thomas Soumarmon <thomas.soumarmon@cogitae.net> 7 (c) 2003 Martijn van Oosterhout, kleptog@svana.org 8 (c) 2002 Bertrik Sikken, bertrik@zonnet.nl 9 10 This file is part of the SANE package. 11 12 This program is free software; you can redistribute it and/or 13 modify it under the terms of the GNU General Public License as 14 published by the Free Software Foundation; either version 2 of the 15 License, or (at your option) any later version. 16 17 This program is distributed in the hope that it will be useful, but 18 WITHOUT ANY WARRANTY; without even the implied warranty of 19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 General Public License for more details. 21 22 You should have received a copy of the GNU General Public License 23 along with this program. If not, see <https://www.gnu.org/licenses/>. 24 25 As a special exception, the authors of SANE give permission for 26 additional uses of the libraries contained in this release of SANE. 27 28 The exception is that, if you link a SANE library with other files 29 to produce an executable, this does not by itself cause the 30 resulting executable to be covered by the GNU General Public 31 License. Your use of that executable is in no way restricted on 32 account of linking the SANE library code into it. 33 34 This exception does not, however, invalidate any other reasons why 35 the executable file might be covered by the GNU General Public 36 License. 37 38 If you submit changes to SANE to the maintainers to be included in 39 a subsequent release, you agree by submitting the changes that 40 those changes may be distributed with this exception intact. 41 42 If you write modifications of your own for SANE, it is your choice 43 whether to permit this exception to apply to your modifications. 44 If you do not wish that, delete this exception notice. 45 46 HP5400/5470 Test util. 47 Currently is only able to read back the scanner version string, 48 but this basically demonstrates ability to communicate with the scanner. 49 50 Massively expanded. Can do calibration scan, upload gamma and calibration 51 tables and stores the results of a scan. - 19/02/2003 Martijn 52 */ 53 54 #include "../include/_stdint.h" 55 56 #ifdef __GNUC__ 57 #define PACKED __attribute__ ((packed)) 58 #else 59 #define PACKED 60 #endif 61 62 /* If this is enabled, a copy of the raw data from the scanner will be saved to 63 imagedebug.dat and the attempted conversion to imagedebug.ppm */ 64 /* #define IMAGE_DEBUG */ 65 66 /* If this is defined you get extra info on the calibration */ 67 /* #define CALIB_DEBUG */ 68 69 #define CMD_GETVERSION 0x1200 70 #define CMD_GETUITEXT 0xf00b 71 #define CMD_GETCMDID 0xc500 72 #define CMD_SCANREQUEST 0x2505 /* This is for previews */ 73 #define CMD_SCANREQUEST2 0x2500 /* This is for real scans */ 74 #define CMD_SCANRESPONSE 0x3400 75 #define CMD_GETSENSORS 0x2000 76 #define CMD_READPANEL 0x2100 // Reads info from the scanner. BW/Col + Copy Count. Others, not sure. 77 #define CMD_WRITEPANEL 0x2200 // Ditto for setting. 78 79 /* Testing stuff to make it work */ 80 #define CMD_SETDPI 0x1500 /* ??? */ 81 #define CMD_STOPSCAN 0x1B01 /* 0x40 = lamp in on, 0x00 = lamp is off */ 82 #define CMD_STARTSCAN 0x1B05 /* 0x40 = lamp in on, 0x00 = lamp is off */ 83 #define CMD_UNKNOWN 0x2300 /* Send fixed string */ 84 #define CMD_UNKNOWN2 0xD600 /* ??? Set to 0x04 */ 85 #define CMD_UNKNOWN3 0xC000 /* ??? Set to 02 03 03 3C */ 86 #define CMD_SETOFFSET 0xE700 /* two ints in network order. X-offset, Y-offset of full scan */ 87 /* Given values seem to be 0x0054 (=4.57mm) and 0x0282 (=54.36mm) */ 88 89 #define CMD_INITBULK1 0x0087 /* send 0x14 */ 90 #define CMD_INITBULK2 0x0083 /* send 0x24 */ 91 #define CMD_INITBULK3 0x0082 /* transfer length 0xf000 */ 92 93 94 struct ScanRequest 95 { 96 uint8_t x1; /* Set to 0x08 */ 97 uint16_t dpix, dpiy; /* Set to 75, 150 or 300 in network order */ 98 uint16_t offx, offy; /* Offset to scan, in 1/300th of dpi, in network order */ 99 uint16_t lenx, leny; /* Size of scan, in 1/300th of dpi, in network order */ 100 uint16_t flags1, flags2, flags3; /* Undetermined flag info */ 101 /* Known combinations are: 102 1st calibration scan: 0x0000, 0x0010, 0x1820 = 24bpp 103 2nd calibration scan: 0x0000, 0x0010, 0x3020 = 48bpp ??? 104 3rd calibration scan: 0x0000, 0x0010, 0x3024 = 48bpp ??? 105 Preview scan: 0x0080, 0x0000, 0x18E8 = 8bpp 106 4th & 5th like 2nd and 3rd 107 B&W scan: 0x0080, 0x0040, 0x08E8 = 8bpp 108 6th & 7th like 2nd and 3rd 109 True colour scan 0x0080, 0x0040, 0x18E8 = 24bpp 110 */ 111 uint8_t zero; /* Seems to always be zero */ 112 uint16_t gamma[3]; /* Set to 100 in network order. Gamma? */ 113 uint16_t pad[3]; /* Zero padding to 32 bytes??? */ 114 } 115 PACKED; 116 117 /* More known combos (All 24-bit): 118 300 x 300 light calibration: 0x0000, 0x0010, 0x1820 119 300 x 300 dark calibration: 0x0000, 0x0010, 0x3024 120 75 x 75 preview scan: 0x0080, 0x0000, 0x18E8 121 300 x 300 full scan: 0x0080, 0x0000, 0x18E8 122 600 x 300 light calibration: 0x0000, 0x0010, 0x3000 123 600 x 300 dark calibration: 0x0000, 0x0010, 0x3004 124 600 x 600 full scan: 0x0080, 0x0000, 0x18C8 125 1200 x 300 light calibration: 0x0000, 0x0010, 0x3000 126 1200 x 300 dark calibration: 0x0000, 0x0010, 0x3004 127 1200 x 1200 full scan: 0x0080, 0x0000, 0x18C8 128 2400 x 300 light calibration: 0x0000, 0x0010, 0x3000 129 2400 x 300 dark calibration: 0x0000, 0x0010, 0x3004 130 2400 x 2400 full scan: 0x0080, 0x0000, 0x18C0 131 */ 132 133 struct ScanResponse 134 { 135 uint16_t x1; /* Usually 0x0000 or 0x4000 */ 136 uint32_t transfersize; /* Number of bytes to be transferred */ 137 uint32_t xsize; /* Shape of returned bitmap */ 138 uint16_t ysize; /* Why does the X get more bytes? */ 139 uint16_t pad[2]; /* Zero padding to 16 bytes??? */ 140 } 141 PACKED; 142 143 /* 144 * Note: this is the structure of the response we get from CMD_READPANEL. 145 * We only know about two items for the moment. The rest will be ignored 146 * until we understand it better. 147 * 148 * 44 bytes in total. 149 * 150 * Since we don't know what the other things mean, I will assume that they 151 * mean the same things for Get and SET. For SET, we will have to GET, change 152 * what we wish change and SET it back otherwise goodness knows what evil 153 * we will unleash. 154 * 155 * Note that for setting, different values in the buffer seem to apply between the copy count 156 * and the colour/BW switch setting. I don't know what that means at the moment. 157 * 158 * I'm calling it PanelInfo because I can't think of anything better. 159 * That may change as the other values are revealed. 160 * 161 */ 162 struct PanelInfo 163 { 164 uint32_t unknown1[10]; 165 uint8_t unknown2; 166 uint8_t copycount; // 0..99 from the LCD display. 167 uint8_t bwcolour; // 1 or 2 from the Colour/BW leds. 168 uint8_t unknown3; 169 } 170 PACKED; 171 172 HP5400_SANE_STATIC 173 int 174 InitScan2 (enum ScanType type, struct ScanRequest *req, 175 THWParams * pHWParams, struct ScanResponse *res, 176 int iColourOffset, int code); 177 178 HP5400_SANE_STATIC 179 void 180 FinishScan (THWParams * pHWParams); 181 182 HP5400_SANE_STATIC 183 int 184 WriteByte (int iHandle, int cmd, char data); 185 186 HP5400_SANE_STATIC 187 int 188 SetLamp (THWParams * pHWParams, int fLampOn); 189 190 HP5400_SANE_STATIC 191 int 192 GetSensors (THWParams * pHWParams, uint16_t *sensorMap); 193 194 HP5400_SANE_STATIC 195 int 196 GetPanelInfo (THWParams * pHWParams, TPanelInfo *panelInfo); 197 198 HP5400_SANE_STATIC 199 int 200 SetCopyCount(THWParams * pHWParams, SANE_Word copyCount); 201 202 HP5400_SANE_STATIC 203 int 204 SetColourBW(THWParams * pHWParams, SANE_Word colourBW); 205 206 HP5400_SANE_STATIC 207 int 208 WarmupLamp (int iHandle); 209 210 HP5400_SANE_STATIC 211 int 212 SetCalibration (int iHandle, int numPixels, 213 unsigned int *low_vals[3], 214 unsigned int *high_vals[3], int dpi); 215 216 HP5400_SANE_STATIC 217 void 218 WriteGammaCalibTable (int iHandle, const int *pabGammaR, 219 const int *pabGammaG, 220 const int *pabGammaB); 221 #ifdef STANDALONE 222 HP5400_SANE_STATIC 223 void 224 SetDefaultGamma (int iHandle); 225 #endif 226 227 HP5400_SANE_STATIC 228 void 229 CircBufferInit (int iHandle, TDataPipe * p, int iBytesPerLine, 230 int bpp, int iMisAlignment, int blksize, 231 int iTransferSize); 232 233 HP5400_SANE_STATIC 234 int 235 CircBufferGetLine (int iHandle, TDataPipe * p, void *pabLine); 236 237 HP5400_SANE_STATIC 238 void 239 CircBufferExit (TDataPipe * p); 240 241 #ifdef STANDALONE 242 HP5400_SANE_STATIC 243 void 244 DecodeImage (FILE * file, int planes, int bpp, int xsize, int ysize, 245 const char *filename); 246 247 HP5400_SANE_STATIC 248 int 249 hp5400_test_scan_response (struct ScanResponse *resp, 250 struct ScanRequest *req); 251 #endif 252 253 254 HP5400_SANE_STATIC 255 int 256 DoAverageScan (int iHandle, struct ScanRequest *req, int code, 257 unsigned int **array); 258 259 #ifdef STANDALONE 260 HP5400_SANE_STATIC 261 int 262 DoScan (int iHandle, struct ScanRequest *req, const char *filename, int code, 263 struct ScanResponse *res); 264 #endif 265 266 HP5400_SANE_STATIC 267 int 268 Calibrate (int iHandle, int dpi); 269 270 #ifdef STANDALONE 271 HP5400_SANE_STATIC 272 int 273 hp5400_scan (int iHandle, TScanParams * params, THWParams * pHWParams, 274 const char *filename); 275 276 HP5400_SANE_STATIC 277 int 278 PreviewScan (int iHandle); 279 280 HP5400_SANE_STATIC 281 int 282 InitScanner (int iHandle); 283 #endif 284 285 HP5400_SANE_STATIC 286 int 287 InitScan (enum ScanType scantype, TScanParams * pParams, 288 THWParams * pHWParams); 289 290 HP5400_SANE_STATIC 291 void 292 FinishScan (THWParams * pHWParams); 293 294 HP5400_SANE_STATIC 295 int 296 HP5400Open (THWParams * params, const char *filename); 297 298 HP5400_SANE_STATIC 299 void 300 HP5400Close (THWParams * params); 301 302 HP5400_SANE_STATIC 303 int 304 HP5400Detect (const char *filename, 305 int (*_ReportDevice) (TScannerModel * pModel, 306 const char *pszDeviceName)); 307 308 309 HP5400_SANE_STATIC 310 int 311 InitHp5400_internal( void ); 312 313 HP5400_SANE_STATIC 314 int 315 FreeHp5400_internal( void ); 316 317 318 #ifdef STANDALONE 319 int 320 main (int argc, char *argv[]); 321 #endif 322 323 #endif 324