.gitlab-ci.yml: Revert poppler related changes

The Docker images used by CI have been updated to include the required
packages.
fix-build-obselete-jpeg
Ordissimo 2020-03-14 09:01:17 +00:00 zatwierdzone przez Olaf Meeuwissen
rodzic 0033357120
commit 5dcd770e5e
8 zmienionych plików z 544 dodań i 8 usunięć

Wyświetl plik

@ -6,7 +6,7 @@
variables:
REGISTRY_HUB: "registry.gitlab.com/sane-project/ci-envs"
CONFIGURE_MINI: "--enable-silent-rules"
CONFIGURE_FULL: "--with-usb --enable-avahi --enable-pnm-backend --with-libcurl"
CONFIGURE_FULL: "--with-usb --enable-avahi --enable-pnm-backend --with-libcurl --with-poppler-glib"
stages:
- tarball

Wyświetl plik

@ -437,13 +437,26 @@ EXTRA_DIST += dmc.conf.in
if have_libavahi
if have_libcurl
if have_libxml2
libescl_la_SOURCES = escl/escl.c escl/escl_capabilities.c escl/escl_devices.c escl/escl.h escl/escl_newjob.c escl/escl_reset.c escl/escl_scan.c escl/escl_status.c escl/escl_jpeg.c escl/escl_png.c escl/escl_tiff.c escl/escl_crop.c
libescl_la_CPPFLAGS = $(AM_CPPFLAGS) $(JPEG_CFLAGS) $(PNG_CFLAGS) $(TIFF_CFLAGS) $(XML_CFLAGS) $(libcurl_CFLAGS) $(AVAHI_CFLAGS) -DBACKEND_NAME=escl
libescl_la_SOURCES = escl/escl.c \
escl/escl_capabilities.c \
escl/escl_devices.c \
escl/escl.h \
escl/escl_newjob.c \
escl/escl_reset.c \
escl/escl_scan.c \
escl/escl_status.c \
escl/escl_jpeg.c \
escl/escl_png.c \
escl/escl_tiff.c \
escl/escl_pdf.c \
escl/escl_crop.c
libescl_la_CPPFLAGS = $(AM_CPPFLAGS) $(JPEG_CFLAGS) $(PNG_CFLAGS) $(TIFF_CFLAGS) $(POPPLER_GLIB_CFLAGS) $(XML_CFLAGS) $(libcurl_CFLAGS) $(AVAHI_CFLAGS) -DBACKEND_NAME=escl
nodist_libsane_escl_la_SOURCES = escl-s.c
libsane_escl_la_CPPFLAGS = $(AM_CPPFLAGS) $(JPEG_CFLAGS) $(PNG_CFLAGS) $(TIFF_CFLAGS) $(XML_CFLAGS) $(libcurl_CFLAGS) $(AVAHI_CFLAGS) -DBACKEND_NAME=escl
libsane_escl_la_CPPFLAGS = $(AM_CPPFLAGS) $(JPEG_CFLAGS) $(PNG_CFLAGS) $(TIFF_CFLAGS) $(POPPLER_GLIB_CFLAGS) $(XML_CFLAGS) $(libcurl_CFLAGS) $(AVAHI_CFLAGS) -DBACKEND_NAME=escl
libsane_escl_la_CFLAGS = $(AM_CFLAGS) $(JPEG_CFLAGS) $(PNG_CFLAGS) $(TIFF_CFLAGS) $(POPPLER_GLIB_CFLAGS) $(XML_CFLAGS) $(libcurl_CFLAGS) $(AVAHI_CFLAGS) -DBACKEND_NAME=escl
libsane_escl_la_LDFLAGS = $(DIST_SANELIBS_LDFLAGS)
libsane_escl_la_LIBADD = $(COMMON_LIBS) libescl.la ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo ../sanei/sanei_config.lo sane_strstatus.lo $(MATH_LIB) $(JPEG_LIBS) $(PNG_LIBS) $(TIFF_LIBS) $(XML_LIBS) $(libcurl_LIBS) $(AVAHI_LIBS)
libsane_escl_la_LIBADD = $(COMMON_LIBS) libescl.la ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo ../sanei/sanei_config.lo sane_strstatus.lo $(MATH_LIB) $(JPEG_LIBS) $(PNG_LIBS) $(TIFF_LIBS) $(POPPLER_GLIB_LIBS) $(XML_LIBS) $(libcurl_LIBS) $(AVAHI_LIBS)
endif
endif
endif

Wyświetl plik

@ -739,7 +739,7 @@ sane_start(SANE_Handle h)
{
int i = 0, val = 9999;;
if (handler->val[OPT_GRAY_PREVIEW].w == SANE_TRUE ||
!strncasecmp(handler->val[OPT_MODE].s, SANE_VALUE_SCAN_MODE_GRAY, 3))
!strcasecmp(handler->val[OPT_MODE].s, SANE_VALUE_SCAN_MODE_GRAY))
handler->scanner->default_color = strdup("Grayscale8");
else
handler->scanner->default_color = strdup("RGB24");
@ -757,8 +757,10 @@ sane_start(SANE_Handle h)
else
{
handler->scanner->default_resolution = handler->val[OPT_RESOLUTION].w;
if (!strncasecmp(handler->val[OPT_MODE].s, SANE_VALUE_SCAN_MODE_GRAY, 3))
if (!strcasecmp(handler->val[OPT_MODE].s, SANE_VALUE_SCAN_MODE_GRAY))
handler->scanner->default_color = strdup("Grayscale8");
else if (!strcasecmp(handler->val[OPT_MODE].s, SANE_VALUE_SCAN_MODE_LINEART))
handler->scanner->default_color = strdup("BlackAndWhite1");
else
handler->scanner->default_color = strdup("RGB24");
}
@ -793,6 +795,10 @@ sane_start(SANE_Handle h)
{
status = get_TIFF_data(handler->scanner, &w, &he, &bps);
}
else if (!strcmp(handler->scanner->default_format, "application/pdf"))
{
status = get_PDF_data(handler->scanner, &w, &he, &bps);
}
else {
DBG(10, "Unknow image format\n");
return SANE_STATUS_INVAL;

Wyświetl plik

@ -178,4 +178,7 @@ SANE_Status get_PNG_data(capabilities_t *scanner, int *width, int *height, int *
// TIFF
SANE_Status get_TIFF_data(capabilities_t *scanner, int *width, int *height, int *bps);
// PDF
SANE_Status get_PDF_data(capabilities_t *scanner, int *width, int *height, int *bps);
#endif

Wyświetl plik

@ -45,7 +45,7 @@ struct cap
* \fn static SANE_String_Const convert_elements(SANE_String_Const str)
* \brief Function that converts the 'color modes' of the scanner (color/gray) to be understood by SANE.
*
* \return SANE_VALUE_SCAN_MODE_GRAY / SANE_VALUE_SCAN_MODE_COLOR ; NULL otherwise
* \return SANE_VALUE_SCAN_MODE_GRAY / SANE_VALUE_SCAN_MODE_COLOR / SANE_VALUE_SCAN_MODE_LINEART; NULL otherwise
*/
static SANE_String_Const
convert_elements(SANE_String_Const str)
@ -54,6 +54,10 @@ convert_elements(SANE_String_Const str)
return (SANE_VALUE_SCAN_MODE_GRAY);
else if (strcmp(str, "RGB24") == 0)
return (SANE_VALUE_SCAN_MODE_COLOR);
#if(defined HAVE_POPPLER_GLIB)
else if (strcmp(str, "BlackAndWhite1") == 0)
return (SANE_VALUE_SCAN_MODE_LINEART);
#endif
return (NULL);
}
@ -207,6 +211,14 @@ find_valor_of_array_variables(xmlNode *node, capabilities_t *scanner)
free(scanner->default_format);
scanner->default_format = strdup("image/tiff");
}
#endif
#if(defined HAVE_POPPLER_GLIB)
else if(!strcmp(scanner->DocumentFormats[i], "application/pdf"))
{
if (scanner->default_format)
free(scanner->default_format);
scanner->default_format = strdup("application/pdf");
}
#endif
}
fprintf(stderr, "Capability : [%s]\n", scanner->default_format);

Wyświetl plik

@ -0,0 +1,256 @@
/* sane - Scanner Access Now Easy.
Copyright (C) 2019 Thierry HUCHARD <thierry@ordissimo.com>
This file is part of the SANE package.
SANE is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
SANE is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with sane; see the file COPYING. If not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
This file implements a SANE backend for eSCL scanners. */
#define DEBUG_DECLARE_ONLY
#include "../include/sane/config.h"
#include "escl.h"
#include "../include/sane/sanei.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#if(defined HAVE_MUPDF)
#include <mupdf/fitz.h>
#endif
#include <setjmp.h>
#if(defined HAVE_MUPDF)
// TODO: WIN32: HANDLE CreateFileW(), etc.
// TODO: POSIX: int creat(), read(), write(), lseeko, etc.
typedef struct fz_file_stream_escl_s
{
FILE *file;
unsigned char buffer[4096];
} fz_file_stream_escl;
static int
next_file_escl(fz_context *ctx, fz_stream *stm, size_t n)
{
fz_file_stream_escl *state = stm->state;
/* n is only a hint, that we can safely ignore */
n = fread(state->buffer, 1, sizeof(state->buffer), state->file);
if (n < sizeof(state->buffer) && ferror(state->file))
fz_throw(ctx, FZ_ERROR_GENERIC, "read error: %s", strerror(errno));
stm->rp = state->buffer;
stm->wp = state->buffer + n;
stm->pos += (int64_t)n;
if (n == 0)
return EOF;
return *stm->rp++;
}
static void
drop_file_escl(fz_context *ctx, void *state_)
{
fz_file_stream_escl *state = state_;
int n = fclose(state->file);
if (n < 0)
fz_warn(ctx, "close error: %s", strerror(errno));
fz_free(ctx, state);
}
static void
seek_file_escl(fz_context *ctx, fz_stream *stm, int64_t offset, int whence)
{
fz_file_stream_escl *state = stm->state;
#ifdef _WIN32
int64_t n = _fseeki64(state->file, offset, whence);
#else
int64_t n = fseeko(state->file, offset, whence);
#endif
if (n < 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot seek: %s", strerror(errno));
#ifdef _WIN32
stm->pos = _ftelli64(state->file);
#else
stm->pos = ftello(state->file);
#endif
stm->rp = state->buffer;
stm->wp = state->buffer;
}
static fz_stream *
fz_open_file_ptr_escl(fz_context *ctx, FILE *file)
{
fz_stream *stm;
fz_file_stream_escl *state = fz_malloc_struct(ctx, fz_file_stream_escl);
state->file = file;
stm = fz_new_stream(ctx, state, next_file_escl, drop_file_escl);
stm->seek = seek_file_escl;
return stm;
}
/**
* \fn SANE_Status escl_sane_decompressor(escl_sane_t *handler)
* \brief Function that aims to decompress the pdf image to SANE be able
* to read the image.
* This function is called in the "sane_read" function.
*
* \return SANE_STATUS_GOOD (if everything is OK, otherwise,
* SANE_STATUS_NO_MEM/SANE_STATUS_INVAL)
*/
SANE_Status
get_PDF_data(capabilities_t *scanner, int *width, int *height, int *bps)
{
int page_number = -1, page_count = -2;
fz_context *ctx;
fz_document *doc;
fz_pixmap *pix;
fz_matrix ctm;
fz_stream *stream;
unsigned char *surface = NULL; /* Image data */
SANE_Status status = SANE_STATUS_GOOD;
/* Create a context to hold the exception stack and various caches. */
ctx = fz_new_context(NULL, NULL, FZ_STORE_UNLIMITED);
if (!ctx)
{
DBG(1, "cannot create mupdf context\n");
status = SANE_STATUS_INVAL;
goto close_file;
}
/* Register the default file types to handle. */
fz_try(ctx)
fz_register_document_handlers(ctx);
fz_catch(ctx)
{
DBG(1, "cannot register document handlers: %s\n", fz_caught_message(ctx));
status = SANE_STATUS_INVAL;
goto drop_context;
}
/* Open the stream. */
fz_try(ctx)
stream = fz_open_file_ptr_escl(ctx, scanner->tmp);
fz_catch(ctx)
{
DBG(1, "cannot open stream: %s\n", fz_caught_message(ctx));
status = SANE_STATUS_INVAL;
goto drop_context;
}
/* Seek stream. */
fz_try(ctx)
fz_seek(ctx, stream, 0, SEEK_SET);
fz_catch(ctx)
{
DBG(1, "cannot seek stream: %s\n", fz_caught_message(ctx));
status = SANE_STATUS_INVAL;
goto drop_stream;
}
/* Open the document. */
fz_try(ctx)
doc = fz_open_document_with_stream(ctx, "filename.pdf", stream);
fz_catch(ctx)
{
DBG(1, "cannot open document: %s\n", fz_caught_message(ctx));
status = SANE_STATUS_INVAL;
goto drop_stream;
}
/* Count the number of pages. */
fz_try(ctx)
page_count = fz_count_pages(ctx, doc);
fz_catch(ctx)
{
DBG(1, "cannot count number of pages: %s\n", fz_caught_message(ctx));
status = SANE_STATUS_INVAL;
goto drop_document;
}
if (page_number < 0 || page_number >= page_count)
{
DBG(1, "page number out of range: %d (page count %d)\n", page_number + 1, page_count);
status = SANE_STATUS_INVAL;
goto drop_document;
}
/* Compute a transformation matrix for the zoom and rotation desired. */
/* The default resolution without scaling is 72 dpi. */
fz_scale(&ctm, (float)1.0, (float)1.0);
fz_pre_rotate(&ctm, (float)0.0);
/* Render page to an RGB pixmap. */
fz_try(ctx)
pix = fz_new_pixmap_from_page_number(ctx, doc, 0, &ctm, fz_device_rgb(ctx), 0);
fz_catch(ctx)
{
DBG(1, "cannot render page: %s\n", fz_caught_message(ctx));
status = SANE_STATUS_INVAL;
goto drop_document;
}
surface = malloc(pix->h * pix->stride);
memcpy(surface, pix->samples, (pix->h * pix->stride));
// If necessary, trim the image.
surface = escl_crop_surface(scanner, surface, pix->w, pix->h, pix->n, width, height);
if (!surface) {
DBG( 1, "Escl Pdf : Surface Memory allocation problem\n");
status = SANE_STATUS_NO_MEM;
goto drop_pix;
}
*bps = pix->n;
/* Clean up. */
drop_pix:
fz_drop_pixmap(ctx, pix);
drop_document:
fz_drop_document(ctx, doc);
drop_stream:
fz_drop_stream(ctx, stream);
drop_context:
fz_drop_context(ctx);
close_file:
if (scanner->tmp)
fclose(scanner->tmp);
scanner->tmp = NULL;
return status;
}
#else
SANE_Status
get_PDF_data(capabilities_t __sane_unused__ *scanner,
int __sane_unused__ *width,
int __sane_unused__ *height,
int __sane_unused__ *bps)
{
return (SANE_STATUS_INVAL);
}
#endif

Wyświetl plik

@ -0,0 +1,223 @@
/* sane - Scanner Access Now Easy.
Copyright (C) 2019 Thierry HUCHARD <thierry@ordissimo.com>
This file is part of the SANE package.
SANE is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
SANE is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with sane; see the file COPYING. If not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
This file implements a SANE backend for eSCL scanners. */
#define DEBUG_DECLARE_ONLY
#include "../include/sane/config.h"
#include "escl.h"
#include "../include/sane/sanei.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stddef.h>
#include <math.h>
#include <errno.h>
#if(defined HAVE_POPPLER_GLIB)
#include <poppler/glib/poppler.h>
#endif
#include <setjmp.h>
#if(defined HAVE_POPPLER_GLIB)
#define INPUT_BUFFER_SIZE 4096
static unsigned char*
set_file_in_buffer(FILE *fp, int *size)
{
char buffer[1024] = { 0 };
unsigned char *data = (unsigned char *)calloc(1, sizeof(char));
int nx = 0;
while(!feof(fp))
{
int n = fread(buffer,sizeof(char),1024,fp);
unsigned char *t = realloc(data, nx + n + 1);
if (t == NULL) {
DBG(10, "not enough memory (realloc returned NULL)");
free(data);
return NULL;
}
data = t;
memcpy(&(data[nx]), buffer, n);
nx = nx + n;
data[nx] = 0;
}
*size = nx;
return data;
}
static unsigned char *
cairo_surface_to_pixels (cairo_surface_t *surface, int bps)
{
int cairo_width, cairo_height, cairo_rowstride;
unsigned char *data, *dst, *cairo_data;
unsigned int *src;
int x, y;
cairo_width = cairo_image_surface_get_width (surface);
cairo_height = cairo_image_surface_get_height (surface);
cairo_rowstride = cairo_image_surface_get_stride (surface);
cairo_data = cairo_image_surface_get_data (surface);
data = (unsigned char*)calloc(1, sizeof(unsigned char) * (cairo_height * cairo_width * bps));
for (y = 0; y < cairo_height; y++)
{
src = (unsigned int *) (cairo_data + y * cairo_rowstride);
dst = data + y * (cairo_width * bps);
for (x = 0; x < cairo_width; x++)
{
dst[0] = (*src >> 16) & 0xff;
dst[1] = (*src >> 8) & 0xff;
dst[2] = (*src >> 0) & 0xff;
dst += bps;
src++;
}
}
return data;
}
SANE_Status
get_PDF_data(capabilities_t *scanner, int *width, int *height, int *bps)
{
cairo_surface_t *cairo_surface = NULL;
cairo_t *cr;
PopplerPage *page;
PopplerDocument *doc;
double dw, dh;
int w, h, size = 0;
char *data = NULL;
unsigned char* surface = NULL;
SANE_Status status = SANE_STATUS_GOOD;
data = (char*)set_file_in_buffer(scanner->tmp, &size);
if (!data) {
DBG(1, "Error : poppler_document_new_from_data");
status = SANE_STATUS_INVAL;
goto close_file;
}
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;
}
page = poppler_document_get_page (doc, 0);
if (!page) {
DBG(1, "Error : poppler_document_get_page");
status = SANE_STATUS_INVAL;
goto free_doc;
}
poppler_page_get_size (page, &dw, &dh);
dw = (double)scanner->default_resolution * dw / 72.0;
dh = (double)scanner->default_resolution * dh / 72.0;
w = (int)ceil(dw);
h = (int)ceil(dh);
cairo_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w, h);
if (!cairo_surface) {
DBG(1, "Error : cairo_image_surface_create");
status = SANE_STATUS_INVAL;
goto free_page;
}
cr = cairo_create (cairo_surface);
if (!cairo_surface) {
DBG(1, "Error : cairo_create");
status = SANE_STATUS_INVAL;
goto free_surface;
}
cairo_scale (cr, (double)scanner->default_resolution / 72.0,
(double)scanner->default_resolution / 72.0);
cairo_save (cr);
poppler_page_render (page, cr);
cairo_restore (cr);
cairo_set_operator (cr, CAIRO_OPERATOR_DEST_OVER);
cairo_set_source_rgb (cr, 1, 1, 1);
cairo_paint (cr);
int st = cairo_status(cr);
if (st)
{
DBG(1, "%s", cairo_status_to_string (st));
status = SANE_STATUS_INVAL;
goto destroy_cr;
}
*bps = 3;
DBG(1, "Escl Pdf : Image Size [%dx%d]\n", w, h);
surface = cairo_surface_to_pixels (cairo_surface, *bps);
if (!surface) {
status = SANE_STATUS_NO_MEM;
DBG(1, "Escl Pdf : Surface Memory allocation problem");
goto destroy_cr;
}
// If necessary, trim the image.
surface = escl_crop_surface(scanner, surface, w, h, *bps, width, height);
if (!surface) {
DBG(1, "Escl Pdf Crop: Surface Memory allocation problem");
status = SANE_STATUS_NO_MEM;
}
destroy_cr:
cairo_destroy (cr);
free_surface:
cairo_surface_destroy (cairo_surface);
free_page:
g_object_unref (page);
free_doc:
g_object_unref (doc);
free_file:
free(data);
close_file:
if (scanner->tmp)
fclose(scanner->tmp);
scanner->tmp = NULL;
return status;
}
#else
SANE_Status
get_PDF_data(capabilities_t __sane_unused__ *scanner,
int __sane_unused__ *width,
int __sane_unused__ *height,
int __sane_unused__ *bps)
{
return (SANE_STATUS_INVAL);
}
#endif

Wyświetl plik

@ -453,6 +453,28 @@ AS_IF([test xno != "x$with_libcurl"],
])
AM_CONDITIONAL([have_libcurl], [test x != "x$libcurl_LIBS"])
dnl ******************************************************************
dnl Check for poppler-glib availability
dnl ******************************************************************
AC_ARG_WITH(poppler-glib,
AS_HELP_STRING([--with-poppler-glib],
[enable functionality that needs poppler-glib @<:@default=check@:>@]),
[],
[with_poppler_glib=check])
AC_DEFINE(HAVE_POPPLER_GLIB,
[0], [Define to 1 if libpoppler-glib is available])
AS_IF([test xno != "x$with_poppler_glib"],
[PKG_CHECK_MODULES(POPPLER_GLIB, [poppler-glib],
[AC_DEFINE([HAVE_POPPLER_GLIB], [1])
with_poppler_glib=yes
],
[AS_IF([test xcheck != "x$with_poppler_glib"],
[AC_MSG_ERROR([poppler-glib requested but not found])])
with_poppler_glib=no
])
])
AM_CONDITIONAL([have_poppler_glib], [test x != "x$POPPLER_GLIB_LIBS"])
dnl ******************************************************************
dnl Check for USB record/replay support
dnl ******************************************************************
@ -819,6 +841,7 @@ fi
echo "IPv6 support: `eval eval echo ${ipv6}`"
echo "Avahi support: `eval eval echo ${enable_avahi}`"
echo "cURL support: `eval eval echo ${with_libcurl}`"
echo "POPPLER_GLIB support: `eval eval echo ${with_poppler_glib}`"
echo "SNMP support: `eval eval echo ${with_snmp}`"
echo "-> The following backends will be built:"
for backend in ${BACKENDS} ; do