summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim Woelders <kim@woelders.dk>2021-04-27 18:56:58 +0200
committerKim Woelders <kim@woelders.dk>2021-04-30 10:04:05 +0200
commit933fc2ab1fb5ca7fb88e0ae8c47b93364baaced3 (patch)
treee4a7bb93c7e68562c964320f5c12f638117838f9
parentc1ee164d6db491b0cd92986259ee76ef46fcb87c (diff)
TIFF loader: Drop use of libtiff defined types deprecated in libtiff-4.3.0HEADmaster
Switch to using C99 types, uint8 -> uint8_t, etc. now used by libtiff.
-rw-r--r--src/modules/loaders/loader_tiff.c80
1 files changed, 38 insertions, 42 deletions
diff --git a/src/modules/loaders/loader_tiff.c b/src/modules/loaders/loader_tiff.c
index 9411fe6..4d5d029 100644
--- a/src/modules/loaders/loader_tiff.c
+++ b/src/modules/loaders/loader_tiff.c
@@ -4,54 +4,28 @@
4#include "loader_common.h" 4#include "loader_common.h"
5#include <setjmp.h> 5#include <setjmp.h>
6#include <stdarg.h> 6#include <stdarg.h>
7#include <stdint.h>
7#include <tiffio.h> 8#include <tiffio.h>
8 9
9/* This is a wrapper data structure for TIFFRGBAImage, so that data can be */ 10/* This is a wrapper data structure for TIFFRGBAImage, so that data can be */
10/* passed into the callbacks. More elegent, I think, than a bunch of globals */ 11/* passed into the callbacks. More elegent, I think, than a bunch of globals */
11 12
12struct TIFFRGBAImage_Extra { 13typedef struct {
13 TIFFRGBAImage rgba; 14 TIFFRGBAImage rgba;
14 tileContigRoutine put_contig; 15 tileContigRoutine put_contig;
15 tileSeparateRoutine put_separate; 16 tileSeparateRoutine put_separate;
16 ImlibImage *image; 17 ImlibImage *image;
17}; 18} TIFFRGBAImage_Extra;
18
19typedef struct TIFFRGBAImage_Extra TIFFRGBAImage_Extra;
20
21static void raster(TIFFRGBAImage_Extra * img, uint32 * raster, uint32 x,
22 uint32 y, uint32 w, uint32 h);
23
24static void
25put_contig_and_raster(TIFFRGBAImage * img, uint32 * rast,
26 uint32 x, uint32 y, uint32 w, uint32 h,
27 int32 fromskew, int32 toskew, unsigned char *cp)
28{
29 (*(((TIFFRGBAImage_Extra *) img)->put_contig)) (img, rast, x, y, w, h,
30 fromskew, toskew, cp);
31 raster((TIFFRGBAImage_Extra *) img, rast, x, y, w, h);
32}
33
34static void
35put_separate_and_raster(TIFFRGBAImage * img, uint32 * rast,
36 uint32 x, uint32 y, uint32 w, uint32 h,
37 int32 fromskew, int32 toskew,
38 unsigned char *r, unsigned char *g, unsigned char *b,
39 unsigned char *a)
40{
41 (*(((TIFFRGBAImage_Extra *) img)->put_separate))
42 (img, rast, x, y, w, h, fromskew, toskew, r, g, b, a);
43 raster((TIFFRGBAImage_Extra *) img, rast, x, y, w, h);
44}
45 19
46#define PIM(_x, _y) buffer + ((_x) + image_width * (_y)) 20#define PIM(_x, _y) buffer + ((_x) + image_width * (_y))
47 21
48static void 22static void
49raster(TIFFRGBAImage_Extra * img, uint32 * rast, 23raster(TIFFRGBAImage_Extra * img, uint32_t * rast,
50 uint32 x, uint32 y, uint32 w, uint32 h) 24 uint32_t x, uint32_t y, uint32_t w, uint32_t h)
51{ 25{
52 uint32 image_width, image_height; 26 uint32_t image_width, image_height;
53 uint32 *pixel, pixel_value; 27 uint32_t *pixel, pixel_value;
54 uint32 i, j, k; 28 uint32_t i, j, k;
55 DATA32 *buffer_pixel, *buffer = img->image->data; 29 DATA32 *buffer_pixel, *buffer = img->image->data;
56 int alpha_premult; 30 int alpha_premult;
57 int a, r, g, b; 31 int a, r, g, b;
@@ -237,22 +211,44 @@ raster(TIFFRGBAImage_Extra * img, uint32 * rast,
237 } 211 }
238} 212}
239 213
214static void
215put_contig_and_raster(TIFFRGBAImage * img, uint32_t * rast,
216 uint32_t x, uint32_t y, uint32_t w, uint32_t h,
217 int32_t fromskew, int32_t toskew, unsigned char *cp)
218{
219 ((TIFFRGBAImage_Extra *) img)->put_contig(img, rast, x, y, w, h,
220 fromskew, toskew, cp);
221 raster((TIFFRGBAImage_Extra *) img, rast, x, y, w, h);
222}
223
224static void
225put_separate_and_raster(TIFFRGBAImage * img, uint32_t * rast,
226 uint32_t x, uint32_t y, uint32_t w, uint32_t h,
227 int32_t fromskew, int32_t toskew,
228 unsigned char *r, unsigned char *g, unsigned char *b,
229 unsigned char *a)
230{
231 ((TIFFRGBAImage_Extra *) img)->put_separate(img, rast, x, y, w, h,
232 fromskew, toskew, r, g, b, a);
233 raster((TIFFRGBAImage_Extra *) img, rast, x, y, w, h);
234}
235
240int 236int
241load2(ImlibImage * im, int load_data) 237load2(ImlibImage * im, int load_data)
242{ 238{
243 int rc; 239 int rc;
244 TIFF *tif = NULL; 240 TIFF *tif = NULL;
245 int fd; 241 int fd;
246 uint16 magic_number; 242 uint16_t magic_number;
247 TIFFRGBAImage_Extra rgba_image; 243 TIFFRGBAImage_Extra rgba_image;
248 uint32 *rast = NULL; 244 uint32_t *rast = NULL;
249 char txt[1024]; 245 char txt[1024];
250 246
251 rc = LOAD_FAIL; 247 rc = LOAD_FAIL;
252 rgba_image.image = NULL; 248 rgba_image.image = NULL;
253 249
254 fd = fileno(im->fp); 250 fd = fileno(im->fp);
255 if (read(fd, &magic_number, sizeof(uint16)) != sizeof(uint16)) 251 if (read(fd, &magic_number, sizeof(uint16_t)) != sizeof(uint16_t))
256 goto quit; 252 goto quit;
257 253
258 if ((magic_number != TIFF_BIGENDIAN) /* Checks if actually tiff file */ 254 if ((magic_number != TIFF_BIGENDIAN) /* Checks if actually tiff file */
@@ -322,7 +318,7 @@ load2(ImlibImage * im, int load_data)
322 if (!__imlib_AllocateData(im)) 318 if (!__imlib_AllocateData(im))
323 goto quit; 319 goto quit;
324 320
325 rast = (uint32 *) _TIFFmalloc(sizeof(uint32) * im->w * im->h); 321 rast = _TIFFmalloc(sizeof(uint32_t) * im->w * im->h);
326 if (!rast) 322 if (!rast)
327 { 323 {
328 fprintf(stderr, "imlib2-tiffloader: Out of memory\n"); 324 fprintf(stderr, "imlib2-tiffloader: Out of memory\n");
@@ -367,11 +363,11 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
367{ 363{
368 int rc; 364 int rc;
369 TIFF *tif = NULL; 365 TIFF *tif = NULL;
370 uint8 *buf = NULL; 366 uint8_t *buf = NULL;
371 DATA32 pixel, *data = im->data; 367 DATA32 pixel, *data = im->data;
372 double alpha_factor; 368 double alpha_factor;
373 int x, y; 369 int x, y;
374 uint8 r, g, b, a = 0; 370 uint8_t r, g, b, a = 0;
375 int has_alpha = IMAGE_HAS_ALPHA(im); 371 int has_alpha = IMAGE_HAS_ALPHA(im);
376 int i; 372 int i;
377 373
@@ -440,7 +436,7 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
440 436
441 if (has_alpha) 437 if (has_alpha)
442 { 438 {
443 uint16 extras[] = { EXTRASAMPLE_ASSOCALPHA }; 439 uint16_t extras[] = { EXTRASAMPLE_ASSOCALPHA };
444 TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 4); 440 TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 4);
445 TIFFSetField(tif, TIFFTAG_EXTRASAMPLES, 1, extras); 441 TIFFSetField(tif, TIFFTAG_EXTRASAMPLES, 1, extras);
446 } 442 }
@@ -451,7 +447,7 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
451 TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8); 447 TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
452 TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(tif, 0)); 448 TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(tif, 0));
453 449
454 buf = (uint8 *) _TIFFmalloc(TIFFScanlineSize(tif)); 450 buf = _TIFFmalloc(TIFFScanlineSize(tif));
455 if (!buf) 451 if (!buf)
456 goto quit; 452 goto quit;
457 453