|
Packit Service |
db44fb |
/* $Id: tif_read.c,v 1.16.2.3 2010-06-09 14:32:47 bfriesen Exp $ */
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
/*
|
|
Packit Service |
db44fb |
* Copyright (c) 1988-1997 Sam Leffler
|
|
Packit Service |
db44fb |
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
|
|
Packit Service |
db44fb |
*
|
|
Packit Service |
db44fb |
* Permission to use, copy, modify, distribute, and sell this software and
|
|
Packit Service |
db44fb |
* its documentation for any purpose is hereby granted without fee, provided
|
|
Packit Service |
db44fb |
* that (i) the above copyright notices and this permission notice appear in
|
|
Packit Service |
db44fb |
* all copies of the software and related documentation, and (ii) the names of
|
|
Packit Service |
db44fb |
* Sam Leffler and Silicon Graphics may not be used in any advertising or
|
|
Packit Service |
db44fb |
* publicity relating to the software without the specific, prior written
|
|
Packit Service |
db44fb |
* permission of Sam Leffler and Silicon Graphics.
|
|
Packit Service |
db44fb |
*
|
|
Packit Service |
db44fb |
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
|
Packit Service |
db44fb |
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
|
Packit Service |
db44fb |
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
|
Packit Service |
db44fb |
*
|
|
Packit Service |
db44fb |
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
|
|
Packit Service |
db44fb |
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
|
|
Packit Service |
db44fb |
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
|
Packit Service |
db44fb |
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
|
Packit Service |
db44fb |
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
|
Packit Service |
db44fb |
* OF THIS SOFTWARE.
|
|
Packit Service |
db44fb |
*/
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
/*
|
|
Packit Service |
db44fb |
* TIFF Library.
|
|
Packit Service |
db44fb |
* Scanline-oriented Read Support
|
|
Packit Service |
db44fb |
*/
|
|
Packit Service |
db44fb |
#include "tiffiop.h"
|
|
Packit Service |
db44fb |
#include <stdio.h>
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
int TIFFFillStrip(TIFF*, tstrip_t);
|
|
Packit Service |
db44fb |
int TIFFFillTile(TIFF*, ttile_t);
|
|
Packit Service |
db44fb |
static int TIFFStartStrip(TIFF*, tstrip_t);
|
|
Packit Service |
db44fb |
static int TIFFStartTile(TIFF*, ttile_t);
|
|
Packit Service |
db44fb |
static int TIFFCheckRead(TIFF*, int);
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
#define NOSTRIP ((tstrip_t) -1) /* undefined state */
|
|
Packit Service |
db44fb |
#define NOTILE ((ttile_t) -1) /* undefined state */
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
/*
|
|
Packit Service |
db44fb |
* Seek to a random row+sample in a file.
|
|
Packit Service |
db44fb |
*/
|
|
Packit Service |
db44fb |
static int
|
|
Packit Service |
db44fb |
TIFFSeek(TIFF* tif, uint32 row, tsample_t sample)
|
|
Packit Service |
db44fb |
{
|
|
Packit Service |
db44fb |
register TIFFDirectory *td = &tif->tif_dir;
|
|
Packit Service |
db44fb |
tstrip_t strip;
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
if (row >= td->td_imagelength) { /* out of range */
|
|
Packit Service |
db44fb |
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
|
|
Packit Service |
db44fb |
"%lu: Row out of range, max %lu",
|
|
Packit Service |
db44fb |
(unsigned long) row,
|
|
Packit Service |
db44fb |
(unsigned long) td->td_imagelength);
|
|
Packit Service |
db44fb |
return (0);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
if (td->td_planarconfig == PLANARCONFIG_SEPARATE) {
|
|
Packit Service |
db44fb |
if (sample >= td->td_samplesperpixel) {
|
|
Packit Service |
db44fb |
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
|
|
Packit Service |
db44fb |
"%lu: Sample out of range, max %lu",
|
|
Packit Service |
db44fb |
(unsigned long) sample, (unsigned long) td->td_samplesperpixel);
|
|
Packit Service |
db44fb |
return (0);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
strip = sample*td->td_stripsperimage + row/td->td_rowsperstrip;
|
|
Packit Service |
db44fb |
} else
|
|
Packit Service |
db44fb |
strip = row / td->td_rowsperstrip;
|
|
Packit Service |
db44fb |
if (strip != tif->tif_curstrip) { /* different strip, refill */
|
|
Packit Service |
db44fb |
if (!TIFFFillStrip(tif, strip))
|
|
Packit Service |
db44fb |
return (0);
|
|
Packit Service |
db44fb |
} else if (row < tif->tif_row) {
|
|
Packit Service |
db44fb |
/*
|
|
Packit Service |
db44fb |
* Moving backwards within the same strip: backup
|
|
Packit Service |
db44fb |
* to the start and then decode forward (below).
|
|
Packit Service |
db44fb |
*
|
|
Packit Service |
db44fb |
* NB: If you're planning on lots of random access within a
|
|
Packit Service |
db44fb |
* strip, it's better to just read and decode the entire
|
|
Packit Service |
db44fb |
* strip, and then access the decoded data in a random fashion.
|
|
Packit Service |
db44fb |
*/
|
|
Packit Service |
db44fb |
if (!TIFFStartStrip(tif, strip))
|
|
Packit Service |
db44fb |
return (0);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
if (row != tif->tif_row) {
|
|
Packit Service |
db44fb |
/*
|
|
Packit Service |
db44fb |
* Seek forward to the desired row.
|
|
Packit Service |
db44fb |
*/
|
|
Packit Service |
db44fb |
if (!(*tif->tif_seek)(tif, row - tif->tif_row))
|
|
Packit Service |
db44fb |
return (0);
|
|
Packit Service |
db44fb |
tif->tif_row = row;
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
return (1);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
int
|
|
Packit Service |
db44fb |
TIFFReadScanline(TIFF* tif, tdata_t buf, uint32 row, tsample_t sample)
|
|
Packit Service |
db44fb |
{
|
|
Packit Service |
db44fb |
int e;
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
if (!TIFFCheckRead(tif, 0))
|
|
Packit Service |
db44fb |
return (-1);
|
|
Packit Service |
db44fb |
if( (e = TIFFSeek(tif, row, sample)) != 0) {
|
|
Packit Service |
db44fb |
/*
|
|
Packit Service |
db44fb |
* Decompress desired row into user buffer.
|
|
Packit Service |
db44fb |
*/
|
|
Packit Service |
db44fb |
e = (*tif->tif_decoderow)
|
|
Packit Service |
db44fb |
(tif, (tidata_t) buf, tif->tif_scanlinesize, sample);
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
/* we are now poised at the beginning of the next row */
|
|
Packit Service |
db44fb |
tif->tif_row = row + 1;
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
if (e)
|
|
Packit Service |
db44fb |
(*tif->tif_postdecode)(tif, (tidata_t) buf,
|
|
Packit Service |
db44fb |
tif->tif_scanlinesize);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
return (e > 0 ? 1 : -1);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
/*
|
|
Packit Service |
db44fb |
* Read a strip of data and decompress the specified
|
|
Packit Service |
db44fb |
* amount into the user-supplied buffer.
|
|
Packit Service |
db44fb |
*/
|
|
Packit Service |
db44fb |
tsize_t
|
|
Packit Service |
db44fb |
TIFFReadEncodedStrip(TIFF* tif, tstrip_t strip, tdata_t buf, tsize_t size)
|
|
Packit Service |
db44fb |
{
|
|
Packit Service |
db44fb |
TIFFDirectory *td = &tif->tif_dir;
|
|
Packit Service |
db44fb |
uint32 nrows;
|
|
Packit Service |
db44fb |
tsize_t stripsize;
|
|
Packit Service |
db44fb |
tstrip_t sep_strip, strips_per_sep;
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
if (!TIFFCheckRead(tif, 0))
|
|
Packit Service |
db44fb |
return (-1);
|
|
Packit Service |
db44fb |
if (strip >= td->td_nstrips) {
|
|
Packit Service |
db44fb |
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
|
|
Packit Service |
db44fb |
"%ld: Strip out of range, max %ld",
|
|
Packit Service |
db44fb |
(long) strip, (long) td->td_nstrips);
|
|
Packit Service |
db44fb |
return (-1);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
/*
|
|
Packit Service |
db44fb |
* Calculate the strip size according to the number of
|
|
Packit Service |
db44fb |
* rows in the strip (check for truncated last strip on any
|
|
Packit Service |
db44fb |
* of the separations).
|
|
Packit Service |
db44fb |
*/
|
|
Packit Service |
db44fb |
if( td->td_rowsperstrip >= td->td_imagelength )
|
|
Packit Service |
db44fb |
strips_per_sep = 1;
|
|
Packit Service |
db44fb |
else
|
|
Packit Service |
db44fb |
strips_per_sep = (td->td_imagelength+td->td_rowsperstrip-1)
|
|
Packit Service |
db44fb |
/ td->td_rowsperstrip;
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
sep_strip = strip % strips_per_sep;
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
if (sep_strip != strips_per_sep-1 ||
|
|
Packit Service |
db44fb |
(nrows = td->td_imagelength % td->td_rowsperstrip) == 0)
|
|
Packit Service |
db44fb |
nrows = td->td_rowsperstrip;
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
stripsize = TIFFVStripSize(tif, nrows);
|
|
Packit Service |
db44fb |
if (size == (tsize_t) -1)
|
|
Packit Service |
db44fb |
size = stripsize;
|
|
Packit Service |
db44fb |
else if (size > stripsize)
|
|
Packit Service |
db44fb |
size = stripsize;
|
|
Packit Service |
db44fb |
if (TIFFFillStrip(tif, strip)
|
|
Packit Service |
db44fb |
&& (*tif->tif_decodestrip)(tif, (tidata_t) buf, size,
|
|
Packit Service |
db44fb |
(tsample_t)(strip / td->td_stripsperimage)) > 0 ) {
|
|
Packit Service |
db44fb |
(*tif->tif_postdecode)(tif, (tidata_t) buf, size);
|
|
Packit Service |
db44fb |
return (size);
|
|
Packit Service |
db44fb |
} else
|
|
Packit Service |
db44fb |
return ((tsize_t) -1);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
static tsize_t
|
|
Packit Service |
db44fb |
TIFFReadRawStrip1(TIFF* tif,
|
|
Packit Service |
db44fb |
tstrip_t strip, tdata_t buf, tsize_t size, const char* module)
|
|
Packit Service |
db44fb |
{
|
|
Packit Service |
db44fb |
TIFFDirectory *td = &tif->tif_dir;
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
assert((tif->tif_flags&TIFF_NOREADRAW)==0);
|
|
Packit Service |
db44fb |
if (!isMapped(tif)) {
|
|
Packit Service |
db44fb |
tsize_t cc;
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
if (!SeekOK(tif, td->td_stripoffset[strip])) {
|
|
Packit Service |
db44fb |
TIFFErrorExt(tif->tif_clientdata, module,
|
|
Packit Service |
db44fb |
"%s: Seek error at scanline %lu, strip %lu",
|
|
Packit Service |
db44fb |
tif->tif_name,
|
|
Packit Service |
db44fb |
(unsigned long) tif->tif_row, (unsigned long) strip);
|
|
Packit Service |
db44fb |
return (-1);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
cc = TIFFReadFile(tif, buf, size);
|
|
Packit Service |
db44fb |
if (cc != size) {
|
|
Packit Service |
db44fb |
TIFFErrorExt(tif->tif_clientdata, module,
|
|
Packit Service |
db44fb |
"%s: Read error at scanline %lu; got %lu bytes, expected %lu",
|
|
Packit Service |
db44fb |
tif->tif_name,
|
|
Packit Service |
db44fb |
(unsigned long) tif->tif_row,
|
|
Packit Service |
db44fb |
(unsigned long) cc,
|
|
Packit Service |
db44fb |
(unsigned long) size);
|
|
Packit Service |
db44fb |
return (-1);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
} else {
|
|
Packit Service |
db44fb |
if (td->td_stripoffset[strip] + size > tif->tif_size) {
|
|
Packit Service |
db44fb |
TIFFErrorExt(tif->tif_clientdata, module,
|
|
Packit Service |
db44fb |
"%s: Read error at scanline %lu, strip %lu; got %lu bytes, expected %lu",
|
|
Packit Service |
db44fb |
tif->tif_name,
|
|
Packit Service |
db44fb |
(unsigned long) tif->tif_row,
|
|
Packit Service |
db44fb |
(unsigned long) strip,
|
|
Packit Service |
db44fb |
(unsigned long) tif->tif_size - td->td_stripoffset[strip],
|
|
Packit Service |
db44fb |
(unsigned long) size);
|
|
Packit Service |
db44fb |
return (-1);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
_TIFFmemcpy(buf, tif->tif_base + td->td_stripoffset[strip],
|
|
Packit Service |
db44fb |
size);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
return (size);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
/*
|
|
Packit Service |
db44fb |
* Read a strip of data from the file.
|
|
Packit Service |
db44fb |
*/
|
|
Packit Service |
db44fb |
tsize_t
|
|
Packit Service |
db44fb |
TIFFReadRawStrip(TIFF* tif, tstrip_t strip, tdata_t buf, tsize_t size)
|
|
Packit Service |
db44fb |
{
|
|
Packit Service |
db44fb |
static const char module[] = "TIFFReadRawStrip";
|
|
Packit Service |
db44fb |
TIFFDirectory *td = &tif->tif_dir;
|
|
Packit Service |
db44fb |
/*
|
|
Packit Service |
db44fb |
* FIXME: butecount should have tsize_t type, but for now libtiff
|
|
Packit Service |
db44fb |
* defines tsize_t as a signed 32-bit integer and we are losing
|
|
Packit Service |
db44fb |
* ability to read arrays larger than 2^31 bytes. So we are using
|
|
Packit Service |
db44fb |
* uint32 instead of tsize_t here.
|
|
Packit Service |
db44fb |
*/
|
|
Packit Service |
db44fb |
uint32 bytecount;
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
if (!TIFFCheckRead(tif, 0))
|
|
Packit Service |
db44fb |
return ((tsize_t) -1);
|
|
Packit Service |
db44fb |
if (strip >= td->td_nstrips) {
|
|
Packit Service |
db44fb |
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
|
|
Packit Service |
db44fb |
"%lu: Strip out of range, max %lu",
|
|
Packit Service |
db44fb |
(unsigned long) strip,
|
|
Packit Service |
db44fb |
(unsigned long) td->td_nstrips);
|
|
Packit Service |
db44fb |
return ((tsize_t) -1);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
if (tif->tif_flags&TIFF_NOREADRAW)
|
|
Packit Service |
db44fb |
{
|
|
Packit Service |
db44fb |
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
|
|
Packit Service |
db44fb |
"Compression scheme does not support access to raw uncompressed data");
|
|
Packit Service |
db44fb |
return ((tsize_t) -1);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
bytecount = td->td_stripbytecount[strip];
|
|
Packit Service |
db44fb |
if (bytecount <= 0) {
|
|
Packit Service |
db44fb |
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
|
|
Packit Service |
db44fb |
"%lu: Invalid strip byte count, strip %lu",
|
|
Packit Service |
db44fb |
(unsigned long) bytecount, (unsigned long) strip);
|
|
Packit Service |
db44fb |
return ((tsize_t) -1);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
if (size != (tsize_t)-1 && (uint32)size < bytecount)
|
|
Packit Service |
db44fb |
bytecount = size;
|
|
Packit Service |
db44fb |
return (TIFFReadRawStrip1(tif, strip, buf, bytecount, module));
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
/*
|
|
Packit Service |
db44fb |
* Read the specified strip and setup for decoding. The data buffer is
|
|
Packit Service |
db44fb |
* expanded, as necessary, to hold the strip's data.
|
|
Packit Service |
db44fb |
*/
|
|
Packit Service |
db44fb |
int
|
|
Packit Service |
db44fb |
TIFFFillStrip(TIFF* tif, tstrip_t strip)
|
|
Packit Service |
db44fb |
{
|
|
Packit Service |
db44fb |
static const char module[] = "TIFFFillStrip";
|
|
Packit Service |
db44fb |
TIFFDirectory *td = &tif->tif_dir;
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
if ((tif->tif_flags&TIFF_NOREADRAW)==0)
|
|
Packit Service |
db44fb |
{
|
|
Packit Service |
db44fb |
/*
|
|
Packit Service |
db44fb |
* FIXME: butecount should have tsize_t type, but for now
|
|
Packit Service |
db44fb |
* libtiff defines tsize_t as a signed 32-bit integer and we
|
|
Packit Service |
db44fb |
* are losing ability to read arrays larger than 2^31 bytes.
|
|
Packit Service |
db44fb |
* So we are using uint32 instead of tsize_t here.
|
|
Packit Service |
db44fb |
*/
|
|
Packit Service |
db44fb |
uint32 bytecount = td->td_stripbytecount[strip];
|
|
Packit Service |
db44fb |
if (bytecount <= 0) {
|
|
Packit Service |
db44fb |
TIFFErrorExt(tif->tif_clientdata, module,
|
|
Packit Service |
db44fb |
"%s: Invalid strip byte count %lu, strip %lu",
|
|
Packit Service |
db44fb |
tif->tif_name, (unsigned long) bytecount,
|
|
Packit Service |
db44fb |
(unsigned long) strip);
|
|
Packit Service |
db44fb |
return (0);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
if (isMapped(tif) &&
|
|
Packit Service |
db44fb |
(isFillOrder(tif, td->td_fillorder)
|
|
Packit Service |
db44fb |
|| (tif->tif_flags & TIFF_NOBITREV))) {
|
|
Packit Service |
db44fb |
/*
|
|
Packit Service |
db44fb |
* The image is mapped into memory and we either don't
|
|
Packit Service |
db44fb |
* need to flip bits or the compression routine is
|
|
Packit Service |
db44fb |
* going to handle this operation itself. In this
|
|
Packit Service |
db44fb |
* case, avoid copying the raw data and instead just
|
|
Packit Service |
db44fb |
* reference the data from the memory mapped file
|
|
Packit Service |
db44fb |
* image. This assumes that the decompression
|
|
Packit Service |
db44fb |
* routines do not modify the contents of the raw data
|
|
Packit Service |
db44fb |
* buffer (if they try to, the application will get a
|
|
Packit Service |
db44fb |
* fault since the file is mapped read-only).
|
|
Packit Service |
db44fb |
*/
|
|
Packit Service |
db44fb |
if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata)
|
|
Packit Service |
db44fb |
_TIFFfree(tif->tif_rawdata);
|
|
Packit Service |
db44fb |
tif->tif_flags &= ~TIFF_MYBUFFER;
|
|
Packit Service |
db44fb |
/*
|
|
Packit Service |
db44fb |
* We must check for overflow, potentially causing
|
|
Packit Service |
db44fb |
* an OOB read. Instead of simple
|
|
Packit Service |
db44fb |
*
|
|
Packit Service |
db44fb |
* td->td_stripoffset[strip]+bytecount > tif->tif_size
|
|
Packit Service |
db44fb |
*
|
|
Packit Service |
db44fb |
* comparison (which can overflow) we do the following
|
|
Packit Service |
db44fb |
* two comparisons:
|
|
Packit Service |
db44fb |
*/
|
|
Packit Service |
db44fb |
if (bytecount > tif->tif_size ||
|
|
Packit Service |
db44fb |
td->td_stripoffset[strip] > tif->tif_size - bytecount) {
|
|
Packit Service |
db44fb |
/*
|
|
Packit Service |
db44fb |
* This error message might seem strange, but
|
|
Packit Service |
db44fb |
* it's what would happen if a read were done
|
|
Packit Service |
db44fb |
* instead.
|
|
Packit Service |
db44fb |
*/
|
|
Packit Service |
db44fb |
TIFFErrorExt(tif->tif_clientdata, module,
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
"%s: Read error on strip %lu; "
|
|
Packit Service |
db44fb |
"got %lu bytes, expected %lu",
|
|
Packit Service |
db44fb |
tif->tif_name, (unsigned long) strip,
|
|
Packit Service |
db44fb |
(unsigned long) tif->tif_size - td->td_stripoffset[strip],
|
|
Packit Service |
db44fb |
(unsigned long) bytecount);
|
|
Packit Service |
db44fb |
tif->tif_curstrip = NOSTRIP;
|
|
Packit Service |
db44fb |
return (0);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
tif->tif_rawdatasize = bytecount;
|
|
Packit Service |
db44fb |
tif->tif_rawdata = tif->tif_base + td->td_stripoffset[strip];
|
|
Packit Service |
db44fb |
} else {
|
|
Packit Service |
db44fb |
/*
|
|
Packit Service |
db44fb |
* Expand raw data buffer, if needed, to hold data
|
|
Packit Service |
db44fb |
* strip coming from file (perhaps should set upper
|
|
Packit Service |
db44fb |
* bound on the size of a buffer we'll use?).
|
|
Packit Service |
db44fb |
*/
|
|
Packit Service |
db44fb |
if (bytecount > (uint32)tif->tif_rawdatasize) {
|
|
Packit Service |
db44fb |
tif->tif_curstrip = NOSTRIP;
|
|
Packit Service |
db44fb |
if ((tif->tif_flags & TIFF_MYBUFFER) == 0) {
|
|
Packit Service |
db44fb |
TIFFErrorExt(tif->tif_clientdata,
|
|
Packit Service |
db44fb |
module,
|
|
Packit Service |
db44fb |
"%s: Data buffer too small to hold strip %lu",
|
|
Packit Service |
db44fb |
tif->tif_name,
|
|
Packit Service |
db44fb |
(unsigned long) strip);
|
|
Packit Service |
db44fb |
return (0);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
if (!TIFFReadBufferSetup(tif, 0,
|
|
Packit Service |
db44fb |
TIFFroundup(bytecount, 1024)))
|
|
Packit Service |
db44fb |
return (0);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
if ((uint32)TIFFReadRawStrip1(tif, strip,
|
|
Packit Service |
db44fb |
(unsigned char *)tif->tif_rawdata,
|
|
Packit Service |
db44fb |
bytecount, module) != bytecount)
|
|
Packit Service |
db44fb |
return (0);
|
|
Packit Service |
db44fb |
if (!isFillOrder(tif, td->td_fillorder) &&
|
|
Packit Service |
db44fb |
(tif->tif_flags & TIFF_NOBITREV) == 0)
|
|
Packit Service |
db44fb |
TIFFReverseBits(tif->tif_rawdata, bytecount);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
return (TIFFStartStrip(tif, strip));
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
/*
|
|
Packit Service |
db44fb |
* Tile-oriented Read Support
|
|
Packit Service |
db44fb |
* Contributed by Nancy Cam (Silicon Graphics).
|
|
Packit Service |
db44fb |
*/
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
/*
|
|
Packit Service |
db44fb |
* Read and decompress a tile of data. The
|
|
Packit Service |
db44fb |
* tile is selected by the (x,y,z,s) coordinates.
|
|
Packit Service |
db44fb |
*/
|
|
Packit Service |
db44fb |
tsize_t
|
|
Packit Service |
db44fb |
TIFFReadTile(TIFF* tif,
|
|
Packit Service |
db44fb |
tdata_t buf, uint32 x, uint32 y, uint32 z, tsample_t s)
|
|
Packit Service |
db44fb |
{
|
|
Packit Service |
db44fb |
if (!TIFFCheckRead(tif, 1) || !TIFFCheckTile(tif, x, y, z, s))
|
|
Packit Service |
db44fb |
return (-1);
|
|
Packit Service |
db44fb |
return (TIFFReadEncodedTile(tif,
|
|
Packit Service |
db44fb |
TIFFComputeTile(tif, x, y, z, s), buf, (tsize_t) -1));
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
/*
|
|
Packit Service |
db44fb |
* Read a tile of data and decompress the specified
|
|
Packit Service |
db44fb |
* amount into the user-supplied buffer.
|
|
Packit Service |
db44fb |
*/
|
|
Packit Service |
db44fb |
tsize_t
|
|
Packit Service |
db44fb |
TIFFReadEncodedTile(TIFF* tif, ttile_t tile, tdata_t buf, tsize_t size)
|
|
Packit Service |
db44fb |
{
|
|
Packit Service |
db44fb |
TIFFDirectory *td = &tif->tif_dir;
|
|
Packit Service |
db44fb |
tsize_t tilesize = tif->tif_tilesize;
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
if (!TIFFCheckRead(tif, 1))
|
|
Packit Service |
db44fb |
return (-1);
|
|
Packit Service |
db44fb |
if (tile >= td->td_nstrips) {
|
|
Packit Service |
db44fb |
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
|
|
Packit Service |
db44fb |
"%ld: Tile out of range, max %ld",
|
|
Packit Service |
db44fb |
(long) tile, (unsigned long) td->td_nstrips);
|
|
Packit Service |
db44fb |
return (-1);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
if (size == (tsize_t) -1)
|
|
Packit Service |
db44fb |
size = tilesize;
|
|
Packit Service |
db44fb |
else if (size > tilesize)
|
|
Packit Service |
db44fb |
size = tilesize;
|
|
Packit Service |
db44fb |
if (TIFFFillTile(tif, tile) && (*tif->tif_decodetile)(tif,
|
|
Packit Service |
db44fb |
(tidata_t) buf, size, (tsample_t)(tile/td->td_stripsperimage))) {
|
|
Packit Service |
db44fb |
(*tif->tif_postdecode)(tif, (tidata_t) buf, size);
|
|
Packit Service |
db44fb |
return (size);
|
|
Packit Service |
db44fb |
} else
|
|
Packit Service |
db44fb |
return (-1);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
static tsize_t
|
|
Packit Service |
db44fb |
TIFFReadRawTile1(TIFF* tif,
|
|
Packit Service |
db44fb |
ttile_t tile, tdata_t buf, tsize_t size, const char* module)
|
|
Packit Service |
db44fb |
{
|
|
Packit Service |
db44fb |
TIFFDirectory *td = &tif->tif_dir;
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
assert((tif->tif_flags&TIFF_NOREADRAW)==0);
|
|
Packit Service |
db44fb |
if (!isMapped(tif)) {
|
|
Packit Service |
db44fb |
tsize_t cc;
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
if (!SeekOK(tif, td->td_stripoffset[tile])) {
|
|
Packit Service |
db44fb |
TIFFErrorExt(tif->tif_clientdata, module,
|
|
Packit Service |
db44fb |
"%s: Seek error at row %ld, col %ld, tile %ld",
|
|
Packit Service |
db44fb |
tif->tif_name,
|
|
Packit Service |
db44fb |
(long) tif->tif_row,
|
|
Packit Service |
db44fb |
(long) tif->tif_col,
|
|
Packit Service |
db44fb |
(long) tile);
|
|
Packit Service |
db44fb |
return ((tsize_t) -1);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
cc = TIFFReadFile(tif, buf, size);
|
|
Packit Service |
db44fb |
if (cc != size) {
|
|
Packit Service |
db44fb |
TIFFErrorExt(tif->tif_clientdata, module,
|
|
Packit Service |
db44fb |
"%s: Read error at row %ld, col %ld; got %lu bytes, expected %lu",
|
|
Packit Service |
db44fb |
tif->tif_name,
|
|
Packit Service |
db44fb |
(long) tif->tif_row,
|
|
Packit Service |
db44fb |
(long) tif->tif_col,
|
|
Packit Service |
db44fb |
(unsigned long) cc,
|
|
Packit Service |
db44fb |
(unsigned long) size);
|
|
Packit Service |
db44fb |
return ((tsize_t) -1);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
} else {
|
|
Packit Service |
db44fb |
if (td->td_stripoffset[tile] + size > tif->tif_size) {
|
|
Packit Service |
db44fb |
TIFFErrorExt(tif->tif_clientdata, module,
|
|
Packit Service |
db44fb |
"%s: Read error at row %ld, col %ld, tile %ld; got %lu bytes, expected %lu",
|
|
Packit Service |
db44fb |
tif->tif_name,
|
|
Packit Service |
db44fb |
(long) tif->tif_row,
|
|
Packit Service |
db44fb |
(long) tif->tif_col,
|
|
Packit Service |
db44fb |
(long) tile,
|
|
Packit Service |
db44fb |
(unsigned long) tif->tif_size - td->td_stripoffset[tile],
|
|
Packit Service |
db44fb |
(unsigned long) size);
|
|
Packit Service |
db44fb |
return ((tsize_t) -1);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
_TIFFmemcpy(buf, tif->tif_base + td->td_stripoffset[tile], size);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
return (size);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
/*
|
|
Packit Service |
db44fb |
* Read a tile of data from the file.
|
|
Packit Service |
db44fb |
*/
|
|
Packit Service |
db44fb |
tsize_t
|
|
Packit Service |
db44fb |
TIFFReadRawTile(TIFF* tif, ttile_t tile, tdata_t buf, tsize_t size)
|
|
Packit Service |
db44fb |
{
|
|
Packit Service |
db44fb |
static const char module[] = "TIFFReadRawTile";
|
|
Packit Service |
db44fb |
TIFFDirectory *td = &tif->tif_dir;
|
|
Packit Service |
db44fb |
/*
|
|
Packit Service |
db44fb |
* FIXME: butecount should have tsize_t type, but for now libtiff
|
|
Packit Service |
db44fb |
* defines tsize_t as a signed 32-bit integer and we are losing
|
|
Packit Service |
db44fb |
* ability to read arrays larger than 2^31 bytes. So we are using
|
|
Packit Service |
db44fb |
* uint32 instead of tsize_t here.
|
|
Packit Service |
db44fb |
*/
|
|
Packit Service |
db44fb |
uint32 bytecount;
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
if (!TIFFCheckRead(tif, 1))
|
|
Packit Service |
db44fb |
return ((tsize_t) -1);
|
|
Packit Service |
db44fb |
if (tile >= td->td_nstrips) {
|
|
Packit Service |
db44fb |
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
|
|
Packit Service |
db44fb |
"%lu: Tile out of range, max %lu",
|
|
Packit Service |
db44fb |
(unsigned long) tile, (unsigned long) td->td_nstrips);
|
|
Packit Service |
db44fb |
return ((tsize_t) -1);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
if (tif->tif_flags&TIFF_NOREADRAW)
|
|
Packit Service |
db44fb |
{
|
|
Packit Service |
db44fb |
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
|
|
Packit Service |
db44fb |
"Compression scheme does not support access to raw uncompressed data");
|
|
Packit Service |
db44fb |
return ((tsize_t) -1);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
bytecount = td->td_stripbytecount[tile];
|
|
Packit Service |
db44fb |
if (size != (tsize_t) -1 && (uint32)size < bytecount)
|
|
Packit Service |
db44fb |
bytecount = size;
|
|
Packit Service |
db44fb |
return (TIFFReadRawTile1(tif, tile, buf, bytecount, module));
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
/*
|
|
Packit Service |
db44fb |
* Read the specified tile and setup for decoding. The data buffer is
|
|
Packit Service |
db44fb |
* expanded, as necessary, to hold the tile's data.
|
|
Packit Service |
db44fb |
*/
|
|
Packit Service |
db44fb |
int
|
|
Packit Service |
db44fb |
TIFFFillTile(TIFF* tif, ttile_t tile)
|
|
Packit Service |
db44fb |
{
|
|
Packit Service |
db44fb |
static const char module[] = "TIFFFillTile";
|
|
Packit Service |
db44fb |
TIFFDirectory *td = &tif->tif_dir;
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
if ((tif->tif_flags&TIFF_NOREADRAW)==0)
|
|
Packit Service |
db44fb |
{
|
|
Packit Service |
db44fb |
/*
|
|
Packit Service |
db44fb |
* FIXME: butecount should have tsize_t type, but for now
|
|
Packit Service |
db44fb |
* libtiff defines tsize_t as a signed 32-bit integer and we
|
|
Packit Service |
db44fb |
* are losing ability to read arrays larger than 2^31 bytes.
|
|
Packit Service |
db44fb |
* So we are using uint32 instead of tsize_t here.
|
|
Packit Service |
db44fb |
*/
|
|
Packit Service |
db44fb |
uint32 bytecount = td->td_stripbytecount[tile];
|
|
Packit Service |
db44fb |
if (bytecount <= 0) {
|
|
Packit Service |
db44fb |
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
|
|
Packit Service |
db44fb |
"%lu: Invalid tile byte count, tile %lu",
|
|
Packit Service |
db44fb |
(unsigned long) bytecount, (unsigned long) tile);
|
|
Packit Service |
db44fb |
return (0);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
if (isMapped(tif) &&
|
|
Packit Service |
db44fb |
(isFillOrder(tif, td->td_fillorder)
|
|
Packit Service |
db44fb |
|| (tif->tif_flags & TIFF_NOBITREV))) {
|
|
Packit Service |
db44fb |
/*
|
|
Packit Service |
db44fb |
* The image is mapped into memory and we either don't
|
|
Packit Service |
db44fb |
* need to flip bits or the compression routine is
|
|
Packit Service |
db44fb |
* going to handle this operation itself. In this
|
|
Packit Service |
db44fb |
* case, avoid copying the raw data and instead just
|
|
Packit Service |
db44fb |
* reference the data from the memory mapped file
|
|
Packit Service |
db44fb |
* image. This assumes that the decompression
|
|
Packit Service |
db44fb |
* routines do not modify the contents of the raw data
|
|
Packit Service |
db44fb |
* buffer (if they try to, the application will get a
|
|
Packit Service |
db44fb |
* fault since the file is mapped read-only).
|
|
Packit Service |
db44fb |
*/
|
|
Packit Service |
db44fb |
if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata)
|
|
Packit Service |
db44fb |
_TIFFfree(tif->tif_rawdata);
|
|
Packit Service |
db44fb |
tif->tif_flags &= ~TIFF_MYBUFFER;
|
|
Packit Service |
db44fb |
/*
|
|
Packit Service |
db44fb |
* We must check for overflow, potentially causing
|
|
Packit Service |
db44fb |
* an OOB read. Instead of simple
|
|
Packit Service |
db44fb |
*
|
|
Packit Service |
db44fb |
* td->td_stripoffset[tile]+bytecount > tif->tif_size
|
|
Packit Service |
db44fb |
*
|
|
Packit Service |
db44fb |
* comparison (which can overflow) we do the following
|
|
Packit Service |
db44fb |
* two comparisons:
|
|
Packit Service |
db44fb |
*/
|
|
Packit Service |
db44fb |
if (bytecount > tif->tif_size ||
|
|
Packit Service |
db44fb |
td->td_stripoffset[tile] > tif->tif_size - bytecount) {
|
|
Packit Service |
db44fb |
tif->tif_curtile = NOTILE;
|
|
Packit Service |
db44fb |
return (0);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
tif->tif_rawdatasize = bytecount;
|
|
Packit Service |
db44fb |
tif->tif_rawdata =
|
|
Packit Service |
db44fb |
tif->tif_base + td->td_stripoffset[tile];
|
|
Packit Service |
db44fb |
} else {
|
|
Packit Service |
db44fb |
/*
|
|
Packit Service |
db44fb |
* Expand raw data buffer, if needed, to hold data
|
|
Packit Service |
db44fb |
* tile coming from file (perhaps should set upper
|
|
Packit Service |
db44fb |
* bound on the size of a buffer we'll use?).
|
|
Packit Service |
db44fb |
*/
|
|
Packit Service |
db44fb |
if (bytecount > (uint32)tif->tif_rawdatasize) {
|
|
Packit Service |
db44fb |
tif->tif_curtile = NOTILE;
|
|
Packit Service |
db44fb |
if ((tif->tif_flags & TIFF_MYBUFFER) == 0) {
|
|
Packit Service |
db44fb |
TIFFErrorExt(tif->tif_clientdata,
|
|
Packit Service |
db44fb |
module,
|
|
Packit Service |
db44fb |
"%s: Data buffer too small to hold tile %ld",
|
|
Packit Service |
db44fb |
tif->tif_name,
|
|
Packit Service |
db44fb |
(long) tile);
|
|
Packit Service |
db44fb |
return (0);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
if (!TIFFReadBufferSetup(tif, 0,
|
|
Packit Service |
db44fb |
TIFFroundup(bytecount, 1024)))
|
|
Packit Service |
db44fb |
return (0);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
if ((uint32)TIFFReadRawTile1(tif, tile,
|
|
Packit Service |
db44fb |
(unsigned char *)tif->tif_rawdata,
|
|
Packit Service |
db44fb |
bytecount, module) != bytecount)
|
|
Packit Service |
db44fb |
return (0);
|
|
Packit Service |
db44fb |
if (!isFillOrder(tif, td->td_fillorder) &&
|
|
Packit Service |
db44fb |
(tif->tif_flags & TIFF_NOBITREV) == 0)
|
|
Packit Service |
db44fb |
TIFFReverseBits(tif->tif_rawdata, bytecount);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
return (TIFFStartTile(tif, tile));
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
/*
|
|
Packit Service |
db44fb |
* Setup the raw data buffer in preparation for
|
|
Packit Service |
db44fb |
* reading a strip of raw data. If the buffer
|
|
Packit Service |
db44fb |
* is specified as zero, then a buffer of appropriate
|
|
Packit Service |
db44fb |
* size is allocated by the library. Otherwise,
|
|
Packit Service |
db44fb |
* the client must guarantee that the buffer is
|
|
Packit Service |
db44fb |
* large enough to hold any individual strip of
|
|
Packit Service |
db44fb |
* raw data.
|
|
Packit Service |
db44fb |
*/
|
|
Packit Service |
db44fb |
int
|
|
Packit Service |
db44fb |
TIFFReadBufferSetup(TIFF* tif, tdata_t bp, tsize_t size)
|
|
Packit Service |
db44fb |
{
|
|
Packit Service |
db44fb |
static const char module[] = "TIFFReadBufferSetup";
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
assert((tif->tif_flags&TIFF_NOREADRAW)==0);
|
|
Packit Service |
db44fb |
if (tif->tif_rawdata) {
|
|
Packit Service |
db44fb |
if (tif->tif_flags & TIFF_MYBUFFER)
|
|
Packit Service |
db44fb |
_TIFFfree(tif->tif_rawdata);
|
|
Packit Service |
db44fb |
tif->tif_rawdata = NULL;
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
if (bp) {
|
|
Packit Service |
db44fb |
tif->tif_rawdatasize = size;
|
|
Packit Service |
db44fb |
tif->tif_rawdata = (tidata_t) bp;
|
|
Packit Service |
db44fb |
tif->tif_flags &= ~TIFF_MYBUFFER;
|
|
Packit Service |
db44fb |
} else {
|
|
Packit Service |
db44fb |
tif->tif_rawdatasize = TIFFroundup(size, 1024);
|
|
Packit Service |
db44fb |
if (tif->tif_rawdatasize > 0)
|
|
Packit Service |
db44fb |
tif->tif_rawdata = (tidata_t) _TIFFmalloc(tif->tif_rawdatasize);
|
|
Packit Service |
db44fb |
tif->tif_flags |= TIFF_MYBUFFER;
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
if ((tif->tif_rawdata == NULL) || (tif->tif_rawdatasize == 0)) {
|
|
Packit Service |
db44fb |
TIFFErrorExt(tif->tif_clientdata, module,
|
|
Packit Service |
db44fb |
"%s: No space for data buffer at scanline %ld",
|
|
Packit Service |
db44fb |
tif->tif_name, (long) tif->tif_row);
|
|
Packit Service |
db44fb |
tif->tif_rawdatasize = 0;
|
|
Packit Service |
db44fb |
return (0);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
return (1);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
/*
|
|
Packit Service |
db44fb |
* Set state to appear as if a
|
|
Packit Service |
db44fb |
* strip has just been read in.
|
|
Packit Service |
db44fb |
*/
|
|
Packit Service |
db44fb |
static int
|
|
Packit Service |
db44fb |
TIFFStartStrip(TIFF* tif, tstrip_t strip)
|
|
Packit Service |
db44fb |
{
|
|
Packit Service |
db44fb |
TIFFDirectory *td = &tif->tif_dir;
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
if ((tif->tif_flags & TIFF_CODERSETUP) == 0) {
|
|
Packit Service |
db44fb |
if (!(*tif->tif_setupdecode)(tif))
|
|
Packit Service |
db44fb |
return (0);
|
|
Packit Service |
db44fb |
tif->tif_flags |= TIFF_CODERSETUP;
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
tif->tif_curstrip = strip;
|
|
Packit Service |
db44fb |
tif->tif_row = (strip % td->td_stripsperimage) * td->td_rowsperstrip;
|
|
Packit Service |
db44fb |
if (tif->tif_flags&TIFF_NOREADRAW)
|
|
Packit Service |
db44fb |
{
|
|
Packit Service |
db44fb |
tif->tif_rawcp = NULL;
|
|
Packit Service |
db44fb |
tif->tif_rawcc = 0;
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
else
|
|
Packit Service |
db44fb |
{
|
|
Packit Service |
db44fb |
tif->tif_rawcp = tif->tif_rawdata;
|
|
Packit Service |
db44fb |
tif->tif_rawcc = td->td_stripbytecount[strip];
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
return ((*tif->tif_predecode)(tif,
|
|
Packit Service |
db44fb |
(tsample_t)(strip / td->td_stripsperimage)));
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
/*
|
|
Packit Service |
db44fb |
* Set state to appear as if a
|
|
Packit Service |
db44fb |
* tile has just been read in.
|
|
Packit Service |
db44fb |
*/
|
|
Packit Service |
db44fb |
static int
|
|
Packit Service |
db44fb |
TIFFStartTile(TIFF* tif, ttile_t tile)
|
|
Packit Service |
db44fb |
{
|
|
Packit Service |
db44fb |
TIFFDirectory *td = &tif->tif_dir;
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
if ((tif->tif_flags & TIFF_CODERSETUP) == 0) {
|
|
Packit Service |
db44fb |
if (!(*tif->tif_setupdecode)(tif))
|
|
Packit Service |
db44fb |
return (0);
|
|
Packit Service |
db44fb |
tif->tif_flags |= TIFF_CODERSETUP;
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
tif->tif_curtile = tile;
|
|
Packit Service |
db44fb |
tif->tif_row =
|
|
Packit Service |
db44fb |
(tile % TIFFhowmany(td->td_imagewidth, td->td_tilewidth)) *
|
|
Packit Service |
db44fb |
td->td_tilelength;
|
|
Packit Service |
db44fb |
tif->tif_col =
|
|
Packit Service |
db44fb |
(tile % TIFFhowmany(td->td_imagelength, td->td_tilelength)) *
|
|
Packit Service |
db44fb |
td->td_tilewidth;
|
|
Packit Service |
db44fb |
if (tif->tif_flags&TIFF_NOREADRAW)
|
|
Packit Service |
db44fb |
{
|
|
Packit Service |
db44fb |
tif->tif_rawcp = NULL;
|
|
Packit Service |
db44fb |
tif->tif_rawcc = 0;
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
else
|
|
Packit Service |
db44fb |
{
|
|
Packit Service |
db44fb |
tif->tif_rawcp = tif->tif_rawdata;
|
|
Packit Service |
db44fb |
tif->tif_rawcc = td->td_stripbytecount[tile];
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
return ((*tif->tif_predecode)(tif,
|
|
Packit Service |
db44fb |
(tsample_t)(tile/td->td_stripsperimage)));
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
static int
|
|
Packit Service |
db44fb |
TIFFCheckRead(TIFF* tif, int tiles)
|
|
Packit Service |
db44fb |
{
|
|
Packit Service |
db44fb |
if (tif->tif_mode == O_WRONLY) {
|
|
Packit Service |
db44fb |
TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "File not open for reading");
|
|
Packit Service |
db44fb |
return (0);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
if (tiles ^ isTiled(tif)) {
|
|
Packit Service |
db44fb |
TIFFErrorExt(tif->tif_clientdata, tif->tif_name, tiles ?
|
|
Packit Service |
db44fb |
"Can not read tiles from a stripped image" :
|
|
Packit Service |
db44fb |
"Can not read scanlines from a tiled image");
|
|
Packit Service |
db44fb |
return (0);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
return (1);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
void
|
|
Packit Service |
db44fb |
_TIFFNoPostDecode(TIFF* tif, tidata_t buf, tsize_t cc)
|
|
Packit Service |
db44fb |
{
|
|
Packit Service |
db44fb |
(void) tif; (void) buf; (void) cc;
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
void
|
|
Packit Service |
db44fb |
_TIFFSwab16BitData(TIFF* tif, tidata_t buf, tsize_t cc)
|
|
Packit Service |
db44fb |
{
|
|
Packit Service |
db44fb |
(void) tif;
|
|
Packit Service |
db44fb |
assert((cc & 1) == 0);
|
|
Packit Service |
db44fb |
TIFFSwabArrayOfShort((uint16*) buf, cc/2);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
void
|
|
Packit Service |
db44fb |
_TIFFSwab24BitData(TIFF* tif, tidata_t buf, tsize_t cc)
|
|
Packit Service |
db44fb |
{
|
|
Packit Service |
db44fb |
(void) tif;
|
|
Packit Service |
db44fb |
assert((cc % 3) == 0);
|
|
Packit Service |
db44fb |
TIFFSwabArrayOfTriples((uint8*) buf, cc/3);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
void
|
|
Packit Service |
db44fb |
_TIFFSwab32BitData(TIFF* tif, tidata_t buf, tsize_t cc)
|
|
Packit Service |
db44fb |
{
|
|
Packit Service |
db44fb |
(void) tif;
|
|
Packit Service |
db44fb |
assert((cc & 3) == 0);
|
|
Packit Service |
db44fb |
TIFFSwabArrayOfLong((uint32*) buf, cc/4);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
void
|
|
Packit Service |
db44fb |
_TIFFSwab64BitData(TIFF* tif, tidata_t buf, tsize_t cc)
|
|
Packit Service |
db44fb |
{
|
|
Packit Service |
db44fb |
(void) tif;
|
|
Packit Service |
db44fb |
assert((cc & 7) == 0);
|
|
Packit Service |
db44fb |
TIFFSwabArrayOfDouble((double*) buf, cc/8);
|
|
Packit Service |
db44fb |
}
|
|
Packit Service |
db44fb |
|
|
Packit Service |
db44fb |
/* vim: set ts=8 sts=8 sw=8 noet: */
|
|
Packit Service |
db44fb |
/*
|
|
Packit Service |
db44fb |
* Local Variables:
|
|
Packit Service |
db44fb |
* mode: c
|
|
Packit Service |
db44fb |
* c-basic-offset: 8
|
|
Packit Service |
db44fb |
* fill-column: 78
|
|
Packit Service |
db44fb |
* End:
|
|
Packit Service |
db44fb |
*/
|