(The patch is also available on the website http://www.mir.com/mtek/)
To apply:
% cd your-src-dir/sane-0.74/
% patch -p1 < your-patch-dir/microtek-0.9.patch1
-matt m.
--- sane-0.74-dist/backend/microtek.c Fri Aug 7 19:02:44 1998
+++ sane-0.74/backend/microtek.c Fri Aug 7 23:53:02 1998
@@ -55,6 +55,7 @@
#define MICROTEK_MAJOR 0
#define MICROTEK_MINOR 9
+#define MICROTEK_PATCH 1
#include <stdlib.h>
#include <string.h>
@@ -221,18 +222,40 @@
oldsize = rb->size;
rb->size += amount;
- /* fix up them pointers ( < or <= ???? ) */
- if ((rb->tail_red < rb->head_complete) ||
- (rb->tail_green < rb->head_complete) ||
- (rb->tail_blue < rb->head_complete)) {
+ DBG(23, "ring_expand: old, new, inc size: %lu, %lu, %lu\n",
+ (u_long)oldsize, (u_long)rb->size, (u_long)amount);
+ DBG(23, "ring_expand: old tr: %lu tg: %lu tb: %lu hc: %lu\n",
+ (u_long)rb->tail_red, (u_long)rb->tail_green,
+ (u_long)rb->tail_blue, (u_long)rb->head_complete);
+ /* if necessary, move data and fix up them pointers */
+ /* (will break subtly if ring is filled with G or B bytes,
+ and tail_g or tail_b have rolled over...) */
+ if (((rb->complete_count) ||
+ (rb->red_extra) ||
+ (rb->green_extra) ||
+ (rb->blue_extra)) && ((rb->tail_red <= rb->head_complete) ||
+ (rb->tail_green <= rb->head_complete) ||
+ (rb->tail_blue <= rb->head_complete))) {
memmove(rb->base + rb->head_complete + amount,
rb->base + rb->head_complete,
oldsize - rb->head_complete);
- if (rb->tail_red >= rb->head_complete) rb->tail_red += amount;
- if (rb->tail_green >= rb->head_complete) rb->tail_green += amount;
- if (rb->tail_blue >= rb->head_complete) rb->tail_blue += amount;
+ if ((rb->tail_red > rb->head_complete) ||
+ ((rb->tail_red == rb->head_complete) &&
+ !(rb->complete_count) && !(rb->red_extra)))
+ rb->tail_red += amount;
+ if ((rb->tail_green > rb->head_complete) ||
+ ((rb->tail_green == rb->head_complete) &&
+ !(rb->complete_count) && !(rb->green_extra)))
+ rb->tail_green += amount;
+ if ((rb->tail_blue > rb->head_complete) ||
+ ((rb->tail_blue == rb->head_complete) &&
+ !(rb->complete_count) && !(rb->blue_extra)))
+ rb->tail_blue += amount;
rb->head_complete += amount;
}
+ DBG(23, "ring_expand: new tr: %lu tg: %lu tb: %lu hc: %lu\n",
+ (u_long)rb->tail_red, (u_long)rb->tail_green,
+ (u_long)rb->tail_blue, (u_long)rb->head_complete);
return SANE_STATUS_GOOD;
}
@@ -1435,8 +1458,8 @@
int i;
DBG(15, "dump_inquiry...\n");
- fprintf(stderr, " === SANE/Microtek backend v%d.%d ===\n",
- MICROTEK_MAJOR, MICROTEK_MINOR);
+ fprintf(stderr, " === SANE/Microtek backend v%d.%d.%d ===\n",
+ MICROTEK_MAJOR, MICROTEK_MINOR, MICROTEK_PATCH);
fprintf(stderr, "========== Scanner Inquiry Block ========mm\n");
for (i=0; i<96; i++) {
if (!(i % 16) && (i)) fprintf(stderr, "\n");
@@ -1573,8 +1596,8 @@
SANE_Byte response_data_format;
DBG(15, "dump_suspect_inquiry...\n");
- fprintf(stderr, " === SANE/Microtek backend v%d.%d ===\n",
- MICROTEK_MAJOR, MICROTEK_MINOR);
+ fprintf(stderr, " === SANE/Microtek backend v%d.%d.%d ===\n",
+ MICROTEK_MAJOR, MICROTEK_MINOR, MICROTEK_PATCH);
fprintf(stderr, "========== Scanner Inquiry Block ========mm\n");
for (i=0; i<96; i++) {
if (!(i % 16) && (i)) fprintf(stderr, "\n");
@@ -1995,12 +2018,11 @@
(rb->head_complete - start) :
(rb->size - start + rb->head_complete);
size_t length = MIN(nbytes, max_xfer);
- /* what to do if nbytes > max_xfer ???? GGGGGGG */
if (nbytes > max_xfer) {
DBG(23, "pack_flat: must expand ring, %lu + %lu\n",
- (u_long)rb->size, (u_long)rb->initial_size);
- status = ring_expand(rb, rb->initial_size);
+ (u_long)rb->size, (u_long)(nbytes - max_xfer));
+ status = ring_expand(rb, (nbytes - max_xfer));
if (status != SANE_STATUS_GOOD) return status;
}
@@ -2102,9 +2124,13 @@
if ((dr > ar) ||
(dg > ag) ||
(db > ab)) {
+ size_t increase = 0;
+ if (dr > ar) increase = (dr - ar);
+ if (dg > ag) increase = MAX(increase, (dg - ag));
+ if (db > ab) increase = MAX(increase, (db - ab));
DBG(23, "pack_seq: must expand ring, %lu + %lu\n",
- (u_long)rb->size, (u_long)rb->initial_size);
- status = ring_expand(rb, rb->initial_size);
+ (u_long)rb->size, (u_long)increase);
+ status = ring_expand(rb, increase);
if (status != SANE_STATUS_GOOD) return status;
}
}
@@ -2206,9 +2232,13 @@
if ((dr > ar) ||
(dg > ag) ||
(db > ab)) {
+ size_t increase = 0;
+ if (dr > ar) increase = (dr - ar);
+ if (dg > ag) increase = MAX(increase, (dg - ag));
+ if (db > ab) increase = MAX(increase, (db - ab));
DBG(23, "pack_goofy: must expand ring, %lu + %lu\n",
- (u_long)rb->size, (u_long)rb->initial_size);
- status = ring_expand(rb, rb->initial_size);
+ (u_long)rb->size, (u_long)increase);
+ status = ring_expand(rb, increase);
if (status != SANE_STATUS_GOOD) return status;
}
}
@@ -2394,8 +2424,8 @@
FILE *fp;
DBG_INIT();
- DBG(1, "sane_init: MICROTEK says hello! (v%d.%d)\n",
- MICROTEK_MAJOR, MICROTEK_MINOR);
+ DBG(1, "sane_init: MICROTEK says hello! (v%d.%d.%d)\n",
+ MICROTEK_MAJOR, MICROTEK_MINOR, MICROTEK_PATCH);
/* return the SANE version we got compiled under */
if (version_code)
*version_code = SANE_VERSION_CODE (V_MAJOR, V_MINOR, 0);
-- Source code, list archive, and docs: http://www.mostang.com/sane/ To unsubscribe: echo unsubscribe sane-devel | mail majordomo@mostang.com