- added protection against configuration tools that put

several 'port' option in umax_pp.conf file
	- fixed y origin shift bug for 610P
merge-requests/1/head
Stéphane Voltz 2004-05-15 05:03:42 +00:00
rodzic 94e5c585fb
commit aa7f92c063
4 zmienionych plików z 114 dodań i 109 usunięć

Wyświetl plik

@ -1,3 +1,9 @@
2004-05-15 Stéphane Voltz <svoltz@wanadoo.fr>
* backend/umax_pp_low.c backend/umax_pp.c tools/umax_pp.c: fixed
origin shift bug for 610P. Added on guard against configuration
that can put several 'port' option in conf file.
2004-05-13 Stéphane Voltz <svoltz@wanadoo.fr> 2004-05-13 Stéphane Voltz <svoltz@wanadoo.fr>
* backend/umax_pp_low.c backend/umax_pp.c tools/umax_pp.c: fixed * backend/umax_pp_low.c backend/umax_pp.c tools/umax_pp.c: fixed

Wyświetl plik

@ -755,6 +755,7 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
size_t len; size_t len;
FILE *fp; FILE *fp;
SANE_Status ret; SANE_Status ret;
int portdone = 0;
DBG_INIT (); DBG_INIT ();
@ -1003,9 +1004,18 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
} }
else if ((strncmp (cp, "port", 4) == 0) && isspace (cp[4])) else if ((strncmp (cp, "port", 4) == 0) && isspace (cp[4]))
{ {
/* protect ourself from buggy configuration tool such as
* mandrake's 9.2 control panel */
if (portdone)
{
DBG (2,
"'port' option given more than once, check your umax_pp.conf file!!\n");
return SANE_STATUS_INVAL;
}
cp += 5; cp += 5;
cp = sanei_config_skip_whitespace (cp); cp = sanei_config_skip_whitespace (cp);
portdone = 1;
if (*cp) if (*cp)
{ {
@ -2170,8 +2180,8 @@ sane_start (SANE_Handle handle)
delta = umax_pp_get_sync (dev->dpi); delta = umax_pp_get_sync (dev->dpi);
points = 2 * delta; points = 2 * delta;
/* first lines are 'garbage' for 610P */ /* first lines are 'garbage' for 610P */
if(sanei_umax_pp_getastra()<1210) if (sanei_umax_pp_getastra () < 1210)
points*=2; points *= 2;
DBG (64, "sane_start:umax_pp_start(%d,%d,%d,%d,%d,1,%X,%X)\n", DBG (64, "sane_start:umax_pp_start(%d,%d,%d,%d,%d,1,%X,%X)\n",
dev->TopX, dev->TopX,
dev->TopY - points, dev->TopY - points,
@ -2240,9 +2250,10 @@ sane_start (SANE_Handle handle)
dev->read = 0; dev->read = 0;
/* leading lines for 610P aren't complete in color mode */ /* leading lines for 610P aren't complete in color mode */
/* and should be discarded */ /* and should be discarded */
if((sanei_umax_pp_getastra()<1210)&&(dev->color == UMAX_PP_MODE_COLOR)) if ((sanei_umax_pp_getastra () < 1210)
{ && (dev->color == UMAX_PP_MODE_COLOR))
{
rc = rc =
sanei_umax_pp_read (2 * delta * dev->tw * dev->bpp, dev->tw, dev->dpi, sanei_umax_pp_read (2 * delta * dev->tw * dev->bpp, dev->tw, dev->dpi,
0, 0,
@ -2253,7 +2264,7 @@ sane_start (SANE_Handle handle)
DBG (2, "sane_start: first lines discarding failed\n"); DBG (2, "sane_start: first lines discarding failed\n");
return SANE_STATUS_IO_ERROR; return SANE_STATUS_IO_ERROR;
} }
} }
/* in case of color, we have to preload blue and green */ /* in case of color, we have to preload blue and green */
/* data to allow reordering while later read */ /* data to allow reordering while later read */

Wyświetl plik

@ -826,7 +826,7 @@ sanei_parport_find_port (void)
char ** char **
sanei_parport_find_device (void) sanei_parport_find_device (void)
{ {
char *devices[] = { char *devices[] = {
/* FreeBSD */ /* FreeBSD */
"/dev/ppi0", "/dev/ppi0",
"/dev/ppi1", "/dev/ppi1",
@ -3613,11 +3613,13 @@ putByte610p (int data)
{ {
int status, control, j; int status, control, j;
j=0; j = 0;
do { do
status = Inb (STATUS) & 0xF8; {
j++; status = Inb (STATUS) & 0xF8;
} while((j<20)&&(status & 0x08)); j++;
}
while ((j < 20) && (status & 0x08));
if ((status != 0xC8) && (status != 0xC0)) if ((status != 0xC8) && (status != 0xC0))
{ {
@ -4633,12 +4635,12 @@ SPPsendWord610p (int *cmd)
return 0; return 0;
} }
status = Inb (STATUS) & 0xF8; status = Inb (STATUS) & 0xF8;
j=0; j = 0;
while((j<256)&&(status & 0x08)) while ((j < 256) && (status & 0x08))
{ {
j++; j++;
status = Inb (STATUS) & 0xF8; status = Inb (STATUS) & 0xF8;
} }
if ((status != 0x80) && (status != 0xA0)) if ((status != 0x80) && (status != 0xA0))
{ {
DBG (0, "SPPsendWord610p found 0x%X expected 0x80 or 0xA0 (%s:%d)\n", DBG (0, "SPPsendWord610p found 0x%X expected 0x80 or 0xA0 (%s:%d)\n",
@ -5308,12 +5310,12 @@ sendData610p (int *cmd, int len)
status = putByte610p (cmd[i]); status = putByte610p (cmd[i]);
i++; i++;
} }
j=0; j = 0;
while((status & 0x08)&&(j<256)) while ((status & 0x08) && (j < 256))
{ {
status=getStatus610p(); status = getStatus610p ();
j++; j++;
} }
if ((status != 0xC0) && (status != 0xD0)) if ((status != 0xC0) && (status != 0xD0))
{ {
DBG (0, DBG (0,
@ -7912,12 +7914,12 @@ cmdGet610p (int cmd, int len, int *val)
} }
status = getStatus610p (); status = getStatus610p ();
scannerStatus = status; scannerStatus = status;
j=0; j = 0;
while((j<256)&&(status & 0x08)) while ((j < 256) && (status & 0x08))
{ {
status = getStatus610p (); status = getStatus610p ();
j++; j++;
} }
if (status != 0xC0) if (status != 0xC0)
{ {
DBG (0, "Found 0x%02X expected 0xC0 (%s:%d)\n", status, __FILE__, DBG (0, "Found 0x%02X expected 0xC0 (%s:%d)\n", status, __FILE__,
@ -7993,17 +7995,17 @@ cmdSet610p (int cmd, int len, int *val)
} }
status = getStatus610p (); status = getStatus610p ();
scannerStatus = status; scannerStatus = status;
j=0; j = 0;
while((j<256)&&(status & 0x08)) while ((j < 256) && (status & 0x08))
{ {
status = getStatus610p (); status = getStatus610p ();
j++; j++;
} }
if (status != 0xC0) if (status != 0xC0)
{ {
DBG (1, "Found 0x%X expected 0xC0 (%s:%d)\n", status, __FILE__, DBG (1, "Found 0x%X expected 0xC0 (%s:%d)\n", status, __FILE__,
__LINE__); __LINE__);
/* return 0;*/ /* return 0; */
} }
disconnect610p (); disconnect610p ();
return 1; return 1;
@ -10478,18 +10480,18 @@ sanei_umax_pp_scan (int x, int y, int width, int height, int dpi, int color,
/* in color mode, we need extra lines to reorder data */ /* in color mode, we need extra lines to reorder data */
if (color >= RGB_MODE) if (color >= RGB_MODE)
{ {
if(sanei_umax_pp_getastra()<=610) if (sanei_umax_pp_getastra () <= 610)
offset=4 * delta; offset = 4 * delta;
else else
offset=2 *delta; offset = 2 * delta;
} }
else else
offset=0; offset = 0;
rc = sanei_umax_pp_startScan rc = sanei_umax_pp_startScan
(x, y - offset, width, height + offset, dpi, color, brightness, (x, y - offset, width, height + offset, dpi, color, brightness,
contrast, &bpp, &tw, &th); contrast, &bpp, &tw, &th);
if (rc == 1) if (rc == 1)
{ {
/* blocksize must be multiple of the number of bytes per line */ /* blocksize must be multiple of the number of bytes per line */
@ -10498,7 +10500,7 @@ sanei_umax_pp_scan (int x, int y, int width, int height, int dpi, int color,
/* write data to file operation */ /* write data to file operation */
/*blocksize=(2096100/bpl)*bpl; */ /*blocksize=(2096100/bpl)*bpl; */
bpl = bpp * tw; bpl = bpp * tw;
/*hp = 16776960 / bpl;*/ /* XXX STEF XXX 16 Mo buffer (!!) */ /*hp = 16776960 / bpl; *//* XXX STEF XXX 16 Mo buffer (!!) */
hp = 2096100 / bpl; hp = 2096100 / bpl;
blocksize = hp * bpl; blocksize = hp * bpl;
nb = 0; nb = 0;
@ -10507,22 +10509,22 @@ sanei_umax_pp_scan (int x, int y, int width, int height, int dpi, int color,
somme, somme, __FILE__, __LINE__); somme, somme, __FILE__, __LINE__);
/* correct th to be usable scan height */ /* correct th to be usable scan height */
th-=offset; th -= offset;
/* we need a 2 * delta lines reserve to reorder data */ /* we need a 2 * delta lines reserve to reorder data */
if (color >= RGB_MODE) if (color >= RGB_MODE)
{ {
reserve = 2 * delta * bpl; reserve = 2 * delta * bpl;
if(sanei_umax_pp_getastra()<1210) if (sanei_umax_pp_getastra () < 1210)
offset=reserve; offset = reserve;
else else
offset=0; offset = 0;
} }
else else
{ {
reserve = 0; reserve = 0;
offset=0; offset = 0;
} }
/* get scanned data */ /* get scanned data */
@ -10548,46 +10550,45 @@ sanei_umax_pp_scan (int x, int y, int width, int height, int dpi, int color,
/* write pnm header */ /* write pnm header */
if (color >= RGB_MODE) if (color >= RGB_MODE)
fprintf (fout, "P6\n%d %d\n255\n", tw, th - 2 * delta); fprintf (fout, "P6\n%d %d\n255\n", tw, th - 2 * delta);
/*fprintf (fout, "P5\n%d %d\n255\n", tw, 3*th);*/ /*fprintf (fout, "P5\n%d %d\n255\n", tw, 3*th); */
else else
fprintf (fout, "P5\n%d %d\n255\n", tw, th); fprintf (fout, "P5\n%d %d\n255\n", tw, th);
} }
/* read some line first until we got clean data */ /* read some line first until we got clean data */
read=0; read = 0;
remain = 0; remain = 0;
while(read<offset) while (read < offset)
{ {
if (read==0) if (read == 0)
len = offset; len = offset;
else else
len = offset - read; len = offset - read;
len = len = sanei_umax_pp_readBlock (len, tw, dpi, 0, buffer + read);
sanei_umax_pp_readBlock (len, tw, dpi, 0, buffer+read);
if (len == 0) if (len == 0)
{ {
DBG (0, DBG (0,
"sanei_umax_pp_readBlock failed, cancelling scan ...\n"); "sanei_umax_pp_readBlock failed, cancelling scan ...\n");
gCancel = 1; gCancel = 1;
} }
read+=len; read += len;
} }
/* in color mode we have to fill the 'reserve' area /* in color mode we have to fill the 'reserve' area
* so that we can reorder data lines */ * so that we can reorder data lines */
while((read-offset<reserve)&&(!gCancel)) while ((read - offset < reserve) && (!gCancel))
{ {
len = reserve - read + offset; len = reserve - read + offset;
len = len =
sanei_umax_pp_readBlock (len, tw, dpi, 0, buffer+read-offset); sanei_umax_pp_readBlock (len, tw, dpi, 0, buffer + read - offset);
if (len == 0) if (len == 0)
{ {
DBG (0, DBG (0,
"sanei_umax_pp_readBlock failed, cancelling scan ...\n"); "sanei_umax_pp_readBlock failed, cancelling scan ...\n");
gCancel = 1; gCancel = 1;
} }
read+=len; read += len;
} }
/* data reading loop */ /* data reading loop */
#ifdef HAVE_SYS_TIME_H #ifdef HAVE_SYS_TIME_H
@ -10629,14 +10630,14 @@ sanei_umax_pp_scan (int x, int y, int width, int height, int dpi, int color,
switch (sanei_umax_pp_getastra ()) switch (sanei_umax_pp_getastra ())
{ {
case 6100: case 6100:
fwrite (buffer+reserve, hp*bpl, 1, fout); fwrite (buffer + reserve, hp * bpl, 1, fout);
break; break;
case 610: case 610:
/* first comes RED /* first comes RED
* then BLUE * then BLUE
* and finally GREEN */ * and finally GREEN */
for (by = 0; by < hp ; by++) for (by = 0; by < hp; by++)
{ {
for (bx = 0; bx < tw; bx++) for (bx = 0; bx < tw; bx++)
{ {
@ -11065,7 +11066,7 @@ sanei_umax_pp_startScan (int x, int y, int width, int height, int dpi,
vgaGreen = brightness / 256; vgaGreen = brightness / 256;
} }
/* correct y to match exact scan area start /* corrects y to match exact scan area start
* and lets room for a leading zone so that * and lets room for a leading zone so that
* we can reorder data */ * we can reorder data */
switch (sanei_umax_pp_getastra ()) switch (sanei_umax_pp_getastra ())
@ -11075,34 +11076,20 @@ sanei_umax_pp_startScan (int x, int y, int width, int height, int dpi,
switch (dpi) switch (dpi)
{ {
case 600: case 600:
y += 0; y += 64;
break; break;
case 300: case 300:
y += 0; y += 32;
break; break;
case 150: case 150:
y += 0; y += 16;
break; break;
case 75: case 75:
y += 0; y += 8;
break; break;
} }
else else
switch (dpi) y += 80;
{
case 600:
y += 0;
break;
case 300:
y += 0;
break;
case 150:
y += 0;
break;
case 75:
y += 0;
break;
}
default: default:
y += 8; y += 8;
break; break;
@ -12225,7 +12212,7 @@ shadingCalibration (int color, int dcRed, int dcGreen, int dcBlue,
int sum, i; int sum, i;
float avg, coeff; float avg, coeff;
unsigned char *data = NULL; unsigned char *data = NULL;
int top,bottom; int top, bottom;
TRACE (16, "entering shadingCalibration ...\n"); TRACE (16, "entering shadingCalibration ...\n");
if (sanei_umax_pp_getastra () < 1220) if (sanei_umax_pp_getastra () < 1220)
@ -12235,8 +12222,8 @@ shadingCalibration (int color, int dcRed, int dcGreen, int dcBlue,
y = 10; y = 10;
dpi = 300; dpi = 300;
h = 90; h = 90;
top=18; top = 18;
bottom=12; bottom = 12;
} }
else else
{ {
@ -12245,8 +12232,8 @@ shadingCalibration (int color, int dcRed, int dcGreen, int dcBlue,
y = 10; y = 10;
dpi = 600; dpi = 600;
h = 67; h = 67;
top=18; top = 18;
bottom=12; bottom = 12;
} }
data = (unsigned char *) malloc (w * h * 3); data = (unsigned char *) malloc (w * h * 3);
@ -12312,15 +12299,15 @@ shadingCalibration (int color, int dcRed, int dcGreen, int dcBlue,
sum = 0; sum = 0;
for (y = top; y < h - bottom; y++) for (y = top; y < h - bottom; y++)
sum += data[(y * 3 + i) * w + x]; sum += data[(y * 3 + i) * w + x];
avg = ((float) (sum)) / ((float) (h - (top+bottom))); avg = ((float) (sum)) / ((float) (h - (top + bottom)));
if (DBG_LEVEL > 128) if (DBG_LEVEL > 128)
{ {
for (y = 0; y < top; y++) for (y = 0; y < top; y++)
data[(y * 3 + i) * w + x] = avg; data[(y * 3 + i) * w + x] = avg;
for (y = h-bottom; y < h; y++) for (y = h - bottom; y < h; y++)
data[(y * 3 + i) * w + x] = avg; data[(y * 3 + i) * w + x] = avg;
} }
/*coeff = (256.0 * (255.0 / avg - 1.0)) / 1.95;*/ /*coeff = (256.0 * (255.0 / avg - 1.0)) / 1.95; */
coeff = 256.0 * (255.0 / avg - 1.0); coeff = 256.0 * (255.0 / avg - 1.0);
/* prevent overflow */ /* prevent overflow */
if (coeff > 127) if (coeff > 127)
@ -12329,8 +12316,8 @@ shadingCalibration (int color, int dcRed, int dcGreen, int dcBlue,
} }
} }
if (DBG_LEVEL > 128) if (DBG_LEVEL > 128)
DumpNB (w * 3, h, data, NULL); DumpNB (w * 3, h, data, NULL);
free (data); free (data);
TRACE (16, "shadingCalibration end ...\n"); TRACE (16, "shadingCalibration end ...\n");

Wyświetl plik

@ -37,7 +37,7 @@ main (int argc, char **argv)
int found; int found;
int recover = 0; int recover = 0;
int trace = 0; int trace = 0;
int maxw,maxh; int maxw, maxh;
/* scanning parameters : defaults to preview (75 dpi color, full scan area) */ /* scanning parameters : defaults to preview (75 dpi color, full scan area) */
int brightness = 0x0; int brightness = 0x0;
@ -336,7 +336,8 @@ main (int argc, char **argv)
} }
if (trace) if (trace)
{ {
printf ("UMAX 610P/1220P/2000P scanning program version 6.1 starting ...\n"); printf
("UMAX 610P/1220P/2000P scanning program version 6.1 starting ...\n");
#ifdef HAVE_LINUX_PPDEV_H #ifdef HAVE_LINUX_PPDEV_H
printf ("ppdev character device built-in.\n"); printf ("ppdev character device built-in.\n");
#endif #endif
@ -479,7 +480,7 @@ main (int argc, char **argv)
} }
/* set x origin left to right */ /* set x origin left to right */
x = sanei_umax_pp_getLeft() + (maxw - x) - width; x = sanei_umax_pp_getLeft () + (maxw - x) - width;
/* init transport layer */ /* init transport layer */
/* 0: failed /* 0: failed