Fixed bug in lineart scaling and made brightness adjustment work.

DEVEL_2_0_BRANCH-1
Gerhard Jaeger 2001-12-30 13:35:48 +00:00
rodzic 1e9fde8894
commit 996b4f8d69
4 zmienionych plików z 64 dodań i 115 usunięć

Wyświetl plik

@ -893,7 +893,8 @@ static int usbDev_readImage( struct Plustek_Device *dev,
DBG(_DBG_INFO,"dwBytesScanBuf = %lu\n",scanning->dwBytesScanBuf ); DBG(_DBG_INFO,"dwBytesScanBuf = %lu\n",scanning->dwBytesScanBuf );
DBG(_DBG_INFO,"dwLinesDiscard = %lu\n",scanning->dwLinesDiscard ); DBG(_DBG_INFO,"dwLinesDiscard = %lu\n",scanning->dwLinesDiscard );
DBG(_DBG_INFO,"dwLinesToSkip = %u\n", scanning->bLinesToSkip ); DBG(_DBG_INFO,"dwLinesToSkip = %u\n", scanning->bLinesToSkip );
DBG(_DBG_INFO,"dwLinesUser = %lu\n",scanning->dwLinesUser ); DBG(_DBG_INFO,"dwLinesUser = %lu\n",scanning->dwLinesUser );
DBG(_DBG_INFO,"dwBytesLine = %lu\n",scanning->dwBytesLine );
scanning->pbGetDataBuf = scanning->pbScanBufBegin; scanning->pbGetDataBuf = scanning->pbScanBufBegin;

Wyświetl plik

@ -374,7 +374,7 @@ typedef struct
double dMCLK; /* for positive & negative & Adf */ double dMCLK; /* for positive & negative & Adf */
short brightness; short brightness;
short contrast; short contrast;
u_short siThreshold; /* only for B/W output */ short siThreshold; /* only for B/W output */
u_char bSource; /* Reflection/Positive/Negative/Adf (SOURCE_xxx) */ u_char bSource; /* Reflection/Positive/Negative/Adf (SOURCE_xxx) */
u_char bDataType; /* Bw, Gray or Color (see _SCANDATATYPE) */ u_char bDataType; /* Bw, Gray or Color (see _SCANDATATYPE) */
u_char bBitDepth; /* 1/8/14 */ u_char bBitDepth; /* 1/8/14 */

Wyświetl plik

@ -52,10 +52,12 @@
* If you do not wish that, delete this exception notice. * If you do not wish that, delete this exception notice.
*/ */
#define _SCALER 1000
static u_char bShift; static u_char bShift;
static u_char *pbSrce, *pbDest; static u_char *pbSrce, *pbDest;
static int iNext; static int iNext;
static u_long dwPixels, dwBitsPut, dwBits; static u_long dwPixels, dwBitsPut;
static u_short wSum; static u_short wSum;
static u_short *pwDest; static u_short *pwDest;
static u_short wR, wG, wB; static u_short wR, wG, wB;
@ -301,6 +303,20 @@ static void usb_AverageGrayWord( struct Plustek_Device *dev )
} }
} }
/*.............................................................................
* returns the zoom value, used for our scaling algorithm (DDA algo
* digital differential analyzer).
*/
static int usb_GetScaler( pScanDef scanning )
{
double ratio;
ratio = (double)scanning->sParam.UserDpi.x/
(double)scanning->sParam.PhyDpi.x;
return (int)(1.0/ratio * _SCALER);
}
/*............................................................................. /*.............................................................................
* *
*/ */
@ -308,7 +324,6 @@ static void usb_ColorScaleGray( struct Plustek_Device *dev )
{ {
int izoom, ddax; int izoom, ddax;
u_long dw; u_long dw;
double ratio;
pScanDef scanning = &dev->scanning; pScanDef scanning = &dev->scanning;
usb_AverageColorByte( dev ); usb_AverageColorByte( dev );
@ -323,16 +338,14 @@ static void usb_ColorScaleGray( struct Plustek_Device *dev )
dwPixels = 0; dwPixels = 0;
} }
ratio = (double)scanning->sParam.UserDpi.x/ izoom = usb_GetScaler( scanning );
(double)scanning->sParam.PhyDpi.x;
izoom = (int)(1.0/ratio * 1000);
switch( scanning->fGrayFromColor ) { switch( scanning->fGrayFromColor ) {
case 1: case 1:
for( dwBitsPut = 0, ddax = 0; dw; dwBitsPut++ ) { for( dwBitsPut = 0, ddax = 0; dw; dwBitsPut++ ) {
ddax -= 1000; ddax -= _SCALER;
while((ddax < 0) && (dw > 0)) { while((ddax < 0) && (dw > 0)) {
@ -349,7 +362,7 @@ static void usb_ColorScaleGray( struct Plustek_Device *dev )
case 2: case 2:
for( dwBitsPut = 0, ddax = 0; dw; dwBitsPut++ ) { for( dwBitsPut = 0, ddax = 0; dw; dwBitsPut++ ) {
ddax -= 1000; ddax -= _SCALER;
while((ddax < 0) && (dw > 0)) { while((ddax < 0) && (dw > 0)) {
@ -366,7 +379,7 @@ static void usb_ColorScaleGray( struct Plustek_Device *dev )
case 3: case 3:
for( dwBitsPut = 0, ddax = 0; dw; dwBitsPut++ ) { for( dwBitsPut = 0, ddax = 0; dw; dwBitsPut++ ) {
ddax -= 1000; ddax -= _SCALER;
while((ddax < 0) && (dw > 0)) { while((ddax < 0) && (dw > 0)) {
@ -389,7 +402,6 @@ static void usb_ColorScale8( struct Plustek_Device *dev )
{ {
int izoom, ddax; int izoom, ddax;
u_long dw; u_long dw;
double ratio;
pScanDef scanning = &dev->scanning; pScanDef scanning = &dev->scanning;
usb_AverageColorByte( dev ); usb_AverageColorByte( dev );
@ -404,13 +416,11 @@ static void usb_ColorScale8( struct Plustek_Device *dev )
dwPixels = 0; dwPixels = 0;
} }
ratio = (double)scanning->sParam.UserDpi.x/ izoom = usb_GetScaler( scanning );
(double)scanning->sParam.PhyDpi.x;
izoom = (int)(1.0/ratio * 1000);
for( dwBitsPut = 0, ddax = 0; dw; dwBitsPut++ ) { for( dwBitsPut = 0, ddax = 0; dw; dwBitsPut++ ) {
ddax -= 1000; ddax -= _SCALER;
while((ddax < 0) && (dw > 0)) { while((ddax < 0) && (dw > 0)) {
@ -437,7 +447,6 @@ static void usb_ColorScale16( struct Plustek_Device *dev )
{ {
int izoom, ddax; int izoom, ddax;
u_long dw; u_long dw;
double ratio;
pScanDef scanning = &dev->scanning; pScanDef scanning = &dev->scanning;
usb_AverageColorWord( dev ); usb_AverageColorWord( dev );
@ -452,15 +461,13 @@ static void usb_ColorScale16( struct Plustek_Device *dev )
dwPixels = 0; dwPixels = 0;
} }
ratio = (double)scanning->sParam.UserDpi.x/ izoom = usb_GetScaler( scanning );
(double)scanning->sParam.PhyDpi.x;
izoom = (int)(1.0/ratio * 1000);
if( scanning->dwFlag & SCANFLAG_RightAlign ) { if( scanning->dwFlag & SCANFLAG_RightAlign ) {
for( dwBitsPut = 0, ddax = 0; dw; dwBitsPut++ ) { for( dwBitsPut = 0, ddax = 0; dw; dwBitsPut++ ) {
ddax -= 1000; ddax -= _SCALER;
while((ddax < 0) && (dw > 0)) { while((ddax < 0) && (dw > 0)) {
@ -483,7 +490,7 @@ static void usb_ColorScale16( struct Plustek_Device *dev )
for( dwBitsPut = 0, ddax = 0; dw; dwBitsPut++ ) { for( dwBitsPut = 0, ddax = 0; dw; dwBitsPut++ ) {
ddax -= 1000; ddax -= _SCALER;
while((ddax < 0) && (dw > 0)) { while((ddax < 0) && (dw > 0)) {
@ -511,7 +518,6 @@ static void usb_ColorScalePseudo16( struct Plustek_Device *dev )
{ {
int izoom, ddax; int izoom, ddax;
u_long dw; u_long dw;
double ratio;
pScanDef scanning = &dev->scanning; pScanDef scanning = &dev->scanning;
usb_AverageColorByte( dev ); usb_AverageColorByte( dev );
@ -526,9 +532,7 @@ static void usb_ColorScalePseudo16( struct Plustek_Device *dev )
dwPixels = 0; dwPixels = 0;
} }
ratio = (double)scanning->sParam.UserDpi.x/ izoom = usb_GetScaler( scanning );
(double)scanning->sParam.PhyDpi.x;
izoom = (int)(1.0/ratio * 1000);
wR = (u_short)scanning->Red.pcb[0].a_bColor[0]; wR = (u_short)scanning->Red.pcb[0].a_bColor[0];
wG = (u_short)scanning->Green.pcb[0].a_bColor[1]; wG = (u_short)scanning->Green.pcb[0].a_bColor[1];
@ -536,7 +540,7 @@ static void usb_ColorScalePseudo16( struct Plustek_Device *dev )
for( dwBitsPut = 0, ddax = 0; dw; dwBitsPut++ ) { for( dwBitsPut = 0, ddax = 0; dw; dwBitsPut++ ) {
ddax -= 1000; ddax -= _SCALER;
while((ddax < 0) && (dw > 0)) { while((ddax < 0) && (dw > 0)) {
@ -706,12 +710,11 @@ static void usb_ColorDuplicateGray( struct Plustek_Device *dev )
/*............................................................................. /*.............................................................................
* *
*/ */
static void usb_BWReduce( struct Plustek_Device *dev ) static void usb_BWScale( struct Plustek_Device *dev )
{ {
/* u_char tmp; */ u_char tmp;
int izoom, ddax; int izoom, ddax;
u_long /*i,*/dw; u_long i, dw;
double ratio;
pScanDef scanning = &dev->scanning; pScanDef scanning = &dev->scanning;
pbSrce = scanning->Green.pb; pbSrce = scanning->Green.pb;
@ -730,17 +733,15 @@ static void usb_BWReduce( struct Plustek_Device *dev )
iNext = 1; iNext = 1;
} }
ratio = (double)scanning->sParam.UserDpi.x/ izoom = usb_GetScaler( scanning );
(double)scanning->sParam.PhyDpi.x;
izoom = (int)(1.0/ratio * 1000);
memset( pbDest, 0, scanning->sParam.Size.dwPixels ); memset( pbDest, 0, scanning->dwBytesLine );
ddax = 0; ddax = 0;
dw = 0; dw = 0;
#if 0
for( i = 0; i < scanning->sParam.Size.dwValidPixels*8; i++ ) {
ddax -= 1000; for( i = 0; i < scanning->sParam.Size.dwPixels; i++ ) {
ddax -= _SCALER;
while( ddax < 0 ) { while( ddax < 0 ) {
@ -755,43 +756,6 @@ static void usb_BWReduce( struct Plustek_Device *dev )
ddax += izoom; ddax += izoom;
} }
} }
#else
for( wSum = scanning->sParam.PhyDpi.x, dwBits = 8,
dwPixels = scanning->sParam.Size.dwPixels; dwPixels; ) {
for( dwBitsPut = 8; dwBitsPut && dwPixels;) {
wSum += scanning->sParam.UserDpi.x;
if( wSum >= scanning->sParam.PhyDpi.x ) {
wSum -= scanning->sParam.PhyDpi.x;
if (*pbSrce & 0x80)
*pbDest = (*pbDest << 1) | 1;
else
*pbDest <<= 1;
dwBitsPut--;
dwPixels--;
}
if( !--dwBits ) {
pbSrce++;
dwBits = 8;
} else
*pbSrce <<= 1;
}
/* If m_dwBitsPut != 0, all pixels are processed */
if( dwBitsPut )
*pbDest <<= dwBitsPut;
if( scanning->sParam.bSource == SOURCE_ADF )
*pbDest = BitsReverseTable[*pbDest];
pbDest = pbDest + iNext;
if( pbDest < scanning->UserBuf.pb )
break;
}
#endif
} }
/*............................................................................. /*.............................................................................
@ -818,7 +782,6 @@ static void usb_BWDuplicate( struct Plustek_Device *dev )
static void usb_GrayScale8( struct Plustek_Device *dev ) static void usb_GrayScale8( struct Plustek_Device *dev )
{ {
int izoom, ddax; int izoom, ddax;
double ratio;
pScanDef scanning = &dev->scanning; pScanDef scanning = &dev->scanning;
usb_AverageGrayByte( dev ); usb_AverageGrayByte( dev );
@ -832,13 +795,11 @@ static void usb_GrayScale8( struct Plustek_Device *dev )
iNext = 1; iNext = 1;
} }
ratio = (double)scanning->sParam.UserDpi.x/ izoom = usb_GetScaler( scanning );
(double)scanning->sParam.PhyDpi.x;
izoom = (int)(1.0/ratio * 1000);
for( dwPixels = scanning->sParam.Size.dwPixels, ddax = 0; dwPixels; pbSrce++ ) { for( dwPixels = scanning->sParam.Size.dwPixels, ddax = 0; dwPixels; pbSrce++ ) {
ddax -= 1000; ddax -= _SCALER;
while((ddax < 0) && (dwPixels > 0)) { while((ddax < 0) && (dwPixels > 0)) {
@ -856,7 +817,6 @@ static void usb_GrayScale8( struct Plustek_Device *dev )
static void usb_GrayScale16( struct Plustek_Device *dev ) static void usb_GrayScale16( struct Plustek_Device *dev )
{ {
int izoom, ddax; int izoom, ddax;
double ratio;
pScanDef scanning = &dev->scanning; pScanDef scanning = &dev->scanning;
usb_AverageGrayWord( dev); usb_AverageGrayWord( dev);
@ -872,9 +832,7 @@ static void usb_GrayScale16( struct Plustek_Device *dev )
pwDest = scanning->UserBuf.pw; pwDest = scanning->UserBuf.pw;
} }
ratio = (double)scanning->sParam.UserDpi.x/ izoom = usb_GetScaler( scanning );
(double)scanning->sParam.PhyDpi.x;
izoom = (int)(1.0/ratio * 1000);
ddax = 0; ddax = 0;
if( scanning->dwFlag & SCANFLAG_RightAlign ) { if( scanning->dwFlag & SCANFLAG_RightAlign ) {
@ -882,7 +840,7 @@ static void usb_GrayScale16( struct Plustek_Device *dev )
for( dwPixels = scanning->sParam.Size.dwPixels - for( dwPixels = scanning->sParam.Size.dwPixels -
scanning->sParam.UserDpi.x; dwPixels; pwm++ ) { scanning->sParam.UserDpi.x; dwPixels; pwm++ ) {
ddax -= 1000; ddax -= _SCALER;
while((ddax < 0) && (dwPixels > 0)) { while((ddax < 0) && (dwPixels > 0)) {
@ -898,7 +856,7 @@ static void usb_GrayScale16( struct Plustek_Device *dev )
for( dwPixels = scanning->sParam.Size.dwPixels - for( dwPixels = scanning->sParam.Size.dwPixels -
scanning->sParam.UserDpi.x; dwPixels; pwm++ ) { scanning->sParam.UserDpi.x; dwPixels; pwm++ ) {
ddax -= 1000; ddax -= _SCALER;
while((ddax < 0) && (dwPixels > 0)) { while((ddax < 0) && (dwPixels > 0)) {
@ -917,7 +875,6 @@ static void usb_GrayScale16( struct Plustek_Device *dev )
static void usb_GrayScalePseudo16( struct Plustek_Device *dev ) static void usb_GrayScalePseudo16( struct Plustek_Device *dev )
{ {
int izoom, ddax; int izoom, ddax;
double ratio;
pScanDef scanning = &dev->scanning; pScanDef scanning = &dev->scanning;
usb_AverageGrayByte( dev ); usb_AverageGrayByte( dev );
@ -933,14 +890,12 @@ static void usb_GrayScalePseudo16( struct Plustek_Device *dev )
pwDest = scanning->UserBuf.pw; pwDest = scanning->UserBuf.pw;
} }
ratio = (double)scanning->sParam.UserDpi.x/ izoom = usb_GetScaler( scanning );
(double)scanning->sParam.PhyDpi.x;
izoom = (int)(1.0/ratio * 1000);
ddax = 0; ddax = 0;
for( dwPixels = scanning->sParam.Size.dwPixels, ddax = 0; dwPixels; pbSrce++ ) { for( dwPixels = scanning->sParam.Size.dwPixels, ddax = 0; dwPixels; pbSrce++ ) {
ddax -= 1000; ddax -= _SCALER;
while((ddax < 0) && (dwPixels > 0)) { while((ddax < 0) && (dwPixels > 0)) {
@ -1083,8 +1038,8 @@ static void usb_GetImageProc( struct Plustek_Device *dev )
break; break;
default: default:
scanning->pfnProcess = usb_BWReduce; scanning->pfnProcess = usb_BWScale;
DBG( _DBG_INFO, "ImageProc is: BWReduce\n" ); DBG( _DBG_INFO, "ImageProc is: BWScale\n" );
break; break;
} }

Wyświetl plik

@ -206,29 +206,21 @@ static SANE_Bool usb_MapDownload( pPlustek_Device dev, u_char bDataType )
/* write the gamma table entry to merlin */ /* write the gamma table entry to merlin */
if( scanning->sParam.bDataType == SCANDATATYPE_BW ) { if( scanning->sParam.bDataType == SCANDATATYPE_BW ) {
iThreshold = (int)((double)scanning->sParam.siThreshold * 1.27); iThreshold = (int)((double)scanning->sParam.siThreshold *
(_MAP_SIZE/200.0)) + (_MAP_SIZE/2);
iThreshold = _MAP_SIZE - iThreshold;
if(iThreshold < 0)
iThreshold = 0;
if(iThreshold > (int)_MAP_SIZE)
iThreshold = _MAP_SIZE;
/* for registry threshold adjustment */ DBG(_DBG_INFO, "Threshold is at %u siThresh=%i\n",
/* HEINER: not needed !*/ iThreshold, scanning->sParam.siThreshold );
#if 0
if((i = 128 /* HEINER// - Registry.GetThreshold() */)) {
j = ((iThreshold >= 0)? (127 - i): (i + 127));
iThreshold = i + iThreshold * j / 127;
/* } */
#endif
j = _MAP_SIZE / 2 - 16 * iThreshold * 128 / 127; for(i = 0; i < iThreshold; i++)
if(j < 0)
j = 0;
if(j > (int)_MAP_SIZE)
j = _MAP_SIZE;
DBG(_DBG_INFO, "Threshold is at %u siThresh=%u\n", j, iThreshold);
for(i = 0; i < j; i++)
a_bMap[color*_MAP_SIZE + i] = 0; a_bMap[color*_MAP_SIZE + i] = 0;
for(i = j; i < (int)_MAP_SIZE; i++) for(i = iThreshold; i < (int)_MAP_SIZE; i++)
a_bMap[color*_MAP_SIZE + i] = 255; a_bMap[color*_MAP_SIZE + i] = 255;
fInverse = 1; fInverse = 1;
@ -243,7 +235,7 @@ static SANE_Bool usb_MapDownload( pPlustek_Device dev, u_char bDataType )
} }
if((scanning->dwFlag & SCANDEF_Inverse) && if((scanning->dwFlag & SCANDEF_Inverse) &&
!(scanning->dwFlag & SCANFLAG_Pseudo48)) { !(scanning->dwFlag & SCANFLAG_Pseudo48)) {
fInverse ^= 1; fInverse ^= 1;
} }
@ -258,10 +250,11 @@ static SANE_Bool usb_MapDownload( pPlustek_Device dev, u_char bDataType )
map[i] = ~*pMap; map[i] = ~*pMap;
sanei_lm9831_write( dev->fd, 0x06, map, _MAP_SIZE, SANE_FALSE ); sanei_lm9831_write( dev->fd, 0x06, map, _MAP_SIZE, SANE_FALSE );
}
else } else {
sanei_lm9831_write( dev->fd, 0x06, a_bMap+color*_MAP_SIZE, sanei_lm9831_write( dev->fd, 0x06, a_bMap+color*_MAP_SIZE,
_MAP_SIZE, SANE_FALSE ); _MAP_SIZE, SANE_FALSE );
}
} /* for each color */ } /* for each color */