add clear calibration butto and need calibration sensor

- add a 'clear calibration' to clear sheetfed calibration
- add a 'needs calibration' sensor to signal that a sheetfed scanner
  needs to be calibrated
merge-requests/1/head
Stphane Voltz 2009-11-29 07:38:54 +01:00
rodzic 13641ac5b3
commit 03ac144ac8
3 zmienionych plików z 192 dodań i 90 usunięć

Wyświetl plik

@ -1765,6 +1765,15 @@ sane_control_option (SANE_Handle handle, SANE_Int option,
case OPT_CALIBRATE:
status = gt68xx_sheetfed_scanner_calibrate (s);
myinfo |= SANE_INFO_RELOAD_OPTIONS;
break;
case OPT_CLEAR_CALIBRATION:
gt68xx_clear_calibration (s);
break;
case OPT_NEED_CALIBRATION_SW:
*(SANE_Bool *) val = s->calibrated;
break;
default:

Wyświetl plik

@ -2498,93 +2498,163 @@ static char *gt68xx_calibration_file(GT68xx_Scanner * scanner)
return strdup(tmp_str);
}
static SANE_Status gt68xx_write_calibration (GT68xx_Scanner * scanner)
static SANE_Status
gt68xx_clear_calibration (GT68xx_Scanner * scanner)
{
char *fname;
int i;
if (scanner->calibrated == SANE_FALSE)
return SANE_STATUS_GOOD;
/* clear file */
fname = gt68xx_calibration_file (scanner);
unlink (fname);
free (fname);
/* free calibrators */
for (i = 0; i < MAX_RESOLUTIONS && scanner->calibrations[i].dpi > 0; i++)
{
scanner->calibrations[i].dpi = 0;
if (scanner->calibrations[i].red)
gt68xx_calibrator_free (scanner->calibrations[i].red);
if (scanner->calibrations[i].green)
gt68xx_calibrator_free (scanner->calibrations[i].green);
if (scanner->calibrations[i].blue)
gt68xx_calibrator_free (scanner->calibrations[i].blue);
if (scanner->calibrations[i].gray)
gt68xx_calibrator_free (scanner->calibrations[i].gray);
}
/* reset flags */
scanner->calibrated = SANE_FALSE;
scanner->val[OPT_QUALITY_CAL].w = SANE_FALSE;
DBG (5, "gt68xx_clear_calibration: done\n");
return SANE_STATUS_GOOD;
}
static SANE_Status
gt68xx_write_calibration (GT68xx_Scanner * scanner)
{
char *fname;
FILE *fcal;
int i;
SANE_Int nullwidth=0;
SANE_Int nullwidth = 0;
if(scanner->calibrated == SANE_FALSE)
if (scanner->calibrated == SANE_FALSE)
{
return SANE_STATUS_GOOD;
}
/* open file */
fname=gt68xx_calibration_file(scanner);
fcal=fopen(fname,"wb");
free(fname);
if(fcal==NULL)
fname = gt68xx_calibration_file (scanner);
fcal = fopen (fname, "wb");
free (fname);
if (fcal == NULL)
{
DBG(1,"gt68xx_write_calibration: failed to open calibration file for writing %s\n",strerror(errno));
DBG (1,
"gt68xx_write_calibration: failed to open calibration file for writing %s\n",
strerror (errno));
return SANE_STATUS_IO_ERROR;
}
/* TODO we save check endianness and word alignment in case of a home
* directory used trough different archs */
fwrite(&(scanner->afe_params), sizeof(GT68xx_AFE_Parameters), 1, fcal);
fwrite(&(scanner->exposure_params), sizeof(GT68xx_Exposure_Parameters), 1, fcal);
for(i=0;i<MAX_RESOLUTIONS && scanner->calibrations[i].dpi>0;i++)
fwrite (&(scanner->afe_params), sizeof (GT68xx_AFE_Parameters), 1, fcal);
fwrite (&(scanner->exposure_params), sizeof (GT68xx_Exposure_Parameters), 1,
fcal);
for (i = 0; i < MAX_RESOLUTIONS && scanner->calibrations[i].dpi > 0; i++)
{
DBG(1,"gt68xx_write_calibration: saving %d dpi calibration\n",scanner->calibrations[i].dpi);
fwrite(&(scanner->calibrations[i].dpi),sizeof(SANE_Int),1,fcal);
fwrite(&(scanner->calibrations[i].pixel_x0),sizeof(SANE_Int),1,fcal);
DBG (1, "gt68xx_write_calibration: saving %d dpi calibration\n",
scanner->calibrations[i].dpi);
fwrite (&(scanner->calibrations[i].dpi), sizeof (SANE_Int), 1, fcal);
fwrite (&(scanner->calibrations[i].pixel_x0), sizeof (SANE_Int), 1,
fcal);
fwrite(&(scanner->calibrations[i].red->width),sizeof(SANE_Int),1,fcal);
fwrite(&(scanner->calibrations[i].red->white_level),sizeof(SANE_Int),1,fcal);
fwrite(scanner->calibrations[i].red->k_white,sizeof(unsigned int),scanner->calibrations[i].red->width,fcal);
fwrite(scanner->calibrations[i].red->k_black,sizeof(unsigned int),scanner->calibrations[i].red->width,fcal);
fwrite(scanner->calibrations[i].red->white_line,sizeof(double),scanner->calibrations[i].red->width,fcal);
fwrite(scanner->calibrations[i].red->black_line,sizeof(double),scanner->calibrations[i].red->width,fcal);
fwrite (&(scanner->calibrations[i].red->width), sizeof (SANE_Int), 1,
fcal);
fwrite (&(scanner->calibrations[i].red->white_level), sizeof (SANE_Int),
1, fcal);
fwrite (scanner->calibrations[i].red->k_white, sizeof (unsigned int),
scanner->calibrations[i].red->width, fcal);
fwrite (scanner->calibrations[i].red->k_black, sizeof (unsigned int),
scanner->calibrations[i].red->width, fcal);
fwrite (scanner->calibrations[i].red->white_line, sizeof (double),
scanner->calibrations[i].red->width, fcal);
fwrite (scanner->calibrations[i].red->black_line, sizeof (double),
scanner->calibrations[i].red->width, fcal);
fwrite(&(scanner->calibrations[i].green->width),sizeof(SANE_Int),1,fcal);
fwrite(&(scanner->calibrations[i].green->white_level),sizeof(SANE_Int),1,fcal);
fwrite(scanner->calibrations[i].green->k_white,sizeof(unsigned int),scanner->calibrations[i].green->width,fcal);
fwrite(scanner->calibrations[i].green->k_black,sizeof(unsigned int),scanner->calibrations[i].green->width,fcal);
fwrite(scanner->calibrations[i].green->white_line,sizeof(double),scanner->calibrations[i].green->width,fcal);
fwrite(scanner->calibrations[i].green->black_line,sizeof(double),scanner->calibrations[i].green->width,fcal);
fwrite (&(scanner->calibrations[i].green->width), sizeof (SANE_Int), 1,
fcal);
fwrite (&(scanner->calibrations[i].green->white_level),
sizeof (SANE_Int), 1, fcal);
fwrite (scanner->calibrations[i].green->k_white, sizeof (unsigned int),
scanner->calibrations[i].green->width, fcal);
fwrite (scanner->calibrations[i].green->k_black, sizeof (unsigned int),
scanner->calibrations[i].green->width, fcal);
fwrite (scanner->calibrations[i].green->white_line, sizeof (double),
scanner->calibrations[i].green->width, fcal);
fwrite (scanner->calibrations[i].green->black_line, sizeof (double),
scanner->calibrations[i].green->width, fcal);
fwrite(&(scanner->calibrations[i].blue->width),sizeof(SANE_Int),1,fcal);
fwrite(&(scanner->calibrations[i].blue->white_level),sizeof(SANE_Int),1,fcal);
fwrite(scanner->calibrations[i].blue->k_white,sizeof(unsigned int),scanner->calibrations[i].blue->width,fcal);
fwrite(scanner->calibrations[i].blue->k_black,sizeof(unsigned int),scanner->calibrations[i].blue->width,fcal);
fwrite(scanner->calibrations[i].blue->white_line,sizeof(double),scanner->calibrations[i].blue->width,fcal);
fwrite(scanner->calibrations[i].blue->black_line,sizeof(double),scanner->calibrations[i].blue->width,fcal);
fwrite (&(scanner->calibrations[i].blue->width), sizeof (SANE_Int), 1,
fcal);
fwrite (&(scanner->calibrations[i].blue->white_level),
sizeof (SANE_Int), 1, fcal);
fwrite (scanner->calibrations[i].blue->k_white, sizeof (unsigned int),
scanner->calibrations[i].blue->width, fcal);
fwrite (scanner->calibrations[i].blue->k_black, sizeof (unsigned int),
scanner->calibrations[i].blue->width, fcal);
fwrite (scanner->calibrations[i].blue->white_line, sizeof (double),
scanner->calibrations[i].blue->width, fcal);
fwrite (scanner->calibrations[i].blue->black_line, sizeof (double),
scanner->calibrations[i].blue->width, fcal);
if(scanner->calibrations[i].gray!=NULL)
{
fwrite(&(scanner->calibrations[i].gray->width),sizeof(SANE_Int),1,fcal);
fwrite(&(scanner->calibrations[i].gray->white_level),sizeof(SANE_Int),1,fcal);
fwrite(scanner->calibrations[i].gray->k_white,sizeof(unsigned int),scanner->calibrations[i].gray->width,fcal);
fwrite(scanner->calibrations[i].gray->k_black,sizeof(unsigned int),scanner->calibrations[i].gray->width,fcal);
fwrite(scanner->calibrations[i].gray->white_line,sizeof(double),scanner->calibrations[i].gray->width,fcal);
fwrite(scanner->calibrations[i].gray->black_line,sizeof(double),scanner->calibrations[i].gray->width,fcal);
}
if (scanner->calibrations[i].gray != NULL)
{
fwrite (&(scanner->calibrations[i].gray->width), sizeof (SANE_Int),
1, fcal);
fwrite (&(scanner->calibrations[i].gray->white_level),
sizeof (SANE_Int), 1, fcal);
fwrite (scanner->calibrations[i].gray->k_white,
sizeof (unsigned int), scanner->calibrations[i].gray->width,
fcal);
fwrite (scanner->calibrations[i].gray->k_black,
sizeof (unsigned int), scanner->calibrations[i].gray->width,
fcal);
fwrite (scanner->calibrations[i].gray->white_line, sizeof (double),
scanner->calibrations[i].gray->width, fcal);
fwrite (scanner->calibrations[i].gray->black_line, sizeof (double),
scanner->calibrations[i].gray->width, fcal);
}
else
{
fwrite(&nullwidth,sizeof(SANE_Int),1,fcal);
}
{
fwrite (&nullwidth, sizeof (SANE_Int), 1, fcal);
}
}
DBG(5,"gt68xx_write_calibration: wrote %d calibrations\n",i);
DBG (5, "gt68xx_write_calibration: wrote %d calibrations\n", i);
fclose(fcal);
fclose (fcal);
return SANE_STATUS_GOOD;
}
static SANE_Status gt68xx_read_calibration (GT68xx_Scanner * scanner)
static SANE_Status
gt68xx_read_calibration (GT68xx_Scanner * scanner)
{
char *fname;
FILE *fcal;
int i;
SANE_Int width,level;
SANE_Int width, level;
scanner->calibrated = SANE_FALSE;
fname=gt68xx_calibration_file(scanner);
fcal=fopen(fname,"rb");
free(fname);
if(fcal==NULL)
fname = gt68xx_calibration_file (scanner);
fcal = fopen (fname, "rb");
free (fname);
if (fcal == NULL)
{
DBG(1,"gt68xx_read_calibration: failed to open calibration file for reading %s\n",strerror(errno));
DBG (1,
"gt68xx_read_calibration: failed to open calibration file for reading %s\n",
strerror (errno));
return SANE_STATUS_IO_ERROR;
}
@ -2592,57 +2662,76 @@ static SANE_Status gt68xx_read_calibration (GT68xx_Scanner * scanner)
* directory used trough different archs */
/* TODO check for errors */
fread(&(scanner->afe_params), sizeof(GT68xx_AFE_Parameters), 1, fcal);
fread(&(scanner->exposure_params), sizeof(GT68xx_Exposure_Parameters), 1, fcal);
fread (&(scanner->afe_params), sizeof (GT68xx_AFE_Parameters), 1, fcal);
fread (&(scanner->exposure_params), sizeof (GT68xx_Exposure_Parameters), 1,
fcal);
/* loop on calibrators */
i=0;
fread(&(scanner->calibrations[i].dpi),sizeof(SANE_Int),1,fcal);
while(!feof(fcal)&&scanner->calibrations[i].dpi>0)
i = 0;
fread (&(scanner->calibrations[i].dpi), sizeof (SANE_Int), 1, fcal);
while (!feof (fcal) && scanner->calibrations[i].dpi > 0)
{
fread(&(scanner->calibrations[i].pixel_x0),sizeof(SANE_Int),1,fcal);
fread (&(scanner->calibrations[i].pixel_x0), sizeof (SANE_Int), 1,
fcal);
fread(&width,sizeof(SANE_Int),1,fcal);
fread(&level,sizeof(SANE_Int),1,fcal);
fread (&width, sizeof (SANE_Int), 1, fcal);
fread (&level, sizeof (SANE_Int), 1, fcal);
gt68xx_calibrator_new (width, level, &(scanner->calibrations[i].red));
fread(scanner->calibrations[i].red->k_white,sizeof(unsigned int),width,fcal);
fread(scanner->calibrations[i].red->k_black,sizeof(unsigned int),width,fcal);
fread(scanner->calibrations[i].red->white_line,sizeof(double),width,fcal);
fread(scanner->calibrations[i].red->black_line,sizeof(double),width,fcal);
fread (scanner->calibrations[i].red->k_white, sizeof (unsigned int),
width, fcal);
fread (scanner->calibrations[i].red->k_black, sizeof (unsigned int),
width, fcal);
fread (scanner->calibrations[i].red->white_line, sizeof (double), width,
fcal);
fread (scanner->calibrations[i].red->black_line, sizeof (double), width,
fcal);
fread(&width,sizeof(SANE_Int),1,fcal);
fread(&level,sizeof(SANE_Int),1,fcal);
fread (&width, sizeof (SANE_Int), 1, fcal);
fread (&level, sizeof (SANE_Int), 1, fcal);
gt68xx_calibrator_new (width, level, &(scanner->calibrations[i].green));
fread(scanner->calibrations[i].green->k_white,sizeof(unsigned int),width,fcal);
fread(scanner->calibrations[i].green->k_black,sizeof(unsigned int),width,fcal);
fread(scanner->calibrations[i].green->white_line,sizeof(double),width,fcal);
fread(scanner->calibrations[i].green->black_line,sizeof(double),width,fcal);
fread (scanner->calibrations[i].green->k_white, sizeof (unsigned int),
width, fcal);
fread (scanner->calibrations[i].green->k_black, sizeof (unsigned int),
width, fcal);
fread (scanner->calibrations[i].green->white_line, sizeof (double),
width, fcal);
fread (scanner->calibrations[i].green->black_line, sizeof (double),
width, fcal);
fread(&width,sizeof(SANE_Int),1,fcal);
fread(&level,sizeof(SANE_Int),1,fcal);
fread (&width, sizeof (SANE_Int), 1, fcal);
fread (&level, sizeof (SANE_Int), 1, fcal);
gt68xx_calibrator_new (width, level, &(scanner->calibrations[i].blue));
fread(scanner->calibrations[i].blue->k_white,sizeof(unsigned int),width,fcal);
fread(scanner->calibrations[i].blue->k_black,sizeof(unsigned int),width,fcal);
fread(scanner->calibrations[i].blue->white_line,sizeof(double),width,fcal);
fread(scanner->calibrations[i].blue->black_line,sizeof(double),width,fcal);
fread (scanner->calibrations[i].blue->k_white, sizeof (unsigned int),
width, fcal);
fread (scanner->calibrations[i].blue->k_black, sizeof (unsigned int),
width, fcal);
fread (scanner->calibrations[i].blue->white_line, sizeof (double),
width, fcal);
fread (scanner->calibrations[i].blue->black_line, sizeof (double),
width, fcal);
fread(&width,sizeof(SANE_Int),1,fcal);
if(width>0)
{
fread(&level,sizeof(SANE_Int),1,fcal);
gt68xx_calibrator_new (width, level, &(scanner->calibrations[i].gray));
fread(scanner->calibrations[i].gray->k_white,sizeof(unsigned int),width,fcal);
fread(scanner->calibrations[i].gray->k_black,sizeof(unsigned int),width,fcal);
fread(scanner->calibrations[i].gray->white_line,sizeof(double),width,fcal);
fread(scanner->calibrations[i].gray->black_line,sizeof(double),width,fcal);
}
fread (&width, sizeof (SANE_Int), 1, fcal);
if (width > 0)
{
fread (&level, sizeof (SANE_Int), 1, fcal);
gt68xx_calibrator_new (width, level,
&(scanner->calibrations[i].gray));
fread (scanner->calibrations[i].gray->k_white,
sizeof (unsigned int), width, fcal);
fread (scanner->calibrations[i].gray->k_black,
sizeof (unsigned int), width, fcal);
fread (scanner->calibrations[i].gray->white_line, sizeof (double),
width, fcal);
fread (scanner->calibrations[i].gray->black_line, sizeof (double),
width, fcal);
}
/* prepare for nex resolution */
i++;
fread(&(scanner->calibrations[i].dpi),sizeof(SANE_Int),1,fcal);
fread (&(scanner->calibrations[i].dpi), sizeof (SANE_Int), 1, fcal);
}
DBG(5,"gt68xx_read_calibration: read %d calibrations\n",i);
fclose(fcal);
DBG (5, "gt68xx_read_calibration: read %d calibrations\n", i);
fclose (fcal);
scanner->val[OPT_QUALITY_CAL].w = SANE_TRUE;
scanner->calibrated = SANE_TRUE;

Wyświetl plik

@ -230,8 +230,12 @@ enum GT68xx_Option
OPT_BR_Y, /* bottom-right y */
OPT_SENSOR_GROUP,
OPT_NEED_CALIBRATION_SW, /* signals calibration is needed */
OPT_BUTTON_GROUP,
OPT_CALIBRATE, /* button option to trigger call
to sheetfed calibration */
OPT_CLEAR_CALIBRATION, /* clear calibration */
/* must come last: */
NUM_OPTIONS