summaryrefslogtreecommitdiff
path: root/backend/escl/escl_tiff.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2020-09-10 19:11:27 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2020-09-10 19:11:27 +0200
commit7e9455b3b15671ff99ed168638c405e2acedb6df (patch)
tree444e59ece236e09dc153f665e42160aeb0208c24 /backend/escl/escl_tiff.c
parentbc8a517abd2e11e1435f4ef042cfcc8648b62ef7 (diff)
parentbce41b3c37c2a68e7dab234ce0247755a61ceb40 (diff)
Merge branch 'release/debian/1.0.31-1_experimental1' into masterdebian/1.0.31-1_experimental1
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