summaryrefslogtreecommitdiff
path: root/backend/avision.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2023-02-12 17:36:10 +0100
committerJörg Frings-Fürst <debian@jff.email>2023-02-12 17:36:10 +0100
commite0d94cf4d39395df1e2c6bb4d967200298c13881 (patch)
treebe5c7cace6697afc753c152d13ad5145d0884a42 /backend/avision.c
parent527bedac30eb120915718eb7997e6dacd583512e (diff)
parent84357741a6a6e6430f199b2c3f7498e0e97da9ad (diff)
Update upstream source from tag 'upstream/1.2.1'
Update to upstream version '1.2.1' with Debian dir a9bb43f754a5c9a361b076af3635cc767b7e652e
Diffstat (limited to 'backend/avision.c')
-rw-r--r--backend/avision.c555
1 files changed, 288 insertions, 267 deletions
diff --git a/backend/avision.c b/backend/avision.c
index b81578a..c807d9f 100644
--- a/backend/avision.c
+++ b/backend/avision.c
@@ -112,7 +112,7 @@
*
* . . - sane_cancel() : cancel operation, kill reader_process
*
- * . - sane_close() : close opened scanner-device, do_cancel, free buffer and handle
+ * . - sane_close() : do_cancel, close opened scanner-device, free buffer and handle
* - sane_exit() : terminate use of backend, free devicename and device-structure
*/
@@ -159,6 +159,15 @@
static Avision_HWEntry Avision_Device_List [] =
{
+ { NULL, NULL,
+ 0x0638, 0x2E59,
+ "Avision", "AD345F",
+ AV_INT_BUTTON | AV_CANCEL_BUTTON | AV_USE_GRAY_FILTER,
+ { 0, {0, 0}, {{0, 0}, {0, 0}} }
+ },
+ /* comment="duplex! sheetfed + flatbed scanner" */
+ /* status="basic" */
+
{ "AVISION", "AV100CS",
0, 0,
"Avision", "AV100CS",
@@ -688,6 +697,15 @@ static Avision_HWEntry Avision_Device_List [] =
/* comment="1 pass, 600 dpi, zero-edge" ASIC 7 */
/* status="basic" */
+ { NULL, NULL,
+ 0x0638, 0x2a1f,
+ "Avision", "FB2280E",
+ 0,
+ { 0, {0, 0}, {{0, 0}, {0, 0}} }
+ },
+ /* comment="1 pass, 600 dpi, zero-edge" ASIC 7 */
+ /* status="basic" */
+
{ "AVISION", "AV8000S",
0, 0,
"Avision", "AV8000S",
@@ -1592,7 +1610,7 @@ Lexmark X4500 MFP
}\
}\
-static int num_devices;
+static unsigned int num_devices;
static Avision_Device* first_dev;
static Avision_Scanner* first_handle;
static const SANE_Device** devlist = 0;
@@ -2149,8 +2167,8 @@ sense_handler (int fd, u_char* sense, void* arg)
uint8_t sense_key = sense[2] & 0xf;
uint8_t additional_sense = sense[7];
- fd = fd; /* silence gcc */
- arg = arg; /* silence gcc */
+ (void) fd; /* silence gcc */
+ (void) arg; /* silence gcc */
DBG (3, "sense_handler:\n");
@@ -2690,8 +2708,8 @@ bubble_sort (uint8_t* sort_data, size_t count)
for (j = (i + 1); j < count; ++j)
{
- ti = get_double ((sort_data + i*2));
- tj = get_double ((sort_data + j*2));
+ ti = (uint16_t) get_double ((sort_data + i*2));
+ tj = (uint16_t) get_double ((sort_data + j*2));
if (ti > tj) {
set_double ((sort_data + i*2), tj);
@@ -2708,7 +2726,7 @@ bubble_sort (uint8_t* sort_data, size_t count)
/* DBG (7, "bubble_sort: %d values for average\n", k); */
if (k > 0) /* if avg to compute */
- return (uint16_t) (sum / k);
+ return (uint16_t) (sum /(double) k);
else
return (uint16_t) (sum); /* always zero? */
}
@@ -2969,14 +2987,14 @@ compute_parameters (Avision_Scanner* s)
SANE_UNFIX (s->val[OPT_BR_X].w), SANE_UNFIX (s->val[OPT_BR_Y].w));
/* window parameter in pixel */
- s->avdimen.tlx = s->avdimen.hw_xres * SANE_UNFIX (s->val[OPT_TL_X].w)
- / MM_PER_INCH;
- s->avdimen.tly = s->avdimen.hw_yres * SANE_UNFIX (s->val[OPT_TL_Y].w)
- / MM_PER_INCH;
- s->avdimen.brx = s->avdimen.hw_xres * SANE_UNFIX (s->val[OPT_BR_X].w)
- / MM_PER_INCH;
- s->avdimen.bry = s->avdimen.hw_yres * SANE_UNFIX (s->val[OPT_BR_Y].w)
- / MM_PER_INCH;
+ s->avdimen.tlx = (long int) (s->avdimen.hw_xres * SANE_UNFIX (s->val[OPT_TL_X].w)
+ / MM_PER_INCH);
+ s->avdimen.tly = (long int) (s->avdimen.hw_yres * SANE_UNFIX (s->val[OPT_TL_Y].w)
+ / MM_PER_INCH);
+ s->avdimen.brx = (long int) (s->avdimen.hw_xres * SANE_UNFIX (s->val[OPT_BR_X].w)
+ / MM_PER_INCH);
+ s->avdimen.bry = (long int) (s->avdimen.hw_yres * SANE_UNFIX (s->val[OPT_BR_Y].w)
+ / MM_PER_INCH);
/* line difference */
if (color_mode_is_color (s->c_mode) &&
@@ -2990,8 +3008,8 @@ compute_parameters (Avision_Scanner* s)
/* limit bry + line_difference to real scan boundary */
{
- long y_max = dev->inquiry_y_ranges[s->source_mode_dim] *
- s->avdimen.hw_yres / MM_PER_INCH;
+ long y_max = (long int) (dev->inquiry_y_ranges[s->source_mode_dim] *
+ s->avdimen.hw_yres / MM_PER_INCH);
DBG (3, "sane_compute_parameters: y_max: %ld, bry: %ld, line_difference: %d\n",
y_max, s->avdimen.bry, s->avdimen.line_difference);
@@ -3009,10 +3027,10 @@ compute_parameters (Avision_Scanner* s)
/* add overscan */
if (dev->inquiry_tune_scan_length && is_adf_scan (s)) {
/* some extra effort for precise rounding ... */
- int overscan = (s->avdimen.hw_yres *
+ int overscan = (int) ((s->avdimen.hw_yres *
(SANE_UNFIX (s->val[OPT_OVERSCAN_TOP].w) +
SANE_UNFIX (s->val[OPT_OVERSCAN_BOTTOM].w)) + (MM_PER_INCH - 1)
- ) / MM_PER_INCH;
+ ) / MM_PER_INCH);
DBG (3, "sane_compute_parameters: overscan lines: %d\n", overscan);
s->avdimen.bry += overscan;
}
@@ -3171,10 +3189,10 @@ compute_parameters (Avision_Scanner* s)
memset (&s->params, 0, sizeof (s->params));
- s->avdimen.hw_pixels_per_line = (s->avdimen.brx - s->avdimen.tlx);
+ s->avdimen.hw_pixels_per_line = (int) (s->avdimen.brx - s->avdimen.tlx);
s->avdimen.hw_pixels_per_line -= s->avdimen.hw_pixels_per_line % boundary;
- s->avdimen.hw_lines = (s->avdimen.bry - s->avdimen.tly -
+ s->avdimen.hw_lines = (int) (s->avdimen.bry - s->avdimen.tly -
2 * s->avdimen.line_difference);
if (s->avdimen.interlaced_duplex && dev->scanner_type != AV_FILM)
@@ -3252,7 +3270,7 @@ inquiry (Avision_Connection av_con, uint8_t* data, size_t len)
memset (&inquiry, 0, sizeof(inquiry));
inquiry.opc = AVISION_SCSI_INQUIRY;
- inquiry.len = len;
+ inquiry.len = (uint8_t) len;
do {
size_t size = inquiry.len;
@@ -3281,7 +3299,7 @@ wait_ready (Avision_Connection* av_con, int delay)
DBG (3, "wait_ready: sending TEST_UNIT_READY\n");
status = avision_cmd (av_con, test_unit_ready, sizeof (test_unit_ready),
0, 0, 0, 0);
- sleep (delay);
+ sleep ((unsigned int) delay);
switch (status)
{
@@ -3338,6 +3356,7 @@ wait_4_light (Avision_Scanner* s)
status = avision_cmd (&s->av_con, &rcmd, sizeof (rcmd), 0, 0, &result, &size);
if (status != SANE_STATUS_GOOD || size != sizeof (result)) {
+ status = (status != SANE_STATUS_GOOD)? status: SANE_STATUS_IO_ERROR;
DBG (1, "wait_4_light: read failed (%s)\n", sane_strstatus (status));
return status;
}
@@ -3432,6 +3451,7 @@ get_firmware_status (Avision_Connection* av_con)
status = avision_cmd (av_con, &rcmd, sizeof (rcmd), 0, 0, &result, &size);
if (status != SANE_STATUS_GOOD || size != sizeof (result)) {
+ status = (status != SANE_STATUS_GOOD)? status: SANE_STATUS_IO_ERROR;
DBG (1, "get_firmware_status: read failed (%s)\n",
sane_strstatus (status));
return (status);
@@ -3469,6 +3489,7 @@ get_flash_ram_info (Avision_Connection* av_con)
status = avision_cmd (av_con, &rcmd, sizeof (rcmd), 0, 0, result, &size);
if (status != SANE_STATUS_GOOD || size != sizeof (result)) {
+ status = (status != SANE_STATUS_GOOD)? status: SANE_STATUS_IO_ERROR;
DBG (1, "get_flash_ram_info: read failed (%s)\n",
sane_strstatus (status));
return (status);
@@ -3550,21 +3571,21 @@ get_nvram_data (Avision_Scanner* s, nvram_data* nvram)
}
static SANE_Status
-get_and_parse_nvram (Avision_Scanner* s, char* str, int n)
+get_and_parse_nvram (Avision_Scanner* s, char* str, size_t n)
{
SANE_Status status;
- int i = 0;
+ size_t i = 0;
int x;
nvram_data nvram;
uint8_t inquiry_result [AVISION_INQUIRY_SIZE_V1];
status = inquiry (s->av_con, inquiry_result, sizeof(inquiry_result));
if (status == SANE_STATUS_GOOD) {
- i += snprintf (str+i, n-i, "Vendor: %.8s",
+ i += (size_t) snprintf (str+i, n-i, "Vendor: %.8s",
inquiry_result+8);
- i += snprintf (str+i, n-i, "\nModel: %.16s",
+ i += (size_t) snprintf (str+i, n-i, "\nModel: %.16s",
inquiry_result+16);
- i += snprintf (str+i, n-i, "\nFirmware: %.4s",
+ i += (size_t) snprintf (str+i, n-i, "\nFirmware: %.4s",
inquiry_result+32);
}
@@ -3575,32 +3596,32 @@ get_and_parse_nvram (Avision_Scanner* s, char* str, int n)
if (status == SANE_STATUS_GOOD)
{
if (nvram.serial[0])
- i += snprintf (str+i, n-i, "\nSerial: %.24s",
+ i += (size_t) snprintf (str+i, n-i, "\nSerial: %.24s",
nvram.serial);
- if (nvram.born_year)
- i += snprintf (str+i, n-i, "\nManufacturing date: %d-%d-%d",
+ if (get_double(nvram.born_year))
+ i += (size_t) snprintf (str+i, n-i, "\nManufacturing date: %d-%d-%d",
get_double(nvram.born_year),
get_double(nvram.born_month),
get_double(nvram.born_day));
- if (nvram.first_scan_year)
- i += snprintf (str+i, n-i, "\nFirst scan date: %d-%d-%d",
+ if (get_double(nvram.first_scan_year))
+ i += (size_t) snprintf (str+i, n-i, "\nFirst scan date: %d-%d-%d",
get_double(nvram.first_scan_year),
get_double(nvram.first_scan_month),
get_double(nvram.first_scan_day));
x = get_quad (nvram.flatbed_scans);
if (x)
- i += snprintf (str+i, n-i, "\nFlatbed scans: %d", x);
+ i += (size_t) snprintf (str+i, n-i, "\nFlatbed scans: %d", x);
x = get_quad (nvram.pad_scans);
if (x)
- i += snprintf (str+i, n-i, "\nPad scans: %d", x);
+ i += (size_t) snprintf (str+i, n-i, "\nPad scans: %d", x);
x = get_quad (nvram.adf_simplex_scans);
if (x)
- i += snprintf (str+i, n-i, "\nADF simplex scans: %d", x);
+ i += (size_t) snprintf (str+i, n-i, "\nADF simplex scans: %d", x);
x = get_quad (nvram.adf_duplex_scans);
if (x)
- i += snprintf (str+i, n-i, "\nADF duplex scans: %d", x);
+ i += (size_t) snprintf (str+i, n-i, "\nADF duplex scans: %d", x);
}
return status;
@@ -3703,12 +3724,12 @@ adf_reset (Avision_Scanner* s)
uint8_t payload[4];
size_t size;
size_t n;
- int i;
+ ssize_t i;
DBG (3, "adf_reset\n");
/* loop twice */
for (i=1; i >= 0; i--) {
- n=i;
+ n= (size_t) i;
memset (&scmd, 0, sizeof (scmd));
memset (&payload, 0, sizeof (payload));
scmd.opc = AVISION_SCSI_SEND;
@@ -3716,26 +3737,26 @@ adf_reset (Avision_Scanner* s)
set_double (scmd.datatypequal, 0);
size = 2;
set_triple (scmd.transferlen, size);
- payload[1] = 0x10 * i; /* write 0x10 the first time, 0x00 the second */
+ payload[1] = (uint8_t) (0x10 * i); /* write 0x10 the first time, 0x00 the second */
status = avision_cmd (&s->av_con, &scmd, sizeof (scmd), payload, size, 0, 0);
if (status != SANE_STATUS_GOOD) {
- DBG (1, "adf_reset: write %d failed (%s)\n", (2-i),
+ DBG (1, "adf_reset: write %zu failed (%s)\n", (2-i),
sane_strstatus (status));
return (status);
}
- DBG (3, "adf_reset: write %d complete.\n", (2-i));
+ DBG (3, "adf_reset: write %zu complete.\n", (2-i));
memset (&rcmd, 0, sizeof (rcmd));
memset (&payload, 0, sizeof (payload));
rcmd.opc = AVISION_SCSI_READ;
rcmd.datatypecode = AVISION_DATATYPECODE_READ_NVRAM_DATA; /* Read NVRAM data */
set_double (rcmd.datatypequal, dev->data_dq);
- size = 4 - i; /* read 3 bytes the first time, 4 the second */
+ size = (size_t) (4 - i); /* read 3 bytes the first time, 4 the second */
set_triple (rcmd.transferlen, size);
status = avision_cmd (&s->av_con, &rcmd, sizeof (rcmd), 0, 0, payload, &size);
if (status != SANE_STATUS_GOOD || size != (4-n)) {
- DBG (1, "adf_reset: read %zu failed (%s)\n", (4-n),
- sane_strstatus (status));
+ status = (status != SANE_STATUS_GOOD)? status: SANE_STATUS_IO_ERROR;
+ DBG (1, "adf_reset: read %zu failed (%s)\n", (4-n), sane_strstatus (status));
return (status);
}
debug_print_raw (3, "adf_reset: raw data:\n", payload, size);
@@ -3776,8 +3797,8 @@ get_accessories_info (Avision_Scanner* s)
status = avision_cmd (&s->av_con, &rcmd, sizeof (rcmd), 0, 0, result, &size);
if (status != SANE_STATUS_GOOD || size != sizeof (result)) {
- DBG (1, "get_accessories_info: read failed (%s)\n",
- sane_strstatus (status));
+ status = (status != SANE_STATUS_GOOD)? status: SANE_STATUS_IO_ERROR;
+ DBG (1, "get_accessories_info: read failed (%s)\n", sane_strstatus (status));
return (status);
}
@@ -3839,7 +3860,7 @@ get_accessories_info (Avision_Scanner* s)
/* Returns a pointer to static char* strings or NULL for cancel (we do
not want to start memcmp'ing for the cancel case). */
static const char*
-string_for_button (Avision_Scanner* s, int button)
+string_for_button (Avision_Scanner* s, uint8_t button)
{
static char buffer [16];
Avision_Device* dev = s->hw;
@@ -3931,6 +3952,7 @@ get_button_status (Avision_Scanner* s)
status = avision_cmd (&s->av_con, &rcmd, sizeof (rcmd), 0, 0,
(uint8_t*)&result, &size);
if (status != SANE_STATUS_GOOD || size != sizeof (result)) {
+ status = (status != SANE_STATUS_GOOD)? status: SANE_STATUS_IO_ERROR;
DBG (1, "get_button_status: read failed (%s)\n", sane_strstatus (status));
return status;
}
@@ -3982,7 +4004,7 @@ get_button_status (Avision_Scanner* s)
/* simulate button press of the last button ... */
result.press_state = 0x80 | 1;
- result.buttons[0] = dev->inquiry_buttons; /* 1 based */
+ result.buttons[0] = (uint8_t) dev->inquiry_buttons; /* 1 based */
}
}
@@ -4001,7 +4023,7 @@ get_button_status (Avision_Scanner* s)
char* message = message_begin;
#define add_token(format,value) do { \
- int n = snprintf (message, message_end - message, "%s" format, \
+ int n = snprintf (message, (size_t) (message_end - message), "%s" format, \
message == message_begin ? "" : ":", value); \
message += n > 0 ? n : 0; \
} while (0)
@@ -4041,7 +4063,7 @@ get_button_status (Avision_Scanner* s)
}
for (i = 0; i < buttons_pressed; ++i) {
- const unsigned int button = result.buttons[i] - 1; /* 1 based ... */
+ const uint8_t button = result.buttons[i] - 1; /* 1 based ... */
DBG (3, "get_button_status: button %d pressed\n", button);
if (button >= dev->inquiry_buttons) {
DBG (1, "get_button_status: button %d not allocated as not indicated in inquiry\n",
@@ -4089,6 +4111,7 @@ get_frame_info (Avision_Scanner* s)
status = avision_cmd (&s->av_con, &rcmd, sizeof (rcmd), 0, 0, result, &size);
if (status != SANE_STATUS_GOOD || size != sizeof (result)) {
+ status = (status != SANE_STATUS_GOOD)? status: SANE_STATUS_IO_ERROR;
DBG (1, "get_frame_info: read failed (%s)\n", sane_strstatus (status));
return (status);
}
@@ -4104,10 +4127,10 @@ get_frame_info (Avision_Scanner* s)
DBG (3, "get_frame_info: [2] Frame amount: %d\n", result[2]);
DBG (3, "get_frame_info: [3] Mode: %s\n", BIT(result[3],4)?"APS":"Not APS");
DBG (3, "get_frame_info: [3] Exposures (if APS): %s\n",
- ((i=(BIT(result[3],3)<<1)+BIT(result[2],2))==0)?"Unknown":
+ ((i=(size_t) (BIT(result[3],3)<<1)+BIT(result[2],2))==0)?"Unknown":
(i==1)?"15":(i==2)?"25":"40");
DBG (3, "get_frame_info: [3] Film Type (if APS): %s\n",
- ((i=(BIT(result[1],3)<<1)+BIT(result[0],2))==0)?"Unknown":
+ ((i=(size_t) (BIT(result[1],3)<<1)+BIT(result[0],2))==0)?"Unknown":
(i==1)?"B&W Negative":(i==2)?"Color slide":"Color Negative");
dev->holder_type = result[0];
@@ -4157,6 +4180,7 @@ get_duplex_info (Avision_Scanner* s)
status = avision_cmd (&s->av_con, &rcmd, sizeof (rcmd), 0, 0,
&result, &size);
if (status != SANE_STATUS_GOOD || size != sizeof (result)) {
+ status = (status != SANE_STATUS_GOOD)? status: SANE_STATUS_IO_ERROR;
DBG (1, "get_duplex_info: read failed (%s)\n", sane_strstatus (status));
return (status);
}
@@ -4220,8 +4244,8 @@ set_frame (Avision_Scanner* s, SANE_Word frame)
set_double (scmd.cmd.datatypequal, dev->data_dq);
set_triple (scmd.cmd.transferlen, sizeof (scmd.data) );
- scmd.data[0] = dev->holder_type;
- scmd.data[1] = frame;
+ scmd.data[0] = (uint8_t) dev->holder_type;
+ scmd.data[1] = (uint8_t) frame;
status = avision_cmd (&s->av_con, &scmd.cmd, sizeof (scmd.cmd),
&scmd.data, sizeof (scmd.data), 0, 0);
@@ -4970,7 +4994,7 @@ send_tune_scan_length (Avision_Scanner* s)
if (dev->hw->feature_type & AV_OVERSCAN_OPTDPI)
dpi = dev->inquiry_optical_res;
- top = dpi * SANE_UNFIX (s->val[OPT_OVERSCAN_TOP].w) / MM_PER_INCH;
+ top = (int) (dpi * SANE_UNFIX (s->val[OPT_OVERSCAN_TOP].w) / MM_PER_INCH);
DBG (3, "send_tune_scan_length: top: %d\n", top);
/* top offset compensation */
@@ -4986,7 +5010,7 @@ send_tune_scan_length (Avision_Scanner* s)
offset += dev->hw->offset.first;
/* convert to lines */
- int top_offset = dpi * offset / MM_PER_INCH;
+ int top_offset = (int) (dpi * offset / MM_PER_INCH);
top += top_offset;
DBG (3, "send_tune_scan_length: top offset: %d\n", top_offset);
}
@@ -5007,7 +5031,7 @@ send_tune_scan_length (Avision_Scanner* s)
}
scmd.datatypecode = AVISION_DATATYPECODE_ATTACH_TRUNCATE_TAIL; /* Attach/Truncate tail(right) of scan length */
- bottom = dpi * SANE_UNFIX (s->val[OPT_OVERSCAN_BOTTOM].w) / MM_PER_INCH;
+ bottom = (int) (dpi * SANE_UNFIX (s->val[OPT_OVERSCAN_BOTTOM].w) / MM_PER_INCH);
DBG (3, "send_tune_scan_length: bottom: %d\n", bottom);
/* bottom offset compensation */
@@ -5024,7 +5048,7 @@ send_tune_scan_length (Avision_Scanner* s)
offset += fabs(dev->hw->offset.first);
/* convert to lines */
- int bottom_offset = dpi * offset / MM_PER_INCH;
+ int bottom_offset = (int) (dpi * offset / MM_PER_INCH);
bottom += bottom_offset;
DBG (3, "send_tune_scan_length: bottom offset: %d\n", bottom_offset);
}
@@ -5161,14 +5185,14 @@ get_calib_format (Avision_Scanner* s, struct calibration_format* format)
DBG (3, "get_calib_format: read_data: %lu bytes\n", (u_long) size);
status = avision_cmd (&s->av_con, &rcmd, sizeof (rcmd), 0, 0, result, &size);
if (status != SANE_STATUS_GOOD || size != sizeof (result) ) {
- DBG (1, "get_calib_format: read calib. info failed (%s)\n",
- sane_strstatus (status) );
+ status = (status != SANE_STATUS_GOOD)? status: SANE_STATUS_IO_ERROR;
+ DBG (1, "get_calib_format: read calib. info failed (%s)\n", sane_strstatus (status) );
return status;
}
debug_print_calib_format (3, "get_calib_format", result);
- format->pixel_per_line = get_double (&(result[0]));
+ format->pixel_per_line = (uint16_t) get_double (&(result[0]));
format->bytes_per_channel = result[2];
format->lines = result[3];
format->flags = result[4];
@@ -5176,12 +5200,12 @@ get_calib_format (Avision_Scanner* s, struct calibration_format* format)
format->r_gain = result[6];
format->g_gain = result[7];
format->b_gain = result[8];
- format->r_shading_target = get_double (&(result[9]));
- format->g_shading_target = get_double (&(result[11]));
- format->b_shading_target = get_double (&(result[13]));
- format->r_dark_shading_target = get_double (&(result[15]));
- format->g_dark_shading_target = get_double (&(result[17]));
- format->b_dark_shading_target = get_double (&(result[19]));
+ format->r_shading_target = (uint16_t) get_double (&(result[9]));
+ format->g_shading_target = (uint16_t) get_double (&(result[11]));
+ format->b_shading_target = (uint16_t) get_double (&(result[13]));
+ format->r_dark_shading_target = (uint16_t) get_double (&(result[15]));
+ format->g_dark_shading_target = (uint16_t) get_double (&(result[17]));
+ format->b_dark_shading_target = (uint16_t) get_double (&(result[19]));
/* now translate to normal! */
/* firmware return R--RG--GB--B with 3 line count */
@@ -5261,7 +5285,7 @@ set_calib_data (Avision_Scanner* s, struct calibration_format* format,
{
Avision_Device* dev = s->hw;
- const int elements_per_line = format->pixel_per_line * format->channels;
+ const size_t elements_per_line = format->pixel_per_line * format->channels;
SANE_Status status;
@@ -5270,7 +5294,7 @@ set_calib_data (Avision_Scanner* s, struct calibration_format* format,
struct command_send scmd;
- int i;
+ size_t i;
DBG (3, "set_calib_data:\n");
@@ -5295,13 +5319,13 @@ set_calib_data (Avision_Scanner* s, struct calibration_format* format,
if (BIT (format->ability1, 2) ) {
DBG (3, "set_calib_data: merging dark calibration data\n");
for (i = 0; i < elements_per_line; ++i) {
- uint16_t value_orig = get_double_le (white_data + i*2);
+ uint16_t value_orig = (uint16_t) get_double_le (white_data + i*2);
uint16_t value_new = value_orig;
value_new &= 0xffc0;
- value_new |= (get_double_le (dark_data + i*2) >> 10) & 0x3f;
+ value_new |= (uint16_t) ((get_double_le (dark_data + i*2) >> 10) & 0x3f);
- DBG (9, "set_calib_data: element %d, dark difference %d\n",
+ DBG (9, "set_calib_data: element %zu, dark difference %d\n",
i, value_orig - value_new);
set_double_le ((white_data + i*2), value_new);
@@ -5318,7 +5342,7 @@ set_calib_data (Avision_Scanner* s, struct calibration_format* format,
{
size_t send_size = elements_per_line * 2;
DBG (3, "set_calib_data: all channels in one command\n");
- DBG (3, "set_calib_data: send_size: %lu\n", (u_long) send_size);
+ DBG (3, "set_calib_data: send_size: %zu\n", send_size);
memset (&scmd, 0, sizeof (scmd) );
scmd.opc = AVISION_SCSI_SEND;
@@ -5332,7 +5356,7 @@ set_calib_data (Avision_Scanner* s, struct calibration_format* format,
}
else /* send data channel by channel (some USB ones) */
{
- int conv_out_size = format->pixel_per_line * 2;
+ size_t conv_out_size = format->pixel_per_line * 2;
uint16_t* conv_out_data; /* here it is save to use 16bit data
since we only move whole words around */
@@ -5356,7 +5380,7 @@ set_calib_data (Avision_Scanner* s, struct calibration_format* format,
for (i = 0; i < format->pixel_per_line; ++ i)
conv_out_data [i] = casted_avg_data [i * 3 + channel];
- DBG (3, "set_calib_data: sending %i bytes now\n",
+ DBG (3, "set_calib_data: sending %zu bytes now\n",
conv_out_size);
memset (&scmd, 0, sizeof (scmd));
@@ -5393,9 +5417,9 @@ set_calib_data (Avision_Scanner* s, struct calibration_format* format,
static uint8_t*
sort_and_average (struct calibration_format* format, uint8_t* data)
{
- const int elements_per_line = format->pixel_per_line * format->channels;
- const int stride = format->bytes_per_channel * elements_per_line;
- int i, line;
+ const size_t elements_per_line = format->pixel_per_line * format->channels;
+ const size_t stride = format->bytes_per_channel * elements_per_line;
+ size_t i, line;
uint8_t *sort_data, *avg_data;
@@ -5454,7 +5478,7 @@ compute_dark_shading_data (Avision_Scanner* s,
DBG (3, "compute_dark_shading_data:\n");
if (s->hw->inquiry_max_shading_target != INVALID_DARK_SHADING)
- map_value = s->hw->inquiry_max_shading_target << 8;
+ map_value = (uint16_t) (s->hw->inquiry_max_shading_target << 8);
rgb_map_value[0] = format->r_dark_shading_target;
rgb_map_value[1] = format->g_dark_shading_target;
@@ -5477,7 +5501,7 @@ compute_dark_shading_data (Avision_Scanner* s,
/* Avision SCSI protocol document has bad description. */
for (i = 0; i < elements_per_line; ++i)
{
- uint16_t tmp_data = get_double_le((data + i*2));
+ uint16_t tmp_data = (uint16_t) get_double_le((data + i*2));
if (tmp_data > rgb_map_value[i % 3]) {
set_double ((data + i*2), tmp_data - rgb_map_value[i % 3]);
}
@@ -5504,7 +5528,7 @@ compute_white_shading_data (Avision_Scanner* s,
DBG (3, "compute_white_shading_data:\n");
if (s->hw->inquiry_max_shading_target != INVALID_WHITE_SHADING)
- inquiry_mst = s->hw->inquiry_max_shading_target << 4;
+ inquiry_mst = (uint16_t) (s->hw->inquiry_max_shading_target << 4);
mst[0] = format->r_shading_target;
mst[1] = format->g_shading_target;
@@ -5547,14 +5571,14 @@ compute_white_shading_data (Avision_Scanner* s,
{
int result;
/* calculate calibration value for pixel i */
- uint16_t tmp_data = get_double((data + i*2));
+ uint16_t tmp_data = (uint16_t) get_double((data + i*2));
if (tmp_data == INVALID_WHITE_SHADING) {
tmp_data = DEFAULT_WHITE_SHADING;
++ values_invalid;
}
- result = ( (int)mst[i % 3] * WHITE_MAP_RANGE / (tmp_data + 0.5));
+ result = (int) ( (int)mst[i % 3] * WHITE_MAP_RANGE / (tmp_data + 0.5));
/* sanity check for over-amplification, clipping */
if (result > MAX_WHITE_SHADING) {
@@ -5582,7 +5606,8 @@ normal_calibration (Avision_Scanner* s)
struct calibration_format calib_format;
- int calib_data_size, calib_bytes_per_line;
+ size_t calib_data_size;
+ int calib_bytes_per_line;
uint8_t read_type;
uint8_t *calib_tmp_data;
@@ -5604,7 +5629,7 @@ normal_calibration (Avision_Scanner* s)
calib_bytes_per_line = calib_format.bytes_per_channel *
calib_format.pixel_per_line * calib_format.channels;
- calib_data_size = calib_format.lines * calib_bytes_per_line;
+ calib_data_size = (size_t) calib_format.lines * (size_t) calib_bytes_per_line;
calib_tmp_data = malloc (calib_data_size);
if (!calib_tmp_data)
@@ -5889,7 +5914,7 @@ send_gamma (Avision_Scanner* s)
/* interpolate gamma_values to gamma_data */
for (k = 0; k < gamma_values; ++ k, ++ i) {
gamma_data [i] = (uint8_t)
- (((v1 * (gamma_values - k)) + (v2 * k) ) / (double) gamma_values);
+ (((v1 * (double) (gamma_values - k)) + (v2 * (double) k) ) / (double) gamma_values);
}
}
@@ -5965,7 +5990,7 @@ send_3x3_matrix (Avision_Scanner* s)
a_i = (int) a_f; /* integer */
b_f = a_f - (double) a_i; /* float */
- m |= ((a_i & 0x3) << INT_PART);
+ m |= (uint16_t) ((a_i & 0x3) << INT_PART);
m |= (uint16_t) (b_f * 1024);
set_double (((uint8_t*)(&cmd.matrix.v[i])), m);
}
@@ -6009,6 +6034,7 @@ get_acceleration_info (Avision_Scanner* s, struct acceleration_info* info)
DBG (3, "get_acceleration_info: read_data: %lu bytes\n", (u_long) size);
status = avision_cmd (&s->av_con, &rcmd, sizeof (rcmd), 0, 0, result, &size);
if (status != SANE_STATUS_GOOD || size != sizeof (result) ) {
+ status = (status != SANE_STATUS_GOOD)? status: SANE_STATUS_IO_ERROR;
DBG (1, "get_acceleration_info: read accel. info failed (%s)\n",
sane_strstatus (status) );
return status;
@@ -6016,12 +6042,12 @@ get_acceleration_info (Avision_Scanner* s, struct acceleration_info* info)
debug_print_accel_info (3, "get_acceleration_info", result);
- info->total_steps = get_double (&(result[0]));
- info->stable_steps = get_double (&(result[2]));
- info->table_units = get_quad (&(result[4]));
- info->base_units = get_quad (&(result[8]));
- info->start_speed = get_double (&(result[12]));
- info->target_speed = get_double (&(result[14]));
+ info->total_steps = (uint16_t) get_double (&(result[0]));
+ info->stable_steps = (uint16_t) get_double (&(result[2]));
+ info->table_units = (uint32_t) get_quad (&(result[4]));
+ info->base_units = (uint32_t) get_quad (&(result[8]));
+ info->start_speed = (uint16_t) get_double (&(result[12]));
+ info->target_speed = (uint16_t) get_double (&(result[14]));
info->ability = result[16];
info->table_count = result[17];
@@ -6076,10 +6102,10 @@ send_acceleration_table (Avision_Scanner* s)
needs such a dumb table and also do not know /why/ it has to be
constructed this way. "Works for me" -ReneR */
{
- float low_lim = 0.001;
+ float low_lim = (float) 0.001;
float up_lim = 1.0;
- uint16_t accel_steps = accel_info.total_steps - accel_info.stable_steps + 1;
+ uint16_t accel_steps = (uint16_t) (accel_info.total_steps - accel_info.stable_steps + 1);
/* acceleration ramp */
while ((up_lim - low_lim) > 0.0001)
@@ -6122,7 +6148,7 @@ send_acceleration_table (Avision_Scanner* s)
int add_count;
/* count total steps in table */
- int table_total = 0;
+ uint32_t table_total = 0;
for (i = 0; i < accel_info.total_steps; i++)
table_total += table_data [i];
@@ -6130,9 +6156,9 @@ send_acceleration_table (Avision_Scanner* s)
if (((table_total * accel_info.table_units) % accel_info.base_units) == 0)
add_count = 0;
else
- add_count = (accel_info.base_units -
- ((table_total*accel_info.table_units) % accel_info.base_units))
- / accel_info.table_units;
+ add_count = (int) ((accel_info.base_units -
+ ((table_total*accel_info.table_units) % accel_info.base_units))
+ / accel_info.table_units);
/* add_count should not be bigger than 255 */
if (add_count > 255) {
@@ -6142,7 +6168,7 @@ send_acceleration_table (Avision_Scanner* s)
for (i = 0; i < accel_info.total_steps - 1 && add_count > 0; i++)
{
uint16_t temp_count = 255 - table_data [i];
- temp_count = temp_count > add_count ? add_count : temp_count;
+ temp_count = (uint16_t) (temp_count > add_count ? add_count : temp_count);
table_data [i] += (uint8_t) temp_count;
add_count -= temp_count;
@@ -6186,8 +6212,8 @@ set_window (Avision_Scanner* s)
Avision_Device* dev = s->hw;
SANE_Status status;
int base_dpi_abs, base_dpi_rel;
- int transferlen;
- int paralen;
+ size_t transferlen;
+ size_t paralen;
int bytes_per_line;
int line_count;
@@ -6225,7 +6251,7 @@ set_window (Avision_Scanner* s)
/* optional parameter length to use */
paralen = sizeof (cmd.window.avision) - sizeof (cmd.window.avision.type);
- DBG (2, "set_window: base paralen: %d\n", paralen);
+ DBG (2, "set_window: base paralen: %zu\n", paralen);
if (dev->hw->feature_type & AV_FUJITSU)
paralen += sizeof (cmd.window.avision.type.fujitsu);
@@ -6236,12 +6262,12 @@ set_window (Avision_Scanner* s)
else
paralen += sizeof (cmd.window.avision.type.normal) - 1;
- DBG (2, "set_window: final paralen: %d\n", paralen);
+ DBG (2, "set_window: final paralen: %zu\n", paralen);
transferlen = sizeof (cmd.window)
- sizeof (cmd.window.avision) + paralen;
- DBG (2, "set_window: transferlen: %d\n", transferlen);
+ DBG (2, "set_window: transferlen: %zu\n", transferlen);
/* command setup */
cmd.cmd.opc = AVISION_SCSI_SET_WINDOW;
@@ -6278,20 +6304,20 @@ set_window (Avision_Scanner* s)
/* here go the most significant bits if bigger than 16 bit */
if (dev->inquiry_new_protocol && !(dev->hw->feature_type & AV_FUJITSU) ) {
DBG (2, "set_window: large data-transfer support (>16bit)!\n");
- cmd.window.avision.type.normal.line_width_msb =
- bytes_per_line >> 16;
- cmd.window.avision.type.normal.line_count_msb =
- line_count >> 16;
+ cmd.window.avision.type.normal.line_width_msb = (uint8_t)
+ (bytes_per_line >> 16);
+ cmd.window.avision.type.normal.line_count_msb = (uint8_t)
+ (line_count >> 16);
}
if (dev->inquiry_background_raster)
- cmd.window.avision.type.normal.background_lines = s->val[OPT_BACKGROUND].w;
+ cmd.window.avision.type.normal.background_lines = (uint8_t) s->val[OPT_BACKGROUND].w;
/* scanner should use our line-width and count */
SET_BIT (cmd.window.avision.bitset1, 6);
/* set speed */
- cmd.window.avision.bitset1 |= s->val[OPT_SPEED].w & 0x07; /* only 3 bit */
+ cmd.window.avision.bitset1 |= (uint8_t) (s->val[OPT_SPEED].w & 0x07); /* only 3 bit */
/* ADF scan? */
DBG (3, "set_window: source mode %d source mode dim %d\n",
@@ -6371,7 +6397,7 @@ set_window (Avision_Scanner* s)
/* fixed values */
cmd.window.descriptor.padding_and_bitset = 3;
cmd.window.descriptor.vendor_specific = 0xFF;
- cmd.window.descriptor.paralen = paralen; /* R² was: 9, later 14 */
+ cmd.window.descriptor.paralen = (uint8_t) paralen; /* R² was: 9, later 14 */
/* This is normally unsupported by Avision scanners, and we do this
via the gamma table - which works for all devices ... */
@@ -6443,7 +6469,7 @@ set_window (Avision_Scanner* s)
debug_print_window_descriptor (5, "set_window", &(cmd.window));
- DBG (3, "set_window: sending command. Bytes: %d\n", transferlen);
+ DBG (3, "set_window: sending command. Bytes: %zu\n", transferlen);
status = avision_cmd (&s->av_con, &cmd, sizeof (cmd.cmd),
&(cmd.window), transferlen, 0, 0);
@@ -6482,7 +6508,7 @@ get_background_raster (Avision_Scanner* s)
dev->inquiry_background_raster_pixel, bytes_per_line);
/* according to spec only 8-bit gray or color, TODO: test for bi-level scans */
- size = bytes_per_line * lines;
+ size = (size_t) bytes_per_line * (size_t) lines;
DBG (3, "get_background_raster: buffer size: %ld\n", (long)size);
@@ -6518,7 +6544,7 @@ get_background_raster (Avision_Scanner* s)
else {
this_lines = s->val[OPT_BACKGROUND].w;
}
- this_read = bytes_per_line * this_lines;
+ this_read = (size_t) bytes_per_line * (size_t) this_lines;
DBG (3, "get_background_raster: line: %d, lines: %d, %lu bytes\n",
i, this_lines, (u_long) this_read);
@@ -6528,8 +6554,8 @@ get_background_raster (Avision_Scanner* s)
read_size = this_read;
status = avision_cmd (&s->av_con, &rcmd, sizeof (rcmd), 0, 0, dst_raster, &read_size);
if (status != SANE_STATUS_GOOD || read_size != this_read) {
- DBG (1, "get_background_raster: read raster failed (%s)\n",
- sane_strstatus (status) );
+ status = (status != SANE_STATUS_GOOD)? status: SANE_STATUS_IO_ERROR;
+ DBG (1, "get_background_raster: read raster failed (%s)\n", sane_strstatus (status) );
return status;
}
@@ -6545,7 +6571,7 @@ get_background_raster (Avision_Scanner* s)
write_pnm_header (f, (color_mode_is_color (s->c_mode) ? AV_TRUECOLOR : AV_GRAYSCALE), 8,
bytes_per_line / bpp, lines);
- fwrite (background, 1, bytes_per_line * lines, f);
+ fwrite (background, 1, (size_t) bytes_per_line * (size_t) lines, f);
fclose (f);
}
@@ -6555,7 +6581,7 @@ get_background_raster (Avision_Scanner* s)
/* TODO: add 16bit per sample code? */
int l, p;
- uint8_t* tmp_data = malloc (bytes_per_line);
+ uint8_t* tmp_data = malloc ((size_t) bytes_per_line);
for (l = 0; l < lines; ++l)
{
uint8_t* out_data = tmp_data;
@@ -6569,7 +6595,7 @@ get_background_raster (Avision_Scanner* s)
out_data [p++] = *(b_ptr++);
}
- memcpy (background + (bytes_per_line * l), tmp_data, bytes_per_line);
+ memcpy (background + (bytes_per_line * l), tmp_data, (size_t) bytes_per_line);
}
free (tmp_data);
@@ -6596,7 +6622,7 @@ get_background_raster (Avision_Scanner* s)
src_raster = background + bytes_per_line * i;
DBG(3, "get_background_raster: deinterlaced %d -> %d\n", i, dst_i);
- memcpy(dst_raster, src_raster, bytes_per_line);
+ memcpy(dst_raster, src_raster, (size_t) bytes_per_line);
}
free (background);
@@ -6619,7 +6645,7 @@ get_background_raster (Avision_Scanner* s)
write_pnm_header (f, (color_mode_is_color (s->c_mode) ? AV_TRUECOLOR : AV_GRAYSCALE), 8,
bytes_per_line / bpp, s->val[OPT_BACKGROUND].w);
- fwrite (raster, 1, bytes_per_line * s->val[OPT_BACKGROUND].w, f);
+ fwrite (raster, 1, (size_t) bytes_per_line * (size_t) s->val[OPT_BACKGROUND].w, f);
fclose (f);
}
@@ -6630,7 +6656,7 @@ get_background_raster (Avision_Scanner* s)
src_ptr = background + s->avdimen.tlx * bpp;
for (i = 0; i < lines; ++i)
{
- memmove (dst_ptr, src_ptr, s->avdimen.hw_bytes_per_line);
+ memmove (dst_ptr, src_ptr, (size_t) s->avdimen.hw_bytes_per_line);
dst_ptr += s->avdimen.hw_bytes_per_line;
src_ptr += bytes_per_line;
}
@@ -6659,10 +6685,10 @@ get_background_raster (Avision_Scanner* s)
switch (bpp) {
case 1:
{
- uint8_t v =
- ( out_data [sy*hwbpl + sx ] * (256-xdist) +
+ uint8_t v = (uint8_t)
+ (( out_data [sy*hwbpl + sx ] * (256-xdist) +
out_data [sy*hwbpl + sxx] * xdist
- ) / (256);
+ ) / (256));
*dst++ = v;
}
break;
@@ -6672,10 +6698,10 @@ get_background_raster (Avision_Scanner* s)
int c;
for (c = 0; c < 3; ++c)
{
- uint8_t v =
- ( out_data [sy*hwbpl + sx*3 + c] * (256-xdist) +
+ uint8_t v = (uint8_t)
+ (( out_data [sy*hwbpl + sx*3 + c] * (256-xdist) +
out_data [sy*hwbpl + sxx*3 + c] * xdist
- ) / (256);
+ ) / (256));
*dst++ = v;
}
}
@@ -6702,7 +6728,7 @@ get_background_raster (Avision_Scanner* s)
write_pnm_header (f, (color_mode_is_color (s->c_mode) ? AV_TRUECOLOR : AV_GRAYSCALE), 8,
s->params.bytes_per_line / bpp, s->val[OPT_BACKGROUND].w);
- fwrite (raster, 1, s->params.bytes_per_line * s->val[OPT_BACKGROUND].w, f);
+ fwrite (raster, 1, (size_t) s->params.bytes_per_line * (size_t) s->val[OPT_BACKGROUND].w, f);
fclose (f);
}
}
@@ -6731,7 +6757,7 @@ release_unit (Avision_Scanner* s, int type)
SANE_Status status;
DBG (1, "release unit: type: %d\n", type);
- cmd[5] = type; /* latest scanners also allow 1: release paper and 2: end job */
+ cmd[5] = (char) type; /* latest scanners also allow 1: release paper and 2: end job */
status = avision_cmd (&s->av_con, cmd, sizeof (cmd), 0, 0, 0, 0);
return status;
}
@@ -6944,8 +6970,9 @@ init_options (Avision_Scanner* s)
case AV_ASIC_C5:
dev->dpi_range.min = 80;
break;
- case AV_ASIC_C6: /* TODO: AV610 in ADF mode does not scan less than 180 or so */
- dev->dpi_range.min = 50;
+ case AV_ASIC_C6: /* TODO: AV610 in ADF mode does not scan less than 180 or so; */
+ /* Scanjet 8250 does not work with 50 in normal mode */
+ dev->dpi_range.min = 60;
break;
case AV_ASIC_C7: /* AV610C2 empirically tested out */
dev->dpi_range.min = 75;
@@ -6983,7 +7010,7 @@ init_options (Avision_Scanner* s)
s->opt[OPT_MODE].title = SANE_TITLE_SCAN_MODE;
s->opt[OPT_MODE].desc = SANE_DESC_SCAN_MODE;
s->opt[OPT_MODE].type = SANE_TYPE_STRING;
- s->opt[OPT_MODE].size = max_string_size (dev->color_list);
+ s->opt[OPT_MODE].size = (SANE_Int) max_string_size (dev->color_list);
s->opt[OPT_MODE].constraint_type = SANE_CONSTRAINT_STRING_LIST;
s->opt[OPT_MODE].constraint.string_list = dev->color_list;
s->val[OPT_MODE].s = strdup (dev->color_list[dev->color_list_default]);
@@ -6994,7 +7021,7 @@ init_options (Avision_Scanner* s)
s->opt[OPT_SOURCE].title = SANE_TITLE_SCAN_SOURCE;
s->opt[OPT_SOURCE].desc = SANE_DESC_SCAN_SOURCE;
s->opt[OPT_SOURCE].type = SANE_TYPE_STRING;
- s->opt[OPT_SOURCE].size = max_string_size(dev->source_list);
+ s->opt[OPT_SOURCE].size = (SANE_Int) max_string_size(dev->source_list);
s->opt[OPT_SOURCE].constraint_type = SANE_CONSTRAINT_STRING_LIST;
s->opt[OPT_SOURCE].constraint.string_list = &dev->source_list[0];
s->val[OPT_SOURCE].s = strdup(dev->source_list[0]);
@@ -7314,7 +7341,7 @@ init_options (Avision_Scanner* s)
s->opt[OPT_MESSAGE].cap = SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
s->opt[OPT_MESSAGE].size = 129;
s->opt[OPT_MESSAGE].constraint_type = SANE_CONSTRAINT_NONE;
- s->val[OPT_MESSAGE].s = malloc(s->opt[OPT_MESSAGE].size);
+ s->val[OPT_MESSAGE].s = malloc((size_t) s->opt[OPT_MESSAGE].size);
s->val[OPT_MESSAGE].s[0] = 0;
/* NVRAM */
@@ -7328,7 +7355,7 @@ init_options (Avision_Scanner* s)
s->opt[OPT_NVRAM].unit = SANE_UNIT_NONE;
s->opt[OPT_NVRAM].size = 1024;
s->opt[OPT_NVRAM].constraint_type = SANE_CONSTRAINT_NONE;
- s->val[OPT_NVRAM].s = malloc(s->opt[OPT_NVRAM].size);
+ s->val[OPT_NVRAM].s = malloc((size_t) s->opt[OPT_NVRAM].size);
s->val[OPT_NVRAM].s[0] = 0;
/* paper_length */
@@ -7472,11 +7499,27 @@ reader_process (void *data)
return SANE_STATUS_NO_MEM;
if (dev->adf_offset_compensation) {
+ char duplex_offtmp_fname [] = "/tmp/avision-offtmp-XXXXXX";
+
+ int fd = mkstemp(duplex_offtmp_fname);
+ if (fd == -1) {
+ DBG (1, "reader_process: failed to generate temporary fname for ADF offset compensation temp file\n");
+ return SANE_STATUS_NO_MEM;
+ }
+ DBG (1, "reader_process: temporary fname for ADF offset compensation temp file: %s\n",
+ duplex_offtmp_fname);
+
+ if (unlink(duplex_offtmp_fname) == -1) {
+ DBG(1, "reader_process: failed to delete temporary file prior to use: %s\n", duplex_offtmp_fname);
+ // continue though.
+ }
+
DBG (3, "reader_process: redirecting output data to temp file for ADF offset compensation.\n");
fp_fd = fp;
- fp = fopen (s->duplex_offtmp_fname, "w+");
+ fp = fdopen (fd, "w+");
if (!fp) {
fclose(fp_fd);
+ close(fd);
return SANE_STATUS_NO_MEM;
}
}
@@ -7525,37 +7568,34 @@ reader_process (void *data)
if (!s->duplex_rear_valid) { /* create new file for writing */
DBG (3, "reader_process: opening duplex rear file for writing.\n");
rear_fp = fopen (s->duplex_rear_fname, "w");
- if (! rear_fp) {
- fclose (fp);
- return SANE_STATUS_NO_MEM;
- }
}
else { /* open saved rear data */
DBG (3, "reader_process: opening duplex rear file for reading.\n");
rear_fp = fopen (s->duplex_rear_fname, "r");
- if (! rear_fp) {
- fclose (fp);
- return SANE_STATUS_IO_ERROR;
- }
+ }
+ if (! rear_fp) {
+ fclose (fp);
+ fclose (fp_fd);
+ return SANE_STATUS_IO_ERROR;
}
}
/* it takes quite a few lines to saturate the (USB) bus */
- lines_per_stripe = dev->read_stripe_size;
+ lines_per_stripe = (unsigned int) dev->read_stripe_size;
if (s->avdimen.line_difference)
- lines_per_stripe += 2 * s->avdimen.line_difference;
+ lines_per_stripe += (2 * (unsigned int) s->avdimen.line_difference);
- stripe_size = s->avdimen.hw_bytes_per_line * lines_per_stripe;
- lines_per_output = lines_per_stripe - 2 * s->avdimen.line_difference;
+ stripe_size = (unsigned int) s->avdimen.hw_bytes_per_line * lines_per_stripe;
+ lines_per_output = lines_per_stripe - 2 * (unsigned int) s->avdimen.line_difference;
if (s->av_con.connection_type == AV_SCSI)
/* maybe better not /2 ... */
- max_bytes_per_read = dev->scsi_buffer_size / 2;
+ max_bytes_per_read = (unsigned int) dev->scsi_buffer_size / 2;
else
/* vast buffer size to saturate the bus */
max_bytes_per_read = 0x100000;
- out_size = s->avdimen.hw_bytes_per_line * lines_per_output;
+ out_size = (unsigned int) s->avdimen.hw_bytes_per_line * lines_per_output;
DBG (3, "dev->scsi_buffer_size / 2: %d\n",
dev->scsi_buffer_size / 2);
@@ -7576,18 +7616,18 @@ reader_process (void *data)
s->avdimen.hw_yres != s->avdimen.yres)
{
/* layout out_data so that the interpolation history is exactly in front */
- ip_history = malloc (s->avdimen.hw_bytes_per_line + out_size);
+ ip_history = malloc ((size_t) s->avdimen.hw_bytes_per_line + out_size);
out_data = ip_history + s->avdimen.hw_bytes_per_line;
- ip_data = malloc (s->params.bytes_per_line);
+ ip_data = malloc ((size_t) s->params.bytes_per_line);
}
else {
out_data = malloc (out_size);
}
/* calculate params for the reading loop */
- total_size = s->avdimen.hw_bytes_per_line *
- (s->avdimen.hw_lines + 2 * s->avdimen.line_difference);
+ total_size = (size_t) s->avdimen.hw_bytes_per_line *
+ ((size_t) s->avdimen.hw_lines + 2 * (size_t) s->avdimen.line_difference);
if (deinterlace != NONE && !s->duplex_rear_valid)
total_size *= 2;
@@ -7599,7 +7639,7 @@ reader_process (void *data)
{
raw_fp = fopen ("/tmp/sane-avision.raw", "w");
write_pnm_header (fp, s->c_mode, s->params.depth,
- s->avdimen.hw_pixels_per_line, total_size / s->avdimen.hw_bytes_per_line);
+ s->avdimen.hw_pixels_per_line, (int) (total_size / (size_t) s->avdimen.hw_bytes_per_line));
}
processed_bytes = 0;
@@ -7613,7 +7653,7 @@ reader_process (void *data)
background += s->params.bytes_per_line * s->val[OPT_BACKGROUND].w;
DBG (5, "reader_process: dumping background raster\n");
- fwrite (background, s->params.bytes_per_line, s->val[OPT_BACKGROUND].w, fp);
+ fwrite (background, (size_t) s->params.bytes_per_line, (size_t) s->val[OPT_BACKGROUND].w, fp);
}
/* Data read; loop until all data has been processed. Might exit
@@ -7636,7 +7676,7 @@ reader_process (void *data)
byte_per_lines, otherwise some scanners freeze. */
if (this_read > max_bytes_per_read)
this_read = (max_bytes_per_read -
- max_bytes_per_read % s->avdimen.hw_bytes_per_line);
+ max_bytes_per_read % (unsigned int) s->avdimen.hw_bytes_per_line);
if (processed_bytes + this_read > total_size)
this_read = total_size - processed_bytes;
@@ -7694,7 +7734,7 @@ reader_process (void *data)
exit_status = status;
}
- stripe_fill += this_read;
+ stripe_fill += (unsigned int) this_read;
processed_bytes += this_read;
}
@@ -7716,7 +7756,7 @@ reader_process (void *data)
DBG (5, "reader_process: virtual this_read: %lu\n", (u_long) this_read);
got = fread (stripe_data + stripe_fill, 1, this_read, rear_fp);
- stripe_fill += got;
+ stripe_fill += (unsigned int) got;
processed_bytes += got;
if (got != this_read)
exit_status = SANE_STATUS_EOF;
@@ -7727,7 +7767,7 @@ reader_process (void *data)
useful_bytes = stripe_fill;
if (color_mode_is_color (s->c_mode))
- useful_bytes -= 2 * s->avdimen.line_difference * s->avdimen.hw_bytes_per_line;
+ useful_bytes -= (unsigned int) (2 * s->avdimen.line_difference * s->avdimen.hw_bytes_per_line);
DBG (3, "reader_process: useful_bytes %i\n", useful_bytes);
@@ -7737,26 +7777,26 @@ reader_process (void *data)
if (deinterlace != NONE && !s->duplex_rear_valid)
{
/* for all lines we have in the buffer: */
- unsigned int absline = (processed_bytes - stripe_fill) / s->avdimen.hw_bytes_per_line;
- unsigned int abslines = absline + useful_bytes / s->avdimen.hw_bytes_per_line;
+ unsigned int absline = (unsigned int) ((processed_bytes - stripe_fill) / (size_t) s->avdimen.hw_bytes_per_line);
+ unsigned int abslines = absline + useful_bytes / (unsigned int) s->avdimen.hw_bytes_per_line;
uint8_t* ptr = stripe_data;
for ( ; absline < abslines; ++absline)
{
DBG (9, "reader_process: deinterlacing line %d\n", absline);
/* interlaced? save the back data to the rear buffer */
if ( (deinterlace == STRIPE && absline % (lines_per_stripe*2) >= lines_per_stripe) ||
- (deinterlace == HALF && absline >= total_size / s->avdimen.hw_bytes_per_line / 2) ||
+ (deinterlace == HALF && absline >= total_size / (size_t) s->avdimen.hw_bytes_per_line / 2) ||
(deinterlace == LINE && (absline & 0x1)) ) /* last bit equals % 2 */
{
DBG (9, "reader_process: saving rear line %d to temporary file.\n", absline);
- fwrite (ptr, s->avdimen.hw_bytes_per_line, 1, rear_fp);
+ fwrite (ptr, (size_t) s->avdimen.hw_bytes_per_line, 1, rear_fp);
if (deinterlace == LINE)
memmove (ptr, ptr+s->avdimen.hw_bytes_per_line,
- stripe_data + stripe_fill - ptr - s->avdimen.hw_bytes_per_line);
+ (size_t) (stripe_data + stripe_fill - ptr - s->avdimen.hw_bytes_per_line));
else
ptr += s->avdimen.hw_bytes_per_line;
- useful_bytes -= s->avdimen.hw_bytes_per_line;
- stripe_fill -= s->avdimen.hw_bytes_per_line;
+ useful_bytes -= (unsigned int) s->avdimen.hw_bytes_per_line;
+ stripe_fill -= (unsigned int) s->avdimen.hw_bytes_per_line;
}
else
ptr += s->avdimen.hw_bytes_per_line;
@@ -7766,14 +7806,14 @@ reader_process (void *data)
}
if ((dev->hw->feature_type & AV_ADF_FLIPPING_DUPLEX) && s->source_mode == AV_ADF_DUPLEX && !(s->page % 2) && !s->duplex_rear_valid) {
/* Here we flip the image by writing the lines from the end of the file to the beginning. */
- unsigned int absline = (processed_bytes - stripe_fill) / s->avdimen.hw_bytes_per_line;
- unsigned int abslines = absline + useful_bytes / s->avdimen.hw_bytes_per_line;
+ unsigned int absline = (unsigned int) ((processed_bytes - stripe_fill) / (size_t) s->avdimen.hw_bytes_per_line);
+ unsigned int abslines = absline + useful_bytes / (unsigned int) s->avdimen.hw_bytes_per_line;
uint8_t* ptr = stripe_data;
for ( ; absline < abslines; ++absline) {
- fseek (rear_fp, ((0 - s->params.lines) - absline - 2) * s->avdimen.hw_bytes_per_line, SEEK_SET);
- fwrite (ptr, s->avdimen.hw_bytes_per_line, 1, rear_fp);
- useful_bytes -= s->avdimen.hw_bytes_per_line;
- stripe_fill -= s->avdimen.hw_bytes_per_line;
+ fseek (rear_fp, ((0 - s->params.lines) - (SANE_Int) absline - 2) * s->avdimen.hw_bytes_per_line, SEEK_SET);
+ fwrite (ptr, (size_t) s->avdimen.hw_bytes_per_line, 1, rear_fp);
+ useful_bytes -= (unsigned int) s->avdimen.hw_bytes_per_line;
+ stripe_fill -= (unsigned int) s->avdimen.hw_bytes_per_line;
ptr += s->avdimen.hw_bytes_per_line;
}
DBG (9, "reader_process: after page flip: useful_bytes: %d, stripe_fill: %d\n",
@@ -7813,16 +7853,16 @@ reader_process (void *data)
else if (dev->inquiry_needs_line_pack) /* line-pack */
{
/* TODO: add 16bit per sample code? */
- int i = 0, l, p;
- const int lines = useful_bytes / s->avdimen.hw_bytes_per_line;
+ unsigned int i = 0, l, p;
+ const unsigned int lines = useful_bytes / (unsigned int) s->avdimen.hw_bytes_per_line;
for (l = 0; l < lines; ++l)
{
- uint8_t* r_ptr = stripe_data + (s->avdimen.hw_bytes_per_line * l);
+ uint8_t* r_ptr = stripe_data + ((unsigned int) s->avdimen.hw_bytes_per_line * l);
uint8_t* g_ptr = r_ptr + s->avdimen.hw_pixels_per_line;
uint8_t* b_ptr = g_ptr + s->avdimen.hw_pixels_per_line;
- for (p = 0; p < s->avdimen.hw_pixels_per_line; ++p) {
+ for (p = 0; p < (unsigned int) s->avdimen.hw_pixels_per_line; ++p) {
out_data [i++] = *(r_ptr++);
out_data [i++] = *(g_ptr++);
out_data [i++] = *(b_ptr++);
@@ -7846,12 +7886,12 @@ reader_process (void *data)
/* Mirroring with bgr -> rgb conversion: Just mirror the
* whole line */
- int l;
- int lines = useful_bytes / s->avdimen.hw_bytes_per_line;
+ unsigned int l;
+ unsigned int lines = useful_bytes / (unsigned int) s->avdimen.hw_bytes_per_line;
for (l = 0; l < lines; ++l)
{
- uint8_t* begin_ptr = out_data + (l * s->avdimen.hw_bytes_per_line);
+ uint8_t* begin_ptr = out_data + (l * (unsigned int) s->avdimen.hw_bytes_per_line);
uint8_t* end_ptr = begin_ptr + s->avdimen.hw_bytes_per_line;
while (begin_ptr < end_ptr) {
@@ -7866,12 +7906,12 @@ reader_process (void *data)
{
/* Non-trivial Mirroring with element swapping */
- int l;
- int lines = useful_bytes / s->avdimen.hw_bytes_per_line;
+ unsigned int l;
+ unsigned int lines = useful_bytes / (unsigned int) s->avdimen.hw_bytes_per_line;
for (l = 0; l < lines; ++l)
{
- uint8_t* begin_ptr = out_data + (l * s->avdimen.hw_bytes_per_line);
+ uint8_t* begin_ptr = out_data + (l * (unsigned int) s->avdimen.hw_bytes_per_line);
uint8_t* end_ptr = begin_ptr + s->avdimen.hw_bytes_per_line - 3;
while (begin_ptr < end_ptr) {
@@ -7904,8 +7944,8 @@ reader_process (void *data)
s->c_mode == AV_TRUECOLOR12 ||
s->c_mode == AV_TRUECOLOR16) {
- int l;
- int lines = useful_bytes / s->avdimen.hw_bytes_per_line;
+ unsigned int l;
+ unsigned int lines = useful_bytes / (unsigned int) s->avdimen.hw_bytes_per_line;
uint8_t* dark_avg_data = s->dark_avg_data;
uint8_t* white_avg_data = s->white_avg_data;
@@ -7923,9 +7963,9 @@ reader_process (void *data)
uint16_t white_avg = WHITE_MAP_RANGE;
if (dark_avg_data)
- dark_avg = get_double_le (dark_avg_data);
+ dark_avg = (uint16_t) get_double_le (dark_avg_data);
if (white_avg_data)
- white_avg = get_double_le (white_avg_data);
+ white_avg = (uint16_t) get_double_le (white_avg_data);
line_ptr = begin_ptr;
for (l = 0; l < lines; ++ l)
@@ -7935,11 +7975,11 @@ reader_process (void *data)
if (0)
v = (v - dark_avg) * white_avg / WHITE_MAP_RANGE;
- v2 = v < 0xFFFF ? v : 0xFFFF;
+ v2 = ((uint16_t) v) < 0xFFFF ? ((uint16_t) v) : 0xFFFF;
/* SANE Standard 3.2.1 "... bytes of each sample value are
transmitted in the machine's native byte order." */
- *line_ptr = v2;
+ *line_ptr = (uint8_t) v2;
line_ptr += s->avdimen.hw_bytes_per_line;
}
@@ -7954,19 +7994,14 @@ reader_process (void *data)
/* SOFTWARE SCALING WITH INTERPOLATION (IF NECESSARY) */
- if (s->avdimen.hw_xres == s->avdimen.xres &&
- s->avdimen.hw_yres == s->avdimen.yres) /* No scaling */
- {
- fwrite (out_data, useful_bytes, 1, fp);
- line += useful_bytes / s->avdimen.hw_bytes_per_line;
- }
- else /* Software scaling - watch out - this code bites back! */
+ if (s->avdimen.hw_xres != s->avdimen.xres ||
+ s->avdimen.hw_yres != s->avdimen.yres) /* Software scaling */
{
int x;
/* for convenience in the 16bit code path */
uint16_t* out_data16 = (uint16_t*) out_data;
- const int hw_line_end = hw_line + useful_bytes / s->avdimen.hw_bytes_per_line;
+ const int hw_line_end = hw_line + (int) useful_bytes / s->avdimen.hw_bytes_per_line;
/* on-the-fly bi-linear interpolation */
while (1) {
@@ -7993,6 +8028,9 @@ reader_process (void *data)
break;
}
+ DBG (8, "reader_process: out line: %d <- from: %d-%d\n",
+ line, sy, syy);
+
/* convert to offset in current stripe */
sy -= hw_line;
syy -= hw_line;
@@ -8002,9 +8040,6 @@ reader_process (void *data)
sy = -1;
}
- DBG (8, "reader_process: out line: %d <- from: %d-%d\n",
- line, sy, syy);
-
for (x = 0; x < s->params.pixels_per_line; ++x) {
const double bx = (-1.0 + s->avdimen.hw_pixels_per_line) * x / s->params.pixels_per_line;
const int sx = (int)floor(bx);
@@ -8022,16 +8057,16 @@ reader_process (void *data)
/* Repeating this over and over again is not fast, but
as a seldom used code-path we want it readable.
x/8 is the byte, and x%8 the bit position. */
- v =
+ v = (unsigned int) (
( ((out_data [sy*hwbpl + sx/8 ] >> (7-sx%8 )) & 1) * (256-xdist) * (256-ydist) +
((out_data [sy*hwbpl + sxx/8] >> (7-sxx%8)) & 1) * xdist * (256-ydist) +
((out_data [syy*hwbpl + sx/8 ] >> (7-sx%8 )) & 1) * (256-xdist) * ydist +
((out_data [syy*hwbpl + sxx/8] >> (7-sxx%8)) & 1) * xdist * ydist
- ) / (1 + 1 * 256);
+ ) / (1 + 1 * 256));
/* Shift and or the result together and eventually
jump to the next byte. */
- *dst = (*dst << 1) | ((v>>7)&1);
+ *dst = (uint8_t) ((*dst << 1) | ((v>>7)&1));
if (x % 8 == 7)
++dst;
}
@@ -8039,13 +8074,13 @@ reader_process (void *data)
case AV_GRAYSCALE:
{
- v =
+ v = (unsigned int) (
( out_data [sy*hwbpl + sx ] * (256-xdist) * (256-ydist) +
out_data [sy*hwbpl + sxx] * xdist * (256-ydist) +
out_data [syy*hwbpl + sx ] * (256-xdist) * ydist +
out_data [syy*hwbpl + sxx] * xdist * ydist
- ) / (256 * 256);
- *dst++ = v;
+ ) / (256 * 256));
+ *dst++ = (uint8_t) v;
}
break;
@@ -8053,13 +8088,13 @@ reader_process (void *data)
case AV_GRAYSCALE16:
{
/* TODO: test! */
- v =
+ v = (unsigned int) (
( out_data16 [sy*hwbpl + sx ] * (256-xdist) * (256-ydist) +
out_data16 [sy*hwbpl + sxx] * xdist * (256-ydist) +
out_data16 [syy*hwbpl + sx ] * (256-xdist) * ydist +
out_data16 [syy*hwbpl + sxx] * xdist * ydist
- ) / (256 * 256);
- *dst16++ = v;
+ ) / (256 * 256));
+ *dst16++ = (uint16_t) v;
}
break;
@@ -8068,13 +8103,13 @@ reader_process (void *data)
int c;
for (c = 0; c < 3; ++c)
{
- v =
+ v = (unsigned int) (
( out_data [sy*hwbpl + sx*3 + c] * (256-xdist) * (256-ydist) +
out_data [sy*hwbpl + sxx*3 + c] * xdist * (256-ydist) +
out_data [syy*hwbpl + sx*3 + c] * (256-xdist) * ydist +
out_data [syy*hwbpl + sxx*3 + c] * xdist * ydist
- ) / (256 * 256);
- *dst++ = v;
+ ) / (256 * 256));
+ *dst++ = (uint8_t) v;
}
}
break;
@@ -8086,13 +8121,13 @@ reader_process (void *data)
int c;
for (c = 0; c < 3; ++c)
{
- v =
+ v = (unsigned int) (
( out_data16 [sy*hwbpl + sx*3 + c] * (256-xdist) * (256-ydist) +
out_data16 [sy*hwbpl + sxx*3 + c] * xdist * (256-ydist) +
out_data16 [syy*hwbpl + sx*3 + c] * (256-xdist) * ydist +
out_data16 [syy*hwbpl + sxx*3 + c] * xdist * ydist
- ) / (256 * 256);
- *dst16++ = v;
+ ) / (256 * 256));
+ *dst16++ = (uint16_t) v;
}
}
break;
@@ -8101,13 +8136,18 @@ reader_process (void *data)
; /* silence compiler warning */
}
}
- fwrite (ip_data, s->params.bytes_per_line, 1, fp);
+ fwrite (ip_data, (size_t) s->params.bytes_per_line, 1, fp);
++line;
}
/* copy one line of history for the next pass */
memcpy (ip_history,
out_data + useful_bytes - s->avdimen.hw_bytes_per_line,
- s->avdimen.hw_bytes_per_line);
+ (size_t) s->avdimen.hw_bytes_per_line);
+ }
+ else /* No scaling */
+ {
+ fwrite (out_data, useful_bytes, 1, fp);
+ line += (int) useful_bytes / s->avdimen.hw_bytes_per_line;
}
}
@@ -8116,7 +8156,7 @@ reader_process (void *data)
if (stripe_fill > 0)
memcpy (stripe_data, stripe_data + useful_bytes, stripe_fill);
- hw_line += useful_bytes / s->avdimen.hw_bytes_per_line;
+ hw_line += (int) useful_bytes / s->avdimen.hw_bytes_per_line;
DBG (3, "reader_process: end of iteration\n");
} /* end while not all lines or inf. mode */
@@ -8131,12 +8171,12 @@ reader_process (void *data)
/* maybe we need to fill in some white data */
if (exit_status == SANE_STATUS_EOF && line < s->params.lines) {
DBG (3, "reader_process: padding with white data\n");
- memset (out_data, gray_mode ? 0xff : 0x00, s->params.bytes_per_line);
+ memset (out_data, gray_mode ? 0xff : 0x00, (size_t) s->params.bytes_per_line);
DBG (6, "reader_process: padding line %d - %d\n",
line, s->params.lines);
while (line < s->params.lines) {
- fwrite (out_data, s->params.bytes_per_line, 1, fp);
+ fwrite (out_data, (size_t) s->params.bytes_per_line, 1, fp);
++line;
}
}
@@ -8147,12 +8187,12 @@ reader_process (void *data)
long lines;
uint8_t* buffer;
- buffer = malloc (s->params.bytes_per_line);
+ buffer = malloc ((size_t) s->params.bytes_per_line);
lines = ftell(fp) / s->params.bytes_per_line;
rewind(fp);
for (long line = 0; line < lines; line++) {
- fread(buffer, s->params.bytes_per_line, 1, fp);
+ fread(buffer, (size_t) s->params.bytes_per_line, 1, fp);
if ( (!s->duplex_rear_valid && (line < s->avdimen.offset.front.top)) ||
(s->duplex_rear_valid && (line < s->avdimen.offset.rear.top)) ) {
@@ -8166,7 +8206,7 @@ reader_process (void *data)
break; /* nothing more to write, so break out here */
}
- fwrite(buffer, s->params.bytes_per_line, 1, fp_fd);
+ fwrite(buffer, (size_t) s->params.bytes_per_line, 1, fp_fd);
}
}
@@ -8442,7 +8482,7 @@ sane_reload_devices (void)
SANE_Status
sane_init (SANE_Int* version_code, SANE_Auth_Callback authorize)
{
- authorize = authorize; /* silence gcc */
+ (void) authorize; /* silence gcc */
DBG_INIT();
@@ -8489,9 +8529,9 @@ SANE_Status
sane_get_devices (const SANE_Device*** device_list, SANE_Bool local_only)
{
Avision_Device* dev;
- int i;
+ unsigned int i;
- local_only = local_only; /* silence gcc */
+ (void) local_only; /* silence gcc */
DBG (3, "sane_get_devices:\n");
@@ -8581,7 +8621,7 @@ sane_open (SANE_String_Const devicename, SANE_Handle *handle)
for (i = 0; i < 4; ++ i)
for (j = 0; j < 256; ++ j)
- s->gamma_table[i][j] = pow( (double) j / 255, one_over_gamma) * 255;
+ s->gamma_table[i][j] = (SANE_Int) (pow( (double) j / 255, one_over_gamma) * 255);
}
/* insert newly opened handle into list of open handles: */
@@ -8640,33 +8680,21 @@ sane_open (SANE_String_Const devicename, SANE_Handle *handle)
dev->hw->offset.duplex.rear.bottom != 0) )
dev->adf_offset_compensation = SANE_TRUE;
- if (dev->adf_offset_compensation) {
- strncpy(s->duplex_offtmp_fname, "/tmp/avision-offtmp-XXXXXX", PATH_MAX);
-
- if (! mktemp(s->duplex_offtmp_fname) ) {
- DBG (1, "sane_open: failed to generate temporary fname for ADF offset compensation temp file\n");
- return SANE_STATUS_NO_MEM;
- }
- else {
- DBG (1, "sane_open: temporary fname for ADF offset compensation temp file: %s\n",
- s->duplex_offtmp_fname);
- }
- }
-
if (dev->inquiry_duplex_interlaced || dev->scanner_type == AV_FILM ||
dev->hw->feature_type & AV_ADF_FLIPPING_DUPLEX) {
/* Might need at least *DOS (Windows flavour and OS/2) portability fix
However, I was told Cygwin (et al.) takes care of it. */
+
+ /* Create the file but close the fd. It is not used to open the file later. :( */
strncpy(s->duplex_rear_fname, "/tmp/avision-rear-XXXXXX", PATH_MAX);
- if (! mkstemp(s->duplex_rear_fname) ) {
+ int fd = mkstemp(s->duplex_rear_fname);
+ if (fd == -1) {
DBG (1, "sane_open: failed to generate temporary fname for duplex scans\n");
return SANE_STATUS_NO_MEM;
}
- else {
- DBG (1, "sane_open: temporary fname for duplex scans: %s\n",
- s->duplex_rear_fname);
- }
+ DBG (1, "sane_open: temporary fname for duplex scans: %s\n", s->duplex_rear_fname);
+ close(fd);
}
/* calibrate film scanners, as this must be done without the
@@ -8713,22 +8741,14 @@ void
sane_close (SANE_Handle handle)
{
Avision_Scanner* prev;
- Avision_Scanner* s = handle;
+ Avision_Scanner* s;
int i;
DBG (3, "sane_close:\n");
- /* close the device */
- if (avision_is_open (&s->av_con) ) {
- avision_close (&s->av_con);
- }
-
- /* remove handle from list of open handles: */
- prev = 0;
- for (s = first_handle; s; s = s->next) {
+ for (prev = 0, s = first_handle; s; prev = s, s = s->next) {
if (s == handle)
break;
- prev = s;
}
/* a handle we know about ? */
@@ -8740,6 +8760,12 @@ sane_close (SANE_Handle handle)
if (s->scanning)
do_cancel (handle);
+ /* close the device */
+ if (avision_is_open(&s->av_con)) {
+ avision_close(&s->av_con);
+ }
+
+ /* remove handle from list of open handles */
if (prev)
prev->next = s->next;
else
@@ -8764,11 +8790,6 @@ sane_close (SANE_Handle handle)
*(s->duplex_rear_fname) = 0;
}
- if (*(s->duplex_offtmp_fname)) {
- unlink (s->duplex_offtmp_fname);
- *(s->duplex_offtmp_fname) = 0;
- }
-
free (handle);
}
@@ -8863,7 +8884,7 @@ sane_control_option (SANE_Handle handle, SANE_Int option,
case OPT_GAMMA_VECTOR_R:
case OPT_GAMMA_VECTOR_G:
case OPT_GAMMA_VECTOR_B:
- memcpy (val, s->val[option].wa, s->opt[option].size);
+ memcpy (val, s->val[option].wa, (size_t) s->opt[option].size);
return SANE_STATUS_GOOD;
/* string options: */
@@ -8923,7 +8944,7 @@ sane_control_option (SANE_Handle handle, SANE_Int option,
case OPT_GAMMA_VECTOR_R:
case OPT_GAMMA_VECTOR_G:
case OPT_GAMMA_VECTOR_B:
- memcpy (s->val[option].wa, val, s->opt[option].size);
+ memcpy (s->val[option].wa, val, (size_t) s->opt[option].size);
return SANE_STATUS_GOOD;
/* options with side-effects: */
@@ -9327,7 +9348,7 @@ sane_read (SANE_Handle handle, SANE_Byte* buf, SANE_Int max_len, SANE_Int* len)
DBG (8, "sane_read: max_len: %d\n", max_len);
- nread = read (s->read_fds, buf, max_len);
+ nread = read (s->read_fds, buf, (size_t) max_len);
if (nread > 0) {
DBG (8, "sane_read: got %ld bytes\n", (long) nread);
}
@@ -9347,7 +9368,7 @@ sane_read (SANE_Handle handle, SANE_Byte* buf, SANE_Int max_len, SANE_Int* len)
}
}
- *len = nread;
+ *len = (SANE_Int) nread;
/* if all data was passed through */
if (nread == 0)