summaryrefslogtreecommitdiff
path: root/backend/escl/escl_pdf.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2023-02-12 17:35:53 +0100
committerJörg Frings-Fürst <debian@jff.email>2023-02-12 17:35:53 +0100
commit84357741a6a6e6430f199b2c3f7498e0e97da9ad (patch)
tree23e8d66ede9506b94c76fb36910ca3c7dd15c74e /backend/escl/escl_pdf.c
parent302276dc1b90cfc972fb726ca94a23b18f4b0088 (diff)
New upstream version 1.2.1upstream/1.2.1upstream
Diffstat (limited to 'backend/escl/escl_pdf.c')
-rw-r--r--backend/escl/escl_pdf.c51
1 files changed, 42 insertions, 9 deletions
diff --git a/backend/escl/escl_pdf.c b/backend/escl/escl_pdf.c
index 02dce66..8277e1d 100644
--- a/backend/escl/escl_pdf.c
+++ b/backend/escl/escl_pdf.c
@@ -44,8 +44,9 @@
#if HAVE_POPPLER_GLIB
-#define INPUT_BUFFER_SIZE 4096
+#define ESCL_PDF_USE_MAPPED_FILE POPPLER_CHECK_VERSION(0,82,0)
+#if ! ESCL_PDF_USE_MAPPED_FILE
static unsigned char*
set_file_in_buffer(FILE *fp, int *size)
{
@@ -70,6 +71,7 @@ set_file_in_buffer(FILE *fp, int *size)
*size = nx;
return data;
}
+#endif
static unsigned char *
cairo_surface_to_pixels (cairo_surface_t *surface, int bps)
@@ -109,28 +111,52 @@ get_PDF_data(capabilities_t *scanner, int *width, int *height, int *bps)
PopplerPage *page;
PopplerDocument *doc;
double dw, dh;
- int w, h, size = 0;
- char *data = NULL;
+ int w, h;
unsigned char* surface = NULL;
SANE_Status status = SANE_STATUS_GOOD;
+#if ESCL_PDF_USE_MAPPED_FILE
+ GMappedFile *file;
+ GBytes *bytes;
+
+ file = g_mapped_file_new_from_fd (fileno (scanner->tmp), 0, NULL);
+ if (!file) {
+ DBG(1, "Error : g_mapped_file_new_from_fd");
+ status = SANE_STATUS_INVAL;
+ goto close_file;
+ }
+
+ bytes = g_mapped_file_get_bytes (file);
+ if (!bytes) {
+ DBG(1, "Error : g_mapped_file_get_bytes");
+ status = SANE_STATUS_INVAL;
+ goto free_file;
+ }
+
+ doc = poppler_document_new_from_bytes (bytes, NULL, NULL);
+ if (!doc) {
+ DBG(1, "Error : poppler_document_new_from_bytes");
+ status = SANE_STATUS_INVAL;
+ goto free_bytes;
+ }
+#else
+ int size = 0;
+ char *data = NULL;
data = (char*)set_file_in_buffer(scanner->tmp, &size);
if (!data) {
- DBG(1, "Error : poppler_document_new_from_data");
+ DBG(1, "Error : set_file_in_buffer");
status = SANE_STATUS_INVAL;
goto close_file;
}
- doc = poppler_document_new_from_data(data,
- size,
- NULL,
- NULL);
+ doc = poppler_document_new_from_data (data, size, NULL, NULL);
if (!doc) {
DBG(1, "Error : poppler_document_new_from_data");
status = SANE_STATUS_INVAL;
- goto free_file;
+ goto free_data;
}
+#endif
page = poppler_document_get_page (doc, 0);
if (!page) {
@@ -201,8 +227,15 @@ free_page:
g_object_unref (page);
free_doc:
g_object_unref (doc);
+#if ESCL_PDF_USE_MAPPED_FILE
+free_bytes:
+ g_bytes_unref (bytes);
free_file:
+ g_mapped_file_unref (file);
+#else
+free_data:
free(data);
+#endif
close_file:
if (scanner->tmp)
fclose(scanner->tmp);