kopia lustrzana https://gitlab.com/sane-project/backends
working full width in memory calibration
- added debug traces and calibration image files - tuned default OpticSlim M12 exposure parameters - bug fixes to make calibration work in memorymerge-requests/1/head
rodzic
3a3e581f90
commit
c951328202
|
@ -1857,15 +1857,6 @@ sane_start (SANE_Handle handle)
|
|||
{
|
||||
s->calib = s->val[OPT_QUALITY_CAL].w;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* if there is calibration data, create calibrators from it */
|
||||
if (s->calibrated == SANE_TRUE)
|
||||
{
|
||||
RIE (gt68xx_assign_calibration (s));
|
||||
}
|
||||
s->calib = s->calibrated;
|
||||
}
|
||||
|
||||
if (!(s->dev->model->flags & GT68XX_FLAG_NO_STOP))
|
||||
RIE (gt68xx_device_stop_scan (s->dev));
|
||||
|
@ -1898,16 +1889,8 @@ sane_start (SANE_Handle handle)
|
|||
}
|
||||
else
|
||||
{
|
||||
if(s->calibrated)
|
||||
{
|
||||
/* restore settings from calibration stored */
|
||||
memcpy(s->dev->afe,&(s->afe_params), sizeof(GT68xx_AFE_Parameters));
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
s->calib = s->calibrated;
|
||||
}
|
||||
|
||||
|
||||
/* some sheetfed scanners need a special operation to move
|
||||
* paper before starting real scan */
|
||||
|
@ -1916,7 +1899,18 @@ sane_start (SANE_Handle handle)
|
|||
RIE (gt68xx_sheetfed_move_to_scan_area (s, &scan_request));
|
||||
}
|
||||
|
||||
/* send scan request to the scanner */
|
||||
RIE (gt68xx_scanner_start_scan (s, &scan_request, &scan_params));
|
||||
|
||||
/* once scan request has been done, we can restore calibration */
|
||||
if( (s->dev->model->flags & GT68XX_FLAG_HAS_CALIBRATE)
|
||||
&&(s->calibrated == SANE_TRUE))
|
||||
{
|
||||
/* restore settings from calibration stored */
|
||||
memcpy(s->dev->afe,&(s->afe_params), sizeof(GT68xx_AFE_Parameters));
|
||||
RIE (gt68xx_assign_calibration (s, scan_params));
|
||||
}
|
||||
|
||||
for (i = 0; i < scan_params.overscan_lines; ++i)
|
||||
RIE (gt68xx_scanner_read_line (s, buffer_pointers));
|
||||
DBG (4, "sane_start: wanted: dpi=%d, x=%.1f, y=%.1f, width=%.1f, "
|
||||
|
|
|
@ -1642,7 +1642,7 @@ static GT68xx_Model plustek_opticslim_m12_model = {
|
|||
|
||||
COLOR_ORDER_BGR, /* Order of the CCD/CIS colors */
|
||||
{0x24, 0x0a, 0x23, 0x0f, 0x23, 0x0b}, /* Default offset/gain */
|
||||
{0x157, 0x157, 0x157}, /* Default exposure parameters */
|
||||
{0x100, 0x100, 0x100}, /* Default exposure parameters */
|
||||
SANE_FIX (2.0), /* Default gamma value */
|
||||
|
||||
SANE_TRUE, /* Is this a CIS scanner? */
|
||||
|
|
|
@ -1931,24 +1931,36 @@ gt68xx_afe_cis_auto (GT68xx_Scanner * scanner)
|
|||
* @return SANE_STATUS_GOOD and a filled calibrator if enough memory
|
||||
*/
|
||||
static SANE_Status
|
||||
gt68xx_calibrator_create_copy (GT68xx_Calibrator **calibrator, GT68xx_Calibrator *reference, int width, int offset)
|
||||
gt68xx_calibrator_create_copy (GT68xx_Calibrator ** calibrator,
|
||||
GT68xx_Calibrator * reference, int width,
|
||||
int offset)
|
||||
{
|
||||
SANE_Status status;
|
||||
size_t intsize=width*sizeof(unsigned int);
|
||||
size_t doublesize=width*sizeof(double);
|
||||
size_t intoffset=offset*sizeof(unsigned int);
|
||||
size_t doubleoffset=offset*sizeof(double);
|
||||
size_t intsize = width * sizeof (unsigned int);
|
||||
size_t doublesize = width * sizeof (double);
|
||||
size_t intoffset = offset * sizeof (unsigned int);
|
||||
size_t doubleoffset = offset * sizeof (double);
|
||||
|
||||
status = gt68xx_calibrator_new (width, 65535, calibrator);
|
||||
if(status!=SANE_STATUS_GOOD)
|
||||
if (reference == NULL)
|
||||
{
|
||||
DBG (1, "gt68xx_assign_calibration: failed to create calibrator: %s\n", sane_strstatus (status));
|
||||
DBG (1, "gt68xx_calibrator_create_copy: NULL reference, skipping...\n");
|
||||
*calibrator = NULL;
|
||||
return SANE_STATUS_GOOD;
|
||||
}
|
||||
status = gt68xx_calibrator_new (width, 65535, calibrator);
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
{
|
||||
DBG (1,
|
||||
"gt68xx_calibrator_create_copy: failed to create calibrator: %s\n",
|
||||
sane_strstatus (status));
|
||||
return status;
|
||||
}
|
||||
memcpy((*calibrator)->k_white, reference->k_white+intoffset, intsize);
|
||||
memcpy((*calibrator)->k_black, reference->k_black+intoffset, intsize);
|
||||
memcpy((*calibrator)->white_line, reference->white_line+doubleoffset, doublesize);
|
||||
memcpy((*calibrator)->black_line, reference->black_line+doubleoffset, doublesize);
|
||||
memcpy ((*calibrator)->k_white, reference->k_white + intoffset, intsize);
|
||||
memcpy ((*calibrator)->k_black, reference->k_black + intoffset, intsize);
|
||||
memcpy ((*calibrator)->white_line, reference->white_line + doubleoffset,
|
||||
doublesize);
|
||||
memcpy ((*calibrator)->black_line, reference->black_line + doubleoffset,
|
||||
doublesize);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
@ -1990,6 +2002,10 @@ gt68xx_sheetfed_scanner_calibrate (GT68xx_Scanner * scanner)
|
|||
GT68xx_Scan_Parameters params;
|
||||
int count, i, x, y, white;
|
||||
unsigned int *buffer_pointers[3];
|
||||
#ifdef DEBUG_CALIBRATION
|
||||
FILE *fcal;
|
||||
char title[50];
|
||||
#endif
|
||||
|
||||
DBG (3, "gt68xx_sheetfed_scanner_calibrate: start.\n");
|
||||
|
||||
|
@ -2004,13 +2020,13 @@ gt68xx_sheetfed_scanner_calibrate (GT68xx_Scanner * scanner)
|
|||
}
|
||||
}
|
||||
|
||||
/* move to white area */
|
||||
/* move to white area SA_CALIBRATE uses its own y0/ys fixed values */
|
||||
request.x0 = 0;
|
||||
request.y0 = SANE_FIX (10.0);
|
||||
request.xs = scanner->dev->model->x_size;
|
||||
/* maximum vertical size to scan */
|
||||
request.ys = SANE_FIX (500.0);
|
||||
|
||||
/* TODO we must also loop over bpp */
|
||||
request.depth = 8;
|
||||
|
||||
request.color = SANE_FALSE;
|
||||
request.mbs = SANE_TRUE;
|
||||
request.mds = SANE_TRUE;
|
||||
|
@ -2109,6 +2125,17 @@ gt68xx_sheetfed_scanner_calibrate (GT68xx_Scanner * scanner)
|
|||
{
|
||||
request.xdpi = scanner->dev->model->xdpi_values[i];
|
||||
request.ydpi = scanner->dev->model->xdpi_values[i];
|
||||
request.x0 = 0;
|
||||
request.xs = scanner->dev->model->x_size;
|
||||
request.color = SANE_FALSE;
|
||||
request.mbs = SANE_FALSE;
|
||||
request.mds = SANE_TRUE;
|
||||
request.mas = SANE_FALSE;
|
||||
request.lamp = SANE_TRUE;
|
||||
request.calculate = SANE_FALSE;
|
||||
request.use_ta = SANE_FALSE;
|
||||
request.backtrack = SANE_FALSE;
|
||||
request.backtrack_lines = 0;
|
||||
|
||||
/* calibrate in color */
|
||||
request.color = SANE_TRUE;
|
||||
|
@ -2121,37 +2148,44 @@ gt68xx_sheetfed_scanner_calibrate (GT68xx_Scanner * scanner)
|
|||
return status;
|
||||
}
|
||||
|
||||
/* since auto afe is done at a fixed resolution, we don't need to
|
||||
* do each each time, once is enough */
|
||||
scanner->auto_afe = SANE_FALSE;
|
||||
|
||||
/* allocate and save per dpi calibrators */
|
||||
scanner->calibrations[i].dpi = request.xdpi;
|
||||
status =
|
||||
gt68xx_calibrator_create_copy (&(scanner->calibrations[i].red),
|
||||
scanner->cal_r, params.pixel_xs, 0);
|
||||
scanner->cal_r, scanner->cal_r->width,
|
||||
0);
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
{
|
||||
DBG (1,
|
||||
"gt68xx_sheetfed_scanner_calibrate: failed to create calibrator: %s\n",
|
||||
"gt68xx_sheetfed_scanner_calibrate: failed to create red calibrator: %s\n",
|
||||
sane_strstatus (status));
|
||||
return status;
|
||||
}
|
||||
|
||||
status =
|
||||
gt68xx_calibrator_create_copy (&(scanner->calibrations[i].green),
|
||||
scanner->cal_g, params.pixel_xs, 0);
|
||||
scanner->cal_g, scanner->cal_g->width,
|
||||
0);
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
{
|
||||
DBG (1,
|
||||
"gt68xx_sheetfed_scanner_calibrate: failed to create calibrator: %s\n",
|
||||
"gt68xx_sheetfed_scanner_calibrate: failed to create green calibrator: %s\n",
|
||||
sane_strstatus (status));
|
||||
return status;
|
||||
}
|
||||
|
||||
status =
|
||||
gt68xx_calibrator_create_copy (&(scanner->calibrations[i].blue),
|
||||
scanner->cal_b, params.pixel_xs, 0);
|
||||
scanner->cal_b, scanner->cal_b->width,
|
||||
0);
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
{
|
||||
DBG (1,
|
||||
"gt68xx_sheetfed_scanner_calibrate: failed to create calibrator: %s\n",
|
||||
"gt68xx_sheetfed_scanner_calibrate: failed to create blue calibrator: %s\n",
|
||||
sane_strstatus (status));
|
||||
return status;
|
||||
}
|
||||
|
@ -2167,27 +2201,63 @@ gt68xx_sheetfed_scanner_calibrate (GT68xx_Scanner * scanner)
|
|||
return status;
|
||||
}
|
||||
|
||||
status =
|
||||
gt68xx_calibrator_create_copy (&(scanner->calibrations[i].gray),
|
||||
scanner->cal_gray, params.pixel_xs, 0);
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
if (scanner->cal_gray)
|
||||
{
|
||||
DBG (1,
|
||||
"gt68xx_sheetfed_scanner_calibrate: failed to create calibrator: %s\n",
|
||||
sane_strstatus (status));
|
||||
return status;
|
||||
status =
|
||||
gt68xx_calibrator_create_copy (&(scanner->calibrations[i].gray),
|
||||
scanner->cal_gray,
|
||||
scanner->cal_gray->width, 0);
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
{
|
||||
DBG (1,
|
||||
"gt68xx_sheetfed_scanner_calibrate: failed to create gray calibrator: %s\n",
|
||||
sane_strstatus (status));
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG_CALIBRATION
|
||||
sprintf (title, "cal-%03d-red.pnm", scanner->calibrations[i].dpi);
|
||||
fcal = fopen (title, "wb");
|
||||
if (fcal != NULL)
|
||||
{
|
||||
fprintf (fcal, "P5\n%d 1\n255\n", params.pixel_xs);
|
||||
for (x = 0; x < params.pixel_xs; x++)
|
||||
fputc ((scanner->calibrations[i].red->k_white[x] >> 8) & 0xff,
|
||||
fcal);
|
||||
fclose (fcal);
|
||||
}
|
||||
sprintf (title, "cal-%03d-green.pnm", scanner->calibrations[i].dpi);
|
||||
fcal = fopen (title, "wb");
|
||||
if (fcal != NULL)
|
||||
{
|
||||
fprintf (fcal, "P5\n%d 1\n255\n", params.pixel_xs);
|
||||
for (x = 0; x < params.pixel_xs; x++)
|
||||
fputc ((scanner->calibrations[i].green->k_white[x] >> 8) & 0xff,
|
||||
fcal);
|
||||
fclose (fcal);
|
||||
}
|
||||
sprintf (title, "cal-%03d-blue.pnm", scanner->calibrations[i].dpi);
|
||||
fcal = fopen (title, "wb");
|
||||
if (fcal != NULL)
|
||||
{
|
||||
fprintf (fcal, "P5\n%d 1\n255\n", params.pixel_xs);
|
||||
for (x = 0; x < params.pixel_xs; x++)
|
||||
fputc ((scanner->calibrations[i].blue->k_white[x] >> 8) & 0xff,
|
||||
fcal);
|
||||
fclose (fcal);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* next resolution */
|
||||
i++;
|
||||
|
||||
/* since auto afe is done at a fixed resolution, we don't need to
|
||||
* do each each time, once is enough */
|
||||
scanner->auto_afe = SANE_FALSE;
|
||||
}
|
||||
|
||||
scanner->calibrated = SANE_TRUE;
|
||||
|
||||
/* eject calibration target from feeder */
|
||||
gt68xx_device_paperfeed (scanner->dev);
|
||||
|
||||
DBG (3, "gt68xx_sheetfed_scanner_calibrate: end.\n");
|
||||
return SANE_STATUS_GOOD;
|
||||
}
|
||||
|
@ -2201,74 +2271,116 @@ gt68xx_sheetfed_scanner_calibrate (GT68xx_Scanner * scanner)
|
|||
* otherwise.
|
||||
*/
|
||||
static SANE_Status
|
||||
gt68xx_assign_calibration (GT68xx_Scanner * scanner)
|
||||
gt68xx_assign_calibration (GT68xx_Scanner * scanner,
|
||||
GT68xx_Scan_Parameters params)
|
||||
{
|
||||
int i,dpi, offset;
|
||||
SANE_Status status=SANE_STATUS_GOOD;
|
||||
GT68xx_Scan_Parameters params=scanner->reader->params;
|
||||
int i, dpi, offset;
|
||||
SANE_Status status = SANE_STATUS_GOOD;
|
||||
|
||||
DBG (3, "gt68xx_assign_calibration: start.\n");
|
||||
if (scanner->val[OPT_RESOLUTION].w > scanner->dev->model->optical_xdpi)
|
||||
dpi=scanner->dev->model->optical_xdpi;
|
||||
else
|
||||
dpi=scanner->val[OPT_RESOLUTION].w;
|
||||
|
||||
DBG (4, "gt68xx_assign_calibration: searching calibration for %d dpi\n",dpi);
|
||||
dpi = params.xdpi;
|
||||
DBG (4, "gt68xx_assign_calibration: searching calibration for %d dpi\n",
|
||||
dpi);
|
||||
|
||||
/* search matching dpi */
|
||||
i=0;
|
||||
while(scanner->calibrations[i].dpi>0 && scanner->calibrations[i].dpi!=dpi)
|
||||
i = 0;
|
||||
while (scanner->calibrations[i].dpi > 0
|
||||
&& scanner->calibrations[i].dpi != dpi)
|
||||
{
|
||||
i++;
|
||||
}
|
||||
|
||||
/* check if found a match */
|
||||
if(scanner->calibrations[i].dpi==0)
|
||||
if (scanner->calibrations[i].dpi == 0)
|
||||
{
|
||||
DBG (4, "gt68xx_assign_calibration: failed to find calibration for %d dpi\n",dpi);
|
||||
DBG (4,
|
||||
"gt68xx_assign_calibration: failed to find calibration for %d dpi\n",
|
||||
dpi);
|
||||
return SANE_STATUS_INVAL;
|
||||
}
|
||||
DBG (4, "gt68xx_assign_calibration: using entry %d for %d dpi\n",i,dpi);
|
||||
DBG (4, "gt68xx_assign_calibration: using entry %d for %d dpi\n", i, dpi);
|
||||
|
||||
DBG (5,
|
||||
"gt68xx_assign_calibration: using scan_parameters: pixel_xs=%d, scan_xs=%d \n",
|
||||
params.pixel_xs, params.scan_xs);
|
||||
|
||||
/* AFE/exposure data copy */
|
||||
memcpy(scanner->dev->afe,&(scanner->afe_params), sizeof(GT68xx_AFE_Parameters));
|
||||
scanner->dev->exposure->r_time=scanner->exposure_params.r_time;
|
||||
scanner->dev->exposure->g_time=scanner->exposure_params.g_time;
|
||||
scanner->dev->exposure->b_time=scanner->exposure_params.b_time;
|
||||
memcpy (scanner->dev->afe, &(scanner->afe_params),
|
||||
sizeof (GT68xx_AFE_Parameters));
|
||||
scanner->dev->exposure->r_time = scanner->exposure_params.r_time;
|
||||
scanner->dev->exposure->g_time = scanner->exposure_params.g_time;
|
||||
scanner->dev->exposure->b_time = scanner->exposure_params.b_time;
|
||||
|
||||
/* free calibrators if needed */
|
||||
gt68xx_scanner_free_calibrators (scanner);
|
||||
|
||||
/* TODO compute offset based on the x0 value from scan_request */
|
||||
offset=0;
|
||||
offset = 0;
|
||||
|
||||
/* calibrator allocation and copy */
|
||||
status = gt68xx_calibrator_create_copy (&(scanner->cal_r), scanner->calibrations[i].red, params.pixel_xs, offset);
|
||||
if(status!=SANE_STATUS_GOOD)
|
||||
if (scanner->calibrations[i].red)
|
||||
{
|
||||
DBG (1, "gt68xx_assign_calibration: failed to create calibrator: %s\n", sane_strstatus (status));
|
||||
return status;
|
||||
status =
|
||||
gt68xx_calibrator_create_copy (&(scanner->cal_r),
|
||||
scanner->calibrations[i].red,
|
||||
scanner->calibrations[i].red->width -
|
||||
offset, offset);
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
{
|
||||
DBG (1,
|
||||
"gt68xx_assign_calibration: failed to create calibrator: %s\n",
|
||||
sane_strstatus (status));
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
status = gt68xx_calibrator_create_copy (&(scanner->cal_g), scanner->calibrations[i].green, params.pixel_xs, offset);
|
||||
if(status!=SANE_STATUS_GOOD)
|
||||
|
||||
if (scanner->calibrations[i].green)
|
||||
{
|
||||
DBG (1, "gt68xx_assign_calibration: failed to create calibrator: %s\n", sane_strstatus (status));
|
||||
return status;
|
||||
status =
|
||||
gt68xx_calibrator_create_copy (&(scanner->cal_g),
|
||||
scanner->calibrations[i].green,
|
||||
scanner->calibrations[i].green->width -
|
||||
offset, offset);
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
{
|
||||
DBG (1,
|
||||
"gt68xx_assign_calibration: failed to create calibrator: %s\n",
|
||||
sane_strstatus (status));
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
status = gt68xx_calibrator_create_copy (&(scanner->cal_b), scanner->calibrations[i].blue, params.pixel_xs, offset);
|
||||
if(status!=SANE_STATUS_GOOD)
|
||||
|
||||
if (scanner->calibrations[i].blue)
|
||||
{
|
||||
DBG (1, "gt68xx_assign_calibration: failed to create calibrator: %s\n", sane_strstatus (status));
|
||||
return status;
|
||||
status =
|
||||
gt68xx_calibrator_create_copy (&(scanner->cal_b),
|
||||
scanner->calibrations[i].blue,
|
||||
scanner->calibrations[i].blue->width -
|
||||
offset, offset);
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
{
|
||||
DBG (1,
|
||||
"gt68xx_assign_calibration: failed to create calibrator: %s\n",
|
||||
sane_strstatus (status));
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
status = gt68xx_calibrator_create_copy (&(scanner->cal_gray), scanner->calibrations[i].gray, params.pixel_xs, offset);
|
||||
if(status!=SANE_STATUS_GOOD)
|
||||
|
||||
if (scanner->calibrations[i].gray)
|
||||
{
|
||||
DBG (1, "gt68xx_assign_calibration: failed to create calibrator: %s\n", sane_strstatus (status));
|
||||
return status;
|
||||
status =
|
||||
gt68xx_calibrator_create_copy (&(scanner->cal_gray),
|
||||
scanner->calibrations[i].gray,
|
||||
scanner->calibrations[i].gray->width -
|
||||
offset, offset);
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
{
|
||||
DBG (1,
|
||||
"gt68xx_assign_calibration: failed to create calibrator: %s\n",
|
||||
sane_strstatus (status));
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
DBG (3, "gt68xx_assign_calibration: end.\n");
|
||||
|
|
Ładowanie…
Reference in New Issue