File: simage_tiff.c

package info (click to toggle)
simage 1.7.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,908 kB
  • sloc: ansic: 14,231; sh: 12,587; cpp: 930; perl: 854; makefile: 617; lisp: 25
file content (667 lines) | stat: -rw-r--r-- 16,714 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
/*
 * based on example code found in libtiff
 * 
 */

#include <config.h>
#ifdef HAVE_TIFFLIB

#include <simage_tiff.h>
#include <stdio.h>

#include <tiffio.h>

#include <string.h>
#include <stdarg.h>
#include <stdlib.h>

#define ERR_NO_ERROR    0
#define ERR_OPEN        1
#define ERR_READ        2
#define ERR_MEM         3
#define ERR_UNSUPPORTED 4
#define ERR_TIFFLIB     5
#define ERR_OPEN_WRITE  6
#define ERR_WRITE       7

static int tifferror = ERR_NO_ERROR;

int
simage_tiff_error(char * buffer, int buflen)
{
  switch (tifferror) {
  case ERR_OPEN:
    strncpy(buffer, "TIFF loader: Error opening file", buflen);
    break;
  case ERR_MEM:
    strncpy(buffer, "TIFF loader: Out of memory error", buflen);
    break;
  case ERR_UNSUPPORTED:
    strncpy(buffer, "TIFF loader: Unsupported image type", buflen);
    break;    
  case ERR_TIFFLIB:
    strncpy(buffer, "TIFF loader: Illegal tiff file", buflen);
    break;
  case ERR_OPEN_WRITE:
    strncpy(buffer, "TIFF saver: Error opening file", buflen);
    break;
  case ERR_WRITE:
    strncpy(buffer, "TIFF loader: Error writing file", buflen);
    break;
  }
  return tifferror;
}


static void 
tiff_error(const char* module, const char* fmt, va_list list)
{
  /* FIXME: store error message ? */
}

static void 
tiff_warn(const char * module, const char * fmt, va_list list)
{
  /* FIXME: notify? */
}

static int
checkcmap(int n, uint16* r, uint16* g, uint16* b)
{
  while (n-- > 0)
    if (*r++ >= 256 || *g++ >= 256 || *b++ >= 256)
      return (16);
  /* Assuming 8-bit colormap */
  return (8);
}

static void 
invert_row(unsigned char *ptr, unsigned char *data, int n, int invert)
{
  while (n--) {
    if (invert) *ptr++ = 255 - *data++;
    else *ptr++ = *data++;
  }
}


static void 
remap_row(unsigned char *ptr, unsigned char *data, int n,
	  unsigned short *rmap, unsigned short *gmap, unsigned short *bmap,unsigned char *amap)
{
  unsigned int ix;
  while (n--) {
    ix = *data++;
    *ptr++ = (unsigned char) rmap[ix];
    *ptr++ = (unsigned char) gmap[ix];
    *ptr++ = (unsigned char) bmap[ix];
    if (amap) *ptr++ = (unsigned char) amap[ix];
  }
}

static void 
copy_row(unsigned char *ptr, unsigned char *data, int n, int numcomponents)
{
  memcpy(ptr, data, n*numcomponents);
}

static void 
interleave_row(unsigned char *ptr,
	       unsigned char *red, 
               unsigned char *blue, 
               unsigned char *green,
               unsigned char *alpha,
	       int n)
{
  while (n--) {
    *ptr++ = *red++;
    *ptr++ = *green++;
    *ptr++ = *blue++;
    if (alpha) *ptr++ = *alpha++;
  }
}

static int
tiff_try_read_rgba(TIFF *in, int w, int h, int format, 
                      unsigned char * buffer)
{
  unsigned char * newbuffer = NULL;
  if (format != 4) {
    newbuffer = (unsigned char*) malloc(w*h*4);
  }
  else {
    newbuffer = buffer;
  }
  if (!TIFFReadRGBAImage(in, w, h, 
                         (unsigned int*) newbuffer, 1)) {
    free(newbuffer);
    return ERR_READ;
  }
  if (format != 4) {
    unsigned char * src = newbuffer;
    unsigned char * dst = buffer;
    int i, n = w*h;
    for (i = 0; i < n; i++) {
      switch (format) {
      case 1:
        *dst++ = src[0];
        break;
      case 2:
        *dst++ = src[0];
        *dst++ = src[3];
        break;
      case 3:
        *dst++ = src[0];
        *dst++ = src[1];
        *dst++ = src[2];
        break;
      default:
        break;

      }
      src += 4;
    }
    free(newbuffer);
  }

  return ERR_NO_ERROR;
}


int 
simage_tiff_identify(const char *ptr,
		     const unsigned char *header,
		     int headerlen)
{
  static unsigned char tifcmp[] = {0x4d, 0x4d, 0x0, 0x2a};
  static unsigned char tifcmp2[] = {0x49, 0x49, 0x2a, 0}; 
  
  if (headerlen < 4) return 0;
  if (memcmp((const void*)header, (const void*)tifcmp, 4) == 0) return 1;
  if (memcmp((const void*)header, (const void*)tifcmp2, 4) == 0) return 1;
  return 0;
}

/* useful defines (undef'ed below) */
#define	CVT(x)		(((x) * 255L) / ((1L<<16)-1))
#define	pack(a,b)	((a)<<8 | (b))

unsigned char *
simage_tiff_load(const char *filename,
		  int *width_ret,
		  int *height_ret,
		  int *numComponents_ret)
{
  TIFF *in;
  uint16 samplesperpixel;
  uint16 bitspersample;
  uint16 photometric;
  uint32 w, h;
  uint16 config;
  uint16* red;
  uint16* green;
  uint16* blue;
  unsigned char *inbuf = NULL;
  tsize_t rowsize;
  uint32 row;
  int format;
  unsigned char *buffer;
  int width;
  int height;
  unsigned char *currPtr;


  TIFFSetErrorHandler(tiff_error);
  TIFFSetWarningHandler(tiff_warn);
  
  in = TIFFOpen(filename, "r");
  if (in == NULL) {
    tifferror = ERR_OPEN;
    return NULL;
  }  
  if (TIFFGetField(in, TIFFTAG_PHOTOMETRIC, &photometric) == 1) {
    if (photometric != PHOTOMETRIC_RGB && photometric != PHOTOMETRIC_PALETTE &&
	photometric != PHOTOMETRIC_MINISWHITE && 
	photometric != PHOTOMETRIC_MINISBLACK) {
      /*Bad photometric; can only handle Grayscale, RGB and Palette images :-( */
      TIFFClose(in);
      tifferror = ERR_UNSUPPORTED;
      return NULL;
    }
  }
  else {
    tifferror = ERR_READ;
    TIFFClose(in);
    return NULL;
  }
  
  if (TIFFGetField(in, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel) == 1) {
    if (samplesperpixel < 1 || samplesperpixel > 4) {
      /* Bad samples/pixel */
      tifferror = ERR_UNSUPPORTED;
      TIFFClose(in);
      return NULL;
    }
  }
  else {
    tifferror = ERR_READ;
    TIFFClose(in);
    return NULL;
  }
	
  if (TIFFGetField(in, TIFFTAG_BITSPERSAMPLE, &bitspersample) == 1) {
    if (bitspersample != 8) {
      /* can only handle 8-bit samples. */
      TIFFClose(in);
      tifferror = ERR_UNSUPPORTED;
      return NULL;
    }
  }
  else {
    tifferror = ERR_READ;
    TIFFClose(in);
    return NULL;
  }

  if (TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &w) != 1 ||
      TIFFGetField(in, TIFFTAG_IMAGELENGTH, &h) != 1 ||
      TIFFGetField(in, TIFFTAG_PLANARCONFIG, &config) != 1) {
    TIFFClose(in);
    tifferror = ERR_READ;
    return NULL;
  }
  
  if (photometric == PHOTOMETRIC_MINISWHITE || 
      photometric == PHOTOMETRIC_MINISBLACK)
    format = 1;
  else {
    if (photometric == PHOTOMETRIC_PALETTE) format = 3;
    else format = samplesperpixel;
  }
  buffer = (unsigned char*)malloc(w*h*format);
  
  if (!buffer) {
    tifferror = ERR_MEM;
    TIFFClose(in);
    return NULL;
  }

  width = w;
  height = h;
  
  currPtr = buffer + (h-1)*w*format;
  
  tifferror = ERR_NO_ERROR;

  switch (pack(photometric, config)) {
  case pack(PHOTOMETRIC_MINISWHITE, PLANARCONFIG_CONTIG):
  case pack(PHOTOMETRIC_MINISBLACK, PLANARCONFIG_CONTIG):
  case pack(PHOTOMETRIC_MINISWHITE, PLANARCONFIG_SEPARATE):
  case pack(PHOTOMETRIC_MINISBLACK, PLANARCONFIG_SEPARATE):

    inbuf = (unsigned char *)malloc(TIFFScanlineSize(in));
    for (row = 0; row < h; row++) {
      if (TIFFReadScanline(in, inbuf, row, 0) < 0) {
	tifferror = ERR_READ;
	break;
      }
      invert_row(currPtr, inbuf, w, photometric == PHOTOMETRIC_MINISWHITE);  
      currPtr -= format*w;
    }
    if (tifferror == ERR_READ) {
      tifferror = tiff_try_read_rgba(in, w, h, format, buffer);
    }

    break;
    
  case pack(PHOTOMETRIC_PALETTE, PLANARCONFIG_CONTIG):
  case pack(PHOTOMETRIC_PALETTE, PLANARCONFIG_SEPARATE):
    if (TIFFGetField(in, TIFFTAG_COLORMAP, &red, &green, &blue) != 1)
      tifferror = ERR_READ;
    /* */
    /* Convert 16-bit colormap to 8-bit (unless it looks */
    /* like an old-style 8-bit colormap). */
    /* */
    if (!tifferror && checkcmap(1<<bitspersample, red, green, blue) == 16) {
      int i;
      for (i = (1<<bitspersample)-1; i >= 0; i--) {
	red[i] = CVT(red[i]);
	green[i] = CVT(green[i]);
	blue[i] = CVT(blue[i]);
      }
    }

    inbuf = (unsigned char *)malloc(TIFFScanlineSize(in));
    for (row = 0; row < h; row++) {
      if (TIFFReadScanline(in, inbuf, row, 0) < 0) {
	tifferror = ERR_READ;
	break;
      }
      remap_row(currPtr, inbuf, w, red, green, blue, NULL);
      currPtr -= format*w;
    }
    if (tifferror == ERR_READ) {
      tifferror = tiff_try_read_rgba(in, w, h, format, buffer);
    }

    break;

  case pack(PHOTOMETRIC_RGB, PLANARCONFIG_CONTIG):
    inbuf = (unsigned char *)malloc(TIFFScanlineSize(in));
    for (row = 0; row < h; row++) {
      if (TIFFReadScanline(in, inbuf, row, 0) < 0) {
	tifferror = ERR_READ;
	break;
      }
      copy_row(currPtr, inbuf, w, format);  
      currPtr -= format*w;
    }
    if (tifferror == ERR_READ) {
      tifferror = tiff_try_read_rgba(in, w, h, format, buffer);
    }
    
    break;

  case pack(PHOTOMETRIC_RGB, PLANARCONFIG_SEPARATE):
    rowsize = TIFFScanlineSize(in);
    inbuf = (unsigned char *)malloc(format*rowsize);
    for (row = 0; !tifferror && row < h; row++) {
      int s;
      for (s = 0; s < format; s++) {
	if (TIFFReadScanline(in, (tdata_t)(inbuf+s*rowsize), (uint32)row, (tsample_t)s) < 0) {
	  tifferror = ERR_READ; break;
	}
      }
      if (tifferror != ERR_READ) {
	interleave_row(currPtr, inbuf, inbuf+rowsize, inbuf+2*rowsize, 
                       format == 4 ? inbuf+3*rowsize : NULL, w);
	currPtr -= format*w;
      }
    }
    if (tifferror == ERR_READ) {
      tifferror = tiff_try_read_rgba(in, w, h, format, buffer);
    }

    break;
  default:
    tifferror = ERR_UNSUPPORTED;
    break;
  }
  
  if (inbuf) free(inbuf);
  TIFFClose(in);
  
  if (tifferror) {
    if (buffer) free(buffer);
    return NULL;
  }
  *width_ret = width;
  *height_ret = height;
  *numComponents_ret = format;
  return buffer;
}

int 
simage_tiff_save(const char *filename,
                 const unsigned char * bytes,
                 int width,
                 int height,
                 int numcomponents)
{
  uint16 photometric;
  TIFF * out;
  int y, bytesperrow;
  short config = PLANARCONFIG_CONTIG;
  int16 compression = COMPRESSION_PACKBITS; /* RLE */

  out = TIFFOpen(filename, "w");
  if (out == NULL) {
    tifferror = ERR_OPEN_WRITE;
    return 0;
  }

  TIFFSetField(out, TIFFTAG_IMAGEWIDTH, (uint32) width);
  TIFFSetField(out, TIFFTAG_IMAGELENGTH, (uint32) height);
  TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 8);
  TIFFSetField(out, TIFFTAG_COMPRESSION, compression);
  if (numcomponents <= 2)
    photometric = PHOTOMETRIC_MINISBLACK;
  else
    photometric = PHOTOMETRIC_RGB;
  TIFFSetField(out, TIFFTAG_PHOTOMETRIC, photometric);

  TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
  TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, numcomponents);
  if (numcomponents == 2 || numcomponents == 4) {
    uint16 v[1];
    v[0] = EXTRASAMPLE_UNASSALPHA;
    TIFFSetField(out, TIFFTAG_EXTRASAMPLES, 1, v);
  }
  TIFFSetField(out, TIFFTAG_MINSAMPLEVALUE, (uint16) 0);
  TIFFSetField(out, TIFFTAG_MAXSAMPLEVALUE, (uint16) 255);
  TIFFSetField(out, TIFFTAG_PLANARCONFIG, config);
  /* force 1 row/strip for library limitation */
  TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, 1L);
  TIFFSetField(out, TIFFTAG_IMAGEDESCRIPTION, filename);
  
  bytesperrow = width * numcomponents;

  for (y = 0; y < height; y++) {
    if (TIFFWriteScanline(out, (tdata_t) (bytes + bytesperrow * (height-y-1)), y, 0) < 0) {
      TIFFClose(out);
      tifferror = ERR_WRITE;
      return 0;
    }
  }

  TIFFClose(out);
  return 1;
}

typedef struct {
  TIFF * in;
  uint16 samplesperpixel;
  uint16 bitspersample;
  uint16 photometric;
  uint32 w, h;
  uint16 config;
  uint16 * red;
  uint16 * green;
  uint16 * blue;
  int format;
  int rowsize;
  unsigned char * inbuf;
} simage_tiff_opendata;

void * 
simage_tiff_open(const char * filename,
                 int * width,
                 int * height,
                 int * numcomponents)
{
  TIFF * in;
  simage_tiff_opendata * od;

  tifferror = ERR_NO_ERROR;

  TIFFSetErrorHandler(tiff_error);
  TIFFSetWarningHandler(tiff_warn);

  in = TIFFOpen(filename, "r");
  if (in == NULL) {
    tifferror = ERR_OPEN;
    return NULL;
  }
  od = (simage_tiff_opendata*) malloc(sizeof(simage_tiff_opendata));
  od->in = in;

  /* random access of lines is not be supported for palette images */
  if (TIFFGetField(in, TIFFTAG_PHOTOMETRIC, &od->photometric) == 1) {
    if (od->photometric != PHOTOMETRIC_RGB && 
        /* od->photometric != PHOTOMETRIC_PALETTE && */
	od->photometric != PHOTOMETRIC_MINISWHITE && 
	od->photometric != PHOTOMETRIC_MINISBLACK) {
      /* Bad photometric; can only handle Grayscale and RGB images */
      TIFFClose(in);
      tifferror = ERR_UNSUPPORTED;
      free(od);
      return NULL;
    }
  }
  else {
    tifferror = ERR_READ;
    free(od);
    TIFFClose(in);
    return NULL;
  }
  
  if (TIFFGetField(in, TIFFTAG_SAMPLESPERPIXEL, &od->samplesperpixel) == 1) {
    if (od->samplesperpixel < 1 || od->samplesperpixel > 4) {
      /* Bad samples/pixel */
      tifferror = ERR_UNSUPPORTED;
      free(od);
      TIFFClose(in);
      return NULL;
    }
  }
  else {
    tifferror = ERR_READ;
    free(od);
    TIFFClose(in);
    return NULL;
  }
	
  if (TIFFGetField(in, TIFFTAG_BITSPERSAMPLE, &od->bitspersample) == 1) {
    if (od->bitspersample != 8) {
      /* can only handle 8-bit samples. */
      TIFFClose(in);
      tifferror = ERR_UNSUPPORTED;
      free(od);
      return NULL;
    }
  }
  else {
    tifferror = ERR_READ;
    TIFFClose(in);
    free(od);
    return NULL;
  }

  if (TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &od->w) != 1 ||
      TIFFGetField(in, TIFFTAG_IMAGELENGTH, &od->h) != 1 ||
      TIFFGetField(in, TIFFTAG_PLANARCONFIG, &od->config) != 1) {
    TIFFClose(in);
    tifferror = ERR_READ;
    free(od);
    return NULL;
  }
  
  if (od->photometric == PHOTOMETRIC_MINISWHITE || 
      od->photometric == PHOTOMETRIC_MINISBLACK)
    od->format = 1;
  else {
    if (od->photometric == PHOTOMETRIC_PALETTE) od->format = 3;
    else od->format = od->samplesperpixel;
  }
  switch (pack(od->photometric, od->config)) {
  default:
    break;
  case pack(PHOTOMETRIC_PALETTE, PLANARCONFIG_CONTIG):
  case pack(PHOTOMETRIC_PALETTE, PLANARCONFIG_SEPARATE):
    if (TIFFGetField(in, TIFFTAG_COLORMAP, &od->red, &od->green, &od->blue) != 1)
      tifferror = ERR_READ;
    /* */
    /* Convert 16-bit colormap to 8-bit (unless it looks */
    /* like an old-style 8-bit colormap). */
    /* */
    if (!tifferror && checkcmap(1<<od->bitspersample, od->red, od->green, od->blue) == 16) {
      int i;
      for (i = (1<<od->bitspersample)-1; i >= 0; i--) {
	od->red[i] = CVT(od->red[i]);
	od->green[i] = CVT(od->green[i]);
	od->blue[i] = CVT(od->blue[i]);
      }
    }    
  }
  od->rowsize = TIFFScanlineSize(in);
  od->inbuf = (unsigned char *) malloc(od->rowsize * 4); /* *4 to support all formats */

  *width = od->w;
  *height = od->h;
  *numcomponents = od->format;

  return (void*) od;
}


void 
simage_tiff_close(void * opendata)
{
  simage_tiff_opendata * od = (simage_tiff_opendata*) opendata;
  TIFFClose(od->in);
  free(od->inbuf);
  free(od);
}

int 
simage_tiff_read_line(void * opendata, int y, unsigned char * buf)
{
  int s, row;
  simage_tiff_opendata * od;
  tifferror = ERR_NO_ERROR;
  
  od = (simage_tiff_opendata*) opendata;
  row = (od->h-1)-y;
  
  switch (pack(od->photometric, od->config)) {
  case pack(PHOTOMETRIC_MINISWHITE, PLANARCONFIG_CONTIG):
  case pack(PHOTOMETRIC_MINISBLACK, PLANARCONFIG_CONTIG):
  case pack(PHOTOMETRIC_MINISWHITE, PLANARCONFIG_SEPARATE):
  case pack(PHOTOMETRIC_MINISBLACK, PLANARCONFIG_SEPARATE):
    if (TIFFReadScanline(od->in, od->inbuf, row, 0) < 0) {
      tifferror = ERR_READ;
      break;
    }
    invert_row(buf, od->inbuf, od->w, od->photometric == PHOTOMETRIC_MINISWHITE);  
    break;

  case pack(PHOTOMETRIC_PALETTE, PLANARCONFIG_CONTIG):
  case pack(PHOTOMETRIC_PALETTE, PLANARCONFIG_SEPARATE):
    if (TIFFReadScanline(od->in, od->inbuf, row, 0) < 0) {
      tifferror = ERR_READ;
      break;
    }
    remap_row(buf, od->inbuf, od->w, od->red, od->green, od->blue, NULL);
    break;

  case pack(PHOTOMETRIC_RGB, PLANARCONFIG_CONTIG):
    if (TIFFReadScanline(od->in, od->inbuf, row, 0) < 0) {
      tifferror = ERR_READ;
      break;
    }
    copy_row(buf, od->inbuf, od->w, od->format);  
    break;

  case pack(PHOTOMETRIC_RGB, PLANARCONFIG_SEPARATE):
    for (s = 0; s < od->format; s++) {
      if (TIFFReadScanline(od->in, (tdata_t)(od->inbuf+s*od->rowsize), 
                           (uint32)row, (tsample_t)s) < 0) {      
        tifferror = ERR_READ; break;
      }
    }
    if (!tifferror) {
      interleave_row(buf, od->inbuf, od->inbuf+od->rowsize, od->inbuf + 2*od->rowsize, 
                     od->format == 4 ? od->inbuf + 3*od->rowsize: NULL, od->w);
    }
    break;
  default:
    tifferror = ERR_UNSUPPORTED;
    break;
  }
  return tifferror == ERR_NO_ERROR;
}

#undef CVT
#undef pack

#endif /* HAVE_TIFFLIB */