From ffa8801644a7d53cc1c785e3450f794c07a14eb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sun, 2 Feb 2020 17:13:01 +0100 Subject: New upstream version 1.0.29 --- backend/escl/escl_tiff.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 backend/escl/escl_tiff.c (limited to 'backend/escl/escl_tiff.c') diff --git a/backend/escl/escl_tiff.c b/backend/escl/escl_tiff.c new file mode 100644 index 0000000..52aec20 --- /dev/null +++ b/backend/escl/escl_tiff.c @@ -0,0 +1,119 @@ +/* sane - Scanner Access Now Easy. + + Copyright (C) 2019 Touboul Nathane + Copyright (C) 2019 Thierry HUCHARD + + 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 +#include +#include +#include + +#if(defined HAVE_TIFFIO_H) +#include +#endif + +#include + + +#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) { + DBG( 1, "Escl Tiff : Can not open, or not a TIFF file.\n"); + if (scanner->tmp) { + fclose(scanner->tmp); + scanner->tmp = NULL; + } + 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) + { + DBG( 1, "Escl Tiff : Memory allocation problem.\n"); + if (scanner->tmp) { + fclose(scanner->tmp); + scanner->tmp = NULL; + } + return (SANE_STATUS_INVAL); + } + + if (!TIFFReadRGBAImage(tif, width, height, (uint32 *)raster, 0)) + { + DBG( 1, "Escl Tiff : Problem reading image data.\n"); + if (scanner->tmp) { + fclose(scanner->tmp); + scanner->tmp = NULL; + } + 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 -- cgit v1.2.3