Tried to use the settings from SANE-1.0.13.

Added _TWEAK_GAIN to allow increasing GAIN during
lamp coarse calibration.
Added call to speedtest function.
merge-requests/1/head
Gerhard Jaeger 2005-08-15 14:57:07 +00:00
rodzic 3290aae207
commit 2c1b5226b5
1 zmienionych plików z 74 dodań i 62 usunięć

Wyświetl plik

@ -40,6 +40,10 @@
* - 0.48 - cleanup * - 0.48 - cleanup
* - 0.49 - a_bRegs is now part of the device structure * - 0.49 - a_bRegs is now part of the device structure
* - fixed lampsetting in cano_AdjustLightsource() * - fixed lampsetting in cano_AdjustLightsource()
* - 0.50 - tried to use the settings from SANE-1.0.13
* - added _TWEAK_GAIN to allow increasing GAIN during
* lamp coarse calibration
* - added also speedtest
* *
* This file is part of the SANE package. * This file is part of the SANE package.
* *
@ -81,6 +85,11 @@
* <hr> * <hr>
*/ */
/* un-/comment the following to en-/disable lamp coarse calibration to tweak
* the initial AFE gain settings
*/
#define _TWEAK_GAIN 1
/** 0 for not ready, 1 pos white lamp on, 2 lamp off */ /** 0 for not ready, 1 pos white lamp on, 2 lamp off */
static int strip_state = 0; static int strip_state = 0;
@ -89,7 +98,7 @@ static int strip_state=0;
*/ */
static int cano_PrepareToReadWhiteCal( Plustek_Device *dev ) static int cano_PrepareToReadWhiteCal( Plustek_Device *dev )
{ {
pHWDef hw = &dev->usbDev.HwSetting; HWDef *hw = &dev->usbDev.HwSetting;
switch (strip_state) { switch (strip_state) {
case 0: case 0:
@ -170,25 +179,24 @@ static int cano_LampOnAfterCalibration( Plustek_Device *dev )
} }
/** function to adjust the CIS lamp-off setting for a given channel. /** function to adjust the CIS lamp-off setting for a given channel.
* @param min - pointer to the ON point of the CIS-channel * @param min - pointer to the min OFF point for the CIS-channel
* @param max - pointer to the max OFF point of the CIS-channel * @param max - pointer to the max OFF point for the CIS-channel
* @param off - pointer to the current OFF point of the CIS-channel * @param off - pointer to the current OFF point of the CIS-channel
* @param val - current value to check * @param val - current value to check
* @return returns 0 if the value is fine, 1, if we need to adjust * @return returns 0 if the value is fine, 1, if we need to adjust
*/ */
static int cano_adjLampSetting( u_short *min, static int
u_short *max, u_short *off, u_short val ) cano_adjLampSetting( u_short *min, u_short *max, u_short *off, u_short val )
{ {
u_long newoff = *off; u_long newoff = *off;
/* perfect value, no need to adjust /* perfect value, no need to adjust
* val ¤ [53440..59440] is perfect * val ¤ [53440..61440] is perfect
*/ */
if((val < (IDEAL_GainNormal-2000)) && (val > (IDEAL_GainNormal-8000))) if((val < (IDEAL_GainNormal)) && (val > (IDEAL_GainNormal-8000)))
return 0; return 0;
if(val >= (IDEAL_GainNormal-2000)) { if(val >= (IDEAL_GainNormal-4000)) {
DBG(_DBG_INFO2, "* TOO BRIGHT --> reduce\n" ); DBG(_DBG_INFO2, "* TOO BRIGHT --> reduce\n" );
*max = newoff; *max = newoff;
*off = ((newoff + *min)>>1); *off = ((newoff + *min)>>1);
@ -271,7 +279,8 @@ static int cano_AdjustLightsource( Plustek_Device *dev )
DBG( _DBG_INFO2, "* Bytes = %lu\n", m_ScanParam.Size.dwBytes ); DBG( _DBG_INFO2, "* Bytes = %lu\n", m_ScanParam.Size.dwBytes );
DBG( _DBG_INFO2, "* Origin.X = %u\n", m_ScanParam.Origin.x ); DBG( _DBG_INFO2, "* Origin.X = %u\n", m_ScanParam.Origin.x );
max_rgb.Red = max_rgb.Green = max_rgb.Blue = 0xffff; /* init... */
max_rgb.Red = max_rgb.Green = max_rgb.Blue = 0x3fff;
min_rgb.Red = hw->red_lamp_on; min_rgb.Red = hw->red_lamp_on;
min_rgb.Green = hw->green_lamp_on; min_rgb.Green = hw->green_lamp_on;
min_rgb.Blue = hw->blue_lamp_on; min_rgb.Blue = hw->blue_lamp_on;
@ -282,8 +291,10 @@ static int cano_AdjustLightsource( Plustek_Device *dev )
return SANE_TRUE; return SANE_TRUE;
} }
/* we probably should preset gain to some reasonably good value */ /* we probably should preset gain to some reasonably good value
#if 0 * i.e. 0x0a as it's done by Canon within their Windoze driver!
*/
#ifdef _TWEAK_GAIN
for( i=0x3b; i<0x3e; i++ ) for( i=0x3b; i<0x3e; i++ )
dev->usbDev.a_bRegs[i] = 0x0a; dev->usbDev.a_bRegs[i] = 0x0a;
#endif #endif
@ -336,9 +347,9 @@ static int cano_AdjustLightsource( Plustek_Device *dev )
dwB += ((u_short*)scanbuf) dwB += ((u_short*)scanbuf)
[dw+(m_ScanParam.Size.dwPhyPixels+1)*2]; [dw+(m_ScanParam.Size.dwPhyPixels+1)*2];
} else { } else {
dwR += ((pRGBUShortDef)scanbuf)[dw].Red; dwR += ((RGBUShortDef*)scanbuf)[dw].Red;
dwG += ((pRGBUShortDef)scanbuf)[dw].Green; dwG += ((RGBUShortDef*)scanbuf)[dw].Green;
dwB += ((pRGBUShortDef)scanbuf)[dw].Blue; dwB += ((RGBUShortDef*)scanbuf)[dw].Blue;
} }
} else { } else {
dwG += ((u_short*)scanbuf)[dw]; dwG += ((u_short*)scanbuf)[dw];
@ -388,9 +399,6 @@ static int cano_AdjustLightsource( Plustek_Device *dev )
res_g = cano_adjLampSetting( &min_rgb.Green, &max_rgb.Green, res_g = cano_adjLampSetting( &min_rgb.Green, &max_rgb.Green,
&hw->green_lamp_off, tmp_rgb.Green ); &hw->green_lamp_off, tmp_rgb.Green );
/* need to be set in any case! */
usb_AdjustLamps(dev);
/* nothing adjusted, so stop here */ /* nothing adjusted, so stop here */
if((res_r == 0) && (res_g == 0) && (res_b == 0)) if((res_r == 0) && (res_g == 0) && (res_b == 0))
break; break;
@ -402,18 +410,20 @@ static int cano_AdjustLightsource( Plustek_Device *dev )
break; break;
/* we raise the gain for channel, that have been limited */ /* we raise the gain for channel, that have been limited */
#ifdef _TWEAK_GAIN
if( res_r == 10 ) { if( res_r == 10 ) {
if( dev->usbDev.a_bRegs[0x3b] < 0x0b) if( dev->usbDev.a_bRegs[0x3b] < 0xf)
dev->usbDev.a_bRegs[0x3b]++; dev->usbDev.a_bRegs[0x3b]++;
} }
if( res_g == 10 ) { if( res_g == 10 ) {
if( dev->usbDev.a_bRegs[0x3c] < 0x0b) if( dev->usbDev.a_bRegs[0x3c] < 0x0f)
dev->usbDev.a_bRegs[0x3c]++; dev->usbDev.a_bRegs[0x3c]++;
} }
if( res_b == 10 ) { if( res_b == 10 ) {
if( dev->usbDev.a_bRegs[0x3d] < 0x0b) if( dev->usbDev.a_bRegs[0x3d] < 0x0f)
dev->usbDev.a_bRegs[0x3d]++; dev->usbDev.a_bRegs[0x3d]++;
} }
#endif
/* now decide what to do: /* now decide what to do:
* if we were too bright, we have to rerun the loop in any * if we were too bright, we have to rerun the loop in any
@ -424,12 +434,8 @@ static int cano_AdjustLightsource( Plustek_Device *dev )
if( i >= 10 ) { if( i >= 10 ) {
DBG(_DBG_INFO, "* 10 times limit reached, still too dark!!!\n"); DBG(_DBG_INFO, "* 10 times limit reached, still too dark!!!\n");
break; break;
#if 0
} else {
DBG(_DBG_INFO2, "* CIS-Warmup, 1s!!!\n" );
sleep( 1 );
#endif
} }
usb_AdjustLamps(dev);
} }
DBG( _DBG_INFO, "* red_lamp_on = %u\n", hw->red_lamp_on ); DBG( _DBG_INFO, "* red_lamp_on = %u\n", hw->red_lamp_on );
@ -579,9 +585,9 @@ static SANE_Bool cano_AdjustGain( Plustek_Device *dev )
dwB += ((u_short*)scanbuf) dwB += ((u_short*)scanbuf)
[dw+(m_ScanParam.Size.dwPhyPixels+1)*2]; [dw+(m_ScanParam.Size.dwPhyPixels+1)*2];
} else { } else {
dwR += ((pRGBUShortDef)scanbuf)[dw].Red; dwR += ((RGBUShortDef*)scanbuf)[dw].Red;
dwG += ((pRGBUShortDef)scanbuf)[dw].Green; dwG += ((RGBUShortDef*)scanbuf)[dw].Green;
dwB += ((pRGBUShortDef)scanbuf)[dw].Blue; dwB += ((RGBUShortDef*)scanbuf)[dw].Blue;
} }
} }
dwR = dwR / dwDiv; dwR = dwR / dwDiv;
@ -760,9 +766,9 @@ static int cano_AdjustOffset( Plustek_Device *dev )
scanbuf)[dw+(m_ScanParam.Size.dwPhyPixels+1)*2]; scanbuf)[dw+(m_ScanParam.Size.dwPhyPixels+1)*2];
} else { } else {
dwSum[0] += ((pRGBUShortDef)scanbuf)[dw].Red; dwSum[0] += ((RGBUShortDef*)scanbuf)[dw].Red;
dwSum[1] += ((pRGBUShortDef)scanbuf)[dw].Green; dwSum[1] += ((RGBUShortDef*)scanbuf)[dw].Green;
dwSum[2] += ((pRGBUShortDef)scanbuf)[dw].Blue; dwSum[2] += ((RGBUShortDef*)scanbuf)[dw].Blue;
} }
} }
@ -970,6 +976,9 @@ static SANE_Bool cano_AdjustDarkShading( Plustek_Device *dev )
a_wDarkShading, m_ScanParam.Size.dwPhyPixels * 2); a_wDarkShading, m_ScanParam.Size.dwPhyPixels * 2);
} }
usb_line_statistics( "Dark", a_wDarkShading, m_ScanParam.Size.dwPhyPixels,
scan->sParam.bDataType == SCANDATATYPE_Color?1:0);
DBG( _DBG_INFO, "cano_AdjustDarkShading() done\n" ); DBG( _DBG_INFO, "cano_AdjustDarkShading() done\n" );
return SANE_TRUE; return SANE_TRUE;
} }
@ -1069,19 +1078,17 @@ static SANE_Bool cano_AdjustWhiteShading( Plustek_Device *dev )
green += *bufp; bufp+=step; green += *bufp; bufp+=step;
blue += *bufp; bufp+=step; blue += *bufp; bufp+=step;
} else { } else {
red += bufp[0]; red += bufp[0];
green += bufp[1]; green += bufp[1];
blue += bufp[2]; blue += bufp[2];
bufp += step; bufp += step;
} }
} }
/* tweaked by the settings in swGain --> 1000/swGain[r,g,b] */ /* tweaked by the settings in swGain --> 1000/swGain[r,g,b] */
red = (65535.*1000./param->swGain[0]) * 16384.*m_ScanParam.Size.dwPhyLines/red; red = (65535.*1000./(double)param->swGain[0]) * 16384.*j/red;
green = (65535.*1000./param->swGain[1]) * 16384.*m_ScanParam.Size.dwPhyLines/green; green = (65535.*1000./(double)param->swGain[1]) * 16384.*j/green;
blue = (65535.*1000./param->swGain[2]) * 16384.*m_ScanParam.Size.dwPhyLines/blue; blue = (65535.*1000./(double)param->swGain[2]) * 16384.*j/blue;
a_wWhiteShading[i] = (red > 65535 ? 65535:red ); a_wWhiteShading[i] = (red > 65535 ? 65535:red );
a_wWhiteShading[i+stepW] = (green > 65535 ? 65535:green); a_wWhiteShading[i+stepW] = (green > 65535 ? 65535:green);
@ -1101,7 +1108,7 @@ static SANE_Bool cano_AdjustWhiteShading( Plustek_Device *dev )
gray += *bufp; bufp+=step; gray += *bufp; bufp+=step;
} }
gray = (65535.*1000./param->swGain[0]) * 16384.*j/gray; gray = (65535.*1000./(double)param->swGain[0]) * 16384.*j/gray;
a_wWhiteShading[i]= (gray > 65535 ? 65535:gray); a_wWhiteShading[i]= (gray > 65535 ? 65535:gray);
} }
@ -1114,6 +1121,9 @@ static SANE_Bool cano_AdjustWhiteShading( Plustek_Device *dev )
a_wWhiteShading, m_ScanParam.Size.dwPhyPixels * 2); a_wWhiteShading, m_ScanParam.Size.dwPhyPixels * 2);
} }
usb_line_statistics( "White", a_wWhiteShading, m_ScanParam.Size.dwPhyPixels,
scan->sParam.bDataType == SCANDATATYPE_Color?1:0);
DBG( _DBG_INFO, "cano_AdjustWhiteShading() done\n" ); DBG( _DBG_INFO, "cano_AdjustWhiteShading() done\n" );
return SANE_TRUE; return SANE_TRUE;
} }
@ -1143,6 +1153,8 @@ static int cano_DoCalibration( Plustek_Device *dev )
scaps->workaroundFlag &= ~_WAF_SKIP_FINE; scaps->workaroundFlag &= ~_WAF_SKIP_FINE;
scaps->workaroundFlag &= ~_WAF_BYPASS_CALIBRATION; scaps->workaroundFlag &= ~_WAF_BYPASS_CALIBRATION;
usb_SpeedTest( dev );
/* Set the shading position to undefined */ /* Set the shading position to undefined */
strip_state = 0; strip_state = 0;
usb_PrepareCalibration( dev ); usb_PrepareCalibration( dev );
@ -1232,4 +1244,4 @@ static int cano_DoCalibration( Plustek_Device *dev )
return SANE_TRUE; return SANE_TRUE;
} }
/* END PLUSTEK-USBCAL.C_.....................................................*/ /* END PLUSTEK-USBCAL.C .....................................................*/