* libtiff/tif_read.c: make TIFFReadEncodedStrip() and
TIFFReadEncodedTile() directly use user provided buffer when no compression (and other conditions) to save a memcpy(). * libtiff/tif_write.c: make TIFFWriteEncodedStrip() and TIFFWriteEncodedTile() directly use user provided buffer when no compression to save a memcpy().
This commit is contained in:
parent
33c391eff4
commit
b46aa51809
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
|||||||
|
2016-07-0333Even Rouault <even.rouault at spatialys.com>
|
||||||
|
|
||||||
|
* libtiff/tif_read.c: make TIFFReadEncodedStrip() and
|
||||||
|
TIFFReadEncodedTile() directly use user provided buffer when
|
||||||
|
no compression (and other conditions) to save a memcpy().
|
||||||
|
|
||||||
|
* libtiff/tif_write.c: make TIFFWriteEncodedStrip() and
|
||||||
|
TIFFWriteEncodedTile() directly use user provided buffer when
|
||||||
|
no compression to save a memcpy().
|
||||||
|
|
||||||
2016-07-01 Even Rouault <even.rouault at spatialys.com>
|
2016-07-01 Even Rouault <even.rouault at spatialys.com>
|
||||||
|
|
||||||
* libtiff/tif_luv.c: validate that for COMPRESSION_SGILOG and
|
* libtiff/tif_luv.c: validate that for COMPRESSION_SGILOG and
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $Id: tif_read.c,v 1.47 2016-01-03 10:01:25 erouault Exp $ */
|
/* $Id: tif_read.c,v 1.48 2016-07-03 16:02:17 erouault Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1988-1997 Sam Leffler
|
* Copyright (c) 1988-1997 Sam Leffler
|
||||||
@ -38,6 +38,8 @@ static int TIFFStartTile(TIFF* tif, uint32 tile);
|
|||||||
static int TIFFCheckRead(TIFF*, int);
|
static int TIFFCheckRead(TIFF*, int);
|
||||||
static tmsize_t
|
static tmsize_t
|
||||||
TIFFReadRawStrip1(TIFF* tif, uint32 strip, void* buf, tmsize_t size,const char* module);
|
TIFFReadRawStrip1(TIFF* tif, uint32 strip, void* buf, tmsize_t size,const char* module);
|
||||||
|
static tmsize_t
|
||||||
|
TIFFReadRawTile1(TIFF* tif, uint32 tile, void* buf, tmsize_t size, const char* module);
|
||||||
|
|
||||||
#define NOSTRIP ((uint32)(-1)) /* undefined state */
|
#define NOSTRIP ((uint32)(-1)) /* undefined state */
|
||||||
#define NOTILE ((uint32)(-1)) /* undefined state */
|
#define NOTILE ((uint32)(-1)) /* undefined state */
|
||||||
@ -350,6 +352,24 @@ TIFFReadEncodedStrip(TIFF* tif, uint32 strip, void* buf, tmsize_t size)
|
|||||||
stripsize=TIFFVStripSize(tif,rows);
|
stripsize=TIFFVStripSize(tif,rows);
|
||||||
if (stripsize==0)
|
if (stripsize==0)
|
||||||
return((tmsize_t)(-1));
|
return((tmsize_t)(-1));
|
||||||
|
|
||||||
|
/* shortcut to avoid an extra memcpy() */
|
||||||
|
if( td->td_compression == COMPRESSION_NONE &&
|
||||||
|
size!=(tmsize_t)(-1) && size >= stripsize &&
|
||||||
|
!isMapped(tif) &&
|
||||||
|
((tif->tif_flags&TIFF_NOREADRAW)==0) )
|
||||||
|
{
|
||||||
|
if (TIFFReadRawStrip1(tif, strip, buf, stripsize, module) != stripsize)
|
||||||
|
return ((tmsize_t)(-1));
|
||||||
|
|
||||||
|
if (!isFillOrder(tif, td->td_fillorder) &&
|
||||||
|
(tif->tif_flags & TIFF_NOBITREV) == 0)
|
||||||
|
TIFFReverseBits(buf,stripsize);
|
||||||
|
|
||||||
|
(*tif->tif_postdecode)(tif,buf,stripsize);
|
||||||
|
return (stripsize);
|
||||||
|
}
|
||||||
|
|
||||||
if ((size!=(tmsize_t)(-1))&&(size<stripsize))
|
if ((size!=(tmsize_t)(-1))&&(size<stripsize))
|
||||||
stripsize=size;
|
stripsize=size;
|
||||||
if (!TIFFFillStrip(tif,strip))
|
if (!TIFFFillStrip(tif,strip))
|
||||||
@ -661,6 +681,24 @@ TIFFReadEncodedTile(TIFF* tif, uint32 tile, void* buf, tmsize_t size)
|
|||||||
(unsigned long) tile, (unsigned long) td->td_nstrips);
|
(unsigned long) tile, (unsigned long) td->td_nstrips);
|
||||||
return ((tmsize_t)(-1));
|
return ((tmsize_t)(-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* shortcut to avoid an extra memcpy() */
|
||||||
|
if( td->td_compression == COMPRESSION_NONE &&
|
||||||
|
size!=(tmsize_t)(-1) && size >= tilesize &&
|
||||||
|
!isMapped(tif) &&
|
||||||
|
((tif->tif_flags&TIFF_NOREADRAW)==0) )
|
||||||
|
{
|
||||||
|
if (TIFFReadRawTile1(tif, tile, buf, tilesize, module) != tilesize)
|
||||||
|
return ((tmsize_t)(-1));
|
||||||
|
|
||||||
|
if (!isFillOrder(tif, td->td_fillorder) &&
|
||||||
|
(tif->tif_flags & TIFF_NOBITREV) == 0)
|
||||||
|
TIFFReverseBits(buf,tilesize);
|
||||||
|
|
||||||
|
(*tif->tif_postdecode)(tif,buf,tilesize);
|
||||||
|
return (tilesize);
|
||||||
|
}
|
||||||
|
|
||||||
if (size == (tmsize_t)(-1))
|
if (size == (tmsize_t)(-1))
|
||||||
size = tilesize;
|
size = tilesize;
|
||||||
else if (size > tilesize)
|
else if (size > tilesize)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $Id: tif_write.c,v 1.43 2015-12-12 18:04:26 erouault Exp $ */
|
/* $Id: tif_write.c,v 1.44 2016-07-03 16:02:17 erouault Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1988-1997 Sam Leffler
|
* Copyright (c) 1988-1997 Sam Leffler
|
||||||
@ -258,6 +258,23 @@ TIFFWriteEncodedStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc)
|
|||||||
tif->tif_rawcp = tif->tif_rawdata;
|
tif->tif_rawcp = tif->tif_rawdata;
|
||||||
|
|
||||||
tif->tif_flags &= ~TIFF_POSTENCODE;
|
tif->tif_flags &= ~TIFF_POSTENCODE;
|
||||||
|
|
||||||
|
/* shortcut to avoid an extra memcpy() */
|
||||||
|
if( td->td_compression == COMPRESSION_NONE )
|
||||||
|
{
|
||||||
|
/* swab if needed - note that source buffer will be altered */
|
||||||
|
tif->tif_postdecode( tif, (uint8*) data, cc );
|
||||||
|
|
||||||
|
if (!isFillOrder(tif, td->td_fillorder) &&
|
||||||
|
(tif->tif_flags & TIFF_NOBITREV) == 0)
|
||||||
|
TIFFReverseBits((uint8*) data, cc);
|
||||||
|
|
||||||
|
if (cc > 0 &&
|
||||||
|
!TIFFAppendToStrip(tif, strip, (uint8*) data, cc))
|
||||||
|
return ((tmsize_t) -1);
|
||||||
|
return (cc);
|
||||||
|
}
|
||||||
|
|
||||||
sample = (uint16)(strip / td->td_stripsperimage);
|
sample = (uint16)(strip / td->td_stripsperimage);
|
||||||
if (!(*tif->tif_preencode)(tif, sample))
|
if (!(*tif->tif_preencode)(tif, sample))
|
||||||
return ((tmsize_t) -1);
|
return ((tmsize_t) -1);
|
||||||
@ -431,9 +448,7 @@ TIFFWriteEncodedTile(TIFF* tif, uint32 tile, void* data, tmsize_t cc)
|
|||||||
tif->tif_flags |= TIFF_CODERSETUP;
|
tif->tif_flags |= TIFF_CODERSETUP;
|
||||||
}
|
}
|
||||||
tif->tif_flags &= ~TIFF_POSTENCODE;
|
tif->tif_flags &= ~TIFF_POSTENCODE;
|
||||||
sample = (uint16)(tile/td->td_stripsperimage);
|
|
||||||
if (!(*tif->tif_preencode)(tif, sample))
|
|
||||||
return ((tmsize_t)(-1));
|
|
||||||
/*
|
/*
|
||||||
* Clamp write amount to the tile size. This is mostly
|
* Clamp write amount to the tile size. This is mostly
|
||||||
* done so that callers can pass in some large number
|
* done so that callers can pass in some large number
|
||||||
@ -442,6 +457,25 @@ TIFFWriteEncodedTile(TIFF* tif, uint32 tile, void* data, tmsize_t cc)
|
|||||||
if ( cc < 1 || cc > tif->tif_tilesize)
|
if ( cc < 1 || cc > tif->tif_tilesize)
|
||||||
cc = tif->tif_tilesize;
|
cc = tif->tif_tilesize;
|
||||||
|
|
||||||
|
/* shortcut to avoid an extra memcpy() */
|
||||||
|
if( td->td_compression == COMPRESSION_NONE )
|
||||||
|
{
|
||||||
|
/* swab if needed - note that source buffer will be altered */
|
||||||
|
tif->tif_postdecode( tif, (uint8*) data, cc );
|
||||||
|
|
||||||
|
if (!isFillOrder(tif, td->td_fillorder) &&
|
||||||
|
(tif->tif_flags & TIFF_NOBITREV) == 0)
|
||||||
|
TIFFReverseBits((uint8*) data, cc);
|
||||||
|
|
||||||
|
if (cc > 0 &&
|
||||||
|
!TIFFAppendToStrip(tif, tile, (uint8*) data, cc))
|
||||||
|
return ((tmsize_t) -1);
|
||||||
|
return (cc);
|
||||||
|
}
|
||||||
|
|
||||||
|
sample = (uint16)(tile/td->td_stripsperimage);
|
||||||
|
if (!(*tif->tif_preencode)(tif, sample))
|
||||||
|
return ((tmsize_t)(-1));
|
||||||
/* swab if needed - note that source buffer will be altered */
|
/* swab if needed - note that source buffer will be altered */
|
||||||
tif->tif_postdecode( tif, (uint8*) data, cc );
|
tif->tif_postdecode( tif, (uint8*) data, cc );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user