From aa7f92c0636941989ba6163867788c22536a8e03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Voltz?= Date: Sat, 15 May 2004 05:03:42 +0000 Subject: [PATCH] - added protection against configuration tools that put several 'port' option in umax_pp.conf file - fixed y origin shift bug for 610P --- ChangeLog | 6 ++ backend/umax_pp.c | 23 ++++-- backend/umax_pp_low.c | 187 ++++++++++++++++++++---------------------- tools/umax_pp.c | 7 +- 4 files changed, 114 insertions(+), 109 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6d9201a0b..b89b51272 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2004-05-15 Stéphane Voltz + + * 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 * backend/umax_pp_low.c backend/umax_pp.c tools/umax_pp.c: fixed diff --git a/backend/umax_pp.c b/backend/umax_pp.c index 810ff8b49..4965cd136 100644 --- a/backend/umax_pp.c +++ b/backend/umax_pp.c @@ -755,6 +755,7 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) size_t len; FILE *fp; SANE_Status ret; + int portdone = 0; 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])) { + /* 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 = sanei_config_skip_whitespace (cp); + portdone = 1; if (*cp) { @@ -2170,8 +2180,8 @@ sane_start (SANE_Handle handle) delta = umax_pp_get_sync (dev->dpi); points = 2 * delta; /* first lines are 'garbage' for 610P */ - if(sanei_umax_pp_getastra()<1210) - points*=2; + if (sanei_umax_pp_getastra () < 1210) + points *= 2; DBG (64, "sane_start:umax_pp_start(%d,%d,%d,%d,%d,1,%X,%X)\n", dev->TopX, dev->TopY - points, @@ -2240,9 +2250,10 @@ sane_start (SANE_Handle handle) dev->read = 0; /* leading lines for 610P aren't complete in color mode */ - /* and should be discarded */ - if((sanei_umax_pp_getastra()<1210)&&(dev->color == UMAX_PP_MODE_COLOR)) - { + /* and should be discarded */ + if ((sanei_umax_pp_getastra () < 1210) + && (dev->color == UMAX_PP_MODE_COLOR)) + { rc = sanei_umax_pp_read (2 * delta * dev->tw * dev->bpp, dev->tw, dev->dpi, 0, @@ -2253,7 +2264,7 @@ sane_start (SANE_Handle handle) DBG (2, "sane_start: first lines discarding failed\n"); return SANE_STATUS_IO_ERROR; } - } + } /* in case of color, we have to preload blue and green */ /* data to allow reordering while later read */ diff --git a/backend/umax_pp_low.c b/backend/umax_pp_low.c index b7f8c5e35..35a89485e 100644 --- a/backend/umax_pp_low.c +++ b/backend/umax_pp_low.c @@ -826,7 +826,7 @@ sanei_parport_find_port (void) char ** sanei_parport_find_device (void) { - char *devices[] = { + char *devices[] = { /* FreeBSD */ "/dev/ppi0", "/dev/ppi1", @@ -3613,11 +3613,13 @@ putByte610p (int data) { int status, control, j; - j=0; - do { - status = Inb (STATUS) & 0xF8; - j++; - } while((j<20)&&(status & 0x08)); + j = 0; + do + { + status = Inb (STATUS) & 0xF8; + j++; + } + while ((j < 20) && (status & 0x08)); if ((status != 0xC8) && (status != 0xC0)) { @@ -4633,12 +4635,12 @@ SPPsendWord610p (int *cmd) return 0; } status = Inb (STATUS) & 0xF8; - j=0; - while((j<256)&&(status & 0x08)) - { - j++; - status = Inb (STATUS) & 0xF8; - } + j = 0; + while ((j < 256) && (status & 0x08)) + { + j++; + status = Inb (STATUS) & 0xF8; + } if ((status != 0x80) && (status != 0xA0)) { 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]); i++; } - j=0; - while((status & 0x08)&&(j<256)) - { - status=getStatus610p(); - j++; - } + j = 0; + while ((status & 0x08) && (j < 256)) + { + status = getStatus610p (); + j++; + } if ((status != 0xC0) && (status != 0xD0)) { DBG (0, @@ -7912,12 +7914,12 @@ cmdGet610p (int cmd, int len, int *val) } status = getStatus610p (); scannerStatus = status; - j=0; - while((j<256)&&(status & 0x08)) - { - status = getStatus610p (); - j++; - } + j = 0; + while ((j < 256) && (status & 0x08)) + { + status = getStatus610p (); + j++; + } if (status != 0xC0) { 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 (); scannerStatus = status; - j=0; - while((j<256)&&(status & 0x08)) - { - status = getStatus610p (); - j++; - } + j = 0; + while ((j < 256) && (status & 0x08)) + { + status = getStatus610p (); + j++; + } if (status != 0xC0) { DBG (1, "Found 0x%X expected 0xC0 (%s:%d)\n", status, __FILE__, __LINE__); - /* return 0;*/ + /* return 0; */ } disconnect610p (); 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 */ if (color >= RGB_MODE) - { - if(sanei_umax_pp_getastra()<=610) - offset=4 * delta; - else - offset=2 *delta; - } + { + if (sanei_umax_pp_getastra () <= 610) + offset = 4 * delta; + else + offset = 2 * delta; + } else - offset=0; + offset = 0; - rc = sanei_umax_pp_startScan - (x, y - offset, width, height + offset, dpi, color, brightness, - contrast, &bpp, &tw, &th); + rc = sanei_umax_pp_startScan + (x, y - offset, width, height + offset, dpi, color, brightness, + contrast, &bpp, &tw, &th); if (rc == 1) { /* 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 */ /*blocksize=(2096100/bpl)*bpl; */ bpl = bpp * tw; - /*hp = 16776960 / bpl;*/ /* XXX STEF XXX 16 Mo buffer (!!) */ + /*hp = 16776960 / bpl; *//* XXX STEF XXX 16 Mo buffer (!!) */ hp = 2096100 / bpl; blocksize = hp * bpl; 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__); /* correct th to be usable scan height */ - th-=offset; + th -= offset; /* we need a 2 * delta lines reserve to reorder data */ if (color >= RGB_MODE) - { - reserve = 2 * delta * bpl; - if(sanei_umax_pp_getastra()<1210) - offset=reserve; - else - offset=0; - } + { + reserve = 2 * delta * bpl; + if (sanei_umax_pp_getastra () < 1210) + offset = reserve; + else + offset = 0; + } else - { - reserve = 0; - offset=0; - } + { + reserve = 0; + offset = 0; + } /* 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 */ if (color >= RGB_MODE) 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 fprintf (fout, "P5\n%d %d\n255\n", tw, th); } /* read some line first until we got clean data */ - read=0; + read = 0; remain = 0; - while(read 128) { for (y = 0; y < top; y++) 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; } - /*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); /* prevent overflow */ if (coeff > 127) @@ -12329,8 +12316,8 @@ shadingCalibration (int color, int dcRed, int dcGreen, int dcBlue, } } - if (DBG_LEVEL > 128) - DumpNB (w * 3, h, data, NULL); + if (DBG_LEVEL > 128) + DumpNB (w * 3, h, data, NULL); free (data); TRACE (16, "shadingCalibration end ...\n"); diff --git a/tools/umax_pp.c b/tools/umax_pp.c index fd2072677..3d47d6925 100644 --- a/tools/umax_pp.c +++ b/tools/umax_pp.c @@ -37,7 +37,7 @@ main (int argc, char **argv) int found; int recover = 0; int trace = 0; - int maxw,maxh; + int maxw, maxh; /* scanning parameters : defaults to preview (75 dpi color, full scan area) */ int brightness = 0x0; @@ -336,7 +336,8 @@ main (int argc, char **argv) } 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 printf ("ppdev character device built-in.\n"); #endif @@ -479,7 +480,7 @@ main (int argc, char **argv) } /* 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 */ /* 0: failed