fa24aa835b5d2eaf9c1db6ca58d4793cec9ddf42
1 /* $Id: tif_read.c,v 1.59 2017-05-13 15:34:06 erouault Exp $ */
4 * Copyright (c) 1988-1997 Sam Leffler
5 * Copyright (c) 1991-1997 Silicon Graphics, Inc.
7 * Permission to use, copy, modify, distribute, and sell this software and
8 * its documentation for any purpose is hereby granted without fee, provided
9 * that (i) the above copyright notices and this permission notice appear in
10 * all copies of the software and related documentation, and (ii) the names of
11 * Sam Leffler and Silicon Graphics may not be used in any advertising or
12 * publicity relating to the software without the specific, prior written
13 * permission of Sam Leffler and Silicon Graphics.
15 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
17 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
19 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
20 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
21 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
22 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
23 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
29 * Scanline-oriented Read Support
35 #define TIFF_SIZE_T_MAX ((size_t) ~ ((size_t)0))
36 #define TIFF_TMSIZE_T_MAX (tmsize_t)(TIFF_SIZE_T_MAX >> 1)
38 int TIFFFillStrip(TIFF
* tif
, uint32 strip
);
39 int TIFFFillTile(TIFF
* tif
, uint32 tile
);
40 static int TIFFStartStrip(TIFF
* tif
, uint32 strip
);
41 static int TIFFStartTile(TIFF
* tif
, uint32 tile
);
42 static int TIFFCheckRead(TIFF
*, int);
44 TIFFReadRawStrip1(TIFF
* tif
, uint32 strip
, void* buf
, tmsize_t size
,const char* module
);
46 TIFFReadRawTile1(TIFF
* tif
, uint32 tile
, void* buf
, tmsize_t size
, const char* module
);
48 #define NOSTRIP ((uint32)(-1)) /* undefined state */
49 #define NOTILE ((uint32)(-1)) /* undefined state */
51 #define INITIAL_THRESHOLD (1024 * 1024)
52 #define THRESHOLD_MULTIPLIER 10
53 #define MAX_THRESHOLD (THRESHOLD_MULTIPLIER * THRESHOLD_MULTIPLIER * THRESHOLD_MULTIPLIER * INITIAL_THRESHOLD)
55 /* Read 'size' bytes in tif_rawdata buffer starting at offset 'rawdata_offset'
56 * Returns 1 in case of success, 0 otherwise. */
57 static int TIFFReadAndRealloc( TIFF
* tif
, tmsize_t size
,
58 tmsize_t rawdata_offset
,
59 int is_strip
, uint32 strip_or_tile
,
62 #if SIZEOF_VOIDP == 8 || SIZEOF_SIZE_T == 8
63 tmsize_t threshold
= INITIAL_THRESHOLD
;
65 tmsize_t already_read
= 0;
67 /* On 64 bit processes, read first a maximum of 1 MB, then 10 MB, etc */
68 /* so as to avoid allocating too much memory in case the file is too */
69 /* short. We could ask for the file size, but this might be */
70 /* expensive with some I/O layers (think of reading a gzipped file) */
71 /* Restrict to 64 bit processes, so as to avoid reallocs() */
72 /* on 32 bit processes where virtual memory is scarce. */
73 while( already_read
< size
)
76 tmsize_t to_read
= size
- already_read
;
77 #if SIZEOF_VOIDP == 8 || SIZEOF_SIZE_T == 8
78 if( to_read
>= threshold
&& threshold
< MAX_THRESHOLD
&&
79 already_read
+ to_read
+ rawdata_offset
> tif
->tif_rawdatasize
)
82 threshold
*= THRESHOLD_MULTIPLIER
;
85 if (already_read
+ to_read
+ rawdata_offset
> tif
->tif_rawdatasize
) {
87 assert((tif
->tif_flags
& TIFF_MYBUFFER
) != 0);
88 tif
->tif_rawdatasize
= (tmsize_t
)TIFFroundup_64(
89 (uint64
)already_read
+ to_read
+ rawdata_offset
, 1024);
90 if (tif
->tif_rawdatasize
==0) {
91 TIFFErrorExt(tif
->tif_clientdata
, module
,
92 "Invalid buffer size");
95 new_rawdata
= (uint8
*) _TIFFrealloc(
96 tif
->tif_rawdata
, tif
->tif_rawdatasize
);
97 if( new_rawdata
== 0 )
99 TIFFErrorExt(tif
->tif_clientdata
, module
,
100 "No space for data buffer at scanline %lu",
101 (unsigned long) tif
->tif_row
);
102 _TIFFfree(tif
->tif_rawdata
);
103 tif
->tif_rawdata
= 0;
104 tif
->tif_rawdatasize
= 0;
107 tif
->tif_rawdata
= new_rawdata
;
110 bytes_read
= TIFFReadFile(tif
,
111 tif
->tif_rawdata
+ rawdata_offset
+ already_read
, to_read
);
112 already_read
+= bytes_read
;
113 if (bytes_read
!= to_read
) {
114 memset( tif
->tif_rawdata
+ rawdata_offset
+ already_read
, 0,
115 tif
->tif_rawdatasize
- rawdata_offset
- already_read
);
116 #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
119 TIFFErrorExt(tif
->tif_clientdata
, module
,
120 "Read error at scanline %lu; got %I64u bytes, "
122 (unsigned long) tif
->tif_row
,
123 (unsigned __int64
) already_read
,
124 (unsigned __int64
) size
);
128 TIFFErrorExt(tif
->tif_clientdata
, module
,
129 "Read error at row %lu, col %lu, tile %lu; "
130 "got %I64u bytes, expected %I64u",
131 (unsigned long) tif
->tif_row
,
132 (unsigned long) tif
->tif_col
,
133 (unsigned long) strip_or_tile
,
134 (unsigned __int64
) already_read
,
135 (unsigned __int64
) size
);
140 TIFFErrorExt(tif
->tif_clientdata
, module
,
141 "Read error at scanline %lu; got %llu bytes, "
143 (unsigned long) tif
->tif_row
,
144 (unsigned long long) already_read
,
145 (unsigned long long) size
);
149 TIFFErrorExt(tif
->tif_clientdata
, module
,
150 "Read error at row %lu, col %lu, tile %lu; "
151 "got %llu bytes, expected %llu",
152 (unsigned long) tif
->tif_row
,
153 (unsigned long) tif
->tif_col
,
154 (unsigned long) strip_or_tile
,
155 (unsigned long long) already_read
,
156 (unsigned long long) size
);
167 TIFFFillStripPartial( TIFF
*tif
, int strip
, tmsize_t read_ahead
, int restart
)
169 static const char module
[] = "TIFFFillStripPartial";
170 register TIFFDirectory
*td
= &tif
->tif_dir
;
171 tmsize_t unused_data
;
174 tmsize_t read_ahead_mod
;
175 /* tmsize_t bytecountm; */
177 if (!_TIFFFillStriles( tif
) || !tif
->tif_dir
.td_stripbytecount
)
181 * Expand raw data buffer, if needed, to hold data
182 * strip coming from file (perhaps should set upper
183 * bound on the size of a buffer we'll use?).
186 /* bytecountm=(tmsize_t) td->td_stripbytecount[strip]; */
188 /* Not completely sure where the * 2 comes from, but probably for */
189 /* an exponentional growth strategy of tif_rawdatasize */
190 if( read_ahead
< TIFF_TMSIZE_T_MAX
/ 2 )
191 read_ahead_mod
= read_ahead
* 2;
193 read_ahead_mod
= read_ahead
;
194 if (read_ahead_mod
> tif
->tif_rawdatasize
) {
197 tif
->tif_curstrip
= NOSTRIP
;
198 if ((tif
->tif_flags
& TIFF_MYBUFFER
) == 0) {
199 TIFFErrorExt(tif
->tif_clientdata
, module
,
200 "Data buffer too small to hold part of strip %lu",
201 (unsigned long) strip
);
208 tif
->tif_rawdataloaded
= 0;
209 tif
->tif_rawdataoff
= 0;
213 ** If we are reading more data, move any unused data to the
214 ** start of the buffer.
216 if( tif
->tif_rawdataloaded
> 0 )
217 unused_data
= tif
->tif_rawdataloaded
- (tif
->tif_rawcp
- tif
->tif_rawdata
);
221 if( unused_data
> 0 )
223 assert((tif
->tif_flags
&TIFF_BUFFERMMAP
)==0);
224 memmove( tif
->tif_rawdata
, tif
->tif_rawcp
, unused_data
);
228 ** Seek to the point in the file where more data should be read.
230 read_offset
= td
->td_stripoffset
[strip
]
231 + tif
->tif_rawdataoff
+ tif
->tif_rawdataloaded
;
233 if (!SeekOK(tif
, read_offset
)) {
234 TIFFErrorExt(tif
->tif_clientdata
, module
,
235 "Seek error at scanline %lu, strip %lu",
236 (unsigned long) tif
->tif_row
, (unsigned long) strip
);
241 ** How much do we want to read?
243 if( read_ahead_mod
> tif
->tif_rawdatasize
)
244 to_read
= read_ahead_mod
- unused_data
;
246 to_read
= tif
->tif_rawdatasize
- unused_data
;
247 if( (uint64
) to_read
> td
->td_stripbytecount
[strip
]
248 - tif
->tif_rawdataoff
- tif
->tif_rawdataloaded
)
250 to_read
= (tmsize_t
) td
->td_stripbytecount
[strip
]
251 - tif
->tif_rawdataoff
- tif
->tif_rawdataloaded
;
254 assert((tif
->tif_flags
&TIFF_BUFFERMMAP
)==0);
255 if( !TIFFReadAndRealloc( tif
, to_read
, unused_data
,
257 0, /* strip_or_tile */
263 tif
->tif_rawdataoff
= tif
->tif_rawdataoff
+ tif
->tif_rawdataloaded
- unused_data
;
264 tif
->tif_rawdataloaded
= unused_data
+ to_read
;
266 tif
->tif_rawcp
= tif
->tif_rawdata
;
268 if (!isFillOrder(tif
, td
->td_fillorder
) &&
269 (tif
->tif_flags
& TIFF_NOBITREV
) == 0) {
270 assert((tif
->tif_flags
&TIFF_BUFFERMMAP
)==0);
271 TIFFReverseBits(tif
->tif_rawdata
+ unused_data
, to_read
);
275 ** When starting a strip from the beginning we need to
276 ** restart the decoder.
279 return TIFFStartStrip(tif
, strip
);
282 tif
->tif_rawcc
= tif
->tif_rawdataloaded
;
288 * Seek to a random row+sample in a file.
290 * Only used by TIFFReadScanline, and is only used on
291 * strip organized files. We do some tricky stuff to try
292 * and avoid reading the whole compressed raw data for big
296 TIFFSeek(TIFF
* tif
, uint32 row
, uint16 sample
)
298 register TIFFDirectory
*td
= &tif
->tif_dir
;
301 tmsize_t read_ahead
= 0;
304 ** Establish what strip we are working from.
306 if (row
>= td
->td_imagelength
) { /* out of range */
307 TIFFErrorExt(tif
->tif_clientdata
, tif
->tif_name
,
308 "%lu: Row out of range, max %lu",
310 (unsigned long) td
->td_imagelength
);
313 if (td
->td_planarconfig
== PLANARCONFIG_SEPARATE
) {
314 if (sample
>= td
->td_samplesperpixel
) {
315 TIFFErrorExt(tif
->tif_clientdata
, tif
->tif_name
,
316 "%lu: Sample out of range, max %lu",
317 (unsigned long) sample
, (unsigned long) td
->td_samplesperpixel
);
320 strip
= (uint32
)sample
*td
->td_stripsperimage
+ row
/td
->td_rowsperstrip
;
322 strip
= row
/ td
->td_rowsperstrip
;
325 * Do we want to treat this strip as one whole chunk or
326 * read it a few lines at a time?
328 #if defined(CHUNKY_STRIP_READ_SUPPORT)
329 if (!_TIFFFillStriles( tif
) || !tif
->tif_dir
.td_stripbytecount
)
331 whole_strip
= tif
->tif_dir
.td_stripbytecount
[strip
] < 10
339 /* 16 is for YCbCr mode where we may need to read 16 */
340 /* lines at a time to get a decompressed line, and 5000 */
341 /* is some constant value, for example for JPEG tables */
342 if( tif
->tif_scanlinesize
< TIFF_TMSIZE_T_MAX
/ 16 &&
343 tif
->tif_scanlinesize
* 16 < TIFF_TMSIZE_T_MAX
- 5000 )
345 read_ahead
= tif
->tif_scanlinesize
* 16 + 5000;
349 read_ahead
= tif
->tif_scanlinesize
;
354 * If we haven't loaded this strip, do so now, possibly
355 * only reading the first part.
357 if (strip
!= tif
->tif_curstrip
) { /* different strip, refill */
361 if (!TIFFFillStrip(tif
, strip
))
366 if( !TIFFFillStripPartial(tif
,strip
,read_ahead
,1) )
372 ** If we already have some data loaded, do we need to read some more?
374 else if( !whole_strip
)
376 if( ((tif
->tif_rawdata
+ tif
->tif_rawdataloaded
) - tif
->tif_rawcp
) < read_ahead
377 && (uint64
) tif
->tif_rawdataoff
+tif
->tif_rawdataloaded
< td
->td_stripbytecount
[strip
] )
379 if( !TIFFFillStripPartial(tif
,strip
,read_ahead
,0) )
384 if (row
< tif
->tif_row
) {
386 * Moving backwards within the same strip: backup
387 * to the start and then decode forward (below).
389 * NB: If you're planning on lots of random access within a
390 * strip, it's better to just read and decode the entire
391 * strip, and then access the decoded data in a random fashion.
394 if( tif
->tif_rawdataoff
!= 0 )
396 if( !TIFFFillStripPartial(tif
,strip
,read_ahead
,1) )
401 if (!TIFFStartStrip(tif
, strip
))
406 if (row
!= tif
->tif_row
) {
408 * Seek forward to the desired row.
411 /* TODO: Will this really work with partial buffers? */
413 if (!(*tif
->tif_seek
)(tif
, row
- tif
->tif_row
))
422 TIFFReadScanline(TIFF
* tif
, void* buf
, uint32 row
, uint16 sample
)
426 if (!TIFFCheckRead(tif
, 0))
428 if( (e
= TIFFSeek(tif
, row
, sample
)) != 0) {
430 * Decompress desired row into user buffer.
432 e
= (*tif
->tif_decoderow
)
433 (tif
, (uint8
*) buf
, tif
->tif_scanlinesize
, sample
);
435 /* we are now poised at the beginning of the next row */
436 tif
->tif_row
= row
+ 1;
439 (*tif
->tif_postdecode
)(tif
, (uint8
*) buf
,
440 tif
->tif_scanlinesize
);
442 return (e
> 0 ? 1 : -1);
446 * Read a strip of data and decompress the specified
447 * amount into the user-supplied buffer.
450 TIFFReadEncodedStrip(TIFF
* tif
, uint32 strip
, void* buf
, tmsize_t size
)
452 static const char module
[] = "TIFFReadEncodedStrip";
453 TIFFDirectory
*td
= &tif
->tif_dir
;
455 uint32 stripsperplane
;
460 if (!TIFFCheckRead(tif
,0))
461 return((tmsize_t
)(-1));
462 if (strip
>=td
->td_nstrips
)
464 TIFFErrorExt(tif
->tif_clientdata
,module
,
465 "%lu: Strip out of range, max %lu",(unsigned long)strip
,
466 (unsigned long)td
->td_nstrips
);
467 return((tmsize_t
)(-1));
470 * Calculate the strip size according to the number of
471 * rows in the strip (check for truncated last strip on any
472 * of the separations).
474 rowsperstrip
=td
->td_rowsperstrip
;
475 if (rowsperstrip
>td
->td_imagelength
)
476 rowsperstrip
=td
->td_imagelength
;
477 stripsperplane
= TIFFhowmany_32_maxuint_compat(td
->td_imagelength
, rowsperstrip
);
478 stripinplane
=(strip
%stripsperplane
);
479 plane
=(uint16
)(strip
/stripsperplane
);
480 rows
=td
->td_imagelength
-stripinplane
*rowsperstrip
;
481 if (rows
>rowsperstrip
)
483 stripsize
=TIFFVStripSize(tif
,rows
);
485 return((tmsize_t
)(-1));
487 /* shortcut to avoid an extra memcpy() */
488 if( td
->td_compression
== COMPRESSION_NONE
&&
489 size
!=(tmsize_t
)(-1) && size
>= stripsize
&&
491 ((tif
->tif_flags
&TIFF_NOREADRAW
)==0) )
493 if (TIFFReadRawStrip1(tif
, strip
, buf
, stripsize
, module
) != stripsize
)
494 return ((tmsize_t
)(-1));
496 if (!isFillOrder(tif
, td
->td_fillorder
) &&
497 (tif
->tif_flags
& TIFF_NOBITREV
) == 0)
498 TIFFReverseBits(buf
,stripsize
);
500 (*tif
->tif_postdecode
)(tif
,buf
,stripsize
);
504 if ((size
!=(tmsize_t
)(-1))&&(size
<stripsize
))
506 if (!TIFFFillStrip(tif
,strip
))
507 return((tmsize_t
)(-1));
508 if ((*tif
->tif_decodestrip
)(tif
,buf
,stripsize
,plane
)<=0)
509 return((tmsize_t
)(-1));
510 (*tif
->tif_postdecode
)(tif
,buf
,stripsize
);
515 TIFFReadRawStrip1(TIFF
* tif
, uint32 strip
, void* buf
, tmsize_t size
,
518 TIFFDirectory
*td
= &tif
->tif_dir
;
520 if (!_TIFFFillStriles( tif
))
521 return ((tmsize_t
)(-1));
523 assert((tif
->tif_flags
&TIFF_NOREADRAW
)==0);
524 if (!isMapped(tif
)) {
527 if (!SeekOK(tif
, td
->td_stripoffset
[strip
])) {
528 TIFFErrorExt(tif
->tif_clientdata
, module
,
529 "Seek error at scanline %lu, strip %lu",
530 (unsigned long) tif
->tif_row
, (unsigned long) strip
);
531 return ((tmsize_t
)(-1));
533 cc
= TIFFReadFile(tif
, buf
, size
);
535 #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
536 TIFFErrorExt(tif
->tif_clientdata
, module
,
537 "Read error at scanline %lu; got %I64u bytes, expected %I64u",
538 (unsigned long) tif
->tif_row
,
539 (unsigned __int64
) cc
,
540 (unsigned __int64
) size
);
542 TIFFErrorExt(tif
->tif_clientdata
, module
,
543 "Read error at scanline %lu; got %llu bytes, expected %llu",
544 (unsigned long) tif
->tif_row
,
545 (unsigned long long) cc
,
546 (unsigned long long) size
);
548 return ((tmsize_t
)(-1));
553 if ((td
->td_stripoffset
[strip
] > (uint64
)TIFF_TMSIZE_T_MAX
)||
554 ((ma
=(tmsize_t
)td
->td_stripoffset
[strip
])>tif
->tif_size
))
558 else if( ma
> TIFF_TMSIZE_T_MAX
- size
)
565 if (mb
>tif
->tif_size
)
571 #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
572 TIFFErrorExt(tif
->tif_clientdata
, module
,
573 "Read error at scanline %lu, strip %lu; got %I64u bytes, expected %I64u",
574 (unsigned long) tif
->tif_row
,
575 (unsigned long) strip
,
576 (unsigned __int64
) n
,
577 (unsigned __int64
) size
);
579 TIFFErrorExt(tif
->tif_clientdata
, module
,
580 "Read error at scanline %lu, strip %lu; got %llu bytes, expected %llu",
581 (unsigned long) tif
->tif_row
,
582 (unsigned long) strip
,
583 (unsigned long long) n
,
584 (unsigned long long) size
);
586 return ((tmsize_t
)(-1));
588 _TIFFmemcpy(buf
, tif
->tif_base
+ ma
,
595 TIFFReadRawStripOrTile2(TIFF
* tif
, uint32 strip_or_tile
, int is_strip
,
596 tmsize_t size
, const char* module
)
598 TIFFDirectory
*td
= &tif
->tif_dir
;
600 assert( !isMapped(tif
) );
601 assert((tif
->tif_flags
&TIFF_NOREADRAW
)==0);
603 if (!SeekOK(tif
, td
->td_stripoffset
[strip_or_tile
])) {
606 TIFFErrorExt(tif
->tif_clientdata
, module
,
607 "Seek error at scanline %lu, strip %lu",
608 (unsigned long) tif
->tif_row
,
609 (unsigned long) strip_or_tile
);
613 TIFFErrorExt(tif
->tif_clientdata
, module
,
614 "Seek error at row %lu, col %lu, tile %lu",
615 (unsigned long) tif
->tif_row
,
616 (unsigned long) tif
->tif_col
,
617 (unsigned long) strip_or_tile
);
619 return ((tmsize_t
)(-1));
622 if( !TIFFReadAndRealloc( tif
, size
, 0, is_strip
,
623 strip_or_tile
, module
) )
625 return ((tmsize_t
)(-1));
632 * Read a strip of data from the file.
635 TIFFReadRawStrip(TIFF
* tif
, uint32 strip
, void* buf
, tmsize_t size
)
637 static const char module
[] = "TIFFReadRawStrip";
638 TIFFDirectory
*td
= &tif
->tif_dir
;
642 if (!TIFFCheckRead(tif
, 0))
643 return ((tmsize_t
)(-1));
644 if (strip
>= td
->td_nstrips
) {
645 TIFFErrorExt(tif
->tif_clientdata
, module
,
646 "%lu: Strip out of range, max %lu",
647 (unsigned long) strip
,
648 (unsigned long) td
->td_nstrips
);
649 return ((tmsize_t
)(-1));
651 if (tif
->tif_flags
&TIFF_NOREADRAW
)
653 TIFFErrorExt(tif
->tif_clientdata
, module
,
654 "Compression scheme does not support access to raw uncompressed data");
655 return ((tmsize_t
)(-1));
657 bytecount
= td
->td_stripbytecount
[strip
];
658 if ((int64
)bytecount
<= 0) {
659 #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
660 TIFFErrorExt(tif
->tif_clientdata
, module
,
661 "%I64u: Invalid strip byte count, strip %lu",
662 (unsigned __int64
) bytecount
,
663 (unsigned long) strip
);
665 TIFFErrorExt(tif
->tif_clientdata
, module
,
666 "%llu: Invalid strip byte count, strip %lu",
667 (unsigned long long) bytecount
,
668 (unsigned long) strip
);
670 return ((tmsize_t
)(-1));
672 bytecountm
= (tmsize_t
)bytecount
;
673 if ((uint64
)bytecountm
!=bytecount
) {
674 TIFFErrorExt(tif
->tif_clientdata
, module
, "Integer overflow");
675 return ((tmsize_t
)(-1));
677 if (size
!= (tmsize_t
)(-1) && size
< bytecountm
)
679 return (TIFFReadRawStrip1(tif
, strip
, buf
, bytecountm
, module
));
683 * Read the specified strip and setup for decoding. The data buffer is
684 * expanded, as necessary, to hold the strip's data.
687 TIFFFillStrip(TIFF
* tif
, uint32 strip
)
689 static const char module
[] = "TIFFFillStrip";
690 TIFFDirectory
*td
= &tif
->tif_dir
;
692 if (!_TIFFFillStriles( tif
) || !tif
->tif_dir
.td_stripbytecount
)
695 if ((tif
->tif_flags
&TIFF_NOREADRAW
)==0)
697 uint64 bytecount
= td
->td_stripbytecount
[strip
];
698 if ((int64
)bytecount
<= 0) {
699 #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
700 TIFFErrorExt(tif
->tif_clientdata
, module
,
701 "Invalid strip byte count %I64u, strip %lu",
702 (unsigned __int64
) bytecount
,
703 (unsigned long) strip
);
705 TIFFErrorExt(tif
->tif_clientdata
, module
,
706 "Invalid strip byte count %llu, strip %lu",
707 (unsigned long long) bytecount
,
708 (unsigned long) strip
);
713 /* To avoid excessive memory allocations: */
714 /* Byte count should normally not be larger than a number of */
715 /* times the uncompressed size plus some margin */
716 if( bytecount
> 1024 * 1024 )
718 /* 10 and 4096 are just values that could be adjusted. */
719 /* Hopefully they are safe enough for all codecs */
720 tmsize_t stripsize
= TIFFStripSize(tif
);
721 if( stripsize
!= 0 &&
722 (bytecount
- 4096) / 10 > (uint64
)stripsize
)
724 uint64 newbytecount
= (uint64
)stripsize
* 10 + 4096;
725 if( (int64
)newbytecount
>= 0 )
727 #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
728 TIFFWarningExt(tif
->tif_clientdata
, module
,
729 "Too large strip byte count %I64u, strip %lu. Limiting to %I64u",
730 (unsigned __int64
) bytecount
,
731 (unsigned long) strip
,
732 (unsigned __int64
) newbytecount
);
734 TIFFErrorExt(tif
->tif_clientdata
, module
,
735 "Too large strip byte count %llu, strip %lu. Limiting to %llu",
736 (unsigned long long) bytecount
,
737 (unsigned long) strip
,
738 (unsigned long long) newbytecount
);
740 bytecount
= newbytecount
;
746 (isFillOrder(tif
, td
->td_fillorder
)
747 || (tif
->tif_flags
& TIFF_NOBITREV
))) {
749 * The image is mapped into memory and we either don't
750 * need to flip bits or the compression routine is
751 * going to handle this operation itself. In this
752 * case, avoid copying the raw data and instead just
753 * reference the data from the memory mapped file
754 * image. This assumes that the decompression
755 * routines do not modify the contents of the raw data
756 * buffer (if they try to, the application will get a
757 * fault since the file is mapped read-only).
759 if ((tif
->tif_flags
& TIFF_MYBUFFER
) && tif
->tif_rawdata
) {
760 _TIFFfree(tif
->tif_rawdata
);
761 tif
->tif_rawdata
= NULL
;
762 tif
->tif_rawdatasize
= 0;
764 tif
->tif_flags
&= ~TIFF_MYBUFFER
;
766 * We must check for overflow, potentially causing
767 * an OOB read. Instead of simple
769 * td->td_stripoffset[strip]+bytecount > tif->tif_size
771 * comparison (which can overflow) we do the following
774 if (bytecount
> (uint64
)tif
->tif_size
||
775 td
->td_stripoffset
[strip
] > (uint64
)tif
->tif_size
- bytecount
) {
777 * This error message might seem strange, but
778 * it's what would happen if a read were done
781 #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
782 TIFFErrorExt(tif
->tif_clientdata
, module
,
784 "Read error on strip %lu; "
785 "got %I64u bytes, expected %I64u",
786 (unsigned long) strip
,
787 (unsigned __int64
) tif
->tif_size
- td
->td_stripoffset
[strip
],
788 (unsigned __int64
) bytecount
);
790 TIFFErrorExt(tif
->tif_clientdata
, module
,
792 "Read error on strip %lu; "
793 "got %llu bytes, expected %llu",
794 (unsigned long) strip
,
795 (unsigned long long) tif
->tif_size
- td
->td_stripoffset
[strip
],
796 (unsigned long long) bytecount
);
798 tif
->tif_curstrip
= NOSTRIP
;
801 tif
->tif_rawdatasize
= (tmsize_t
)bytecount
;
802 tif
->tif_rawdata
= tif
->tif_base
+ (tmsize_t
)td
->td_stripoffset
[strip
];
803 tif
->tif_rawdataoff
= 0;
804 tif
->tif_rawdataloaded
= (tmsize_t
) bytecount
;
807 * When we have tif_rawdata reference directly into the memory mapped file
808 * we need to be pretty careful about how we use the rawdata. It is not
809 * a general purpose working buffer as it normally otherwise is. So we
810 * keep track of this fact to avoid using it improperly.
812 tif
->tif_flags
|= TIFF_BUFFERMMAP
;
815 * Expand raw data buffer, if needed, to hold data
816 * strip coming from file (perhaps should set upper
817 * bound on the size of a buffer we'll use?).
820 bytecountm
=(tmsize_t
)bytecount
;
821 if ((uint64
)bytecountm
!=bytecount
)
823 TIFFErrorExt(tif
->tif_clientdata
,module
,"Integer overflow");
826 if (bytecountm
> tif
->tif_rawdatasize
) {
827 tif
->tif_curstrip
= NOSTRIP
;
828 if ((tif
->tif_flags
& TIFF_MYBUFFER
) == 0) {
829 TIFFErrorExt(tif
->tif_clientdata
, module
,
830 "Data buffer too small to hold strip %lu",
831 (unsigned long) strip
);
835 if (tif
->tif_flags
&TIFF_BUFFERMMAP
) {
836 tif
->tif_curstrip
= NOSTRIP
;
837 tif
->tif_rawdata
= NULL
;
838 tif
->tif_rawdatasize
= 0;
839 tif
->tif_flags
&= ~TIFF_BUFFERMMAP
;
844 if (bytecountm
> tif
->tif_rawdatasize
&&
845 !TIFFReadBufferSetup(tif
, 0, bytecountm
))
849 if (TIFFReadRawStrip1(tif
, strip
, tif
->tif_rawdata
,
850 bytecountm
, module
) != bytecountm
)
857 if (TIFFReadRawStripOrTile2(tif
, strip
, 1,
858 bytecountm
, module
) != bytecountm
)
865 tif
->tif_rawdataoff
= 0;
866 tif
->tif_rawdataloaded
= bytecountm
;
868 if (!isFillOrder(tif
, td
->td_fillorder
) &&
869 (tif
->tif_flags
& TIFF_NOBITREV
) == 0)
870 TIFFReverseBits(tif
->tif_rawdata
, bytecountm
);
873 return (TIFFStartStrip(tif
, strip
));
877 * Tile-oriented Read Support
878 * Contributed by Nancy Cam (Silicon Graphics).
882 * Read and decompress a tile of data. The
883 * tile is selected by the (x,y,z,s) coordinates.
886 TIFFReadTile(TIFF
* tif
, void* buf
, uint32 x
, uint32 y
, uint32 z
, uint16 s
)
888 if (!TIFFCheckRead(tif
, 1) || !TIFFCheckTile(tif
, x
, y
, z
, s
))
889 return ((tmsize_t
)(-1));
890 return (TIFFReadEncodedTile(tif
,
891 TIFFComputeTile(tif
, x
, y
, z
, s
), buf
, (tmsize_t
)(-1)));
895 * Read a tile of data and decompress the specified
896 * amount into the user-supplied buffer.
899 TIFFReadEncodedTile(TIFF
* tif
, uint32 tile
, void* buf
, tmsize_t size
)
901 static const char module
[] = "TIFFReadEncodedTile";
902 TIFFDirectory
*td
= &tif
->tif_dir
;
903 tmsize_t tilesize
= tif
->tif_tilesize
;
905 if (!TIFFCheckRead(tif
, 1))
906 return ((tmsize_t
)(-1));
907 if (tile
>= td
->td_nstrips
) {
908 TIFFErrorExt(tif
->tif_clientdata
, module
,
909 "%lu: Tile out of range, max %lu",
910 (unsigned long) tile
, (unsigned long) td
->td_nstrips
);
911 return ((tmsize_t
)(-1));
914 /* shortcut to avoid an extra memcpy() */
915 if( td
->td_compression
== COMPRESSION_NONE
&&
916 size
!=(tmsize_t
)(-1) && size
>= tilesize
&&
918 ((tif
->tif_flags
&TIFF_NOREADRAW
)==0) )
920 if (TIFFReadRawTile1(tif
, tile
, buf
, tilesize
, module
) != tilesize
)
921 return ((tmsize_t
)(-1));
923 if (!isFillOrder(tif
, td
->td_fillorder
) &&
924 (tif
->tif_flags
& TIFF_NOBITREV
) == 0)
925 TIFFReverseBits(buf
,tilesize
);
927 (*tif
->tif_postdecode
)(tif
,buf
,tilesize
);
931 if (size
== (tmsize_t
)(-1))
933 else if (size
> tilesize
)
935 if (TIFFFillTile(tif
, tile
) && (*tif
->tif_decodetile
)(tif
,
936 (uint8
*) buf
, size
, (uint16
)(tile
/td
->td_stripsperimage
))) {
937 (*tif
->tif_postdecode
)(tif
, (uint8
*) buf
, size
);
940 return ((tmsize_t
)(-1));
944 TIFFReadRawTile1(TIFF
* tif
, uint32 tile
, void* buf
, tmsize_t size
, const char* module
)
946 TIFFDirectory
*td
= &tif
->tif_dir
;
948 if (!_TIFFFillStriles( tif
))
949 return ((tmsize_t
)(-1));
951 assert((tif
->tif_flags
&TIFF_NOREADRAW
)==0);
952 if (!isMapped(tif
)) {
955 if (!SeekOK(tif
, td
->td_stripoffset
[tile
])) {
956 TIFFErrorExt(tif
->tif_clientdata
, module
,
957 "Seek error at row %lu, col %lu, tile %lu",
958 (unsigned long) tif
->tif_row
,
959 (unsigned long) tif
->tif_col
,
960 (unsigned long) tile
);
961 return ((tmsize_t
)(-1));
963 cc
= TIFFReadFile(tif
, buf
, size
);
965 #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
966 TIFFErrorExt(tif
->tif_clientdata
, module
,
967 "Read error at row %lu, col %lu; got %I64u bytes, expected %I64u",
968 (unsigned long) tif
->tif_row
,
969 (unsigned long) tif
->tif_col
,
970 (unsigned __int64
) cc
,
971 (unsigned __int64
) size
);
973 TIFFErrorExt(tif
->tif_clientdata
, module
,
974 "Read error at row %lu, col %lu; got %llu bytes, expected %llu",
975 (unsigned long) tif
->tif_row
,
976 (unsigned long) tif
->tif_col
,
977 (unsigned long long) cc
,
978 (unsigned long long) size
);
980 return ((tmsize_t
)(-1));
985 ma
=(tmsize_t
)td
->td_stripoffset
[tile
];
987 if ((td
->td_stripoffset
[tile
] > (uint64
)TIFF_TMSIZE_T_MAX
)||(ma
>tif
->tif_size
))
989 else if ((mb
<ma
)||(mb
<size
)||(mb
>tif
->tif_size
))
994 #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
995 TIFFErrorExt(tif
->tif_clientdata
, module
,
996 "Read error at row %lu, col %lu, tile %lu; got %I64u bytes, expected %I64u",
997 (unsigned long) tif
->tif_row
,
998 (unsigned long) tif
->tif_col
,
999 (unsigned long) tile
,
1000 (unsigned __int64
) n
,
1001 (unsigned __int64
) size
);
1003 TIFFErrorExt(tif
->tif_clientdata
, module
,
1004 "Read error at row %lu, col %lu, tile %lu; got %llu bytes, expected %llu",
1005 (unsigned long) tif
->tif_row
,
1006 (unsigned long) tif
->tif_col
,
1007 (unsigned long) tile
,
1008 (unsigned long long) n
,
1009 (unsigned long long) size
);
1011 return ((tmsize_t
)(-1));
1013 _TIFFmemcpy(buf
, tif
->tif_base
+ ma
, size
);
1019 * Read a tile of data from the file.
1022 TIFFReadRawTile(TIFF
* tif
, uint32 tile
, void* buf
, tmsize_t size
)
1024 static const char module
[] = "TIFFReadRawTile";
1025 TIFFDirectory
*td
= &tif
->tif_dir
;
1027 tmsize_t bytecountm
;
1029 if (!TIFFCheckRead(tif
, 1))
1030 return ((tmsize_t
)(-1));
1031 if (tile
>= td
->td_nstrips
) {
1032 TIFFErrorExt(tif
->tif_clientdata
, module
,
1033 "%lu: Tile out of range, max %lu",
1034 (unsigned long) tile
, (unsigned long) td
->td_nstrips
);
1035 return ((tmsize_t
)(-1));
1037 if (tif
->tif_flags
&TIFF_NOREADRAW
)
1039 TIFFErrorExt(tif
->tif_clientdata
, module
,
1040 "Compression scheme does not support access to raw uncompressed data");
1041 return ((tmsize_t
)(-1));
1043 bytecount64
= td
->td_stripbytecount
[tile
];
1044 if (size
!= (tmsize_t
)(-1) && (uint64
)size
< bytecount64
)
1045 bytecount64
= (uint64
)size
;
1046 bytecountm
= (tmsize_t
)bytecount64
;
1047 if ((uint64
)bytecountm
!=bytecount64
)
1049 TIFFErrorExt(tif
->tif_clientdata
,module
,"Integer overflow");
1050 return ((tmsize_t
)(-1));
1052 return (TIFFReadRawTile1(tif
, tile
, buf
, bytecountm
, module
));
1056 * Read the specified tile and setup for decoding. The data buffer is
1057 * expanded, as necessary, to hold the tile's data.
1060 TIFFFillTile(TIFF
* tif
, uint32 tile
)
1062 static const char module
[] = "TIFFFillTile";
1063 TIFFDirectory
*td
= &tif
->tif_dir
;
1065 if (!_TIFFFillStriles( tif
) || !tif
->tif_dir
.td_stripbytecount
)
1068 if ((tif
->tif_flags
&TIFF_NOREADRAW
)==0)
1070 uint64 bytecount
= td
->td_stripbytecount
[tile
];
1071 if ((int64
)bytecount
<= 0) {
1072 #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
1073 TIFFErrorExt(tif
->tif_clientdata
, module
,
1074 "%I64u: Invalid tile byte count, tile %lu",
1075 (unsigned __int64
) bytecount
,
1076 (unsigned long) tile
);
1078 TIFFErrorExt(tif
->tif_clientdata
, module
,
1079 "%llu: Invalid tile byte count, tile %lu",
1080 (unsigned long long) bytecount
,
1081 (unsigned long) tile
);
1085 if (isMapped(tif
) &&
1086 (isFillOrder(tif
, td
->td_fillorder
)
1087 || (tif
->tif_flags
& TIFF_NOBITREV
))) {
1089 * The image is mapped into memory and we either don't
1090 * need to flip bits or the compression routine is
1091 * going to handle this operation itself. In this
1092 * case, avoid copying the raw data and instead just
1093 * reference the data from the memory mapped file
1094 * image. This assumes that the decompression
1095 * routines do not modify the contents of the raw data
1096 * buffer (if they try to, the application will get a
1097 * fault since the file is mapped read-only).
1099 if ((tif
->tif_flags
& TIFF_MYBUFFER
) && tif
->tif_rawdata
) {
1100 _TIFFfree(tif
->tif_rawdata
);
1101 tif
->tif_rawdata
= NULL
;
1102 tif
->tif_rawdatasize
= 0;
1104 tif
->tif_flags
&= ~TIFF_MYBUFFER
;
1106 * We must check for overflow, potentially causing
1107 * an OOB read. Instead of simple
1109 * td->td_stripoffset[tile]+bytecount > tif->tif_size
1111 * comparison (which can overflow) we do the following
1114 if (bytecount
> (uint64
)tif
->tif_size
||
1115 td
->td_stripoffset
[tile
] > (uint64
)tif
->tif_size
- bytecount
) {
1116 tif
->tif_curtile
= NOTILE
;
1119 tif
->tif_rawdatasize
= (tmsize_t
)bytecount
;
1121 tif
->tif_base
+ (tmsize_t
)td
->td_stripoffset
[tile
];
1122 tif
->tif_rawdataoff
= 0;
1123 tif
->tif_rawdataloaded
= (tmsize_t
) bytecount
;
1124 tif
->tif_flags
|= TIFF_BUFFERMMAP
;
1127 * Expand raw data buffer, if needed, to hold data
1128 * tile coming from file (perhaps should set upper
1129 * bound on the size of a buffer we'll use?).
1131 tmsize_t bytecountm
;
1132 bytecountm
=(tmsize_t
)bytecount
;
1133 if ((uint64
)bytecountm
!=bytecount
)
1135 TIFFErrorExt(tif
->tif_clientdata
,module
,"Integer overflow");
1138 if (bytecountm
> tif
->tif_rawdatasize
) {
1139 tif
->tif_curtile
= NOTILE
;
1140 if ((tif
->tif_flags
& TIFF_MYBUFFER
) == 0) {
1141 TIFFErrorExt(tif
->tif_clientdata
, module
,
1142 "Data buffer too small to hold tile %lu",
1143 (unsigned long) tile
);
1147 if (tif
->tif_flags
&TIFF_BUFFERMMAP
) {
1148 tif
->tif_curtile
= NOTILE
;
1149 tif
->tif_rawdata
= NULL
;
1150 tif
->tif_rawdatasize
= 0;
1151 tif
->tif_flags
&= ~TIFF_BUFFERMMAP
;
1156 if (bytecountm
> tif
->tif_rawdatasize
&&
1157 !TIFFReadBufferSetup(tif
, 0, bytecountm
))
1161 if (TIFFReadRawTile1(tif
, tile
, tif
->tif_rawdata
,
1162 bytecountm
, module
) != bytecountm
)
1169 if (TIFFReadRawStripOrTile2(tif
, tile
, 0,
1170 bytecountm
, module
) != bytecountm
)
1177 tif
->tif_rawdataoff
= 0;
1178 tif
->tif_rawdataloaded
= bytecountm
;
1180 if (!isFillOrder(tif
, td
->td_fillorder
) &&
1181 (tif
->tif_flags
& TIFF_NOBITREV
) == 0)
1182 TIFFReverseBits(tif
->tif_rawdata
,
1183 tif
->tif_rawdataloaded
);
1186 return (TIFFStartTile(tif
, tile
));
1190 * Setup the raw data buffer in preparation for
1191 * reading a strip of raw data. If the buffer
1192 * is specified as zero, then a buffer of appropriate
1193 * size is allocated by the library. Otherwise,
1194 * the client must guarantee that the buffer is
1195 * large enough to hold any individual strip of
1199 TIFFReadBufferSetup(TIFF
* tif
, void* bp
, tmsize_t size
)
1201 static const char module
[] = "TIFFReadBufferSetup";
1203 assert((tif
->tif_flags
&TIFF_NOREADRAW
)==0);
1204 tif
->tif_flags
&= ~TIFF_BUFFERMMAP
;
1206 if (tif
->tif_rawdata
) {
1207 if (tif
->tif_flags
& TIFF_MYBUFFER
)
1208 _TIFFfree(tif
->tif_rawdata
);
1209 tif
->tif_rawdata
= NULL
;
1210 tif
->tif_rawdatasize
= 0;
1213 tif
->tif_rawdatasize
= size
;
1214 tif
->tif_rawdata
= (uint8
*) bp
;
1215 tif
->tif_flags
&= ~TIFF_MYBUFFER
;
1217 tif
->tif_rawdatasize
= (tmsize_t
)TIFFroundup_64((uint64
)size
, 1024);
1218 if (tif
->tif_rawdatasize
==0) {
1219 TIFFErrorExt(tif
->tif_clientdata
, module
,
1220 "Invalid buffer size");
1223 /* Initialize to zero to avoid uninitialized buffers in case of */
1224 /* short reads (http://bugzilla.maptools.org/show_bug.cgi?id=2651) */
1225 tif
->tif_rawdata
= (uint8
*) _TIFFcalloc(1, tif
->tif_rawdatasize
);
1226 tif
->tif_flags
|= TIFF_MYBUFFER
;
1228 if (tif
->tif_rawdata
== NULL
) {
1229 TIFFErrorExt(tif
->tif_clientdata
, module
,
1230 "No space for data buffer at scanline %lu",
1231 (unsigned long) tif
->tif_row
);
1232 tif
->tif_rawdatasize
= 0;
1239 * Set state to appear as if a
1240 * strip has just been read in.
1243 TIFFStartStrip(TIFF
* tif
, uint32 strip
)
1245 TIFFDirectory
*td
= &tif
->tif_dir
;
1247 if (!_TIFFFillStriles( tif
) || !tif
->tif_dir
.td_stripbytecount
)
1250 if ((tif
->tif_flags
& TIFF_CODERSETUP
) == 0) {
1251 if (!(*tif
->tif_setupdecode
)(tif
))
1253 tif
->tif_flags
|= TIFF_CODERSETUP
;
1255 tif
->tif_curstrip
= strip
;
1256 tif
->tif_row
= (strip
% td
->td_stripsperimage
) * td
->td_rowsperstrip
;
1257 tif
->tif_flags
&= ~TIFF_BUF4WRITE
;
1259 if (tif
->tif_flags
&TIFF_NOREADRAW
)
1261 tif
->tif_rawcp
= NULL
;
1266 tif
->tif_rawcp
= tif
->tif_rawdata
;
1267 if( tif
->tif_rawdataloaded
> 0 )
1268 tif
->tif_rawcc
= tif
->tif_rawdataloaded
;
1270 tif
->tif_rawcc
= (tmsize_t
)td
->td_stripbytecount
[strip
];
1272 return ((*tif
->tif_predecode
)(tif
,
1273 (uint16
)(strip
/ td
->td_stripsperimage
)));
1277 * Set state to appear as if a
1278 * tile has just been read in.
1281 TIFFStartTile(TIFF
* tif
, uint32 tile
)
1283 static const char module
[] = "TIFFStartTile";
1284 TIFFDirectory
*td
= &tif
->tif_dir
;
1287 if (!_TIFFFillStriles( tif
) || !tif
->tif_dir
.td_stripbytecount
)
1290 if ((tif
->tif_flags
& TIFF_CODERSETUP
) == 0) {
1291 if (!(*tif
->tif_setupdecode
)(tif
))
1293 tif
->tif_flags
|= TIFF_CODERSETUP
;
1295 tif
->tif_curtile
= tile
;
1296 howmany32
=TIFFhowmany_32(td
->td_imagewidth
, td
->td_tilewidth
);
1297 if (howmany32
== 0) {
1298 TIFFErrorExt(tif
->tif_clientdata
,module
,"Zero tiles");
1301 tif
->tif_row
= (tile
% howmany32
) * td
->td_tilelength
;
1302 howmany32
=TIFFhowmany_32(td
->td_imagelength
, td
->td_tilelength
);
1303 if (howmany32
== 0) {
1304 TIFFErrorExt(tif
->tif_clientdata
,module
,"Zero tiles");
1307 tif
->tif_col
= (tile
% howmany32
) * td
->td_tilewidth
;
1308 tif
->tif_flags
&= ~TIFF_BUF4WRITE
;
1309 if (tif
->tif_flags
&TIFF_NOREADRAW
)
1311 tif
->tif_rawcp
= NULL
;
1316 tif
->tif_rawcp
= tif
->tif_rawdata
;
1317 tif
->tif_rawcc
= (tmsize_t
)td
->td_stripbytecount
[tile
];
1319 return ((*tif
->tif_predecode
)(tif
,
1320 (uint16
)(tile
/td
->td_stripsperimage
)));
1324 TIFFCheckRead(TIFF
* tif
, int tiles
)
1326 if (tif
->tif_mode
== O_WRONLY
) {
1327 TIFFErrorExt(tif
->tif_clientdata
, tif
->tif_name
, "File not open for reading");
1330 if (tiles
^ isTiled(tif
)) {
1331 TIFFErrorExt(tif
->tif_clientdata
, tif
->tif_name
, tiles
?
1332 "Can not read tiles from a stripped image" :
1333 "Can not read scanlines from a tiled image");
1340 _TIFFNoPostDecode(TIFF
* tif
, uint8
* buf
, tmsize_t cc
)
1342 (void) tif
; (void) buf
; (void) cc
;
1346 _TIFFSwab16BitData(TIFF
* tif
, uint8
* buf
, tmsize_t cc
)
1349 assert((cc
& 1) == 0);
1350 TIFFSwabArrayOfShort((uint16
*) buf
, cc
/2);
1354 _TIFFSwab24BitData(TIFF
* tif
, uint8
* buf
, tmsize_t cc
)
1357 assert((cc
% 3) == 0);
1358 TIFFSwabArrayOfTriples((uint8
*) buf
, cc
/3);
1362 _TIFFSwab32BitData(TIFF
* tif
, uint8
* buf
, tmsize_t cc
)
1365 assert((cc
& 3) == 0);
1366 TIFFSwabArrayOfLong((uint32
*) buf
, cc
/4);
1370 _TIFFSwab64BitData(TIFF
* tif
, uint8
* buf
, tmsize_t cc
)
1373 assert((cc
& 7) == 0);
1374 TIFFSwabArrayOfDouble((double*) buf
, cc
/8);
1377 /* vim: set ts=8 sts=8 sw=8 noet: */