- free (devlist) added so memory allocated by sane_get_devices() will be released (bugreport 300128)
- added more DEBUG lines and some small fixes.
merge-requests/1/head
Gerard Klaver 2005-05-06 21:12:21 +00:00
rodzic b3669f8d6e
commit c33139cc82
2 zmienionych plików z 410 dodań i 294 usunięć

Wyświetl plik

@ -1,3 +1,8 @@
2005-05-06 Gerard Klaver <gerard at gkall dot hobby dot nl>
* backend/qcam.c -indent -gnu, bugreport 300128 free (devlist) added,
DEBUG output added and some small fixes.
2005-05-05 Henning Meier-Geinitz <henning@meier-geinitz.de>
* doc/descriptions/unsupported.desc: Added Dell 922.

Wyświetl plik

@ -131,66 +131,58 @@ static int num_devices;
static QC_Device *first_dev;
static QC_Scanner *first_handle;
static const SANE_String_Const resolution_list[] =
{
static const SANE_String_Const resolution_list[] = {
"Low", /* million-mode */
"High", /* billion-mode */
0
};
static const SANE_Int mono_depth_list[] =
{
static const SANE_Int mono_depth_list[] = {
2, /* # of elements */
4, 6
};
static const SANE_Int color_depth_list[] =
{
/*2*/ 1, /* # of elements */
/*16,*/ 24 /* "thousand" mode not implemented yet */
static const SANE_Int color_depth_list[] = {
/*2 */ 1,
/* # of elements */
/*16, */ 24
/* "thousand" mode not implemented yet */
};
static const SANE_Int xfer_scale_list[] =
{
static const SANE_Int xfer_scale_list[] = {
3, /* # of elements */
1, 2, 4
};
static const SANE_Range u8_range =
{
static const SANE_Range u8_range = {
/* min, max, quantization */
0, 255, 0
};
static const SANE_Range brightness_range =
{
static const SANE_Range brightness_range = {
/* min, max, quantization */
0, 254, 0 /* 255 is bulb mode! */
};
static const SANE_Range x_range[] =
{
static const SANE_Range x_range[] = {
/* min, max, quantization */
{0, 338, 2}, /* million mode */
{0, 676, 4}, /* billion mode */
};
static const SANE_Range odd_x_range[] =
{
static const SANE_Range odd_x_range[] = {
/* min, max, quantization */
{1, 339, 2}, /* million mode */
{3, 683, 4}, /* billion mode */
};
static const SANE_Range y_range[] =
{
static const SANE_Range y_range[] = {
/* min, max, quantization */
{0, 249, 1}, /* million mode */
{0, 498, 2}, /* billion mode */
};
static const SANE_Range odd_y_range[] =
{
static const SANE_Range odd_y_range[] = {
/* min, max, quantization */
{0, 249, 1}, /* million mode */
{1, 499, 2}, /* billion mode */
@ -300,9 +292,7 @@ qc_lock_wait (QC_Device * q, int wait)
char lockfile[128];
sprintf (lockfile, "/tmp/LOCK.qcam.0x%x", q->port);
q->lock_fd = open (lockfile,
O_WRONLY | O_CREAT | O_EXCL
, 0666);
q->lock_fd = open (lockfile, O_WRONLY | O_CREAT | O_EXCL, 0666);
if (q->lock_fd < 0)
{
DBG (1, "qc_lock_wait: failed to open %s (%s)\n",
@ -329,6 +319,7 @@ qc_lock_wait (QC_Device * q, int wait)
static SANE_Status
qc_unlock (QC_Device * q)
{
SANE_Status status;
char lockfile[128];
#ifdef F_SETLK
#ifndef HAVE_STRUCT_FLOCK
@ -344,30 +335,35 @@ qc_unlock (QC_Device *q)
struct flock sfl;
#endif
DBG(3, "qc_lock_wait: releasing lock for 0x%x\n", q->port);
DBG (3, "qc_unlock: releasing lock for 0x%x\n", q->port);
#ifdef F_SETLK
memset (&sfl, 0, sizeof (sfl));
#endif
if (q->lock_fd < 0)
return SANE_STATUS_INVAL; /* port was not locked */
{
DBG (3, "qc_unlock; port was not locked\n");
return SANE_STATUS_INVAL;
}
/* clear the exclusive lock */
#ifdef F_SETLK
sfl.l_type = F_UNLCK;
if (fcntl (q->lock_fd, F_SETLK, &sfl) != 0)
{
DBG(1, "qc_lock_wait: failed to release lock (%s)\n",
strerror (errno));
DBG (3, "qc_unlock: failed to release lock (%s)\n", strerror (errno));
return SANE_STATUS_INVAL;
}
#endif
sprintf (lockfile, "/tmp/LOCK.qcam.0x%x", q->port);
DBG (1, "qc_unlock: /tmp/LOCK.qcam.0x%x\n", q->port);
unlink (lockfile);
close (q->lock_fd);
q->lock_fd = -1;
return SANE_STATUS_GOOD;
DBG (1, "qc_unlock: exit\n");
status = SANE_STATUS_GOOD;
return status;
}
static SANE_Status
@ -397,9 +393,11 @@ qc_waithand2 (QC_Device *q, int val)
{
unsigned int status;
do {
do
{
status = read_lpdata (q);
} while ((status & CamRdy2) != (unsigned int) val);
}
while ((status & CamRdy2) != (unsigned int) val);
return status;
}
@ -473,23 +471,38 @@ qc_setscanmode (QC_Scanner *s, u_int *modep)
{
switch (s->val[OPT_XFER_SCALE].w)
{
case 1: mode = 0; break;
case 2: mode = 4; break;
case 4: mode = 8; break;
case 1:
mode = 0;
break;
case 2:
mode = 4;
break;
case 4:
mode = 8;
break;
}
switch (s->val[OPT_DEPTH].w)
{
case 4: break;
case 6: mode += 2; break;
case 4:
break;
case 6:
mode += 2;
break;
}
}
else
{
switch (s->val[OPT_XFER_SCALE].w)
{
case 1: mode = 0; break;
case 2: mode = 2; break;
case 4: mode = 4; break;
case 1:
mode = 0;
break;
case 2:
mode = 2;
break;
case 4:
mode = 4;
break;
}
if (s->resolution == QC_RES_LOW)
mode |= 0x18; /* millions mode */
@ -703,17 +716,20 @@ despeckle (int width, int height, SANE_Byte *in, SANE_Byte *out)
memcpy (&out[i * 3], &in[i * 3], 3);
else
{
if (R - (G+B)/2 > NO_LIGHTS + ((pR - (pG+pB)/2) + (nR - (nG+nB)/2)))
if (R - (G + B) / 2 >
NO_LIGHTS + ((pR - (pG + pB) / 2) + (nR - (nG + nB) / 2)))
out[i * 3] = (pR + nR) / 2;
else
out[i * 3] = R;
if (G - (R+B)/2 > NO_LIGHTS + ((pG - (pR+pB)/2) + (nG - (nR+nB)/2)))
if (G - (R + B) / 2 >
NO_LIGHTS + ((pG - (pR + pB) / 2) + (nG - (nR + nB) / 2)))
out[i * 3 + 1] = (pG + nG) / 2;
else
out[i * 3 + 1] = G;
if (B - (G+R)/2 > NO_LIGHTS + ((pB - (pG+pR)/2) + (nB - (nG+nR)/2)))
if (B - (G + R) / 2 >
NO_LIGHTS + ((pB - (pG + pR) / 2) + (nB - (nG + nR) / 2)))
out[i * 3 + 2] = (pB + nB) / 2;
else
out[i * 3 + 2] = B;
@ -763,7 +779,8 @@ despeckle32 (int width, int height, SANE_Byte *in, SANE_Byte *out)
R instead: */
nR = R;
if (R - ((Ga+Gb)/2+B)/2 > NO_LIGHTS + ((pR - ((pGa+pGb)/2+pB)/2) +
if (R - ((Ga + Gb) / 2 + B) / 2 >
NO_LIGHTS + ((pR - ((pGa + pGb) / 2 + pB) / 2) +
(nR - ((nGa + nGb) / 2 + nB) / 2)))
out[i * 4 + 3] = (pR + nR) / 2;
else
@ -781,7 +798,8 @@ despeckle32 (int width, int height, SANE_Byte *in, SANE_Byte *out)
else
out[i * 4 + 2] = Gb;
if (B - ((Ga+Gb)/2+R)/2 > NO_LIGHTS + ((pB - ((pGa+pGb)/2+pR)/2) +
if (B - ((Ga + Gb) / 2 + R) / 2 >
NO_LIGHTS + ((pB - ((pGa + pGb) / 2 + pR) / 2) +
(nB - ((nGa + nGb) / 2 + nR) / 2)))
out[i * 4 + 0] = (pB + nB) / 2;
else
@ -816,6 +834,8 @@ reader_process (QC_Scanner *s, int in_fd, int out_fd)
SANE_Byte *src;
FILE *ofp;
DBG (5, "reader_process: enter\n");
enable_ports (q);
ofp = fdopen (out_fd, "w");
@ -855,7 +875,8 @@ reader_process (QC_Scanner *s, int in_fd, int out_fd)
qc_send (q, req.mode);
if (req.despeckle
&& (!extra || buffer_size < num_bytes || buffer_size >= 2*num_bytes))
&& (!extra || buffer_size < num_bytes
|| buffer_size >= 2 * num_bytes))
{
if (extra)
extra = realloc (extra, num_bytes);
@ -863,7 +884,8 @@ reader_process (QC_Scanner *s, int in_fd, int out_fd)
extra = malloc (num_bytes);
if (!extra)
{
DBG(1, "reader_process: malloc(%ld) failed\n", (long) num_bytes);
DBG (1, "reader_process: malloc(%ld) failed\n",
(long) num_bytes);
exit (1);
}
}
@ -876,7 +898,8 @@ reader_process (QC_Scanner *s, int in_fd, int out_fd)
buffer = malloc (num_bytes);
if (!buffer)
{
DBG(1, "reader_process: malloc(%ld) failed\n", (long) num_bytes);
DBG (1, "reader_process: malloc(%ld) failed\n",
(long) num_bytes);
exit (1);
}
buffer_size = num_bytes;
@ -975,7 +998,9 @@ reader_process (QC_Scanner *s, int in_fd, int out_fd)
{
int red1, green1, blue1, green2, blue2;
blue1 = src[0]; green1 = src[1]; red1 = src[3];
blue1 = src[0];
green1 = src[1];
red1 = src[3];
if (x >= width - 2)
{
red1 = src[-1]; /* last red seems to be missing */
@ -989,8 +1014,12 @@ reader_process (QC_Scanner *s, int in_fd, int out_fd)
}
src += 4;
buf[0] = red1; buf[1] = green1; buf[2] = blue1;
buf[3] = red1; buf[4] = green2; buf[5] = blue2;
buf[0] = red1;
buf[1] = green1;
buf[2] = blue1;
buf[3] = red1;
buf[4] = green2;
buf[5] = blue2;
if (fwrite (buf, 1, 6, ofp) != 6)
{
perror ("fwrite: short write");
@ -1029,8 +1058,12 @@ reader_process (QC_Scanner *s, int in_fd, int out_fd)
}
src += 4;
buf[0] = red1; buf[1] = green3; buf[2] = blue3;
buf[3] = red1; buf[4] = green4; buf[5] = blue4;
buf[0] = red1;
buf[1] = green3;
buf[2] = blue3;
buf[3] = red1;
buf[4] = green4;
buf[5] = blue4;
if (fwrite (buf, 1, 6, ofp) != 6)
{
perror ("fwrite: short write");
@ -1059,6 +1092,7 @@ reader_process (QC_Scanner *s, int in_fd, int out_fd)
fflush (ofp);
}
assert (SANE_FALSE); /* not reached */
DBG (5, "reader_process: exit\n");
return 1;
}
@ -1066,10 +1100,11 @@ static SANE_Status
attach (const char *devname, QC_Device ** devp)
{
int i, n1, n2, s1, s2, cmd, port, force_unidir;
SANE_Status result;
SANE_Status result, status;
QC_Device *q;
char *endp;
DBG (3, "attach: enter\n");
errno = 0;
force_unidir = 0;
if (devname[0] == 'u')
@ -1171,8 +1206,12 @@ attach (const char *devname, QC_Device **devp)
usleep (10000);
}
qc_unlock (q);
status = qc_unlock (q);
if (status != SANE_STATUS_GOOD)
{
DBG (1, "attach: status qc_unlock NOK\n");
/* status = SANE_STATUS_GOOD; */
}
q->sane.name = strdup (devname);
q->sane.vendor = "Connectix";
q->sane.model =
@ -1185,12 +1224,21 @@ attach (const char *devname, QC_Device **devp)
if (devp)
*devp = q;
return SANE_STATUS_GOOD;
DBG (3, "attach: exit status OK\n");
status = SANE_STATUS_GOOD;
return status;
unlock_and_fail:
qc_unlock (q);
status = qc_unlock (q);
if (status != SANE_STATUS_GOOD)
{
DBG (1, "attach: unlock_and_fail status qc_unlock NOK\n");
}
free (q);
return SANE_STATUS_INVAL;
DBG (3, "attach: exit status NOK\n");
status = SANE_STATUS_INVAL;
return status;
}
static SANE_Status
@ -1198,6 +1246,8 @@ init_options (QC_Scanner *s)
{
int i;
DBG (3, "init_options: enter\n");
memset (s->opt, 0, sizeof (s->opt));
memset (s->val, 0, sizeof (s->val));
@ -1395,6 +1445,8 @@ init_options (QC_Scanner *s)
s->opt[OPT_SATURATION].constraint.range = &u8_range;
s->val[OPT_SATURATION].w = 100;
DBG (3, "init_options: exit\n");
return SANE_STATUS_GOOD;
}
@ -1404,11 +1456,12 @@ sane_init (SANE_Int *version_code, SANE_Auth_Callback authorize)
char dev_name[PATH_MAX], *str;
size_t len;
FILE *fp;
authorize = authorize; /* silence compilation warnings */
DBG_INIT ();
DBG (1, "sane_init: enter\n");
if (version_code)
*version_code = SANE_VERSION_CODE (V_MAJOR, V_MINOR, 0);
@ -1434,6 +1487,8 @@ sane_init (SANE_Int *version_code, SANE_Auth_Callback authorize)
attach (dev_name, 0);
}
fclose (fp);
DBG (1, "sane_init: exit\n");
return SANE_STATUS_GOOD;
}
@ -1441,6 +1496,9 @@ void
sane_exit (void)
{
QC_Device *dev, *next;
static const SANE_Device **devlist;
DBG (5, "sane_exit: enter\n");
for (dev = first_dev; dev; dev = next)
{
@ -1449,6 +1507,11 @@ sane_exit (void)
disable_ports (dev);
free (dev);
}
if (devlist) {
free (devlist);
devlist = NULL;
}
DBG (5, "sane_exit: exit\n");
}
SANE_Status
@ -1458,6 +1521,8 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only)
QC_Device *dev;
int i;
DBG (5, "sane_get_devices: enter\n");
local_only = local_only; /* silence compilation warnings */
if (devlist)
@ -1473,6 +1538,9 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only)
devlist[i++] = 0;
*device_list = devlist;
DBG (5, "sane_get_devices: exit\n");
return SANE_STATUS_GOOD;
}
@ -1483,8 +1551,7 @@ sane_open (SANE_String_Const devicename, SANE_Handle *handle)
QC_Device *dev;
QC_Scanner *s;
DBG(4, "open(%s)\n", devicename);
DBG (5, "sane_open: enter: (devicename = %s)\n", devicename);
if (devicename[0])
{
status = attach (devicename, &dev);
@ -1551,6 +1618,9 @@ sane_open (SANE_String_Const devicename, SANE_Handle *handle)
first_handle = s;
*handle = s;
DBG (5, "sane_open: exit\n");
return SANE_STATUS_GOOD;
}
@ -1559,6 +1629,8 @@ sane_close (SANE_Handle handle)
{
QC_Scanner *prev, *s;
DBG (5, "sane_close: enter\n");
/* remove handle from list of open handles: */
prev = 0;
for (s = first_handle; s; s = s->next)
@ -1594,6 +1666,9 @@ sane_close (SANE_Handle handle)
close (s->read_fd);
free (s);
DBG (5, "sane_close: exit\n");
}
const SANE_Option_Descriptor *
@ -1601,8 +1676,13 @@ sane_get_option_descriptor (SANE_Handle handle, SANE_Int option)
{
QC_Scanner *s = handle;
DBG (5, "sane_get_option_descriptor: enter\n");
if ((unsigned) option >= NUM_OPTIONS)
return 0;
DBG (5, "sane_get_option_descriptor: exit\n");
return s->opt + option;
}
@ -1617,6 +1697,8 @@ sane_control_option (SANE_Handle handle, SANE_Int option,
char *old_val;
int i;
DBG (5, "sane_control_option: enter\n");
if (info)
*info = 0;
@ -1753,6 +1835,7 @@ sane_control_option (SANE_Handle handle, SANE_Int option,
if (s->val[i].w > s->opt[i].constraint.range->max)
s->val[i].w = s->opt[i].constraint.range->max;
DBG (5, "sane_control_option: exit\n");
return SANE_STATUS_GOOD;
}
}
@ -1762,12 +1845,15 @@ sane_control_option (SANE_Handle handle, SANE_Int option,
{
case OPT_BRIGHTNESS:
/* not implemented yet */
DBG (5, "sane_control_option: exit\n");
return SANE_STATUS_GOOD;
default:
break;
}
}
DBG (5, "sane_control_option: NOK exit\n");
return SANE_STATUS_INVAL;
}
@ -1779,6 +1865,8 @@ sane_get_parameters (SANE_Handle handle, SANE_Parameters *params)
int xfer_scale;
size_t Bpp = 3; /* # of bytes per pixel */
DBG (5, "sane_get_parameters: enter\n");
if (!s->scanning)
{
/* Only compute new parameters when not scanning---allows
@ -1810,6 +1898,8 @@ sane_get_parameters (SANE_Handle handle, SANE_Parameters *params)
if (params)
*params = s->params;
DBG (5, "sane_get_parameters: exit\n");
return SANE_STATUS_GOOD;
}
@ -1821,6 +1911,8 @@ sane_start (SANE_Handle handle)
QC_Device *q = s->hw;
QC_Scan_Request req;
DBG (5, "sane_start: enter\n");
if (s->scanning)
return SANE_STATUS_DEVICE_BUSY;
@ -2005,6 +2097,9 @@ sane_start (SANE_Handle handle)
s->scanning = SANE_TRUE;
s->deliver_eof = 0;
DBG (5, "sane_start: exit\n");
return SANE_STATUS_GOOD;
}
@ -2012,11 +2107,14 @@ SANE_Status
sane_read (SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len,
SANE_Int * lenp)
{
SANE_Status status;
QC_Scanner *s = handle;
QC_Device *q = s->hw;
ssize_t nread;
size_t len;
DBG (5, "sane_read: enter\n");
*lenp = 0;
if (s->deliver_eof)
@ -2049,7 +2147,9 @@ sane_read (SANE_Handle handle, SANE_Byte *buf, SANE_Int max_len,
if (nread > 0 && s->holding_lock)
{
qc_unlock (q); /* now we can unlock the camera */
status = qc_unlock (q); /* now we can unlock the camera */
if (status != SANE_STATUS_GOOD)
DBG(3, "sane_read: qc_unlock error\n");
s->holding_lock = SANE_FALSE;
}
@ -2065,7 +2165,7 @@ sane_read (SANE_Handle handle, SANE_Byte *buf, SANE_Int max_len,
if (lenp)
*lenp = nread;
DBG(8, "read: got %d bytes\n", *lenp);
DBG (5, "sane_read: exit, read got %d bytes\n", *lenp);
return SANE_STATUS_GOOD;
}
@ -2074,6 +2174,9 @@ sane_cancel (SANE_Handle handle)
{
QC_Scanner *s = handle;
SANE_Bool was_scanning;
SANE_Status status;
DBG (5, "sane_cancel: enter\n");
was_scanning = s->scanning;
s->scanning = SANE_FALSE;
@ -2122,9 +2225,12 @@ sane_cancel (SANE_Handle handle)
}
if (s->holding_lock)
{
qc_unlock (s->hw);
status = qc_unlock (s->hw);
if (status != SANE_STATUS_GOOD)
DBG(3, "sane_cancel: qc_unlock error\n");
s->holding_lock = SANE_FALSE;
}
DBG (5, "sane_cancel: exit\n");
}
SANE_Status
@ -2132,11 +2238,14 @@ sane_set_io_mode (SANE_Handle handle, SANE_Bool non_blocking)
{
QC_Scanner *s = handle;
DBG (5, "sane_set_io_mode: enter\n");
if (!s->scanning)
return SANE_STATUS_INVAL;
if (fcntl (s->read_fd, F_SETFL, non_blocking ? O_NONBLOCK : 0) < 0)
return SANE_STATUS_IO_ERROR;
DBG (5, "sane_set_io_mode: exit\n");
return SANE_STATUS_GOOD;
}
@ -2145,9 +2254,11 @@ sane_get_select_fd (SANE_Handle handle, SANE_Int *fd)
{
QC_Scanner *s = handle;
DBG (5, "sane_get_select_fd: enter\n");
if (!s->scanning)
return SANE_STATUS_INVAL;
*fd = s->read_fd;
DBG (5, "sane_get_select_fd: exit\n");
return SANE_STATUS_GOOD;
}