diff --git a/backend/epsonds-cmd.c b/backend/epsonds-cmd.c index ba80c2376..7af896fe1 100644 --- a/backend/epsonds-cmd.c +++ b/backend/epsonds-cmd.c @@ -225,9 +225,11 @@ static SANE_Status esci2_cmd_simple(epsonds_scanner* s, char *cmd, SANE_Status ( SANE_Status esci2_fin(epsonds_scanner *s) { + SANE_Status status; + DBG(5, "%s\n", __func__); - SANE_Status status = esci2_cmd_simple(s, "FIN x0000000", NULL); + status = esci2_cmd_simple(s, "FIN x0000000", NULL); s->locked = 0; return status; } @@ -261,6 +263,7 @@ static int decode_value(char *buf, int len) static char *decode_binary(char *buf) { char tmp[6]; + int hl; memcpy(tmp, buf, 4); tmp[4] = '\0'; @@ -268,7 +271,7 @@ static char *decode_binary(char *buf) if (buf[0] != 'h') return NULL; - int hl = strtol(tmp + 1, NULL, 16); + hl = strtol(tmp + 1, NULL, 16); if (hl) { char *v = malloc(hl + 1); @@ -283,12 +286,12 @@ static char *decode_binary(char *buf) static char *decode_string(char *buf) { - char *s = decode_binary(buf); + char *p, *s = decode_binary(buf); if (s == NULL) return NULL; /* trim white space at the end */ - char *p = s + strlen(s); + p = s + strlen(s); while (*--p == ' ') *p = '\0'; @@ -309,13 +312,14 @@ static void debug_token(int level, const char *func, char *token, int len) static SANE_Status info_cb(void *userdata, char *token, int len) { epsonds_scanner *s = (epsonds_scanner *)userdata; + char *value; if (DBG_LEVEL >= 11) { debug_token(DBG_LEVEL, __func__, token, len); } /* pointer to the token's value */ - char *value = token + 3; + value = token + 3; /* nrd / nrdBUSY */ @@ -537,11 +541,11 @@ static SANE_Status info_cb(void *userdata, char *token, int len) SANE_Status esci2_info(epsonds_scanner *s) { - DBG(1, "= gathering device information\n"); - SANE_Status status; int i = 4; + DBG(1, "= gathering device information\n"); + do { status = esci2_cmd_simple(s, "INFOx0000000", &info_cb); if (status == SANE_STATUS_DEVICE_BUSY) { @@ -800,11 +804,11 @@ static SANE_Status img_cb(void *userdata, char *token, int len) if (strncmp("err", token, 3) == 0) { - s->scanning = 0; - char *option = token + 3; /* ADF, TPU, FB */ char *cause = token + 3 + 4; /* OPN, PJ, PE, ERR, LTF, LOCK, DFED, DTCL, AUT, PERM */ + s->scanning = 0; + DBG(1, "%s: error on option %3.3s, cause %4.4s\n", __func__, option, cause); @@ -839,6 +843,9 @@ SANE_Status esci2_img(struct epsonds_scanner *s, SANE_Int *length) { SANE_Status status = SANE_STATUS_GOOD; + SANE_Status parse_status; + unsigned int more; + ssize_t read; *length = 0; @@ -859,13 +866,13 @@ esci2_img(struct epsonds_scanner *s, SANE_Int *length) } /* check if we need to read any image data */ - unsigned int more = 0; + more = 0; if (!esci2_check_header("IMG ", (char *)s->buf, &more)) { return SANE_STATUS_IO_ERROR; } /* this handles eof and errors */ - SANE_Status parse_status = esci2_parse_block((char *)s->buf + 12, 64 - 12, s, &img_cb); + parse_status = esci2_parse_block((char *)s->buf + 12, 64 - 12, s, &img_cb); /* no more data? return using the status of the esci2_parse_block * call, which might hold other error conditions. @@ -875,7 +882,7 @@ esci2_img(struct epsonds_scanner *s, SANE_Int *length) } /* ALWAYS read image data */ - ssize_t read = eds_recv(s, s->buf, more, &status); + read = eds_recv(s, s->buf, more, &status); if (status != SANE_STATUS_GOOD) { return status; } diff --git a/backend/epsonds-jpeg.c b/backend/epsonds-jpeg.c index d825d9965..76a52cbb6 100644 --- a/backend/epsonds-jpeg.c +++ b/backend/epsonds-jpeg.c @@ -48,16 +48,17 @@ METHODDEF(boolean) jpeg_fill_input_buffer(j_decompress_ptr cinfo) { epsonds_src_mgr *src = (epsonds_src_mgr *)cinfo->src; + int avail, size; /* read from the scanner or the ring buffer */ - int avail = eds_ring_avail(src->s->current); + avail = eds_ring_avail(src->s->current); if (avail == 0) { return FALSE; } /* read from scanner if no data? */ - int size = min(1024, avail); + size = min(1024, avail); eds_ring_read(src->s->current, src->buffer, size); @@ -129,12 +130,14 @@ eds_jpeg_read_header(epsonds_scanner *s) if (jpeg_start_decompress(&s->jpeg_cinfo)) { + int size; + DBG(3, "%s: w: %d, h: %d, components: %d\n", __func__, s->jpeg_cinfo.output_width, s->jpeg_cinfo.output_height, s->jpeg_cinfo.output_components); - int size = s->jpeg_cinfo.output_width * s->jpeg_cinfo.output_components * 1; + size = s->jpeg_cinfo.output_width * s->jpeg_cinfo.output_components * 1; src->linebuffer = (*s->jpeg_cinfo.mem->alloc_large)((j_common_ptr)&s->jpeg_cinfo, JPOOL_PERMANENT, size); @@ -168,11 +171,13 @@ eds_jpeg_read(SANE_Handle handle, SANE_Byte *data, { epsonds_scanner *s = handle; - *length = 0; - struct jpeg_decompress_struct cinfo = s->jpeg_cinfo; epsonds_src_mgr *src = (epsonds_src_mgr *)s->jpeg_cinfo.src; + int l; + + *length = 0; + /* copy from line buffer if available */ if (src->linebuffer_size && src->linebuffer_index < src->linebuffer_size) { @@ -196,7 +201,7 @@ eds_jpeg_read(SANE_Handle handle, SANE_Byte *data, * only one line at time is supported */ - int l = jpeg_read_scanlines(&cinfo, s->jdst->buffer, 1); + l = jpeg_read_scanlines(&cinfo, s->jdst->buffer, 1); if (l == 0) { return; } diff --git a/backend/epsonds-ops.c b/backend/epsonds-ops.c index 94f107102..403cd5899 100644 --- a/backend/epsonds-ops.c +++ b/backend/epsonds-ops.c @@ -48,9 +48,10 @@ eds_dev_init(epsonds_device *dev) SANE_Status eds_dev_post_init(struct epsonds_device *dev) { + SANE_String_Const *source_list_add = source_list; + DBG(10, "%s\n", __func__); - SANE_String_Const *source_list_add = source_list; if (dev->has_fb) *source_list_add++ = FBF_STR; @@ -337,12 +338,13 @@ eds_copy_image_from_ring(epsonds_scanner *s, SANE_Byte *data, SANE_Int max_lengt while (lines--) { + int i; + SANE_Byte *p; + eds_ring_read(s->current, s->line_buffer, s->params.bytes_per_line); eds_ring_skip(s->current, s->dummy); - int i; - - SANE_Byte *p = s->line_buffer; + p = s->line_buffer; for (i = 0; i < s->params.bytes_per_line; i++) { *data++ = ~*p++; @@ -379,12 +381,14 @@ SANE_Status eds_ring_init(ring_buffer *ring, SANE_Int size) SANE_Status eds_ring_write(ring_buffer *ring, SANE_Byte *buf, SANE_Int size) { + SANE_Int tail; + if (size > (ring->size - ring->fill)) { DBG(1, "ring buffer full, requested: %d, available: %d\n", size, ring->size - ring->fill); return SANE_STATUS_NO_MEM; } - SANE_Int tail = ring->end - ring->wp; + tail = ring->end - ring->wp; if (size < tail) { memcpy(ring->wp, buf, size); @@ -409,6 +413,8 @@ SANE_Status eds_ring_write(ring_buffer *ring, SANE_Byte *buf, SANE_Int size) SANE_Int eds_ring_read(ring_buffer *ring, SANE_Byte *buf, SANE_Int size) { + SANE_Int tail; + DBG(18, "reading from ring, %d bytes available\n", (int)ring->fill); /* limit read to available */ @@ -417,7 +423,7 @@ SANE_Int eds_ring_read(ring_buffer *ring, SANE_Byte *buf, SANE_Int size) size = ring->fill; } - SANE_Int tail = ring->end - ring->rp; + tail = ring->end - ring->rp; if (size < tail) { memcpy(buf, ring->rp, size); @@ -444,11 +450,12 @@ SANE_Int eds_ring_read(ring_buffer *ring, SANE_Byte *buf, SANE_Int size) SANE_Int eds_ring_skip(ring_buffer *ring, SANE_Int size) { + SANE_Int tail; /* limit skip to available */ if (size > ring->fill) size = ring->fill; - SANE_Int tail = ring->end - ring->rp; + tail = ring->end - ring->rp; if (size < tail) { ring->rp += size; } else { diff --git a/backend/epsonds.c b/backend/epsonds.c index 8db070bbf..2f85312a5 100644 --- a/backend/epsonds.c +++ b/backend/epsonds.c @@ -330,10 +330,11 @@ static SANE_Status attach(const char *name, int type) { SANE_Status status; + epsonds_scanner * s; DBG(7, "%s: devname = %s, type = %d\n", __func__, name, type); - epsonds_scanner *s = device_detect(name, type, &status); + s = device_detect(name, type, &status); if (s == NULL) return status; @@ -1041,6 +1042,7 @@ sane_start(SANE_Handle handle) { epsonds_scanner *s = (epsonds_scanner *)handle; char buf[64]; + char cmd[100]; /* take care not to overflow */ SANE_Status status = 0; s->pages++; @@ -1103,8 +1105,6 @@ sane_start(SANE_Handle handle) /* set scanning parameters */ - char cmd[100]; /* take care not to overflow */ - /* document source */ if (strcmp(source_list[s->val[OPT_SOURCE].w], ADF_STR) == 0) { @@ -1194,6 +1194,7 @@ sane_read(SANE_Handle handle, SANE_Byte *data, SANE_Int max_length, SANE_Int *length) { SANE_Int read = 0, tries = 3; + SANE_Int available; SANE_Status status = 0; epsonds_scanner *s = (epsonds_scanner *)handle; @@ -1208,7 +1209,7 @@ sane_read(SANE_Handle handle, SANE_Byte *data, SANE_Int max_length, } /* anything in the buffer? pass it to the frontend */ - SANE_Int available = eds_ring_avail(s->current); + available = eds_ring_avail(s->current); if (available) { DBG(18, "reading from ring buffer, %d left\n", available);