Porównaj commity

...

6 Commity

Autor SHA1 Wiadomość Data
Andrew Sayers 1c751b5489 Merge branch 'do-not-append-slack-lines' into 'master'
xerox_mfp: do not append slack lines

See merge request sane-project/backends!616
2024-04-23 04:58:12 +00:00
Ralph Little 0f472aa205 Merge branch 'editorconfig_inline_comment' into 'master'
.editorconfig: inline comments are forbidden

See merge request sane-project/backends!832
2024-04-19 19:53:22 +00:00
ThierryFR 728ca40272 Merge branch 'escl-force-idle-status' into 'master'
Escl force idle status

See merge request sane-project/backends!835
2024-04-16 20:45:49 +00:00
ThierryFR 113be50f6b Escl force idle status 2024-04-16 20:45:49 +00:00
Guillaume Girol a6d63a72ec .editorconfig: inline comments are forbidden
source: https://spec.editorconfig.org/#no-inline-comments

this makes neovim unhappy, at least.
2024-02-26 12:00:00 +00:00
Andrew Sayers 8c306b0234 xerox_mfp: do not append slack lines
xerox_mfp devices return a page height in millimetres.  We previously
converted that to pixels, guaranteed the image's height in pixels,
and added some slack lines if the scanner returned too few.

Return an image height of -1 instead, and get rid of the slack lines.
2021-03-30 12:20:48 +01:00
7 zmienionych plików z 187 dodań i 31 usunięć

Wyświetl plik

@ -6,7 +6,8 @@
# Your editor may need a plugin for this configuration to take effect.
# See http://editorconfig.org/#download for details.
root = true ; look no further
; look no further
root = true
[*]
charset = utf-8

Wyświetl plik

@ -1345,7 +1345,7 @@ sane_cancel(SANE_Handle h)
}
handler->scanner->work = SANE_FALSE;
handler->cancel = SANE_TRUE;
escl_scanner(handler->device, handler->scanner->scanJob, handler->result);
escl_scanner(handler->device, handler->scanner->scanJob, handler->result, SANE_TRUE);
free(handler->result);
handler->result = NULL;
free(handler->scanner->scanJob);
@ -1566,6 +1566,7 @@ sane_start(SANE_Handle h)
handler->decompress_scan_data = SANE_FALSE;
handler->end_read = SANE_FALSE;
if (handler->scanner->work == SANE_FALSE) {
escl_reset_all_jobs(handler->device);
SANE_Status st = escl_status(handler->device,
handler->scanner->source,
NULL,

Wyświetl plik

@ -248,7 +248,11 @@ SANE_Status escl_scan(capabilities_t *scanner,
void escl_scanner(const ESCL_Device *device,
char *scanJob,
char *result);
char *result,
SANE_Bool status);
SANE_Status escl_reset_all_jobs(ESCL_Device *device);
typedef void CURL;

Wyświetl plik

@ -44,7 +44,32 @@ write_callback(void __sane_unused__*str,
* This function is called in the 'sane_cancel' function.
*/
void
escl_scanner(const ESCL_Device *device, char *scanJob, char *result)
escl_delete(const ESCL_Device *device, char *uri)
{
CURL *curl_handle = NULL;
long answer = 0;
if (uri == NULL)
return;
curl_handle = curl_easy_init();
if (curl_handle != NULL) {
escl_curl_url(curl_handle, device, uri);
curl_easy_setopt(curl_handle, CURLOPT_CUSTOMREQUEST, "DELETE");
if (curl_easy_perform(curl_handle) == CURLE_OK) {
curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &answer);
return;
}
curl_easy_cleanup(curl_handle);
}
}
/**
* \fn void escl_scanner(const ESCL_Device *device, char *result)
* \brief Function that resets the scanner after each scan, using curl.
* This function is called in the 'sane_cancel' function.
*/
void
escl_scanner(const ESCL_Device *device, char *scanJob, char *result, SANE_Bool status)
{
CURL *curl_handle = NULL;
const char *scan_jobs = "/eSCL/";
@ -70,10 +95,15 @@ CURL_CALL:
if (i >= 15) return;
}
curl_easy_cleanup(curl_handle);
if (SANE_STATUS_GOOD != escl_status(device,
PLATEN,
NULL,
NULL))
goto CURL_CALL;
char* end = strrchr(scan_cmd, '/');
*end = 0;
escl_delete(device, scan_cmd);
if (status) {
if (SANE_STATUS_GOOD != escl_status(device,
PLATEN,
NULL,
NULL))
goto CURL_CALL;
}
}
}

Wyświetl plik

@ -29,6 +29,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <libxml/parser.h>
@ -270,3 +271,135 @@ clean_data:
}
return (status);
}
static void
print_xml_job_finish(xmlNode *node,
SANE_Status *job)
{
while (node) {
if (node->type == XML_ELEMENT_NODE) {
if (find_nodes_s(node)) {
if (strcmp((const char *)node->name, "JobState") == 0) {
const char *state = (const char *)xmlNodeGetContent(node);
if (!strcmp(state, "Canceled")) {
*job = SANE_STATUS_GOOD;
DBG(10, "jobId Completed SANE_STATUS_GOOD\n");
}
else if (!strcmp(state, "Aborted")) {
*job = SANE_STATUS_GOOD;
DBG(10, "jobId Completed SANE_STATUS_GOOD\n");
}
else if (!strcmp(state, "Completed")) {
*job = SANE_STATUS_GOOD;
DBG(10, "jobId Completed SANE_STATUS_GOOD\n");
}
}
}
}
print_xml_job_finish(node->children, job);
node = node->next;
}
}
static void
print_xml_reset_all_jobs (xmlNode *node,
ESCL_Device *device)
{
DBG(10, "print_xml_reset_all_jobs\n");
SANE_Status status = SANE_STATUS_DEVICE_BUSY;
while (node) {
if (node->type == XML_ELEMENT_NODE) {
if (find_nodes_s(node)) {
if (strcmp((const char *)node->name, "JobUri") == 0) {
DBG(10, "print_xml_reset_all_jobs: %s\n", node->name);
if (device != NULL) {
print_xml_job_finish (node, &status);
if (status == SANE_STATUS_DEVICE_BUSY) {
char *jobUri = (char *)xmlNodeGetContent(node);
char *job = strrchr((const char *)jobUri, '/');
char *scanj = NULL;
if (job != NULL) {
if (strstr(jobUri,"ScanJobs"))
scanj = strdup("ScanJobs");
else
scanj = strdup("ScanJob");
DBG(10, "print_xml_reset_all_jobs: %s/%s\n", scanj, job);
escl_scanner(device, scanj, job, SANE_FALSE);
free(scanj);
}
DBG(10, "print_xml_reset_all_jobs: sleep to finish the job\n");
}
}
}
}
}
print_xml_reset_all_jobs (node->children,
device);
node = node->next;
}
}
/**
* \fn SANE_Status escl_reset_all_jobs (ESCL_Device *device, , char *scanJob)
* \brief Function that forces the end of jobs, using curl.
* This function is called in the 'sane_start' function.
*
* \return status (if everything is OK, status = SANE_STATUS_GOOD, otherwise, SANE_STATUS_NO_MEM/SANE_STATUS_INVAL)
*/
SANE_Status
escl_reset_all_jobs(ESCL_Device *device)
{
CURL *curl_handle = NULL;
xmlDoc *data = NULL;
xmlNode *node = NULL;
struct idle *var = NULL;
const char *scanner_status = "/eSCL/ScannerStatus";
SANE_Status status = SANE_STATUS_DEVICE_BUSY;
DBG(10, "escl_reset_all_jobs\n");
if (device == NULL)
return (SANE_STATUS_NO_MEM);
DBG(10, "1 - escl_reset_all_jobs\n");
var = (struct idle*)calloc(1, sizeof(struct idle));
if (var == NULL)
return (SANE_STATUS_NO_MEM);
DBG(10, "2 - escl_reset_all_jobs\n");
var->memory = malloc(1);
var->size = 0;
curl_handle = curl_easy_init();
escl_curl_url(curl_handle, device, scanner_status);
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, memory_callback_s);
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)var);
curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS, 3L);
CURLcode res = curl_easy_perform(curl_handle);
if (res != CURLE_OK) {
DBG( 1, "The scanner didn't respond: %s\n", curl_easy_strerror(res));
status = SANE_STATUS_INVAL;
goto clean_data1;
}
DBG(10, "3 - escl_reset_all_jobs\n");
DBG( 10, "eSCL : Status : %s.\n", var->memory);
data = xmlReadMemory(var->memory, var->size, "file.xml", NULL, 0);
if (data == NULL) {
status = SANE_STATUS_NO_MEM;
goto clean_data1;
}
node = xmlDocGetRootElement(data);
if (node == NULL) {
status = SANE_STATUS_NO_MEM;
goto clean1;
}
print_xml_reset_all_jobs (node, device);
status = SANE_STATUS_GOOD;
clean1:
xmlFreeDoc(data);
clean_data1:
xmlCleanupParser();
xmlMemoryDump();
curl_easy_cleanup(curl_handle);
free(var->memory);
free(var);
return status;
}

Wyświetl plik

@ -364,7 +364,7 @@ static SANE_Status dev_stop(struct device *dev)
dev->reserved = 0;
dev_cmd(dev, CMD_RELEASE_UNIT);
DBG(3, "total image %d*%d size %d (win %d*%d), %d*%d %d data: %d, out %d bytes\n",
dev->para.pixels_per_line, dev->para.lines,
dev->para.pixels_per_line, dev->total_lines,
dev->total_img_size,
dev->win_width, dev->win_len,
dev->pixels_per_line, dev->ulines, dev->blocks,
@ -680,7 +680,7 @@ static void set_parameters(struct device *dev)
px_to_len = 1213.9 / dev->val[OPT_RESOLUTION].w;
#endif
}
dev->para.lines = dev->win_len / px_to_len;
dev->total_lines = dev->win_len / px_to_len;
if (dev->composition == MODE_LINEART ||
dev->composition == MODE_HALFTONE) {
dev->para.format = SANE_FRAME_GRAY;
@ -1256,19 +1256,6 @@ static int dev_acquire(struct device *dev)
return 1;
}
static int fill_slack(struct device *dev, SANE_Byte *buf, int maxlen)
{
const int slack = dev->total_img_size - dev->total_out_size;
const int havelen = MIN(slack, maxlen);
int j;
if (havelen <= 0)
return 0;
for (j = 0; j < havelen; j++)
buf[j] = 255;
return havelen;
}
static int copy_plain_trim(struct device *dev, SANE_Byte *buf, int maxlen, int *olenp)
{
int j;
@ -1281,7 +1268,7 @@ static int copy_plain_trim(struct device *dev, SANE_Byte *buf, int maxlen, int *
if (y >= dev->vertical)
break; /* slack */
if (x < dev->para.bytes_per_line &&
(y + dev->y_off) < dev->para.lines) {
(y + dev->y_off) < dev->total_lines) {
*buf++ = dev->data[(dev->dataoff + j) & DATAMASK];
(*olenp)++;
}
@ -1318,7 +1305,7 @@ static int copy_mix_bands_trim(struct device *dev, SANE_Byte *buf, int maxlen, i
const int y_rly = y + y_off + dev->y_off; /* global y */
if (x < dev->para.pixels_per_line &&
y_rly < dev->para.lines) {
y_rly < dev->total_lines) {
*buf++ = dev->data[(dev->dataoff + band + x + y * linesize) & DATAMASK];
(*olenp)++;
}
@ -1375,8 +1362,7 @@ sane_read(SANE_Handle h, SANE_Byte *buf, SANE_Int maxlen, SANE_Int *lenp)
/* but we may need to fill slack */
if (buf && lenp && slack > 0) {
*lenp = fill_slack(dev, buf, maxlen);
dev->total_out_size += *lenp;
dev->total_out_size += MIN(slack, maxlen);
DBG(9, "<> slack: %d, filled: %d, maxlen %d\n",
slack, *lenp, maxlen);
return SANE_STATUS_GOOD;
@ -1469,10 +1455,10 @@ sane_read(SANE_Handle h, SANE_Byte *buf, SANE_Int maxlen, SANE_Int *lenp)
DBG(9, "<> olen: %d, clrlen: %d, blocklen: %d/%d, maxlen %d (%d %d %d)\n",
olen, clrlen, dev->blocklen, dev->datalen, maxlen,
dev->dataindex / dev->bytes_per_line + dev->y_off,
dev->y_off, dev->para.lines);
dev->y_off, dev->total_lines);
/* slack beyond last line */
if (dev->dataindex / dev->bytes_per_line + dev->y_off >= dev->para.lines) {
if (dev->dataindex / dev->bytes_per_line + dev->y_off >= dev->total_lines) {
dev->datalen = 0;
dev->dataoff = 0;
}
@ -1559,7 +1545,7 @@ sane_start(SANE_Handle h)
dev->para.bytes_per_line = dev->para.pixels_per_line;
}
dev->total_img_size = dev->para.bytes_per_line * dev->para.lines;
dev->total_img_size = dev->para.bytes_per_line * dev->total_lines;
if (isJPEGEnabled(dev) &&
dev->composition == MODE_RGB24) {

Wyświetl plik

@ -122,6 +122,7 @@ struct device {
int total_img_size; /* predicted image size */
int total_out_size; /* total we sent to user */
int total_data_size; /* total of what scanner sent us */
int total_lines; /* number of lines expected */
/* transport to use */
transport *io;