2001-12-29 15:34:03 +00:00
|
|
|
/*.............................................................................
|
2003-01-10 13:32:11 +00:00
|
|
|
* Project : SANE library for Plustek flatbed scanners.
|
2001-12-29 15:34:03 +00:00
|
|
|
*.............................................................................
|
2003-01-10 13:32:11 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file plustek-usbimg.c
|
|
|
|
* @brief Image processing functions for copying and scaling image lines.
|
2001-12-29 15:34:03 +00:00
|
|
|
*
|
2003-01-10 13:32:11 +00:00
|
|
|
* Based on sources acquired from Plustek Inc.<br>
|
2007-11-08 19:49:53 +00:00
|
|
|
* Copyright (C) 2001-2007 Gerhard Jaeger <gerhard@gjaeger.de>
|
2001-12-29 15:34:03 +00:00
|
|
|
*
|
2003-01-10 13:32:11 +00:00
|
|
|
* History:
|
|
|
|
* - 0.40 - starting version of the USB support
|
|
|
|
* - 0.41 - fixed the 14bit problem for LM9831 devices
|
|
|
|
* - 0.42 - no changes
|
|
|
|
* - 0.43 - no changes
|
|
|
|
* - 0.44 - added CIS parts and dumpPic function
|
|
|
|
* - 0.45 - added gray scaling functions for CIS devices
|
|
|
|
* - fixed usb_GrayScale16 function
|
2003-01-24 11:44:04 +00:00
|
|
|
* - fixed a bug in usb_ColorScale16_2 function
|
2003-03-03 14:34:20 +00:00
|
|
|
* - fixed endless loop bug
|
|
|
|
* - fixed a bug in usb_GrayScalePseudo16 function
|
|
|
|
* - fixed a bug in usb_GrayDuplicatePseudo16 function
|
2003-05-15 17:19:32 +00:00
|
|
|
* - removed the scaler stuff for CIS devices
|
2003-12-18 13:24:26 +00:00
|
|
|
* - 0.46 - minor fixes
|
|
|
|
* - 0.47 - added big-endian/little endian stuff
|
2004-07-02 13:09:36 +00:00
|
|
|
* - 0.48 - fixed usb_ColorDuplicateGray16() and
|
|
|
|
* usb_ColorScaleGray16()
|
2006-05-28 11:25:53 +00:00
|
|
|
* - added usb_BWScaleFromColor() and usb_BWDuplicateFromColor()
|
2004-07-02 13:09:36 +00:00
|
|
|
* - cleanup
|
2004-11-19 12:38:46 +00:00
|
|
|
* - 0.49 - a_bRegs is now part of the device structure
|
2005-08-15 14:55:24 +00:00
|
|
|
* - 0.50 - cleanup
|
2006-05-28 11:25:53 +00:00
|
|
|
* - 0.51 - added usb_ColorDuplicateGray16_2(), usb_ColorScaleGray16_2()
|
|
|
|
* usb_BWScaleFromColor_2() and usb_BWDuplicateFromColor_2()
|
2007-06-29 08:39:56 +00:00
|
|
|
* - 0.52 - cleanup
|
2003-01-10 13:32:11 +00:00
|
|
|
* .
|
|
|
|
* <hr>
|
2001-12-29 15:34:03 +00:00
|
|
|
* This file is part of the SANE package.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* As a special exception, the authors of SANE give permission for
|
|
|
|
* additional uses of the libraries contained in this release of SANE.
|
|
|
|
*
|
|
|
|
* The exception is that, if you link a SANE library with other files
|
|
|
|
* to produce an executable, this does not by itself cause the
|
|
|
|
* resulting executable to be covered by the GNU General Public
|
|
|
|
* License. Your use of that executable is in no way restricted on
|
|
|
|
* account of linking the SANE library code into it.
|
|
|
|
*
|
|
|
|
* This exception does not, however, invalidate any other reasons why
|
|
|
|
* the executable file might be covered by the GNU General Public
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* If you submit changes to SANE to the maintainers to be included in
|
|
|
|
* a subsequent release, you agree by submitting the changes that
|
|
|
|
* those changes may be distributed with this exception intact.
|
|
|
|
*
|
|
|
|
* If you write modifications of your own for SANE, it is your choice
|
|
|
|
* whether to permit this exception to apply to your modifications.
|
|
|
|
* If you do not wish that, delete this exception notice.
|
2003-01-10 13:32:11 +00:00
|
|
|
* <hr>
|
2001-12-29 15:34:03 +00:00
|
|
|
*/
|
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
#define _SCALER 1000
|
2001-12-30 13:35:48 +00:00
|
|
|
|
2003-01-10 13:32:11 +00:00
|
|
|
static u_char bShift, Shift;
|
2005-07-04 09:54:31 +00:00
|
|
|
static u_short wSum, Mask;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
*/
|
2005-07-04 09:54:31 +00:00
|
|
|
static u_char BitTable[8] = {
|
2007-06-29 08:39:56 +00:00
|
|
|
0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01
|
2004-07-05 12:59:03 +00:00
|
|
|
};
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
static u_char BitsReverseTable[256] = {
|
2007-06-29 08:39:56 +00:00
|
|
|
0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
|
|
|
|
0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
|
|
|
|
0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
|
|
|
|
0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
|
|
|
|
0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
|
|
|
|
0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
|
|
|
|
0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
|
|
|
|
0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
|
|
|
|
0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
|
|
|
|
0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
|
|
|
|
0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
|
|
|
|
0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
|
|
|
|
0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
|
|
|
|
0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
|
|
|
|
0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
|
|
|
|
0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
|
|
|
|
0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
|
|
|
|
0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
|
|
|
|
0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
|
|
|
|
0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
|
|
|
|
0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
|
|
|
|
0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
|
|
|
|
0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
|
|
|
|
0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
|
|
|
|
0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
|
|
|
|
0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
|
|
|
|
0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
|
|
|
|
0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
|
|
|
|
0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
|
|
|
|
0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
|
|
|
|
0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
|
|
|
|
0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
|
2001-12-29 15:34:03 +00:00
|
|
|
};
|
2004-07-05 12:59:03 +00:00
|
|
|
|
|
|
|
/************************ some helper functions ******************************/
|
2001-12-29 15:34:03 +00:00
|
|
|
|
|
|
|
static void ReverseBits( int b, u_char **pTar, int *iByte, int *iWeightSum,
|
2004-07-05 12:59:03 +00:00
|
|
|
int iSrcWeight, int iTarWeight, int cMax )
|
2001-12-29 15:34:03 +00:00
|
|
|
{
|
|
|
|
int bit;
|
|
|
|
|
|
|
|
cMax = (1 << cMax);
|
2005-07-04 09:54:31 +00:00
|
|
|
if(iSrcWeight == iTarWeight) {
|
2001-12-29 15:34:03 +00:00
|
|
|
for( bit = 1; bit < cMax; bit <<= 1) {
|
|
|
|
*iByte <<= 1;
|
|
|
|
if(b & bit)
|
|
|
|
*iByte |= 1;
|
|
|
|
if(*iByte >= 0x100) {
|
|
|
|
**pTar++ = (u_char)*iByte;
|
|
|
|
*iByte = 1;
|
|
|
|
}
|
|
|
|
}
|
2005-07-04 09:54:31 +00:00
|
|
|
} else {
|
2001-12-29 15:34:03 +00:00
|
|
|
for( bit = 1; bit < cMax; bit <<= 1 ) {
|
|
|
|
|
|
|
|
*iWeightSum += iTarWeight;
|
|
|
|
while(*iWeightSum >= iSrcWeight)
|
|
|
|
{
|
|
|
|
*iWeightSum -= iSrcWeight;
|
|
|
|
*iByte <<= 1;
|
|
|
|
if(b & bit)
|
|
|
|
*iByte |= 1;
|
|
|
|
if(*iByte >= 0x100)
|
|
|
|
{
|
|
|
|
**pTar++ = (u_char)*iByte;
|
|
|
|
*iByte = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-07-05 12:59:03 +00:00
|
|
|
|
2001-12-29 15:34:03 +00:00
|
|
|
static void usb_ReverseBitStream( u_char *pSrc, u_char *pTar, int iPixels,
|
|
|
|
int iBufSize, int iSrcWeight/* = 0*/,
|
|
|
|
int iTarWeight/* = 0*/, int iPadBit/* = 1*/)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int iByte = 1;
|
|
|
|
int cBytes = iPixels / 8;
|
|
|
|
int cBits = iPixels % 8;
|
|
|
|
u_char bPad = iPadBit? 0xff: 0;
|
|
|
|
u_char *pTarget = pTar;
|
|
|
|
int iWeightSum = 0;
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
if(iSrcWeight == iTarWeight) {
|
2001-12-29 15:34:03 +00:00
|
|
|
if(cBits)
|
|
|
|
{
|
|
|
|
int cShift = 8 - cBits;
|
|
|
|
for(i = cBytes, pSrc = pSrc + cBytes - 1; i > 0; i--, pSrc--, pTar++)
|
|
|
|
*pTar = BitsReverseTable[(u_char)((*pSrc << cBits) | (*(pSrc+1) >> cShift))];
|
|
|
|
ReverseBits(*(pSrc+1) >> cShift, &pTar, &iByte, &iWeightSum, iSrcWeight, iTarWeight, cBits);
|
|
|
|
}
|
|
|
|
else /* byte boundary */
|
|
|
|
{
|
|
|
|
for(i = cBytes, pSrc = pSrc + cBytes - 1; i > 0; i--, pSrc--, pTar++)
|
|
|
|
*pTar = BitsReverseTable[*pSrc];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* To shrink or enlarge */
|
|
|
|
{
|
2005-07-04 09:54:31 +00:00
|
|
|
if(cBits) {
|
2001-12-29 15:34:03 +00:00
|
|
|
int cShift = 8 - cBits;
|
|
|
|
for(i = cBytes, pSrc = pSrc + cBytes - 1; i > 0; i--, pSrc--)
|
|
|
|
ReverseBits((*pSrc << cBits) | (*(pSrc+1) >> cShift), &pTar, &iByte, &iWeightSum, iSrcWeight, iTarWeight, 8);
|
|
|
|
ReverseBits(*(pSrc+1) >> cShift, &pTar, &iByte, &iWeightSum, iSrcWeight, iTarWeight, cBits);
|
|
|
|
}
|
|
|
|
else /* byte boundary */
|
|
|
|
{
|
|
|
|
for(i = cBytes, pSrc = pSrc + cBytes - 1; i > 0; i--, pSrc--)
|
|
|
|
ReverseBits(*pSrc, &pTar, &iByte, &iWeightSum, iSrcWeight, iTarWeight, 8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
if(iByte != 1) {
|
2001-12-29 15:34:03 +00:00
|
|
|
while(iByte < 0x100)
|
|
|
|
{
|
|
|
|
iByte <<= 1;
|
|
|
|
iByte |= iPadBit;
|
|
|
|
}
|
|
|
|
*pTar++ = (u_char)iByte;
|
|
|
|
}
|
|
|
|
|
|
|
|
cBytes = (int)(pTar - pTarget);
|
|
|
|
|
|
|
|
for(i = iBufSize - cBytes; i > 0; i--, pTar++)
|
|
|
|
*pTar = bPad;
|
|
|
|
}
|
|
|
|
|
2003-12-18 13:24:26 +00:00
|
|
|
/**
|
2001-12-29 15:34:03 +00:00
|
|
|
*/
|
2004-07-05 12:59:03 +00:00
|
|
|
static void usb_AverageColorByte( Plustek_Device *dev )
|
2001-12-29 15:34:03 +00:00
|
|
|
{
|
|
|
|
u_long dw;
|
2005-08-15 14:55:24 +00:00
|
|
|
ScanDef *scan = &dev->scanning;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
if((scan->sParam.bSource == SOURCE_Negative ||
|
|
|
|
scan->sParam.bSource == SOURCE_Transparency) &&
|
|
|
|
scan->sParam.PhyDpi.x > 800) {
|
2002-09-28 11:31:53 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
for (dw = 0; dw < (scan->sParam.Size.dwPhyPixels - 1); dw++)
|
2001-12-29 15:34:03 +00:00
|
|
|
{
|
2004-07-05 12:59:03 +00:00
|
|
|
scan->Red.pcb[dw].a_bColor[0] =
|
|
|
|
(u_char)(((u_short)scan->Red.pcb[dw].a_bColor[0] +
|
|
|
|
(u_short)scan->Red.pcb[dw + 1].a_bColor[0]) / 2);
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
scan->Green.pcb[dw].a_bColor[0] =
|
|
|
|
(u_char)(((u_short)scan->Green.pcb[dw].a_bColor[0] +
|
|
|
|
(u_short)scan->Green.pcb[dw + 1].a_bColor[0]) / 2);
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
scan->Blue.pcb[dw].a_bColor[0] =
|
|
|
|
(u_char)(((u_short)scan->Blue.pcb[dw].a_bColor[0] +
|
|
|
|
(u_short)scan->Blue.pcb[dw + 1].a_bColor[0]) / 2);
|
2001-12-29 15:34:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-18 13:24:26 +00:00
|
|
|
/**
|
2001-12-29 15:34:03 +00:00
|
|
|
*/
|
2004-07-05 12:59:03 +00:00
|
|
|
static void usb_AverageColorWord( Plustek_Device *dev )
|
2001-12-29 15:34:03 +00:00
|
|
|
{
|
2003-12-18 13:24:26 +00:00
|
|
|
u_char ls = 2;
|
2001-12-29 15:34:03 +00:00
|
|
|
u_long dw;
|
2005-08-15 14:55:24 +00:00
|
|
|
ScanDef *scan = &dev->scanning;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2003-12-18 13:24:26 +00:00
|
|
|
if((scan->sParam.bSource == SOURCE_Negative ||
|
|
|
|
scan->sParam.bSource == SOURCE_Transparency) &&
|
|
|
|
scan->sParam.PhyDpi.x > 800) {
|
|
|
|
|
|
|
|
scan->Red.pcw[0].Colors[0] = _HILO2WORD(scan->Red.pcw[0].HiLo[0]) >> ls;
|
|
|
|
scan->Green.pcw[0].Colors[0] = _HILO2WORD(scan->Green.pcw[0].HiLo[0]) >> ls;
|
|
|
|
scan->Blue.pcw[0].Colors[0] = _HILO2WORD(scan->Blue.pcw[0].HiLo[0]) >> ls;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2003-12-18 13:24:26 +00:00
|
|
|
for (dw = 0; dw < (scan->sParam.Size.dwPhyPixels - 1); dw++)
|
2001-12-29 15:34:03 +00:00
|
|
|
{
|
2003-12-18 13:24:26 +00:00
|
|
|
scan->Red.pcw[dw + 1].Colors[0] = _HILO2WORD(scan->Red.pcw[dw + 1].HiLo[0]) >> ls;
|
|
|
|
scan->Green.pcw[dw + 1].Colors[0] = _HILO2WORD(scan->Green.pcw[dw + 1].HiLo[0]) >> ls;
|
|
|
|
scan->Blue.pcw[dw + 1].Colors[0] = _HILO2WORD(scan->Blue.pcw[dw + 1].HiLo[0]) >> ls;
|
|
|
|
|
|
|
|
scan->Red.pcw[dw].Colors[0] = (u_short)(((u_long)scan->Red.pcw[dw].Colors[0] +
|
|
|
|
(u_long)scan->Red.pcw[dw + 1].Colors[0]) / 2);
|
|
|
|
scan->Green.pcw[dw].Colors[0] = (u_short)(((u_long)scan->Green.pcw[dw].Colors[0] +
|
|
|
|
(u_long)scan->Green.pcw[dw + 1].Colors[0]) / 2);
|
|
|
|
scan->Blue.pcw[dw].Colors[0] = (u_short)(((u_long)scan->Blue.pcw[dw].Colors[0] +
|
|
|
|
(u_long)scan->Blue.pcw[dw + 1].Colors[0]) / 2);
|
|
|
|
|
|
|
|
scan->Red.pcw[dw].Colors[0] = _HILO2WORD(scan->Red.pcw[dw].HiLo[0]) << ls;
|
|
|
|
scan->Green.pcw[dw].Colors[0] = _HILO2WORD(scan->Green.pcw[dw].HiLo[0]) << ls;
|
|
|
|
scan->Blue.pcw[dw].Colors[0] = _HILO2WORD(scan->Blue.pcw[dw].HiLo[0]) << ls;
|
2001-12-29 15:34:03 +00:00
|
|
|
}
|
|
|
|
|
2003-12-18 13:24:26 +00:00
|
|
|
scan->Red.pcw[dw].Colors[0] = _HILO2WORD(scan->Red.pcw[dw].HiLo[0]) << ls;
|
|
|
|
scan->Green.pcw[dw].Colors[0] = _HILO2WORD(scan->Green.pcw[dw].HiLo[0]) << ls;
|
|
|
|
scan->Blue.pcw[dw].Colors[0] = _HILO2WORD(scan->Blue.pcw[dw].HiLo[0]) << ls;
|
2001-12-29 15:34:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-10 13:32:11 +00:00
|
|
|
/**
|
2001-12-29 15:34:03 +00:00
|
|
|
*/
|
2004-07-05 12:59:03 +00:00
|
|
|
static void usb_AverageGrayByte( Plustek_Device *dev )
|
2001-12-29 15:34:03 +00:00
|
|
|
{
|
|
|
|
u_long dw;
|
2005-08-15 14:55:24 +00:00
|
|
|
ScanDef *scan = &dev->scanning;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
if((scan->sParam.bSource == SOURCE_Negative ||
|
|
|
|
scan->sParam.bSource == SOURCE_Transparency) &&
|
|
|
|
scan->sParam.PhyDpi.x > 800)
|
2001-12-29 15:34:03 +00:00
|
|
|
{
|
2004-07-05 12:59:03 +00:00
|
|
|
for (dw = 0; dw < (scan->sParam.Size.dwPhyPixels - 1); dw++)
|
|
|
|
scan->Green.pb[dw] = (u_char)(((u_short)scan->Green.pb[dw]+
|
|
|
|
(u_short)scan->Green.pb[dw+1]) / 2);
|
2001-12-29 15:34:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-18 13:24:26 +00:00
|
|
|
/**
|
2001-12-29 15:34:03 +00:00
|
|
|
*/
|
2004-07-05 12:59:03 +00:00
|
|
|
static void usb_AverageGrayWord( Plustek_Device *dev )
|
2001-12-29 15:34:03 +00:00
|
|
|
{
|
|
|
|
u_long dw;
|
2005-08-15 14:55:24 +00:00
|
|
|
ScanDef *scan = &dev->scanning;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
if((scan->sParam.bSource == SOURCE_Negative ||
|
|
|
|
scan->sParam.bSource == SOURCE_Transparency) &&
|
|
|
|
scan->sParam.PhyDpi.x > 800)
|
2001-12-29 15:34:03 +00:00
|
|
|
{
|
2004-07-05 12:59:03 +00:00
|
|
|
scan->Green.pw[0] = _HILO2WORD(scan->Green.philo[0]) >> 2;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
for (dw = 0; dw < (scan->sParam.Size.dwPhyPixels - 1); dw++)
|
2001-12-29 15:34:03 +00:00
|
|
|
{
|
2004-07-05 12:59:03 +00:00
|
|
|
scan->Green.pw[dw + 1] = _HILO2WORD(scan->Green.philo[dw+1]) >> 2;
|
|
|
|
scan->Green.pw[dw] = (u_short)(((u_long)scan->Green.pw[dw]+
|
|
|
|
(u_long)scan->Green.pw[dw+1]) / 2);
|
|
|
|
scan->Green.pw[dw] = _HILO2WORD(scan->Green.philo[dw]) << 2;
|
2001-12-29 15:34:03 +00:00
|
|
|
}
|
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
scan->Green.pw[dw] = _HILO2WORD(scan->Green.philo[dw]) << 2;
|
2001-12-29 15:34:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-10 13:32:11 +00:00
|
|
|
/**
|
2001-12-30 13:35:48 +00:00
|
|
|
* returns the zoom value, used for our scaling algorithm (DDA algo
|
|
|
|
* digital differential analyzer).
|
|
|
|
*/
|
2004-07-05 12:59:03 +00:00
|
|
|
static int usb_GetScaler( ScanDef *scan )
|
2001-12-30 13:35:48 +00:00
|
|
|
{
|
|
|
|
double ratio;
|
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
ratio = (double)scan->sParam.UserDpi.x/
|
|
|
|
(double)scan->sParam.PhyDpi.x;
|
|
|
|
|
2003-12-18 13:24:26 +00:00
|
|
|
return (int)(1.0/ratio * _SCALER);
|
2001-12-30 13:35:48 +00:00
|
|
|
}
|
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
/******************************* the copy functions **************************/
|
|
|
|
|
|
|
|
/** do a simple memcopy from scan-buffer to user buffer
|
2001-12-29 15:34:03 +00:00
|
|
|
*/
|
2004-07-05 12:59:03 +00:00
|
|
|
static void usb_ColorDuplicate8( Plustek_Device *dev )
|
2001-12-29 15:34:03 +00:00
|
|
|
{
|
2005-07-04 09:54:31 +00:00
|
|
|
int next;
|
|
|
|
u_long dw, pixels;
|
|
|
|
ScanDef *scan = &dev->scanning;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
|
|
|
usb_AverageColorByte( dev );
|
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
if( scan->sParam.bSource == SOURCE_ADF ) {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = -1;
|
|
|
|
pixels = scan->sParam.Size.dwPixels - 1;
|
2001-12-29 15:34:03 +00:00
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = 1;
|
|
|
|
pixels = 0;
|
2001-12-29 15:34:03 +00:00
|
|
|
}
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
for( dw = 0; dw < scan->sParam.Size.dwPixels; dw++, pixels += next ) {
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pb_rgb[pixels].Red = scan->Red.pcb[dw].a_bColor[0];
|
|
|
|
scan->UserBuf.pb_rgb[pixels].Green = scan->Green.pcb[dw].a_bColor[0];
|
|
|
|
scan->UserBuf.pb_rgb[pixels].Blue = scan->Blue.pcb[dw].a_bColor[0];
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
|
|
|
}
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
/** reorder from rgb line to rgb pixel (CIS scanner)
|
|
|
|
*/
|
|
|
|
static void usb_ColorDuplicate8_2( Plustek_Device *dev )
|
|
|
|
{
|
2005-07-04 09:54:31 +00:00
|
|
|
int next;
|
|
|
|
u_long dw, pixels;
|
|
|
|
ScanDef *scan = &dev->scanning;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
if( scan->sParam.bSource == SOURCE_ADF ) {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = -1;
|
|
|
|
pixels = scan->sParam.Size.dwPixels - 1;
|
2004-07-05 12:59:03 +00:00
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = 1;
|
|
|
|
pixels = 0;
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
for( dw = 0; dw < scan->sParam.Size.dwPixels; dw++, pixels += next ) {
|
2004-07-05 12:59:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pb_rgb[pixels].Red = (u_char)scan->Red.pb[dw];
|
|
|
|
scan->UserBuf.pb_rgb[pixels].Green = (u_char)scan->Green.pb[dw];
|
|
|
|
scan->UserBuf.pb_rgb[pixels].Blue = (u_char)scan->Blue.pb[dw];
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
static void usb_ColorDuplicate16( Plustek_Device *dev )
|
|
|
|
{
|
2005-07-04 09:54:31 +00:00
|
|
|
int next;
|
2004-07-05 12:59:03 +00:00
|
|
|
u_char ls;
|
2005-07-04 09:54:31 +00:00
|
|
|
u_long dw, pixels;
|
|
|
|
ScanDef *scan = &dev->scanning;
|
2004-07-05 12:59:03 +00:00
|
|
|
SANE_Bool swap = usb_HostSwap();
|
|
|
|
|
|
|
|
usb_AverageColorWord( dev );
|
|
|
|
|
|
|
|
if( scan->sParam.bSource == SOURCE_ADF ) {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = -1;
|
|
|
|
pixels = scan->sParam.Size.dwPixels - 1;
|
2004-07-05 12:59:03 +00:00
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = 1;
|
|
|
|
pixels = 0;
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( scan->dwFlag & SCANFLAG_RightAlign )
|
|
|
|
ls = Shift;
|
|
|
|
else
|
|
|
|
ls = 0;
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
for (dw = 0; dw < scan->sParam.Size.dwPixels; dw++, pixels += next) {
|
2004-07-05 12:59:03 +00:00
|
|
|
|
|
|
|
if( swap ) {
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pw_rgb[pixels].Red =
|
|
|
|
_HILO2WORD(scan->Red.pcw[dw].HiLo[0]) >> ls;
|
|
|
|
scan->UserBuf.pw_rgb[pixels].Green =
|
|
|
|
_HILO2WORD(scan->Green.pcw[dw].HiLo[0]) >> ls;
|
|
|
|
scan->UserBuf.pw_rgb[pixels].Blue =
|
|
|
|
_HILO2WORD(scan->Blue.pcw[dw].HiLo[0]) >> ls;
|
2004-07-05 12:59:03 +00:00
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pw_rgb[pixels].Red = scan->Red.pw[dw] >> ls;
|
|
|
|
scan->UserBuf.pw_rgb[pixels].Green= scan->Green.pw[dw] >> ls;
|
|
|
|
scan->UserBuf.pw_rgb[pixels].Blue = scan->Blue.pw[dw] >> ls;
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
static void usb_ColorDuplicate16_2( Plustek_Device *dev )
|
|
|
|
{
|
2005-07-04 09:54:31 +00:00
|
|
|
int next;
|
2004-07-05 12:59:03 +00:00
|
|
|
u_char ls;
|
|
|
|
HiLoDef tmp;
|
2005-07-04 09:54:31 +00:00
|
|
|
u_long dw, pixels;
|
|
|
|
ScanDef *scan = &dev->scanning;
|
2004-07-05 12:59:03 +00:00
|
|
|
SANE_Bool swap = usb_HostSwap();
|
|
|
|
|
|
|
|
usb_AverageColorWord( dev );
|
|
|
|
|
|
|
|
if( scan->sParam.bSource == SOURCE_ADF ) {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = -1;
|
|
|
|
pixels = scan->sParam.Size.dwPixels - 1;
|
2004-07-05 12:59:03 +00:00
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = 1;
|
|
|
|
pixels = 0;
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( scan->dwFlag & SCANFLAG_RightAlign )
|
|
|
|
ls = Shift;
|
|
|
|
else
|
|
|
|
ls = 0;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
for( dw = 0; dw < scan->sParam.Size.dwPixels; dw++, pixels += next) {
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
if( swap ) {
|
2005-08-15 14:55:24 +00:00
|
|
|
tmp = *((HiLoDef*)&scan->Red.pw[dw]);
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pw_rgb[pixels].Red = _HILO2WORD(tmp) >> ls;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2005-08-15 14:55:24 +00:00
|
|
|
tmp = *((HiLoDef*)&scan->Green.pw[dw]);
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pw_rgb[pixels].Green = _HILO2WORD(tmp) >> ls;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2005-08-15 14:55:24 +00:00
|
|
|
tmp = *((HiLoDef*)&scan->Blue.pw[dw]);
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pw_rgb[pixels].Blue = _HILO2WORD(tmp) >> ls;
|
2004-07-05 12:59:03 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pw_rgb[pixels].Red = scan->Red.pw[dw] >> ls;
|
|
|
|
scan->UserBuf.pw_rgb[pixels].Green = scan->Green.pw[dw] >> ls;
|
|
|
|
scan->UserBuf.pw_rgb[pixels].Blue = scan->Blue.pw[dw] >> ls;
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
static void usb_ColorDuplicatePseudo16( Plustek_Device *dev )
|
|
|
|
{
|
2005-07-04 09:54:31 +00:00
|
|
|
int next;
|
|
|
|
u_short wR, wG, wB;
|
|
|
|
u_long dw, pixels;
|
|
|
|
ScanDef *scan = &dev->scanning;
|
2004-07-05 12:59:03 +00:00
|
|
|
|
|
|
|
usb_AverageColorByte( dev );
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
if (scan->sParam.bSource == SOURCE_ADF) {
|
|
|
|
next = -1;
|
|
|
|
pixels = scan->sParam.Size.dwPixels - 1;
|
|
|
|
} else {
|
|
|
|
next = 1;
|
|
|
|
pixels = 0;
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wR = (u_short)scan->Red.pcb[0].a_bColor[0];
|
|
|
|
wG = (u_short)scan->Green.pcb[0].a_bColor[0];
|
|
|
|
wB = (u_short)scan->Blue.pcb[0].a_bColor[0];
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
for (dw = 0; dw < scan->sParam.Size.dwPixels; dw++, pixels += next) {
|
|
|
|
|
|
|
|
scan->UserBuf.pw_rgb[pixels].Red =
|
2004-07-05 12:59:03 +00:00
|
|
|
(wR + scan->Red.pcb[dw].a_bColor[0]) << bShift;
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pw_rgb[pixels].Green =
|
2004-07-05 12:59:03 +00:00
|
|
|
(wG + scan->Green.pcb[dw].a_bColor[0]) << bShift;
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pw_rgb[pixels].Blue =
|
2004-07-05 12:59:03 +00:00
|
|
|
(wB + scan->Blue.pcb[dw].a_bColor[0]) << bShift;
|
|
|
|
|
|
|
|
wR = (u_short)scan->Red.pcb[dw].a_bColor[0];
|
|
|
|
wG = (u_short)scan->Green.pcb[dw].a_bColor[0];
|
|
|
|
wB = (u_short)scan->Blue.pcb[dw].a_bColor[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
static void usb_ColorDuplicateGray( Plustek_Device *dev )
|
|
|
|
{
|
2005-07-04 09:54:31 +00:00
|
|
|
int next;
|
|
|
|
u_long dw, pixels;
|
|
|
|
ScanDef *scan = &dev->scanning;
|
2004-07-05 12:59:03 +00:00
|
|
|
|
|
|
|
usb_AverageColorByte( dev );
|
|
|
|
|
|
|
|
if (scan->sParam.bSource == SOURCE_ADF) {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = -1;
|
|
|
|
pixels = scan->sParam.Size.dwPixels - 1;
|
2004-07-05 12:59:03 +00:00
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = 1;
|
|
|
|
pixels = 0;
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch(scan->fGrayFromColor) {
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
case 1:
|
2005-07-04 09:54:31 +00:00
|
|
|
for (dw = 0; dw < scan->sParam.Size.dwPixels; dw++, pixels += next)
|
|
|
|
scan->UserBuf.pb[pixels] = scan->Red.pcb[dw].a_bColor[0];
|
2004-07-05 12:59:03 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2005-07-04 09:54:31 +00:00
|
|
|
for (dw = 0; dw < scan->sParam.Size.dwPixels; dw++, pixels += next)
|
|
|
|
scan->UserBuf.pb[pixels] = scan->Green.pcb[dw].a_bColor[0];
|
2004-07-05 12:59:03 +00:00
|
|
|
break;
|
2001-12-29 15:34:03 +00:00
|
|
|
case 3:
|
2005-07-04 09:54:31 +00:00
|
|
|
for (dw = 0; dw < scan->sParam.Size.dwPixels; dw++, pixels += next)
|
|
|
|
scan->UserBuf.pb[pixels] = scan->Blue.pcb[dw].a_bColor[0];
|
2004-07-05 12:59:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
/**
|
|
|
|
*/
|
|
|
|
static void usb_ColorDuplicateGray_2( Plustek_Device *dev )
|
|
|
|
{
|
2005-07-04 09:54:31 +00:00
|
|
|
int next;
|
|
|
|
u_long dw, pixels;
|
|
|
|
ScanDef *scan = &dev->scanning;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
usb_AverageColorByte( dev );
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
if (scan->sParam.bSource == SOURCE_ADF) {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = -1;
|
|
|
|
pixels = scan->sParam.Size.dwPixels - 1;
|
2004-07-05 12:59:03 +00:00
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = 1;
|
|
|
|
pixels = 0;
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch(scan->fGrayFromColor)
|
|
|
|
{
|
|
|
|
case 1:
|
2005-07-04 09:54:31 +00:00
|
|
|
for (dw = 0; dw < scan->sParam.Size.dwPixels; dw++, pixels += next)
|
|
|
|
scan->UserBuf.pb[pixels] = scan->Red.pb[dw];
|
2004-07-05 12:59:03 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2005-07-04 09:54:31 +00:00
|
|
|
for (dw = 0; dw < scan->sParam.Size.dwPixels; dw++, pixels += next)
|
|
|
|
scan->UserBuf.pb[pixels] = scan->Blue.pb[dw];
|
2004-07-05 12:59:03 +00:00
|
|
|
break;
|
|
|
|
default:
|
2005-07-04 09:54:31 +00:00
|
|
|
for (dw = 0; dw < scan->sParam.Size.dwPixels; dw++, pixels += next)
|
|
|
|
scan->UserBuf.pb[pixels] = scan->Green.pb[dw];
|
2001-12-29 15:34:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-10 13:32:11 +00:00
|
|
|
/**
|
|
|
|
*/
|
2004-07-05 12:59:03 +00:00
|
|
|
static void usb_ColorDuplicateGray16( Plustek_Device *dev )
|
2003-01-10 13:32:11 +00:00
|
|
|
{
|
2005-07-04 09:54:31 +00:00
|
|
|
int next;
|
2004-07-05 12:59:03 +00:00
|
|
|
u_char ls;
|
2005-07-04 09:54:31 +00:00
|
|
|
u_long dw, pixels;
|
|
|
|
ScanDef *scan = &dev->scanning;
|
2004-07-05 12:59:03 +00:00
|
|
|
SANE_Bool swap = usb_HostSwap();
|
2003-01-10 13:32:11 +00:00
|
|
|
|
2006-05-28 11:25:53 +00:00
|
|
|
usb_AverageColorWord( dev );
|
2003-01-10 13:32:11 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
if (scan->sParam.bSource == SOURCE_ADF) {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = -1;
|
|
|
|
pixels = scan->sParam.Size.dwPixels - 1;
|
2004-07-05 12:59:03 +00:00
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = 1;
|
|
|
|
pixels = 0;
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
|
|
|
if( scan->dwFlag & SCANFLAG_RightAlign )
|
|
|
|
ls = Shift;
|
|
|
|
else
|
|
|
|
ls = 0;
|
2003-01-10 13:32:11 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
switch(scan->fGrayFromColor) {
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
if( swap ) {
|
2005-07-04 09:54:31 +00:00
|
|
|
for (dw = 0; dw < scan->sParam.Size.dwPixels; dw++, pixels += next)
|
|
|
|
scan->UserBuf.pw[pixels] =
|
|
|
|
_HILO2WORD(scan->Red.pcw[dw].HiLo[0]) >> ls;
|
2004-07-05 12:59:03 +00:00
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
for (dw = 0; dw < scan->sParam.Size.dwPixels; dw++, pixels += next)
|
|
|
|
scan->UserBuf.pw[pixels] = scan->Red.pw[dw] >> ls;
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if( swap ) {
|
2005-07-04 09:54:31 +00:00
|
|
|
for (dw = 0; dw < scan->sParam.Size.dwPixels; dw++, pixels += next)
|
|
|
|
scan->UserBuf.pw[pixels] =
|
|
|
|
_HILO2WORD(scan->Green.pcw[dw].HiLo[0]) >> ls;
|
2004-07-05 12:59:03 +00:00
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
for (dw = 0; dw < scan->sParam.Size.dwPixels; dw++, pixels += next)
|
|
|
|
scan->UserBuf.pw[pixels] = scan->Green.pw[dw] >> ls;
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if( swap ) {
|
2005-07-04 09:54:31 +00:00
|
|
|
for (dw = 0; dw < scan->sParam.Size.dwPixels; dw++, pixels += next)
|
|
|
|
scan->UserBuf.pw[pixels] =
|
|
|
|
_HILO2WORD(scan->Blue.pcw[dw].HiLo[0]) >> ls;
|
2004-07-05 12:59:03 +00:00
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
for (dw = 0; dw < scan->sParam.Size.dwPixels; dw++, pixels += next)
|
|
|
|
scan->UserBuf.pw[pixels] = scan->Blue.pw[dw] >> ls;
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-28 11:25:53 +00:00
|
|
|
/**
|
|
|
|
*/
|
|
|
|
static void usb_ColorDuplicateGray16_2( Plustek_Device *dev )
|
|
|
|
{
|
|
|
|
int next;
|
|
|
|
u_char ls;
|
|
|
|
u_long dw, pixels;
|
|
|
|
HiLoDef tmp;
|
|
|
|
ScanDef *scan = &dev->scanning;
|
|
|
|
SANE_Bool swap = usb_HostSwap();
|
|
|
|
|
|
|
|
usb_AverageColorWord( dev );
|
|
|
|
|
|
|
|
if (scan->sParam.bSource == SOURCE_ADF) {
|
|
|
|
next = -1;
|
|
|
|
pixels = scan->sParam.Size.dwPixels - 1;
|
|
|
|
} else {
|
|
|
|
next = 1;
|
|
|
|
pixels = 0;
|
|
|
|
}
|
|
|
|
if( scan->dwFlag & SCANFLAG_RightAlign )
|
|
|
|
ls = Shift;
|
|
|
|
else
|
|
|
|
ls = 0;
|
|
|
|
|
|
|
|
switch(scan->fGrayFromColor) {
|
|
|
|
case 1:
|
|
|
|
if( swap ) {
|
|
|
|
for (dw = 0; dw < scan->sParam.Size.dwPixels; dw++, pixels += next) {
|
|
|
|
tmp = *((HiLoDef*)&scan->Red.pw[dw]);
|
|
|
|
scan->UserBuf.pw[pixels] = _HILO2WORD(tmp) >> ls;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (dw = 0; dw < scan->sParam.Size.dwPixels; dw++, pixels += next) {
|
|
|
|
scan->UserBuf.pw[pixels] = scan->Red.pw[dw] >> ls;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if( swap ) {
|
|
|
|
for (dw = 0; dw < scan->sParam.Size.dwPixels; dw++, pixels += next) {
|
|
|
|
tmp = *((HiLoDef*)&scan->Green.pw[dw]);
|
|
|
|
scan->UserBuf.pw[pixels] = _HILO2WORD(tmp) >> ls;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (dw = 0; dw < scan->sParam.Size.dwPixels; dw++, pixels += next) {
|
|
|
|
scan->UserBuf.pw[pixels] = scan->Green.pw[dw] >> ls;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if( swap ) {
|
|
|
|
for (dw = 0; dw < scan->sParam.Size.dwPixels; dw++, pixels += next) {
|
|
|
|
tmp = *((HiLoDef*)&scan->Blue.pw[dw]);
|
|
|
|
scan->UserBuf.pw[pixels] = _HILO2WORD(tmp) >> ls;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (dw = 0; dw < scan->sParam.Size.dwPixels; dw++, pixels += next) {
|
|
|
|
scan->UserBuf.pw[pixels] = scan->Blue.pw[dw] >> ls;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
/**
|
|
|
|
*/
|
|
|
|
static void usb_GrayDuplicate8( Plustek_Device *dev )
|
|
|
|
{
|
2005-07-04 09:54:31 +00:00
|
|
|
u_char *dest, *src;
|
|
|
|
u_long pixels;
|
|
|
|
ScanDef *scan = &dev->scanning;
|
2004-07-05 12:59:03 +00:00
|
|
|
|
|
|
|
usb_AverageGrayByte( dev );
|
|
|
|
|
|
|
|
if( scan->sParam.bSource == SOURCE_ADF ) {
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
pixels = scan->sParam.Size.dwPixels;
|
|
|
|
src = scan->Green.pb;
|
|
|
|
dest = scan->UserBuf.pb + pixels - 1;
|
2004-07-05 12:59:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
for(; pixels; pixels--, src++, dest--)
|
|
|
|
*dest = *src;
|
|
|
|
} else {
|
2004-07-05 12:59:03 +00:00
|
|
|
memcpy( scan->UserBuf.pb, scan->Green.pb, scan->sParam.Size.dwBytes );
|
2005-07-04 09:54:31 +00:00
|
|
|
}
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
static void usb_GrayDuplicate16( Plustek_Device *dev )
|
|
|
|
{
|
2005-07-04 09:54:31 +00:00
|
|
|
int next;
|
2004-07-05 12:59:03 +00:00
|
|
|
u_char ls;
|
2005-07-04 09:54:31 +00:00
|
|
|
u_short *dest;
|
|
|
|
u_long pixels;
|
|
|
|
HiLoDef *pwm;
|
|
|
|
ScanDef *scan = &dev->scanning;
|
2004-07-05 12:59:03 +00:00
|
|
|
SANE_Bool swap = usb_HostSwap();
|
|
|
|
|
|
|
|
usb_AverageGrayWord( dev );
|
|
|
|
|
|
|
|
if( scan->sParam.bSource == SOURCE_ADF ) {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = -1;
|
|
|
|
dest = scan->UserBuf.pw + scan->sParam.Size.dwPixels - 1;
|
2004-07-05 12:59:03 +00:00
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = 1;
|
|
|
|
dest = scan->UserBuf.pw;
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( scan->dwFlag & SCANFLAG_RightAlign )
|
|
|
|
ls = Shift;
|
|
|
|
else
|
|
|
|
ls = 0;
|
|
|
|
|
|
|
|
pwm = scan->Green.philo;
|
2005-07-04 09:54:31 +00:00
|
|
|
for( pixels=scan->sParam.Size.dwPixels; pixels--; pwm++, dest += next ) {
|
2004-07-05 12:59:03 +00:00
|
|
|
if( swap )
|
2005-07-04 09:54:31 +00:00
|
|
|
*dest = (_PHILO2WORD(pwm)) >> ls;
|
2004-07-05 12:59:03 +00:00
|
|
|
else
|
2007-12-17 14:28:13 +00:00
|
|
|
*dest = (_PLOHI2WORD(pwm)) >> ls;
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
static void usb_GrayDuplicatePseudo16( Plustek_Device *dev )
|
|
|
|
{
|
2005-07-04 09:54:31 +00:00
|
|
|
u_char *src;
|
|
|
|
int next;
|
|
|
|
u_short g;
|
|
|
|
u_short *dest;
|
|
|
|
u_long pixels;
|
|
|
|
ScanDef *scan = &dev->scanning;
|
2004-07-05 12:59:03 +00:00
|
|
|
|
|
|
|
usb_AverageGrayByte( dev );
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
if (scan->sParam.bSource == SOURCE_ADF) {
|
|
|
|
next = -1;
|
|
|
|
dest = scan->UserBuf.pw + scan->sParam.Size.dwPixels - 1;
|
|
|
|
} else {
|
|
|
|
next = 1;
|
|
|
|
dest = scan->UserBuf.pw;
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
src = scan->Green.pb;
|
|
|
|
g = (u_short)*src;
|
2004-07-05 12:59:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
for( pixels=scan->sParam.Size.dwPixels; pixels--; src++, dest += next ) {
|
2004-07-05 12:59:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
*dest = (g + *src) << bShift;
|
|
|
|
g = (u_short)*src;
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** copy binary data to the user buffer
|
|
|
|
*/
|
|
|
|
static void usb_BWDuplicate( Plustek_Device *dev )
|
|
|
|
{
|
2005-08-15 14:55:24 +00:00
|
|
|
ScanDef *scan = &dev->scanning;
|
2004-07-05 12:59:03 +00:00
|
|
|
|
|
|
|
if(scan->sParam.bSource == SOURCE_ADF)
|
|
|
|
{
|
|
|
|
usb_ReverseBitStream( scan->Green.pb, scan->UserBuf.pb,
|
|
|
|
scan->sParam.Size.dwValidPixels,
|
|
|
|
scan->dwBytesLine, 0, 0, 1 );
|
|
|
|
} else {
|
|
|
|
memcpy( scan->UserBuf.pb, scan->Green.pb, scan->sParam.Size.dwBytes );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** generate binary data from one of the three color inputs according to the
|
2006-05-28 11:25:53 +00:00
|
|
|
* value in fGrayFromColor (CCD version)
|
2004-07-05 12:59:03 +00:00
|
|
|
*/
|
|
|
|
static void usb_BWDuplicateFromColor( Plustek_Device *dev )
|
|
|
|
{
|
2005-07-04 09:54:31 +00:00
|
|
|
int next;
|
|
|
|
u_char d, s, *dest;
|
2004-07-05 12:59:03 +00:00
|
|
|
u_short j;
|
2005-07-04 09:54:31 +00:00
|
|
|
u_long pixels;
|
2004-07-05 12:59:03 +00:00
|
|
|
ColorByteDef *src;
|
2005-07-04 09:54:31 +00:00
|
|
|
ScanDef *scan = &dev->scanning;
|
2004-07-05 12:59:03 +00:00
|
|
|
|
|
|
|
if( scan->sParam.bSource == SOURCE_ADF ) {
|
2005-07-04 09:54:31 +00:00
|
|
|
dest = scan->UserBuf.pb + scan->sParam.Size.dwPixels - 1;
|
|
|
|
next = -1;
|
2004-07-05 12:59:03 +00:00
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
dest = scan->UserBuf.pb;
|
|
|
|
next = 1;
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch(scan->fGrayFromColor) {
|
|
|
|
case 1: src = scan->Red.pcb; break;
|
|
|
|
case 3: src = scan->Blue.pcb; break;
|
|
|
|
default: src = scan->Green.pcb; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
d = j = 0;
|
2005-07-04 09:54:31 +00:00
|
|
|
for( pixels = scan->sParam.Size.dwPixels; pixels; pixels--, src++ ) {
|
2004-07-05 12:59:03 +00:00
|
|
|
|
|
|
|
s = src->a_bColor[0];
|
|
|
|
if( s != 0 )
|
|
|
|
d |= BitTable[j];
|
|
|
|
j++;
|
|
|
|
if( j == 8 ) {
|
2005-07-04 09:54:31 +00:00
|
|
|
*dest = d;
|
|
|
|
dest += next;
|
2004-07-05 12:59:03 +00:00
|
|
|
|
|
|
|
d = j = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-28 11:25:53 +00:00
|
|
|
/** generate binary data from one of the three color inputs according to the
|
|
|
|
* value in fGrayFromColor (CIS version)
|
|
|
|
*/
|
|
|
|
static void usb_BWDuplicateFromColor_2( Plustek_Device *dev )
|
|
|
|
{
|
|
|
|
int next;
|
|
|
|
u_char d, *dest, *src;
|
|
|
|
u_short j;
|
|
|
|
u_long pixels;
|
|
|
|
ScanDef *scan = &dev->scanning;
|
|
|
|
|
|
|
|
if( scan->sParam.bSource == SOURCE_ADF ) {
|
|
|
|
dest = scan->UserBuf.pb + scan->sParam.Size.dwPixels - 1;
|
|
|
|
next = -1;
|
|
|
|
} else {
|
|
|
|
dest = scan->UserBuf.pb;
|
|
|
|
next = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(scan->fGrayFromColor) {
|
|
|
|
case 1: src = scan->Red.pb; break;
|
|
|
|
case 3: src = scan->Blue.pb; break;
|
|
|
|
default: src = scan->Green.pb; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
d = j = 0;
|
|
|
|
for( pixels = scan->sParam.Size.dwPixels; pixels; pixels--, src++ ) {
|
|
|
|
|
|
|
|
if( *src != 0 )
|
|
|
|
d |= BitTable[j];
|
|
|
|
j++;
|
|
|
|
if( j == 8 ) {
|
|
|
|
*dest = d;
|
|
|
|
dest += next;
|
|
|
|
|
|
|
|
d = j = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
/************************** the scaling functions ****************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
static void usb_ColorScaleGray( Plustek_Device *dev )
|
|
|
|
{
|
2005-07-04 09:54:31 +00:00
|
|
|
int izoom, ddax, next;
|
|
|
|
u_long dw, pixels;
|
2004-07-05 12:59:03 +00:00
|
|
|
ColorByteDef *src;
|
2005-07-04 09:54:31 +00:00
|
|
|
ScanDef *scan = &dev->scanning;
|
2004-07-05 12:59:03 +00:00
|
|
|
|
|
|
|
usb_AverageColorByte( dev );
|
|
|
|
|
|
|
|
dw = scan->sParam.Size.dwPixels;
|
|
|
|
|
|
|
|
if( scan->sParam.bSource == SOURCE_ADF ) {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = -1;
|
|
|
|
pixels = scan->sParam.Size.dwPixels - 1;
|
2003-01-10 13:32:11 +00:00
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = 1;
|
|
|
|
pixels = 0;
|
2003-01-10 13:32:11 +00:00
|
|
|
}
|
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
switch(scan->fGrayFromColor) {
|
|
|
|
case 1: src = scan->Red.pcb; break;
|
|
|
|
case 3: src = scan->Blue.pcb; break;
|
|
|
|
default: src = scan->Green.pcb; break;
|
|
|
|
}
|
2003-01-10 13:32:11 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
izoom = usb_GetScaler( scan );
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
for( ddax = 0; dw; src++ ) {
|
2003-01-10 13:32:11 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
ddax -= _SCALER;
|
|
|
|
while((ddax < 0) && (dw > 0)) {
|
2003-01-10 13:32:11 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pb[pixels] = src->a_bColor[0];
|
2004-07-05 12:59:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
pixels += next;
|
|
|
|
ddax += izoom;
|
2004-07-05 12:59:03 +00:00
|
|
|
dw--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-01-10 13:32:11 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
/**
|
|
|
|
*/
|
|
|
|
static void usb_ColorScaleGray_2( Plustek_Device *dev )
|
|
|
|
{
|
2005-07-04 09:54:31 +00:00
|
|
|
u_char *src;
|
|
|
|
int izoom, ddax, next;
|
|
|
|
u_long dw, pixels;
|
|
|
|
ScanDef *scan = &dev->scanning;
|
2003-01-10 13:32:11 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
usb_AverageColorByte( dev );
|
2003-01-10 13:32:11 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
dw = scan->sParam.Size.dwPixels;
|
2003-01-10 13:32:11 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
if( scan->sParam.bSource == SOURCE_ADF ) {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = -1;
|
|
|
|
pixels = scan->sParam.Size.dwPixels - 1;
|
2004-07-05 12:59:03 +00:00
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = 1;
|
|
|
|
pixels = 0;
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
2003-01-10 13:32:11 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
switch(scan->fGrayFromColor) {
|
2005-07-04 09:54:31 +00:00
|
|
|
case 1: src = scan->Red.pb; break;
|
|
|
|
case 3: src = scan->Blue.pb; break;
|
|
|
|
default: src = scan->Green.pb; break;
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
2003-01-10 13:32:11 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
izoom = usb_GetScaler( scan );
|
2003-01-10 13:32:11 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
for( ddax = 0; dw; src++ ) {
|
2003-01-10 13:32:11 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
ddax -= _SCALER;
|
|
|
|
while((ddax < 0) && (dw > 0)) {
|
2003-01-10 13:32:11 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pb[pixels] = *src;
|
2003-01-10 13:32:11 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
pixels += next;
|
|
|
|
ddax += izoom;
|
2004-07-05 12:59:03 +00:00
|
|
|
dw--;
|
|
|
|
}
|
2003-01-10 13:32:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-04 13:56:46 +00:00
|
|
|
/**
|
|
|
|
*/
|
2004-07-05 12:59:03 +00:00
|
|
|
static void usb_ColorScaleGray16( Plustek_Device *dev )
|
2004-04-04 13:56:46 +00:00
|
|
|
{
|
|
|
|
u_char ls;
|
2005-07-04 09:54:31 +00:00
|
|
|
int izoom, ddax, next;
|
|
|
|
u_long dw, pixels, bitsput;
|
|
|
|
SANE_Bool swap = usb_HostSwap();
|
|
|
|
ScanDef *scan = &dev->scanning;
|
2004-04-04 13:56:46 +00:00
|
|
|
|
|
|
|
usb_AverageColorByte( dev );
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
dw = scan->sParam.Size.dwPixels;
|
2004-04-04 13:56:46 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
if( scan->sParam.bSource == SOURCE_ADF ) {
|
|
|
|
next = -1;
|
|
|
|
pixels = scan->sParam.Size.dwPixels - 1;
|
2004-04-04 13:56:46 +00:00
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = 1;
|
|
|
|
pixels = 0;
|
2004-04-04 13:56:46 +00:00
|
|
|
}
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
izoom = usb_GetScaler( scan );
|
2004-04-04 13:56:46 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
if( scan->dwFlag & SCANFLAG_RightAlign )
|
2004-04-04 13:56:46 +00:00
|
|
|
ls = Shift;
|
|
|
|
else
|
|
|
|
ls = 0;
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
switch( scan->fGrayFromColor ) {
|
2004-04-04 13:56:46 +00:00
|
|
|
|
|
|
|
case 1:
|
2005-07-04 09:54:31 +00:00
|
|
|
for( bitsput = 0, ddax = 0; dw; bitsput++ ) {
|
2004-04-04 13:56:46 +00:00
|
|
|
|
2004-07-02 13:09:36 +00:00
|
|
|
ddax -= _SCALER;
|
2004-04-04 13:56:46 +00:00
|
|
|
|
|
|
|
while((ddax < 0) && (dw > 0)) {
|
|
|
|
if( swap ) {
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pw[pixels] =
|
|
|
|
_HILO2WORD(scan->Red.pcw[bitsput].HiLo[0]) >> ls;
|
2004-04-04 13:56:46 +00:00
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pw[pixels] = scan->Red.pw[bitsput] >> ls;
|
2004-04-04 13:56:46 +00:00
|
|
|
}
|
2005-07-04 09:54:31 +00:00
|
|
|
pixels += next;
|
|
|
|
ddax += izoom;
|
2004-04-04 13:56:46 +00:00
|
|
|
dw--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2005-07-04 09:54:31 +00:00
|
|
|
for( bitsput = 0, ddax = 0; dw; bitsput++ ) {
|
2004-04-04 13:56:46 +00:00
|
|
|
|
2004-07-02 13:09:36 +00:00
|
|
|
ddax -= _SCALER;
|
2004-04-04 13:56:46 +00:00
|
|
|
|
|
|
|
while((ddax < 0) && (dw > 0)) {
|
|
|
|
if( swap ) {
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pw[pixels] =
|
|
|
|
_HILO2WORD(scan->Green.pcw[bitsput].HiLo[0]) >> ls;
|
2004-04-04 13:56:46 +00:00
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pw[pixels] = scan->Green.pw[bitsput] >> ls;
|
2004-04-04 13:56:46 +00:00
|
|
|
}
|
2005-07-04 09:54:31 +00:00
|
|
|
pixels += next;
|
|
|
|
ddax += izoom;
|
2004-04-04 13:56:46 +00:00
|
|
|
dw--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
2005-07-04 09:54:31 +00:00
|
|
|
for( bitsput = 0, ddax = 0; dw; bitsput++ ) {
|
2004-04-04 13:56:46 +00:00
|
|
|
|
2004-07-02 13:09:36 +00:00
|
|
|
ddax -= _SCALER;
|
2004-04-04 13:56:46 +00:00
|
|
|
|
|
|
|
while((ddax < 0) && (dw > 0)) {
|
|
|
|
if( swap ) {
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pw[pixels] =
|
|
|
|
_HILO2WORD(scan->Blue.pcw[bitsput].HiLo[0]) >> ls;
|
2004-04-04 13:56:46 +00:00
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pw[pixels] = scan->Blue.pw[bitsput] >> ls;
|
2004-04-04 13:56:46 +00:00
|
|
|
}
|
2005-07-04 09:54:31 +00:00
|
|
|
pixels += next;
|
|
|
|
ddax += izoom;
|
2004-04-04 13:56:46 +00:00
|
|
|
dw--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-28 11:25:53 +00:00
|
|
|
/**
|
|
|
|
*/
|
|
|
|
static void usb_ColorScaleGray16_2( Plustek_Device *dev )
|
|
|
|
{
|
|
|
|
u_char ls;
|
|
|
|
int izoom, ddax, next;
|
|
|
|
u_long dw, pixels, bitsput;
|
|
|
|
HiLoDef tmp;
|
|
|
|
SANE_Bool swap = usb_HostSwap();
|
|
|
|
ScanDef *scan = &dev->scanning;
|
|
|
|
|
|
|
|
usb_AverageColorByte( dev );
|
|
|
|
|
|
|
|
dw = scan->sParam.Size.dwPixels;
|
|
|
|
|
|
|
|
if( scan->sParam.bSource == SOURCE_ADF ) {
|
|
|
|
next = -1;
|
|
|
|
pixels = scan->sParam.Size.dwPixels - 1;
|
|
|
|
} else {
|
|
|
|
next = 1;
|
|
|
|
pixels = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
izoom = usb_GetScaler( scan );
|
|
|
|
|
|
|
|
if( scan->dwFlag & SCANFLAG_RightAlign )
|
|
|
|
ls = Shift;
|
|
|
|
else
|
|
|
|
ls = 0;
|
|
|
|
|
|
|
|
switch( scan->fGrayFromColor ) {
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
for( bitsput = 0, ddax = 0; dw; bitsput++ ) {
|
|
|
|
|
|
|
|
ddax -= _SCALER;
|
|
|
|
|
|
|
|
while((ddax < 0) && (dw > 0)) {
|
|
|
|
if( swap ) {
|
|
|
|
tmp = *((HiLoDef*)&scan->Red.pw[bitsput]);
|
|
|
|
scan->UserBuf.pw[pixels] = _HILO2WORD(tmp) >> ls;
|
|
|
|
} else {
|
|
|
|
scan->UserBuf.pw[pixels] = scan->Red.pw[dw] >> ls;
|
|
|
|
}
|
|
|
|
pixels += next;
|
|
|
|
ddax += izoom;
|
|
|
|
dw--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
for( bitsput = 0, ddax = 0; dw; bitsput++ ) {
|
|
|
|
|
|
|
|
ddax -= _SCALER;
|
|
|
|
|
|
|
|
while((ddax < 0) && (dw > 0)) {
|
|
|
|
if( swap ) {
|
|
|
|
tmp = *((HiLoDef*)&scan->Green.pw[bitsput]);
|
|
|
|
scan->UserBuf.pw[pixels] = _HILO2WORD(tmp) >> ls;
|
|
|
|
} else {
|
|
|
|
scan->UserBuf.pw[pixels] = scan->Green.pw[bitsput] >> ls;
|
|
|
|
}
|
|
|
|
pixels += next;
|
|
|
|
ddax += izoom;
|
|
|
|
dw--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
for( bitsput = 0, ddax = 0; dw; bitsput++ ) {
|
|
|
|
|
|
|
|
ddax -= _SCALER;
|
|
|
|
|
|
|
|
while((ddax < 0) && (dw > 0)) {
|
|
|
|
if( swap ) {
|
|
|
|
tmp = *((HiLoDef*)&scan->Blue.pw[bitsput]);
|
|
|
|
scan->UserBuf.pw[pixels] = _HILO2WORD(tmp) >> ls;
|
|
|
|
} else {
|
|
|
|
scan->UserBuf.pw[pixels] = scan->Blue.pw[bitsput] >> ls;
|
|
|
|
}
|
|
|
|
pixels += next;
|
|
|
|
ddax += izoom;
|
|
|
|
dw--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-04 13:56:46 +00:00
|
|
|
/** here we copy and scale from scanner world to user world...
|
2001-12-29 15:34:03 +00:00
|
|
|
*/
|
2004-07-05 12:59:03 +00:00
|
|
|
static void usb_ColorScale8( Plustek_Device *dev )
|
2001-12-29 15:34:03 +00:00
|
|
|
{
|
2005-07-04 09:54:31 +00:00
|
|
|
int izoom, ddax, next;
|
|
|
|
u_long dw, pixels, bitsput;
|
|
|
|
ScanDef *scan = &dev->scanning;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
|
|
|
usb_AverageColorByte( dev );
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
dw = scan->sParam.Size.dwPixels;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
if( scan->sParam.bSource == SOURCE_ADF ) {
|
|
|
|
next = -1;
|
|
|
|
pixels = scan->sParam.Size.dwPixels - 1;
|
2001-12-29 15:34:03 +00:00
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = 1;
|
|
|
|
pixels = 0;
|
2001-12-29 15:34:03 +00:00
|
|
|
}
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
izoom = usb_GetScaler( scan );
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
for( bitsput = 0, ddax = 0; dw; bitsput++ ) {
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2001-12-30 13:35:48 +00:00
|
|
|
ddax -= _SCALER;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
|
|
|
while((ddax < 0) && (dw > 0)) {
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pb_rgb[pixels].Red =
|
|
|
|
scan->Red.pcb[bitsput].a_bColor[0];
|
|
|
|
scan->UserBuf.pb_rgb[pixels].Green =
|
|
|
|
scan->Green.pcb[bitsput].a_bColor[0];
|
|
|
|
scan->UserBuf.pb_rgb[pixels].Blue =
|
|
|
|
scan->Blue.pcb[bitsput].a_bColor[0];
|
|
|
|
pixels += next;
|
|
|
|
ddax += izoom;
|
2001-12-29 15:34:03 +00:00
|
|
|
dw--;
|
|
|
|
}
|
2005-07-04 09:54:31 +00:00
|
|
|
}
|
2001-12-29 15:34:03 +00:00
|
|
|
}
|
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
static void usb_ColorScale8_2( Plustek_Device *dev )
|
2002-09-28 11:31:53 +00:00
|
|
|
{
|
2005-07-04 09:54:31 +00:00
|
|
|
int izoom, ddax, next;
|
|
|
|
u_long dw, pixels, bitsput;
|
|
|
|
ScanDef *scan = &dev->scanning;
|
2002-09-28 11:31:53 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
dw = scan->sParam.Size.dwPixels;
|
2002-09-28 11:31:53 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
if( scan->sParam.bSource == SOURCE_ADF ) {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = -1;
|
|
|
|
pixels = scan->sParam.Size.dwPixels - 1;
|
2002-09-28 11:31:53 +00:00
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = 1;
|
|
|
|
pixels = 0;
|
2002-09-28 11:31:53 +00:00
|
|
|
}
|
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
izoom = usb_GetScaler( scan );
|
2002-09-28 11:31:53 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
for( bitsput = 0, ddax = 0; dw; bitsput++ ) {
|
2002-09-28 11:31:53 +00:00
|
|
|
|
|
|
|
ddax -= _SCALER;
|
|
|
|
|
|
|
|
while((ddax < 0) && (dw > 0)) {
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pb_rgb[pixels].Red = scan->Red.pb[bitsput];
|
|
|
|
scan->UserBuf.pb_rgb[pixels].Green = scan->Green.pb[bitsput];
|
|
|
|
scan->UserBuf.pb_rgb[pixels].Blue = scan->Blue.pb[bitsput];
|
2004-07-05 12:59:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
pixels += next;
|
|
|
|
ddax += izoom;
|
2002-09-28 11:31:53 +00:00
|
|
|
dw--;
|
|
|
|
}
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
2002-09-28 11:31:53 +00:00
|
|
|
}
|
|
|
|
|
2002-10-04 17:55:55 +00:00
|
|
|
/**
|
2001-12-29 15:34:03 +00:00
|
|
|
*/
|
2004-07-05 12:59:03 +00:00
|
|
|
static void usb_ColorScale16( Plustek_Device *dev )
|
2001-12-29 15:34:03 +00:00
|
|
|
{
|
2003-12-18 13:24:26 +00:00
|
|
|
u_char ls;
|
2005-07-04 09:54:31 +00:00
|
|
|
int izoom, ddax, next;
|
|
|
|
u_long dw, pixels, bitsput;
|
|
|
|
SANE_Bool swap = usb_HostSwap();
|
|
|
|
ScanDef *scan = &dev->scanning;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
|
|
|
usb_AverageColorWord( dev );
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
dw = scan->sParam.Size.dwPixels;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
if( scan->sParam.bSource == SOURCE_ADF ) {
|
|
|
|
next = -1;
|
|
|
|
pixels = scan->sParam.Size.dwPixels - 1;
|
2001-12-29 15:34:03 +00:00
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = 1;
|
|
|
|
pixels = 0;
|
2001-12-29 15:34:03 +00:00
|
|
|
}
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
izoom = usb_GetScaler( scan );
|
2004-04-04 13:56:46 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
if( scan->dwFlag & SCANFLAG_RightAlign )
|
2003-12-18 13:24:26 +00:00
|
|
|
ls = Shift;
|
|
|
|
else
|
|
|
|
ls = 0;
|
2004-04-04 13:56:46 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
for( bitsput = 0, ddax = 0; dw; bitsput++ ) {
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2003-12-18 13:24:26 +00:00
|
|
|
ddax -= _SCALER;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2003-12-18 13:24:26 +00:00
|
|
|
while((ddax < 0) && (dw > 0)) {
|
|
|
|
|
|
|
|
if( swap ) {
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pw_rgb[pixels].Red =
|
|
|
|
_HILO2WORD(scan->Red.pcw[bitsput].HiLo[0]) >> ls;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pw_rgb[pixels].Green =
|
|
|
|
_HILO2WORD(scan->Green.pcw[bitsput].HiLo[0]) >> ls;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pw_rgb[pixels].Blue =
|
|
|
|
_HILO2WORD(scan->Blue.pcw[bitsput].HiLo[0]) >> ls;
|
2003-12-18 13:24:26 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
} else {
|
2003-12-18 13:24:26 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pw_rgb[pixels].Red = scan->Red.pw[bitsput]>>ls;
|
|
|
|
scan->UserBuf.pw_rgb[pixels].Green = scan->Green.pw[bitsput] >> ls;
|
|
|
|
scan->UserBuf.pw_rgb[pixels].Blue = scan->Blue.pw[bitsput] >> ls;
|
2001-12-29 15:34:03 +00:00
|
|
|
}
|
2005-07-04 09:54:31 +00:00
|
|
|
pixels += next;
|
|
|
|
ddax += izoom;
|
2003-12-18 13:24:26 +00:00
|
|
|
dw--;
|
|
|
|
}
|
2005-07-04 09:54:31 +00:00
|
|
|
}
|
2001-12-29 15:34:03 +00:00
|
|
|
}
|
|
|
|
|
2002-10-04 17:55:55 +00:00
|
|
|
/**
|
|
|
|
*/
|
2004-07-05 12:59:03 +00:00
|
|
|
static void usb_ColorScale16_2( Plustek_Device *dev )
|
2002-10-04 17:55:55 +00:00
|
|
|
{
|
2005-07-04 09:54:31 +00:00
|
|
|
u_char ls;
|
|
|
|
HiLoDef tmp;
|
|
|
|
int izoom, ddax, next;
|
|
|
|
u_long dw, pixels, bitsput;
|
|
|
|
SANE_Bool swap = usb_HostSwap();
|
|
|
|
ScanDef *scan = &dev->scanning;
|
2002-10-04 17:55:55 +00:00
|
|
|
|
|
|
|
usb_AverageColorWord( dev );
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
dw = scan->sParam.Size.dwPixels;
|
2002-10-04 17:55:55 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
if( scan->sParam.bSource == SOURCE_ADF ) {
|
|
|
|
next = -1;
|
|
|
|
pixels = scan->sParam.Size.dwPixels - 1;
|
2002-10-04 17:55:55 +00:00
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = 1;
|
|
|
|
pixels = 0;
|
2002-10-04 17:55:55 +00:00
|
|
|
}
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
izoom = usb_GetScaler( scan );
|
2002-10-04 17:55:55 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
if( scan->dwFlag & SCANFLAG_RightAlign )
|
2003-12-18 13:24:26 +00:00
|
|
|
ls = Shift;
|
|
|
|
else
|
|
|
|
ls = 0;
|
2002-10-04 17:55:55 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
for( bitsput = 0, ddax = 0; dw; bitsput++ ) {
|
2002-10-04 17:55:55 +00:00
|
|
|
|
2003-12-18 13:24:26 +00:00
|
|
|
ddax -= _SCALER;
|
2002-10-04 17:55:55 +00:00
|
|
|
|
2003-12-18 13:24:26 +00:00
|
|
|
while((ddax < 0) && (dw > 0)) {
|
2002-10-04 17:55:55 +00:00
|
|
|
|
2003-12-18 13:24:26 +00:00
|
|
|
if( swap ) {
|
|
|
|
|
2005-08-15 14:55:24 +00:00
|
|
|
tmp = *((HiLoDef*)&scan->Red.pw[bitsput]);
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pw_rgb[pixels].Red = _HILO2WORD(tmp) >> ls;
|
2002-10-04 17:55:55 +00:00
|
|
|
|
2005-08-15 14:55:24 +00:00
|
|
|
tmp = *((HiLoDef*)&scan->Green.pw[bitsput]);
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pw_rgb[pixels].Green = _HILO2WORD(tmp) >> ls;
|
2002-10-04 17:55:55 +00:00
|
|
|
|
2005-08-15 14:55:24 +00:00
|
|
|
tmp = *((HiLoDef*)&scan->Blue.pw[bitsput]);
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pw_rgb[pixels].Blue = _HILO2WORD(tmp) >> ls;
|
2002-10-04 17:55:55 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
} else {
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pw_rgb[pixels].Red = scan->Red.pw[bitsput] >> ls;
|
|
|
|
scan->UserBuf.pw_rgb[pixels].Green = scan->Green.pw[bitsput] >> ls;
|
|
|
|
scan->UserBuf.pw_rgb[pixels].Blue = scan->Blue.pw[bitsput] >> ls;
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
2005-07-04 09:54:31 +00:00
|
|
|
pixels += next;
|
|
|
|
ddax += izoom;
|
2004-07-05 12:59:03 +00:00
|
|
|
dw--;
|
|
|
|
}
|
2001-12-29 15:34:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-10 13:32:11 +00:00
|
|
|
/**
|
|
|
|
*/
|
2004-07-05 12:59:03 +00:00
|
|
|
static void usb_ColorScalePseudo16( Plustek_Device *dev )
|
2003-01-10 13:32:11 +00:00
|
|
|
{
|
2005-07-04 09:54:31 +00:00
|
|
|
int izoom, ddax, next;
|
|
|
|
u_short wR, wG, wB;
|
|
|
|
u_long dw, pixels, bitsput;
|
|
|
|
ScanDef *scan = &dev->scanning;
|
2003-01-10 13:32:11 +00:00
|
|
|
|
|
|
|
usb_AverageColorByte( dev );
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
dw = scan->sParam.Size.dwPixels;
|
2004-07-05 12:59:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
if( scan->sParam.bSource == SOURCE_ADF ) {
|
|
|
|
next = -1;
|
|
|
|
pixels = scan->sParam.Size.dwPixels - 1;
|
2004-07-05 12:59:03 +00:00
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = 1;
|
|
|
|
pixels = 0;
|
2003-01-10 13:32:11 +00:00
|
|
|
}
|
2004-07-05 12:59:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
izoom = usb_GetScaler( scan );
|
2003-01-10 13:32:11 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
wR = (u_short)scan->Red.pcb[0].a_bColor[0];
|
|
|
|
wG = (u_short)scan->Green.pcb[0].a_bColor[1];
|
|
|
|
wB = (u_short)scan->Blue.pcb[0].a_bColor[2];
|
2004-04-04 13:56:46 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
for( bitsput = 0, ddax = 0; dw; bitsput++ ) {
|
2004-04-04 13:56:46 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
ddax -= _SCALER;
|
2004-04-04 13:56:46 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
while((ddax < 0) && (dw > 0)) {
|
2004-04-04 13:56:46 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pw_rgb[pixels].Red =
|
|
|
|
(wR + scan->Red.pcb[bitsput].a_bColor[0]) << bShift;
|
2004-07-05 12:59:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pw_rgb[pixels].Green =
|
|
|
|
(wG + scan->Green.pcb[bitsput].a_bColor[0]) << bShift;
|
2004-07-05 12:59:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->UserBuf.pw_rgb[pixels].Blue =
|
|
|
|
(wB + scan->Blue.pcb[bitsput].a_bColor[0]) << bShift;
|
2004-07-05 12:59:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
pixels += next;
|
|
|
|
ddax += izoom;
|
2004-07-05 12:59:03 +00:00
|
|
|
dw--;
|
2004-04-04 13:56:46 +00:00
|
|
|
}
|
2005-07-04 09:54:31 +00:00
|
|
|
|
|
|
|
wR = (u_short)scan->Red.pcb[bitsput].a_bColor[0];
|
|
|
|
wG = (u_short)scan->Green.pcb[bitsput].a_bColor[0];
|
|
|
|
wB = (u_short)scan->Blue.pcb[bitsput].a_bColor[0];
|
|
|
|
}
|
2004-04-04 13:56:46 +00:00
|
|
|
}
|
|
|
|
|
2003-01-10 13:32:11 +00:00
|
|
|
/**
|
2001-12-29 15:34:03 +00:00
|
|
|
*/
|
2004-07-05 12:59:03 +00:00
|
|
|
static void usb_BWScale( Plustek_Device *dev )
|
2001-12-29 15:34:03 +00:00
|
|
|
{
|
2005-07-04 09:54:31 +00:00
|
|
|
u_char tmp, *dest, *src;
|
2001-12-29 15:34:03 +00:00
|
|
|
int izoom, ddax;
|
2001-12-30 13:35:48 +00:00
|
|
|
u_long i, dw;
|
2005-07-04 09:54:31 +00:00
|
|
|
ScanDef *scan = &dev->scanning;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
src = scan->Green.pb;
|
|
|
|
if( scan->sParam.bSource == SOURCE_ADF ) {
|
2001-12-29 15:34:03 +00:00
|
|
|
int iSum = wSum;
|
2005-07-04 09:54:31 +00:00
|
|
|
usb_ReverseBitStream(scan->Green.pb, scan->UserBuf.pb,
|
|
|
|
scan->sParam.Size.dwValidPixels,
|
|
|
|
scan->dwBytesLine, scan->sParam.PhyDpi.x,
|
|
|
|
scan->sParam.UserDpi.x, 1 );
|
2001-12-29 15:34:03 +00:00
|
|
|
wSum = iSum;
|
|
|
|
return;
|
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
dest = scan->UserBuf.pb;
|
2001-12-29 15:34:03 +00:00
|
|
|
}
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
izoom = usb_GetScaler( scan );
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
memset( dest, 0, scan->dwBytesLine );
|
2001-12-29 15:34:03 +00:00
|
|
|
ddax = 0;
|
2004-07-05 12:59:03 +00:00
|
|
|
dw = 0;
|
2003-01-10 13:32:11 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
for( i = 0; i < scan->sParam.Size.dwValidPixels; i++ ) {
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2001-12-30 13:35:48 +00:00
|
|
|
ddax -= _SCALER;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
|
|
|
while( ddax < 0 ) {
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
tmp = src[(i>>3)];
|
2004-07-05 12:59:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
if((dw>>3) < scan->sParam.Size.dwValidPixels ) {
|
2001-12-29 15:34:03 +00:00
|
|
|
|
|
|
|
if( 0 != (tmp &= (1 << ((~(i & 0x7))&0x7))))
|
2005-07-04 09:54:31 +00:00
|
|
|
dest[dw>>3] |= (1 << ((~(dw & 0x7))&0x7));
|
2001-12-29 15:34:03 +00:00
|
|
|
}
|
|
|
|
dw++;
|
|
|
|
ddax += izoom;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-10 13:32:11 +00:00
|
|
|
/**
|
2001-12-29 15:34:03 +00:00
|
|
|
*/
|
2004-07-05 12:59:03 +00:00
|
|
|
static void usb_BWScaleFromColor( Plustek_Device *dev )
|
2001-12-29 15:34:03 +00:00
|
|
|
{
|
2005-07-04 09:54:31 +00:00
|
|
|
u_char d, s, *dest;
|
2004-07-05 12:59:03 +00:00
|
|
|
u_short j;
|
2005-07-04 09:54:31 +00:00
|
|
|
u_long pixels;
|
|
|
|
int izoom, ddax, next;
|
2004-07-05 12:59:03 +00:00
|
|
|
ColorByteDef *src;
|
2005-07-04 09:54:31 +00:00
|
|
|
ScanDef *scan = &dev->scanning;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
if (scan->sParam.bSource == SOURCE_ADF) {
|
2005-07-04 09:54:31 +00:00
|
|
|
dest = scan->UserBuf.pb + scan->sParam.Size.dwPixels - 1;
|
|
|
|
next = -1;
|
2001-12-29 15:34:03 +00:00
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
dest = scan->UserBuf.pb;
|
|
|
|
next = 1;
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* setup the source buffer */
|
|
|
|
switch(scan->fGrayFromColor) {
|
|
|
|
case 1: src = scan->Red.pcb; break;
|
|
|
|
case 3: src = scan->Blue.pcb; break;
|
|
|
|
default: src = scan->Green.pcb; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
izoom = usb_GetScaler( scan );
|
|
|
|
ddax = 0;
|
|
|
|
|
|
|
|
d = j = 0;
|
2005-07-04 09:54:31 +00:00
|
|
|
for( pixels = scan->sParam.Size.dwPixels; pixels; src++ ) {
|
2004-07-05 12:59:03 +00:00
|
|
|
|
|
|
|
ddax -= _SCALER;
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
while((ddax < 0) && (pixels > 0)) {
|
2004-07-05 12:59:03 +00:00
|
|
|
|
|
|
|
s = src->a_bColor[0];
|
|
|
|
if( s != 0 )
|
|
|
|
d |= BitTable[j];
|
|
|
|
j++;
|
|
|
|
if( j == 8 ) {
|
2005-07-04 09:54:31 +00:00
|
|
|
*dest = d;
|
|
|
|
dest += next;
|
2004-07-05 12:59:03 +00:00
|
|
|
d = j = 0;
|
|
|
|
}
|
|
|
|
ddax += izoom;
|
2005-07-04 09:54:31 +00:00
|
|
|
pixels--;
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
|
|
|
}
|
2001-12-29 15:34:03 +00:00
|
|
|
}
|
|
|
|
|
2006-05-28 11:25:53 +00:00
|
|
|
/**
|
|
|
|
*/
|
|
|
|
static void usb_BWScaleFromColor_2( Plustek_Device *dev )
|
|
|
|
{
|
|
|
|
u_char d, *dest, *src;
|
|
|
|
u_short j;
|
|
|
|
u_long pixels;
|
|
|
|
int izoom, ddax, next;
|
|
|
|
ScanDef *scan = &dev->scanning;
|
|
|
|
|
|
|
|
if (scan->sParam.bSource == SOURCE_ADF) {
|
|
|
|
dest = scan->UserBuf.pb + scan->sParam.Size.dwPixels - 1;
|
|
|
|
next = -1;
|
|
|
|
} else {
|
|
|
|
dest = scan->UserBuf.pb;
|
|
|
|
next = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* setup the source buffer */
|
|
|
|
switch(scan->fGrayFromColor) {
|
|
|
|
case 1: src = scan->Red.pb; break;
|
|
|
|
case 3: src = scan->Blue.pb; break;
|
|
|
|
default: src = scan->Green.pb; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
izoom = usb_GetScaler( scan );
|
|
|
|
ddax = 0;
|
|
|
|
|
|
|
|
d = j = 0;
|
|
|
|
for( pixels = scan->sParam.Size.dwPixels; pixels; src++ ) {
|
|
|
|
|
|
|
|
ddax -= _SCALER;
|
|
|
|
|
|
|
|
while((ddax < 0) && (pixels > 0)) {
|
|
|
|
|
|
|
|
if( *src != 0 )
|
|
|
|
d |= BitTable[j];
|
|
|
|
j++;
|
|
|
|
if( j == 8 ) {
|
|
|
|
*dest = d;
|
|
|
|
dest += next;
|
|
|
|
d = j = 0;
|
|
|
|
}
|
|
|
|
ddax += izoom;
|
|
|
|
pixels--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-10 13:32:11 +00:00
|
|
|
/**
|
2001-12-29 15:34:03 +00:00
|
|
|
*/
|
2004-07-05 12:59:03 +00:00
|
|
|
static void usb_GrayScale8( Plustek_Device *dev )
|
2001-12-29 15:34:03 +00:00
|
|
|
{
|
2005-07-04 09:54:31 +00:00
|
|
|
u_char *dest, *src;
|
|
|
|
int izoom, ddax, next;
|
|
|
|
u_long pixels;
|
|
|
|
ScanDef *scan = &dev->scanning;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
|
|
|
usb_AverageGrayByte( dev );
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
src = scan->Green.pb;
|
2004-07-05 12:59:03 +00:00
|
|
|
if( scan->sParam.bSource == SOURCE_ADF ) {
|
2005-07-04 09:54:31 +00:00
|
|
|
dest = scan->UserBuf.pb + scan->sParam.Size.dwPixels - 1;
|
|
|
|
next = -1;
|
2001-12-29 15:34:03 +00:00
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
dest = scan->UserBuf.pb;
|
|
|
|
next = 1;
|
2001-12-29 15:34:03 +00:00
|
|
|
}
|
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
izoom = usb_GetScaler( scan );
|
2003-03-03 14:34:20 +00:00
|
|
|
ddax = 0;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
for( pixels = scan->sParam.Size.dwPixels; pixels; src++ ) {
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2001-12-30 13:35:48 +00:00
|
|
|
ddax -= _SCALER;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
while((ddax < 0) && (pixels > 0)) {
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
*dest = *src;
|
|
|
|
dest += next;
|
2001-12-29 15:34:03 +00:00
|
|
|
ddax += izoom;
|
2005-07-04 09:54:31 +00:00
|
|
|
pixels--;
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
2001-12-29 15:34:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-10 13:32:11 +00:00
|
|
|
/**
|
2001-12-29 15:34:03 +00:00
|
|
|
*/
|
2004-07-05 12:59:03 +00:00
|
|
|
static void usb_GrayScale16( Plustek_Device *dev )
|
2001-12-29 15:34:03 +00:00
|
|
|
{
|
2003-12-18 13:24:26 +00:00
|
|
|
u_char ls;
|
2005-07-04 09:54:31 +00:00
|
|
|
int izoom, ddax, next;
|
|
|
|
u_short *dest;
|
|
|
|
u_long pixels;
|
|
|
|
HiLoDef *pwm;
|
|
|
|
ScanDef *scan = &dev->scanning;
|
2004-07-05 12:59:03 +00:00
|
|
|
SANE_Bool swap = usb_HostSwap();
|
2001-12-29 15:34:03 +00:00
|
|
|
|
|
|
|
usb_AverageGrayWord( dev);
|
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
pwm = scan->Green.philo;
|
|
|
|
wSum = scan->sParam.PhyDpi.x;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
if( scan->sParam.bSource == SOURCE_ADF ) {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = -1;
|
|
|
|
dest = scan->UserBuf.pw + scan->sParam.Size.dwPixels - 1;
|
2001-12-29 15:34:03 +00:00
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = 1;
|
|
|
|
dest = scan->UserBuf.pw;
|
2001-12-29 15:34:03 +00:00
|
|
|
}
|
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
izoom = usb_GetScaler( scan );
|
2001-12-29 15:34:03 +00:00
|
|
|
ddax = 0;
|
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
if( scan->dwFlag & SCANFLAG_RightAlign )
|
2003-12-18 13:24:26 +00:00
|
|
|
ls = Shift;
|
|
|
|
else
|
|
|
|
ls = 0;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
for( pixels = scan->sParam.Size.dwPixels; pixels; pwm++ ) {
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2003-12-18 13:24:26 +00:00
|
|
|
ddax -= _SCALER;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
while((ddax < 0) && (pixels > 0)) {
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2003-12-18 13:24:26 +00:00
|
|
|
if( swap )
|
2005-07-04 09:54:31 +00:00
|
|
|
*dest = _PHILO2WORD(pwm) >> ls;
|
2003-12-18 13:24:26 +00:00
|
|
|
else
|
2007-12-17 14:28:13 +00:00
|
|
|
*dest = _PLOHI2WORD(pwm) >> ls;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
dest += next;
|
|
|
|
ddax += izoom;
|
|
|
|
pixels--;
|
2003-12-18 13:24:26 +00:00
|
|
|
}
|
2001-12-29 15:34:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-10 13:32:11 +00:00
|
|
|
/**
|
2001-12-29 15:34:03 +00:00
|
|
|
*/
|
2004-07-05 12:59:03 +00:00
|
|
|
static void usb_GrayScalePseudo16( Plustek_Device *dev )
|
2001-12-29 15:34:03 +00:00
|
|
|
{
|
2005-07-04 09:54:31 +00:00
|
|
|
u_char *src;
|
|
|
|
int izoom, ddax, next;
|
|
|
|
u_short *dest, g;
|
|
|
|
u_long pixels;
|
|
|
|
ScanDef *scan = &dev->scanning;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
|
|
|
usb_AverageGrayByte( dev );
|
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
if( scan->sParam.bSource == SOURCE_ADF ) {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = -1;
|
|
|
|
dest = scan->UserBuf.pw + scan->sParam.Size.dwPixels - 1;
|
2001-12-29 15:34:03 +00:00
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
next = 1;
|
|
|
|
dest = scan->UserBuf.pw;
|
2001-12-29 15:34:03 +00:00
|
|
|
}
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
src = scan->Green.pb;
|
|
|
|
g = (u_short)*src;
|
2003-03-03 14:34:20 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
izoom = usb_GetScaler( scan );
|
2001-12-29 15:34:03 +00:00
|
|
|
ddax = 0;
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
for( pixels = scan->sParam.Size.dwPixels; pixels; src++ ) {
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2001-12-30 13:35:48 +00:00
|
|
|
ddax -= _SCALER;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
while((ddax < 0) && (pixels > 0)) {
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
*dest = (g + *src) << bShift;
|
|
|
|
dest += next;
|
|
|
|
ddax += izoom;
|
|
|
|
pixels--;
|
|
|
|
}
|
|
|
|
g = (u_short)*src;
|
2001-12-29 15:34:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-18 13:24:26 +00:00
|
|
|
/** function to select the apropriate pixel copy function
|
2001-12-29 15:34:03 +00:00
|
|
|
*/
|
2004-07-05 12:59:03 +00:00
|
|
|
static void usb_GetImageProc( Plustek_Device *dev )
|
2001-12-29 15:34:03 +00:00
|
|
|
{
|
2005-07-04 09:54:31 +00:00
|
|
|
ScanDef *scan = &dev->scanning;
|
|
|
|
DCapsDef *sc = &dev->usbDev.Caps;
|
|
|
|
HWDef *hw = &dev->usbDev.HwSetting;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
bShift = 0;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
if( scan->sParam.UserDpi.x != scan->sParam.PhyDpi.x ) {
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2002-09-28 11:31:53 +00:00
|
|
|
/* Pixel scaling... */
|
2005-07-04 09:54:31 +00:00
|
|
|
switch( scan->sParam.bDataType ) {
|
2001-12-29 15:34:03 +00:00
|
|
|
|
|
|
|
case SCANDATATYPE_Color:
|
2005-07-04 09:54:31 +00:00
|
|
|
if (scan->sParam.bBitDepth > 8) {
|
2002-10-04 17:55:55 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
if( usb_IsCISDevice(dev)){
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->pfnProcess = usb_ColorScale16_2;
|
2002-10-04 17:55:55 +00:00
|
|
|
DBG( _DBG_INFO, "ImageProc is: ColorScale16_2\n" );
|
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->pfnProcess = usb_ColorScale16;
|
2002-10-04 17:55:55 +00:00
|
|
|
DBG( _DBG_INFO, "ImageProc is: ColorScale16\n" );
|
|
|
|
}
|
2005-07-04 09:54:31 +00:00
|
|
|
if (scan->fGrayFromColor) {
|
2006-05-28 11:25:53 +00:00
|
|
|
if( usb_IsCISDevice(dev)){
|
|
|
|
scan->pfnProcess = usb_ColorScaleGray16_2;
|
|
|
|
DBG( _DBG_INFO, "ImageProc is: ColorScaleGray16_2\n" );
|
|
|
|
} else {
|
|
|
|
scan->pfnProcess = usb_ColorScaleGray16;
|
|
|
|
DBG( _DBG_INFO, "ImageProc is: ColorScaleGray16\n" );
|
|
|
|
}
|
2004-04-04 13:56:46 +00:00
|
|
|
}
|
2005-07-04 09:54:31 +00:00
|
|
|
} else if (scan->dwFlag & SCANFLAG_Pseudo48) {
|
|
|
|
scan->pfnProcess = usb_ColorScalePseudo16;
|
2001-12-29 15:34:03 +00:00
|
|
|
DBG( _DBG_INFO, "ImageProc is: ColorScalePseudo16\n" );
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
} else if (scan->fGrayFromColor) {
|
2003-01-10 13:32:11 +00:00
|
|
|
|
2006-05-28 11:25:53 +00:00
|
|
|
if( usb_IsCISDevice(dev)){
|
|
|
|
if (scan->fGrayFromColor > 7 ) {
|
|
|
|
scan->pfnProcess = usb_BWScaleFromColor_2;
|
|
|
|
DBG( _DBG_INFO, "ImageProc is: BWScaleFromColor_2\n" );
|
|
|
|
} else {
|
|
|
|
scan->pfnProcess = usb_ColorScaleGray_2;
|
|
|
|
DBG( _DBG_INFO, "ImageProc is: ColorScaleGray_2\n" );
|
|
|
|
}
|
2003-01-10 13:32:11 +00:00
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
if (scan->fGrayFromColor > 7 ) {
|
|
|
|
scan->pfnProcess = usb_BWScaleFromColor;
|
2004-07-05 12:59:03 +00:00
|
|
|
DBG( _DBG_INFO, "ImageProc is: BWScaleFromColor\n" );
|
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->pfnProcess = usb_ColorScaleGray;
|
2004-07-05 12:59:03 +00:00
|
|
|
DBG( _DBG_INFO, "ImageProc is: ColorScaleGray\n" );
|
|
|
|
}
|
2003-01-10 13:32:11 +00:00
|
|
|
}
|
2001-12-29 15:34:03 +00:00
|
|
|
} else {
|
2002-09-28 11:31:53 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
if( usb_IsCISDevice(dev)){
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->pfnProcess = usb_ColorScale8_2;
|
2002-09-28 11:31:53 +00:00
|
|
|
DBG( _DBG_INFO, "ImageProc is: ColorScale8_2\n" );
|
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->pfnProcess = usb_ColorScale8;
|
2002-09-28 11:31:53 +00:00
|
|
|
DBG( _DBG_INFO, "ImageProc is: ColorScale8\n" );
|
|
|
|
}
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
2001-12-29 15:34:03 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SCANDATATYPE_Gray:
|
2005-07-04 09:54:31 +00:00
|
|
|
if (scan->sParam.bBitDepth > 8) {
|
|
|
|
scan->pfnProcess = usb_GrayScale16;
|
2001-12-29 15:34:03 +00:00
|
|
|
DBG( _DBG_INFO, "ImageProc is: GrayScale16\n" );
|
|
|
|
} else {
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
if (scan->dwFlag & SCANFLAG_Pseudo48) {
|
|
|
|
scan->pfnProcess = usb_GrayScalePseudo16;
|
2001-12-29 15:34:03 +00:00
|
|
|
DBG( _DBG_INFO, "ImageProc is: GrayScalePseudo16\n" );
|
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->pfnProcess = usb_GrayScale8;
|
2001-12-29 15:34:03 +00:00
|
|
|
DBG( _DBG_INFO, "ImageProc is: GrayScale8\n" );
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
|
|
|
}
|
2001-12-29 15:34:03 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->pfnProcess = usb_BWScale;
|
2001-12-30 13:35:48 +00:00
|
|
|
DBG( _DBG_INFO, "ImageProc is: BWScale\n" );
|
2001-12-29 15:34:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* Pixel copy */
|
2005-07-04 09:54:31 +00:00
|
|
|
switch( scan->sParam.bDataType ) {
|
2001-12-29 15:34:03 +00:00
|
|
|
|
|
|
|
case SCANDATATYPE_Color:
|
2005-07-04 09:54:31 +00:00
|
|
|
if (scan->sParam.bBitDepth > 8) {
|
2006-05-28 11:25:53 +00:00
|
|
|
if( usb_IsCISDevice(dev)){
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->pfnProcess = usb_ColorDuplicate16_2;
|
2002-09-28 11:31:53 +00:00
|
|
|
DBG( _DBG_INFO, "ImageProc is: ColorDuplicate16_2\n" );
|
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->pfnProcess = usb_ColorDuplicate16;
|
2002-09-28 11:31:53 +00:00
|
|
|
DBG( _DBG_INFO, "ImageProc is: ColorDuplicate16\n" );
|
|
|
|
}
|
2005-07-04 09:54:31 +00:00
|
|
|
if (scan->fGrayFromColor) {
|
2006-05-28 11:25:53 +00:00
|
|
|
if( usb_IsCISDevice(dev)){
|
|
|
|
scan->pfnProcess = usb_ColorDuplicateGray16_2;
|
|
|
|
DBG( _DBG_INFO, "ImageProc is: ColorDuplicateGray16_2\n" );
|
|
|
|
} else {
|
|
|
|
scan->pfnProcess = usb_ColorDuplicateGray16;
|
|
|
|
DBG( _DBG_INFO, "ImageProc is: ColorDuplicateGray16\n" );
|
|
|
|
}
|
2004-04-04 13:56:46 +00:00
|
|
|
}
|
2005-07-04 09:54:31 +00:00
|
|
|
} else if (scan->dwFlag & SCANFLAG_Pseudo48) {
|
|
|
|
scan->pfnProcess = usb_ColorDuplicatePseudo16;
|
2001-12-29 15:34:03 +00:00
|
|
|
DBG( _DBG_INFO, "ImageProc is: ColorDuplicatePseudo16\n" );
|
2005-07-04 09:54:31 +00:00
|
|
|
} else if (scan->fGrayFromColor) {
|
2006-05-28 11:25:53 +00:00
|
|
|
if( usb_IsCISDevice(dev)){
|
|
|
|
if (scan->fGrayFromColor > 7 ) {
|
|
|
|
scan->pfnProcess = usb_BWDuplicateFromColor_2;
|
|
|
|
DBG( _DBG_INFO, "ImageProc is: BWDuplicateFromColor_2\n" );
|
|
|
|
} else {
|
|
|
|
scan->pfnProcess = usb_ColorDuplicateGray_2;
|
|
|
|
DBG( _DBG_INFO, "ImageProc is: ColorDuplicateGray_2\n" );
|
|
|
|
}
|
2003-01-10 13:32:11 +00:00
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
if (scan->fGrayFromColor > 7 ) {
|
|
|
|
scan->pfnProcess = usb_BWDuplicateFromColor;
|
2004-07-05 12:59:03 +00:00
|
|
|
DBG( _DBG_INFO, "ImageProc is: BWDuplicateFromColor\n" );
|
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->pfnProcess = usb_ColorDuplicateGray;
|
2004-07-05 12:59:03 +00:00
|
|
|
DBG( _DBG_INFO, "ImageProc is: ColorDuplicateGray\n" );
|
|
|
|
}
|
2003-01-10 13:32:11 +00:00
|
|
|
}
|
2001-12-29 15:34:03 +00:00
|
|
|
} else {
|
2004-07-05 12:59:03 +00:00
|
|
|
if( usb_IsCISDevice(dev)){
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->pfnProcess = usb_ColorDuplicate8_2;
|
2002-09-28 11:31:53 +00:00
|
|
|
DBG( _DBG_INFO, "ImageProc is: ColorDuplicate8_2\n" );
|
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->pfnProcess = usb_ColorDuplicate8;
|
2002-09-28 11:31:53 +00:00
|
|
|
DBG( _DBG_INFO, "ImageProc is: ColorDuplicate8\n" );
|
|
|
|
}
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
2001-12-29 15:34:03 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SCANDATATYPE_Gray:
|
2005-07-04 09:54:31 +00:00
|
|
|
if (scan->sParam.bBitDepth > 8) {
|
|
|
|
scan->pfnProcess = usb_GrayDuplicate16;
|
2001-12-29 15:34:03 +00:00
|
|
|
DBG( _DBG_INFO, "ImageProc is: GrayDuplicate16\n" );
|
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
if (scan->dwFlag & SCANFLAG_Pseudo48) {
|
|
|
|
scan->pfnProcess = usb_GrayDuplicatePseudo16;
|
2001-12-29 15:34:03 +00:00
|
|
|
DBG( _DBG_INFO, "ImageProc is: GrayDuplicatePseudo16\n" );
|
|
|
|
} else {
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->pfnProcess = usb_GrayDuplicate8;
|
2001-12-29 15:34:03 +00:00
|
|
|
DBG( _DBG_INFO, "ImageProc is: GrayDuplicate8\n" );
|
2004-07-05 12:59:03 +00:00
|
|
|
}
|
|
|
|
}
|
2001-12-29 15:34:03 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2005-07-04 09:54:31 +00:00
|
|
|
scan->pfnProcess = usb_BWDuplicate;
|
2001-12-29 15:34:03 +00:00
|
|
|
DBG( _DBG_INFO, "ImageProc is: BWDuplicate\n" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
if( scan->sParam.bBitDepth == 8 ) {
|
2002-01-10 19:39:32 +00:00
|
|
|
|
2005-07-04 09:54:31 +00:00
|
|
|
if( scan->dwFlag & SCANFLAG_Pseudo48 ) {
|
|
|
|
if( scan->dwFlag & SCANFLAG_RightAlign ) {
|
2001-12-29 15:34:03 +00:00
|
|
|
bShift = 5;
|
|
|
|
} else {
|
2002-01-10 19:39:32 +00:00
|
|
|
|
2004-07-05 12:59:03 +00:00
|
|
|
/* this should fix the Bearpaw/U12 discrepancy
|
2002-01-10 19:39:32 +00:00
|
|
|
* in general the fix is needed, but not for the U12
|
|
|
|
* why? - no idea!
|
2004-07-05 12:59:03 +00:00
|
|
|
*/
|
2002-01-10 19:39:32 +00:00
|
|
|
if(_WAF_BSHIFT7_BUG == (_WAF_BSHIFT7_BUG & sc->workaroundFlag))
|
|
|
|
bShift = 0; /* Holger Bischof 16.12.2001 */
|
|
|
|
else
|
|
|
|
bShift = 7;
|
2001-12-29 15:34:03 +00:00
|
|
|
}
|
|
|
|
DBG( _DBG_INFO, "bShift adjusted: %u\n", bShift );
|
|
|
|
}
|
|
|
|
}
|
2003-01-10 13:32:11 +00:00
|
|
|
|
|
|
|
if( _LM9833 == hw->chip ) {
|
|
|
|
Shift = 0;
|
|
|
|
Mask = 0xFFFF;
|
|
|
|
} else {
|
|
|
|
Shift = 2;
|
|
|
|
Mask = 0xFFFC;
|
|
|
|
}
|
2001-12-29 15:34:03 +00:00
|
|
|
}
|
|
|
|
|
2003-01-10 13:32:11 +00:00
|
|
|
/**
|
2001-12-29 15:34:03 +00:00
|
|
|
* here we read the image data into our intermediate buffer (in the NT version
|
|
|
|
* the function was implemented as thread)
|
|
|
|
*/
|
2004-07-05 12:59:03 +00:00
|
|
|
static SANE_Int usb_ReadData( Plustek_Device *dev )
|
2001-12-29 15:34:03 +00:00
|
|
|
{
|
2003-05-15 17:19:32 +00:00
|
|
|
u_long dw, dwRet, dwBytes, pl;
|
2005-07-04 09:54:31 +00:00
|
|
|
ScanDef *scan = &dev->scanning;
|
|
|
|
HWDef *hw = &dev->usbDev.HwSetting;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
|
|
|
DBG( _DBG_READ, "usb_ReadData()\n" );
|
|
|
|
|
2004-11-19 12:38:46 +00:00
|
|
|
pl = dev->usbDev.a_bRegs[0x4e] * hw->wDRAMSize/128;
|
2002-09-28 11:31:53 +00:00
|
|
|
|
2004-07-02 13:09:36 +00:00
|
|
|
while( scan->sParam.Size.dwTotalBytes ) {
|
2003-05-15 17:19:32 +00:00
|
|
|
|
2001-12-29 15:34:03 +00:00
|
|
|
if( usb_IsEscPressed()) {
|
|
|
|
DBG( _DBG_INFO, "usb_ReadData() - Cancel detected...\n" );
|
|
|
|
return 0;
|
|
|
|
}
|
2003-05-15 17:19:32 +00:00
|
|
|
|
2004-07-02 13:09:36 +00:00
|
|
|
if( scan->sParam.Size.dwTotalBytes > scan->dwBytesScanBuf )
|
|
|
|
dw = scan->dwBytesScanBuf;
|
2003-12-18 13:24:26 +00:00
|
|
|
else
|
2004-07-02 13:09:36 +00:00
|
|
|
dw = scan->sParam.Size.dwTotalBytes;
|
2003-05-15 17:19:32 +00:00
|
|
|
|
2004-07-02 13:09:36 +00:00
|
|
|
scan->sParam.Size.dwTotalBytes -= dw;
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2004-07-02 13:09:36 +00:00
|
|
|
if(!scan->sParam.Size.dwTotalBytes && dw < (pl * 1024))
|
2003-12-18 13:24:26 +00:00
|
|
|
{
|
2004-11-19 12:38:46 +00:00
|
|
|
if(!(dev->usbDev.a_bRegs[0x4e] = (u_char)ceil((double)dw /
|
2004-07-05 12:59:03 +00:00
|
|
|
(4.0 * hw->wDRAMSize)))) {
|
2004-11-19 12:38:46 +00:00
|
|
|
dev->usbDev.a_bRegs[0x4e] = 1;
|
2003-01-10 13:32:11 +00:00
|
|
|
}
|
2004-11-19 12:38:46 +00:00
|
|
|
dev->usbDev.a_bRegs[0x4f] = 0;
|
2003-05-15 17:19:32 +00:00
|
|
|
|
2004-11-19 12:38:46 +00:00
|
|
|
sanei_lm983x_write( dev->fd, 0x4e, &dev->usbDev.a_bRegs[0x4e], 2, SANE_TRUE );
|
2003-12-18 13:24:26 +00:00
|
|
|
}
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2004-07-02 13:09:36 +00:00
|
|
|
while( scan->bLinesToSkip ) {
|
2003-05-15 17:19:32 +00:00
|
|
|
|
2004-07-02 13:09:36 +00:00
|
|
|
DBG( _DBG_READ, "Skipping %u lines\n", scan->bLinesToSkip );
|
2002-09-28 11:31:53 +00:00
|
|
|
|
2004-07-02 13:09:36 +00:00
|
|
|
dwBytes = scan->bLinesToSkip * scan->sParam.Size.dwPhyBytes;
|
2003-05-15 17:19:32 +00:00
|
|
|
|
2004-07-02 13:09:36 +00:00
|
|
|
if (dwBytes > scan->dwBytesScanBuf) {
|
2003-05-15 17:19:32 +00:00
|
|
|
|
2004-07-02 13:09:36 +00:00
|
|
|
dwBytes = scan->dwBytesScanBuf;
|
|
|
|
scan->bLinesToSkip -= scan->dwLinesScanBuf;
|
2003-12-18 13:24:26 +00:00
|
|
|
} else {
|
2004-07-02 13:09:36 +00:00
|
|
|
scan->bLinesToSkip = 0;
|
2003-12-18 13:24:26 +00:00
|
|
|
}
|
2003-05-15 17:19:32 +00:00
|
|
|
|
2004-07-02 13:09:36 +00:00
|
|
|
if( !usb_ScanReadImage( dev, scan->pbGetDataBuf, dwBytes ))
|
2003-03-03 14:34:20 +00:00
|
|
|
return 0;
|
2003-12-18 13:24:26 +00:00
|
|
|
}
|
2003-05-15 17:19:32 +00:00
|
|
|
|
2004-07-02 13:09:36 +00:00
|
|
|
if( usb_ScanReadImage( dev, scan->pbGetDataBuf, dw )) {
|
2002-09-28 11:31:53 +00:00
|
|
|
|
2007-12-17 14:28:13 +00:00
|
|
|
dumpPic("plustek-pic.raw", scan->pbGetDataBuf, dw, 0);
|
2003-05-15 17:19:32 +00:00
|
|
|
|
2004-07-02 13:09:36 +00:00
|
|
|
if( scan->dwLinesDiscard ) {
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2004-07-02 13:09:36 +00:00
|
|
|
DBG(_DBG_READ, "Discarding %lu lines\n", scan->dwLinesDiscard);
|
2003-05-15 17:19:32 +00:00
|
|
|
|
2004-07-02 13:09:36 +00:00
|
|
|
dwRet = dw / scan->sParam.Size.dwPhyBytes;
|
2003-05-15 17:19:32 +00:00
|
|
|
|
2004-07-02 13:09:36 +00:00
|
|
|
if (scan->dwLinesDiscard > dwRet) {
|
|
|
|
scan->dwLinesDiscard -= dwRet;
|
2003-12-18 13:24:26 +00:00
|
|
|
dwRet = 0;
|
|
|
|
} else {
|
2004-07-02 13:09:36 +00:00
|
|
|
dwRet -= scan->dwLinesDiscard;
|
|
|
|
scan->dwLinesDiscard = 0;
|
2003-12-18 13:24:26 +00:00
|
|
|
}
|
|
|
|
} else {
|
2002-09-28 11:31:53 +00:00
|
|
|
|
2004-07-02 13:09:36 +00:00
|
|
|
dwRet = dw / scan->sParam.Size.dwPhyBytes;
|
2003-12-18 13:24:26 +00:00
|
|
|
}
|
2001-12-29 15:34:03 +00:00
|
|
|
|
2004-07-02 13:09:36 +00:00
|
|
|
scan->pbGetDataBuf += scan->dwBytesScanBuf;
|
|
|
|
if( scan->pbGetDataBuf >= scan->pbScanBufEnd ) {
|
|
|
|
scan->pbGetDataBuf = scan->pbScanBufBegin;
|
2003-12-18 13:24:26 +00:00
|
|
|
}
|
2003-05-15 17:19:32 +00:00
|
|
|
|
2003-12-18 13:24:26 +00:00
|
|
|
if( dwRet )
|
|
|
|
return dwRet;
|
|
|
|
}
|
2001-12-29 15:34:03 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* END PLUSTEK-USBIMG.C .....................................................*/
|