kopia lustrzana https://gitlab.com/sane-project/backends
Addition of the TIFF decoder.
rodzic
a23dfbfff5
commit
65470e95aa
|
@ -437,13 +437,13 @@ 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
|
||||
libescl_la_CPPFLAGS = $(AM_CPPFLAGS) $(JPEG_CFLAGS) $(PNG_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
|
||||
libescl_la_CPPFLAGS = $(AM_CPPFLAGS) $(JPEG_CFLAGS) $(PNG_CFLAGS) $(TIFF_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) $(XML_CFLAGS) $(libcurl_CFLAGS) $(AVAHI_CFLAGS) -DBACKEND_NAME=escl
|
||||
libsane_escl_la_CPPFLAGS = $(AM_CPPFLAGS) $(JPEG_CFLAGS) $(PNG_CFLAGS) $(TIFF_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 $(JPEG_LIBS) $(PNG_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 $(JPEG_LIBS) $(PNG_LIBS) $(TIFF_LIBS) $(XML_LIBS) $(libcurl_LIBS) $(AVAHI_LIBS)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <png.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include "../include/sane/saneopts.h"
|
||||
|
@ -649,21 +648,23 @@ sane_start(SANE_Handle h)
|
|||
status = escl_scan(handler->scanner, handler->name, handler->result);
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
return (status);
|
||||
fprintf(stderr, "DIM : [%s]\n", handler->scanner->default_format);
|
||||
if (!strncmp(handler->scanner->default_format, "image/jpeg", 10))
|
||||
{
|
||||
status = get_JPEG_data(handler->scanner, &w, &he, &bps);
|
||||
fprintf(stderr, "JPEG DIM : [%s]\n", handler->scanner->default_format);
|
||||
}
|
||||
else
|
||||
else if (!strncmp(handler->scanner->default_format, "image/png", 9))
|
||||
{
|
||||
status = get_PNG_data(handler->scanner, &w, &he, &bps);
|
||||
fprintf(stderr, "PNG DIM : [%s]\n", handler->scanner->default_format);
|
||||
}
|
||||
else if (!strncmp(handler->scanner->default_format, "image/tiff", 10))
|
||||
{
|
||||
status = get_TIFF_data(handler->scanner, &w, &he, &bps);
|
||||
}
|
||||
else
|
||||
return SANE_STATUS_INVAL;
|
||||
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
return (status);
|
||||
fprintf(stderr, "SIZE [%dx%dx%d]\n", w, he, bps);
|
||||
fprintf(stderr, "2-SIZE [%dx%dx%d]\n", w, he, bps);
|
||||
handler->ps.depth = 8;
|
||||
handler->ps.pixels_per_line = w;
|
||||
handler->ps.lines = he;
|
||||
|
@ -697,9 +698,6 @@ sane_get_parameters(SANE_Handle h, SANE_Parameters *p)
|
|||
p->pixels_per_line = handler->ps.pixels_per_line;
|
||||
p->lines = handler->ps.lines;
|
||||
p->bytes_per_line = handler->ps.bytes_per_line;
|
||||
fprintf(stderr, "GET SIZE [%dx%dx%d]\n", p->pixels_per_line,
|
||||
p->lines,
|
||||
(p->bytes_per_line / p->pixels_per_line));
|
||||
}
|
||||
return (status);
|
||||
}
|
||||
|
@ -729,7 +727,6 @@ sane_read(SANE_Handle h, SANE_Byte *buf, SANE_Int maxlen, SANE_Int *len)
|
|||
if (!handler->write_scan_data)
|
||||
handler->write_scan_data = SANE_TRUE;
|
||||
if (!handler->decompress_scan_data) {
|
||||
fprintf(stderr, "READ : [%s]\n", handler->scanner->default_format);
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
return (status);
|
||||
handler->decompress_scan_data = SANE_TRUE;
|
||||
|
|
|
@ -46,6 +46,13 @@
|
|||
#warning "The escl backend recommends libpng"
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_TIFFIO_H
|
||||
/* FIXME: Make TIFF support optional.
|
||||
*/
|
||||
#warning "The escl backend recommends libtiff"
|
||||
#endif
|
||||
|
||||
|
||||
#include "../include/sane/sane.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -158,4 +165,7 @@ SANE_Status get_JPEG_data(capabilities_t *scanner, int *w, int *h, int *bps);
|
|||
// PNG
|
||||
SANE_Status get_PNG_data(capabilities_t *scanner, int *w, int *h, int *bps);
|
||||
|
||||
// TIFF
|
||||
SANE_Status get_TIFF_data(capabilities_t *scanner, int *w, int *h, int *bps);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -189,17 +189,21 @@ find_valor_of_array_variables(xmlNode *node, capabilities_t *scanner)
|
|||
if (scanner->default_format == NULL && !strncmp(scanner->DocumentFormats[i], "image/jpeg", 10))
|
||||
{
|
||||
scanner->default_format = strdup("image/jpeg");
|
||||
#if(defined HAVE_LIBPNG)
|
||||
}
|
||||
else if(!strncmp(scanner->DocumentFormats[i], "image/png", 9))
|
||||
#if(defined HAVE_LIBPNG)
|
||||
else if(!strncmp(scanner->DocumentFormats[i], "image/png", 9) && (scanner->default_format == NULL || strncmp(scanner->default_format, "image/tiff", 10)))
|
||||
{
|
||||
if (scanner->default_format)
|
||||
free(scanner->default_format);
|
||||
scanner->default_format = strdup("image/png");
|
||||
break;
|
||||
}
|
||||
#else
|
||||
break;
|
||||
#endif
|
||||
#if(defined HAVE_TIFFIO_H)
|
||||
else if(!strncmp(scanner->DocumentFormats[i], "image/tiff", 10))
|
||||
{
|
||||
if (scanner->default_format)
|
||||
free(scanner->default_format);
|
||||
scanner->default_format = strdup("image/png");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -68,6 +68,9 @@ static char formatExtJPEG[] =
|
|||
static char formatExtPNG[] =
|
||||
" <scan:DocumentFormatExt>image/png</scan:DocumentFormatExt>";
|
||||
|
||||
static char formatExtTIFF[] =
|
||||
" <scan:DocumentFormatExt>image/TIFF</scan:DocumentFormatExt>";
|
||||
|
||||
/**
|
||||
* \fn static size_t download_callback(void *str, size_t size, size_t nmemb, void *userp)
|
||||
* \brief Callback function that stocks in memory the content of the 'job'. Example below :
|
||||
|
@ -155,8 +158,12 @@ escl_newjob (capabilities_t *scanner, SANE_String_Const name, SANE_Status *statu
|
|||
{
|
||||
if (!strncmp(scanner->default_format, "image/jpeg", 10))
|
||||
format_ext = formatExtJPEG;
|
||||
else
|
||||
else if (!strncmp(scanner->default_format, "image/png", 9))
|
||||
format_ext = formatExtPNG;
|
||||
else if (!strncmp(scanner->default_format, "image/tiff", 10))
|
||||
format_ext = formatExtTIFF;
|
||||
else
|
||||
format_ext = f_ext;
|
||||
}
|
||||
else
|
||||
format_ext = f_ext;
|
||||
|
@ -164,7 +171,7 @@ escl_newjob (capabilities_t *scanner, SANE_String_Const name, SANE_Status *statu
|
|||
snprintf(cap_data, sizeof(cap_data), settings, scanner->height, scanner->width, 0, 0, scanner->default_format,
|
||||
format_ext,
|
||||
scanner->default_color, scanner->default_resolution, scanner->default_resolution);
|
||||
fprintf(stderr, "CAP_DATA = %s\n", cap_data);
|
||||
// fprintf(stderr, "CAP_DATA = %s\n", cap_data);
|
||||
upload->read_data = strdup(cap_data);
|
||||
upload->size = strlen(cap_data);
|
||||
download->memory = malloc(1);
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
#include "escl.h"
|
||||
|
||||
#include "../include/sane/sanei.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if(defined HAVE_TIFFIO_H)
|
||||
#include <tiffio.h>
|
||||
#endif
|
||||
|
||||
#include <setjmp.h>
|
||||
|
||||
|
||||
#if(defined HAVE_TIFFIO_H)
|
||||
|
||||
/**
|
||||
* \fn SANE_Status escl_sane_decompressor(escl_sane_t *handler)
|
||||
* \brief Function that aims to decompress the png 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_TIFF_data(capabilities_t *scanner, int *w, int *h, int *components)
|
||||
{
|
||||
TIFF* tif = NULL;
|
||||
uint32 width = 0; /* largeur */
|
||||
uint32 height = 0; /* hauteur */
|
||||
unsigned char *raster = NULL; /* données de l'image */
|
||||
int bps = 4;
|
||||
uint32 npixels = 0;
|
||||
|
||||
lseek(fileno(scanner->tmp), 0, SEEK_SET);
|
||||
tif = TIFFFdOpen(fileno(scanner->tmp), "temp", "r");
|
||||
if (!tif) {
|
||||
fprintf(stderr, "Can not open, or not a TIFF file.\n");
|
||||
return (SANE_STATUS_INVAL);
|
||||
}
|
||||
|
||||
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width);
|
||||
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height);
|
||||
npixels = width * height;
|
||||
raster = (unsigned char*) malloc(npixels * sizeof (uint32));
|
||||
if (raster != NULL)
|
||||
{
|
||||
fprintf(stderr, "Memory allocation problem.\n");
|
||||
return (SANE_STATUS_INVAL);
|
||||
}
|
||||
|
||||
if (!TIFFReadRGBAImage(tif, width, height, (uint32 *)raster, 0))
|
||||
{
|
||||
fprintf(stderr, "Problem reading image data.\n");
|
||||
return (SANE_STATUS_INVAL);
|
||||
}
|
||||
*w = (int)width;
|
||||
*h = (int)height;
|
||||
*components = bps;
|
||||
// we don't need row pointers anymore
|
||||
scanner->img_data = raster;
|
||||
scanner->img_size = (int)(width * height * bps);
|
||||
scanner->img_read = 0;
|
||||
TIFFClose(tif);
|
||||
fclose(scanner->tmp);
|
||||
scanner->tmp = NULL;
|
||||
return (SANE_STATUS_GOOD);
|
||||
}
|
||||
#else
|
||||
|
||||
SANE_Status
|
||||
get_TIFF_data(capabilities_t __sane_unused__ *scanner,
|
||||
int __sane_unused__ *w,
|
||||
int __sane_unused__ *h,
|
||||
int __sane_unused__ *bps)
|
||||
{
|
||||
return (SANE_STATUS_INVAL);
|
||||
}
|
||||
|
||||
#endif
|
Ładowanie…
Reference in New Issue