summaryrefslogtreecommitdiff
path: root/backend/escl/escl_tiff.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2020-08-24 18:44:51 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2020-08-24 18:44:51 +0200
commitad38bc6ecb80ddeb562841b33258dd53659b1da6 (patch)
treee02e9c3ff760554fd87f70df0e18b88594091a48 /backend/escl/escl_tiff.c
parent9c23ed018d72eed2554f4f9cff1ae6e6bb0cd479 (diff)
New upstream version 1.0.31upstream/1.0.31
Diffstat (limited to 'backend/escl/escl_tiff.c')
-rw-r--r--backend/escl/escl_tiff.c71
1 files changed, 35 insertions, 36 deletions
diff --git a/backend/escl/escl_tiff.c b/backend/escl/escl_tiff.c
index 52aec20..98bc5f3 100644
--- a/backend/escl/escl_tiff.c
+++ b/backend/escl/escl_tiff.c
@@ -50,60 +50,59 @@
* \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)
+get_TIFF_data(capabilities_t *scanner, int *width, int *height, int *bps)
{
TIFF* tif = NULL;
- uint32 width = 0; /* largeur */
- uint32 height = 0; /* hauteur */
- unsigned char *raster = NULL; /* données de l'image */
- int bps = 4;
+ uint32 w = 0;
+ uint32 h = 0;
+ unsigned char *surface = NULL; /* image data*/
+ int components = 4;
uint32 npixels = 0;
+ SANE_Status status = SANE_STATUS_GOOD;
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);
+ status = SANE_STATUS_INVAL;
+ goto close_file;
}
- TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width);
- TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height);
- npixels = width * height;
- raster = (unsigned char*) malloc(npixels * sizeof (uint32));
- if (raster != NULL)
+ TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
+ TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
+ npixels = w * h;
+ surface = (unsigned char*) malloc(npixels * sizeof (uint32));
+ if (surface != NULL)
{
- DBG( 1, "Escl Tiff : Memory allocation problem.\n");
- if (scanner->tmp) {
- fclose(scanner->tmp);
- scanner->tmp = NULL;
- }
- return (SANE_STATUS_INVAL);
+ DBG( 1, "Escl Tiff : raster Memory allocation problem.\n");
+ status = SANE_STATUS_INVAL;
+ goto close_tiff;
}
- if (!TIFFReadRGBAImage(tif, width, height, (uint32 *)raster, 0))
+ if (!TIFFReadRGBAImage(tif, w, h, (uint32 *)surface, 0))
{
DBG( 1, "Escl Tiff : Problem reading image data.\n");
- if (scanner->tmp) {
- fclose(scanner->tmp);
- scanner->tmp = NULL;
- }
- return (SANE_STATUS_INVAL);
+ status = SANE_STATUS_INVAL;
+ free(surface);
+ goto close_tiff;
}
- *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;
+
+ *bps = components;
+
+ // If necessary, trim the image.
+ surface = escl_crop_surface(scanner, surface, w, h, components, width, height);
+ if (!surface) {
+ DBG( 1, "Escl Tiff : Surface Memory allocation problem\n");
+ status = SANE_STATUS_INVAL;
+ }
+
+close_tiff:
TIFFClose(tif);
- fclose(scanner->tmp);
+close_file:
+ if (scanner->tmp)
+ fclose(scanner->tmp);
scanner->tmp = NULL;
- return (SANE_STATUS_GOOD);
+ return (status);
}
#else