upgraded libtiff to 3.6.1 + security fixes (patch from Tim Kosse)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30659 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -45,6 +45,7 @@
|
||||
src/tiff/tif_aux.c
|
||||
src/tiff/tif_close.c
|
||||
src/tiff/tif_codec.c
|
||||
src/tiff/tif_color.c
|
||||
src/tiff/tif_compress.c
|
||||
src/tiff/tif_dir.c
|
||||
src/tiff/tif_dirinfo.c
|
||||
|
@@ -1 +1 @@
|
||||
3.5.2
|
||||
3.6.1-2
|
||||
|
@@ -1,50 +1,93 @@
|
||||
#
|
||||
# Simple MS VC++ Makefile
|
||||
#
|
||||
# To build:
|
||||
# C:\libtiff\libtiff> nmake /f makefile.vc all
|
||||
#
|
||||
|
||||
!if "$(FINAL)" == "1"
|
||||
LIBTARGET=$(WXDIR)\lib\tiff.lib
|
||||
!else if "$(FINAL)" == "hybrid"
|
||||
LIBTARGET=$(WXDIR)\lib\tiffh.lib
|
||||
!else
|
||||
LIBTARGET=$(WXDIR)\lib\tiffd.lib
|
||||
!endif
|
||||
#
|
||||
# Select _CONSOLE to build a library which reports errors to stderr, or
|
||||
# _WINDOWED to build such that errors are reported via MessageBox().
|
||||
#
|
||||
WINMODE = -DTIF_PLATFORM_CONSOLE
|
||||
#WINMODE = -DTIF_PLATFORM_WINDOWED
|
||||
|
||||
OBJECTS= \
|
||||
$D\tif_aux.obj \
|
||||
$D\tif_close.obj \
|
||||
$D\tif_codec.obj \
|
||||
$D\tif_compress.obj \
|
||||
$D\tif_dir.obj \
|
||||
$D\tif_dirinfo.obj \
|
||||
$D\tif_dirread.obj \
|
||||
$D\tif_dirwrite.obj \
|
||||
$D\tif_dumpmode.obj \
|
||||
$D\tif_error.obj \
|
||||
$D\tif_fax3.obj \
|
||||
$D\tif_fax3sm.obj \
|
||||
$D\tif_flush.obj \
|
||||
$D\tif_getimage.obj \
|
||||
$D\tif_jpeg.obj \
|
||||
$D\tif_luv.obj \
|
||||
$D\tif_lzw.obj \
|
||||
$D\tif_next.obj \
|
||||
$D\tif_open.obj \
|
||||
$D\tif_packbits.obj \
|
||||
$D\tif_pixarlog.obj \
|
||||
$D\tif_predict.obj \
|
||||
$D\tif_print.obj \
|
||||
$D\tif_read.obj \
|
||||
$D\tif_strip.obj \
|
||||
$D\tif_swab.obj \
|
||||
$D\tif_thunder.obj \
|
||||
$D\tif_tile.obj \
|
||||
$D\tif_version.obj \
|
||||
$D\tif_warning.obj \
|
||||
$D\tif_win32.obj \
|
||||
$D\tif_write.obj \
|
||||
$D\tif_zip.obj \
|
||||
# Uncomment and edit following lines to enable JPEG support
|
||||
#JPEG_SUPPORT = 1
|
||||
#JPEGDIR = d:/projects/jpeg-6b
|
||||
|
||||
CC = cl
|
||||
INCL = -I.
|
||||
LIBS =
|
||||
EXTRAFLAGS =
|
||||
|
||||
!IFDEF JPEG_SUPPORT
|
||||
INCL = $(INCL) -I$(JPEGDIR)
|
||||
EXTRAFLAGS = $(EXTRAFLAGS) -DJPEG_SUPPORT
|
||||
!ENDIF
|
||||
|
||||
CFLAGS = /nologo /W3 $(INCL) $(WINMODE) $(EXTRAFLAGS)
|
||||
|
||||
OBJ = \
|
||||
tif_aux.obj \
|
||||
tif_close.obj \
|
||||
tif_codec.obj \
|
||||
tif_color.obj \
|
||||
tif_compress.obj \
|
||||
tif_dir.obj \
|
||||
tif_dirinfo.obj \
|
||||
tif_dirread.obj \
|
||||
tif_dirwrite.obj \
|
||||
tif_dumpmode.obj \
|
||||
tif_error.obj \
|
||||
tif_extension.obj \
|
||||
tif_fax3.obj \
|
||||
fax3sm_winnt.obj \
|
||||
tif_getimage.obj \
|
||||
tif_jpeg.obj \
|
||||
tif_ojpeg.obj \
|
||||
tif_flush.obj \
|
||||
tif_luv.obj \
|
||||
tif_lzw.obj \
|
||||
tif_next.obj \
|
||||
tif_open.obj \
|
||||
tif_packbits.obj \
|
||||
tif_pixarlog.obj \
|
||||
tif_predict.obj \
|
||||
tif_print.obj \
|
||||
tif_read.obj \
|
||||
tif_swab.obj \
|
||||
tif_strip.obj \
|
||||
tif_thunder.obj \
|
||||
tif_tile.obj \
|
||||
tif_win32.obj \
|
||||
tif_version.obj \
|
||||
tif_warning.obj \
|
||||
tif_write.obj \
|
||||
tif_zip.obj
|
||||
|
||||
VERSION = ..\VERSION
|
||||
ALPHA = ..\dist\tiff.alpha
|
||||
|
||||
default: libtiff.lib
|
||||
|
||||
all: libtiff.lib libtiff.dll
|
||||
|
||||
libtiff.lib: tiffvers.h $(OBJ)
|
||||
lib /out:libtiff.lib $(OBJ)
|
||||
|
||||
libtiff.dll: $(OBJ)
|
||||
link /dll /def:libtiff.def /out:libtiff.dll /implib:libtiff_i.lib \
|
||||
$(OBJ) $(LIBS)
|
||||
|
||||
tiffvers.h: $(VERSION) mkversion.c
|
||||
$(CC) mkversion.c
|
||||
if exist tiffvers.h del tiffvers.h
|
||||
.\mkversion.exe -v $(VERSION) tiffvers.h
|
||||
|
||||
clean:
|
||||
del *.obj *.lib libtiff.dll
|
||||
|
||||
tif_version.obj: tiffvers.h
|
||||
|
||||
|
||||
|
||||
# Pull in standard variable definitions
|
||||
|
||||
!include ..\makelib.vc
|
||||
|
||||
|
@@ -39,21 +39,19 @@
|
||||
* Create below fills in a blank creator signature and sets the file type
|
||||
* to 'TIFF'. It is much better for the application to do this by Create'ing
|
||||
* the file first and TIFFOpen'ing it later.
|
||||
* ---------
|
||||
* This code has been "Carbonized", and may not work with older MacOS versions.
|
||||
* If so, grab the tif_apple.c out of an older libtiff distribution, like
|
||||
* 3.5.5 from www.libtiff.org.
|
||||
*/
|
||||
|
||||
#ifdef __MACH__
|
||||
#include <ansi_prefix.mach.h>
|
||||
#include <msl_c_version.h>
|
||||
#include <stdint.h>
|
||||
#undef WCHAR_MAX
|
||||
#include <machine/ansi.h>
|
||||
#endif
|
||||
#include "tiffiop.h"
|
||||
#include <MacErrors.h>
|
||||
#include <Errors.h>
|
||||
#include <Files.h>
|
||||
#include <Memory.h>
|
||||
#include <Script.h>
|
||||
|
||||
#if defined(__PPCC__) || defined(__SYMANTEC__) || defined(__MRC__) || defined(applec)
|
||||
#if defined(__PPCC__) || defined(__SC__) || defined(__MRC__) || defined(applec)
|
||||
#define CtoPstr c2pstr
|
||||
#endif
|
||||
|
||||
@@ -149,6 +147,13 @@ TIFFFdOpen(int fd, const char* name, const char* mode)
|
||||
return (tif);
|
||||
}
|
||||
|
||||
static void ourc2pstr( char* inString )
|
||||
{
|
||||
int sLen = strlen( inString );
|
||||
BlockMoveData( inString, &inString[1], sLen );
|
||||
inString[0] = sLen;
|
||||
}
|
||||
|
||||
/*
|
||||
* Open a TIFF file for read/writing.
|
||||
*/
|
||||
@@ -160,32 +165,38 @@ TIFFOpen(const char* name, const char* mode)
|
||||
FInfo finfo;
|
||||
short fref;
|
||||
OSErr err;
|
||||
FSSpec fSpec;
|
||||
|
||||
strcpy((char*) pname, name);
|
||||
CtoPstr((char*) pname);
|
||||
ourc2pstr((char*) pname);
|
||||
|
||||
err = FSMakeFSSpec( 0, 0, pname, &fSpec );
|
||||
|
||||
switch (_TIFFgetMode(mode, module)) {
|
||||
default:
|
||||
return ((TIFF*) 0);
|
||||
case O_RDWR | O_CREAT | O_TRUNC:
|
||||
if (GetFInfo(pname, 0, &finfo) == noErr)
|
||||
FSDelete(pname, 0);
|
||||
if (FSpGetFInfo(&fSpec, &finfo) == noErr)
|
||||
FSpDelete(&fSpec);
|
||||
/* fall through */
|
||||
case O_RDWR | O_CREAT:
|
||||
if ((err = GetFInfo(pname, 0, &finfo)) == fnfErr) {
|
||||
if (Create(pname, 0, ' ', 'TIFF') != noErr)
|
||||
if ((err = FSpGetFInfo(&fSpec, &finfo)) == fnfErr) {
|
||||
if (FSpCreate(&fSpec, ' ', 'TIFF', smSystemScript) != noErr)
|
||||
goto badCreate;
|
||||
if (FSOpen(pname, 0, &fref) != noErr)
|
||||
if (FSpOpenDF(&fSpec, fsRdWrPerm, &fref) != noErr)
|
||||
goto badOpen;
|
||||
} else if (err == noErr) {
|
||||
if (FSOpen(pname, 0, &fref) != noErr)
|
||||
if (FSpOpenDF(&fSpec, fsRdWrPerm, &fref) != noErr)
|
||||
goto badOpen;
|
||||
} else
|
||||
goto badOpen;
|
||||
break;
|
||||
case O_RDONLY:
|
||||
if (FSpOpenDF(&fSpec, fsRdPerm, &fref) != noErr)
|
||||
goto badOpen;
|
||||
break;
|
||||
case O_RDWR:
|
||||
if (FSOpen(pname, 0, &fref) != noErr)
|
||||
if (FSpOpenDF(&fSpec, fsRdWrPerm, &fref) != noErr)
|
||||
goto badOpen;
|
||||
break;
|
||||
}
|
||||
|
@@ -30,42 +30,63 @@
|
||||
* Auxiliary Support Routines.
|
||||
*/
|
||||
#include "tiffiop.h"
|
||||
|
||||
#ifdef COLORIMETRY_SUPPORT
|
||||
#include "tif_predict.h"
|
||||
#include <math.h>
|
||||
|
||||
static void
|
||||
static int
|
||||
TIFFDefaultTransferFunction(TIFFDirectory* td)
|
||||
{
|
||||
uint16 **tf = td->td_transferfunction;
|
||||
long i, n = 1<<td->td_bitspersample;
|
||||
tsize_t i, n, nbytes;
|
||||
|
||||
tf[0] = (uint16 *)_TIFFmalloc(n * sizeof (uint16));
|
||||
tf[0] = tf[1] = tf[2] = 0;
|
||||
if (td->td_bitspersample >= sizeof(tsize_t) * 8 - 2)
|
||||
return 0;
|
||||
|
||||
n = 1<<td->td_bitspersample;
|
||||
nbytes = n * sizeof (uint16);
|
||||
if (!(tf[0] = (uint16 *)_TIFFmalloc(nbytes)))
|
||||
return 0;
|
||||
tf[0][0] = 0;
|
||||
for (i = 1; i < n; i++) {
|
||||
double t = (double)i/((double) n-1.);
|
||||
tf[0][i] = (uint16)floor(65535.*pow(t, 2.2) + .5);
|
||||
}
|
||||
|
||||
if (td->td_samplesperpixel - td->td_extrasamples > 1) {
|
||||
tf[1] = (uint16 *)_TIFFmalloc(n * sizeof (uint16));
|
||||
_TIFFmemcpy(tf[1], tf[0], n * sizeof (uint16));
|
||||
tf[2] = (uint16 *)_TIFFmalloc(n * sizeof (uint16));
|
||||
_TIFFmemcpy(tf[2], tf[0], n * sizeof (uint16));
|
||||
if (!(tf[1] = (uint16 *)_TIFFmalloc(nbytes)))
|
||||
goto bad;
|
||||
_TIFFmemcpy(tf[1], tf[0], nbytes);
|
||||
if (!(tf[2] = (uint16 *)_TIFFmalloc(nbytes)))
|
||||
goto bad;
|
||||
_TIFFmemcpy(tf[2], tf[0], nbytes);
|
||||
}
|
||||
return 1;
|
||||
|
||||
bad:
|
||||
if (tf[0])
|
||||
_TIFFfree(tf[0]);
|
||||
if (tf[1])
|
||||
_TIFFfree(tf[1]);
|
||||
if (tf[2])
|
||||
_TIFFfree(tf[2]);
|
||||
tf[0] = tf[1] = tf[2] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
static int
|
||||
TIFFDefaultRefBlackWhite(TIFFDirectory* td)
|
||||
{
|
||||
int i;
|
||||
|
||||
td->td_refblackwhite = (float *)_TIFFmalloc(6*sizeof (float));
|
||||
if (!(td->td_refblackwhite = (float *)_TIFFmalloc(6*sizeof (float))))
|
||||
return 0;
|
||||
for (i = 0; i < 3; i++) {
|
||||
td->td_refblackwhite[2*i+0] = 0;
|
||||
td->td_refblackwhite[2*i+1] = (float)((1L<<td->td_bitspersample)-1L);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Like TIFFGetField, but return any default
|
||||
@@ -116,7 +137,12 @@ TIFFVGetFieldDefaulted(TIFF* tif, ttag_t tag, va_list ap)
|
||||
case TIFFTAG_RESOLUTIONUNIT:
|
||||
*va_arg(ap, uint16 *) = td->td_resolutionunit;
|
||||
return (1);
|
||||
#ifdef CMYK_SUPPORT
|
||||
case TIFFTAG_PREDICTOR:
|
||||
{
|
||||
TIFFPredictorState* sp = (TIFFPredictorState*) tif->tif_data;
|
||||
*va_arg(ap, uint16*) = (uint16) sp->predictor;
|
||||
return (1);
|
||||
}
|
||||
case TIFFTAG_DOTRANGE:
|
||||
*va_arg(ap, uint16 *) = 0;
|
||||
*va_arg(ap, uint16 *) = (1<<td->td_bitspersample)-1;
|
||||
@@ -127,7 +153,6 @@ TIFFVGetFieldDefaulted(TIFF* tif, ttag_t tag, va_list ap)
|
||||
case TIFFTAG_NUMBEROFINKS:
|
||||
*va_arg(ap, uint16 *) = td->td_ninks;
|
||||
return (1);
|
||||
#endif
|
||||
case TIFFTAG_EXTRASAMPLES:
|
||||
*va_arg(ap, uint16 *) = td->td_extrasamples;
|
||||
*va_arg(ap, uint16 **) = td->td_sampleinfo;
|
||||
@@ -143,14 +168,18 @@ TIFFVGetFieldDefaulted(TIFF* tif, ttag_t tag, va_list ap)
|
||||
case TIFFTAG_DATATYPE:
|
||||
*va_arg(ap, uint16 *) = td->td_sampleformat-1;
|
||||
return (1);
|
||||
case TIFFTAG_SAMPLEFORMAT:
|
||||
*va_arg(ap, uint16 *) = td->td_sampleformat;
|
||||
return(1);
|
||||
case TIFFTAG_IMAGEDEPTH:
|
||||
*va_arg(ap, uint32 *) = td->td_imagedepth;
|
||||
return (1);
|
||||
#ifdef YCBCR_SUPPORT
|
||||
case TIFFTAG_YCBCRCOEFFICIENTS:
|
||||
if (!td->td_ycbcrcoeffs) {
|
||||
td->td_ycbcrcoeffs = (float *)
|
||||
_TIFFmalloc(3*sizeof (float));
|
||||
if (!td->td_ycbcrcoeffs)
|
||||
return (0);
|
||||
/* defaults are from CCIR Recommendation 601-1 */
|
||||
td->td_ycbcrcoeffs[0] = 0.299f;
|
||||
td->td_ycbcrcoeffs[1] = 0.587f;
|
||||
@@ -165,11 +194,28 @@ TIFFVGetFieldDefaulted(TIFF* tif, ttag_t tag, va_list ap)
|
||||
case TIFFTAG_YCBCRPOSITIONING:
|
||||
*va_arg(ap, uint16 *) = td->td_ycbcrpositioning;
|
||||
return (1);
|
||||
#endif
|
||||
#ifdef COLORIMETRY_SUPPORT
|
||||
case TIFFTAG_WHITEPOINT:
|
||||
if (!td->td_whitepoint) {
|
||||
td->td_whitepoint = (float *)
|
||||
_TIFFmalloc(2 * sizeof (float));
|
||||
if (!td->td_whitepoint)
|
||||
return (0);
|
||||
/* TIFF 6.0 specification says that it is no default
|
||||
value for the WhitePoint, but AdobePhotoshop TIFF
|
||||
Technical Note tells that it should be CIE D50. */
|
||||
td->td_whitepoint[0] =
|
||||
D50_X0 / (D50_X0 + D50_Y0 + D50_Z0);
|
||||
td->td_whitepoint[1] =
|
||||
D50_Y0 / (D50_X0 + D50_Y0 + D50_Z0);
|
||||
}
|
||||
*va_arg(ap, float **) = td->td_whitepoint;
|
||||
return (1);
|
||||
case TIFFTAG_TRANSFERFUNCTION:
|
||||
if (!td->td_transferfunction[0])
|
||||
TIFFDefaultTransferFunction(td);
|
||||
if (!td->td_transferfunction[0] &&
|
||||
!TIFFDefaultTransferFunction(td)) {
|
||||
TIFFError(tif->tif_name, "No space for \"TransferFunction\" tag");
|
||||
return (0);
|
||||
}
|
||||
*va_arg(ap, uint16 **) = td->td_transferfunction[0];
|
||||
if (td->td_samplesperpixel - td->td_extrasamples > 1) {
|
||||
*va_arg(ap, uint16 **) = td->td_transferfunction[1];
|
||||
@@ -177,11 +223,10 @@ TIFFVGetFieldDefaulted(TIFF* tif, ttag_t tag, va_list ap)
|
||||
}
|
||||
return (1);
|
||||
case TIFFTAG_REFERENCEBLACKWHITE:
|
||||
if (!td->td_refblackwhite)
|
||||
TIFFDefaultRefBlackWhite(td);
|
||||
if (!td->td_refblackwhite && !TIFFDefaultRefBlackWhite(td))
|
||||
return (0);
|
||||
*va_arg(ap, float **) = td->td_refblackwhite;
|
||||
return (1);
|
||||
#endif
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
@@ -32,19 +32,49 @@
|
||||
void
|
||||
TIFFClose(TIFF* tif)
|
||||
{
|
||||
if (tif->tif_mode != O_RDONLY)
|
||||
/*
|
||||
* Flush buffered data and directory (if dirty).
|
||||
*/
|
||||
TIFFFlush(tif);
|
||||
(*tif->tif_cleanup)(tif);
|
||||
TIFFFreeDirectory(tif);
|
||||
if (tif->tif_rawdata && (tif->tif_flags&TIFF_MYBUFFER))
|
||||
_TIFFfree(tif->tif_rawdata);
|
||||
if (isMapped(tif))
|
||||
TIFFUnmapFileContents(tif, tif->tif_base, tif->tif_size);
|
||||
(void) TIFFCloseFile(tif);
|
||||
if (tif->tif_fieldinfo)
|
||||
_TIFFfree(tif->tif_fieldinfo);
|
||||
_TIFFfree(tif);
|
||||
if (tif->tif_mode != O_RDONLY)
|
||||
/*
|
||||
* Flush buffered data and directory (if dirty).
|
||||
*/
|
||||
TIFFFlush(tif);
|
||||
(*tif->tif_cleanup)(tif);
|
||||
TIFFFreeDirectory(tif);
|
||||
|
||||
if (tif->tif_dirlist)
|
||||
_TIFFfree(tif->tif_dirlist);
|
||||
|
||||
/* Clean up client info links */
|
||||
while( tif->tif_clientinfo )
|
||||
{
|
||||
TIFFClientInfoLink *link = tif->tif_clientinfo;
|
||||
|
||||
tif->tif_clientinfo = link->next;
|
||||
_TIFFfree( link->name );
|
||||
_TIFFfree( link );
|
||||
}
|
||||
|
||||
if (tif->tif_rawdata && (tif->tif_flags&TIFF_MYBUFFER))
|
||||
_TIFFfree(tif->tif_rawdata);
|
||||
if (isMapped(tif))
|
||||
TIFFUnmapFileContents(tif, tif->tif_base, tif->tif_size);
|
||||
(void) TIFFCloseFile(tif);
|
||||
if (tif->tif_nfields > 0)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < tif->tif_nfields; i++)
|
||||
{
|
||||
TIFFFieldInfo *fld = tif->tif_fieldinfo[i];
|
||||
if (fld->field_bit == FIELD_CUSTOM &&
|
||||
strncmp("Tag ", fld->field_name, 4) == 0)
|
||||
{
|
||||
_TIFFfree(fld->field_name);
|
||||
_TIFFfree(fld);
|
||||
}
|
||||
}
|
||||
|
||||
_TIFFfree(tif->tif_fieldinfo);
|
||||
}
|
||||
|
||||
_TIFFfree(tif);
|
||||
}
|
||||
|
@@ -4,23 +4,23 @@
|
||||
* Copyright (c) 1988-1997 Sam Leffler
|
||||
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* its documentation for any purpose is hereby granted without fee, provided
|
||||
* that (i) the above copyright notices and this permission notice appear in
|
||||
* all copies of the software and related documentation, and (ii) the names of
|
||||
* Sam Leffler and Silicon Graphics may not be used in any advertising or
|
||||
* publicity relating to the software without the specific, prior written
|
||||
* permission of Sam Leffler and Silicon Graphics.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
|
||||
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
|
||||
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
||||
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
||||
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
*/
|
||||
#include "tiffiop.h"
|
||||
|
||||
static int LINKAGEMODE NotConfigured(TIFF*, int);
|
||||
static int NotConfigured(TIFF*, int);
|
||||
|
||||
#ifndef LZW_SUPPORT
|
||||
#define TIFFInitLZW NotConfigured
|
||||
@@ -91,6 +91,7 @@ TIFFCodec _TIFFBuiltinCODECS[] = {
|
||||
{ "CCITT Group 4", COMPRESSION_CCITTFAX4, TIFFInitCCITTFax4 },
|
||||
{ "ISO JBIG", COMPRESSION_JBIG, TIFFInitJBIG },
|
||||
{ "Deflate", COMPRESSION_DEFLATE, TIFFInitZIP },
|
||||
{ "AdobeDeflate", COMPRESSION_ADOBE_DEFLATE , TIFFInitZIP },
|
||||
{ "PixarLog", COMPRESSION_PIXARLOG, TIFFInitPixarLog },
|
||||
{ "SGILog", COMPRESSION_SGILOG, TIFFInitSGILog },
|
||||
{ "SGILog24", COMPRESSION_SGILOG24, TIFFInitSGILog },
|
||||
@@ -107,10 +108,43 @@ _notConfigured(TIFF* tif)
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int LINKAGEMODE
|
||||
static int
|
||||
NotConfigured(TIFF* tif, int scheme)
|
||||
{
|
||||
tif->tif_setupdecode = _notConfigured;
|
||||
tif->tif_setupencode = _notConfigured;
|
||||
return (1);
|
||||
(void) scheme;
|
||||
|
||||
tif->tif_decodestatus = FALSE;
|
||||
tif->tif_setupdecode = _notConfigured;
|
||||
tif->tif_encodestatus = FALSE;
|
||||
tif->tif_setupencode = _notConfigured;
|
||||
return (1);
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
/* TIFFIsCODECConfigured() */
|
||||
/************************************************************************/
|
||||
|
||||
/**
|
||||
* Check whether we have working codec for the specific coding scheme.
|
||||
*
|
||||
* @return returns 1 if the codec is configured and working. Otherwise
|
||||
* 0 will be returned.
|
||||
*/
|
||||
|
||||
int
|
||||
TIFFIsCODECConfigured(uint16 scheme)
|
||||
{
|
||||
const TIFFCodec* codec = TIFFFindCODEC(scheme);
|
||||
|
||||
if(codec == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if(codec->init == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if(codec->init != NotConfigured){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -4,23 +4,23 @@
|
||||
* Copyright (c) 1988-1997 Sam Leffler
|
||||
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* its documentation for any purpose is hereby granted without fee, provided
|
||||
* that (i) the above copyright notices and this permission notice appear in
|
||||
* all copies of the software and related documentation, and (ii) the names of
|
||||
* Sam Leffler and Silicon Graphics may not be used in any advertising or
|
||||
* publicity relating to the software without the specific, prior written
|
||||
* permission of Sam Leffler and Silicon Graphics.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
|
||||
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
|
||||
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
||||
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
||||
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
@@ -36,13 +36,21 @@ TIFFNoEncode(TIFF* tif, char* method)
|
||||
{
|
||||
const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression);
|
||||
|
||||
if (c)
|
||||
TIFFError(tif->tif_name, "%s %s encoding is not implemented",
|
||||
c->name, method);
|
||||
else
|
||||
if (c) {
|
||||
if (! strncmp(c->name, "LZW", 3) ){
|
||||
TIFFError(tif->tif_name,
|
||||
"%s %s encoding is no longer implemented due to Unisys patent enforcement",
|
||||
c->name, method);
|
||||
} else {
|
||||
TIFFError(tif->tif_name, "%s %s encoding is not implemented",
|
||||
c->name, method);
|
||||
}
|
||||
}
|
||||
else {
|
||||
TIFFError(tif->tif_name,
|
||||
"Compression scheme %u %s encoding is not implemented",
|
||||
"Compression scheme %u %s encoding is not implemented",
|
||||
tif->tif_dir.td_compression, method);
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
|
||||
@@ -122,14 +130,16 @@ _TIFFNoPreCode(TIFF* tif, tsample_t s)
|
||||
static int _TIFFtrue(TIFF* tif) { (void) tif; return (1); }
|
||||
static void _TIFFvoid(TIFF* tif) { (void) tif; }
|
||||
|
||||
void LINKAGEMODE
|
||||
void
|
||||
_TIFFSetDefaultCompressionState(TIFF* tif)
|
||||
{
|
||||
tif->tif_decodestatus = TRUE;
|
||||
tif->tif_setupdecode = _TIFFtrue;
|
||||
tif->tif_predecode = _TIFFNoPreCode;
|
||||
tif->tif_decoderow = _TIFFNoRowDecode;
|
||||
tif->tif_decodestrip = _TIFFNoStripDecode;
|
||||
tif->tif_decodetile = _TIFFNoTileDecode;
|
||||
tif->tif_encodestatus = TRUE;
|
||||
tif->tif_setupencode = _TIFFtrue;
|
||||
tif->tif_preencode = _TIFFNoPreCode;
|
||||
tif->tif_postencode = _TIFFtrue;
|
||||
@@ -145,9 +155,9 @@ _TIFFSetDefaultCompressionState(TIFF* tif)
|
||||
}
|
||||
|
||||
int
|
||||
TIFFSetCompressionScheme(TIFF* tif, uint16 scheme)
|
||||
TIFFSetCompressionScheme(TIFF* tif, int scheme)
|
||||
{
|
||||
const TIFFCodec *c = TIFFFindCODEC(scheme);
|
||||
const TIFFCodec *c = TIFFFindCODEC((uint16) scheme);
|
||||
|
||||
_TIFFSetDefaultCompressionState(tif);
|
||||
/*
|
||||
@@ -200,9 +210,11 @@ TIFFRegisterCODEC(uint16 scheme, const char* name, TIFFInitMethod init)
|
||||
cd->info->init = init;
|
||||
cd->next = registeredCODECS;
|
||||
registeredCODECS = cd;
|
||||
} else
|
||||
} else {
|
||||
TIFFError("TIFFRegisterCODEC",
|
||||
"No space to register compression scheme %s", name);
|
||||
return NULL;
|
||||
}
|
||||
return (cd->info);
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -34,7 +34,7 @@
|
||||
* Internal format of a TIFF directory entry.
|
||||
*/
|
||||
typedef struct {
|
||||
#define FIELD_SETLONGS 3
|
||||
#define FIELD_SETLONGS 4
|
||||
/* bit vector of fields that are set */
|
||||
u_long td_fieldsset[FIELD_SETLONGS];
|
||||
|
||||
@@ -69,7 +69,7 @@ typedef struct {
|
||||
char* td_imagedescription;
|
||||
char* td_make;
|
||||
char* td_model;
|
||||
char* td_software;
|
||||
char* td_copyright;
|
||||
char* td_pagename;
|
||||
tstrip_t td_stripsperimage;
|
||||
tstrip_t td_nstrips; /* size of offset & bytecount arrays */
|
||||
@@ -110,6 +110,18 @@ typedef struct {
|
||||
uint32 td_richtiffiptcLength;
|
||||
void *td_richtiffiptcData;
|
||||
#endif
|
||||
/* Begin Pixar Tag values. */
|
||||
uint32 td_imagefullwidth, td_imagefulllength;
|
||||
char* td_textureformat;
|
||||
char* td_wrapmodes;
|
||||
float td_fovcot;
|
||||
float* td_matrixWorldToScreen;
|
||||
float* td_matrixWorldToCamera;
|
||||
/* End Pixar Tag Values. */
|
||||
uint32 td_xmlpacketLength;
|
||||
void *td_xmlpacketData;
|
||||
int td_customValueCount;
|
||||
TIFFTagValue *td_customValues;
|
||||
} TIFFDirectory;
|
||||
|
||||
/*
|
||||
@@ -160,7 +172,7 @@ typedef struct {
|
||||
#define FIELD_ARTIST 27
|
||||
#define FIELD_DATETIME 28
|
||||
#define FIELD_HOSTCOMPUTER 29
|
||||
#define FIELD_SOFTWARE 30
|
||||
/* unused - was FIELD_SOFTWARE 30 */
|
||||
#define FIELD_EXTRASAMPLES 31
|
||||
#define FIELD_SAMPLEFORMAT 32
|
||||
#define FIELD_SMINSAMPLEVALUE 33
|
||||
@@ -185,8 +197,21 @@ typedef struct {
|
||||
#define FIELD_PHOTOSHOP 52
|
||||
#define FIELD_RICHTIFFIPTC 53
|
||||
#define FIELD_STONITS 54
|
||||
/* Begin PIXAR */
|
||||
#define FIELD_IMAGEFULLWIDTH 55
|
||||
#define FIELD_IMAGEFULLLENGTH 56
|
||||
#define FIELD_TEXTUREFORMAT 57
|
||||
#define FIELD_WRAPMODES 58
|
||||
#define FIELD_FOVCOT 59
|
||||
#define FIELD_MATRIX_WORLDTOSCREEN 60
|
||||
#define FIELD_MATRIX_WORLDTOCAMERA 61
|
||||
#define FIELD_COPYRIGHT 62
|
||||
#define FIELD_XMLPACKET 63
|
||||
/* FIELD_CUSTOM (see tiffio.h) 65 */
|
||||
/* end of support for well-known tags; codec-private tags follow */
|
||||
#define FIELD_CODEC 55 /* base of codec-private tags */
|
||||
#define FIELD_CODEC 66 /* base of codec-private tags */
|
||||
|
||||
|
||||
/*
|
||||
* Pseudo-tags don't normally need field bits since they
|
||||
* are not written to an output file (by definition).
|
||||
@@ -210,23 +235,6 @@ typedef struct {
|
||||
((v) & (tif)->tif_typemask[type]) << (tif)->tif_typeshift[type] : \
|
||||
(v) & (tif)->tif_typemask[type]))
|
||||
|
||||
typedef struct {
|
||||
ttag_t field_tag; /* field's tag */
|
||||
short field_readcount; /* read count/TIFF_VARIABLE/TIFF_SPP */
|
||||
short field_writecount; /* write count/TIFF_VARIABLE */
|
||||
TIFFDataType field_type; /* type of associated data */
|
||||
u_short field_bit; /* bit in fieldsset bit vector */
|
||||
u_char field_oktochange; /* if true, can change while writing */
|
||||
u_char field_passcount; /* if true, pass dir count on set */
|
||||
char *field_name; /* ASCII name */
|
||||
} TIFFFieldInfo;
|
||||
|
||||
#define TIFF_ANY TIFF_NOTYPE /* for field descriptor searching */
|
||||
#define TIFF_VARIABLE -1 /* marker for variable length tags */
|
||||
#define TIFF_SPP -2 /* marker for SamplesPerPixel tags */
|
||||
#define TIFF_VARIABLE2 -3 /* marker for uint32 var-length tags */
|
||||
|
||||
extern const int tiffDataWidth[]; /* table of tag datatype widths */
|
||||
|
||||
#define BITn(n) (((u_long)1L)<<((n)&0x1f))
|
||||
#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n)/32])
|
||||
@@ -241,11 +249,18 @@ extern const int tiffDataWidth[]; /* table of tag datatype widths */
|
||||
extern "C" {
|
||||
#endif
|
||||
extern void _TIFFSetupFieldInfo(TIFF*);
|
||||
extern void _TIFFMergeFieldInfo(TIFF*, const TIFFFieldInfo[], int);
|
||||
extern void _TIFFPrintFieldInfo(TIFF*, FILE*);
|
||||
extern const TIFFFieldInfo* _TIFFFindFieldInfo(TIFF*, ttag_t, TIFFDataType);
|
||||
extern const TIFFFieldInfo* _TIFFFieldWithTag(TIFF*, ttag_t);
|
||||
extern TIFFDataType _TIFFSampleToTagType(TIFF*);
|
||||
extern const TIFFFieldInfo* _TIFFFindOrRegisterFieldInfo( TIFF *tif,
|
||||
ttag_t tag,
|
||||
TIFFDataType dt );
|
||||
extern TIFFFieldInfo* _TIFFCreateAnonFieldInfo( TIFF *tif, ttag_t tag,
|
||||
TIFFDataType dt );
|
||||
|
||||
#define _TIFFMergeFieldInfo TIFFMergeFieldInfo
|
||||
#define _TIFFFindFieldInfo TIFFFindFieldInfo
|
||||
#define _TIFFFieldWithTag TIFFFieldWithTag
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
@@ -4,23 +4,23 @@
|
||||
* Copyright (c) 1988-1997 Sam Leffler
|
||||
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* its documentation for any purpose is hereby granted without fee, provided
|
||||
* that (i) the above copyright notices and this permission notice appear in
|
||||
* all copies of the software and related documentation, and (ii) the names of
|
||||
* Sam Leffler and Silicon Graphics may not be used in any advertising or
|
||||
* publicity relating to the software without the specific, prior written
|
||||
* permission of Sam Leffler and Silicon Graphics.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
|
||||
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
|
||||
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
||||
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
||||
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
@@ -31,14 +31,25 @@
|
||||
*/
|
||||
#include "tiffiop.h"
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
* NB: NB: THIS ARRAY IS ASSUMED TO BE SORTED BY TAG.
|
||||
* If a tag can have both LONG and SHORT types
|
||||
* then the LONG must be placed before the SHORT for
|
||||
* writing to work properly.
|
||||
*
|
||||
* NOTE: The second field (field_readcount) and third field (field_writecount)
|
||||
* sometimes use the values TIFF_VARIABLE (-1), TIFF_VARIABLE2 (-3)
|
||||
* and TIFFTAG_SPP (-2). The macros should be used but would throw off
|
||||
* the formatting of the code, so please interprete the -1, -2 and -3
|
||||
* values accordingly.
|
||||
*/
|
||||
static const TIFFFieldInfo tiffFieldInfo[] = {
|
||||
#ifndef VMS
|
||||
static
|
||||
#endif
|
||||
const TIFFFieldInfo tiffFieldInfo[] = {
|
||||
{ TIFFTAG_SUBFILETYPE, 1, 1, TIFF_LONG, FIELD_SUBFILETYPE,
|
||||
TRUE, FALSE, "SubfileType" },
|
||||
/* XXX SHORT for compatibility w/ old versions of the library */
|
||||
@@ -54,10 +65,19 @@ static const TIFFFieldInfo tiffFieldInfo[] = {
|
||||
TRUE, FALSE, "ImageLength" },
|
||||
{ TIFFTAG_IMAGELENGTH, 1, 1, TIFF_SHORT, FIELD_IMAGEDIMENSIONS,
|
||||
TRUE, FALSE, "ImageLength" },
|
||||
/* XXX LONG for compatibility with some broken TIFF writers */
|
||||
{ TIFFTAG_BITSPERSAMPLE, -1,-1, TIFF_LONG, FIELD_BITSPERSAMPLE,
|
||||
FALSE, FALSE, "BitsPerSample" },
|
||||
{ TIFFTAG_BITSPERSAMPLE, -1,-1, TIFF_SHORT, FIELD_BITSPERSAMPLE,
|
||||
FALSE, FALSE, "BitsPerSample" },
|
||||
/* XXX LONG for compatibility with some broken TIFF writers */
|
||||
{ TIFFTAG_COMPRESSION, -1, 1, TIFF_LONG, FIELD_COMPRESSION,
|
||||
FALSE, FALSE, "Compression" },
|
||||
{ TIFFTAG_COMPRESSION, -1, 1, TIFF_SHORT, FIELD_COMPRESSION,
|
||||
FALSE, FALSE, "Compression" },
|
||||
/* XXX LONG for compatibility with some broken TIFF writers */
|
||||
{ TIFFTAG_PHOTOMETRIC, 1, 1, TIFF_LONG, FIELD_PHOTOMETRIC,
|
||||
FALSE, FALSE, "PhotometricInterpretation" },
|
||||
{ TIFFTAG_PHOTOMETRIC, 1, 1, TIFF_SHORT, FIELD_PHOTOMETRIC,
|
||||
FALSE, FALSE, "PhotometricInterpretation" },
|
||||
{ TIFFTAG_THRESHHOLDING, 1, 1, TIFF_SHORT, FIELD_THRESHHOLDING,
|
||||
@@ -122,11 +142,9 @@ static const TIFFFieldInfo tiffFieldInfo[] = {
|
||||
TRUE, FALSE, "PageNumber" },
|
||||
{ TIFFTAG_COLORRESPONSEUNIT, 1, 1, TIFF_SHORT, FIELD_IGNORE,
|
||||
TRUE, FALSE, "ColorResponseUnit" },
|
||||
#ifdef COLORIMETRY_SUPPORT
|
||||
{ TIFFTAG_TRANSFERFUNCTION, -1,-1, TIFF_SHORT, FIELD_TRANSFERFUNCTION,
|
||||
TRUE, FALSE, "TransferFunction" },
|
||||
#endif
|
||||
{ TIFFTAG_SOFTWARE, -1,-1, TIFF_ASCII, FIELD_SOFTWARE,
|
||||
{ TIFFTAG_SOFTWARE, -1,-1, TIFF_ASCII, FIELD_CUSTOM,
|
||||
TRUE, FALSE, "Software" },
|
||||
{ TIFFTAG_DATETIME, 20,20, TIFF_ASCII, FIELD_DATETIME,
|
||||
TRUE, FALSE, "DateTime" },
|
||||
@@ -134,12 +152,10 @@ static const TIFFFieldInfo tiffFieldInfo[] = {
|
||||
TRUE, FALSE, "Artist" },
|
||||
{ TIFFTAG_HOSTCOMPUTER, -1,-1, TIFF_ASCII, FIELD_HOSTCOMPUTER,
|
||||
TRUE, FALSE, "HostComputer" },
|
||||
#ifdef COLORIMETRY_SUPPORT
|
||||
{ TIFFTAG_WHITEPOINT, 2, 2, TIFF_RATIONAL,FIELD_WHITEPOINT,
|
||||
TRUE, FALSE, "WhitePoint" },
|
||||
{ TIFFTAG_PRIMARYCHROMATICITIES,6,6,TIFF_RATIONAL,FIELD_PRIMARYCHROMAS,
|
||||
TRUE, FALSE, "PrimaryChromaticities" },
|
||||
#endif
|
||||
{ TIFFTAG_COLORMAP, -1,-1, TIFF_SHORT, FIELD_COLORMAP,
|
||||
TRUE, FALSE, "ColorMap" },
|
||||
{ TIFFTAG_HALFTONEHINTS, 2, 2, TIFF_SHORT, FIELD_HALFTONEHINTS,
|
||||
@@ -158,11 +174,8 @@ static const TIFFFieldInfo tiffFieldInfo[] = {
|
||||
FALSE, FALSE, "TileByteCounts" },
|
||||
{ TIFFTAG_TILEBYTECOUNTS, -1, 1, TIFF_SHORT, FIELD_STRIPBYTECOUNTS,
|
||||
FALSE, FALSE, "TileByteCounts" },
|
||||
#ifdef TIFFTAG_SUBIFD
|
||||
{ TIFFTAG_SUBIFD, -1,-1, TIFF_LONG, FIELD_SUBIFD,
|
||||
TRUE, TRUE, "SubIFD" },
|
||||
#endif
|
||||
#ifdef CMYK_SUPPORT /* 6.0 CMYK tags */
|
||||
{ TIFFTAG_INKSET, 1, 1, TIFF_SHORT, FIELD_INKSET,
|
||||
FALSE, FALSE, "InkSet" },
|
||||
{ TIFFTAG_INKNAMES, -1,-1, TIFF_ASCII, FIELD_INKNAMES,
|
||||
@@ -175,7 +188,6 @@ static const TIFFFieldInfo tiffFieldInfo[] = {
|
||||
FALSE, FALSE, "DotRange" },
|
||||
{ TIFFTAG_TARGETPRINTER, -1,-1, TIFF_ASCII, FIELD_TARGETPRINTER,
|
||||
TRUE, FALSE, "TargetPrinter" },
|
||||
#endif
|
||||
{ TIFFTAG_EXTRASAMPLES, -1,-1, TIFF_SHORT, FIELD_EXTRASAMPLES,
|
||||
FALSE, FALSE, "ExtraSamples" },
|
||||
/* XXX for bogus Adobe Photoshop v2.5 files */
|
||||
@@ -187,21 +199,19 @@ static const TIFFFieldInfo tiffFieldInfo[] = {
|
||||
TRUE, FALSE, "SMinSampleValue" },
|
||||
{ TIFFTAG_SMAXSAMPLEVALUE, -2,-1, TIFF_ANY, FIELD_SMAXSAMPLEVALUE,
|
||||
TRUE, FALSE, "SMaxSampleValue" },
|
||||
#ifdef YCBCR_SUPPORT /* 6.0 YCbCr tags */
|
||||
{ TIFFTAG_YCBCRCOEFFICIENTS, 3, 3, TIFF_RATIONAL, FIELD_YCBCRCOEFFICIENTS,
|
||||
FALSE, FALSE, "YCbCrCoefficients" },
|
||||
{ TIFFTAG_YCBCRSUBSAMPLING, 2, 2, TIFF_SHORT, FIELD_YCBCRSUBSAMPLING,
|
||||
FALSE, FALSE, "YCbCrSubsampling" },
|
||||
{ TIFFTAG_YCBCRPOSITIONING, 1, 1, TIFF_SHORT, FIELD_YCBCRPOSITIONING,
|
||||
FALSE, FALSE, "YCbCrPositioning" },
|
||||
#endif
|
||||
#ifdef COLORIMETRY_SUPPORT
|
||||
{ TIFFTAG_REFERENCEBLACKWHITE,6,6,TIFF_RATIONAL, FIELD_REFBLACKWHITE,
|
||||
TRUE, FALSE, "ReferenceBlackWhite" },
|
||||
/* XXX temporarily accept LONG for backwards compatibility */
|
||||
{ TIFFTAG_REFERENCEBLACKWHITE,6,6,TIFF_LONG, FIELD_REFBLACKWHITE,
|
||||
TRUE, FALSE, "ReferenceBlackWhite" },
|
||||
#endif
|
||||
{ TIFFTAG_XMLPACKET, -1,-3, TIFF_UNDEFINED, FIELD_XMLPACKET,
|
||||
FALSE, TRUE, "XMLPacket" },
|
||||
/* begin SGI tags */
|
||||
{ TIFFTAG_MATTEING, 1, 1, TIFF_SHORT, FIELD_EXTRASAMPLES,
|
||||
FALSE, FALSE, "Matteing" },
|
||||
@@ -216,25 +226,37 @@ static const TIFFFieldInfo tiffFieldInfo[] = {
|
||||
{ TIFFTAG_TILEDEPTH, 1, 1, TIFF_SHORT, FIELD_TILEDEPTH,
|
||||
FALSE, FALSE, "TileDepth" },
|
||||
/* end SGI tags */
|
||||
/* begin Pixar tags */
|
||||
{ TIFFTAG_PIXAR_IMAGEFULLWIDTH, 1, 1, TIFF_LONG, FIELD_IMAGEFULLWIDTH,
|
||||
TRUE, FALSE, "ImageFullWidth" },
|
||||
{ TIFFTAG_PIXAR_IMAGEFULLLENGTH, 1, 1, TIFF_LONG, FIELD_IMAGEFULLLENGTH,
|
||||
TRUE, FALSE, "ImageFullLength" },
|
||||
{ TIFFTAG_PIXAR_TEXTUREFORMAT, -1,-1, TIFF_ASCII, FIELD_TEXTUREFORMAT,
|
||||
TRUE, FALSE, "TextureFormat" },
|
||||
{ TIFFTAG_PIXAR_WRAPMODES, -1,-1, TIFF_ASCII, FIELD_WRAPMODES,
|
||||
TRUE, FALSE, "TextureWrapModes" },
|
||||
{ TIFFTAG_PIXAR_FOVCOT, 1, 1, TIFF_FLOAT, FIELD_FOVCOT,
|
||||
TRUE, FALSE, "FieldOfViewCotan" },
|
||||
{ TIFFTAG_PIXAR_MATRIX_WORLDTOSCREEN, 16,16, TIFF_FLOAT,
|
||||
FIELD_MATRIX_WORLDTOSCREEN, TRUE, FALSE, "MatrixWorldToScreen" },
|
||||
{ TIFFTAG_PIXAR_MATRIX_WORLDTOCAMERA, 16,16, TIFF_FLOAT,
|
||||
FIELD_MATRIX_WORLDTOCAMERA, TRUE, FALSE, "MatrixWorldToCamera" },
|
||||
{ TIFFTAG_COPYRIGHT, -1,-1, TIFF_ASCII, FIELD_COPYRIGHT,
|
||||
TRUE, FALSE, "Copyright" },
|
||||
/* end Pixar tags */
|
||||
#ifdef IPTC_SUPPORT
|
||||
#ifdef PHOTOSHOP_SUPPORT
|
||||
{ TIFFTAG_RICHTIFFIPTC, -1,-1, TIFF_LONG, FIELD_RICHTIFFIPTC,
|
||||
{ TIFFTAG_RICHTIFFIPTC, -1,-1, TIFF_LONG, FIELD_RICHTIFFIPTC,
|
||||
FALSE, TRUE, "RichTIFFIPTC" },
|
||||
#else
|
||||
{ TIFFTAG_RICHTIFFIPTC, -1,-3, TIFF_UNDEFINED, FIELD_RICHTIFFIPTC,
|
||||
{ TIFFTAG_RICHTIFFIPTC, -1,-3, TIFF_UNDEFINED, FIELD_RICHTIFFIPTC,
|
||||
FALSE, TRUE, "RichTIFFIPTC" },
|
||||
#endif
|
||||
#endif
|
||||
#ifdef PHOTOSHOP_SUPPORT
|
||||
{ TIFFTAG_PHOTOSHOP, -1,-3, TIFF_UNDEFINED, FIELD_PHOTOSHOP,
|
||||
{ TIFFTAG_PHOTOSHOP, -1,-3, TIFF_BYTE, FIELD_PHOTOSHOP,
|
||||
FALSE, TRUE, "Photoshop" },
|
||||
{ TIFFTAG_PHOTOSHOP, -1,-1, TIFF_BYTE, FIELD_PHOTOSHOP,
|
||||
FALSE, TRUE, "Photoshop" },
|
||||
#endif
|
||||
#ifdef ICC_SUPPORT
|
||||
{ TIFFTAG_ICCPROFILE, -1,-3, TIFF_UNDEFINED, FIELD_ICCPROFILE,
|
||||
FALSE, TRUE, "ICC Profile" },
|
||||
#endif
|
||||
{ TIFFTAG_STONITS, 1, 1, TIFF_DOUBLE, FIELD_STONITS,
|
||||
FALSE, FALSE, "StoNits" },
|
||||
};
|
||||
@@ -244,13 +266,26 @@ void
|
||||
_TIFFSetupFieldInfo(TIFF* tif)
|
||||
{
|
||||
if (tif->tif_fieldinfo) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < tif->tif_nfields; i++)
|
||||
{
|
||||
TIFFFieldInfo *fld = tif->tif_fieldinfo[i];
|
||||
if (fld->field_bit == FIELD_CUSTOM &&
|
||||
strncmp("Tag ", fld->field_name, 4) == 0)
|
||||
{
|
||||
_TIFFfree(fld->field_name);
|
||||
_TIFFfree(fld);
|
||||
}
|
||||
}
|
||||
|
||||
_TIFFfree(tif->tif_fieldinfo);
|
||||
tif->tif_nfields = 0;
|
||||
}
|
||||
_TIFFMergeFieldInfo(tif, tiffFieldInfo, N(tiffFieldInfo));
|
||||
}
|
||||
|
||||
static int LINKAGEMODE
|
||||
static int
|
||||
tagCompare(const void* a, const void* b)
|
||||
{
|
||||
const TIFFFieldInfo* ta = *(const TIFFFieldInfo**) a;
|
||||
@@ -259,7 +294,7 @@ tagCompare(const void* a, const void* b)
|
||||
if (ta->field_tag != tb->field_tag)
|
||||
return (ta->field_tag < tb->field_tag ? -1 : 1);
|
||||
else
|
||||
return (tb->field_type < ta->field_type ? -1 : 1);
|
||||
return ((int)tb->field_type - (int)ta->field_type);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -276,17 +311,14 @@ _TIFFMergeFieldInfo(TIFF* tif, const TIFFFieldInfo info[], int n)
|
||||
tif->tif_fieldinfo = (TIFFFieldInfo**)
|
||||
_TIFFmalloc(n * sizeof (TIFFFieldInfo*));
|
||||
}
|
||||
assert(tif->tif_fieldinfo != NULL);
|
||||
tp = &tif->tif_fieldinfo[tif->tif_nfields];
|
||||
for (i = 0; i < n; i++)
|
||||
tp[i] = (TIFFFieldInfo*) &info[i]; /* XXX */
|
||||
/*
|
||||
* NB: the core tags are presumed sorted correctly.
|
||||
*/
|
||||
if (tif->tif_nfields > 0)
|
||||
qsort(tif->tif_fieldinfo, (size_t) (tif->tif_nfields += n),
|
||||
sizeof (TIFFFieldInfo*), tagCompare);
|
||||
else
|
||||
tif->tif_nfields += n;
|
||||
|
||||
/* Sort the field info by tag number */
|
||||
qsort(tif->tif_fieldinfo, (size_t) (tif->tif_nfields += n),
|
||||
sizeof (TIFFFieldInfo*), tagCompare);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -310,21 +342,36 @@ _TIFFPrintFieldInfo(TIFF* tif, FILE* fd)
|
||||
}
|
||||
}
|
||||
|
||||
const int tiffDataWidth[] = {
|
||||
1, /* nothing */
|
||||
1, /* TIFF_BYTE */
|
||||
1, /* TIFF_ASCII */
|
||||
2, /* TIFF_SHORT */
|
||||
4, /* TIFF_LONG */
|
||||
8, /* TIFF_RATIONAL */
|
||||
1, /* TIFF_SBYTE */
|
||||
1, /* TIFF_UNDEFINED */
|
||||
2, /* TIFF_SSHORT */
|
||||
4, /* TIFF_SLONG */
|
||||
8, /* TIFF_SRATIONAL */
|
||||
4, /* TIFF_FLOAT */
|
||||
8, /* TIFF_DOUBLE */
|
||||
};
|
||||
/*
|
||||
* Return size of TIFFDataType in bytes
|
||||
*/
|
||||
int
|
||||
TIFFDataWidth(TIFFDataType type)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case 0: /* nothing */
|
||||
case 1: /* TIFF_BYTE */
|
||||
case 2: /* TIFF_ASCII */
|
||||
case 6: /* TIFF_SBYTE */
|
||||
case 7: /* TIFF_UNDEFINED */
|
||||
return 1;
|
||||
case 3: /* TIFF_SHORT */
|
||||
case 8: /* TIFF_SSHORT */
|
||||
return 2;
|
||||
case 4: /* TIFF_LONG */
|
||||
case 9: /* TIFF_SLONG */
|
||||
case 11: /* TIFF_FLOAT */
|
||||
case 13: /* TIFF_IFD */
|
||||
return 4;
|
||||
case 5: /* TIFF_RATIONAL */
|
||||
case 10: /* TIFF_SRATIONAL */
|
||||
case 12: /* TIFF_DOUBLE */
|
||||
return 8;
|
||||
default:
|
||||
return 0; /* will return 0 for unknown types */
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Return nearest TIFFDataType to the sample type of an image.
|
||||
@@ -332,7 +379,7 @@ const int tiffDataWidth[] = {
|
||||
TIFFDataType
|
||||
_TIFFSampleToTagType(TIFF* tif)
|
||||
{
|
||||
int bps = (int) TIFFhowmany(tif->tif_dir.td_bitspersample, 8);
|
||||
uint32 bps = TIFFhowmany8(tif->tif_dir.td_bitspersample);
|
||||
|
||||
switch (tif->tif_dir.td_sampleformat) {
|
||||
case SAMPLEFORMAT_IEEEFP:
|
||||
@@ -360,7 +407,16 @@ _TIFFFindFieldInfo(TIFF* tif, ttag_t tag, TIFFDataType dt)
|
||||
(dt == TIFF_ANY || dt == last->field_type))
|
||||
return (last);
|
||||
/* NB: if table gets big, use sorted search (e.g. binary search) */
|
||||
for (i = 0, n = tif->tif_nfields; i < n; i++) {
|
||||
if(dt != TIFF_ANY) {
|
||||
TIFFFieldInfo key = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
key.field_tag = tag;
|
||||
key.field_type = dt;
|
||||
return((const TIFFFieldInfo *) bsearch(&key,
|
||||
tif->tif_fieldinfo,
|
||||
tif->tif_nfields,
|
||||
sizeof(TIFFFieldInfo),
|
||||
tagCompare));
|
||||
} else for (i = 0, n = tif->tif_nfields; i < n; i++) {
|
||||
const TIFFFieldInfo* fip = tif->tif_fieldinfo[i];
|
||||
if (fip->field_tag == tag &&
|
||||
(dt == TIFF_ANY || fip->field_type == dt))
|
||||
@@ -369,9 +425,6 @@ _TIFFFindFieldInfo(TIFF* tif, ttag_t tag, TIFFDataType dt)
|
||||
return ((const TIFFFieldInfo *)0);
|
||||
}
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
const TIFFFieldInfo*
|
||||
_TIFFFieldWithTag(TIFF* tif, ttag_t tag)
|
||||
{
|
||||
@@ -384,3 +437,50 @@ _TIFFFieldWithTag(TIFF* tif, ttag_t tag)
|
||||
}
|
||||
return (fip);
|
||||
}
|
||||
|
||||
const TIFFFieldInfo*
|
||||
_TIFFFindOrRegisterFieldInfo( TIFF *tif, ttag_t tag, TIFFDataType dt )
|
||||
|
||||
{
|
||||
const TIFFFieldInfo *fld;
|
||||
|
||||
fld = _TIFFFindFieldInfo( tif, tag, dt );
|
||||
if( fld == NULL )
|
||||
{
|
||||
fld = _TIFFCreateAnonFieldInfo( tif, tag, dt );
|
||||
_TIFFMergeFieldInfo( tif, fld, 1 );
|
||||
}
|
||||
|
||||
return fld;
|
||||
}
|
||||
|
||||
TIFFFieldInfo*
|
||||
_TIFFCreateAnonFieldInfo(TIFF *tif, ttag_t tag, TIFFDataType field_type)
|
||||
{
|
||||
TIFFFieldInfo *fld;
|
||||
|
||||
fld = (TIFFFieldInfo *) _TIFFmalloc(sizeof (TIFFFieldInfo));
|
||||
if (fld == NULL)
|
||||
return NULL;
|
||||
_TIFFmemset( fld, 0, sizeof(TIFFFieldInfo) );
|
||||
|
||||
fld->field_tag = tag;
|
||||
fld->field_readcount = TIFF_VARIABLE;
|
||||
fld->field_writecount = TIFF_VARIABLE;
|
||||
fld->field_type = field_type;
|
||||
fld->field_bit = FIELD_CUSTOM;
|
||||
fld->field_oktochange = TRUE;
|
||||
fld->field_passcount = TRUE;
|
||||
fld->field_name = (char *) _TIFFmalloc(32);
|
||||
if (fld->field_name == NULL) {
|
||||
_TIFFfree(fld);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* note that this name is a special sign to TIFFClose() and
|
||||
* _TIFFSetupFieldInfo() to free the field
|
||||
*/
|
||||
sprintf(fld->field_name, "Tag %d", (int) tag);
|
||||
|
||||
return fld;
|
||||
}
|
||||
|
@@ -41,7 +41,7 @@ extern void TIFFCvtIEEEFloatToNative(TIFF*, uint32, float*);
|
||||
extern void TIFFCvtIEEEDoubleToNative(TIFF*, uint32, double*);
|
||||
#endif
|
||||
|
||||
static void EstimateStripByteCounts(TIFF*, TIFFDirEntry*, uint16);
|
||||
static int EstimateStripByteCounts(TIFF*, TIFFDirEntry*, uint16);
|
||||
static void MissingRequired(TIFF*, const char*);
|
||||
static int CheckDirCount(TIFF*, TIFFDirEntry*, uint32);
|
||||
static tsize_t TIFFFetchData(TIFF*, TIFFDirEntry*, char*);
|
||||
@@ -62,11 +62,17 @@ static int TIFFFetchShortPair(TIFF*, TIFFDirEntry*);
|
||||
static void ChopUpSingleUncompressedStrip(TIFF*);
|
||||
|
||||
static char *
|
||||
CheckMalloc(TIFF* tif, tsize_t n, const char* what)
|
||||
CheckMalloc(TIFF* tif, size_t nmemb, size_t elem_size, const char* what)
|
||||
{
|
||||
char *cp = (char*)_TIFFmalloc(n);
|
||||
char *cp = NULL;
|
||||
tsize_t bytes = nmemb * elem_size;
|
||||
|
||||
if (elem_size && bytes / elem_size == nmemb)
|
||||
cp = (char*)_TIFFmalloc(bytes);
|
||||
|
||||
if (cp == NULL)
|
||||
TIFFError(tif->tif_name, "No space %s", what);
|
||||
|
||||
return (cp);
|
||||
}
|
||||
|
||||
@@ -78,6 +84,8 @@ CheckMalloc(TIFF* tif, tsize_t n, const char* what)
|
||||
int
|
||||
TIFFReadDirectory(TIFF* tif)
|
||||
{
|
||||
static const char module[] = "TIFFReadDirectory";
|
||||
|
||||
register TIFFDirEntry* dp;
|
||||
register int n;
|
||||
register TIFFDirectory* td;
|
||||
@@ -88,13 +96,36 @@ TIFFReadDirectory(TIFF* tif)
|
||||
const TIFFFieldInfo* fip;
|
||||
int fix;
|
||||
uint16 dircount;
|
||||
uint32 nextdiroff;
|
||||
toff_t nextdiroff;
|
||||
char* cp;
|
||||
int diroutoforderwarning = 0;
|
||||
toff_t* new_dirlist;
|
||||
|
||||
tif->tif_diroff = tif->tif_nextdiroff;
|
||||
if (tif->tif_diroff == 0) /* no more directories */
|
||||
return (0);
|
||||
|
||||
/*
|
||||
* XXX: Trick to prevent IFD looping. The one can create TIFF file
|
||||
* with looped directory pointers. We will maintain a list of already
|
||||
* seen directories and check every IFD offset against this list.
|
||||
*/
|
||||
for (n = 0; n < tif->tif_dirnumber; n++) {
|
||||
if (tif->tif_dirlist[n] == tif->tif_diroff)
|
||||
return (0);
|
||||
}
|
||||
tif->tif_dirnumber++;
|
||||
new_dirlist = _TIFFrealloc(tif->tif_dirlist,
|
||||
tif->tif_dirnumber * sizeof(toff_t));
|
||||
if (!new_dirlist) {
|
||||
TIFFError(module,
|
||||
"%.1000s: Failed to allocate space for IFD list",
|
||||
tif->tif_name);
|
||||
return (0);
|
||||
}
|
||||
tif->tif_dirlist = new_dirlist;
|
||||
tif->tif_dirlist[tif->tif_dirnumber - 1] = tif->tif_diroff;
|
||||
|
||||
/*
|
||||
* Cleanup any previous compression state.
|
||||
*/
|
||||
@@ -103,23 +134,27 @@ TIFFReadDirectory(TIFF* tif)
|
||||
nextdiroff = 0;
|
||||
if (!isMapped(tif)) {
|
||||
if (!SeekOK(tif, tif->tif_diroff)) {
|
||||
TIFFError(tif->tif_name,
|
||||
"Seek error accessing TIFF directory");
|
||||
TIFFError(module,
|
||||
"%.1000s: Seek error accessing TIFF directory",
|
||||
tif->tif_name);
|
||||
return (0);
|
||||
}
|
||||
if (!ReadOK(tif, &dircount, sizeof (uint16))) {
|
||||
TIFFError(tif->tif_name,
|
||||
"Can not read TIFF directory count");
|
||||
TIFFError(module,
|
||||
"%.1000s: Can not read TIFF directory count",
|
||||
tif->tif_name);
|
||||
return (0);
|
||||
}
|
||||
if (tif->tif_flags & TIFF_SWAB)
|
||||
TIFFSwabShort(&dircount);
|
||||
dir = (TIFFDirEntry *)CheckMalloc(tif,
|
||||
dircount * sizeof (TIFFDirEntry), "to read TIFF directory");
|
||||
dircount, sizeof (TIFFDirEntry), "to read TIFF directory");
|
||||
if (dir == NULL)
|
||||
return (0);
|
||||
if (!ReadOK(tif, dir, dircount*sizeof (TIFFDirEntry))) {
|
||||
TIFFError(tif->tif_name, "Can not read TIFF directory");
|
||||
TIFFError(module,
|
||||
"%.100s: Can not read TIFF directory",
|
||||
tif->tif_name);
|
||||
goto bad;
|
||||
}
|
||||
/*
|
||||
@@ -130,8 +165,9 @@ TIFFReadDirectory(TIFF* tif)
|
||||
toff_t off = tif->tif_diroff;
|
||||
|
||||
if (off + sizeof (uint16) > tif->tif_size) {
|
||||
TIFFError(tif->tif_name,
|
||||
"Can not read TIFF directory count");
|
||||
TIFFError(module,
|
||||
"%.1000s: Can not read TIFF directory count",
|
||||
tif->tif_name);
|
||||
return (0);
|
||||
} else
|
||||
_TIFFmemcpy(&dircount, tif->tif_base + off, sizeof (uint16));
|
||||
@@ -139,15 +175,18 @@ TIFFReadDirectory(TIFF* tif)
|
||||
if (tif->tif_flags & TIFF_SWAB)
|
||||
TIFFSwabShort(&dircount);
|
||||
dir = (TIFFDirEntry *)CheckMalloc(tif,
|
||||
dircount * sizeof (TIFFDirEntry), "to read TIFF directory");
|
||||
dircount, sizeof (TIFFDirEntry), "to read TIFF directory");
|
||||
if (dir == NULL)
|
||||
return (0);
|
||||
if (off + dircount*sizeof (TIFFDirEntry) > tif->tif_size) {
|
||||
TIFFError(tif->tif_name, "Can not read TIFF directory");
|
||||
TIFFError(module,
|
||||
"%.1000s: Can not read TIFF directory",
|
||||
tif->tif_name);
|
||||
goto bad;
|
||||
} else
|
||||
} else {
|
||||
_TIFFmemcpy(dir, tif->tif_base + off,
|
||||
dircount*sizeof (TIFFDirEntry));
|
||||
dircount*sizeof (TIFFDirEntry));
|
||||
}
|
||||
off += dircount* sizeof (TIFFDirEntry);
|
||||
if (off + sizeof (uint32) <= tif->tif_size)
|
||||
_TIFFmemcpy(&nextdiroff, tif->tif_base+off, sizeof (uint32));
|
||||
@@ -218,9 +257,9 @@ TIFFReadDirectory(TIFF* tif)
|
||||
if( TIFFReassignTagToIgnore(TIS_EXTRACT, dp->tdir_tag) )
|
||||
dp->tdir_tag = IGNORE;
|
||||
|
||||
if (dp->tdir_tag == IGNORE)
|
||||
continue;
|
||||
|
||||
if (fix >= tif->tif_nfields || dp->tdir_tag == IGNORE)
|
||||
continue;
|
||||
|
||||
/*
|
||||
* Silicon Beach (at least) writes unordered
|
||||
* directory tags (violating the spec). Handle
|
||||
@@ -228,23 +267,32 @@ TIFFReadDirectory(TIFF* tif)
|
||||
*/
|
||||
if (dp->tdir_tag < tif->tif_fieldinfo[fix]->field_tag) {
|
||||
if (!diroutoforderwarning) {
|
||||
TIFFWarning(tif->tif_name,
|
||||
"invalid TIFF directory; tags are not sorted in ascending order");
|
||||
TIFFWarning(module,
|
||||
"%.1000s: invalid TIFF directory; tags are not sorted in ascending order",
|
||||
tif->tif_name);
|
||||
diroutoforderwarning = 1;
|
||||
}
|
||||
fix = 0; /* O(n^2) */
|
||||
}
|
||||
while (fix < tif->tif_nfields &&
|
||||
tif->tif_fieldinfo[fix]->field_tag < dp->tdir_tag)
|
||||
tif->tif_fieldinfo[fix]->field_tag < dp->tdir_tag)
|
||||
fix++;
|
||||
if (fix == tif->tif_nfields ||
|
||||
if (fix >= tif->tif_nfields ||
|
||||
tif->tif_fieldinfo[fix]->field_tag != dp->tdir_tag) {
|
||||
TIFFWarning(tif->tif_name,
|
||||
"unknown field with tag %d (0x%x) ignored",
|
||||
dp->tdir_tag, dp->tdir_tag);
|
||||
dp->tdir_tag = IGNORE;
|
||||
fix = 0; /* restart search */
|
||||
continue;
|
||||
|
||||
TIFFWarning(module,
|
||||
"%.1000s: unknown field with tag %d (0x%x) encountered",
|
||||
tif->tif_name, dp->tdir_tag, dp->tdir_tag);
|
||||
|
||||
TIFFMergeFieldInfo( tif,
|
||||
_TIFFCreateAnonFieldInfo( tif,
|
||||
dp->tdir_tag,
|
||||
(TIFFDataType) dp->tdir_type ),
|
||||
1 );
|
||||
fix = 0;
|
||||
while (fix < tif->tif_nfields &&
|
||||
tif->tif_fieldinfo[fix]->field_tag < dp->tdir_tag)
|
||||
fix++;
|
||||
}
|
||||
/*
|
||||
* Null out old tags that we ignore.
|
||||
@@ -264,9 +312,10 @@ TIFFReadDirectory(TIFF* tif)
|
||||
fip++, fix++;
|
||||
if (fix == tif->tif_nfields ||
|
||||
fip->field_tag != dp->tdir_tag) {
|
||||
TIFFWarning(tif->tif_name,
|
||||
"wrong data type %d for \"%s\"; tag ignored",
|
||||
dp->tdir_type, fip[-1].field_name);
|
||||
TIFFWarning(module,
|
||||
"%.1000s: wrong data type %d for \"%s\"; tag ignored",
|
||||
tif->tif_name, dp->tdir_type,
|
||||
fip[-1].field_name);
|
||||
goto ignore;
|
||||
}
|
||||
}
|
||||
@@ -350,6 +399,11 @@ TIFFReadDirectory(TIFF* tif)
|
||||
td->td_nstrips = TIFFNumberOfTiles(tif);
|
||||
tif->tif_flags |= TIFF_ISTILED;
|
||||
}
|
||||
if (!td->td_nstrips) {
|
||||
TIFFError(module, "%s: cannot handle zero number of %s",
|
||||
tif->tif_name, isTiled(tif) ? "tiles" : "strips");
|
||||
goto bad;
|
||||
}
|
||||
td->td_stripsperimage = td->td_nstrips;
|
||||
if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
|
||||
td->td_stripsperimage /= td->td_samplesperpixel;
|
||||
@@ -426,7 +480,7 @@ TIFFReadDirectory(TIFF* tif)
|
||||
break;
|
||||
}
|
||||
v *= sizeof (uint16);
|
||||
cp = CheckMalloc(tif, dp->tdir_count * sizeof (uint16),
|
||||
cp = CheckMalloc(tif, dp->tdir_count, sizeof (uint16),
|
||||
"to read \"TransferFunction\" tag");
|
||||
if (cp != NULL) {
|
||||
if (TIFFFetchData(tif, dp, cp)) {
|
||||
@@ -501,14 +555,23 @@ TIFFReadDirectory(TIFF* tif)
|
||||
MissingRequired(tif, "StripByteCounts");
|
||||
goto bad;
|
||||
}
|
||||
TIFFWarning(tif->tif_name,
|
||||
"TIFF directory is missing required \"%s\" field, calculating from imagelength",
|
||||
_TIFFFieldWithTag(tif,TIFFTAG_STRIPBYTECOUNTS)->field_name);
|
||||
EstimateStripByteCounts(tif, dir, dircount);
|
||||
TIFFWarning(module,
|
||||
"%.1000s: TIFF directory is missing required "
|
||||
"\"%s\" field, calculating from imagelength",
|
||||
tif->tif_name,
|
||||
_TIFFFieldWithTag(tif,TIFFTAG_STRIPBYTECOUNTS)->field_name);
|
||||
if (EstimateStripByteCounts(tif, dir, dircount) < 0)
|
||||
goto bad;
|
||||
/*
|
||||
* Assume we have wrong StripByteCount value (in case of single strip) in
|
||||
* following cases:
|
||||
* - it is equal to zero along with StripOffset;
|
||||
* - it is larger than file itself (in case of uncompressed image).
|
||||
*/
|
||||
#define BYTECOUNTLOOKSBAD \
|
||||
(td->td_stripbytecount[0] == 0 || \
|
||||
(td->td_compression == COMPRESSION_NONE && \
|
||||
td->td_stripbytecount[0] > TIFFGetFileSize(tif) - td->td_stripoffset[0]))
|
||||
( (td->td_stripbytecount[0] == 0 && td->td_stripoffset[0] != 0) || \
|
||||
(td->td_compression == COMPRESSION_NONE && \
|
||||
td->td_stripbytecount[0] > TIFFGetFileSize(tif) - td->td_stripoffset[0]) )
|
||||
} else if (td->td_nstrips == 1 && BYTECOUNTLOOKSBAD) {
|
||||
/*
|
||||
* Plexus (and others) sometimes give a value
|
||||
@@ -517,13 +580,17 @@ TIFFReadDirectory(TIFF* tif)
|
||||
* simple case of estimating the size of a one
|
||||
* strip image.
|
||||
*/
|
||||
TIFFWarning(tif->tif_name,
|
||||
"Bogus \"%s\" field, ignoring and calculating from imagelength",
|
||||
_TIFFFieldWithTag(tif,TIFFTAG_STRIPBYTECOUNTS)->field_name);
|
||||
EstimateStripByteCounts(tif, dir, dircount);
|
||||
TIFFWarning(module,
|
||||
"%.1000s: Bogus \"%s\" field, ignoring and calculating from imagelength",
|
||||
tif->tif_name,
|
||||
_TIFFFieldWithTag(tif,TIFFTAG_STRIPBYTECOUNTS)->field_name);
|
||||
if(EstimateStripByteCounts(tif, dir, dircount) < 0)
|
||||
goto bad;
|
||||
}
|
||||
if (dir)
|
||||
if (dir) {
|
||||
_TIFFfree((char *)dir);
|
||||
dir = NULL;
|
||||
}
|
||||
if (!TIFFFieldSet(tif, FIELD_MAXSAMPLEVALUE))
|
||||
td->td_maxsamplevalue = (uint16)((1L<<td->td_bitspersample)-1);
|
||||
/*
|
||||
@@ -552,6 +619,17 @@ TIFFReadDirectory(TIFF* tif)
|
||||
tif->tif_curtile = (ttile_t) -1;
|
||||
tif->tif_tilesize = TIFFTileSize(tif);
|
||||
tif->tif_scanlinesize = TIFFScanlineSize(tif);
|
||||
|
||||
if (!tif->tif_tilesize) {
|
||||
TIFFError(module, "%s: cannot handle zero tile size",
|
||||
tif->tif_name);
|
||||
return (0);
|
||||
}
|
||||
if (!tif->tif_scanlinesize) {
|
||||
TIFFError(module, "%s: cannot handle zero scanline size",
|
||||
tif->tif_name);
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
bad:
|
||||
if (dir)
|
||||
@@ -559,9 +637,11 @@ bad:
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
static int
|
||||
EstimateStripByteCounts(TIFF* tif, TIFFDirEntry* dir, uint16 dircount)
|
||||
{
|
||||
static const char module[] = "EstimateStripByteCounts";
|
||||
|
||||
register TIFFDirEntry *dp;
|
||||
register TIFFDirectory *td = &tif->tif_dir;
|
||||
uint16 i;
|
||||
@@ -569,7 +649,7 @@ EstimateStripByteCounts(TIFF* tif, TIFFDirEntry* dir, uint16 dircount)
|
||||
if (td->td_stripbytecount)
|
||||
_TIFFfree(td->td_stripbytecount);
|
||||
td->td_stripbytecount = (uint32*)
|
||||
CheckMalloc(tif, td->td_nstrips * sizeof (uint32),
|
||||
CheckMalloc(tif, td->td_nstrips, sizeof (uint32),
|
||||
"for \"StripByteCounts\" array");
|
||||
if (td->td_compression != COMPRESSION_NONE) {
|
||||
uint32 space = (uint32)(sizeof (TIFFHeader)
|
||||
@@ -580,8 +660,16 @@ EstimateStripByteCounts(TIFF* tif, TIFFDirEntry* dir, uint16 dircount)
|
||||
uint16 n;
|
||||
|
||||
/* calculate amount of space used by indirect values */
|
||||
for (dp = dir, n = dircount; n > 0; n--, dp++) {
|
||||
uint32 cc = dp->tdir_count*tiffDataWidth[dp->tdir_type];
|
||||
for (dp = dir, n = dircount; n > 0; n--, dp++)
|
||||
{
|
||||
uint32 cc = TIFFDataWidth((TIFFDataType) dp->tdir_type);
|
||||
if (cc == 0) {
|
||||
TIFFError(module,
|
||||
"%.1000s: Cannot determine size of unknown tag type %d",
|
||||
tif->tif_name, dp->tdir_type);
|
||||
return -1;
|
||||
}
|
||||
cc = cc * dp->tdir_count;
|
||||
if (cc > sizeof (uint32))
|
||||
space += cc;
|
||||
}
|
||||
@@ -598,7 +686,8 @@ EstimateStripByteCounts(TIFF* tif, TIFFDirEntry* dir, uint16 dircount)
|
||||
* of data in the strip and trim this number back accordingly.
|
||||
*/
|
||||
i--;
|
||||
if (td->td_stripoffset[i] + td->td_stripbytecount[i] > filesize)
|
||||
if (((toff_t)(td->td_stripoffset[i]+td->td_stripbytecount[i]))
|
||||
> filesize)
|
||||
td->td_stripbytecount[i] =
|
||||
filesize - td->td_stripoffset[i];
|
||||
} else {
|
||||
@@ -610,13 +699,17 @@ EstimateStripByteCounts(TIFF* tif, TIFFDirEntry* dir, uint16 dircount)
|
||||
TIFFSetFieldBit(tif, FIELD_STRIPBYTECOUNTS);
|
||||
if (!TIFFFieldSet(tif, FIELD_ROWSPERSTRIP))
|
||||
td->td_rowsperstrip = td->td_imagelength;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
MissingRequired(TIFF* tif, const char* tagname)
|
||||
{
|
||||
TIFFError(tif->tif_name,
|
||||
"TIFF directory is missing required \"%s\" field", tagname);
|
||||
static const char module[] = "MissingRequired";
|
||||
|
||||
TIFFError(module,
|
||||
"%.1000s: TIFF directory is missing required \"%s\" field",
|
||||
tif->tif_name, tagname);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -644,7 +737,7 @@ CheckDirCount(TIFF* tif, TIFFDirEntry* dir, uint32 count)
|
||||
static tsize_t
|
||||
TIFFFetchData(TIFF* tif, TIFFDirEntry* dir, char* cp)
|
||||
{
|
||||
int w = tiffDataWidth[dir->tdir_type];
|
||||
int w = TIFFDataWidth((TIFFDataType) dir->tdir_type);
|
||||
tsize_t cc = dir->tdir_count * w;
|
||||
|
||||
if (!isMapped(tif)) {
|
||||
@@ -755,28 +848,44 @@ TIFFFetchFloat(TIFF* tif, TIFFDirEntry* dir)
|
||||
static int
|
||||
TIFFFetchByteArray(TIFF* tif, TIFFDirEntry* dir, uint16* v)
|
||||
{
|
||||
if (dir->tdir_count <= 4) {
|
||||
/*
|
||||
* Extract data from offset field.
|
||||
*/
|
||||
if (tif->tif_header.tiff_magic == TIFF_BIGENDIAN) {
|
||||
switch (dir->tdir_count) {
|
||||
case 4: v[3] = dir->tdir_offset & 0xff;
|
||||
case 3: v[2] = (dir->tdir_offset >> 8) & 0xff;
|
||||
case 2: v[1] = (dir->tdir_offset >> 16) & 0xff;
|
||||
case 1: v[0] = dir->tdir_offset >> 24;
|
||||
}
|
||||
} else {
|
||||
switch (dir->tdir_count) {
|
||||
case 4: v[3] = dir->tdir_offset >> 24;
|
||||
case 3: v[2] = (dir->tdir_offset >> 16) & 0xff;
|
||||
case 2: v[1] = (dir->tdir_offset >> 8) & 0xff;
|
||||
case 1: v[0] = dir->tdir_offset & 0xff;
|
||||
}
|
||||
if (dir->tdir_count <= 4) {
|
||||
/*
|
||||
* Extract data from offset field.
|
||||
*/
|
||||
if (tif->tif_header.tiff_magic == TIFF_BIGENDIAN) {
|
||||
if (dir->tdir_type == TIFF_SBYTE)
|
||||
switch (dir->tdir_count) {
|
||||
case 4: v[3] = (signed char)(dir->tdir_offset & 0xff);
|
||||
case 3: v[2] = (signed char)((dir->tdir_offset >> 8) & 0xff);
|
||||
case 2: v[1] = (signed char)((dir->tdir_offset >> 16) & 0xff);
|
||||
case 1: v[0] = (signed char)(dir->tdir_offset >> 24);
|
||||
}
|
||||
else
|
||||
switch (dir->tdir_count) {
|
||||
case 4: v[3] = (uint16)(dir->tdir_offset & 0xff);
|
||||
case 3: v[2] = (uint16)((dir->tdir_offset >> 8) & 0xff);
|
||||
case 2: v[1] = (uint16)((dir->tdir_offset >> 16) & 0xff);
|
||||
case 1: v[0] = (uint16)(dir->tdir_offset >> 24);
|
||||
}
|
||||
} else {
|
||||
if (dir->tdir_type == TIFF_SBYTE)
|
||||
switch (dir->tdir_count) {
|
||||
case 4: v[3] = (signed char)(dir->tdir_offset >> 24);
|
||||
case 3: v[2] = (signed char)((dir->tdir_offset >> 16) & 0xff);
|
||||
case 2: v[1] = (signed char)((dir->tdir_offset >> 8) & 0xff);
|
||||
case 1: v[0] = (signed char)(dir->tdir_offset & 0xff);
|
||||
}
|
||||
return (1);
|
||||
} else
|
||||
return (TIFFFetchData(tif, dir, (char*) v) != 0); /* XXX */
|
||||
else
|
||||
switch (dir->tdir_count) {
|
||||
case 4: v[3] = (uint16)(dir->tdir_offset >> 24);
|
||||
case 3: v[2] = (uint16)((dir->tdir_offset >> 16) & 0xff);
|
||||
case 2: v[1] = (uint16)((dir->tdir_offset >> 8) & 0xff);
|
||||
case 1: v[0] = (uint16)(dir->tdir_offset & 0xff);
|
||||
}
|
||||
}
|
||||
return (1);
|
||||
} else
|
||||
return (TIFFFetchData(tif, dir, (char*) v) != 0); /* XXX */
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -788,13 +897,13 @@ TIFFFetchShortArray(TIFF* tif, TIFFDirEntry* dir, uint16* v)
|
||||
if (dir->tdir_count <= 2) {
|
||||
if (tif->tif_header.tiff_magic == TIFF_BIGENDIAN) {
|
||||
switch (dir->tdir_count) {
|
||||
case 2: v[1] = dir->tdir_offset & 0xffff;
|
||||
case 1: v[0] = dir->tdir_offset >> 16;
|
||||
case 2: v[1] = (uint16) (dir->tdir_offset & 0xffff);
|
||||
case 1: v[0] = (uint16) (dir->tdir_offset >> 16);
|
||||
}
|
||||
} else {
|
||||
switch (dir->tdir_count) {
|
||||
case 2: v[1] = dir->tdir_offset >> 16;
|
||||
case 1: v[0] = dir->tdir_offset & 0xffff;
|
||||
case 2: v[1] = (uint16) (dir->tdir_offset >> 16);
|
||||
case 1: v[0] = (uint16) (dir->tdir_offset & 0xffff);
|
||||
}
|
||||
}
|
||||
return (1);
|
||||
@@ -808,7 +917,7 @@ TIFFFetchShortArray(TIFF* tif, TIFFDirEntry* dir, uint16* v)
|
||||
static int
|
||||
TIFFFetchShortPair(TIFF* tif, TIFFDirEntry* dir)
|
||||
{
|
||||
uint16 v[2];
|
||||
uint16 v[4];
|
||||
int ok = 0;
|
||||
|
||||
switch (dir->tdir_type) {
|
||||
@@ -849,7 +958,7 @@ TIFFFetchRationalArray(TIFF* tif, TIFFDirEntry* dir, float* v)
|
||||
uint32* l;
|
||||
|
||||
l = (uint32*)CheckMalloc(tif,
|
||||
dir->tdir_count*tiffDataWidth[dir->tdir_type],
|
||||
dir->tdir_count, TIFFDataWidth((TIFFDataType) dir->tdir_type),
|
||||
"to fetch array of rationals");
|
||||
if (l) {
|
||||
if (TIFFFetchData(tif, dir, (char *)l)) {
|
||||
@@ -980,7 +1089,7 @@ TIFFFetchAnyArray(TIFF* tif, TIFFDirEntry* dir, double* v)
|
||||
/* TIFF_ASCII */
|
||||
/* TIFF_UNDEFINED */
|
||||
TIFFError(tif->tif_name,
|
||||
"Cannot read TIFF_ANY type %d for field \"%s\"",
|
||||
"cannot read TIFF_ANY type %d for field \"%s\"",
|
||||
_TIFFFieldWithTag(tif, dir->tdir_tag)->field_name);
|
||||
return (0);
|
||||
}
|
||||
@@ -1005,35 +1114,35 @@ TIFFFetchNormalTag(TIFF* tif, TIFFDirEntry* dp)
|
||||
case TIFF_SBYTE:
|
||||
/* NB: always expand BYTE values to shorts */
|
||||
cp = CheckMalloc(tif,
|
||||
dp->tdir_count * sizeof (uint16), mesg);
|
||||
dp->tdir_count, sizeof (uint16), mesg);
|
||||
ok = cp && TIFFFetchByteArray(tif, dp, (uint16*) cp);
|
||||
break;
|
||||
case TIFF_SHORT:
|
||||
case TIFF_SSHORT:
|
||||
cp = CheckMalloc(tif,
|
||||
dp->tdir_count * sizeof (uint16), mesg);
|
||||
dp->tdir_count, sizeof (uint16), mesg);
|
||||
ok = cp && TIFFFetchShortArray(tif, dp, (uint16*) cp);
|
||||
break;
|
||||
case TIFF_LONG:
|
||||
case TIFF_SLONG:
|
||||
cp = CheckMalloc(tif,
|
||||
dp->tdir_count * sizeof (uint32), mesg);
|
||||
dp->tdir_count, sizeof (uint32), mesg);
|
||||
ok = cp && TIFFFetchLongArray(tif, dp, (uint32*) cp);
|
||||
break;
|
||||
case TIFF_RATIONAL:
|
||||
case TIFF_SRATIONAL:
|
||||
cp = CheckMalloc(tif,
|
||||
dp->tdir_count * sizeof (float), mesg);
|
||||
dp->tdir_count, sizeof (float), mesg);
|
||||
ok = cp && TIFFFetchRationalArray(tif, dp, (float*) cp);
|
||||
break;
|
||||
case TIFF_FLOAT:
|
||||
cp = CheckMalloc(tif,
|
||||
dp->tdir_count * sizeof (float), mesg);
|
||||
dp->tdir_count, sizeof (float), mesg);
|
||||
ok = cp && TIFFFetchFloatArray(tif, dp, (float*) cp);
|
||||
break;
|
||||
case TIFF_DOUBLE:
|
||||
cp = CheckMalloc(tif,
|
||||
dp->tdir_count * sizeof (double), mesg);
|
||||
dp->tdir_count, sizeof (double), mesg);
|
||||
ok = cp && TIFFFetchDoubleArray(tif, dp, (double*) cp);
|
||||
break;
|
||||
case TIFF_ASCII:
|
||||
@@ -1042,7 +1151,7 @@ TIFFFetchNormalTag(TIFF* tif, TIFFDirEntry* dp)
|
||||
* Some vendors write strings w/o the trailing
|
||||
* NULL byte, so always append one just in case.
|
||||
*/
|
||||
cp = CheckMalloc(tif, dp->tdir_count+1, mesg);
|
||||
cp = CheckMalloc(tif, dp->tdir_count+1, 1, mesg);
|
||||
if( (ok = (cp && TIFFFetchString(tif, dp, cp))) != 0 )
|
||||
cp[dp->tdir_count] = '\0'; /* XXX */
|
||||
break;
|
||||
@@ -1144,8 +1253,9 @@ TIFFFetchPerSampleShorts(TIFF* tif, TIFFDirEntry* dir, int* pl)
|
||||
uint16* v = buf;
|
||||
|
||||
if (samples > NITEMS(buf))
|
||||
v = (uint16*) _TIFFmalloc(samples * sizeof (uint16));
|
||||
if (TIFFFetchShortArray(tif, dir, v)) {
|
||||
v = (uint16*) CheckMalloc(tif, samples, sizeof (uint16),
|
||||
"to fetch per-sample values");
|
||||
if (v && TIFFFetchShortArray(tif, dir, v)) {
|
||||
int i;
|
||||
for (i = 1; i < samples; i++)
|
||||
if (v[i] != v[0]) {
|
||||
@@ -1158,7 +1268,7 @@ TIFFFetchPerSampleShorts(TIFF* tif, TIFFDirEntry* dir, int* pl)
|
||||
status = 1;
|
||||
}
|
||||
bad:
|
||||
if (v != buf)
|
||||
if (v && v != buf)
|
||||
_TIFFfree((char*) v);
|
||||
}
|
||||
return (status);
|
||||
@@ -1180,8 +1290,9 @@ TIFFFetchPerSampleAnys(TIFF* tif, TIFFDirEntry* dir, double* pl)
|
||||
double* v = buf;
|
||||
|
||||
if (samples > NITEMS(buf))
|
||||
v = (double*) _TIFFmalloc(samples * sizeof (double));
|
||||
if (TIFFFetchAnyArray(tif, dir, v)) {
|
||||
v = (double*) CheckMalloc(tif, samples, sizeof (double),
|
||||
"to fetch per-sample values");
|
||||
if (v && TIFFFetchAnyArray(tif, dir, v)) {
|
||||
int i;
|
||||
for (i = 1; i < samples; i++)
|
||||
if (v[i] != v[0]) {
|
||||
@@ -1194,7 +1305,7 @@ TIFFFetchPerSampleAnys(TIFF* tif, TIFFDirEntry* dir, double* pl)
|
||||
status = 1;
|
||||
}
|
||||
bad:
|
||||
if (v != buf)
|
||||
if (v && v != buf)
|
||||
_TIFFfree(v);
|
||||
}
|
||||
return (status);
|
||||
@@ -1212,32 +1323,58 @@ TIFFFetchStripThing(TIFF* tif, TIFFDirEntry* dir, long nstrips, uint32** lpp)
|
||||
register uint32* lp;
|
||||
int status;
|
||||
|
||||
if (!CheckDirCount(tif, dir, (uint32) nstrips))
|
||||
return (0);
|
||||
CheckDirCount(tif, dir, (uint32) nstrips);
|
||||
|
||||
/*
|
||||
* Allocate space for strip information.
|
||||
*/
|
||||
if (*lpp == NULL &&
|
||||
(*lpp = (uint32 *)CheckMalloc(tif,
|
||||
nstrips * sizeof (uint32), "for strip array")) == NULL)
|
||||
nstrips, sizeof (uint32), "for strip array")) == NULL)
|
||||
return (0);
|
||||
lp = *lpp;
|
||||
memset( lp, 0, sizeof(uint32) * nstrips );
|
||||
|
||||
if (dir->tdir_type == (int)TIFF_SHORT) {
|
||||
/*
|
||||
* Handle uint16->uint32 expansion.
|
||||
*/
|
||||
uint16* dp = (uint16*) CheckMalloc(tif,
|
||||
dir->tdir_count* sizeof (uint16), "to fetch strip tag");
|
||||
dir->tdir_count, sizeof (uint16), "to fetch strip tag");
|
||||
if (dp == NULL)
|
||||
return (0);
|
||||
if( (status = TIFFFetchShortArray(tif, dir, dp)) != 0 ) {
|
||||
register uint16* wp = dp;
|
||||
while (nstrips-- > 0)
|
||||
*lp++ = *wp++;
|
||||
int i;
|
||||
|
||||
for( i = 0; i < nstrips && i < (int) dir->tdir_count; i++ )
|
||||
{
|
||||
lp[i] = dp[i];
|
||||
}
|
||||
}
|
||||
_TIFFfree((char*) dp);
|
||||
|
||||
} else if( nstrips != (int) dir->tdir_count ) {
|
||||
/* Special case to correct length */
|
||||
|
||||
uint32* dp = (uint32*) CheckMalloc(tif,
|
||||
dir->tdir_count, sizeof (uint32), "to fetch strip tag");
|
||||
if (dp == NULL)
|
||||
return (0);
|
||||
|
||||
status = TIFFFetchLongArray(tif, dir, dp);
|
||||
if( status != 0 ) {
|
||||
int i;
|
||||
|
||||
for( i = 0; i < nstrips && i < (int) dir->tdir_count; i++ )
|
||||
{
|
||||
lp[i] = dp[i];
|
||||
}
|
||||
}
|
||||
|
||||
_TIFFfree( (char *) dp );
|
||||
} else
|
||||
status = TIFFFetchLongArray(tif, dir, lp);
|
||||
status = TIFFFetchLongArray(tif, dir, lp);
|
||||
|
||||
return (status);
|
||||
}
|
||||
|
||||
@@ -1252,8 +1389,12 @@ TIFFFetchExtraSamples(TIFF* tif, TIFFDirEntry* dir)
|
||||
uint16* v = buf;
|
||||
int status;
|
||||
|
||||
if (dir->tdir_count > NITEMS(buf))
|
||||
v = (uint16*) _TIFFmalloc(dir->tdir_count * sizeof (uint16));
|
||||
if (dir->tdir_count > NITEMS(buf)) {
|
||||
v = (uint16*) CheckMalloc(tif, dir->tdir_count, sizeof (uint16),
|
||||
"to fetch extra samples");
|
||||
if (!v)
|
||||
return (0);
|
||||
}
|
||||
if (dir->tdir_type == TIFF_BYTE)
|
||||
status = TIFFFetchByteArray(tif, dir, v);
|
||||
else
|
||||
@@ -1282,10 +1423,10 @@ TIFFFetchRefBlackWhite(TIFF* tif, TIFFDirEntry* dir)
|
||||
/*
|
||||
* Handle LONG's for backward compatibility.
|
||||
*/
|
||||
cp = CheckMalloc(tif, dir->tdir_count * sizeof (uint32), mesg);
|
||||
cp = CheckMalloc(tif, dir->tdir_count, sizeof (uint32), mesg);
|
||||
if( (ok = (cp && TIFFFetchLongArray(tif, dir, (uint32*) cp))) != 0) {
|
||||
float* fp = (float*)
|
||||
CheckMalloc(tif, dir->tdir_count * sizeof (float), mesg);
|
||||
CheckMalloc(tif, dir->tdir_count, sizeof (float), mesg);
|
||||
if( (ok = (fp != NULL)) != 0 ) {
|
||||
uint32 i;
|
||||
for (i = 0; i < dir->tdir_count; i++)
|
||||
@@ -1325,17 +1466,20 @@ ChopUpSingleUncompressedStrip(TIFF* tif)
|
||||
if (rowbytes > 8192) {
|
||||
stripbytes = rowbytes;
|
||||
rowsperstrip = 1;
|
||||
} else {
|
||||
} else if (rowbytes > 0 ) {
|
||||
rowsperstrip = 8192 / rowbytes;
|
||||
stripbytes = rowbytes * rowsperstrip;
|
||||
}
|
||||
else
|
||||
return;
|
||||
|
||||
/* never increase the number of strips in an image */
|
||||
if (rowsperstrip >= td->td_rowsperstrip)
|
||||
return;
|
||||
nstrips = (tstrip_t) TIFFhowmany(bytecount, stripbytes);
|
||||
newcounts = (uint32*) CheckMalloc(tif, nstrips * sizeof (uint32),
|
||||
newcounts = (uint32*) CheckMalloc(tif, nstrips, sizeof (uint32),
|
||||
"for chopped \"StripByteCounts\" array");
|
||||
newoffsets = (uint32*) CheckMalloc(tif, nstrips * sizeof (uint32),
|
||||
newoffsets = (uint32*) CheckMalloc(tif, nstrips, sizeof (uint32),
|
||||
"for chopped \"StripOffsets\" array");
|
||||
if (newcounts == NULL || newoffsets == NULL) {
|
||||
/*
|
||||
@@ -1354,7 +1498,7 @@ ChopUpSingleUncompressedStrip(TIFF* tif)
|
||||
* the broken-up format.
|
||||
*/
|
||||
for (strip = 0; strip < nstrips; strip++) {
|
||||
if (stripbytes > bytecount)
|
||||
if (stripbytes > (tsize_t) bytecount)
|
||||
stripbytes = bytecount;
|
||||
newcounts[strip] = stripbytes;
|
||||
newoffsets[strip] = offset;
|
||||
|
@@ -41,6 +41,7 @@ extern void TIFFCvtNativeToIEEEDouble(TIFF*, uint32, double*);
|
||||
|
||||
static int TIFFWriteNormalTag(TIFF*, TIFFDirEntry*, const TIFFFieldInfo*);
|
||||
static void TIFFSetupShortLong(TIFF*, ttag_t, TIFFDirEntry*, uint32);
|
||||
static void TIFFSetupShort(TIFF*, ttag_t, TIFFDirEntry*, uint16);
|
||||
static int TIFFSetupShortPair(TIFF*, ttag_t, TIFFDirEntry*);
|
||||
static int TIFFWritePerSampleShorts(TIFF*, ttag_t, TIFFDirEntry*);
|
||||
static int TIFFWritePerSampleAnys(TIFF*, TIFFDataType, ttag_t, TIFFDirEntry*);
|
||||
@@ -87,11 +88,11 @@ static int TIFFWriteRational(TIFF*,
|
||||
* handle overwriting a directory with auxiliary
|
||||
* storage that's been changed.
|
||||
*/
|
||||
int
|
||||
TIFFWriteDirectory(TIFF* tif)
|
||||
static int
|
||||
_TIFFWriteDirectory(TIFF* tif, int done)
|
||||
{
|
||||
uint16 dircount;
|
||||
uint32 diroff;
|
||||
toff_t diroff;
|
||||
ttag_t tag;
|
||||
uint32 nfields;
|
||||
tsize_t dirsize;
|
||||
@@ -108,30 +109,34 @@ TIFFWriteDirectory(TIFF* tif)
|
||||
* different characteristics get the right buffers
|
||||
* setup for them.
|
||||
*/
|
||||
if (tif->tif_flags & TIFF_POSTENCODE) {
|
||||
tif->tif_flags &= ~TIFF_POSTENCODE;
|
||||
if (!(*tif->tif_postencode)(tif)) {
|
||||
TIFFError(tif->tif_name,
|
||||
"Error post-encoding before directory write");
|
||||
return (0);
|
||||
}
|
||||
if (done)
|
||||
{
|
||||
if (tif->tif_flags & TIFF_POSTENCODE) {
|
||||
tif->tif_flags &= ~TIFF_POSTENCODE;
|
||||
if (!(*tif->tif_postencode)(tif)) {
|
||||
TIFFError(tif->tif_name,
|
||||
"Error post-encoding before directory write");
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
(*tif->tif_close)(tif); /* shutdown encoder */
|
||||
/*
|
||||
* Flush any data that might have been written
|
||||
* by the compression close+cleanup routines.
|
||||
*/
|
||||
if (tif->tif_rawcc > 0 && !TIFFFlushData1(tif)) {
|
||||
TIFFError(tif->tif_name,
|
||||
"Error flushing data before directory write");
|
||||
return (0);
|
||||
}
|
||||
if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata) {
|
||||
_TIFFfree(tif->tif_rawdata);
|
||||
tif->tif_rawdata = NULL;
|
||||
tif->tif_rawcc = 0;
|
||||
tif->tif_rawdatasize = 0;
|
||||
}
|
||||
tif->tif_flags &= ~(TIFF_BEENWRITING|TIFF_BUFFERSETUP);
|
||||
}
|
||||
(*tif->tif_close)(tif); /* shutdown encoder */
|
||||
/*
|
||||
* Flush any data that might have been written
|
||||
* by the compression close+cleanup routines.
|
||||
*/
|
||||
if (tif->tif_rawcc > 0 && !TIFFFlushData1(tif)) {
|
||||
TIFFError(tif->tif_name,
|
||||
"Error flushing data before directory write");
|
||||
return (0);
|
||||
}
|
||||
if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata) {
|
||||
_TIFFfree(tif->tif_rawdata);
|
||||
tif->tif_rawdata = NULL;
|
||||
tif->tif_rawcc = 0;
|
||||
}
|
||||
tif->tif_flags &= ~(TIFF_BEENWRITING|TIFF_BUFFERSETUP);
|
||||
|
||||
td = &tif->tif_dir;
|
||||
/*
|
||||
@@ -141,8 +146,9 @@ TIFFWriteDirectory(TIFF* tif)
|
||||
*/
|
||||
nfields = 0;
|
||||
for (b = 0; b <= FIELD_LAST; b++)
|
||||
if (TIFFFieldSet(tif, b))
|
||||
if (TIFFFieldSet(tif, b) && b != FIELD_CUSTOM)
|
||||
nfields += (b < FIELD_SUBFILETYPE ? 2 : 1);
|
||||
nfields += td->td_customValueCount;
|
||||
dirsize = nfields * sizeof (TIFFDirEntry);
|
||||
data = (char*) _TIFFmalloc(dirsize);
|
||||
if (data == NULL) {
|
||||
@@ -180,12 +186,35 @@ TIFFWriteDirectory(TIFF* tif)
|
||||
} /*XXX*/
|
||||
for (fi = 0, nfi = tif->tif_nfields; nfi > 0; nfi--, fi++) {
|
||||
const TIFFFieldInfo* fip = tif->tif_fieldinfo[fi];
|
||||
if (!FieldSet(fields, fip->field_bit))
|
||||
continue;
|
||||
switch (fip->field_bit) {
|
||||
|
||||
/*
|
||||
** For custom fields, we test to see if the custom field
|
||||
** is set or not. For normal fields, we just use the
|
||||
** FieldSet test.
|
||||
*/
|
||||
if( fip->field_bit == FIELD_CUSTOM )
|
||||
{
|
||||
int ci, is_set = FALSE;
|
||||
|
||||
for( ci = 0; ci < td->td_customValueCount; ci++ )
|
||||
is_set |= (td->td_customValues[ci].info == fip);
|
||||
|
||||
if( !is_set )
|
||||
continue;
|
||||
}
|
||||
else if (!FieldSet(fields, fip->field_bit))
|
||||
continue;
|
||||
|
||||
|
||||
/*
|
||||
** Handle other fields.
|
||||
*/
|
||||
switch (fip->field_bit)
|
||||
{
|
||||
case FIELD_STRIPOFFSETS:
|
||||
/*
|
||||
* We use one field bit for both strip and tile
|
||||
|
||||
* offsets, and so must be careful in selecting
|
||||
* the appropriate field descriptor (so that tags
|
||||
* are written in sorted order).
|
||||
@@ -234,6 +263,14 @@ TIFFWriteDirectory(TIFF* tif)
|
||||
TIFFSetupShortLong(tif, TIFFTAG_TILELENGTH,
|
||||
dir, td->td_tilelength);
|
||||
break;
|
||||
case FIELD_COMPRESSION:
|
||||
TIFFSetupShort(tif, TIFFTAG_COMPRESSION,
|
||||
dir, td->td_compression);
|
||||
break;
|
||||
case FIELD_PHOTOMETRIC:
|
||||
TIFFSetupShort(tif, TIFFTAG_PHOTOMETRIC,
|
||||
dir, td->td_photometric);
|
||||
break;
|
||||
case FIELD_POSITION:
|
||||
WriteRationalPair(TIFF_RATIONAL,
|
||||
TIFFTAG_XPOSITION, td->td_xposition,
|
||||
@@ -294,7 +331,7 @@ TIFFWriteDirectory(TIFF* tif)
|
||||
*/
|
||||
if (dir->tdir_count > 0) {
|
||||
tif->tif_flags |= TIFF_INSUBIFD;
|
||||
tif->tif_nsubifd = dir->tdir_count;
|
||||
tif->tif_nsubifd = (uint16) dir->tdir_count;
|
||||
if (dir->tdir_count > 1)
|
||||
tif->tif_subifdoff = dir->tdir_offset;
|
||||
else
|
||||
@@ -311,8 +348,11 @@ TIFFWriteDirectory(TIFF* tif)
|
||||
break;
|
||||
}
|
||||
dir++;
|
||||
ResetFieldBit(fields, fip->field_bit);
|
||||
|
||||
if( fip->field_bit != FIELD_CUSTOM )
|
||||
ResetFieldBit(fields, fip->field_bit);
|
||||
}
|
||||
|
||||
/*
|
||||
* Write directory.
|
||||
*/
|
||||
@@ -350,20 +390,18 @@ TIFFWriteDirectory(TIFF* tif)
|
||||
TIFFError(tif->tif_name, "Error writing directory link");
|
||||
goto bad;
|
||||
}
|
||||
TIFFFreeDirectory(tif);
|
||||
_TIFFfree(data);
|
||||
tif->tif_flags &= ~TIFF_DIRTYDIRECT;
|
||||
(*tif->tif_cleanup)(tif);
|
||||
if (done) {
|
||||
TIFFFreeDirectory(tif);
|
||||
tif->tif_flags &= ~TIFF_DIRTYDIRECT;
|
||||
(*tif->tif_cleanup)(tif);
|
||||
|
||||
/*
|
||||
* Reset directory-related state for subsequent
|
||||
* directories.
|
||||
*/
|
||||
TIFFDefaultDirectory(tif);
|
||||
tif->tif_diroff = 0;
|
||||
tif->tif_curoff = 0;
|
||||
tif->tif_row = (uint32) -1;
|
||||
tif->tif_curstrip = (tstrip_t) -1;
|
||||
/*
|
||||
* Reset directory-related state for subsequent
|
||||
* directories.
|
||||
*/
|
||||
TIFFCreateDirectory(tif);
|
||||
}
|
||||
_TIFFfree(data);
|
||||
return (1);
|
||||
bad:
|
||||
_TIFFfree(data);
|
||||
@@ -371,6 +409,30 @@ bad:
|
||||
}
|
||||
#undef WriteRationalPair
|
||||
|
||||
int
|
||||
TIFFWriteDirectory(TIFF* tif)
|
||||
{
|
||||
return _TIFFWriteDirectory(tif, TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Similar to TIFFWriteDirectory(), writes the directory out
|
||||
* but leaves all data structures in memory so that it can be
|
||||
* written again. This will make a partially written TIFF file
|
||||
* readable before it is successfully completed/closed.
|
||||
*/
|
||||
int
|
||||
TIFFCheckpointDirectory(TIFF* tif)
|
||||
{
|
||||
int rc;
|
||||
/* Setup the strips arrays, if they haven't already been. */
|
||||
if (tif->tif_dir.td_stripoffset == NULL)
|
||||
(void) TIFFSetupStrips(tif);
|
||||
rc = _TIFFWriteDirectory(tif, FALSE);
|
||||
(void) TIFFSetWriteOffset(tif, TIFFSeekFile(tif, 0, SEEK_END));
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
* Process tags that are not special cased.
|
||||
*/
|
||||
@@ -380,7 +442,7 @@ TIFFWriteNormalTag(TIFF* tif, TIFFDirEntry* dir, const TIFFFieldInfo* fip)
|
||||
u_short wc = (u_short) fip->field_writecount;
|
||||
uint32 wc2;
|
||||
|
||||
dir->tdir_tag = fip->field_tag;
|
||||
dir->tdir_tag = (uint16) fip->field_tag;
|
||||
dir->tdir_type = (u_short) fip->field_type;
|
||||
dir->tdir_count = wc;
|
||||
#define WRITEF(x,y) x(tif, fip->field_type, fip->field_tag, dir, wc, y)
|
||||
@@ -389,81 +451,123 @@ TIFFWriteNormalTag(TIFF* tif, TIFFDirEntry* dir, const TIFFFieldInfo* fip)
|
||||
case TIFF_SSHORT:
|
||||
if (wc > 1) {
|
||||
uint16* wp;
|
||||
if (wc == (u_short) TIFF_VARIABLE)
|
||||
if (wc == (u_short) TIFF_VARIABLE
|
||||
|| fip->field_passcount)
|
||||
TIFFGetField(tif, fip->field_tag, &wc, &wp);
|
||||
else
|
||||
TIFFGetField(tif, fip->field_tag, &wp);
|
||||
if (!WRITEF(TIFFWriteShortArray, wp))
|
||||
return (0);
|
||||
} else {
|
||||
uint16 sv;
|
||||
TIFFGetField(tif, fip->field_tag, &sv);
|
||||
dir->tdir_offset =
|
||||
TIFFInsertData(tif, dir->tdir_type, sv);
|
||||
if (fip->field_passcount) {
|
||||
uint16* wp;
|
||||
TIFFGetField(tif, fip->field_tag, &wc, &wp);
|
||||
if (!WRITEF(TIFFWriteShortArray, wp))
|
||||
return 0;
|
||||
} else {
|
||||
uint16 sv;
|
||||
TIFFGetField(tif, fip->field_tag, &sv);
|
||||
dir->tdir_offset =
|
||||
TIFFInsertData(tif, dir->tdir_type, sv);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TIFF_LONG:
|
||||
case TIFF_SLONG:
|
||||
case TIFF_IFD:
|
||||
if (wc > 1) {
|
||||
uint32* lp;
|
||||
if (wc == (u_short) TIFF_VARIABLE)
|
||||
if (wc == (u_short) TIFF_VARIABLE
|
||||
|| fip->field_passcount)
|
||||
TIFFGetField(tif, fip->field_tag, &wc, &lp);
|
||||
else
|
||||
TIFFGetField(tif, fip->field_tag, &lp);
|
||||
if (!WRITEF(TIFFWriteLongArray, lp))
|
||||
return (0);
|
||||
} else {
|
||||
/* XXX handle LONG->SHORT conversion */
|
||||
TIFFGetField(tif, fip->field_tag, &dir->tdir_offset);
|
||||
if (fip->field_passcount) {
|
||||
uint32* lp;
|
||||
TIFFGetField(tif, fip->field_tag, &wc, &lp);
|
||||
if (!WRITEF(TIFFWriteLongArray, lp))
|
||||
return 0;
|
||||
} else {
|
||||
/* XXX handle LONG->SHORT conversion */
|
||||
TIFFGetField(tif, fip->field_tag,
|
||||
&dir->tdir_offset);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TIFF_RATIONAL:
|
||||
case TIFF_SRATIONAL:
|
||||
if (wc > 1) {
|
||||
float* fp;
|
||||
if (wc == (u_short) TIFF_VARIABLE)
|
||||
if (wc == (u_short) TIFF_VARIABLE
|
||||
|| fip->field_passcount)
|
||||
TIFFGetField(tif, fip->field_tag, &wc, &fp);
|
||||
else
|
||||
TIFFGetField(tif, fip->field_tag, &fp);
|
||||
if (!WRITEF(TIFFWriteRationalArray, fp))
|
||||
return (0);
|
||||
} else {
|
||||
float fv;
|
||||
TIFFGetField(tif, fip->field_tag, &fv);
|
||||
if (!WRITEF(TIFFWriteRationalArray, &fv))
|
||||
return (0);
|
||||
if (fip->field_passcount) {
|
||||
float* fp;
|
||||
TIFFGetField(tif, fip->field_tag, &wc, &fp);
|
||||
if (!WRITEF(TIFFWriteRationalArray, fp))
|
||||
return 0;
|
||||
} else {
|
||||
float fv;
|
||||
TIFFGetField(tif, fip->field_tag, &fv);
|
||||
if (!WRITEF(TIFFWriteRationalArray, &fv))
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TIFF_FLOAT:
|
||||
if (wc > 1) {
|
||||
float* fp;
|
||||
if (wc == (u_short) TIFF_VARIABLE)
|
||||
if (wc == (u_short) TIFF_VARIABLE
|
||||
|| fip->field_passcount)
|
||||
TIFFGetField(tif, fip->field_tag, &wc, &fp);
|
||||
else
|
||||
TIFFGetField(tif, fip->field_tag, &fp);
|
||||
if (!WRITEF(TIFFWriteFloatArray, fp))
|
||||
return (0);
|
||||
} else {
|
||||
float fv;
|
||||
TIFFGetField(tif, fip->field_tag, &fv);
|
||||
if (!WRITEF(TIFFWriteFloatArray, &fv))
|
||||
return (0);
|
||||
if (fip->field_passcount) {
|
||||
float* fp;
|
||||
TIFFGetField(tif, fip->field_tag, &wc, &fp);
|
||||
if (!WRITEF(TIFFWriteFloatArray, fp))
|
||||
return 0;
|
||||
} else {
|
||||
float fv;
|
||||
TIFFGetField(tif, fip->field_tag, &fv);
|
||||
if (!WRITEF(TIFFWriteFloatArray, &fv))
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TIFF_DOUBLE:
|
||||
if (wc > 1) {
|
||||
double* dp;
|
||||
if (wc == (u_short) TIFF_VARIABLE)
|
||||
if (wc == (u_short) TIFF_VARIABLE
|
||||
|| fip->field_passcount)
|
||||
TIFFGetField(tif, fip->field_tag, &wc, &dp);
|
||||
else
|
||||
TIFFGetField(tif, fip->field_tag, &dp);
|
||||
if (!WRITEF(TIFFWriteDoubleArray, dp))
|
||||
return (0);
|
||||
} else {
|
||||
double dv;
|
||||
TIFFGetField(tif, fip->field_tag, &dv);
|
||||
if (!WRITEF(TIFFWriteDoubleArray, &dv))
|
||||
return (0);
|
||||
if (fip->field_passcount) {
|
||||
double* dp;
|
||||
TIFFGetField(tif, fip->field_tag, &wc, &dp);
|
||||
if (!WRITEF(TIFFWriteDoubleArray, dp))
|
||||
return 0;
|
||||
} else {
|
||||
double dv;
|
||||
TIFFGetField(tif, fip->field_tag, &dv);
|
||||
if (!WRITEF(TIFFWriteDoubleArray, &dv))
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TIFF_ASCII:
|
||||
@@ -479,20 +583,32 @@ TIFFWriteNormalTag(TIFF* tif, TIFFDirEntry* dir, const TIFFFieldInfo* fip)
|
||||
correctness not verified (FW, 99/08) */
|
||||
case TIFF_BYTE:
|
||||
case TIFF_SBYTE:
|
||||
if (wc > 1) {
|
||||
char* cp;
|
||||
if (wc == (u_short) TIFF_VARIABLE) {
|
||||
TIFFGetField(tif, fip->field_tag, &wc, &cp);
|
||||
dir->tdir_count = wc;
|
||||
} else
|
||||
TIFFGetField(tif, fip->field_tag, &cp);
|
||||
if (!TIFFWriteByteArray(tif, dir, cp))
|
||||
return (0);
|
||||
if (wc > 1) {
|
||||
char* cp;
|
||||
if (wc == (u_short) TIFF_VARIABLE
|
||||
|| fip->field_passcount) {
|
||||
TIFFGetField(tif, fip->field_tag, &wc, &cp);
|
||||
dir->tdir_count = wc;
|
||||
} else if (wc == (u_short) TIFF_VARIABLE2) {
|
||||
TIFFGetField(tif, fip->field_tag, &wc2, &cp);
|
||||
dir->tdir_count = wc2;
|
||||
} else
|
||||
TIFFGetField(tif, fip->field_tag, &cp);
|
||||
if (!TIFFWriteByteArray(tif, dir, cp))
|
||||
return (0);
|
||||
} else {
|
||||
char cv;
|
||||
TIFFGetField(tif, fip->field_tag, &cv);
|
||||
if (!TIFFWriteByteArray(tif, dir, &cv))
|
||||
return (0);
|
||||
if (fip->field_passcount) {
|
||||
char* cp;
|
||||
TIFFGetField(tif, fip->field_tag, &wc, &cp);
|
||||
dir->tdir_count = wc;
|
||||
if (!TIFFWriteByteArray(tif, dir, cp))
|
||||
return 0;
|
||||
} else {
|
||||
char cv;
|
||||
TIFFGetField(tif, fip->field_tag, &cv);
|
||||
if (!TIFFWriteByteArray(tif, dir, &cv))
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -525,7 +641,7 @@ TIFFWriteNormalTag(TIFF* tif, TIFFDirEntry* dir, const TIFFFieldInfo* fip)
|
||||
static void
|
||||
TIFFSetupShortLong(TIFF* tif, ttag_t tag, TIFFDirEntry* dir, uint32 v)
|
||||
{
|
||||
dir->tdir_tag = tag;
|
||||
dir->tdir_tag = (uint16) tag;
|
||||
dir->tdir_count = 1;
|
||||
if (v > 0xffffL) {
|
||||
dir->tdir_type = (short) TIFF_LONG;
|
||||
@@ -535,6 +651,18 @@ TIFFSetupShortLong(TIFF* tif, ttag_t tag, TIFFDirEntry* dir, uint32 v)
|
||||
dir->tdir_offset = TIFFInsertData(tif, (int) TIFF_SHORT, v);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Setup a SHORT directory entry
|
||||
*/
|
||||
static void
|
||||
TIFFSetupShort(TIFF* tif, ttag_t tag, TIFFDirEntry* dir, uint16 v)
|
||||
{
|
||||
dir->tdir_tag = (uint16) tag;
|
||||
dir->tdir_count = 1;
|
||||
dir->tdir_type = (short) TIFF_SHORT;
|
||||
dir->tdir_offset = TIFFInsertData(tif, (int) TIFF_SHORT, v);
|
||||
}
|
||||
#undef MakeShortDirent
|
||||
|
||||
#ifndef TIFFWriteRational
|
||||
@@ -564,8 +692,14 @@ TIFFWritePerSampleShorts(TIFF* tif, ttag_t tag, TIFFDirEntry* dir)
|
||||
uint16* w = buf;
|
||||
int i, status, samples = tif->tif_dir.td_samplesperpixel;
|
||||
|
||||
if (samples > NITEMS(buf))
|
||||
if (samples > NITEMS(buf)) {
|
||||
w = (uint16*) _TIFFmalloc(samples * sizeof (uint16));
|
||||
if (w == NULL) {
|
||||
TIFFError(tif->tif_name,
|
||||
"No space to write per-sample shorts");
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
TIFFGetField(tif, tag, &v);
|
||||
for (i = 0; i < samples; i++)
|
||||
w[i] = v;
|
||||
@@ -589,8 +723,14 @@ TIFFWritePerSampleAnys(TIFF* tif,
|
||||
int i, status;
|
||||
int samples = (int) tif->tif_dir.td_samplesperpixel;
|
||||
|
||||
if (samples > NITEMS(buf))
|
||||
if (samples > NITEMS(buf)) {
|
||||
w = (double*) _TIFFmalloc(samples * sizeof (double));
|
||||
if (w == NULL) {
|
||||
TIFFError(tif->tif_name,
|
||||
"No space to write per-sample values");
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
TIFFGetField(tif, tag, &v);
|
||||
for (i = 0; i < samples; i++)
|
||||
w[i] = v;
|
||||
@@ -625,7 +765,7 @@ TIFFWriteShortTable(TIFF* tif,
|
||||
{
|
||||
uint32 i, off;
|
||||
|
||||
dir->tdir_tag = tag;
|
||||
dir->tdir_tag = (uint16) tag;
|
||||
dir->tdir_type = (short) TIFF_SHORT;
|
||||
/* XXX -- yech, fool TIFFWriteData */
|
||||
dir->tdir_count = (uint32) (1L<<tif->tif_dir.td_bitspersample);
|
||||
@@ -660,7 +800,7 @@ static int
|
||||
TIFFWriteShortArray(TIFF* tif,
|
||||
TIFFDataType type, ttag_t tag, TIFFDirEntry* dir, uint32 n, uint16* v)
|
||||
{
|
||||
dir->tdir_tag = tag;
|
||||
dir->tdir_tag = (uint16) tag;
|
||||
dir->tdir_type = (short) type;
|
||||
dir->tdir_count = n;
|
||||
if (n <= 2) {
|
||||
@@ -686,7 +826,7 @@ static int
|
||||
TIFFWriteLongArray(TIFF* tif,
|
||||
TIFFDataType type, ttag_t tag, TIFFDirEntry* dir, uint32 n, uint32* v)
|
||||
{
|
||||
dir->tdir_tag = tag;
|
||||
dir->tdir_tag = (uint16) tag;
|
||||
dir->tdir_type = (short) type;
|
||||
dir->tdir_count = n;
|
||||
if (n == 1) {
|
||||
@@ -708,10 +848,15 @@ TIFFWriteRationalArray(TIFF* tif,
|
||||
uint32* t;
|
||||
int status;
|
||||
|
||||
dir->tdir_tag = tag;
|
||||
dir->tdir_tag = (uint16) tag;
|
||||
dir->tdir_type = (short) type;
|
||||
dir->tdir_count = n;
|
||||
t = (uint32*) _TIFFmalloc(2*n * sizeof (uint32));
|
||||
if (t == NULL) {
|
||||
TIFFError(tif->tif_name,
|
||||
"No space to write RATIONAL array");
|
||||
return (0);
|
||||
}
|
||||
for (i = 0; i < n; i++) {
|
||||
float fv = v[i];
|
||||
int sign = 1;
|
||||
@@ -731,7 +876,7 @@ TIFFWriteRationalArray(TIFF* tif,
|
||||
while (fv < 1L<<(31-3) && den < 1L<<(31-3))
|
||||
fv *= 1<<3, den *= 1L<<3;
|
||||
}
|
||||
t[2*i+0] = sign * (fv + 0.5);
|
||||
t[2*i+0] = (uint32) (sign * (fv + 0.5));
|
||||
t[2*i+1] = den;
|
||||
}
|
||||
status = TIFFWriteData(tif, dir, (char *)t);
|
||||
@@ -743,7 +888,7 @@ static int
|
||||
TIFFWriteFloatArray(TIFF* tif,
|
||||
TIFFDataType type, ttag_t tag, TIFFDirEntry* dir, uint32 n, float* v)
|
||||
{
|
||||
dir->tdir_tag = tag;
|
||||
dir->tdir_tag = (uint16) tag;
|
||||
dir->tdir_type = (short) type;
|
||||
dir->tdir_count = n;
|
||||
TIFFCvtNativeToIEEEFloat(tif, n, v);
|
||||
@@ -758,7 +903,7 @@ static int
|
||||
TIFFWriteDoubleArray(TIFF* tif,
|
||||
TIFFDataType type, ttag_t tag, TIFFDirEntry* dir, uint32 n, double* v)
|
||||
{
|
||||
dir->tdir_tag = tag;
|
||||
dir->tdir_tag = (uint16) tag;
|
||||
dir->tdir_type = (short) type;
|
||||
dir->tdir_count = n;
|
||||
TIFFCvtNativeToIEEEDouble(tif, n, v);
|
||||
@@ -782,14 +927,20 @@ TIFFWriteAnyArray(TIFF* tif,
|
||||
char* w = buf;
|
||||
int i, status = 0;
|
||||
|
||||
if (n * tiffDataWidth[type] > sizeof buf)
|
||||
w = (char*) _TIFFmalloc(n * tiffDataWidth[type]);
|
||||
if (n * TIFFDataWidth(type) > sizeof buf) {
|
||||
w = (char*) _TIFFmalloc(n * TIFFDataWidth(type));
|
||||
if (w == NULL) {
|
||||
TIFFError(tif->tif_name,
|
||||
"No space to write array");
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
switch (type) {
|
||||
case TIFF_BYTE:
|
||||
{ uint8* bp = (uint8*) w;
|
||||
for (i = 0; i < n; i++)
|
||||
for (i = 0; i < (int) n; i++)
|
||||
bp[i] = (uint8) v[i];
|
||||
dir->tdir_tag = tag;
|
||||
dir->tdir_tag = (uint16) tag;
|
||||
dir->tdir_type = (short) type;
|
||||
dir->tdir_count = n;
|
||||
if (!TIFFWriteByteArray(tif, dir, (char*) bp))
|
||||
@@ -798,9 +949,9 @@ TIFFWriteAnyArray(TIFF* tif,
|
||||
break;
|
||||
case TIFF_SBYTE:
|
||||
{ int8* bp = (int8*) w;
|
||||
for (i = 0; i < n; i++)
|
||||
for (i = 0; i < (int) n; i++)
|
||||
bp[i] = (int8) v[i];
|
||||
dir->tdir_tag = tag;
|
||||
dir->tdir_tag = (uint16) tag;
|
||||
dir->tdir_type = (short) type;
|
||||
dir->tdir_count = n;
|
||||
if (!TIFFWriteByteArray(tif, dir, (char*) bp))
|
||||
@@ -809,7 +960,7 @@ TIFFWriteAnyArray(TIFF* tif,
|
||||
break;
|
||||
case TIFF_SHORT:
|
||||
{ uint16* bp = (uint16*) w;
|
||||
for (i = 0; i < n; i++)
|
||||
for (i = 0; i < (int) n; i++)
|
||||
bp[i] = (uint16) v[i];
|
||||
if (!TIFFWriteShortArray(tif, type, tag, dir, n, (uint16*)bp))
|
||||
goto out;
|
||||
@@ -817,7 +968,7 @@ TIFFWriteAnyArray(TIFF* tif,
|
||||
break;
|
||||
case TIFF_SSHORT:
|
||||
{ int16* bp = (int16*) w;
|
||||
for (i = 0; i < n; i++)
|
||||
for (i = 0; i < (int) n; i++)
|
||||
bp[i] = (int16) v[i];
|
||||
if (!TIFFWriteShortArray(tif, type, tag, dir, n, (uint16*)bp))
|
||||
goto out;
|
||||
@@ -825,7 +976,7 @@ TIFFWriteAnyArray(TIFF* tif,
|
||||
break;
|
||||
case TIFF_LONG:
|
||||
{ uint32* bp = (uint32*) w;
|
||||
for (i = 0; i < n; i++)
|
||||
for (i = 0; i < (int) n; i++)
|
||||
bp[i] = (uint32) v[i];
|
||||
if (!TIFFWriteLongArray(tif, type, tag, dir, n, bp))
|
||||
goto out;
|
||||
@@ -833,7 +984,7 @@ TIFFWriteAnyArray(TIFF* tif,
|
||||
break;
|
||||
case TIFF_SLONG:
|
||||
{ int32* bp = (int32*) w;
|
||||
for (i = 0; i < n; i++)
|
||||
for (i = 0; i < (int) n; i++)
|
||||
bp[i] = (int32) v[i];
|
||||
if (!TIFFWriteLongArray(tif, type, tag, dir, n, (uint32*) bp))
|
||||
goto out;
|
||||
@@ -841,7 +992,7 @@ TIFFWriteAnyArray(TIFF* tif,
|
||||
break;
|
||||
case TIFF_FLOAT:
|
||||
{ float* bp = (float*) w;
|
||||
for (i = 0; i < n; i++)
|
||||
for (i = 0; i < (int) n; i++)
|
||||
bp[i] = (float) v[i];
|
||||
if (!TIFFWriteFloatArray(tif, type, tag, dir, n, bp))
|
||||
goto out;
|
||||
@@ -931,7 +1082,7 @@ TIFFWriteData(TIFF* tif, TIFFDirEntry* dir, char* cp)
|
||||
}
|
||||
}
|
||||
dir->tdir_offset = tif->tif_dataoff;
|
||||
cc = dir->tdir_count * tiffDataWidth[dir->tdir_type];
|
||||
cc = dir->tdir_count * TIFFDataWidth((TIFFDataType) dir->tdir_type);
|
||||
if (SeekOK(tif, dir->tdir_offset) &&
|
||||
WriteOK(tif, cp, cc)) {
|
||||
tif->tif_dataoff += (cc + 1) & ~1;
|
||||
@@ -942,6 +1093,87 @@ TIFFWriteData(TIFF* tif, TIFFDirEntry* dir, char* cp)
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Similar to TIFFWriteDirectory(), but if the directory has already
|
||||
* been written once, it is relocated to the end of the file, in case it
|
||||
* has changed in size. Note that this will result in the loss of the
|
||||
* previously used directory space.
|
||||
*/
|
||||
|
||||
int
|
||||
TIFFRewriteDirectory( TIFF *tif )
|
||||
{
|
||||
static const char module[] = "TIFFRewriteDirectory";
|
||||
|
||||
/* We don't need to do anything special if it hasn't been written. */
|
||||
if( tif->tif_diroff == 0 )
|
||||
return TIFFWriteDirectory( tif );
|
||||
|
||||
/*
|
||||
** Find and zero the pointer to this directory, so that TIFFLinkDirectory
|
||||
** will cause it to be added after this directories current pre-link.
|
||||
*/
|
||||
|
||||
/* Is it the first directory in the file? */
|
||||
if (tif->tif_header.tiff_diroff == tif->tif_diroff)
|
||||
{
|
||||
tif->tif_header.tiff_diroff = 0;
|
||||
tif->tif_diroff = 0;
|
||||
|
||||
#if defined(__hpux) && defined(__LP64__)
|
||||
#define HDROFF(f) ((toff_t)(unsigned long) &(((TIFFHeader*) 0)->f))
|
||||
#else
|
||||
#define HDROFF(f) ((toff_t) &(((TIFFHeader*) 0)->f))
|
||||
#endif
|
||||
TIFFSeekFile(tif, HDROFF(tiff_diroff), SEEK_SET);
|
||||
if (!WriteOK(tif, &(tif->tif_header.tiff_diroff),
|
||||
sizeof (tif->tif_diroff)))
|
||||
{
|
||||
TIFFError(tif->tif_name, "Error updating TIFF header");
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
toff_t nextdir, off;
|
||||
|
||||
nextdir = tif->tif_header.tiff_diroff;
|
||||
do {
|
||||
uint16 dircount;
|
||||
|
||||
if (!SeekOK(tif, nextdir) ||
|
||||
!ReadOK(tif, &dircount, sizeof (dircount))) {
|
||||
TIFFError(module, "Error fetching directory count");
|
||||
return (0);
|
||||
}
|
||||
if (tif->tif_flags & TIFF_SWAB)
|
||||
TIFFSwabShort(&dircount);
|
||||
(void) TIFFSeekFile(tif,
|
||||
dircount * sizeof (TIFFDirEntry), SEEK_CUR);
|
||||
if (!ReadOK(tif, &nextdir, sizeof (nextdir))) {
|
||||
TIFFError(module, "Error fetching directory link");
|
||||
return (0);
|
||||
}
|
||||
if (tif->tif_flags & TIFF_SWAB)
|
||||
TIFFSwabLong(&nextdir);
|
||||
} while (nextdir != tif->tif_diroff && nextdir != 0);
|
||||
off = TIFFSeekFile(tif, 0, SEEK_CUR); /* get current offset */
|
||||
(void) TIFFSeekFile(tif, off - (toff_t)sizeof(nextdir), SEEK_SET);
|
||||
tif->tif_diroff = 0;
|
||||
if (!WriteOK(tif, &(tif->tif_diroff), sizeof (nextdir))) {
|
||||
TIFFError(module, "Error writing directory link");
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Now use TIFFWriteDirectory() normally.
|
||||
*/
|
||||
|
||||
return TIFFWriteDirectory( tif );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Link the current directory into the
|
||||
* directory chain for the file.
|
||||
@@ -950,11 +1182,11 @@ static int
|
||||
TIFFLinkDirectory(TIFF* tif)
|
||||
{
|
||||
static const char module[] = "TIFFLinkDirectory";
|
||||
uint32 nextdir;
|
||||
uint32 diroff;
|
||||
toff_t nextdir;
|
||||
toff_t diroff, off;
|
||||
|
||||
tif->tif_diroff = (TIFFSeekFile(tif, (toff_t) 0, SEEK_END)+1) &~ 1;
|
||||
diroff = (uint32) tif->tif_diroff;
|
||||
diroff = tif->tif_diroff;
|
||||
if (tif->tif_flags & TIFF_SWAB)
|
||||
TIFFSwabLong(&diroff);
|
||||
#if SUBIFD_SUPPORT
|
||||
@@ -982,7 +1214,7 @@ TIFFLinkDirectory(TIFF* tif)
|
||||
/*
|
||||
* First directory, overwrite offset in header.
|
||||
*/
|
||||
tif->tif_header.tiff_diroff = (uint32) tif->tif_diroff;
|
||||
tif->tif_header.tiff_diroff = tif->tif_diroff;
|
||||
#define HDROFF(f) ((toff_t) &(((TIFFHeader*) 0)->f))
|
||||
(void) TIFFSeekFile(tif, HDROFF(tiff_diroff), SEEK_SET);
|
||||
if (!WriteOK(tif, &diroff, sizeof (diroff))) {
|
||||
@@ -1014,7 +1246,8 @@ TIFFLinkDirectory(TIFF* tif)
|
||||
if (tif->tif_flags & TIFF_SWAB)
|
||||
TIFFSwabLong(&nextdir);
|
||||
} while (nextdir != 0);
|
||||
(void) TIFFSeekFile(tif, -(toff_t) sizeof (nextdir), SEEK_CUR);
|
||||
off = TIFFSeekFile(tif, 0, SEEK_CUR); /* get current offset */
|
||||
(void) TIFFSeekFile(tif, off - (toff_t)sizeof(nextdir), SEEK_SET);
|
||||
if (!WriteOK(tif, &diroff, sizeof (diroff))) {
|
||||
TIFFError(module, "Error writing directory link");
|
||||
return (0);
|
||||
|
@@ -4,23 +4,23 @@
|
||||
* Copyright (c) 1988-1997 Sam Leffler
|
||||
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* its documentation for any purpose is hereby granted without fee, provided
|
||||
* that (i) the above copyright notices and this permission notice appear in
|
||||
* all copies of the software and related documentation, and (ii) the names of
|
||||
* Sam Leffler and Silicon Graphics may not be used in any advertising or
|
||||
* publicity relating to the software without the specific, prior written
|
||||
* permission of Sam Leffler and Silicon Graphics.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
|
||||
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
|
||||
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
||||
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
||||
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
@@ -30,11 +30,12 @@
|
||||
* "Null" Compression Algorithm Support.
|
||||
*/
|
||||
#include "tiffiop.h"
|
||||
#include <assert.h>
|
||||
|
||||
/*
|
||||
* Encode a hunk of pixels.
|
||||
*/
|
||||
static int LINKAGEMODE
|
||||
static int
|
||||
DumpModeEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
|
||||
{
|
||||
(void) s;
|
||||
@@ -44,6 +45,9 @@ DumpModeEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
|
||||
n = cc;
|
||||
if (tif->tif_rawcc + n > tif->tif_rawdatasize)
|
||||
n = tif->tif_rawdatasize - tif->tif_rawcc;
|
||||
|
||||
assert( n > 0 );
|
||||
|
||||
/*
|
||||
* Avoid copy if client has setup raw
|
||||
* data buffer to avoid extra copy.
|
||||
@@ -64,7 +68,7 @@ DumpModeEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
|
||||
/*
|
||||
* Decode a hunk of pixels.
|
||||
*/
|
||||
static int LINKAGEMODE
|
||||
static int
|
||||
DumpModeDecode(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s)
|
||||
{
|
||||
(void) s;
|
||||
@@ -88,7 +92,7 @@ DumpModeDecode(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s)
|
||||
/*
|
||||
* Seek forwards nrows in the current strip.
|
||||
*/
|
||||
static int LINKAGEMODE
|
||||
static int
|
||||
DumpModeSeek(TIFF* tif, uint32 nrows)
|
||||
{
|
||||
tif->tif_rawcp += nrows * tif->tif_scanlinesize;
|
||||
|
@@ -4,23 +4,23 @@
|
||||
* Copyright (c) 1990-1997 Sam Leffler
|
||||
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* its documentation for any purpose is hereby granted without fee, provided
|
||||
* that (i) the above copyright notices and this permission notice appear in
|
||||
* all copies of the software and related documentation, and (ii) the names of
|
||||
* Sam Leffler and Silicon Graphics may not be used in any advertising or
|
||||
* publicity relating to the software without the specific, prior written
|
||||
* permission of Sam Leffler and Silicon Graphics.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
|
||||
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
|
||||
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
||||
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
||||
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
@@ -44,17 +44,12 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
* NB: define PURIFY if you're using purify and you want
|
||||
* to avoid some harmless array bounds complaints that
|
||||
* can happen in the _TIFFFax3fillruns routine.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Compression+decompression state blocks are
|
||||
* derived from this ``base state'' block.
|
||||
*/
|
||||
typedef struct {
|
||||
int rw_mode; /* O_RDONLY for decode, else encode */
|
||||
int mode; /* operating mode */
|
||||
uint32 rowbytes; /* bytes in a decoded scanline */
|
||||
uint32 rowpixels; /* pixels in a scanline */
|
||||
@@ -71,8 +66,11 @@ typedef struct {
|
||||
} Fax3BaseState;
|
||||
#define Fax3State(tif) ((Fax3BaseState*) (tif)->tif_data)
|
||||
|
||||
typedef enum { G3_1D, G3_2D } Ttag;
|
||||
typedef struct {
|
||||
Fax3BaseState b;
|
||||
|
||||
/* Decoder state info */
|
||||
const u_char* bitmap; /* bit reversal table */
|
||||
uint32 data; /* current i/o byte/word */
|
||||
int bit; /* current i/o bit in byte */
|
||||
@@ -81,19 +79,15 @@ typedef struct {
|
||||
uint32* runs; /* b&w runs for current/previous row */
|
||||
uint32* refruns; /* runs for reference line */
|
||||
uint32* curruns; /* runs for current line */
|
||||
} Fax3DecodeState;
|
||||
#define DecoderState(tif) ((Fax3DecodeState*) Fax3State(tif))
|
||||
|
||||
typedef struct {
|
||||
Fax3BaseState b;
|
||||
int data; /* current i/o byte */
|
||||
int bit; /* current i/o bit in byte */
|
||||
enum { G3_1D, G3_2D } tag; /* encoding state */
|
||||
u_char* refline; /* reference line for 2d decoding */
|
||||
int k; /* #rows left that can be 2d encoded */
|
||||
int maxk; /* max #rows that can be 2d encoded */
|
||||
} Fax3EncodeState;
|
||||
#define EncoderState(tif) ((Fax3EncodeState*) Fax3State(tif))
|
||||
/* Encoder state info */
|
||||
Ttag tag; /* encoding state */
|
||||
u_char* refline; /* reference line for 2d decoding */
|
||||
int k; /* #rows left that can be 2d encoded */
|
||||
int maxk; /* max #rows that can be 2d encoded */
|
||||
} Fax3CodecState;
|
||||
#define DecoderState(tif) ((Fax3CodecState*) Fax3State(tif))
|
||||
#define EncoderState(tif) ((Fax3CodecState*) Fax3State(tif))
|
||||
|
||||
#define is2DEncoding(sp) \
|
||||
(sp->b.groupoptions & GROUP3OPT_2DENCODING)
|
||||
@@ -109,7 +103,7 @@ typedef struct {
|
||||
*/
|
||||
#define DECLARE_STATE(tif, sp, mod) \
|
||||
static const char module[] = mod; \
|
||||
Fax3DecodeState* sp = DecoderState(tif); \
|
||||
Fax3CodecState* sp = DecoderState(tif); \
|
||||
int a0; /* reference element */ \
|
||||
int lastx = sp->b.rowpixels; /* last element in row */ \
|
||||
uint32 BitAcc; /* bit accumulator */ \
|
||||
@@ -153,7 +147,7 @@ typedef struct {
|
||||
static int
|
||||
Fax3PreDecode(TIFF* tif, tsample_t s)
|
||||
{
|
||||
Fax3DecodeState* sp = DecoderState(tif);
|
||||
Fax3CodecState* sp = DecoderState(tif);
|
||||
|
||||
(void) s;
|
||||
assert(sp != NULL);
|
||||
@@ -170,7 +164,7 @@ Fax3PreDecode(TIFF* tif, tsample_t s)
|
||||
sp->bitmap =
|
||||
TIFFGetBitRevTable(tif->tif_dir.td_fillorder != FILLORDER_LSB2MSB);
|
||||
if (sp->refruns) { /* init reference line to white */
|
||||
sp->refruns[0] = sp->b.rowpixels;
|
||||
sp->refruns[0] = (uint32) sp->b.rowpixels;
|
||||
sp->refruns[1] = 0;
|
||||
}
|
||||
return (1);
|
||||
@@ -182,7 +176,7 @@ Fax3PreDecode(TIFF* tif, tsample_t s)
|
||||
* overriding the definitions used by the decoder.
|
||||
*/
|
||||
|
||||
static void LINKAGEMODE
|
||||
static void
|
||||
Fax3Unexpected(const char* module, TIFF* tif, uint32 a0)
|
||||
{
|
||||
TIFFError(module, "%s: Bad code word at scanline %d (x %lu)",
|
||||
@@ -190,7 +184,7 @@ Fax3Unexpected(const char* module, TIFF* tif, uint32 a0)
|
||||
}
|
||||
#define unexpected(table, a0) Fax3Unexpected(module, tif, a0)
|
||||
|
||||
static void LINKAGEMODE
|
||||
static void
|
||||
Fax3Extension(const char* module, TIFF* tif, uint32 a0)
|
||||
{
|
||||
TIFFError(module,
|
||||
@@ -199,7 +193,7 @@ Fax3Extension(const char* module, TIFF* tif, uint32 a0)
|
||||
}
|
||||
#define extension(a0) Fax3Extension(module, tif, a0)
|
||||
|
||||
static void LINKAGEMODE
|
||||
static void
|
||||
Fax3BadLength(const char* module, TIFF* tif, uint32 a0, uint32 lastx)
|
||||
{
|
||||
TIFFWarning(module, "%s: %s at scanline %d (got %lu, expected %lu)",
|
||||
@@ -209,7 +203,7 @@ Fax3BadLength(const char* module, TIFF* tif, uint32 a0, uint32 lastx)
|
||||
}
|
||||
#define badlength(a0,lastx) Fax3BadLength(module, tif, a0, lastx)
|
||||
|
||||
static void LINKAGEMODE
|
||||
static void
|
||||
Fax3PrematureEOF(const char* module, TIFF* tif, uint32 a0)
|
||||
{
|
||||
TIFFWarning(module, "%s: Premature EOF at scanline %d (x %lu)",
|
||||
@@ -222,7 +216,7 @@ Fax3PrematureEOF(const char* module, TIFF* tif, uint32 a0)
|
||||
/*
|
||||
* Decode the requested amount of G3 1D-encoded data.
|
||||
*/
|
||||
static int LINKAGEMODE
|
||||
static int
|
||||
Fax3Decode1D(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
|
||||
{
|
||||
DECLARE_STATE(tif, sp, "Fax3Decode1D");
|
||||
@@ -244,8 +238,6 @@ Fax3Decode1D(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
|
||||
(*sp->fill)(buf, thisrun, pa, lastx);
|
||||
buf += sp->b.rowbytes;
|
||||
occ -= sp->b.rowbytes;
|
||||
if (occ != 0)
|
||||
tif->tif_row++;
|
||||
continue;
|
||||
EOF1D: /* premature EOF */
|
||||
CLEANUP_RUNS();
|
||||
@@ -262,7 +254,7 @@ Fax3Decode1D(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
|
||||
/*
|
||||
* Decode the requested amount of G3 2D-encoded data.
|
||||
*/
|
||||
static int LINKAGEMODE
|
||||
static int
|
||||
Fax3Decode2D(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
|
||||
{
|
||||
DECLARE_STATE_2D(tif, sp, "Fax3Decode2D");
|
||||
@@ -298,8 +290,6 @@ Fax3Decode2D(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
|
||||
SWAP(uint32*, sp->curruns, sp->refruns);
|
||||
buf += sp->b.rowbytes;
|
||||
occ -= sp->b.rowbytes;
|
||||
if (occ != 0)
|
||||
tif->tif_row++;
|
||||
continue;
|
||||
EOF2D: /* premature EOF */
|
||||
CLEANUP_RUNS();
|
||||
@@ -319,7 +309,7 @@ Fax3Decode2D(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
|
||||
* this is <8 bytes. We optimize the code here to reflect the
|
||||
* machine characteristics.
|
||||
*/
|
||||
#if defined(__alpha) || _MIPS_SZLONG == 64
|
||||
#if defined(__alpha) || _MIPS_SZLONG == 64 || defined(__LP64__) || defined(__arch64__)
|
||||
#define FILL(n, cp) \
|
||||
switch (n) { \
|
||||
case 15:(cp)[14] = 0xff; case 14:(cp)[13] = 0xff; case 13: (cp)[12] = 0xff;\
|
||||
@@ -372,8 +362,8 @@ _TIFFFax3fillruns(u_char* buf, uint32* runs, uint32* erun, uint32 lastx)
|
||||
x = 0;
|
||||
for (; runs < erun; runs += 2) {
|
||||
run = runs[0];
|
||||
if (x+run > lastx)
|
||||
run = runs[0] = lastx - x;
|
||||
if (x+run > lastx || run > lastx )
|
||||
run = runs[0] = (uint32) (lastx - x);
|
||||
if (run) {
|
||||
cp = buf + (x>>3);
|
||||
bx = x&7;
|
||||
@@ -400,18 +390,14 @@ _TIFFFax3fillruns(u_char* buf, uint32* runs, uint32* erun, uint32 lastx)
|
||||
ZERO(n, cp);
|
||||
run &= 7;
|
||||
}
|
||||
#ifdef PURIFY
|
||||
if (run)
|
||||
cp[0] &= 0xff >> run;
|
||||
#else
|
||||
cp[0] &= 0xff >> run;
|
||||
#endif
|
||||
} else
|
||||
cp[0] &= ~(_fillmasks[run]>>bx);
|
||||
x += runs[0];
|
||||
}
|
||||
run = runs[1];
|
||||
if (x+run > lastx)
|
||||
if (x+run > lastx || run > lastx )
|
||||
run = runs[1] = lastx - x;
|
||||
if (run) {
|
||||
cp = buf + (x>>3);
|
||||
@@ -439,12 +425,8 @@ _TIFFFax3fillruns(u_char* buf, uint32* runs, uint32* erun, uint32 lastx)
|
||||
FILL(n, cp);
|
||||
run &= 7;
|
||||
}
|
||||
#ifdef PURIFY
|
||||
if (run)
|
||||
cp[0] |= 0xff00 >> run;
|
||||
#else
|
||||
cp[0] |= 0xff00 >> run;
|
||||
#endif
|
||||
} else
|
||||
cp[0] |= _fillmasks[run]>>bx;
|
||||
x += runs[1];
|
||||
@@ -455,6 +437,21 @@ _TIFFFax3fillruns(u_char* buf, uint32* runs, uint32* erun, uint32 lastx)
|
||||
#undef ZERO
|
||||
#undef FILL
|
||||
|
||||
static char *
|
||||
CheckMalloc(TIFF* tif, size_t nmemb, size_t elem_size, const char* what)
|
||||
{
|
||||
char *cp = NULL;
|
||||
tsize_t bytes = nmemb * elem_size;
|
||||
|
||||
if (elem_size && bytes / elem_size == nmemb)
|
||||
cp = (char*) _TIFFmalloc(bytes);
|
||||
|
||||
if (cp == NULL)
|
||||
TIFFError(tif->tif_name, "No space %s", what);
|
||||
|
||||
return (cp);
|
||||
}
|
||||
|
||||
/*
|
||||
* Setup G3/G4-related compression/decompression state
|
||||
* before data is processed. This routine is called once
|
||||
@@ -469,6 +466,8 @@ Fax3SetupState(TIFF* tif)
|
||||
Fax3BaseState* sp = Fax3State(tif);
|
||||
long rowbytes, rowpixels;
|
||||
int needsRefLine;
|
||||
Fax3CodecState* dsp = DecoderState(tif);
|
||||
uint32 nruns;
|
||||
|
||||
if (td->td_bitspersample != 1) {
|
||||
TIFFError(tif->tif_name,
|
||||
@@ -494,31 +493,26 @@ Fax3SetupState(TIFF* tif)
|
||||
(sp->groupoptions & GROUP3OPT_2DENCODING) ||
|
||||
td->td_compression == COMPRESSION_CCITTFAX4
|
||||
);
|
||||
if (tif->tif_mode == O_RDONLY) { /* 1d/2d decoding */
|
||||
Fax3DecodeState* dsp = DecoderState(tif);
|
||||
uint32 nruns = needsRefLine ?
|
||||
2*TIFFroundup(rowpixels,32) : rowpixels;
|
||||
|
||||
dsp->runs = (uint32*) _TIFFmalloc((2*nruns+3)*sizeof (uint32));
|
||||
nruns = needsRefLine ? 2*TIFFroundup(rowpixels,32) : rowpixels;
|
||||
|
||||
if (dsp->runs == NULL) {
|
||||
TIFFError("Fax3SetupState",
|
||||
"%s: No space for Group 3/4 run arrays",
|
||||
tif->tif_name);
|
||||
return (0);
|
||||
}
|
||||
dsp->curruns = dsp->runs;
|
||||
if (needsRefLine)
|
||||
dsp->refruns = dsp->runs + (nruns>>1);
|
||||
else
|
||||
dsp->refruns = NULL;
|
||||
if (is2DEncoding(dsp)) { /* NB: default is 1D routine */
|
||||
tif->tif_decoderow = Fax3Decode2D;
|
||||
tif->tif_decodestrip = Fax3Decode2D;
|
||||
tif->tif_decodetile = Fax3Decode2D;
|
||||
}
|
||||
} else if (needsRefLine) { /* 2d encoding */
|
||||
Fax3EncodeState* esp = EncoderState(tif);
|
||||
dsp->runs = (uint32*) CheckMalloc(tif, 2*nruns+3, sizeof (uint32),
|
||||
"for Group 3/4 run arrays");
|
||||
if (dsp->runs == NULL)
|
||||
return (0);
|
||||
dsp->curruns = dsp->runs;
|
||||
if (needsRefLine)
|
||||
dsp->refruns = dsp->runs + (nruns>>1);
|
||||
else
|
||||
dsp->refruns = NULL;
|
||||
if (is2DEncoding(dsp)) { /* NB: default is 1D routine */
|
||||
tif->tif_decoderow = Fax3Decode2D;
|
||||
tif->tif_decodestrip = Fax3Decode2D;
|
||||
tif->tif_decodetile = Fax3Decode2D;
|
||||
}
|
||||
|
||||
if (needsRefLine) { /* 2d encoding */
|
||||
Fax3CodecState* esp = EncoderState(tif);
|
||||
/*
|
||||
* 2d encoding requires a scanline
|
||||
* buffer for the ``reference line''; the
|
||||
@@ -545,14 +539,14 @@ Fax3SetupState(TIFF* tif)
|
||||
#define Fax3FlushBits(tif, sp) { \
|
||||
if ((tif)->tif_rawcc >= (tif)->tif_rawdatasize) \
|
||||
(void) TIFFFlushData1(tif); \
|
||||
*(tif)->tif_rawcp++ = (sp)->data; \
|
||||
*(tif)->tif_rawcp++ = (tidataval_t) (sp)->data; \
|
||||
(tif)->tif_rawcc++; \
|
||||
(sp)->data = 0, (sp)->bit = 8; \
|
||||
}
|
||||
#define _FlushBits(tif) { \
|
||||
if ((tif)->tif_rawcc >= (tif)->tif_rawdatasize) \
|
||||
(void) TIFFFlushData1(tif); \
|
||||
*(tif)->tif_rawcp++ = data; \
|
||||
*(tif)->tif_rawcp++ = (tidataval_t) data; \
|
||||
(tif)->tif_rawcc++; \
|
||||
data = 0, bit = 8; \
|
||||
}
|
||||
@@ -575,11 +569,11 @@ static const int _msbmask[9] =
|
||||
* the output stream. Values are
|
||||
* assumed to be at most 16 bits.
|
||||
*/
|
||||
static void LINKAGEMODE
|
||||
static void
|
||||
Fax3PutBits(TIFF* tif, u_int bits, u_int length)
|
||||
{
|
||||
Fax3EncodeState* sp = EncoderState(tif);
|
||||
int bit = sp->bit;
|
||||
Fax3CodecState* sp = EncoderState(tif);
|
||||
u_int bit = sp->bit;
|
||||
int data = sp->data;
|
||||
|
||||
_PutBits(tif, bits, length);
|
||||
@@ -610,11 +604,11 @@ Fax3PutBits(TIFF* tif, u_int bits, u_int length)
|
||||
* appropriate table that holds the make-up and
|
||||
* terminating codes is supplied.
|
||||
*/
|
||||
static void LINKAGEMODE
|
||||
static void
|
||||
putspan(TIFF* tif, int32 span, const tableentry* tab)
|
||||
{
|
||||
Fax3EncodeState* sp = EncoderState(tif);
|
||||
int bit = sp->bit;
|
||||
Fax3CodecState* sp = EncoderState(tif);
|
||||
u_int bit = sp->bit;
|
||||
int data = sp->data;
|
||||
u_int code, length;
|
||||
|
||||
@@ -653,13 +647,13 @@ putspan(TIFF* tif, int32 span, const tableentry* tab)
|
||||
* here. We also handle writing the tag bit for the next
|
||||
* scanline when doing 2d encoding.
|
||||
*/
|
||||
static void LINKAGEMODE
|
||||
static void
|
||||
Fax3PutEOL(TIFF* tif)
|
||||
{
|
||||
Fax3EncodeState* sp = EncoderState(tif);
|
||||
int bit = sp->bit;
|
||||
Fax3CodecState* sp = EncoderState(tif);
|
||||
u_int bit = sp->bit;
|
||||
int data = sp->data;
|
||||
u_int code, length;
|
||||
u_int code, length, tparm;
|
||||
|
||||
if (sp->b.groupoptions & GROUP3OPT_FILLBITS) {
|
||||
/*
|
||||
@@ -674,17 +668,13 @@ Fax3PutEOL(TIFF* tif)
|
||||
else
|
||||
align = sp->bit - align;
|
||||
code = 0;
|
||||
_PutBits(tif, 0, align);
|
||||
tparm=align;
|
||||
_PutBits(tif, 0, tparm);
|
||||
}
|
||||
}
|
||||
code = EOL, length = 12;
|
||||
if (is2DEncoding(sp))
|
||||
#if defined(__VISAGECPP30__)
|
||||
/* VA 3.0 is just plain wierd. */
|
||||
code = (code<<1) | (sp->tag == Fax3EncodeState::G3_1D), length++;
|
||||
#else
|
||||
code = (code<<1) | (sp->tag == G3_1D), length++;
|
||||
#endif
|
||||
_PutBits(tif, code, length);
|
||||
|
||||
sp->data = data;
|
||||
@@ -697,18 +687,13 @@ Fax3PutEOL(TIFF* tif)
|
||||
static int
|
||||
Fax3PreEncode(TIFF* tif, tsample_t s)
|
||||
{
|
||||
Fax3EncodeState* sp = EncoderState(tif);
|
||||
Fax3CodecState* sp = EncoderState(tif);
|
||||
|
||||
(void) s;
|
||||
assert(sp != NULL);
|
||||
sp->bit = 8;
|
||||
sp->data = 0;
|
||||
#if defined(__VISAGECPP30__)
|
||||
/* VA 3.0 is just plain wierd. */
|
||||
sp->tag = Fax3EncodeState::G3_1D;
|
||||
#else
|
||||
sp->tag = G3_1D;
|
||||
#endif
|
||||
/*
|
||||
* This is necessary for Group 4; otherwise it isn't
|
||||
* needed because the first scanline of each strip ends
|
||||
@@ -789,7 +774,7 @@ static int32 find1span(u_char*, int32, int32);
|
||||
* table. The ``base'' of the bit string is supplied
|
||||
* along with the start+end bit indices.
|
||||
*/
|
||||
INLINE static int32 LINKAGEMODE
|
||||
INLINE static int32
|
||||
find0span(u_char* bp, int32 bs, int32 be)
|
||||
{
|
||||
int32 bits = be - bs;
|
||||
@@ -848,7 +833,7 @@ find0span(u_char* bp, int32 bs, int32 be)
|
||||
return (span);
|
||||
}
|
||||
|
||||
INLINE static int32 LINKAGEMODE
|
||||
INLINE static int32
|
||||
find1span(u_char* bp, int32 bs, int32 be)
|
||||
{
|
||||
int32 bits = be - bs;
|
||||
@@ -927,11 +912,12 @@ find1span(u_char* bp, int32 bs, int32 be)
|
||||
* a sequence of all-white or all-black spans
|
||||
* of pixels encoded with Huffman codes.
|
||||
*/
|
||||
static int LINKAGEMODE
|
||||
static int
|
||||
Fax3Encode1DRow(TIFF* tif, u_char* bp, uint32 bits)
|
||||
{
|
||||
Fax3EncodeState* sp = EncoderState(tif);
|
||||
int32 bs = 0, span;
|
||||
Fax3CodecState* sp = EncoderState(tif);
|
||||
int32 span;
|
||||
uint32 bs = 0;
|
||||
|
||||
for (;;) {
|
||||
span = find0span(bp, bs, bits); /* white span */
|
||||
@@ -973,14 +959,14 @@ static const tableentry vcodes[7] = {
|
||||
* 2d-encode a row of pixels. Consult the CCITT
|
||||
* documentation for the algorithm.
|
||||
*/
|
||||
static int LINKAGEMODE
|
||||
static int
|
||||
Fax3Encode2DRow(TIFF* tif, u_char* bp, u_char* rp, uint32 bits)
|
||||
{
|
||||
#define PIXEL(buf,ix) ((((buf)[(ix)>>3]) >> (7-((ix)&7))) & 1)
|
||||
int32 a0 = 0;
|
||||
int32 a1 = (PIXEL(bp, 0) != 0 ? 0 : finddiff(bp, 0, bits, 0));
|
||||
int32 b1 = (PIXEL(rp, 0) != 0 ? 0 : finddiff(rp, 0, bits, 0));
|
||||
int32 a2, b2;
|
||||
uint32 a0 = 0;
|
||||
uint32 a1 = (PIXEL(bp, 0) != 0 ? 0 : finddiff(bp, 0, bits, 0));
|
||||
uint32 b1 = (PIXEL(rp, 0) != 0 ? 0 : finddiff(rp, 0, bits, 0));
|
||||
uint32 a2, b2;
|
||||
|
||||
for (;;) {
|
||||
b2 = finddiff2(rp, b1, bits, PIXEL(rp,b1));
|
||||
@@ -1018,42 +1004,27 @@ Fax3Encode2DRow(TIFF* tif, u_char* bp, u_char* rp, uint32 bits)
|
||||
/*
|
||||
* Encode a buffer of pixels.
|
||||
*/
|
||||
static int LINKAGEMODE
|
||||
static int
|
||||
Fax3Encode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
|
||||
{
|
||||
Fax3EncodeState* sp = EncoderState(tif);
|
||||
Fax3CodecState* sp = EncoderState(tif);
|
||||
|
||||
(void) s;
|
||||
while ((long)cc > 0) {
|
||||
if ((sp->b.mode & FAXMODE_NOEOL) == 0)
|
||||
Fax3PutEOL(tif);
|
||||
if (is2DEncoding(sp)) {
|
||||
#if defined(__VISAGECPP30__)
|
||||
/* VA 3.0 is just plain wierd. */
|
||||
if (sp->tag == Fax3EncodeState::G3_1D) {
|
||||
#else
|
||||
if (sp->tag == G3_1D) {
|
||||
#endif
|
||||
if (!Fax3Encode1DRow(tif, bp, sp->b.rowpixels))
|
||||
return (0);
|
||||
#if defined(__VISAGECPP30__)
|
||||
/* VA 3.0 is just plain wierd. */
|
||||
sp->tag = Fax3EncodeState::G3_2D;
|
||||
#else
|
||||
sp->tag = G3_2D;
|
||||
#endif
|
||||
} else {
|
||||
if (!Fax3Encode2DRow(tif, bp, sp->refline, sp->b.rowpixels))
|
||||
return (0);
|
||||
sp->k--;
|
||||
}
|
||||
if (sp->k == 0) {
|
||||
#if defined(__VISAGECPP30__)
|
||||
/* VA 3.0 is just plain wierd. */
|
||||
sp->tag = Fax3EncodeState::G3_1D;
|
||||
#else
|
||||
sp->tag = G3_1D;
|
||||
#endif
|
||||
sp->k = sp->maxk-1;
|
||||
} else
|
||||
_TIFFmemcpy(sp->refline, bp, sp->b.rowbytes);
|
||||
@@ -1063,8 +1034,6 @@ Fax3Encode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
|
||||
}
|
||||
bp += sp->b.rowbytes;
|
||||
cc -= sp->b.rowbytes;
|
||||
if (cc != 0)
|
||||
tif->tif_row++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
@@ -1072,7 +1041,7 @@ Fax3Encode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
|
||||
static int
|
||||
Fax3PostEncode(TIFF* tif)
|
||||
{
|
||||
Fax3EncodeState* sp = EncoderState(tif);
|
||||
Fax3CodecState* sp = EncoderState(tif);
|
||||
|
||||
if (sp->bit != 8)
|
||||
Fax3FlushBits(tif, sp);
|
||||
@@ -1083,18 +1052,13 @@ static void
|
||||
Fax3Close(TIFF* tif)
|
||||
{
|
||||
if ((Fax3State(tif)->mode & FAXMODE_NORTC) == 0) {
|
||||
Fax3EncodeState* sp = EncoderState(tif);
|
||||
Fax3CodecState* sp = EncoderState(tif);
|
||||
u_int code = EOL;
|
||||
u_int length = 12;
|
||||
int i;
|
||||
|
||||
if (is2DEncoding(sp))
|
||||
#if defined(__VISAGECPP30__)
|
||||
/* VA 3.0 is just plain wierd. */
|
||||
code = (code<<1) | (sp->tag == Fax3EncodeState::G3_1D), length++;
|
||||
#else
|
||||
code = (code<<1) | (sp->tag == G3_1D), length++;
|
||||
#endif
|
||||
for (i = 0; i < 6; i++)
|
||||
Fax3PutBits(tif, code, length);
|
||||
Fax3FlushBits(tif, sp);
|
||||
@@ -1105,15 +1069,13 @@ static void
|
||||
Fax3Cleanup(TIFF* tif)
|
||||
{
|
||||
if (tif->tif_data) {
|
||||
if (tif->tif_mode == O_RDONLY) {
|
||||
Fax3DecodeState* sp = DecoderState(tif);
|
||||
if (sp->runs)
|
||||
_TIFFfree(sp->runs);
|
||||
} else {
|
||||
Fax3EncodeState* sp = EncoderState(tif);
|
||||
if (sp->refline)
|
||||
_TIFFfree(sp->refline);
|
||||
}
|
||||
Fax3CodecState* sp = DecoderState(tif);
|
||||
|
||||
if (sp->runs)
|
||||
_TIFFfree(sp->runs);
|
||||
if (sp->refline)
|
||||
_TIFFfree(sp->refline);
|
||||
|
||||
if (Fax3State(tif)->subaddress)
|
||||
_TIFFfree(Fax3State(tif)->subaddress);
|
||||
_TIFFfree(tif->tif_data);
|
||||
@@ -1172,8 +1134,7 @@ Fax3VSetField(TIFF* tif, ttag_t tag, va_list ap)
|
||||
sp->mode = va_arg(ap, int);
|
||||
return (1); /* NB: pseudo tag */
|
||||
case TIFFTAG_FAXFILLFUNC:
|
||||
if (tif->tif_mode == O_RDONLY)
|
||||
DecoderState(tif)->fill = va_arg(ap, TIFFFaxFillFunc);
|
||||
DecoderState(tif)->fill = va_arg(ap, TIFFFaxFillFunc);
|
||||
return (1); /* NB: pseudo tag */
|
||||
case TIFFTAG_GROUP3OPTIONS:
|
||||
case TIFFTAG_GROUP4OPTIONS:
|
||||
@@ -1215,8 +1176,7 @@ Fax3VGetField(TIFF* tif, ttag_t tag, va_list ap)
|
||||
*va_arg(ap, int*) = sp->mode;
|
||||
break;
|
||||
case TIFFTAG_FAXFILLFUNC:
|
||||
if (tif->tif_mode == O_RDONLY)
|
||||
*va_arg(ap, TIFFFaxFillFunc*) = DecoderState(tif)->fill;
|
||||
*va_arg(ap, TIFFFaxFillFunc*) = DecoderState(tif)->fill;
|
||||
break;
|
||||
case TIFFTAG_GROUP3OPTIONS:
|
||||
case TIFFTAG_GROUP4OPTIONS:
|
||||
@@ -1246,7 +1206,7 @@ Fax3VGetField(TIFF* tif, ttag_t tag, va_list ap)
|
||||
return (1);
|
||||
}
|
||||
|
||||
static void LINKAGEMODE
|
||||
static void
|
||||
Fax3PrintDir(TIFF* tif, FILE* fd, long flags)
|
||||
{
|
||||
Fax3BaseState* sp = Fax3State(tif);
|
||||
@@ -1302,7 +1262,7 @@ Fax3PrintDir(TIFF* tif, FILE* fd, long flags)
|
||||
(u_long) sp->recvtime);
|
||||
}
|
||||
|
||||
static int LINKAGEMODE
|
||||
static int
|
||||
InitCCITTFax3(TIFF* tif)
|
||||
{
|
||||
Fax3BaseState* sp;
|
||||
@@ -1310,43 +1270,36 @@ InitCCITTFax3(TIFF* tif)
|
||||
/*
|
||||
* Allocate state block so tag methods have storage to record values.
|
||||
*/
|
||||
if (tif->tif_mode == O_RDONLY)
|
||||
#if defined(__VISAGECPP__)
|
||||
tif->tif_data = (tidata_t)_TIFFmalloc(sizeof (Fax3DecodeState));
|
||||
else
|
||||
tif->tif_data = (tidata_t)_TIFFmalloc(sizeof (Fax3EncodeState));
|
||||
#else
|
||||
tif->tif_data = _TIFFmalloc(sizeof (Fax3DecodeState));
|
||||
else
|
||||
tif->tif_data = _TIFFmalloc(sizeof (Fax3EncodeState));
|
||||
#endif
|
||||
tif->tif_data = (tidata_t)
|
||||
_TIFFmalloc(sizeof (Fax3CodecState));
|
||||
|
||||
if (tif->tif_data == NULL) {
|
||||
TIFFError("TIFFInitCCITTFax3",
|
||||
"%s: No space for state block", tif->tif_name);
|
||||
return (0);
|
||||
}
|
||||
|
||||
sp = Fax3State(tif);
|
||||
sp->rw_mode = tif->tif_mode;
|
||||
|
||||
/*
|
||||
* Merge codec-specific tag information and
|
||||
* override parent get/set field methods.
|
||||
*/
|
||||
_TIFFMergeFieldInfo(tif, faxFieldInfo, N(faxFieldInfo));
|
||||
sp->vgetparent = tif->tif_vgetfield;
|
||||
tif->tif_vgetfield = Fax3VGetField; /* hook for codec tags */
|
||||
sp->vsetparent = tif->tif_vsetfield;
|
||||
tif->tif_vsetfield = Fax3VSetField; /* hook for codec tags */
|
||||
tif->tif_printdir = Fax3PrintDir; /* hook for codec tags */
|
||||
sp->vgetparent = tif->tif_tagmethods.vgetfield;
|
||||
tif->tif_tagmethods.vgetfield = Fax3VGetField; /* hook for codec tags */
|
||||
sp->vsetparent = tif->tif_tagmethods.vsetfield;
|
||||
tif->tif_tagmethods.vsetfield = Fax3VSetField; /* hook for codec tags */
|
||||
tif->tif_tagmethods.printdir = Fax3PrintDir; /* hook for codec tags */
|
||||
sp->groupoptions = 0;
|
||||
sp->recvparams = 0;
|
||||
sp->subaddress = NULL;
|
||||
|
||||
if (tif->tif_mode == O_RDONLY) {
|
||||
tif->tif_flags |= TIFF_NOBITREV;/* decoder does bit reversal */
|
||||
DecoderState(tif)->runs = NULL;
|
||||
TIFFSetField(tif, TIFFTAG_FAXFILLFUNC, _TIFFFax3fillruns);
|
||||
} else
|
||||
EncoderState(tif)->refline = NULL;
|
||||
tif->tif_flags |= TIFF_NOBITREV; /* decoder does bit reversal */
|
||||
DecoderState(tif)->runs = NULL;
|
||||
TIFFSetField(tif, TIFFTAG_FAXFILLFUNC, _TIFFFax3fillruns);
|
||||
EncoderState(tif)->refline = NULL;
|
||||
|
||||
/*
|
||||
* Install codec methods.
|
||||
@@ -1391,7 +1344,7 @@ TIFFInitCCITTFax3(TIFF* tif, int scheme)
|
||||
/*
|
||||
* Decode the requested amount of G4-encoded data.
|
||||
*/
|
||||
static int LINKAGEMODE
|
||||
static int
|
||||
Fax4Decode(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
|
||||
{
|
||||
DECLARE_STATE_2D(tif, sp, "Fax4Decode");
|
||||
@@ -1410,15 +1363,22 @@ Fax4Decode(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
|
||||
fflush(stdout);
|
||||
#endif
|
||||
EXPAND2D(EOFG4);
|
||||
if (EOLcnt)
|
||||
goto EOFG4;
|
||||
(*sp->fill)(buf, thisrun, pa, lastx);
|
||||
SETVAL(0); /* imaginary change for reference */
|
||||
SWAP(uint32*, sp->curruns, sp->refruns);
|
||||
buf += sp->b.rowbytes;
|
||||
occ -= sp->b.rowbytes;
|
||||
if (occ != 0)
|
||||
tif->tif_row++;
|
||||
continue;
|
||||
EOFG4:
|
||||
NeedBits16( 13, BADG4 );
|
||||
BADG4:
|
||||
#ifdef FAX3_DEBUG
|
||||
if( GetBits(13) != 0x1001 )
|
||||
fputs( "Bad RTC\n", stderr );
|
||||
#endif
|
||||
ClrBits( 13 );
|
||||
(*sp->fill)(buf, thisrun, pa, lastx);
|
||||
UNCACHE_STATE(tif, sp);
|
||||
return (-1);
|
||||
@@ -1431,10 +1391,10 @@ Fax4Decode(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
|
||||
/*
|
||||
* Encode the requested amount of data.
|
||||
*/
|
||||
static int LINKAGEMODE
|
||||
static int
|
||||
Fax4Encode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
|
||||
{
|
||||
Fax3EncodeState *sp = EncoderState(tif);
|
||||
Fax3CodecState *sp = EncoderState(tif);
|
||||
|
||||
(void) s;
|
||||
while ((long)cc > 0) {
|
||||
@@ -1443,8 +1403,6 @@ Fax4Encode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
|
||||
_TIFFmemcpy(sp->refline, bp, sp->b.rowbytes);
|
||||
bp += sp->b.rowbytes;
|
||||
cc -= sp->b.rowbytes;
|
||||
if (cc != 0)
|
||||
tif->tif_row++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
@@ -1452,7 +1410,7 @@ Fax4Encode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
|
||||
static int
|
||||
Fax4PostEncode(TIFF* tif)
|
||||
{
|
||||
Fax3EncodeState *sp = EncoderState(tif);
|
||||
Fax3CodecState *sp = EncoderState(tif);
|
||||
|
||||
/* terminate strip w/ EOFB */
|
||||
Fax3PutBits(tif, EOL, 12);
|
||||
@@ -1491,7 +1449,7 @@ TIFFInitCCITTFax4(TIFF* tif, int scheme)
|
||||
/*
|
||||
* Decode the requested amount of RLE-encoded data.
|
||||
*/
|
||||
static int LINKAGEMODE
|
||||
static int
|
||||
Fax3DecodeRLE(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
|
||||
{
|
||||
DECLARE_STATE(tif, sp, "Fax3DecodeRLE");
|
||||
@@ -1525,8 +1483,6 @@ Fax3DecodeRLE(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
|
||||
}
|
||||
buf += sp->b.rowbytes;
|
||||
occ -= sp->b.rowbytes;
|
||||
if (occ != 0)
|
||||
tif->tif_row++;
|
||||
continue;
|
||||
EOFRLE: /* premature EOF */
|
||||
(*sp->fill)(buf, thisrun, pa, lastx);
|
||||
|
@@ -360,6 +360,8 @@ static const char* StateNames[] = {
|
||||
doneBlack1d: \
|
||||
if (a0 >= lastx) \
|
||||
goto done1d; \
|
||||
if( *(pa-1) == 0 && *(pa-2) == 0 ) \
|
||||
pa -= 2; \
|
||||
} \
|
||||
eof1d: \
|
||||
prematureEOF(a0); \
|
||||
@@ -485,9 +487,10 @@ done1d: \
|
||||
goto eol2d; \
|
||||
case S_EOL: \
|
||||
*pa++ = lastx - a0; \
|
||||
NeedBits8(5,eof2d); \
|
||||
if (GetBits(5)) \
|
||||
NeedBits8(4,eof2d); \
|
||||
if (GetBits(4)) \
|
||||
unexpected("EOL", a0); \
|
||||
ClrBits(4); \
|
||||
EOLcnt = 1; \
|
||||
goto eol2d; \
|
||||
default: \
|
||||
|
14475
src/tiff/tif_fax3sm.c
14475
src/tiff/tif_fax3sm.c
File diff suppressed because it is too large
Load Diff
@@ -45,6 +45,12 @@ TIFFFlush(TIFF* tif)
|
||||
|
||||
/*
|
||||
* Flush buffered data to the file.
|
||||
*
|
||||
* Frank Warmerdam'2000: I modified this to return 1 if TIFF_BEENWRITING
|
||||
* is not set, so that TIFFFlush() will proceed to write out the directory.
|
||||
* The documentation says returning 1 is an error indicator, but not having
|
||||
* been writing isn't exactly a an error. Hopefully this doesn't cause
|
||||
* problems for other people.
|
||||
*/
|
||||
int
|
||||
TIFFFlushData(TIFF* tif)
|
||||
@@ -58,3 +64,4 @@ TIFFFlushData(TIFF* tif)
|
||||
}
|
||||
return (TIFFFlushData1(tif));
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -41,6 +41,29 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
int TIFFFillStrip(TIFF*, tstrip_t);
|
||||
int TIFFFillTile(TIFF*, ttile_t);
|
||||
|
||||
/* We undefine FAR to avoid conflict with JPEG definition */
|
||||
|
||||
#ifdef FAR
|
||||
#undef FAR
|
||||
#endif
|
||||
|
||||
/*
|
||||
The windows RPCNDR.H file defines boolean, but defines it with the
|
||||
wrong size. So we declare HAVE_BOOLEAN so that the jpeg include file
|
||||
won't try to typedef boolean, but #define it to override the rpcndr.h
|
||||
definition.
|
||||
|
||||
http://bugzilla.remotesensing.org/show_bug.cgi?id=188
|
||||
*/
|
||||
#if defined(__RPCNDR_H__)
|
||||
#define HAVE_BOOLEAN
|
||||
#define boolean unsigned int
|
||||
#endif
|
||||
|
||||
#include "jpeglib.h"
|
||||
#include "jerror.h"
|
||||
|
||||
@@ -75,6 +98,8 @@ typedef struct {
|
||||
struct jpeg_decompress_struct d;
|
||||
struct jpeg_common_struct comm;
|
||||
} cinfo; /* NB: must be first */
|
||||
int cinfo_initialized;
|
||||
|
||||
jpeg_error_mgr err; /* libjpeg error manager */
|
||||
JMP_BUF exit_jmpbuf; /* for catching libjpeg failures */
|
||||
/*
|
||||
@@ -104,6 +129,8 @@ typedef struct {
|
||||
int jpegquality; /* Compression quality level */
|
||||
int jpegcolormode; /* Auto RGB<=>YCbCr convert? */
|
||||
int jpegtablesmode; /* What to put in JPEGTables */
|
||||
|
||||
int ycbcrsampling_fetched;
|
||||
} JPEGState;
|
||||
|
||||
#define JState(tif) ((JPEGState*)(tif)->tif_data)
|
||||
@@ -112,6 +139,7 @@ static int JPEGDecode(TIFF*, tidata_t, tsize_t, tsample_t);
|
||||
static int JPEGDecodeRaw(TIFF*, tidata_t, tsize_t, tsample_t);
|
||||
static int JPEGEncode(TIFF*, tidata_t, tsize_t, tsample_t);
|
||||
static int JPEGEncodeRaw(TIFF*, tidata_t, tsize_t, tsample_t);
|
||||
static int JPEGInitializeLibJPEG( TIFF * tif );
|
||||
|
||||
#define FIELD_JPEGTABLES (FIELD_CODEC+0)
|
||||
|
||||
@@ -549,10 +577,6 @@ alloc_downsampled_buffers(TIFF* tif, jpeg_component_info* comp_info,
|
||||
sp->ds_buffer[ci] = buf;
|
||||
}
|
||||
sp->samplesperclump = samples_per_clump;
|
||||
/* Cb,Cr both have sampling factors 1 */
|
||||
/* so downsampled width of Cb is # of clumps per line */
|
||||
sp->bytesperline = sizeof(JSAMPLE) * samples_per_clump *
|
||||
comp_info[1].downsampled_width;
|
||||
return (1);
|
||||
}
|
||||
|
||||
@@ -567,6 +591,8 @@ JPEGSetupDecode(TIFF* tif)
|
||||
JPEGState* sp = JState(tif);
|
||||
TIFFDirectory *td = &tif->tif_dir;
|
||||
|
||||
JPEGInitializeLibJPEG( tif );
|
||||
|
||||
assert(sp != NULL);
|
||||
assert(sp->cinfo.comm.is_decompressor);
|
||||
|
||||
@@ -628,13 +654,13 @@ JPEGPreDecode(TIFF* tif, tsample_t s)
|
||||
/*
|
||||
* Check image parameters and set decompression parameters.
|
||||
*/
|
||||
segment_width = td->td_imagewidth;
|
||||
segment_height = td->td_imagelength - tif->tif_row;
|
||||
if (isTiled(tif)) {
|
||||
segment_width = td->td_tilewidth;
|
||||
segment_height = td->td_tilelength;
|
||||
segment_width = td->td_tilewidth;
|
||||
segment_height = td->td_tilelength;
|
||||
sp->bytesperline = TIFFTileRowSize(tif);
|
||||
} else {
|
||||
segment_width = td->td_imagewidth;
|
||||
segment_height = td->td_imagelength - tif->tif_row;
|
||||
if (segment_height > td->td_rowsperstrip)
|
||||
segment_height = td->td_rowsperstrip;
|
||||
sp->bytesperline = TIFFScanlineSize(tif);
|
||||
@@ -649,8 +675,12 @@ JPEGPreDecode(TIFF* tif, tsample_t s)
|
||||
}
|
||||
if (sp->cinfo.d.image_width != segment_width ||
|
||||
sp->cinfo.d.image_height != segment_height) {
|
||||
TIFFError(module, "Improper JPEG strip/tile size");
|
||||
return (0);
|
||||
TIFFWarning(module,
|
||||
"Improper JPEG strip/tile size, expected %dx%d, got %dx%d",
|
||||
segment_width,
|
||||
segment_height,
|
||||
sp->cinfo.d.image_width,
|
||||
sp->cinfo.d.image_height);
|
||||
}
|
||||
if (sp->cinfo.d.num_components !=
|
||||
(td->td_planarconfig == PLANARCONFIG_CONTIG ?
|
||||
@@ -666,8 +696,22 @@ JPEGPreDecode(TIFF* tif, tsample_t s)
|
||||
/* Component 0 should have expected sampling factors */
|
||||
if (sp->cinfo.d.comp_info[0].h_samp_factor != sp->h_sampling ||
|
||||
sp->cinfo.d.comp_info[0].v_samp_factor != sp->v_sampling) {
|
||||
TIFFError(module, "Improper JPEG sampling factors");
|
||||
return (0);
|
||||
TIFFWarning(module,
|
||||
"Improper JPEG sampling factors %d,%d\n"
|
||||
"Apparently should be %d,%d, "
|
||||
"decompressor will try reading with "
|
||||
"sampling %d,%d",
|
||||
sp->cinfo.d.comp_info[0].h_samp_factor,
|
||||
sp->cinfo.d.comp_info[0].v_samp_factor,
|
||||
sp->h_sampling,
|
||||
sp->v_sampling,
|
||||
sp->cinfo.d.comp_info[0].h_samp_factor,
|
||||
sp->cinfo.d.comp_info[0].v_samp_factor );
|
||||
|
||||
sp->h_sampling = (uint16)
|
||||
sp->cinfo.d.comp_info[0].h_samp_factor;
|
||||
sp->v_sampling = (uint16)
|
||||
sp->cinfo.d.comp_info[0].v_samp_factor;
|
||||
}
|
||||
/* Rest should have sampling factors 1,1 */
|
||||
for (ci = 1; ci < sp->cinfo.d.num_components; ci++) {
|
||||
@@ -689,11 +733,11 @@ JPEGPreDecode(TIFF* tif, tsample_t s)
|
||||
if (td->td_planarconfig == PLANARCONFIG_CONTIG &&
|
||||
sp->photometric == PHOTOMETRIC_YCBCR &&
|
||||
sp->jpegcolormode == JPEGCOLORMODE_RGB) {
|
||||
/* Convert YCbCr to RGB */
|
||||
/* Convert YCbCr to RGB */
|
||||
sp->cinfo.d.jpeg_color_space = JCS_YCbCr;
|
||||
sp->cinfo.d.out_color_space = JCS_RGB;
|
||||
} else {
|
||||
/* Suppress colorspace handling */
|
||||
/* Suppress colorspace handling */
|
||||
sp->cinfo.d.jpeg_color_space = JCS_UNKNOWN;
|
||||
sp->cinfo.d.out_color_space = JCS_UNKNOWN;
|
||||
if (td->td_planarconfig == PLANARCONFIG_CONTIG &&
|
||||
@@ -731,112 +775,112 @@ JPEGPreDecode(TIFF* tif, tsample_t s)
|
||||
* Decode a chunk of pixels.
|
||||
* "Standard" case: returned data is not downsampled.
|
||||
*/
|
||||
static int
|
||||
/*ARGSUSED*/ static int
|
||||
JPEGDecode(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s)
|
||||
{
|
||||
JPEGState *sp = JState(tif);
|
||||
tsize_t nrows;
|
||||
JSAMPROW bufptr[1];
|
||||
JPEGState *sp = JState(tif);
|
||||
tsize_t nrows;
|
||||
|
||||
(void) s;
|
||||
assert(sp != NULL);
|
||||
/* data is expected to be read in multiples of a scanline */
|
||||
nrows = cc / sp->bytesperline;
|
||||
if (cc % sp->bytesperline)
|
||||
TIFFWarning(tif->tif_name, "fractional scanline not read");
|
||||
nrows = cc / sp->bytesperline;
|
||||
if (cc % sp->bytesperline)
|
||||
TIFFWarning(tif->tif_name, "fractional scanline not read");
|
||||
|
||||
while (nrows-- > 0) {
|
||||
bufptr[0] = (JSAMPROW) buf;
|
||||
if (TIFFjpeg_read_scanlines(sp, bufptr, 1) != 1)
|
||||
return (0);
|
||||
if (nrows > 0)
|
||||
tif->tif_row++;
|
||||
buf += sp->bytesperline;
|
||||
}
|
||||
/* Close down the decompressor if we've finished the strip or tile. */
|
||||
if (sp->cinfo.d.output_scanline == sp->cinfo.d.output_height) {
|
||||
if (TIFFjpeg_finish_decompress(sp) != TRUE)
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
if( nrows > (int) sp->cinfo.d.image_height )
|
||||
nrows = sp->cinfo.d.image_height;
|
||||
|
||||
/* data is expected to be read in multiples of a scanline */
|
||||
if (nrows)
|
||||
{
|
||||
do {
|
||||
JSAMPROW bufptr = (JSAMPROW)buf;
|
||||
|
||||
if (TIFFjpeg_read_scanlines(sp, &bufptr, 1) != 1)
|
||||
return (0);
|
||||
++tif->tif_row;
|
||||
buf += sp->bytesperline;
|
||||
cc -= sp->bytesperline;
|
||||
} while (--nrows > 0);
|
||||
}
|
||||
/* Close down the decompressor if we've finished the strip or tile. */
|
||||
return sp->cinfo.d.output_scanline < sp->cinfo.d.output_height
|
||||
|| TIFFjpeg_finish_decompress(sp);
|
||||
}
|
||||
|
||||
/*
|
||||
* Decode a chunk of pixels.
|
||||
* Returned data is downsampled per sampling factors.
|
||||
*/
|
||||
static int
|
||||
/*ARGSUSED*/ static int
|
||||
JPEGDecodeRaw(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s)
|
||||
{
|
||||
JPEGState *sp = JState(tif);
|
||||
JSAMPLE* inptr;
|
||||
JSAMPLE* outptr;
|
||||
tsize_t nrows;
|
||||
JDIMENSION clumps_per_line, nclump;
|
||||
int clumpoffset, ci, xpos, ypos;
|
||||
jpeg_component_info* compptr;
|
||||
int samples_per_clump = sp->samplesperclump;
|
||||
|
||||
(void) s;
|
||||
assert(sp != NULL);
|
||||
/* data is expected to be read in multiples of a scanline */
|
||||
nrows = cc / sp->bytesperline;
|
||||
if (cc % sp->bytesperline)
|
||||
TIFFWarning(tif->tif_name, "fractional scanline not read");
|
||||
if ( (nrows = sp->cinfo.d.image_height) ) {
|
||||
/* Cb,Cr both have sampling factors 1, so this is correct */
|
||||
JDIMENSION clumps_per_line = sp->cinfo.d.comp_info[1].downsampled_width;
|
||||
int samples_per_clump = sp->samplesperclump;
|
||||
|
||||
do {
|
||||
jpeg_component_info *compptr;
|
||||
int ci, clumpoffset;
|
||||
|
||||
/* Cb,Cr both have sampling factors 1, so this is correct */
|
||||
clumps_per_line = sp->cinfo.d.comp_info[1].downsampled_width;
|
||||
/* Reload downsampled-data buffer if needed */
|
||||
if (sp->scancount >= DCTSIZE) {
|
||||
int n = sp->cinfo.d.max_v_samp_factor * DCTSIZE;
|
||||
|
||||
while (nrows-- > 0) {
|
||||
/* Reload downsampled-data buffer if needed */
|
||||
if (sp->scancount >= DCTSIZE) {
|
||||
int n = sp->cinfo.d.max_v_samp_factor * DCTSIZE;
|
||||
if (TIFFjpeg_read_raw_data(sp, sp->ds_buffer, n) != n)
|
||||
return (0);
|
||||
sp->scancount = 0;
|
||||
/* Close down the decompressor if done. */
|
||||
if (sp->cinfo.d.output_scanline >=
|
||||
sp->cinfo.d.output_height) {
|
||||
if (TIFFjpeg_finish_decompress(sp) != TRUE)
|
||||
if (TIFFjpeg_read_raw_data(sp, sp->ds_buffer, n)
|
||||
!= n)
|
||||
return (0);
|
||||
sp->scancount = 0;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Fastest way to unseparate the data is to make one pass
|
||||
* over the scanline for each row of each component.
|
||||
*/
|
||||
clumpoffset = 0; /* first sample in clump */
|
||||
for (ci = 0, compptr = sp->cinfo.d.comp_info;
|
||||
ci < sp->cinfo.d.num_components;
|
||||
ci++, compptr++) {
|
||||
int hsamp = compptr->h_samp_factor;
|
||||
int vsamp = compptr->v_samp_factor;
|
||||
for (ypos = 0; ypos < vsamp; ypos++) {
|
||||
inptr = sp->ds_buffer[ci][sp->scancount*vsamp + ypos];
|
||||
outptr = ((JSAMPLE*) buf) + clumpoffset;
|
||||
if (hsamp == 1) {
|
||||
/* fast path for at least Cb and Cr */
|
||||
for (nclump = clumps_per_line; nclump-- > 0; ) {
|
||||
outptr[0] = *inptr++;
|
||||
outptr += samples_per_clump;
|
||||
}
|
||||
} else {
|
||||
/* general case */
|
||||
for (nclump = clumps_per_line; nclump-- > 0; ) {
|
||||
for (xpos = 0; xpos < hsamp; xpos++)
|
||||
outptr[xpos] = *inptr++;
|
||||
outptr += samples_per_clump;
|
||||
/*
|
||||
* Fastest way to unseparate data is to make one pass
|
||||
* over the scanline for each row of each component.
|
||||
*/
|
||||
clumpoffset = 0; /* first sample in clump */
|
||||
for (ci = 0, compptr = sp->cinfo.d.comp_info;
|
||||
ci < sp->cinfo.d.num_components;
|
||||
ci++, compptr++) {
|
||||
int hsamp = compptr->h_samp_factor;
|
||||
int vsamp = compptr->v_samp_factor;
|
||||
int ypos;
|
||||
|
||||
for (ypos = 0; ypos < vsamp; ypos++) {
|
||||
JSAMPLE *inptr = sp->ds_buffer[ci][sp->scancount*vsamp + ypos];
|
||||
JSAMPLE *outptr = (JSAMPLE*)buf + clumpoffset;
|
||||
JDIMENSION nclump;
|
||||
|
||||
if (hsamp == 1) {
|
||||
/* fast path for at least Cb and Cr */
|
||||
for (nclump = clumps_per_line; nclump-- > 0; ) {
|
||||
outptr[0] = *inptr++;
|
||||
outptr += samples_per_clump;
|
||||
}
|
||||
} else {
|
||||
int xpos;
|
||||
|
||||
/* general case */
|
||||
for (nclump = clumps_per_line; nclump-- > 0; ) {
|
||||
for (xpos = 0; xpos < hsamp; xpos++)
|
||||
outptr[xpos] = *inptr++;
|
||||
outptr += samples_per_clump;
|
||||
}
|
||||
}
|
||||
clumpoffset += hsamp;
|
||||
}
|
||||
}
|
||||
clumpoffset += hsamp;
|
||||
}
|
||||
}
|
||||
sp->scancount++;
|
||||
if (nrows > 0)
|
||||
tif->tif_row++;
|
||||
buf += sp->bytesperline;
|
||||
++sp->scancount;
|
||||
++tif->tif_row;
|
||||
buf += sp->bytesperline;
|
||||
cc -= sp->bytesperline;
|
||||
} while (--nrows > 0);
|
||||
}
|
||||
return (1);
|
||||
|
||||
/* Close down the decompressor if done. */
|
||||
return sp->cinfo.d.output_scanline < sp->cinfo.d.output_height
|
||||
|| TIFFjpeg_finish_decompress(sp);
|
||||
}
|
||||
|
||||
|
||||
@@ -869,6 +913,8 @@ prepare_JPEGTables(TIFF* tif)
|
||||
{
|
||||
JPEGState* sp = JState(tif);
|
||||
|
||||
JPEGInitializeLibJPEG( tif );
|
||||
|
||||
/* Initialize quant tables for current quality setting */
|
||||
if (!TIFFjpeg_set_quality(sp, sp->jpegquality, FALSE))
|
||||
return (0);
|
||||
@@ -903,6 +949,8 @@ JPEGSetupEncode(TIFF* tif)
|
||||
TIFFDirectory *td = &tif->tif_dir;
|
||||
static const char module[] = "JPEGSetupEncode";
|
||||
|
||||
JPEGInitializeLibJPEG( tif );
|
||||
|
||||
assert(sp != NULL);
|
||||
assert(!sp->cinfo.comm.is_decompressor);
|
||||
|
||||
@@ -926,7 +974,6 @@ JPEGSetupEncode(TIFF* tif)
|
||||
* default value is inappropriate for YCbCr. Fill in the
|
||||
* proper value if application didn't set it.
|
||||
*/
|
||||
#ifdef COLORIMETRY_SUPPORT
|
||||
if (!TIFFFieldSet(tif, FIELD_REFBLACKWHITE)) {
|
||||
float refbw[6];
|
||||
long top = 1L << td->td_bitspersample;
|
||||
@@ -938,7 +985,6 @@ JPEGSetupEncode(TIFF* tif)
|
||||
refbw[5] = refbw[1];
|
||||
TIFFSetField(tif, TIFFTAG_REFERENCEBLACKWHITE, refbw);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case PHOTOMETRIC_PALETTE: /* disallowed by Tech Note */
|
||||
case PHOTOMETRIC_MASK:
|
||||
@@ -1279,7 +1325,8 @@ JPEGCleanup(TIFF* tif)
|
||||
{
|
||||
if (tif->tif_data) {
|
||||
JPEGState *sp = JState(tif);
|
||||
TIFFjpeg_destroy(sp); /* release libjpeg resources */
|
||||
if( sp->cinfo_initialized )
|
||||
TIFFjpeg_destroy(sp); /* release libjpeg resources */
|
||||
if (sp->jpegtables) /* tag value */
|
||||
_TIFFfree(sp->jpegtables);
|
||||
_TIFFfree(tif->tif_data); /* release local state */
|
||||
@@ -1336,6 +1383,10 @@ JPEGVSetField(TIFF* tif, ttag_t tag, va_list ap)
|
||||
case TIFFTAG_JPEGTABLESMODE:
|
||||
sp->jpegtablesmode = va_arg(ap, int);
|
||||
return (1); /* pseudo tag */
|
||||
case TIFFTAG_YCBCRSUBSAMPLING:
|
||||
/* mark the fact that we have a real ycbcrsubsampling! */
|
||||
sp->ycbcrsampling_fetched = 1;
|
||||
return (*sp->vsetparent)(tif, tag, ap);
|
||||
default:
|
||||
return (*sp->vsetparent)(tif, tag, ap);
|
||||
}
|
||||
@@ -1343,6 +1394,73 @@ JPEGVSetField(TIFF* tif, ttag_t tag, va_list ap)
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Some JPEG-in-TIFF produces do not emit the YCBCRSUBSAMPLING values in
|
||||
* the TIFF tags, but still use non-default (2,2) values within the jpeg
|
||||
* data stream itself. In order for TIFF applications to work properly
|
||||
* - for instance to get the strip buffer size right - it is imperative
|
||||
* that the subsampling be available before we start reading the image
|
||||
* data normally. This function will attempt to load the first strip in
|
||||
* order to get the sampling values from the jpeg data stream. Various
|
||||
* hacks are various places are done to ensure this function gets called
|
||||
* before the td_ycbcrsubsampling values are used from the directory structure,
|
||||
* including calling TIFFGetField() for the YCBCRSUBSAMPLING field from
|
||||
* TIFFStripSize(), and the printing code in tif_print.c.
|
||||
*
|
||||
* Note that JPEGPreDeocode() will produce a fairly loud warning when the
|
||||
* discovered sampling does not match the default sampling (2,2) or whatever
|
||||
* was actually in the tiff tags.
|
||||
*
|
||||
* Problems:
|
||||
* o This code will cause one whole strip/tile of compressed data to be
|
||||
* loaded just to get the tags right, even if the imagery is never read.
|
||||
* It would be more efficient to just load a bit of the header, and
|
||||
* initialize things from that.
|
||||
*
|
||||
* See the bug in bugzilla for details:
|
||||
*
|
||||
* http://bugzilla.remotesensing.org/show_bug.cgi?id=168
|
||||
*
|
||||
* Frank Warmerdam, July 2002
|
||||
*/
|
||||
|
||||
static void
|
||||
JPEGFixupTestSubsampling( TIFF * tif )
|
||||
{
|
||||
#if CHECK_JPEG_YCBCR_SUBSAMPLING == 1
|
||||
JPEGState *sp = JState(tif);
|
||||
TIFFDirectory *td = &tif->tif_dir;
|
||||
|
||||
JPEGInitializeLibJPEG( tif );
|
||||
|
||||
/*
|
||||
* Some JPEG-in-TIFF files don't provide the ycbcrsampling tags,
|
||||
* and use a sampling schema other than the default 2,2. To handle
|
||||
* this we actually have to scan the header of a strip or tile of
|
||||
* jpeg data to get the sampling.
|
||||
*/
|
||||
if( !sp->cinfo.comm.is_decompressor
|
||||
|| sp->ycbcrsampling_fetched
|
||||
|| td->td_photometric != PHOTOMETRIC_YCBCR )
|
||||
return;
|
||||
|
||||
sp->ycbcrsampling_fetched = 1;
|
||||
if( TIFFIsTiled( tif ) )
|
||||
{
|
||||
if( !TIFFFillTile( tif, 0 ) )
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !TIFFFillStrip( tif, 0 ) )
|
||||
return;
|
||||
}
|
||||
|
||||
TIFFSetField( tif, TIFFTAG_YCBCRSUBSAMPLING,
|
||||
(uint16) sp->h_sampling, (uint16) sp->v_sampling );
|
||||
#endif /* CHECK_JPEG_YCBCR_SUBSAMPLING == 1 */
|
||||
}
|
||||
|
||||
static int
|
||||
JPEGVGetField(TIFF* tif, ttag_t tag, va_list ap)
|
||||
{
|
||||
@@ -1364,6 +1482,10 @@ JPEGVGetField(TIFF* tif, ttag_t tag, va_list ap)
|
||||
case TIFFTAG_JPEGTABLESMODE:
|
||||
*va_arg(ap, int*) = sp->jpegtablesmode;
|
||||
break;
|
||||
case TIFFTAG_YCBCRSUBSAMPLING:
|
||||
JPEGFixupTestSubsampling( tif );
|
||||
return (*sp->vgetparent)(tif, tag, ap);
|
||||
break;
|
||||
default:
|
||||
return (*sp->vgetparent)(tif, tag, ap);
|
||||
}
|
||||
@@ -1404,6 +1526,72 @@ JPEGDefaultTileSize(TIFF* tif, uint32* tw, uint32* th)
|
||||
*th = TIFFroundup(*th, td->td_ycbcrsubsampling[1] * DCTSIZE);
|
||||
}
|
||||
|
||||
/*
|
||||
* The JPEG library initialized used to be done in TIFFInitJPEG(), but
|
||||
* now that we allow a TIFF file to be opened in update mode it is necessary
|
||||
* to have some way of deciding whether compression or decompression is
|
||||
* desired other than looking at tif->tif_mode. We accomplish this by
|
||||
* examining {TILE/STRIP}BYTECOUNTS to see if there is a non-zero entry.
|
||||
* If so, we assume decompression is desired.
|
||||
*
|
||||
* This is tricky, because TIFFInitJPEG() is called while the directory is
|
||||
* being read, and generally speaking the BYTECOUNTS tag won't have been read
|
||||
* at that point. So we try to defer jpeg library initialization till we
|
||||
* do have that tag ... basically any access that might require the compressor
|
||||
* or decompressor that occurs after the reading of the directory.
|
||||
*
|
||||
* In an ideal world compressors or decompressors would be setup
|
||||
* at the point where a single tile or strip was accessed (for read or write)
|
||||
* so that stuff like update of missing tiles, or replacement of tiles could
|
||||
* be done. However, we aren't trying to crack that nut just yet ...
|
||||
*
|
||||
* NFW, Feb 3rd, 2003.
|
||||
*/
|
||||
|
||||
static int JPEGInitializeLibJPEG( TIFF * tif )
|
||||
{
|
||||
JPEGState* sp = JState(tif);
|
||||
uint32 *byte_counts = NULL;
|
||||
int data_is_empty = TRUE;
|
||||
|
||||
if( sp->cinfo_initialized )
|
||||
return 1;
|
||||
|
||||
/*
|
||||
* Do we have tile data already? Make sure we initialize the
|
||||
* the state in decompressor mode if we have tile data, even if we
|
||||
* are not in read-only file access mode.
|
||||
*/
|
||||
if( TIFFIsTiled( tif )
|
||||
&& TIFFGetField( tif, TIFFTAG_TILEBYTECOUNTS, &byte_counts )
|
||||
&& byte_counts != NULL )
|
||||
{
|
||||
data_is_empty = byte_counts[0] == 0;
|
||||
}
|
||||
if( !TIFFIsTiled( tif )
|
||||
&& TIFFGetField( tif, TIFFTAG_STRIPBYTECOUNTS, &byte_counts)
|
||||
&& byte_counts != NULL )
|
||||
{
|
||||
data_is_empty = byte_counts[0] == 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize libjpeg.
|
||||
*/
|
||||
if (tif->tif_mode == O_RDONLY || !data_is_empty ) {
|
||||
if (!TIFFjpeg_create_decompress(sp))
|
||||
return (0);
|
||||
|
||||
} else {
|
||||
if (!TIFFjpeg_create_compress(sp))
|
||||
return (0);
|
||||
}
|
||||
|
||||
sp->cinfo_initialized = TRUE;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
TIFFInitJPEG(TIFF* tif, int scheme)
|
||||
{
|
||||
@@ -1415,10 +1603,13 @@ TIFFInitJPEG(TIFF* tif, int scheme)
|
||||
* Allocate state block so tag methods have storage to record values.
|
||||
*/
|
||||
tif->tif_data = (tidata_t) _TIFFmalloc(sizeof (JPEGState));
|
||||
|
||||
if (tif->tif_data == NULL) {
|
||||
TIFFError("TIFFInitJPEG", "No space for JPEG state block");
|
||||
return (0);
|
||||
}
|
||||
memset( tif->tif_data, 0, sizeof(JPEGState));
|
||||
|
||||
sp = JState(tif);
|
||||
sp->tif = tif; /* back link */
|
||||
|
||||
@@ -1427,11 +1618,11 @@ TIFFInitJPEG(TIFF* tif, int scheme)
|
||||
* override parent get/set field methods.
|
||||
*/
|
||||
_TIFFMergeFieldInfo(tif, jpegFieldInfo, N(jpegFieldInfo));
|
||||
sp->vgetparent = tif->tif_vgetfield;
|
||||
tif->tif_vgetfield = JPEGVGetField; /* hook for codec tags */
|
||||
sp->vsetparent = tif->tif_vsetfield;
|
||||
tif->tif_vsetfield = JPEGVSetField; /* hook for codec tags */
|
||||
tif->tif_printdir = JPEGPrintDir; /* hook for codec tags */
|
||||
sp->vgetparent = tif->tif_tagmethods.vgetfield;
|
||||
tif->tif_tagmethods.vgetfield = JPEGVGetField; /* hook for codec tags */
|
||||
sp->vsetparent = tif->tif_tagmethods.vsetfield;
|
||||
tif->tif_tagmethods.vsetfield = JPEGVSetField; /* hook for codec tags */
|
||||
tif->tif_tagmethods.printdir = JPEGPrintDir; /* hook for codec tags */
|
||||
|
||||
/* Default values for codec-specific fields */
|
||||
sp->jpegtables = NULL;
|
||||
@@ -1440,6 +1631,8 @@ TIFFInitJPEG(TIFF* tif, int scheme)
|
||||
sp->jpegcolormode = JPEGCOLORMODE_RAW;
|
||||
sp->jpegtablesmode = JPEGTABLESMODE_QUANT | JPEGTABLESMODE_HUFF;
|
||||
|
||||
sp->ycbcrsampling_fetched = 0;
|
||||
|
||||
/*
|
||||
* Install codec methods.
|
||||
*/
|
||||
@@ -1461,16 +1654,13 @@ TIFFInitJPEG(TIFF* tif, int scheme)
|
||||
tif->tif_deftilesize = JPEGDefaultTileSize;
|
||||
tif->tif_flags |= TIFF_NOBITREV; /* no bit reversal, please */
|
||||
|
||||
/*
|
||||
* Initialize libjpeg.
|
||||
*/
|
||||
if (tif->tif_mode == O_RDONLY) {
|
||||
if (!TIFFjpeg_create_decompress(sp))
|
||||
return (0);
|
||||
} else {
|
||||
if (!TIFFjpeg_create_compress(sp))
|
||||
return (0);
|
||||
}
|
||||
sp->cinfo_initialized = FALSE;
|
||||
|
||||
/*
|
||||
* Mark the TIFFTAG_YCBCRSAMPLES as present even if it is not
|
||||
* see: JPEGFixupTestSubsampling().
|
||||
*/
|
||||
TIFFSetFieldBit( tif, FIELD_YCBCRSUBSAMPLING );
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
@@ -2,23 +2,23 @@
|
||||
* Copyright (c) 1997 Greg Ward Larson
|
||||
* Copyright (c) 1997 Silicon Graphics, Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* its documentation for any purpose is hereby granted without fee, provided
|
||||
* that (i) the above copyright notices and this permission notice appear in
|
||||
* all copies of the software and related documentation, and (ii) the names of
|
||||
* Sam Leffler, Greg Larson and Silicon Graphics may not be used in any
|
||||
* advertising or publicity relating to the software without the specific,
|
||||
* prior written permission of Sam Leffler, Greg Larson and Silicon Graphics.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* IN NO EVENT SHALL SAM LEFFLER, GREG LARSON OR SILICON GRAPHICS BE LIABLE
|
||||
* FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
|
||||
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
||||
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
||||
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
* LogLuv image support uses the TIFF library to store 16 or 10-bit
|
||||
* log luminance values with 8 bits each of u and v or a 14-bit index.
|
||||
*
|
||||
* The codec can take as input and produce as output 32-bit IEEE float values
|
||||
* The codec can take as input and produce as output 32-bit IEEE float values
|
||||
* as well as 16-bit integer values. A 16-bit luminance is interpreted
|
||||
* as a sign bit followed by a 15-bit integer that is converted
|
||||
* to and from a linear magnitude using the transformation:
|
||||
@@ -67,8 +67,20 @@
|
||||
* of conversion to and from LogLuv, though the application is still
|
||||
* responsible for interpreting the TIFFTAG_STONITS calibration factor.
|
||||
*
|
||||
* The information is compressed into one of two basic encodings, depending on
|
||||
* the setting of the compression tag, which is one of COMPRESSION_SGILOG
|
||||
* By definition, a CIE XYZ vector of [1 1 1] corresponds to a neutral white
|
||||
* point of (x,y)=(1/3,1/3). However, most color systems assume some other
|
||||
* white point, such as D65, and an absolute color conversion to XYZ then
|
||||
* to another color space with a different white point may introduce an
|
||||
* unwanted color cast to the image. It is often desirable, therefore, to
|
||||
* perform a white point conversion that maps the input white to [1 1 1]
|
||||
* in XYZ, then record the original white point using the TIFFTAG_WHITEPOINT
|
||||
* tag value. A decoder that demands absolute color calibration may use
|
||||
* this white point tag to get back the original colors, but usually it
|
||||
* will be ignored and the new white point will be used instead that
|
||||
* matches the output color space.
|
||||
*
|
||||
* Pixel information is compressed into one of two basic encodings, depending
|
||||
* on the setting of the compression tag, which is one of COMPRESSION_SGILOG
|
||||
* or COMPRESSION_SGILOG24. For COMPRESSION_SGILOG, greyscale data is
|
||||
* stored as:
|
||||
*
|
||||
@@ -120,6 +132,17 @@
|
||||
* scheme by separating the logL, u and v bytes for each row and applying
|
||||
* a PackBits type of compression. Since the 24-bit encoding is not
|
||||
* adaptive, the 32-bit color format takes less space in many cases.
|
||||
*
|
||||
* Further control is provided over the conversion from higher-resolution
|
||||
* formats to final encoded values through the pseudo tag
|
||||
* TIFFTAG_SGILOGENCODE:
|
||||
* SGILOGENCODE_NODITHER = do not dither encoded values
|
||||
* SGILOGENCODE_RANDITHER = apply random dithering during encoding
|
||||
*
|
||||
* The default value of this tag is SGILOGENCODE_NODITHER for
|
||||
* COMPRESSION_SGILOG to maximize run-length encoding and
|
||||
* SGILOGENCODE_RANDITHER for COMPRESSION_SGILOG24 to turn
|
||||
* quantization errors into noise.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -135,10 +158,11 @@ typedef struct logLuvState LogLuvState;
|
||||
|
||||
struct logLuvState {
|
||||
int user_datafmt; /* user data format */
|
||||
int encode_meth; /* encoding method */
|
||||
int pixel_size; /* bytes per pixel */
|
||||
|
||||
tidata_t* tbuf; /* translation buffer */
|
||||
short tbuflen; /* buffer length */
|
||||
int tbuflen; /* buffer length */
|
||||
void (*tfunc)(LogLuvState*, tidata_t, int);
|
||||
|
||||
TIFFVSetMethod vgetparent; /* super-class method */
|
||||
@@ -156,7 +180,7 @@ struct logLuvState {
|
||||
/*
|
||||
* Decode a string of 16-bit gray pixels.
|
||||
*/
|
||||
static int LINKAGEMODE
|
||||
static int
|
||||
LogL16Decode(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
|
||||
{
|
||||
LogLuvState* sp = DecoderState(tif);
|
||||
@@ -186,13 +210,13 @@ LogL16Decode(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
|
||||
for (i = 0; i < npixels && cc > 0; )
|
||||
if (*bp >= 128) { /* run */
|
||||
rc = *bp++ + (2-128);
|
||||
b = (int16)*bp++ << shft;
|
||||
b = (int16)(*bp++ << shft);
|
||||
cc -= 2;
|
||||
while (rc--)
|
||||
while (rc-- && i < npixels)
|
||||
tp[i++] |= b;
|
||||
} else { /* non-run */
|
||||
rc = *bp++; /* nul is noop */
|
||||
while (--cc && rc--)
|
||||
while (--cc && rc-- && i < npixels)
|
||||
tp[i++] |= (int16)*bp++ << shft;
|
||||
}
|
||||
if (i != npixels) {
|
||||
@@ -213,7 +237,7 @@ LogL16Decode(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
|
||||
/*
|
||||
* Decode a string of 24-bit pixels.
|
||||
*/
|
||||
static int LINKAGEMODE
|
||||
static int
|
||||
LogLuvDecode24(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
|
||||
{
|
||||
LogLuvState* sp = DecoderState(tif);
|
||||
@@ -232,7 +256,6 @@ LogLuvDecode24(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
|
||||
assert(sp->tbuflen >= npixels);
|
||||
tp = (uint32 *) sp->tbuf;
|
||||
}
|
||||
_TIFFmemset((tdata_t) tp, 0, npixels*sizeof (tp[0]));
|
||||
/* copy to array of uint32 */
|
||||
bp = (u_char*) tif->tif_rawcp;
|
||||
cc = tif->tif_rawcc;
|
||||
@@ -256,7 +279,7 @@ LogLuvDecode24(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
|
||||
/*
|
||||
* Decode a string of 32-bit pixels.
|
||||
*/
|
||||
static int LINKAGEMODE
|
||||
static int
|
||||
LogLuvDecode32(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
|
||||
{
|
||||
LogLuvState* sp;
|
||||
@@ -289,11 +312,11 @@ LogLuvDecode32(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
|
||||
rc = *bp++ + (2-128);
|
||||
b = (uint32)*bp++ << shft;
|
||||
cc -= 2;
|
||||
while (rc--)
|
||||
while (rc-- && i < npixels)
|
||||
tp[i++] |= b;
|
||||
} else { /* non-run */
|
||||
rc = *bp++; /* nul is noop */
|
||||
while (--cc && rc--)
|
||||
while (--cc && rc-- && i < npixels)
|
||||
tp[i++] |= (uint32)*bp++ << shft;
|
||||
}
|
||||
if (i != npixels) {
|
||||
@@ -316,7 +339,7 @@ LogLuvDecode32(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
|
||||
* maintain synchrony with the encode algorithm, which
|
||||
* is row by row.
|
||||
*/
|
||||
static int LINKAGEMODE
|
||||
static int
|
||||
LogLuvDecodeStrip(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
|
||||
{
|
||||
tsize_t rowlen = TIFFScanlineSize(tif);
|
||||
@@ -332,7 +355,7 @@ LogLuvDecodeStrip(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
|
||||
* maintain synchrony with the encode algorithm, which
|
||||
* is row by row.
|
||||
*/
|
||||
static int LINKAGEMODE
|
||||
static int
|
||||
LogLuvDecodeTile(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
|
||||
{
|
||||
tsize_t rowlen = TIFFTileRowSize(tif);
|
||||
@@ -346,7 +369,7 @@ LogLuvDecodeTile(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
|
||||
/*
|
||||
* Encode a row of 16-bit pixels.
|
||||
*/
|
||||
static int LINKAGEMODE
|
||||
static int
|
||||
LogL16Encode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
|
||||
{
|
||||
LogLuvState* sp = EncoderState(tif);
|
||||
@@ -382,7 +405,7 @@ LogL16Encode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
|
||||
}
|
||||
mask = 0xff << shft; /* find next run */
|
||||
for (beg = i; beg < npixels; beg += rc) {
|
||||
b = tp[beg] & mask;
|
||||
b = (int16) (tp[beg] & mask);
|
||||
rc = 1;
|
||||
while (rc < 127+2 && beg+rc < npixels &&
|
||||
(tp[beg+rc] & mask) == b)
|
||||
@@ -391,36 +414,36 @@ LogL16Encode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
|
||||
break; /* long enough */
|
||||
}
|
||||
if (beg-i > 1 && beg-i < MINRUN) {
|
||||
b = tp[i] & mask; /* check short run */
|
||||
b = (int16) (tp[i] & mask);/*check short run */
|
||||
j = i+1;
|
||||
while ((tp[j++] & mask) == b)
|
||||
if (j == beg) {
|
||||
*op++ = 128-2+j-i;
|
||||
*op++ = b >> shft;
|
||||
occ -= 2;
|
||||
i = beg;
|
||||
break;
|
||||
}
|
||||
if (j == beg) {
|
||||
*op++ = (tidataval_t)(128-2+j-i);
|
||||
*op++ = (tidataval_t) (b >> shft);
|
||||
occ -= 2;
|
||||
i = beg;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (i < beg) { /* write out non-run */
|
||||
if ((j = beg-i) > 127) j = 127;
|
||||
if (occ < j+3) {
|
||||
tif->tif_rawcp = op;
|
||||
tif->tif_rawcc = tif->tif_rawdatasize - occ;
|
||||
if (!TIFFFlushData1(tif))
|
||||
return (-1);
|
||||
op = tif->tif_rawcp;
|
||||
occ = tif->tif_rawdatasize - tif->tif_rawcc;
|
||||
tif->tif_rawcp = op;
|
||||
tif->tif_rawcc = tif->tif_rawdatasize - occ;
|
||||
if (!TIFFFlushData1(tif))
|
||||
return (-1);
|
||||
op = tif->tif_rawcp;
|
||||
occ = tif->tif_rawdatasize - tif->tif_rawcc;
|
||||
}
|
||||
*op++ = j; occ--;
|
||||
*op++ = (tidataval_t) j; occ--;
|
||||
while (j--) {
|
||||
*op++ = tp[i++] >> shft & 0xff;
|
||||
*op++ = (tidataval_t) (tp[i++] >> shft & 0xff);
|
||||
occ--;
|
||||
}
|
||||
}
|
||||
if (rc >= MINRUN) { /* write out run */
|
||||
*op++ = 128-2+rc;
|
||||
*op++ = tp[beg] >> shft & 0xff;
|
||||
*op++ = (tidataval_t) (128-2+rc);
|
||||
*op++ = (tidataval_t) (tp[beg] >> shft & 0xff);
|
||||
occ -= 2;
|
||||
} else
|
||||
rc = 0;
|
||||
@@ -434,7 +457,7 @@ LogL16Encode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
|
||||
/*
|
||||
* Encode a row of 24-bit pixels.
|
||||
*/
|
||||
static int LINKAGEMODE
|
||||
static int
|
||||
LogLuvEncode24(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
|
||||
{
|
||||
LogLuvState* sp = EncoderState(tif);
|
||||
@@ -465,9 +488,9 @@ LogLuvEncode24(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
|
||||
op = tif->tif_rawcp;
|
||||
occ = tif->tif_rawdatasize - tif->tif_rawcc;
|
||||
}
|
||||
*op++ = *tp >> 16;
|
||||
*op++ = *tp >> 8 & 0xff;
|
||||
*op++ = *tp++ & 0xff;
|
||||
*op++ = (tidataval_t)(*tp >> 16);
|
||||
*op++ = (tidataval_t)(*tp >> 8 & 0xff);
|
||||
*op++ = (tidataval_t)(*tp++ & 0xff);
|
||||
occ -= 3;
|
||||
}
|
||||
tif->tif_rawcp = op;
|
||||
@@ -479,7 +502,7 @@ LogLuvEncode24(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
|
||||
/*
|
||||
* Encode a row of 32-bit pixels.
|
||||
*/
|
||||
static int LINKAGEMODE
|
||||
static int
|
||||
LogLuvEncode32(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
|
||||
{
|
||||
LogLuvState* sp = EncoderState(tif);
|
||||
@@ -529,8 +552,8 @@ LogLuvEncode32(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
|
||||
j = i+1;
|
||||
while ((tp[j++] & mask) == b)
|
||||
if (j == beg) {
|
||||
*op++ = 128-2+j-i;
|
||||
*op++ = b >> shft;
|
||||
*op++ = (tidataval_t)(128-2+j-i);
|
||||
*op++ = (tidataval_t)(b >> shft);
|
||||
occ -= 2;
|
||||
i = beg;
|
||||
break;
|
||||
@@ -546,15 +569,15 @@ LogLuvEncode32(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
|
||||
op = tif->tif_rawcp;
|
||||
occ = tif->tif_rawdatasize - tif->tif_rawcc;
|
||||
}
|
||||
*op++ = j; occ--;
|
||||
*op++ = (tidataval_t) j; occ--;
|
||||
while (j--) {
|
||||
*op++ = tp[i++] >> shft & 0xff;
|
||||
*op++ = (tidataval_t)(tp[i++] >> shft & 0xff);
|
||||
occ--;
|
||||
}
|
||||
}
|
||||
if (rc >= MINRUN) { /* write out run */
|
||||
*op++ = 128-2+rc;
|
||||
*op++ = tp[beg] >> shft & 0xff;
|
||||
*op++ = (tidataval_t) (128-2+rc);
|
||||
*op++ = (tidataval_t)(tp[beg] >> shft & 0xff);
|
||||
occ -= 2;
|
||||
} else
|
||||
rc = 0;
|
||||
@@ -569,7 +592,7 @@ LogLuvEncode32(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
|
||||
* Encode a strip of pixels. We break it into rows to
|
||||
* avoid encoding runs across row boundaries.
|
||||
*/
|
||||
static int LINKAGEMODE
|
||||
static int
|
||||
LogLuvEncodeStrip(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
|
||||
{
|
||||
tsize_t rowlen = TIFFScanlineSize(tif);
|
||||
@@ -584,7 +607,7 @@ LogLuvEncodeStrip(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
|
||||
* Encode a tile of pixels. We break it into rows to
|
||||
* avoid encoding runs across row boundaries.
|
||||
*/
|
||||
static int LINKAGEMODE
|
||||
static int
|
||||
LogLuvEncodeTile(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
|
||||
{
|
||||
tsize_t rowlen = TIFFTileRowSize(tif);
|
||||
@@ -598,49 +621,57 @@ LogLuvEncodeTile(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
|
||||
/*
|
||||
* Encode/Decode functions for converting to and from user formats.
|
||||
*/
|
||||
|
||||
#include "uvcode.h"
|
||||
|
||||
#define U_NEU 0.210526316
|
||||
#define V_NEU 0.473684211
|
||||
|
||||
#ifdef M_LN2
|
||||
#define LOGOF2 M_LN2
|
||||
#else
|
||||
#define LOGOF2 0.69314718055994530942
|
||||
#endif
|
||||
#ifndef log2
|
||||
#define log2(x) ((1./LOGOF2)*log(x))
|
||||
#endif
|
||||
#ifndef exp2
|
||||
#define exp2(x) exp(LOGOF2*(x))
|
||||
#endif
|
||||
#ifndef UVSCALE
|
||||
#define U_NEU 0.210526316
|
||||
#define V_NEU 0.473684211
|
||||
#define UVSCALE 410.
|
||||
#endif
|
||||
|
||||
static double
|
||||
pix16toY(int p16)
|
||||
#ifndef M_LN2
|
||||
#define M_LN2 0.69314718055994530942
|
||||
#endif
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
#define log2(x) ((1./M_LN2)*log(x))
|
||||
#define exp2(x) exp(M_LN2*(x))
|
||||
|
||||
#define itrunc(x,m) ((m)==SGILOGENCODE_NODITHER ? \
|
||||
(int)(x) : \
|
||||
(int)((x) + rand()*(1./RAND_MAX) - .5))
|
||||
|
||||
#if !LOGLUV_PUBLIC
|
||||
static
|
||||
#endif
|
||||
double
|
||||
LogL16toY(int p16) /* compute luminance from 16-bit LogL */
|
||||
{
|
||||
int Le = p16 & 0x7fff;
|
||||
double Y;
|
||||
|
||||
if (!Le)
|
||||
return (0.);
|
||||
Y = exp(LOGOF2/256.*(Le+.5) - LOGOF2*64.);
|
||||
if (p16 & 0x8000)
|
||||
return (-Y);
|
||||
return (Y);
|
||||
Y = exp(M_LN2/256.*(Le+.5) - M_LN2*64.);
|
||||
return (!(p16 & 0x8000) ? Y : -Y);
|
||||
}
|
||||
|
||||
static int
|
||||
pix16fromY(double Y)
|
||||
#if !LOGLUV_PUBLIC
|
||||
static
|
||||
#endif
|
||||
int
|
||||
LogL16fromY(double Y, int em) /* get 16-bit LogL from Y */
|
||||
{
|
||||
if (Y >= 1.84467e19)
|
||||
if (Y >= 1.8371976e19)
|
||||
return (0x7fff);
|
||||
if (Y <= -1.84467e19)
|
||||
if (Y <= -1.8371976e19)
|
||||
return (0xffff);
|
||||
if (Y > 5.43571e-20)
|
||||
return (int)(256.*(log2(Y) + 64.));
|
||||
if (Y < -5.43571e-20)
|
||||
return (~0x7fff | (int)(256.*(log2(-Y) + 64.)));
|
||||
if (Y > 5.4136769e-20)
|
||||
return itrunc(256.*(log2(Y) + 64.), em);
|
||||
if (Y < -5.4136769e-20)
|
||||
return (~0x7fff | itrunc(256.*(log2(-Y) + 64.), em));
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -651,7 +682,7 @@ L16toY(LogLuvState* sp, tidata_t op, int n)
|
||||
float* yp = (float*) op;
|
||||
|
||||
while (n-- > 0)
|
||||
*yp++ = pix16toY(*l16++);
|
||||
*yp++ = (float)LogL16toY(*l16++);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -661,8 +692,8 @@ L16toGry(LogLuvState* sp, tidata_t op, int n)
|
||||
uint8* gp = (uint8*) op;
|
||||
|
||||
while (n-- > 0) {
|
||||
double Y = pix16toY(*l16++);
|
||||
*gp++ = (Y <= 0.) ? 0 : (Y >= 1.) ? 255 : (int)(256.*sqrt(Y));
|
||||
double Y = LogL16toY(*l16++);
|
||||
*gp++ = (uint8) ((Y <= 0.) ? 0 : (Y >= 1.) ? 255 : (int)(256.*sqrt(Y)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -673,10 +704,13 @@ L16fromY(LogLuvState* sp, tidata_t op, int n)
|
||||
float* yp = (float*) op;
|
||||
|
||||
while (n-- > 0)
|
||||
*l16++ = pix16fromY(*yp++);
|
||||
*l16++ = (int16) (LogL16fromY(*yp++, sp->encode_meth));
|
||||
}
|
||||
|
||||
static void
|
||||
#if !LOGLUV_PUBLIC
|
||||
static
|
||||
#endif
|
||||
void
|
||||
XYZtoRGB24(float xyz[3], uint8 rgb[3])
|
||||
{
|
||||
double r, g, b;
|
||||
@@ -686,68 +720,161 @@ XYZtoRGB24(float xyz[3], uint8 rgb[3])
|
||||
b = 0.061*xyz[0] + -0.224*xyz[1] + 1.163*xyz[2];
|
||||
/* assume 2.0 gamma for speed */
|
||||
/* could use integer sqrt approx., but this is probably faster */
|
||||
rgb[0] = (r <= 0.) ? 0 : (r >= 1.) ? 255 : (int)(256.*sqrt(r));
|
||||
rgb[1] = (g <= 0.) ? 0 : (g >= 1.) ? 255 : (int)(256.*sqrt(g));
|
||||
rgb[2] = (b <= 0.) ? 0 : (b >= 1.) ? 255 : (int)(256.*sqrt(b));
|
||||
rgb[0] = (uint8)((r<=0.) ? 0 : (r >= 1.) ? 255 : (int)(256.*sqrt(r)));
|
||||
rgb[1] = (uint8)((g<=0.) ? 0 : (g >= 1.) ? 255 : (int)(256.*sqrt(g)));
|
||||
rgb[2] = (uint8)((b<=0.) ? 0 : (b >= 1.) ? 255 : (int)(256.*sqrt(b)));
|
||||
}
|
||||
|
||||
#if !LOGLUV_PUBLIC
|
||||
static
|
||||
#endif
|
||||
double
|
||||
LogL10toY(int p10) /* compute luminance from 10-bit LogL */
|
||||
{
|
||||
if (p10 == 0)
|
||||
return (0.);
|
||||
return (exp(M_LN2/64.*(p10+.5) - M_LN2*12.));
|
||||
}
|
||||
|
||||
#if !LOGLUV_PUBLIC
|
||||
static
|
||||
#endif
|
||||
int
|
||||
LogL10fromY(double Y, int em) /* get 10-bit LogL from Y */
|
||||
{
|
||||
if (Y >= 15.742)
|
||||
return (0x3ff);
|
||||
else if (Y <= .00024283)
|
||||
return (0);
|
||||
else
|
||||
return itrunc(64.*(log2(Y) + 12.), em);
|
||||
}
|
||||
|
||||
#define NANGLES 100
|
||||
#define uv2ang(u, v) ( (NANGLES*.499999999/M_PI) \
|
||||
* atan2((v)-V_NEU,(u)-U_NEU) + .5*NANGLES )
|
||||
|
||||
static int
|
||||
uv_encode(double u, double v) /* encode (u',v') coordinates */
|
||||
oog_encode(double u, double v) /* encode out-of-gamut chroma */
|
||||
{
|
||||
static int oog_table[NANGLES];
|
||||
static int initialized = 0;
|
||||
register int i;
|
||||
|
||||
if (!initialized) { /* set up perimeter table */
|
||||
double eps[NANGLES], ua, va, ang, epsa;
|
||||
int ui, vi, ustep;
|
||||
for (i = NANGLES; i--; )
|
||||
eps[i] = 2.;
|
||||
for (vi = UV_NVS; vi--; ) {
|
||||
va = UV_VSTART + (vi+.5)*UV_SQSIZ;
|
||||
ustep = uv_row[vi].nus-1;
|
||||
if (vi == UV_NVS-1 || vi == 0 || ustep <= 0)
|
||||
ustep = 1;
|
||||
for (ui = uv_row[vi].nus-1; ui >= 0; ui -= ustep) {
|
||||
ua = uv_row[vi].ustart + (ui+.5)*UV_SQSIZ;
|
||||
ang = uv2ang(ua, va);
|
||||
i = (int) ang;
|
||||
epsa = fabs(ang - (i+.5));
|
||||
if (epsa < eps[i]) {
|
||||
oog_table[i] = uv_row[vi].ncum + ui;
|
||||
eps[i] = epsa;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i = NANGLES; i--; ) /* fill any holes */
|
||||
if (eps[i] > 1.5) {
|
||||
int i1, i2;
|
||||
for (i1 = 1; i1 < NANGLES/2; i1++)
|
||||
if (eps[(i+i1)%NANGLES] < 1.5)
|
||||
break;
|
||||
for (i2 = 1; i2 < NANGLES/2; i2++)
|
||||
if (eps[(i+NANGLES-i2)%NANGLES] < 1.5)
|
||||
break;
|
||||
if (i1 < i2)
|
||||
oog_table[i] =
|
||||
oog_table[(i+i1)%NANGLES];
|
||||
else
|
||||
oog_table[i] =
|
||||
oog_table[(i+NANGLES-i2)%NANGLES];
|
||||
}
|
||||
initialized = 1;
|
||||
}
|
||||
i = (int) uv2ang(u, v); /* look up hue angle */
|
||||
return (oog_table[i]);
|
||||
}
|
||||
|
||||
#undef uv2ang
|
||||
#undef NANGLES
|
||||
|
||||
#if !LOGLUV_PUBLIC
|
||||
static
|
||||
#endif
|
||||
int
|
||||
uv_encode(double u, double v, int em) /* encode (u',v') coordinates */
|
||||
{
|
||||
register int vi, ui;
|
||||
|
||||
if (v < UV_VSTART)
|
||||
return(-1);
|
||||
vi = (v - UV_VSTART)*(1./UV_SQSIZ);
|
||||
return oog_encode(u, v);
|
||||
vi = itrunc((v - UV_VSTART)*(1./UV_SQSIZ), em);
|
||||
if (vi >= UV_NVS)
|
||||
return(-1);
|
||||
return oog_encode(u, v);
|
||||
if (u < uv_row[vi].ustart)
|
||||
return(-1);
|
||||
ui = (u - uv_row[vi].ustart)*(1./UV_SQSIZ);
|
||||
return oog_encode(u, v);
|
||||
ui = itrunc((u - uv_row[vi].ustart)*(1./UV_SQSIZ), em);
|
||||
if (ui >= uv_row[vi].nus)
|
||||
return(-1);
|
||||
return(uv_row[vi].ncum + ui);
|
||||
return oog_encode(u, v);
|
||||
|
||||
return (uv_row[vi].ncum + ui);
|
||||
}
|
||||
|
||||
static int
|
||||
#if !LOGLUV_PUBLIC
|
||||
static
|
||||
#endif
|
||||
int
|
||||
uv_decode(double *up, double *vp, int c) /* decode (u',v') index */
|
||||
{
|
||||
int upper, lower;
|
||||
register int ui, vi;
|
||||
|
||||
if (c < 0 || c >= UV_NDIVS)
|
||||
return(-1);
|
||||
lower = 0; /* binary search */
|
||||
return (-1);
|
||||
lower = 0; /* binary search */
|
||||
upper = UV_NVS;
|
||||
do {
|
||||
while (upper - lower > 1) {
|
||||
vi = (lower + upper) >> 1;
|
||||
ui = c - uv_row[vi].ncum;
|
||||
if (ui > 0)
|
||||
lower = vi;
|
||||
else if (ui < 0)
|
||||
upper = vi;
|
||||
else
|
||||
else {
|
||||
lower = vi;
|
||||
break;
|
||||
} while (upper - lower > 1);
|
||||
}
|
||||
}
|
||||
vi = lower;
|
||||
ui = c - uv_row[vi].ncum;
|
||||
*up = uv_row[vi].ustart + (ui+.5)*UV_SQSIZ;
|
||||
*vp = UV_VSTART + (vi+.5)*UV_SQSIZ;
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
pix24toXYZ(uint32 p, float XYZ[3])
|
||||
#if !LOGLUV_PUBLIC
|
||||
static
|
||||
#endif
|
||||
void
|
||||
LogLuv24toXYZ(uint32 p, float XYZ[3])
|
||||
{
|
||||
int Le, Ce;
|
||||
int Ce;
|
||||
double L, u, v, s, x, y;
|
||||
/* decode luminance */
|
||||
Le = p >> 14 & 0x3ff;
|
||||
if (Le == 0) {
|
||||
L = LogL10toY(p>>14 & 0x3ff);
|
||||
if (L <= 0.) {
|
||||
XYZ[0] = XYZ[1] = XYZ[2] = 0.;
|
||||
return;
|
||||
}
|
||||
L = exp(LOGOF2/64.*(Le+.5) - LOGOF2*12.);
|
||||
/* decode color */
|
||||
Ce = p & 0x3fff;
|
||||
if (uv_decode(&u, &v, Ce) < 0) {
|
||||
@@ -757,36 +884,33 @@ pix24toXYZ(uint32 p, float XYZ[3])
|
||||
x = 9.*u * s;
|
||||
y = 4.*v * s;
|
||||
/* convert to XYZ */
|
||||
XYZ[0] = x/y * L;
|
||||
XYZ[1] = L;
|
||||
XYZ[2] = (1.-x-y)/y * L;
|
||||
XYZ[0] = (float)(x/y * L);
|
||||
XYZ[1] = (float)L;
|
||||
XYZ[2] = (float)((1.-x-y)/y * L);
|
||||
}
|
||||
|
||||
static uint32
|
||||
pix24fromXYZ(float XYZ[3])
|
||||
#if !LOGLUV_PUBLIC
|
||||
static
|
||||
#endif
|
||||
uint32
|
||||
LogLuv24fromXYZ(float XYZ[3], int em)
|
||||
{
|
||||
int Le, Ce;
|
||||
double L, u, v, s;
|
||||
double u, v, s;
|
||||
/* encode luminance */
|
||||
L = XYZ[1];
|
||||
if (L >= 16.)
|
||||
Le = 0x3ff;
|
||||
else if (L <= 1./4096.)
|
||||
Le = 0;
|
||||
else
|
||||
Le = 64.*(log2(L) + 12.);
|
||||
Le = LogL10fromY(XYZ[1], em);
|
||||
/* encode color */
|
||||
s = XYZ[0] + 15.*XYZ[1] + 3.*XYZ[2];
|
||||
if (s == 0.) {
|
||||
if (!Le || s <= 0.) {
|
||||
u = U_NEU;
|
||||
v = V_NEU;
|
||||
} else {
|
||||
u = 4.*XYZ[0] / s;
|
||||
v = 9.*XYZ[1] / s;
|
||||
}
|
||||
Ce = uv_encode(u, v);
|
||||
if (Ce < 0)
|
||||
Ce = uv_encode(U_NEU, V_NEU);
|
||||
Ce = uv_encode(u, v, em);
|
||||
if (Ce < 0) /* never happens */
|
||||
Ce = uv_encode(U_NEU, V_NEU, SGILOGENCODE_NODITHER);
|
||||
/* combine encodings */
|
||||
return (Le << 14 | Ce);
|
||||
}
|
||||
@@ -798,7 +922,7 @@ Luv24toXYZ(LogLuvState* sp, tidata_t op, int n)
|
||||
float* xyz = (float*) op;
|
||||
|
||||
while (n-- > 0) {
|
||||
pix24toXYZ(*luv, xyz);
|
||||
LogLuv24toXYZ(*luv, xyz);
|
||||
xyz += 3;
|
||||
luv++;
|
||||
}
|
||||
@@ -813,13 +937,13 @@ Luv24toLuv48(LogLuvState* sp, tidata_t op, int n)
|
||||
while (n-- > 0) {
|
||||
double u, v;
|
||||
|
||||
*luv3++ = (*luv >> 12 & 0xffd) + 13314;
|
||||
*luv3++ = (int16)((*luv >> 12 & 0xffd) + 13314);
|
||||
if (uv_decode(&u, &v, *luv&0x3fff) < 0) {
|
||||
u = U_NEU;
|
||||
v = V_NEU;
|
||||
}
|
||||
*luv3++ = u * (1L<<15);
|
||||
*luv3++ = v * (1L<<15);
|
||||
*luv3++ = (int16)(u * (1L<<15));
|
||||
*luv3++ = (int16)(v * (1L<<15));
|
||||
luv++;
|
||||
}
|
||||
}
|
||||
@@ -833,7 +957,7 @@ Luv24toRGB(LogLuvState* sp, tidata_t op, int n)
|
||||
while (n-- > 0) {
|
||||
float xyz[3];
|
||||
|
||||
pix24toXYZ(*luv++, xyz);
|
||||
LogLuv24toXYZ(*luv++, xyz);
|
||||
XYZtoRGB24(xyz, rgb);
|
||||
rgb += 3;
|
||||
}
|
||||
@@ -846,7 +970,7 @@ Luv24fromXYZ(LogLuvState* sp, tidata_t op, int n)
|
||||
float* xyz = (float*) op;
|
||||
|
||||
while (n-- > 0) {
|
||||
*luv++ = pix24fromXYZ(xyz);
|
||||
*luv++ = LogLuv24fromXYZ(xyz, sp->encode_meth);
|
||||
xyz += 3;
|
||||
}
|
||||
}
|
||||
@@ -864,23 +988,30 @@ Luv24fromLuv48(LogLuvState* sp, tidata_t op, int n)
|
||||
Le = 0;
|
||||
else if (luv3[0] >= (1<<12)+3314)
|
||||
Le = (1<<10) - 1;
|
||||
else
|
||||
else if (sp->encode_meth == SGILOGENCODE_NODITHER)
|
||||
Le = (luv3[0]-3314) >> 2;
|
||||
Ce = uv_encode((luv[1]+.5)/(1<<15), (luv[2]+.5)/(1<<15));
|
||||
if (Ce < 0)
|
||||
Ce = uv_encode(U_NEU, V_NEU);
|
||||
else
|
||||
Le = itrunc(.25*(luv3[0]-3314.), sp->encode_meth);
|
||||
|
||||
Ce = uv_encode((luv3[1]+.5)/(1<<15), (luv3[2]+.5)/(1<<15),
|
||||
sp->encode_meth);
|
||||
if (Ce < 0) /* never happens */
|
||||
Ce = uv_encode(U_NEU, V_NEU, SGILOGENCODE_NODITHER);
|
||||
*luv++ = (uint32)Le << 14 | Ce;
|
||||
luv3 += 3;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pix32toXYZ(uint32 p, float XYZ[3])
|
||||
#if !LOGLUV_PUBLIC
|
||||
static
|
||||
#endif
|
||||
void
|
||||
LogLuv32toXYZ(uint32 p, float XYZ[3])
|
||||
{
|
||||
double L, u, v, s, x, y;
|
||||
/* decode luminance */
|
||||
L = pix16toY((int)p >> 16);
|
||||
if (L == 0.) {
|
||||
L = LogL16toY((int)p >> 16);
|
||||
if (L <= 0.) {
|
||||
XYZ[0] = XYZ[1] = XYZ[2] = 0.;
|
||||
return;
|
||||
}
|
||||
@@ -891,21 +1022,24 @@ pix32toXYZ(uint32 p, float XYZ[3])
|
||||
x = 9.*u * s;
|
||||
y = 4.*v * s;
|
||||
/* convert to XYZ */
|
||||
XYZ[0] = x/y * L;
|
||||
XYZ[1] = L;
|
||||
XYZ[2] = (1.-x-y)/y * L;
|
||||
XYZ[0] = (float)(x/y * L);
|
||||
XYZ[1] = (float)L;
|
||||
XYZ[2] = (float)((1.-x-y)/y * L);
|
||||
}
|
||||
|
||||
static uint32
|
||||
pix32fromXYZ(float XYZ[3])
|
||||
#if !LOGLUV_PUBLIC
|
||||
static
|
||||
#endif
|
||||
uint32
|
||||
LogLuv32fromXYZ(float XYZ[3], int em)
|
||||
{
|
||||
unsigned int Le, ue, ve;
|
||||
double u, v, s;
|
||||
/* encode luminance */
|
||||
Le = (unsigned int)pix16fromY(XYZ[1]);
|
||||
Le = (unsigned int)LogL16fromY(XYZ[1], em);
|
||||
/* encode color */
|
||||
s = XYZ[0] + 15.*XYZ[1] + 3.*XYZ[2];
|
||||
if (s == 0.) {
|
||||
if (!Le || s <= 0.) {
|
||||
u = U_NEU;
|
||||
v = V_NEU;
|
||||
} else {
|
||||
@@ -913,10 +1047,10 @@ pix32fromXYZ(float XYZ[3])
|
||||
v = 9.*XYZ[1] / s;
|
||||
}
|
||||
if (u <= 0.) ue = 0;
|
||||
else ue = UVSCALE * u;
|
||||
else ue = itrunc(UVSCALE*u, em);
|
||||
if (ue > 255) ue = 255;
|
||||
if (v <= 0.) ve = 0;
|
||||
else ve = UVSCALE * v;
|
||||
else ve = itrunc(UVSCALE*v, em);
|
||||
if (ve > 255) ve = 255;
|
||||
/* combine encodings */
|
||||
return (Le << 16 | ue << 8 | ve);
|
||||
@@ -929,7 +1063,7 @@ Luv32toXYZ(LogLuvState* sp, tidata_t op, int n)
|
||||
float* xyz = (float*) op;
|
||||
|
||||
while (n-- > 0) {
|
||||
pix32toXYZ(*luv++, xyz);
|
||||
LogLuv32toXYZ(*luv++, xyz);
|
||||
xyz += 3;
|
||||
}
|
||||
}
|
||||
@@ -943,11 +1077,11 @@ Luv32toLuv48(LogLuvState* sp, tidata_t op, int n)
|
||||
while (n-- > 0) {
|
||||
double u, v;
|
||||
|
||||
*luv3++ = *luv >> 16;
|
||||
*luv3++ = (int16)(*luv >> 16);
|
||||
u = 1./UVSCALE * ((*luv>>8 & 0xff) + .5);
|
||||
v = 1./UVSCALE * ((*luv & 0xff) + .5);
|
||||
*luv3++ = u * (1L<<15);
|
||||
*luv3++ = v * (1L<<15);
|
||||
*luv3++ = (int16)(u * (1L<<15));
|
||||
*luv3++ = (int16)(v * (1L<<15));
|
||||
luv++;
|
||||
}
|
||||
}
|
||||
@@ -961,7 +1095,7 @@ Luv32toRGB(LogLuvState* sp, tidata_t op, int n)
|
||||
while (n-- > 0) {
|
||||
float xyz[3];
|
||||
|
||||
pix32toXYZ(*luv++, xyz);
|
||||
LogLuv32toXYZ(*luv++, xyz);
|
||||
XYZtoRGB24(xyz, rgb);
|
||||
rgb += 3;
|
||||
}
|
||||
@@ -974,7 +1108,7 @@ Luv32fromXYZ(LogLuvState* sp, tidata_t op, int n)
|
||||
float* xyz = (float*) op;
|
||||
|
||||
while (n-- > 0) {
|
||||
*luv++ = pix32fromXYZ(xyz);
|
||||
*luv++ = LogLuv32fromXYZ(xyz, sp->encode_meth);
|
||||
xyz += 3;
|
||||
}
|
||||
}
|
||||
@@ -985,10 +1119,19 @@ Luv32fromLuv48(LogLuvState* sp, tidata_t op, int n)
|
||||
uint32* luv = (uint32*) sp->tbuf;
|
||||
int16* luv3 = (int16*) op;
|
||||
|
||||
if (sp->encode_meth == SGILOGENCODE_NODITHER) {
|
||||
while (n-- > 0) {
|
||||
*luv++ = (uint32)luv3[0] << 16 |
|
||||
(luv3[1]*(uint32)(UVSCALE+.5) >> 7 & 0xff00) |
|
||||
(luv3[2]*(uint32)(UVSCALE+.5) >> 15 & 0xff);
|
||||
luv3 += 3;
|
||||
}
|
||||
return;
|
||||
}
|
||||
while (n-- > 0) {
|
||||
*luv++ = (uint32)luv3[0] << 16 |
|
||||
(luv3[1]*(uint32)(UVSCALE+.5) >> 7 & 0xff00) |
|
||||
(luv3[2]*(uint32)(UVSCALE+.5) >> 15 & 0xff);
|
||||
(itrunc(luv3[1]*(UVSCALE/(1<<15)), sp->encode_meth) << 8 & 0xff00) |
|
||||
(itrunc(luv3[2]*(UVSCALE/(1<<15)), sp->encode_meth) & 0xff);
|
||||
luv3 += 3;
|
||||
}
|
||||
}
|
||||
@@ -1018,6 +1161,17 @@ LogL16GuessDataFmt(TIFFDirectory *td)
|
||||
return (SGILOGDATAFMT_UNKNOWN);
|
||||
}
|
||||
|
||||
static uint32
|
||||
multiply(size_t m1, size_t m2)
|
||||
{
|
||||
uint32 bytes = m1 * m2;
|
||||
|
||||
if (m1 && bytes / m1 != m2)
|
||||
bytes = 0;
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
static int
|
||||
LogL16InitState(TIFF* tif)
|
||||
{
|
||||
@@ -1046,9 +1200,9 @@ LogL16InitState(TIFF* tif)
|
||||
"No support for converting user data format to LogL");
|
||||
return (0);
|
||||
}
|
||||
sp->tbuflen = td->td_imagewidth * td->td_rowsperstrip;
|
||||
sp->tbuf = (tidata_t*) _TIFFmalloc(sp->tbuflen * sizeof (int16));
|
||||
if (sp->tbuf == NULL) {
|
||||
sp->tbuflen = multiply(td->td_imagewidth, td->td_rowsperstrip);
|
||||
if (multiply(sp->tbuflen, sizeof (int16)) == 0 ||
|
||||
(sp->tbuf = (tidata_t*) _TIFFmalloc(sp->tbuflen * sizeof (int16))) == NULL) {
|
||||
TIFFError(module, "%s: No space for SGILog translation buffer",
|
||||
tif->tif_name);
|
||||
return (0);
|
||||
@@ -1144,9 +1298,9 @@ LogLuvInitState(TIFF* tif)
|
||||
"No support for converting user data format to LogLuv");
|
||||
return (0);
|
||||
}
|
||||
sp->tbuflen = td->td_imagewidth * td->td_rowsperstrip;
|
||||
sp->tbuf = (tidata_t*) _TIFFmalloc(sp->tbuflen * sizeof (uint32));
|
||||
if (sp->tbuf == NULL) {
|
||||
sp->tbuflen = multiply(td->td_imagewidth, td->td_rowsperstrip);
|
||||
if (multiply(sp->tbuflen, sizeof (uint32)) == 0 ||
|
||||
(sp->tbuf = (tidata_t*) _TIFFmalloc(sp->tbuflen * sizeof (uint32))) == NULL) {
|
||||
TIFFError(module, "%s: No space for SGILog translation buffer",
|
||||
tif->tif_name);
|
||||
return (0);
|
||||
@@ -1338,6 +1492,7 @@ LogLuvVSetField(TIFF* tif, ttag_t tag, va_list ap)
|
||||
break;
|
||||
case SGILOGDATAFMT_RAW:
|
||||
bps = 32, fmt = SAMPLEFORMAT_UINT;
|
||||
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1);
|
||||
break;
|
||||
case SGILOGDATAFMT_8BIT:
|
||||
bps = 8, fmt = SAMPLEFORMAT_UINT;
|
||||
@@ -1356,6 +1511,16 @@ LogLuvVSetField(TIFF* tif, ttag_t tag, va_list ap)
|
||||
tif->tif_tilesize = TIFFTileSize(tif);
|
||||
tif->tif_scanlinesize = TIFFScanlineSize(tif);
|
||||
return (1);
|
||||
case TIFFTAG_SGILOGENCODE:
|
||||
sp->encode_meth = va_arg(ap, int);
|
||||
if (sp->encode_meth != SGILOGENCODE_NODITHER &&
|
||||
sp->encode_meth != SGILOGENCODE_RANDITHER) {
|
||||
TIFFError(tif->tif_name,
|
||||
"Unknown encoding %d for LogLuv compression",
|
||||
sp->encode_meth);
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
default:
|
||||
return (*sp->vsetparent)(tif, tag, ap);
|
||||
}
|
||||
@@ -1377,7 +1542,9 @@ LogLuvVGetField(TIFF* tif, ttag_t tag, va_list ap)
|
||||
|
||||
static const TIFFFieldInfo LogLuvFieldInfo[] = {
|
||||
{ TIFFTAG_SGILOGDATAFMT, 0, 0, TIFF_SHORT, FIELD_PSEUDO,
|
||||
TRUE, FALSE, "SGILogDataFmt"}
|
||||
TRUE, FALSE, "SGILogDataFmt"},
|
||||
{ TIFFTAG_SGILOGENCODE, 0, 0, TIFF_SHORT, FIELD_PSEUDO,
|
||||
TRUE, FALSE, "SGILogEncode"}
|
||||
};
|
||||
|
||||
int
|
||||
@@ -1395,8 +1562,10 @@ TIFFInitSGILog(TIFF* tif, int scheme)
|
||||
if (tif->tif_data == NULL)
|
||||
goto bad;
|
||||
sp = (LogLuvState*) tif->tif_data;
|
||||
memset(sp, 0, sizeof (*sp));
|
||||
_TIFFmemset((tdata_t)sp, 0, sizeof (*sp));
|
||||
sp->user_datafmt = SGILOGDATAFMT_UNKNOWN;
|
||||
sp->encode_meth = (scheme == COMPRESSION_SGILOG24) ?
|
||||
SGILOGENCODE_RANDITHER : SGILOGENCODE_NODITHER;
|
||||
sp->tfunc = _logLuvNop;
|
||||
|
||||
/*
|
||||
@@ -1415,10 +1584,10 @@ TIFFInitSGILog(TIFF* tif, int scheme)
|
||||
|
||||
/* override SetField so we can handle our private pseudo-tag */
|
||||
_TIFFMergeFieldInfo(tif, LogLuvFieldInfo, N(LogLuvFieldInfo));
|
||||
sp->vgetparent = tif->tif_vgetfield;
|
||||
tif->tif_vgetfield = LogLuvVGetField; /* hook for codec tags */
|
||||
sp->vsetparent = tif->tif_vsetfield;
|
||||
tif->tif_vsetfield = LogLuvVSetField; /* hook for codec tags */
|
||||
sp->vgetparent = tif->tif_tagmethods.vgetfield;
|
||||
tif->tif_tagmethods.vgetfield = LogLuvVGetField; /* hook for codec tags */
|
||||
sp->vsetparent = tif->tif_tagmethods.vsetfield;
|
||||
tif->tif_tagmethods.vsetfield = LogLuvVSetField; /* hook for codec tags */
|
||||
|
||||
return (1);
|
||||
bad:
|
||||
|
@@ -4,23 +4,23 @@
|
||||
* Copyright (c) 1988-1997 Sam Leffler
|
||||
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* its documentation for any purpose is hereby granted without fee, provided
|
||||
* that (i) the above copyright notices and this permission notice appear in
|
||||
* all copies of the software and related documentation, and (ii) the names of
|
||||
* Sam Leffler and Silicon Graphics may not be used in any advertising or
|
||||
* publicity relating to the software without the specific, prior written
|
||||
* permission of Sam Leffler and Silicon Graphics.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
|
||||
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
|
||||
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
||||
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
||||
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
@@ -36,12 +36,7 @@
|
||||
*
|
||||
* The original Berkeley copyright notice appears below in its entirety.
|
||||
*/
|
||||
/* Watcom C++ (or its make utility) doesn't like long filenames */
|
||||
#ifdef wxUSE_SHORTNAMES
|
||||
#include "tif_pred.h"
|
||||
#else
|
||||
#include "tif_predict.h"
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
@@ -110,6 +105,11 @@ typedef struct {
|
||||
#define lzw_nextdata base.nextdata
|
||||
#define lzw_nextbits base.nextbits
|
||||
|
||||
/*
|
||||
* Encoding-specific state.
|
||||
*/
|
||||
typedef uint16 hcode_t; /* codes fit in 16 bits */
|
||||
|
||||
/*
|
||||
* Decoding-specific state.
|
||||
*/
|
||||
@@ -120,10 +120,12 @@ typedef struct code_ent {
|
||||
u_char firstchar; /* first token of string */
|
||||
} code_t;
|
||||
|
||||
typedef int (LINKAGEMODE *decodeFunc)(TIFF*, tidata_t, tsize_t, tsample_t);
|
||||
typedef int (*decodeFunc)(TIFF*, tidata_t, tsize_t, tsample_t);
|
||||
|
||||
typedef struct {
|
||||
LZWBaseState base;
|
||||
|
||||
/* Decoding specific data */
|
||||
long dec_nbitsmask; /* lzw_nbits 1 bits, right adjusted */
|
||||
long dec_restart; /* restart count */
|
||||
#ifdef LZW_CHECKEOS
|
||||
@@ -135,38 +137,15 @@ typedef struct {
|
||||
code_t* dec_free_entp; /* next free entry */
|
||||
code_t* dec_maxcodep; /* max available entry */
|
||||
code_t* dec_codetab; /* kept separate for small machines */
|
||||
} LZWDecodeState;
|
||||
|
||||
/*
|
||||
* Encoding-specific state.
|
||||
*/
|
||||
typedef uint16 hcode_t; /* codes fit in 16 bits */
|
||||
typedef struct {
|
||||
long hash;
|
||||
hcode_t code;
|
||||
} hash_t;
|
||||
|
||||
typedef struct {
|
||||
LZWBaseState base;
|
||||
int enc_oldcode; /* last code encountered */
|
||||
long enc_checkpoint; /* point at which to clear table */
|
||||
#define CHECK_GAP 10000 /* enc_ratio check interval */
|
||||
long enc_ratio; /* current compression ratio */
|
||||
long enc_incount; /* (input) data bytes encoded */
|
||||
long enc_outcount; /* encoded (output) bytes */
|
||||
tidata_t enc_rawlimit; /* bound on tif_rawdata buffer */
|
||||
hash_t* enc_hashtab; /* kept separate for small machines */
|
||||
} LZWEncodeState;
|
||||
} LZWCodecState;
|
||||
|
||||
#define LZWState(tif) ((LZWBaseState*) (tif)->tif_data)
|
||||
#define DecoderState(tif) ((LZWDecodeState*) LZWState(tif))
|
||||
#define EncoderState(tif) ((LZWEncodeState*) LZWState(tif))
|
||||
#define DecoderState(tif) ((LZWCodecState*) LZWState(tif))
|
||||
|
||||
static int LINKAGEMODE LZWDecode(TIFF*, tidata_t, tsize_t, tsample_t);
|
||||
static int LZWDecode(TIFF*, tidata_t, tsize_t, tsample_t);
|
||||
#ifdef LZW_COMPAT
|
||||
static int LINKAGEMODE LZWDecodeCompat(TIFF*, tidata_t, tsize_t, tsample_t);
|
||||
static int LZWDecodeCompat(TIFF*, tidata_t, tsize_t, tsample_t);
|
||||
#endif
|
||||
static void cl_hash(LZWEncodeState*);
|
||||
|
||||
/*
|
||||
* LZW Decoder.
|
||||
@@ -195,11 +174,12 @@ static void cl_hash(LZWEncodeState*);
|
||||
static int
|
||||
LZWSetupDecode(TIFF* tif)
|
||||
{
|
||||
LZWDecodeState* sp = DecoderState(tif);
|
||||
static const char module[] = " LZWSetupDecode";
|
||||
LZWCodecState* sp = DecoderState(tif);
|
||||
static const char module[] = "LZWSetupDecode";
|
||||
int code;
|
||||
|
||||
assert(sp != NULL);
|
||||
|
||||
if (sp->dec_codetab == NULL) {
|
||||
sp->dec_codetab = (code_t*)_TIFFmalloc(CSIZE*sizeof (code_t));
|
||||
if (sp->dec_codetab == NULL) {
|
||||
@@ -209,12 +189,13 @@ LZWSetupDecode(TIFF* tif)
|
||||
/*
|
||||
* Pre-load the table.
|
||||
*/
|
||||
for (code = 255; code >= 0; code--) {
|
||||
sp->dec_codetab[code].value = code;
|
||||
sp->dec_codetab[code].firstchar = code;
|
||||
sp->dec_codetab[code].length = 1;
|
||||
sp->dec_codetab[code].next = NULL;
|
||||
}
|
||||
code = 255;
|
||||
do {
|
||||
sp->dec_codetab[code].value = (u_char) code;
|
||||
sp->dec_codetab[code].firstchar = (u_char) code;
|
||||
sp->dec_codetab[code].length = 1;
|
||||
sp->dec_codetab[code].next = NULL;
|
||||
} while (code--);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
@@ -225,7 +206,7 @@ LZWSetupDecode(TIFF* tif)
|
||||
static int
|
||||
LZWPreDecode(TIFF* tif, tsample_t s)
|
||||
{
|
||||
LZWDecodeState *sp = DecoderState(tif);
|
||||
LZWCodecState *sp = DecoderState(tif);
|
||||
|
||||
(void) s;
|
||||
assert(sp != NULL);
|
||||
@@ -316,7 +297,7 @@ codeLoop(TIFF* tif)
|
||||
static int
|
||||
LZWDecode(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
|
||||
{
|
||||
LZWDecodeState *sp = DecoderState(tif);
|
||||
LZWCodecState *sp = DecoderState(tif);
|
||||
char *op = (char*) op0;
|
||||
long occ = (long) occ0;
|
||||
char *tp;
|
||||
@@ -366,7 +347,7 @@ LZWDecode(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
|
||||
--tp;
|
||||
t = codep->value;
|
||||
codep = codep->next;
|
||||
*tp = t;
|
||||
*tp = (char) t;
|
||||
} while (--residue && codep);
|
||||
sp->dec_restart = 0;
|
||||
}
|
||||
@@ -392,7 +373,7 @@ LZWDecode(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
|
||||
NextCode(tif, sp, bp, code, GetNextCode);
|
||||
if (code == CODE_EOI)
|
||||
break;
|
||||
*op++ = code, occ--;
|
||||
*op++ = (char)code, occ--;
|
||||
oldcodep = sp->dec_codetab + code;
|
||||
continue;
|
||||
}
|
||||
@@ -401,8 +382,22 @@ LZWDecode(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
|
||||
/*
|
||||
* Add the new entry to the code table.
|
||||
*/
|
||||
assert(&sp->dec_codetab[0] <= free_entp && free_entp < &sp->dec_codetab[CSIZE]);
|
||||
if (free_entp < &sp->dec_codetab[0] ||
|
||||
free_entp >= &sp->dec_codetab[CSIZE]) {
|
||||
TIFFError(tif->tif_name,
|
||||
"LZWDecode: Corrupted LZW table at scanline %d",
|
||||
tif->tif_row);
|
||||
return (0);
|
||||
}
|
||||
|
||||
free_entp->next = oldcodep;
|
||||
if (free_entp->next < &sp->dec_codetab[0] ||
|
||||
free_entp->next >= &sp->dec_codetab[CSIZE]) {
|
||||
TIFFError(tif->tif_name,
|
||||
"LZWDecode: Corrupted LZW table at scanline %d",
|
||||
tif->tif_row);
|
||||
return (0);
|
||||
}
|
||||
free_entp->firstchar = free_entp->next->firstchar;
|
||||
free_entp->length = free_entp->next->length+1;
|
||||
free_entp->value = (codep < free_entp) ?
|
||||
@@ -419,6 +414,13 @@ LZWDecode(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
|
||||
* Code maps to a string, copy string
|
||||
* value to output (written in reverse).
|
||||
*/
|
||||
if(codep->length == 0) {
|
||||
TIFFError(tif->tif_name,
|
||||
"LZWDecode: Wrong length of decoded string: "
|
||||
"data probably corrupted at scanline %d",
|
||||
tif->tif_row);
|
||||
return (0);
|
||||
}
|
||||
if (codep->length > occ) {
|
||||
/*
|
||||
* String is too long for decode buffer,
|
||||
@@ -449,7 +451,7 @@ LZWDecode(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
|
||||
--tp;
|
||||
t = codep->value;
|
||||
codep = codep->next;
|
||||
*tp = t;
|
||||
*tp = (char) t;
|
||||
} while (codep && tp > op);
|
||||
if (codep) {
|
||||
codeLoop(tif);
|
||||
@@ -457,7 +459,7 @@ LZWDecode(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
|
||||
}
|
||||
op += len, occ -= len;
|
||||
} else
|
||||
*op++ = code, occ--;
|
||||
*op++ = (char)code, occ--;
|
||||
}
|
||||
|
||||
tif->tif_rawcp = (tidata_t) bp;
|
||||
@@ -494,10 +496,10 @@ LZWDecode(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
|
||||
nextbits -= nbits; \
|
||||
}
|
||||
|
||||
static int LINKAGEMODE
|
||||
static int
|
||||
LZWDecodeCompat(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
|
||||
{
|
||||
LZWDecodeState *sp = DecoderState(tif);
|
||||
LZWCodecState *sp = DecoderState(tif);
|
||||
char *op = (char*) op0;
|
||||
long occ = (long) occ0;
|
||||
char *tp;
|
||||
@@ -567,7 +569,7 @@ LZWDecodeCompat(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
|
||||
NextCode(tif, sp, bp, code, GetNextCodeCompat);
|
||||
if (code == CODE_EOI)
|
||||
break;
|
||||
*op++ = code, occ--;
|
||||
*op++ = (char) code, occ--;
|
||||
oldcodep = sp->dec_codetab + code;
|
||||
continue;
|
||||
}
|
||||
@@ -576,8 +578,22 @@ LZWDecodeCompat(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
|
||||
/*
|
||||
* Add the new entry to the code table.
|
||||
*/
|
||||
assert(&sp->dec_codetab[0] <= free_entp && free_entp < &sp->dec_codetab[CSIZE]);
|
||||
if (free_entp < &sp->dec_codetab[0] ||
|
||||
free_entp >= &sp->dec_codetab[CSIZE]) {
|
||||
TIFFError(tif->tif_name,
|
||||
"LZWDecodeCompat: Corrupted LZW table at scanline %d",
|
||||
tif->tif_row);
|
||||
return (0);
|
||||
}
|
||||
|
||||
free_entp->next = oldcodep;
|
||||
if (free_entp->next < &sp->dec_codetab[0] ||
|
||||
free_entp->next >= &sp->dec_codetab[CSIZE]) {
|
||||
TIFFError(tif->tif_name,
|
||||
"LZWDecodeCompat: Corrupted LZW table at scanline %d",
|
||||
tif->tif_row);
|
||||
return (0);
|
||||
}
|
||||
free_entp->firstchar = free_entp->next->firstchar;
|
||||
free_entp->length = free_entp->next->length+1;
|
||||
free_entp->value = (codep < free_entp) ?
|
||||
@@ -594,6 +610,13 @@ LZWDecodeCompat(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
|
||||
* Code maps to a string, copy string
|
||||
* value to output (written in reverse).
|
||||
*/
|
||||
if(codep->length == 0) {
|
||||
TIFFError(tif->tif_name,
|
||||
"LZWDecodeCompat: Wrong length of decoded "
|
||||
"string: data probably corrupted at scanline %d",
|
||||
tif->tif_row);
|
||||
return (0);
|
||||
}
|
||||
if (codep->length > occ) {
|
||||
/*
|
||||
* String is too long for decode buffer,
|
||||
@@ -619,11 +642,11 @@ LZWDecodeCompat(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
|
||||
*--tp = codep->value;
|
||||
} while( (codep = codep->next) != NULL);
|
||||
} else
|
||||
*op++ = code, occ--;
|
||||
*op++ = (char) code, occ--;
|
||||
}
|
||||
|
||||
tif->tif_rawcp = (tidata_t) bp;
|
||||
sp->lzw_nbits = nbits;
|
||||
sp->lzw_nbits = (u_short) nbits;
|
||||
sp->lzw_nextdata = nextdata;
|
||||
sp->lzw_nextbits = nextbits;
|
||||
sp->dec_nbitsmask = nbitsmask;
|
||||
@@ -641,355 +664,59 @@ LZWDecodeCompat(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
|
||||
}
|
||||
#endif /* LZW_COMPAT */
|
||||
|
||||
/*
|
||||
* LZW Encoding.
|
||||
*/
|
||||
|
||||
static int
|
||||
LZWSetupEncode(TIFF* tif)
|
||||
{
|
||||
LZWEncodeState* sp = EncoderState(tif);
|
||||
static const char module[] = "LZWSetupEncode";
|
||||
|
||||
assert(sp != NULL);
|
||||
sp->enc_hashtab = (hash_t*) _TIFFmalloc(HSIZE*sizeof (hash_t));
|
||||
if (sp->enc_hashtab == NULL) {
|
||||
TIFFError(module, "No space for LZW hash table");
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Reset encoding state at the start of a strip.
|
||||
*/
|
||||
static int
|
||||
LZWPreEncode(TIFF* tif, tsample_t s)
|
||||
{
|
||||
LZWEncodeState *sp = EncoderState(tif);
|
||||
|
||||
(void) s;
|
||||
assert(sp != NULL);
|
||||
sp->lzw_nbits = BITS_MIN;
|
||||
sp->lzw_maxcode = MAXCODE(BITS_MIN);
|
||||
sp->lzw_free_ent = CODE_FIRST;
|
||||
sp->lzw_nextbits = 0;
|
||||
sp->lzw_nextdata = 0;
|
||||
sp->enc_checkpoint = CHECK_GAP;
|
||||
sp->enc_ratio = 0;
|
||||
sp->enc_incount = 0;
|
||||
sp->enc_outcount = 0;
|
||||
/*
|
||||
* The 4 here insures there is space for 2 max-sized
|
||||
* codes in LZWEncode and LZWPostDecode.
|
||||
*/
|
||||
sp->enc_rawlimit = tif->tif_rawdata + tif->tif_rawdatasize-1 - 4;
|
||||
cl_hash(sp); /* clear hash table */
|
||||
sp->enc_oldcode = (hcode_t) -1; /* generates CODE_CLEAR in LZWEncode */
|
||||
return (1);
|
||||
}
|
||||
|
||||
#define CALCRATIO(sp, rat) { \
|
||||
if (incount > 0x007fffff) { /* NB: shift will overflow */\
|
||||
rat = outcount >> 8; \
|
||||
rat = (rat == 0 ? 0x7fffffff : incount/rat); \
|
||||
} else \
|
||||
rat = (incount<<8) / outcount; \
|
||||
}
|
||||
#define PutNextCode(op, c) { \
|
||||
nextdata = (nextdata << nbits) | c; \
|
||||
nextbits += nbits; \
|
||||
*op++ = (u_char)(nextdata >> (nextbits-8)); \
|
||||
nextbits -= 8; \
|
||||
if (nextbits >= 8) { \
|
||||
*op++ = (u_char)(nextdata >> (nextbits-8)); \
|
||||
nextbits -= 8; \
|
||||
} \
|
||||
outcount += nbits; \
|
||||
}
|
||||
|
||||
/*
|
||||
* Encode a chunk of pixels.
|
||||
*
|
||||
* Uses an open addressing double hashing (no chaining) on the
|
||||
* prefix code/next character combination. We do a variant of
|
||||
* Knuth's algorithm D (vol. 3, sec. 6.4) along with G. Knott's
|
||||
* relatively-prime secondary probe. Here, the modular division
|
||||
* first probe is gives way to a faster exclusive-or manipulation.
|
||||
* Also do block compression with an adaptive reset, whereby the
|
||||
* code table is cleared when the compression ratio decreases,
|
||||
* but after the table fills. The variable-length output codes
|
||||
* are re-sized at this point, and a CODE_CLEAR is generated
|
||||
* for the decoder.
|
||||
*/
|
||||
static int LINKAGEMODE
|
||||
LZWEncode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
|
||||
{
|
||||
register LZWEncodeState *sp = EncoderState(tif);
|
||||
register long fcode;
|
||||
register hash_t *hp;
|
||||
register int h, c;
|
||||
hcode_t ent;
|
||||
long disp;
|
||||
long incount, outcount, checkpoint;
|
||||
long nextdata, nextbits;
|
||||
int free_ent, maxcode, nbits;
|
||||
tidata_t op, limit;
|
||||
|
||||
(void) s;
|
||||
if (sp == NULL)
|
||||
return (0);
|
||||
/*
|
||||
* Load local state.
|
||||
*/
|
||||
incount = sp->enc_incount;
|
||||
outcount = sp->enc_outcount;
|
||||
checkpoint = sp->enc_checkpoint;
|
||||
nextdata = sp->lzw_nextdata;
|
||||
nextbits = sp->lzw_nextbits;
|
||||
free_ent = sp->lzw_free_ent;
|
||||
maxcode = sp->lzw_maxcode;
|
||||
nbits = sp->lzw_nbits;
|
||||
op = tif->tif_rawcp;
|
||||
limit = sp->enc_rawlimit;
|
||||
ent = sp->enc_oldcode;
|
||||
|
||||
if (ent == (hcode_t) -1 && cc > 0) {
|
||||
/*
|
||||
* NB: This is safe because it can only happen
|
||||
* at the start of a strip where we know there
|
||||
* is space in the data buffer.
|
||||
*/
|
||||
PutNextCode(op, CODE_CLEAR);
|
||||
ent = *bp++; cc--; incount++;
|
||||
}
|
||||
while (cc > 0) {
|
||||
c = *bp++; cc--; incount++;
|
||||
fcode = ((long)c << BITS_MAX) + ent;
|
||||
h = (c << HSHIFT) ^ ent; /* xor hashing */
|
||||
#ifdef _WINDOWS
|
||||
/*
|
||||
* Check hash index for an overflow.
|
||||
*/
|
||||
if (h >= HSIZE)
|
||||
h -= HSIZE;
|
||||
#endif
|
||||
hp = &sp->enc_hashtab[h];
|
||||
if (hp->hash == fcode) {
|
||||
ent = hp->code;
|
||||
continue;
|
||||
}
|
||||
if (hp->hash >= 0) {
|
||||
/*
|
||||
* Primary hash failed, check secondary hash.
|
||||
*/
|
||||
disp = HSIZE - h;
|
||||
if (h == 0)
|
||||
disp = 1;
|
||||
do {
|
||||
/*
|
||||
* Avoid pointer arithmetic 'cuz of
|
||||
* wraparound problems with segments.
|
||||
*/
|
||||
if ((h -= disp) < 0)
|
||||
h += HSIZE;
|
||||
hp = &sp->enc_hashtab[h];
|
||||
if (hp->hash == fcode) {
|
||||
ent = hp->code;
|
||||
goto hit;
|
||||
}
|
||||
} while (hp->hash >= 0);
|
||||
}
|
||||
/*
|
||||
* New entry, emit code and add to table.
|
||||
*/
|
||||
/*
|
||||
* Verify there is space in the buffer for the code
|
||||
* and any potential Clear code that might be emitted
|
||||
* below. The value of limit is setup so that there
|
||||
* are at least 4 bytes free--room for 2 codes.
|
||||
*/
|
||||
if (op > limit) {
|
||||
tif->tif_rawcc = (tsize_t)(op - tif->tif_rawdata);
|
||||
TIFFFlushData1(tif);
|
||||
op = tif->tif_rawdata;
|
||||
}
|
||||
PutNextCode(op, ent);
|
||||
ent = c;
|
||||
hp->code = free_ent++;
|
||||
hp->hash = fcode;
|
||||
if (free_ent == CODE_MAX-1) {
|
||||
/* table is full, emit clear code and reset */
|
||||
cl_hash(sp);
|
||||
sp->enc_ratio = 0;
|
||||
incount = 0;
|
||||
outcount = 0;
|
||||
free_ent = CODE_FIRST;
|
||||
PutNextCode(op, CODE_CLEAR);
|
||||
nbits = BITS_MIN;
|
||||
maxcode = MAXCODE(BITS_MIN);
|
||||
} else {
|
||||
/*
|
||||
* If the next entry is going to be too big for
|
||||
* the code size, then increase it, if possible.
|
||||
*/
|
||||
if (free_ent > maxcode) {
|
||||
nbits++;
|
||||
assert(nbits <= BITS_MAX);
|
||||
maxcode = (int) MAXCODE(nbits);
|
||||
} else if (incount >= checkpoint) {
|
||||
long rat;
|
||||
/*
|
||||
* Check compression ratio and, if things seem
|
||||
* to be slipping, clear the hash table and
|
||||
* reset state. The compression ratio is a
|
||||
* 24+8-bit fractional number.
|
||||
*/
|
||||
checkpoint = incount+CHECK_GAP;
|
||||
CALCRATIO(sp, rat);
|
||||
if (rat <= sp->enc_ratio) {
|
||||
cl_hash(sp);
|
||||
sp->enc_ratio = 0;
|
||||
incount = 0;
|
||||
outcount = 0;
|
||||
free_ent = CODE_FIRST;
|
||||
PutNextCode(op, CODE_CLEAR);
|
||||
nbits = BITS_MIN;
|
||||
maxcode = MAXCODE(BITS_MIN);
|
||||
} else
|
||||
sp->enc_ratio = rat;
|
||||
}
|
||||
}
|
||||
hit:
|
||||
;
|
||||
}
|
||||
|
||||
/*
|
||||
* Restore global state.
|
||||
*/
|
||||
sp->enc_incount = incount;
|
||||
sp->enc_outcount = outcount;
|
||||
sp->enc_checkpoint = checkpoint;
|
||||
sp->enc_oldcode = ent;
|
||||
sp->lzw_nextdata = nextdata;
|
||||
sp->lzw_nextbits = nextbits;
|
||||
sp->lzw_free_ent = free_ent;
|
||||
sp->lzw_maxcode = maxcode;
|
||||
sp->lzw_nbits = nbits;
|
||||
tif->tif_rawcp = op;
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Finish off an encoded strip by flushing the last
|
||||
* string and tacking on an End Of Information code.
|
||||
*/
|
||||
static int
|
||||
LZWPostEncode(TIFF* tif)
|
||||
{
|
||||
register LZWEncodeState *sp = EncoderState(tif);
|
||||
tidata_t op = tif->tif_rawcp;
|
||||
long nextbits = sp->lzw_nextbits;
|
||||
long nextdata = sp->lzw_nextdata;
|
||||
long outcount = sp->enc_outcount;
|
||||
int nbits = sp->lzw_nbits;
|
||||
|
||||
if (op > sp->enc_rawlimit) {
|
||||
tif->tif_rawcc = (tsize_t)(op - tif->tif_rawdata);
|
||||
TIFFFlushData1(tif);
|
||||
op = tif->tif_rawdata;
|
||||
}
|
||||
if (sp->enc_oldcode != (hcode_t) -1) {
|
||||
PutNextCode(op, sp->enc_oldcode);
|
||||
sp->enc_oldcode = (hcode_t) -1;
|
||||
}
|
||||
PutNextCode(op, CODE_EOI);
|
||||
if (nextbits > 0)
|
||||
*op++ = (u_char)(nextdata << (8-nextbits));
|
||||
tif->tif_rawcc = (tsize_t)(op - tif->tif_rawdata);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Reset encoding hash table.
|
||||
*/
|
||||
static void
|
||||
cl_hash(LZWEncodeState* sp)
|
||||
{
|
||||
register hash_t *hp = &sp->enc_hashtab[HSIZE-1];
|
||||
register long i = HSIZE-8;
|
||||
|
||||
do {
|
||||
i -= 8;
|
||||
hp[-7].hash = -1;
|
||||
hp[-6].hash = -1;
|
||||
hp[-5].hash = -1;
|
||||
hp[-4].hash = -1;
|
||||
hp[-3].hash = -1;
|
||||
hp[-2].hash = -1;
|
||||
hp[-1].hash = -1;
|
||||
hp[ 0].hash = -1;
|
||||
hp -= 8;
|
||||
} while (i >= 0);
|
||||
for (i += 8; i > 0; i--, hp--)
|
||||
hp->hash = -1;
|
||||
}
|
||||
|
||||
static void
|
||||
LZWCleanup(TIFF* tif)
|
||||
{
|
||||
if (tif->tif_data) {
|
||||
if (tif->tif_mode == O_RDONLY) {
|
||||
if (DecoderState(tif)->dec_codetab)
|
||||
_TIFFfree(DecoderState(tif)->dec_codetab);
|
||||
} else {
|
||||
if (EncoderState(tif)->enc_hashtab)
|
||||
_TIFFfree(EncoderState(tif)->enc_hashtab);
|
||||
}
|
||||
_TIFFfree(tif->tif_data);
|
||||
tif->tif_data = NULL;
|
||||
}
|
||||
if (tif->tif_data) {
|
||||
if (DecoderState(tif)->dec_codetab)
|
||||
_TIFFfree(DecoderState(tif)->dec_codetab);
|
||||
_TIFFfree(tif->tif_data);
|
||||
tif->tif_data = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
LZWSetupEncode(TIFF* tif)
|
||||
{
|
||||
TIFFError(tif->tif_name,
|
||||
"LZW compression is not available to due to Unisys patent enforcement");
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
TIFFInitLZW(TIFF* tif, int scheme)
|
||||
{
|
||||
assert(scheme == COMPRESSION_LZW);
|
||||
|
||||
/*
|
||||
* Allocate state block so tag methods have storage to record values.
|
||||
*/
|
||||
if (tif->tif_mode == O_RDONLY) {
|
||||
tif->tif_data = (tidata_t) _TIFFmalloc(sizeof (LZWDecodeState));
|
||||
if (tif->tif_data == NULL)
|
||||
goto bad;
|
||||
DecoderState(tif)->dec_codetab = NULL;
|
||||
DecoderState(tif)->dec_decode = NULL;
|
||||
} else {
|
||||
tif->tif_data = (tidata_t) _TIFFmalloc(sizeof (LZWEncodeState));
|
||||
if (tif->tif_data == NULL)
|
||||
goto bad;
|
||||
EncoderState(tif)->enc_hashtab = NULL;
|
||||
}
|
||||
tif->tif_data = (tidata_t) _TIFFmalloc(sizeof (LZWCodecState));
|
||||
if (tif->tif_data == NULL)
|
||||
goto bad;
|
||||
DecoderState(tif)->dec_codetab = NULL;
|
||||
DecoderState(tif)->dec_decode = NULL;
|
||||
|
||||
/*
|
||||
* Install codec methods.
|
||||
*/
|
||||
tif->tif_setupencode = LZWSetupEncode;
|
||||
tif->tif_setupdecode = LZWSetupDecode;
|
||||
tif->tif_predecode = LZWPreDecode;
|
||||
tif->tif_decoderow = LZWDecode;
|
||||
tif->tif_decodestrip = LZWDecode;
|
||||
tif->tif_decodetile = LZWDecode;
|
||||
tif->tif_setupencode = LZWSetupEncode;
|
||||
tif->tif_preencode = LZWPreEncode;
|
||||
tif->tif_postencode = LZWPostEncode;
|
||||
tif->tif_encoderow = LZWEncode;
|
||||
tif->tif_encodestrip = LZWEncode;
|
||||
tif->tif_encodetile = LZWEncode;
|
||||
tif->tif_cleanup = LZWCleanup;
|
||||
|
||||
/*
|
||||
* Setup predictor setup.
|
||||
*/
|
||||
(void) TIFFPredictorInit(tif);
|
||||
|
||||
return (1);
|
||||
|
||||
bad:
|
||||
TIFFError("TIFFInitLZW", "No space for LZW state block");
|
||||
return (0);
|
||||
|
@@ -4,23 +4,23 @@
|
||||
* Copyright (c) 1988-1997 Sam Leffler
|
||||
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* its documentation for any purpose is hereby granted without fee, provided
|
||||
* that (i) the above copyright notices and this permission notice appear in
|
||||
* all copies of the software and related documentation, and (ii) the names of
|
||||
* Sam Leffler and Silicon Graphics may not be used in any advertising or
|
||||
* publicity relating to the software without the specific, prior written
|
||||
* permission of Sam Leffler and Silicon Graphics.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
|
||||
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
|
||||
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
||||
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
||||
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
#define SETPIXEL(op, v) { \
|
||||
switch (npixels++ & 3) { \
|
||||
case 0: op[0] = (v) << 6; break; \
|
||||
case 0: op[0] = (u_char) ((v) << 6); break; \
|
||||
case 1: op[0] |= (v) << 4; break; \
|
||||
case 2: op[0] |= (v) << 2; break; \
|
||||
case 3: *op++ |= (v); break; \
|
||||
@@ -45,7 +45,7 @@
|
||||
#define LITERALSPAN 0x40
|
||||
#define WHITE ((1<<2)-1)
|
||||
|
||||
static int LINKAGEMODE
|
||||
static int
|
||||
NeXTDecode(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
|
||||
{
|
||||
register u_char *bp, *op;
|
||||
@@ -87,7 +87,7 @@ NeXTDecode(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
|
||||
*/
|
||||
off = (bp[0] * 256) + bp[1];
|
||||
n = (bp[2] * 256) + bp[3];
|
||||
if (cc < 4+n)
|
||||
if (cc < 4+n || off+n > scanline)
|
||||
goto bad;
|
||||
_TIFFmemcpy(row+off, bp+4, n);
|
||||
bp += 4+n;
|
||||
@@ -111,7 +111,7 @@ NeXTDecode(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
|
||||
n &= 0x3f;
|
||||
while (n-- > 0)
|
||||
SETPIXEL(op, grey);
|
||||
if (npixels >= imagewidth)
|
||||
if (npixels >= (int) imagewidth)
|
||||
break;
|
||||
if (cc == 0)
|
||||
goto bad;
|
||||
|
@@ -4,23 +4,23 @@
|
||||
* Copyright (c) 1988-1997 Sam Leffler
|
||||
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* its documentation for any purpose is hereby granted without fee, provided
|
||||
* that (i) the above copyright notices and this permission notice appear in
|
||||
* all copies of the software and related documentation, and (ii) the names of
|
||||
* Sam Leffler and Silicon Graphics may not be used in any advertising or
|
||||
* publicity relating to the software without the specific, prior written
|
||||
* permission of Sam Leffler and Silicon Graphics.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
|
||||
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
|
||||
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
||||
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
||||
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
@@ -29,22 +29,22 @@
|
||||
*/
|
||||
#include "tiffiop.h"
|
||||
|
||||
void LINKAGEMODE _TIFFSetDefaultCompressionState(TIFF* tif);
|
||||
void _TIFFSetDefaultCompressionState(TIFF* tif);
|
||||
|
||||
static const long typemask[13] = {
|
||||
0L, /* TIFF_NOTYPE */
|
||||
0x000000ffL, /* TIFF_BYTE */
|
||||
0xffffffffL, /* TIFF_ASCII */
|
||||
0x0000ffffL, /* TIFF_SHORT */
|
||||
0xffffffffL, /* TIFF_LONG */
|
||||
0xffffffffL, /* TIFF_RATIONAL */
|
||||
0x000000ffL, /* TIFF_SBYTE */
|
||||
0x000000ffL, /* TIFF_UNDEFINED */
|
||||
0x0000ffffL, /* TIFF_SSHORT */
|
||||
0xffffffffL, /* TIFF_SLONG */
|
||||
0xffffffffL, /* TIFF_SRATIONAL */
|
||||
0xffffffffL, /* TIFF_FLOAT */
|
||||
0xffffffffL, /* TIFF_DOUBLE */
|
||||
(long)0L, /* TIFF_NOTYPE */
|
||||
(long)0x000000ffL, /* TIFF_BYTE */
|
||||
(long)0xffffffffL, /* TIFF_ASCII */
|
||||
(long)0x0000ffffL, /* TIFF_SHORT */
|
||||
(long)0xffffffffL, /* TIFF_LONG */
|
||||
(long)0xffffffffL, /* TIFF_RATIONAL */
|
||||
(long)0x000000ffL, /* TIFF_SBYTE */
|
||||
(long)0x000000ffL, /* TIFF_UNDEFINED */
|
||||
(long)0x0000ffffL, /* TIFF_SSHORT */
|
||||
(long)0xffffffffL, /* TIFF_SLONG */
|
||||
(long)0xffffffffL, /* TIFF_SRATIONAL */
|
||||
(long)0xffffffffL, /* TIFF_FLOAT */
|
||||
(long)0xffffffffL, /* TIFF_DOUBLE */
|
||||
};
|
||||
static const int bigTypeshift[13] = {
|
||||
0, /* TIFF_NOTYPE */
|
||||
@@ -156,6 +156,11 @@ TIFFClientOpen(
|
||||
tif->tif_curstrip = (tstrip_t) -1; /* invalid strip */
|
||||
tif->tif_row = (uint32) -1; /* read/write pre-increment */
|
||||
tif->tif_clientdata = clientdata;
|
||||
if (!readproc || !writeproc || !seekproc || !closeproc
|
||||
|| !sizeproc || !mapproc || !unmapproc) {
|
||||
TIFFError(module, "One of the client procedures are NULL pointer");
|
||||
goto bad3;
|
||||
}
|
||||
tif->tif_readproc = readproc;
|
||||
tif->tif_writeproc = writeproc;
|
||||
tif->tif_seekproc = seekproc;
|
||||
@@ -170,11 +175,12 @@ TIFFClientOpen(
|
||||
* a file is opened read-only.
|
||||
*/
|
||||
tif->tif_flags = FILLORDER_MSB2LSB;
|
||||
if (m == O_RDONLY)
|
||||
if (m == O_RDONLY )
|
||||
tif->tif_flags |= TIFF_MAPPED;
|
||||
|
||||
#ifdef STRIPCHOP_DEFAULT
|
||||
tif->tif_flags |= TIFF_MAPPED|STRIPCHOP_DEFAULT;
|
||||
#else
|
||||
tif->tif_flags |= TIFF_MAPPED;
|
||||
if (m == O_RDONLY || m == O_RDWR)
|
||||
tif->tif_flags |= STRIPCHOP_DEFAULT;
|
||||
#endif
|
||||
|
||||
{ union { int32 i; char c[4]; } u; u.i = 1; bigendian = u.c[0] == 0; }
|
||||
@@ -284,6 +290,15 @@ TIFFClientOpen(
|
||||
if (tif->tif_flags & TIFF_SWAB)
|
||||
TIFFSwabShort(&tif->tif_header.tiff_version);
|
||||
tif->tif_header.tiff_diroff = 0; /* filled in later */
|
||||
|
||||
/*
|
||||
* This seek shouldn't be necessary, but I have had some
|
||||
* crazy problems with a failed fseek() on Solaris leaving
|
||||
* the current file pointer out of whack when an fwrite()
|
||||
* is done.
|
||||
*/
|
||||
TIFFSeekFile( tif, 0, SEEK_SET );
|
||||
|
||||
if (!WriteOK(tif, &tif->tif_header, sizeof (TIFFHeader))) {
|
||||
TIFFError(name, "Error writing TIFF header");
|
||||
goto bad;
|
||||
@@ -298,6 +313,8 @@ TIFFClientOpen(
|
||||
if (!TIFFDefaultDirectory(tif))
|
||||
goto bad;
|
||||
tif->tif_diroff = 0;
|
||||
tif->tif_dirlist = NULL;
|
||||
tif->tif_dirnumber = 0;
|
||||
return (tif);
|
||||
}
|
||||
/*
|
||||
@@ -327,7 +344,7 @@ TIFFClientOpen(
|
||||
TIFFError(name,
|
||||
"Not a TIFF file, bad version number %d (0x%x)",
|
||||
tif->tif_header.tiff_version,
|
||||
tif->tif_header.tiff_version);
|
||||
tif->tif_header.tiff_version);
|
||||
goto bad;
|
||||
}
|
||||
tif->tif_flags |= TIFF_MYBUFFER;
|
||||
@@ -369,6 +386,7 @@ bad:
|
||||
return ((TIFF*)0);
|
||||
bad2:
|
||||
(void) (*closeproc)(clientdata);
|
||||
bad3:
|
||||
return ((TIFF*)0);
|
||||
}
|
||||
|
||||
|
@@ -4,23 +4,23 @@
|
||||
* Copyright (c) 1988-1997 Sam Leffler
|
||||
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* its documentation for any purpose is hereby granted without fee, provided
|
||||
* that (i) the above copyright notices and this permission notice appear in
|
||||
* all copies of the software and related documentation, and (ii) the names of
|
||||
* Sam Leffler and Silicon Graphics may not be used in any advertising or
|
||||
* publicity relating to the software without the specific, prior written
|
||||
* permission of Sam Leffler and Silicon Graphics.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
|
||||
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
|
||||
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
||||
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
||||
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
@@ -58,7 +58,7 @@ typedef unsigned char tidata;
|
||||
/*
|
||||
* Encode a run of pixels.
|
||||
*/
|
||||
static int LINKAGEMODE
|
||||
static int
|
||||
PackBitsEncode(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s)
|
||||
{
|
||||
u_char* bp = (u_char*) buf;
|
||||
@@ -109,16 +109,16 @@ PackBitsEncode(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s)
|
||||
state = RUN;
|
||||
if (n > 128) {
|
||||
*op++ = (tidata) -127;
|
||||
*op++ = b;
|
||||
*op++ = (tidataval_t) b;
|
||||
n -= 128;
|
||||
goto again;
|
||||
}
|
||||
*op++ = (tidataval_t)(-(n-1));
|
||||
*op++ = b;
|
||||
*op++ = (tidataval_t) b;
|
||||
} else {
|
||||
lastliteral = op;
|
||||
*op++ = 0;
|
||||
*op++ = b;
|
||||
*op++ = (tidataval_t) b;
|
||||
state = LITERAL;
|
||||
}
|
||||
break;
|
||||
@@ -127,32 +127,32 @@ PackBitsEncode(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s)
|
||||
state = LITERAL_RUN;
|
||||
if (n > 128) {
|
||||
*op++ = (tidata) -127;
|
||||
*op++ = b;
|
||||
*op++ = (tidataval_t) b;
|
||||
n -= 128;
|
||||
goto again;
|
||||
}
|
||||
*op++ = (tidataval_t)(-(n-1)); /* encode run */
|
||||
*op++ = b;
|
||||
*op++ = (tidataval_t) b;
|
||||
} else { /* extend literal */
|
||||
if (++(*lastliteral) == 127)
|
||||
state = BASE;
|
||||
*op++ = b;
|
||||
*op++ = (tidataval_t) b;
|
||||
}
|
||||
break;
|
||||
case RUN: /* last object was run */
|
||||
if (n > 1) {
|
||||
if (n > 128) {
|
||||
*op++ = (tidata) -127;
|
||||
*op++ = b;
|
||||
*op++ = (tidataval_t) b;
|
||||
n -= 128;
|
||||
goto again;
|
||||
}
|
||||
*op++ = (tidataval_t)(-(n-1));
|
||||
*op++ = b;
|
||||
*op++ = (tidataval_t) b;
|
||||
} else {
|
||||
lastliteral = op;
|
||||
*op++ = 0;
|
||||
*op++ = b;
|
||||
*op++ = (tidataval_t) b;
|
||||
state = LITERAL;
|
||||
}
|
||||
break;
|
||||
@@ -185,22 +185,46 @@ PackBitsEncode(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s)
|
||||
* the decoder if data is read, for example, by scanlines
|
||||
* when it was encoded by strips.
|
||||
*/
|
||||
static int LINKAGEMODE
|
||||
static int
|
||||
PackBitsEncodeChunk(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
|
||||
{
|
||||
#if defined(__hpux) && defined(__LP64__)
|
||||
tsize_t rowsize = (tsize_t)(unsigned long) tif->tif_data;
|
||||
#else
|
||||
tsize_t rowsize = (tsize_t) tif->tif_data;
|
||||
#endif
|
||||
|
||||
assert(rowsize > 0);
|
||||
|
||||
#ifdef YCBCR_SUPPORT
|
||||
/*
|
||||
* YCBCR data isn't really separable into rows, so we
|
||||
* might as well encode the whole tile/strip as one chunk.
|
||||
*/
|
||||
if( tif->tif_dir.td_photometric == PHOTOMETRIC_YCBCR ) {
|
||||
#if defined(__hpux) && defined(__LP64__)
|
||||
rowsize = (tsize_t)(unsigned long) tif->tif_data;
|
||||
#else
|
||||
rowsize = (tsize_t) tif->tif_data;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
while ((long)cc > 0) {
|
||||
if (PackBitsEncode(tif, bp, rowsize, s) < 0)
|
||||
return (-1);
|
||||
bp += rowsize;
|
||||
cc -= rowsize;
|
||||
int chunk = rowsize;
|
||||
|
||||
if( cc < chunk )
|
||||
chunk = cc;
|
||||
|
||||
if (PackBitsEncode(tif, bp, chunk, s) < 0)
|
||||
return (-1);
|
||||
bp += chunk;
|
||||
cc -= chunk;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
static int LINKAGEMODE
|
||||
static int
|
||||
PackBitsDecode(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
|
||||
{
|
||||
char *bp;
|
||||
@@ -222,13 +246,29 @@ PackBitsDecode(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
|
||||
if (n < 0) { /* replicate next byte -n+1 times */
|
||||
if (n == -128) /* nop */
|
||||
continue;
|
||||
n = -n + 1;
|
||||
n = -n + 1;
|
||||
if( occ < n )
|
||||
{
|
||||
TIFFWarning(tif->tif_name,
|
||||
"PackBitsDecode: discarding %d bytes "
|
||||
"to avoid buffer overrun",
|
||||
n - occ);
|
||||
n = occ;
|
||||
}
|
||||
occ -= n;
|
||||
b = *bp++, cc--;
|
||||
while (n-- > 0)
|
||||
*op++ = b;
|
||||
*op++ = (tidataval_t) b;
|
||||
} else { /* copy next n+1 bytes literally */
|
||||
_TIFFmemcpy(op, bp, ++n);
|
||||
if (occ < n + 1)
|
||||
{
|
||||
TIFFWarning(tif->tif_name,
|
||||
"PackBitsDecode: discarding %d bytes "
|
||||
"to avoid buffer overrun",
|
||||
n - occ + 1);
|
||||
n = occ - 1;
|
||||
}
|
||||
_TIFFmemcpy(op, bp, ++n);
|
||||
op += n; occ -= n;
|
||||
bp += n; cc -= n;
|
||||
}
|
||||
@@ -241,7 +281,6 @@ PackBitsDecode(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
|
||||
(long) tif->tif_row);
|
||||
return (0);
|
||||
}
|
||||
/* check for buffer overruns? */
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
@@ -84,15 +84,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/* Watcom C++ (or its make utility) doesn't like long filenames */
|
||||
#ifdef __WATCOMC__
|
||||
#include "tif_pred.h"
|
||||
#else
|
||||
#include "tif_predict.h"
|
||||
#endif
|
||||
|
||||
#include "zlib.h"
|
||||
#include "zutil.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
@@ -496,8 +489,7 @@ PixarLogMakeTables(PixarLogState *sp)
|
||||
|
||||
int nlin, lt2size;
|
||||
int i, j;
|
||||
double b, c, linstep, max;
|
||||
double k, v, dv, r, lr2, r2;
|
||||
double b, c, linstep, v;
|
||||
float *ToLinearF;
|
||||
uint16 *ToLinear16;
|
||||
unsigned char *ToLinear8;
|
||||
@@ -506,14 +498,14 @@ PixarLogMakeTables(PixarLogState *sp)
|
||||
uint16 *From8;
|
||||
|
||||
c = log(RATIO);
|
||||
nlin = 1./c; /* nlin must be an integer */
|
||||
nlin = (int)1./c; /* nlin must be an integer */
|
||||
c = 1./nlin;
|
||||
b = exp(-c*ONE); /* multiplicative scale factor [b*exp(c*ONE) = 1] */
|
||||
linstep = b*c*exp(1.);
|
||||
|
||||
LogK1 = 1./c; /* if (v >= 2) token = k1*log(v*k2) */
|
||||
LogK2 = 1./b;
|
||||
lt2size = (2./linstep)+1;
|
||||
lt2size = (int)(2./linstep) + 1;
|
||||
FromLT2 = (uint16 *)_TIFFmalloc(lt2size*sizeof(uint16));
|
||||
From14 = (uint16 *)_TIFFmalloc(16384*sizeof(uint16));
|
||||
From8 = (uint16 *)_TIFFmalloc(256*sizeof(uint16));
|
||||
@@ -551,9 +543,9 @@ PixarLogMakeTables(PixarLogState *sp)
|
||||
|
||||
for (i = 0; i < TSIZEP1; i++) {
|
||||
v = ToLinearF[i]*65535.0 + 0.5;
|
||||
ToLinear16[i] = (v > 65535.0) ? 65535 : v;
|
||||
ToLinear16[i] = (v > 65535.0) ? 65535 : (uint16)v;
|
||||
v = ToLinearF[i]*255.0 + 0.5;
|
||||
ToLinear8[i] = (v > 255.0) ? 255 : v;
|
||||
ToLinear8[i] = (v > 255.0) ? 255 : (unsigned char)v;
|
||||
}
|
||||
|
||||
j = 0;
|
||||
@@ -638,11 +630,23 @@ PixarLogGuessDataFmt(TIFFDirectory *td)
|
||||
return guess;
|
||||
}
|
||||
|
||||
static uint32
|
||||
multiply(size_t m1, size_t m2)
|
||||
{
|
||||
uint32 bytes = m1 * m2;
|
||||
|
||||
if (m1 && bytes / m1 != m2)
|
||||
bytes = 0;
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
static int
|
||||
PixarLogSetupDecode(TIFF* tif)
|
||||
{
|
||||
TIFFDirectory *td = &tif->tif_dir;
|
||||
PixarLogState* sp = DecoderState(tif);
|
||||
tsize_t tbuf_size;
|
||||
static const char module[] = "PixarLogSetupDecode";
|
||||
|
||||
assert(sp != NULL);
|
||||
@@ -655,8 +659,13 @@ PixarLogSetupDecode(TIFF* tif)
|
||||
|
||||
sp->stride = (td->td_planarconfig == PLANARCONFIG_CONTIG ?
|
||||
td->td_samplesperpixel : 1);
|
||||
sp->tbuf = (uint16 *) _TIFFmalloc(sp->stride *
|
||||
td->td_imagewidth * td->td_rowsperstrip * sizeof(uint16));
|
||||
tbuf_size = multiply(multiply(multiply(sp->stride, td->td_imagewidth),
|
||||
td->td_rowsperstrip), sizeof(uint16));
|
||||
if (tbuf_size == 0)
|
||||
return (0);
|
||||
sp->tbuf = (uint16 *) _TIFFmalloc(tbuf_size);
|
||||
if (sp->tbuf == NULL)
|
||||
return (0);
|
||||
if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN)
|
||||
sp->user_datafmt = PixarLogGuessDataFmt(td);
|
||||
if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN) {
|
||||
@@ -681,7 +690,6 @@ PixarLogSetupDecode(TIFF* tif)
|
||||
static int
|
||||
PixarLogPreDecode(TIFF* tif, tsample_t s)
|
||||
{
|
||||
TIFFDirectory *td = &tif->tif_dir;
|
||||
PixarLogState* sp = DecoderState(tif);
|
||||
|
||||
(void) s;
|
||||
@@ -807,6 +815,7 @@ PixarLogSetupEncode(TIFF* tif)
|
||||
{
|
||||
TIFFDirectory *td = &tif->tif_dir;
|
||||
PixarLogState* sp = EncoderState(tif);
|
||||
tsize_t tbuf_size;
|
||||
static const char module[] = "PixarLogSetupEncode";
|
||||
|
||||
assert(sp != NULL);
|
||||
@@ -815,8 +824,13 @@ PixarLogSetupEncode(TIFF* tif)
|
||||
|
||||
sp->stride = (td->td_planarconfig == PLANARCONFIG_CONTIG ?
|
||||
td->td_samplesperpixel : 1);
|
||||
sp->tbuf = (uint16 *) _TIFFmalloc(sp->stride *
|
||||
td->td_imagewidth * td->td_rowsperstrip * sizeof(uint16));
|
||||
tbuf_size = multiply(multiply(multiply(sp->stride, td->td_imagewidth),
|
||||
td->td_rowsperstrip), sizeof(uint16));
|
||||
if (tbuf_size == 0)
|
||||
return (0);
|
||||
sp->tbuf = (uint16 *) _TIFFmalloc(tbuf_size);
|
||||
if (sp->tbuf == NULL)
|
||||
return (0);
|
||||
if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN)
|
||||
sp->user_datafmt = PixarLogGuessDataFmt(td);
|
||||
if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN) {
|
||||
@@ -839,7 +853,6 @@ PixarLogSetupEncode(TIFF* tif)
|
||||
static int
|
||||
PixarLogPreEncode(TIFF* tif, tsample_t s)
|
||||
{
|
||||
TIFFDirectory *td = &tif->tif_dir;
|
||||
PixarLogState *sp = EncoderState(tif);
|
||||
|
||||
(void) s;
|
||||
@@ -1288,10 +1301,10 @@ TIFFInitPixarLog(TIFF* tif, int scheme)
|
||||
|
||||
/* Override SetField so we can handle our private pseudo-tag */
|
||||
_TIFFMergeFieldInfo(tif, pixarlogFieldInfo, N(pixarlogFieldInfo));
|
||||
sp->vgetparent = tif->tif_vgetfield;
|
||||
tif->tif_vgetfield = PixarLogVGetField; /* hook for codec tags */
|
||||
sp->vsetparent = tif->tif_vsetfield;
|
||||
tif->tif_vsetfield = PixarLogVSetField; /* hook for codec tags */
|
||||
sp->vgetparent = tif->tif_tagmethods.vgetfield;
|
||||
tif->tif_tagmethods.vgetfield = PixarLogVGetField; /* hook for codec tags */
|
||||
sp->vsetparent = tif->tif_tagmethods.vsetfield;
|
||||
tif->tif_tagmethods.vsetfield = PixarLogVSetField; /* hook for codec tags */
|
||||
|
||||
/* Default values for codec-specific fields */
|
||||
sp->quality = Z_DEFAULT_COMPRESSION; /* default comp. level */
|
||||
|
@@ -4,23 +4,23 @@
|
||||
* Copyright (c) 1988-1997 Sam Leffler
|
||||
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* its documentation for any purpose is hereby granted without fee, provided
|
||||
* that (i) the above copyright notices and this permission notice appear in
|
||||
* all copies of the software and related documentation, and (ii) the names of
|
||||
* Sam Leffler and Silicon Graphics may not be used in any advertising or
|
||||
* publicity relating to the software without the specific, prior written
|
||||
* permission of Sam Leffler and Silicon Graphics.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
|
||||
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
|
||||
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
||||
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
||||
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
@@ -30,26 +30,21 @@
|
||||
* Predictor Tag Support (used by multiple codecs).
|
||||
*/
|
||||
#include "tiffiop.h"
|
||||
/* Watcom C++ (or its make utility) doesn't like long filenames */
|
||||
#ifdef wxUSE_SHORTNAMES
|
||||
#include "tif_pred.h"
|
||||
#else
|
||||
#include "tif_predict.h"
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#define PredictorState(tif) ((TIFFPredictorState*) (tif)->tif_data)
|
||||
|
||||
static void LINKAGEMODE horAcc8(TIFF*, tidata_t, tsize_t);
|
||||
static void LINKAGEMODE horAcc16(TIFF*, tidata_t, tsize_t);
|
||||
static void LINKAGEMODE swabHorAcc16(TIFF*, tidata_t, tsize_t);
|
||||
static void LINKAGEMODE horDiff8(TIFF*, tidata_t, tsize_t);
|
||||
static void LINKAGEMODE horDiff16(TIFF*, tidata_t, tsize_t);
|
||||
static int LINKAGEMODE PredictorDecodeRow(TIFF*, tidata_t, tsize_t, tsample_t);
|
||||
static int LINKAGEMODE PredictorDecodeTile(TIFF*, tidata_t, tsize_t, tsample_t);
|
||||
static int LINKAGEMODE PredictorEncodeRow(TIFF*, tidata_t, tsize_t, tsample_t);
|
||||
static int LINKAGEMODE PredictorEncodeTile(TIFF*, tidata_t, tsize_t, tsample_t);
|
||||
static void horAcc8(TIFF*, tidata_t, tsize_t);
|
||||
static void horAcc16(TIFF*, tidata_t, tsize_t);
|
||||
static void swabHorAcc16(TIFF*, tidata_t, tsize_t);
|
||||
static void horDiff8(TIFF*, tidata_t, tsize_t);
|
||||
static void horDiff16(TIFF*, tidata_t, tsize_t);
|
||||
static int PredictorDecodeRow(TIFF*, tidata_t, tsize_t, tsample_t);
|
||||
static int PredictorDecodeTile(TIFF*, tidata_t, tsize_t, tsample_t);
|
||||
static int PredictorEncodeRow(TIFF*, tidata_t, tsize_t, tsample_t);
|
||||
static int PredictorEncodeTile(TIFF*, tidata_t, tsize_t, tsample_t);
|
||||
|
||||
static int
|
||||
PredictorSetup(TIFF* tif)
|
||||
@@ -165,7 +160,7 @@ static void
|
||||
horAcc8(TIFF* tif, tidata_t cp0, tsize_t cc)
|
||||
{
|
||||
TIFFPredictorState* sp = PredictorState(tif);
|
||||
u_int stride = sp->stride;
|
||||
tsize_t stride = sp->stride;
|
||||
|
||||
char* cp = (char*) cp0;
|
||||
if (cc > stride) {
|
||||
@@ -179,9 +174,9 @@ horAcc8(TIFF* tif, tidata_t cp0, tsize_t cc)
|
||||
u_int cb = cp[2];
|
||||
do {
|
||||
cc -= 3, cp += 3;
|
||||
cp[0] = (cr += cp[0]);
|
||||
cp[1] = (cg += cp[1]);
|
||||
cp[2] = (cb += cp[2]);
|
||||
cp[0] = (char) (cr += cp[0]);
|
||||
cp[1] = (char) (cg += cp[1]);
|
||||
cp[2] = (char) (cb += cp[2]);
|
||||
} while ((int32) cc > 0);
|
||||
} else if (stride == 4) {
|
||||
u_int cr = cp[0];
|
||||
@@ -190,14 +185,14 @@ horAcc8(TIFF* tif, tidata_t cp0, tsize_t cc)
|
||||
u_int ca = cp[3];
|
||||
do {
|
||||
cc -= 4, cp += 4;
|
||||
cp[0] = (cr += cp[0]);
|
||||
cp[1] = (cg += cp[1]);
|
||||
cp[2] = (cb += cp[2]);
|
||||
cp[3] = (ca += cp[3]);
|
||||
cp[0] = (char) (cr += cp[0]);
|
||||
cp[1] = (char) (cg += cp[1]);
|
||||
cp[2] = (char) (cb += cp[2]);
|
||||
cp[3] = (char) (ca += cp[3]);
|
||||
} while ((int32) cc > 0);
|
||||
} else {
|
||||
do {
|
||||
REPEAT4(stride, cp[stride] += *cp; cp++)
|
||||
REPEAT4(stride, cp[stride] = (char) (cp[stride] + *cp); cp++)
|
||||
cc -= stride;
|
||||
} while ((int32) cc > 0);
|
||||
}
|
||||
@@ -208,7 +203,7 @@ static void
|
||||
swabHorAcc16(TIFF* tif, tidata_t cp0, tsize_t cc)
|
||||
{
|
||||
TIFFPredictorState* sp = PredictorState(tif);
|
||||
u_int stride = sp->stride;
|
||||
tsize_t stride = sp->stride;
|
||||
uint16* wp = (uint16*) cp0;
|
||||
tsize_t wc = cc / 2;
|
||||
|
||||
@@ -225,7 +220,7 @@ swabHorAcc16(TIFF* tif, tidata_t cp0, tsize_t cc)
|
||||
static void
|
||||
horAcc16(TIFF* tif, tidata_t cp0, tsize_t cc)
|
||||
{
|
||||
u_int stride = PredictorState(tif)->stride;
|
||||
tsize_t stride = PredictorState(tif)->stride;
|
||||
uint16* wp = (uint16*) cp0;
|
||||
tsize_t wc = cc / 2;
|
||||
|
||||
@@ -288,7 +283,7 @@ static void
|
||||
horDiff8(TIFF* tif, tidata_t cp0, tsize_t cc)
|
||||
{
|
||||
TIFFPredictorState* sp = PredictorState(tif);
|
||||
u_int stride = sp->stride;
|
||||
tsize_t stride = sp->stride;
|
||||
char* cp = (char*) cp0;
|
||||
|
||||
if (cc > stride) {
|
||||
@@ -333,7 +328,7 @@ static void
|
||||
horDiff16(TIFF* tif, tidata_t cp0, tsize_t cc)
|
||||
{
|
||||
TIFFPredictorState* sp = PredictorState(tif);
|
||||
u_int stride = sp->stride;
|
||||
tsize_t stride = sp->stride;
|
||||
int16 *wp = (int16*) cp0;
|
||||
tsize_t wc = cc/2;
|
||||
|
||||
@@ -420,7 +415,7 @@ PredictorVGetField(TIFF* tif, ttag_t tag, va_list ap)
|
||||
return (1);
|
||||
}
|
||||
|
||||
static void LINKAGEMODE
|
||||
static void
|
||||
PredictorPrintDir(TIFF* tif, FILE* fd, long flags)
|
||||
{
|
||||
TIFFPredictorState* sp = PredictorState(tif);
|
||||
@@ -448,12 +443,15 @@ TIFFPredictorInit(TIFF* tif)
|
||||
* override parent get/set field methods.
|
||||
*/
|
||||
_TIFFMergeFieldInfo(tif, predictFieldInfo, N(predictFieldInfo));
|
||||
sp->vgetparent = tif->tif_vgetfield;
|
||||
tif->tif_vgetfield = PredictorVGetField;/* hook for predictor tag */
|
||||
sp->vsetparent = tif->tif_vsetfield;
|
||||
tif->tif_vsetfield = PredictorVSetField;/* hook for predictor tag */
|
||||
sp->printdir = tif->tif_printdir;
|
||||
tif->tif_printdir = PredictorPrintDir; /* hook for predictor tag */
|
||||
sp->vgetparent = tif->tif_tagmethods.vgetfield;
|
||||
tif->tif_tagmethods.vgetfield =
|
||||
PredictorVGetField;/* hook for predictor tag */
|
||||
sp->vsetparent = tif->tif_tagmethods.vsetfield;
|
||||
tif->tif_tagmethods.vsetfield =
|
||||
PredictorVSetField;/* hook for predictor tag */
|
||||
sp->printdir = tif->tif_tagmethods.printdir;
|
||||
tif->tif_tagmethods.printdir =
|
||||
PredictorPrintDir; /* hook for predictor tag */
|
||||
|
||||
sp->setupdecode = tif->tif_setupdecode;
|
||||
tif->tif_setupdecode = PredictorSetupDecode;
|
||||
|
@@ -72,7 +72,7 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags)
|
||||
uint16 i;
|
||||
long l, n;
|
||||
|
||||
fprintf(fd, "TIFF Directory at offset 0x%lx\n", (long) tif->tif_diroff);
|
||||
fprintf(fd, "TIFF Directory at offset 0x%lx\n", tif->tif_diroff);
|
||||
td = &tif->tif_dir;
|
||||
if (TIFFFieldSet(tif,FIELD_SUBFILETYPE)) {
|
||||
fprintf(fd, " Subfile Type:");
|
||||
@@ -98,6 +98,42 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags)
|
||||
(u_long) td->td_imagedepth);
|
||||
fprintf(fd, "\n");
|
||||
}
|
||||
|
||||
/* Begin Pixar */
|
||||
if (TIFFFieldSet(tif,FIELD_IMAGEFULLWIDTH) ||
|
||||
TIFFFieldSet(tif,FIELD_IMAGEFULLLENGTH)) {
|
||||
fprintf(fd, " Pixar Full Image Width: %lu Full Image Length: %lu\n",
|
||||
(u_long) td->td_imagefullwidth,
|
||||
(u_long) td->td_imagefulllength);
|
||||
}
|
||||
if (TIFFFieldSet(tif,FIELD_TEXTUREFORMAT))
|
||||
_TIFFprintAsciiTag(fd, "Texture Format", td->td_textureformat);
|
||||
if (TIFFFieldSet(tif,FIELD_WRAPMODES))
|
||||
_TIFFprintAsciiTag(fd, "Texture Wrap Modes", td->td_wrapmodes);
|
||||
if (TIFFFieldSet(tif,FIELD_FOVCOT))
|
||||
fprintf(fd, " Field of View Cotangent: %g\n", td->td_fovcot);
|
||||
if (TIFFFieldSet(tif,FIELD_MATRIX_WORLDTOSCREEN)) {
|
||||
typedef float Matrix[4][4];
|
||||
Matrix* m = (Matrix*)td->td_matrixWorldToScreen;
|
||||
|
||||
fprintf(fd, " Matrix NP:\n\t%g %g %g %g\n\t%g %g %g %g\n\t%g %g %g %g\n\t%g %g %g %g\n",
|
||||
(*m)[0][0], (*m)[0][1], (*m)[0][2], (*m)[0][3],
|
||||
(*m)[1][0], (*m)[1][1], (*m)[1][2], (*m)[1][3],
|
||||
(*m)[2][0], (*m)[2][1], (*m)[2][2], (*m)[2][3],
|
||||
(*m)[3][0], (*m)[3][1], (*m)[3][2], (*m)[3][3]);
|
||||
}
|
||||
if (TIFFFieldSet(tif,FIELD_MATRIX_WORLDTOCAMERA)) {
|
||||
typedef float Matrix[4][4];
|
||||
Matrix* m = (Matrix*)td->td_matrixWorldToCamera;
|
||||
|
||||
fprintf(fd, " Matrix Nl:\n\t%g %g %g %g\n\t%g %g %g %g\n\t%g %g %g %g\n\t%g %g %g %g\n",
|
||||
(*m)[0][0], (*m)[0][1], (*m)[0][2], (*m)[0][3],
|
||||
(*m)[1][0], (*m)[1][1], (*m)[1][2], (*m)[1][3],
|
||||
(*m)[2][0], (*m)[2][1], (*m)[2][2], (*m)[2][3],
|
||||
(*m)[3][0], (*m)[3][1], (*m)[3][2], (*m)[3][3]);
|
||||
}
|
||||
/* End Pixar */
|
||||
|
||||
if (TIFFFieldSet(tif,FIELD_TILEDIMENSIONS)) {
|
||||
fprintf(fd, " Tile Width: %lu Tile Length: %lu",
|
||||
(u_long) td->td_tilewidth, (u_long) td->td_tilelength);
|
||||
@@ -149,6 +185,12 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags)
|
||||
case SAMPLEFORMAT_IEEEFP:
|
||||
fprintf(fd, "IEEE floating point\n");
|
||||
break;
|
||||
case SAMPLEFORMAT_COMPLEXINT:
|
||||
fprintf(fd, "complex signed integer\n");
|
||||
break;
|
||||
case SAMPLEFORMAT_COMPLEXIEEEFP:
|
||||
fprintf(fd, "complex IEEE floating point\n");
|
||||
break;
|
||||
default:
|
||||
fprintf(fd, "%u (0x%x)\n",
|
||||
td->td_sampleformat, td->td_sampleformat);
|
||||
@@ -277,8 +319,19 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags)
|
||||
}
|
||||
#ifdef YCBCR_SUPPORT
|
||||
if (TIFFFieldSet(tif,FIELD_YCBCRSUBSAMPLING))
|
||||
{
|
||||
/*
|
||||
* For hacky reasons (see tif_jpeg.c - JPEGFixupTestSubsampling),
|
||||
* we need to fetch this rather than trust what is in our
|
||||
* structures.
|
||||
*/
|
||||
uint16 subsampling[2];
|
||||
|
||||
TIFFGetField( tif, TIFFTAG_YCBCRSUBSAMPLING,
|
||||
subsampling + 0, subsampling + 1 );
|
||||
fprintf(fd, " YCbCr Subsampling: %u, %u\n",
|
||||
td->td_ycbcrsubsampling[0], td->td_ycbcrsubsampling[1]);
|
||||
subsampling[0], subsampling[1] );
|
||||
}
|
||||
if (TIFFFieldSet(tif,FIELD_YCBCRPOSITIONING)) {
|
||||
fprintf(fd, " YCbCr Positioning: ");
|
||||
switch (td->td_ycbcrpositioning) {
|
||||
@@ -309,8 +362,8 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags)
|
||||
_TIFFprintAsciiTag(fd, "Date & Time", td->td_datetime);
|
||||
if (TIFFFieldSet(tif,FIELD_HOSTCOMPUTER))
|
||||
_TIFFprintAsciiTag(fd, "Host Computer", td->td_hostcomputer);
|
||||
if (TIFFFieldSet(tif,FIELD_SOFTWARE))
|
||||
_TIFFprintAsciiTag(fd, "Software", td->td_software);
|
||||
if (TIFFFieldSet(tif,FIELD_COPYRIGHT))
|
||||
_TIFFprintAsciiTag(fd, "Copyright", td->td_copyright);
|
||||
if (TIFFFieldSet(tif,FIELD_DOCUMENTNAME))
|
||||
_TIFFprintAsciiTag(fd, "Document Name", td->td_documentname);
|
||||
if (TIFFFieldSet(tif,FIELD_IMAGEDESCRIPTION))
|
||||
@@ -437,8 +490,85 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags)
|
||||
fputc('\n', fd);
|
||||
}
|
||||
#endif
|
||||
if (tif->tif_printdir)
|
||||
(*tif->tif_printdir)(tif, fd, flags);
|
||||
/*
|
||||
** Custom tag support.
|
||||
*/
|
||||
{
|
||||
int i;
|
||||
short count;
|
||||
|
||||
count = (short) TIFFGetTagListCount( tif );
|
||||
for( i = 0; i < count; i++ )
|
||||
{
|
||||
ttag_t tag = TIFFGetTagListEntry( tif, i );
|
||||
const TIFFFieldInfo *fld;
|
||||
|
||||
fld = TIFFFieldWithTag( tif, tag );
|
||||
if( fld == NULL )
|
||||
continue;
|
||||
|
||||
if( fld->field_passcount )
|
||||
{
|
||||
short value_count;
|
||||
int j;
|
||||
void *raw_data;
|
||||
|
||||
if( TIFFGetField( tif, tag, &value_count, &raw_data ) != 1 )
|
||||
continue;
|
||||
|
||||
fprintf(fd, " %s: ", fld->field_name );
|
||||
|
||||
for( j = 0; j < value_count; j++ )
|
||||
{
|
||||
if( fld->field_type == TIFF_BYTE )
|
||||
fprintf( fd, "%d",
|
||||
(int) ((char *) raw_data)[j] );
|
||||
else if( fld->field_type == TIFF_SHORT )
|
||||
fprintf( fd, "%d",
|
||||
(int) ((short *) raw_data)[j] );
|
||||
else if( fld->field_type == TIFF_LONG )
|
||||
fprintf( fd, "%d",
|
||||
(int) ((long *) raw_data)[j] );
|
||||
else if( fld->field_type == TIFF_RATIONAL )
|
||||
fprintf( fd, "%f",
|
||||
((float *) raw_data)[j] );
|
||||
else if( fld->field_type == TIFF_ASCII )
|
||||
{
|
||||
fprintf( fd, "%s",
|
||||
(char *) raw_data );
|
||||
break;
|
||||
}
|
||||
else if( fld->field_type == TIFF_DOUBLE )
|
||||
fprintf( fd, "%f",
|
||||
((double *) raw_data)[j] );
|
||||
else if( fld->field_type == TIFF_FLOAT )
|
||||
fprintf( fd, "%f",
|
||||
((float *) raw_data)[j] );
|
||||
else
|
||||
{
|
||||
fprintf( fd,
|
||||
"<unsupported data type in TIFFPrint>" );
|
||||
break;
|
||||
}
|
||||
|
||||
if( j < value_count-1 )
|
||||
fprintf( fd, "," );
|
||||
}
|
||||
fprintf( fd, "\n" );
|
||||
}
|
||||
else if( !fld->field_passcount
|
||||
&& fld->field_type == TIFF_ASCII )
|
||||
{
|
||||
char *data;
|
||||
|
||||
if( TIFFGetField( tif, tag, &data ) )
|
||||
fprintf(fd, " %s: %s\n", fld->field_name, data );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tif->tif_tagmethods.printdir)
|
||||
(*tif->tif_tagmethods.printdir)(tif, fd, flags);
|
||||
if ((flags & TIFFPRINT_STRIPS) &&
|
||||
TIFFFieldSet(tif,FIELD_STRIPOFFSETS)) {
|
||||
tstrip_t s;
|
||||
@@ -460,7 +590,7 @@ _TIFFprintAscii(FILE* fd, const char* cp)
|
||||
for (; *cp != '\0'; cp++) {
|
||||
const char* tp;
|
||||
|
||||
if (isprint((int)*cp)) {
|
||||
if (isprint(*cp)) {
|
||||
fputc(*cp, fd);
|
||||
continue;
|
||||
}
|
||||
|
@@ -32,8 +32,8 @@
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
static int TIFFFillStrip(TIFF*, tstrip_t);
|
||||
static int TIFFFillTile(TIFF*, ttile_t);
|
||||
int TIFFFillStrip(TIFF*, tstrip_t);
|
||||
int TIFFFillTile(TIFF*, ttile_t);
|
||||
static int TIFFStartStrip(TIFF*, tstrip_t);
|
||||
static int TIFFStartTile(TIFF*, ttile_t);
|
||||
static int TIFFCheckRead(TIFF*, int);
|
||||
@@ -104,7 +104,10 @@ TIFFReadScanline(TIFF* tif, tdata_t buf, uint32 row, tsample_t sample)
|
||||
*/
|
||||
e = (*tif->tif_decoderow)
|
||||
(tif, (tidata_t) buf, tif->tif_scanlinesize, sample);
|
||||
tif->tif_row++;
|
||||
|
||||
/* we are now poised at the beginning of the next row */
|
||||
tif->tif_row = row + 1;
|
||||
|
||||
if (e)
|
||||
(*tif->tif_postdecode)(tif, (tidata_t) buf,
|
||||
tif->tif_scanlinesize);
|
||||
@@ -122,6 +125,7 @@ TIFFReadEncodedStrip(TIFF* tif, tstrip_t strip, tdata_t buf, tsize_t size)
|
||||
TIFFDirectory *td = &tif->tif_dir;
|
||||
uint32 nrows;
|
||||
tsize_t stripsize;
|
||||
tstrip_t sep_strip, strips_per_sep;
|
||||
|
||||
if (!TIFFCheckRead(tif, 0))
|
||||
return (-1);
|
||||
@@ -132,18 +136,29 @@ TIFFReadEncodedStrip(TIFF* tif, tstrip_t strip, tdata_t buf, tsize_t size)
|
||||
}
|
||||
/*
|
||||
* Calculate the strip size according to the number of
|
||||
* rows in the strip (check for truncated last strip).
|
||||
* rows in the strip (check for truncated last strip on any
|
||||
* of the separations).
|
||||
*/
|
||||
if (strip != td->td_nstrips-1 ||
|
||||
if( td->td_rowsperstrip >= td->td_imagelength )
|
||||
strips_per_sep = 1;
|
||||
else
|
||||
strips_per_sep = (td->td_imagelength+td->td_rowsperstrip-1)
|
||||
/ td->td_rowsperstrip;
|
||||
|
||||
sep_strip = strip % strips_per_sep;
|
||||
|
||||
if (sep_strip != strips_per_sep-1 ||
|
||||
(nrows = td->td_imagelength % td->td_rowsperstrip) == 0)
|
||||
nrows = td->td_rowsperstrip;
|
||||
|
||||
stripsize = TIFFVStripSize(tif, nrows);
|
||||
if (size == (tsize_t) -1)
|
||||
size = stripsize;
|
||||
else if (size > stripsize)
|
||||
size = stripsize;
|
||||
if (TIFFFillStrip(tif, strip) && (*tif->tif_decodestrip)(tif,
|
||||
(tidata_t) buf, size, (tsample_t)(strip / td->td_stripsperimage))) {
|
||||
if (TIFFFillStrip(tif, strip)
|
||||
&& (*tif->tif_decodestrip)(tif, (tidata_t) buf, size,
|
||||
(tsample_t)(strip / td->td_stripsperimage)) > 0 ) {
|
||||
(*tif->tif_postdecode)(tif, (tidata_t) buf, size);
|
||||
return (size);
|
||||
} else
|
||||
@@ -226,7 +241,7 @@ TIFFReadRawStrip(TIFF* tif, tstrip_t strip, tdata_t buf, tsize_t size)
|
||||
* The data buffer is expanded, as necessary, to
|
||||
* hold the strip's data.
|
||||
*/
|
||||
static int
|
||||
int
|
||||
TIFFFillStrip(TIFF* tif, tstrip_t strip)
|
||||
{
|
||||
static const char module[] = "TIFFFillStrip";
|
||||
@@ -256,7 +271,7 @@ TIFFFillStrip(TIFF* tif, tstrip_t strip)
|
||||
if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata)
|
||||
_TIFFfree(tif->tif_rawdata);
|
||||
tif->tif_flags &= ~TIFF_MYBUFFER;
|
||||
if (td->td_stripoffset[strip] + bytecount > tif->tif_size) {
|
||||
if ( td->td_stripoffset[strip] + bytecount > tif->tif_size) {
|
||||
/*
|
||||
* This error message might seem strange, but it's
|
||||
* what would happen if a read were done instead.
|
||||
@@ -423,7 +438,7 @@ TIFFReadRawTile(TIFF* tif, ttile_t tile, tdata_t buf, tsize_t size)
|
||||
* The data buffer is expanded, as necessary, to
|
||||
* hold the tile's data.
|
||||
*/
|
||||
static int
|
||||
int
|
||||
TIFFFillTile(TIFF* tif, ttile_t tile)
|
||||
{
|
||||
static const char module[] = "TIFFFillTile";
|
||||
@@ -453,7 +468,7 @@ TIFFFillTile(TIFF* tif, ttile_t tile)
|
||||
if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata)
|
||||
_TIFFfree(tif->tif_rawdata);
|
||||
tif->tif_flags &= ~TIFF_MYBUFFER;
|
||||
if (td->td_stripoffset[tile] + bytecount > tif->tif_size) {
|
||||
if ( td->td_stripoffset[tile] + bytecount > tif->tif_size) {
|
||||
tif->tif_curtile = NOTILE;
|
||||
return (0);
|
||||
}
|
||||
|
@@ -31,6 +31,32 @@
|
||||
*/
|
||||
#include "tiffiop.h"
|
||||
|
||||
static uint32
|
||||
summarize(TIFF* tif, size_t summand1, size_t summand2, const char* where)
|
||||
{
|
||||
uint32 bytes = summand1 + summand2;
|
||||
|
||||
if (bytes - summand1 != summand2) {
|
||||
TIFFError(tif->tif_name, "Integer overflow in %s", where);
|
||||
bytes = 0;
|
||||
}
|
||||
|
||||
return (bytes);
|
||||
}
|
||||
|
||||
static uint32
|
||||
multiply(TIFF* tif, size_t nmemb, size_t elem_size, const char* where)
|
||||
{
|
||||
uint32 bytes = nmemb * elem_size;
|
||||
|
||||
if (elem_size && bytes / elem_size != nmemb) {
|
||||
TIFFError(tif->tif_name, "Integer overflow in %s", where);
|
||||
bytes = 0;
|
||||
}
|
||||
|
||||
return (bytes);
|
||||
}
|
||||
|
||||
/*
|
||||
* Compute which strip a (row,sample) value is in.
|
||||
*/
|
||||
@@ -66,7 +92,8 @@ TIFFNumberOfStrips(TIFF* tif)
|
||||
(td->td_imagelength != 0 ? 1 : 0) :
|
||||
TIFFhowmany(td->td_imagelength, td->td_rowsperstrip));
|
||||
if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
|
||||
nstrips *= td->td_samplesperpixel;
|
||||
nstrips = multiply(tif, nstrips, td->td_samplesperpixel,
|
||||
"TIFFNumberOfStrips");
|
||||
return (nstrips);
|
||||
}
|
||||
|
||||
@@ -92,18 +119,48 @@ TIFFVStripSize(TIFF* tif, uint32 nrows)
|
||||
* horizontal/vertical subsampling area include
|
||||
* YCbCr data for the extended image.
|
||||
*/
|
||||
tsize_t w =
|
||||
TIFFroundup(td->td_imagewidth, td->td_ycbcrsubsampling[0]);
|
||||
tsize_t scanline = TIFFhowmany(w*td->td_bitspersample, 8);
|
||||
tsize_t samplingarea =
|
||||
td->td_ycbcrsubsampling[0]*td->td_ycbcrsubsampling[1];
|
||||
nrows = TIFFroundup(nrows, td->td_ycbcrsubsampling[1]);
|
||||
uint16 ycbcrsubsampling[2];
|
||||
tsize_t w, scanline, samplingarea;
|
||||
|
||||
TIFFGetField( tif, TIFFTAG_YCBCRSUBSAMPLING,
|
||||
ycbcrsubsampling + 0,
|
||||
ycbcrsubsampling + 1 );
|
||||
|
||||
w = TIFFroundup(td->td_imagewidth, ycbcrsubsampling[0]);
|
||||
scanline = TIFFhowmany8(multiply(tif, w, td->td_bitspersample,
|
||||
"TIFFVStripSize"));
|
||||
samplingarea = ycbcrsubsampling[0]*ycbcrsubsampling[1];
|
||||
nrows = TIFFroundup(nrows, ycbcrsubsampling[1]);
|
||||
/* NB: don't need TIFFhowmany here 'cuz everything is rounded */
|
||||
scanline = multiply(tif, nrows, scanline, "TIFFVStripSize");
|
||||
return ((tsize_t)
|
||||
(nrows*scanline + 2*(nrows*scanline / samplingarea)));
|
||||
summarize(tif, scanline,
|
||||
multiply(tif, 2, scanline / samplingarea,
|
||||
"TIFFVStripSize"), "TIFFVStripSize"));
|
||||
} else
|
||||
#endif
|
||||
return ((tsize_t)(nrows * TIFFScanlineSize(tif)));
|
||||
return ((tsize_t) multiply(tif, nrows, TIFFScanlineSize(tif),
|
||||
"TIFFVStripSize"));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Compute the # bytes in a raw strip.
|
||||
*/
|
||||
tsize_t
|
||||
TIFFRawStripSize(TIFF* tif, tstrip_t strip)
|
||||
{
|
||||
TIFFDirectory* td = &tif->tif_dir;
|
||||
tsize_t bytecount = td->td_stripbytecount[strip];
|
||||
|
||||
if (bytecount <= 0) {
|
||||
TIFFError(tif->tif_name,
|
||||
"%lu: Invalid strip byte count, strip %lu",
|
||||
(u_long) bytecount, (u_long) strip);
|
||||
bytecount = (tsize_t) -1;
|
||||
}
|
||||
|
||||
return bytecount;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -164,10 +221,12 @@ TIFFScanlineSize(TIFF* tif)
|
||||
TIFFDirectory *td = &tif->tif_dir;
|
||||
tsize_t scanline;
|
||||
|
||||
scanline = td->td_bitspersample * td->td_imagewidth;
|
||||
scanline = multiply (tif, td->td_bitspersample, td->td_imagewidth,
|
||||
"TIFFScanlineSize");
|
||||
if (td->td_planarconfig == PLANARCONFIG_CONTIG)
|
||||
scanline *= td->td_samplesperpixel;
|
||||
return ((tsize_t) TIFFhowmany(scanline, 8));
|
||||
scanline = multiply (tif, scanline, td->td_samplesperpixel,
|
||||
"TIFFScanlineSize");
|
||||
return ((tsize_t) TIFFhowmany8(scanline));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -182,11 +241,14 @@ TIFFRasterScanlineSize(TIFF* tif)
|
||||
TIFFDirectory *td = &tif->tif_dir;
|
||||
tsize_t scanline;
|
||||
|
||||
scanline = td->td_bitspersample * td->td_imagewidth;
|
||||
scanline = multiply (tif, td->td_bitspersample, td->td_imagewidth,
|
||||
"TIFFRasterScanlineSize");
|
||||
if (td->td_planarconfig == PLANARCONFIG_CONTIG) {
|
||||
scanline *= td->td_samplesperpixel;
|
||||
return ((tsize_t) TIFFhowmany(scanline, 8));
|
||||
scanline = multiply (tif, scanline, td->td_samplesperpixel,
|
||||
"TIFFRasterScanlineSize");
|
||||
return ((tsize_t) TIFFhowmany8(scanline));
|
||||
} else
|
||||
return ((tsize_t)
|
||||
TIFFhowmany(scanline, 8)*td->td_samplesperpixel);
|
||||
return ((tsize_t) multiply (tif, TIFFhowmany8(scanline),
|
||||
td->td_samplesperpixel,
|
||||
"TIFFRasterScanlineSize"));
|
||||
}
|
||||
|
@@ -36,7 +36,7 @@ void
|
||||
TIFFSwabShort(uint16* wp)
|
||||
{
|
||||
register u_char* cp = (u_char*) wp;
|
||||
int t;
|
||||
u_char t;
|
||||
|
||||
t = cp[1]; cp[1] = cp[0]; cp[0] = t;
|
||||
}
|
||||
@@ -47,7 +47,7 @@ void
|
||||
TIFFSwabLong(uint32* lp)
|
||||
{
|
||||
register u_char* cp = (u_char*) lp;
|
||||
int t;
|
||||
u_char t;
|
||||
|
||||
t = cp[3]; cp[3] = cp[0]; cp[0] = t;
|
||||
t = cp[2]; cp[2] = cp[1]; cp[1] = t;
|
||||
@@ -59,7 +59,7 @@ void
|
||||
TIFFSwabArrayOfShort(uint16* wp, register u_long n)
|
||||
{
|
||||
register u_char* cp;
|
||||
register int t;
|
||||
register u_char t;
|
||||
|
||||
/* XXX unroll loop some */
|
||||
while (n-- > 0) {
|
||||
@@ -75,7 +75,7 @@ void
|
||||
TIFFSwabArrayOfLong(register uint32* lp, register u_long n)
|
||||
{
|
||||
register unsigned char *cp;
|
||||
register int t;
|
||||
register unsigned char t;
|
||||
|
||||
/* XXX unroll loop some */
|
||||
while (n-- > 0) {
|
||||
|
@@ -4,23 +4,23 @@
|
||||
* Copyright (c) 1988-1997 Sam Leffler
|
||||
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* its documentation for any purpose is hereby granted without fee, provided
|
||||
* that (i) the above copyright notices and this permission notice appear in
|
||||
* all copies of the software and related documentation, and (ii) the names of
|
||||
* Sam Leffler and Silicon Graphics may not be used in any advertising or
|
||||
* publicity relating to the software without the specific, prior written
|
||||
* permission of Sam Leffler and Silicon Graphics.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
|
||||
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
|
||||
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
||||
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
||||
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
@@ -60,7 +60,7 @@ static const int threebitdeltas[8] = { 0, 1, 2, 3, 0, -3, -2, -1 };
|
||||
if (npixels++ & 1) \
|
||||
*op++ |= lastpixel; \
|
||||
else \
|
||||
op[0] = lastpixel << 4; \
|
||||
op[0] = (tidataval_t) (lastpixel << 4); \
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -91,8 +91,10 @@ ThunderDecode(TIFF* tif, tidata_t op, tsize_t maxpixels)
|
||||
} else
|
||||
lastpixel |= lastpixel << 4;
|
||||
npixels += n;
|
||||
for (; n > 0; n -= 2)
|
||||
*op++ = lastpixel;
|
||||
if (npixels < maxpixels) {
|
||||
for (; n > 0; n -= 2)
|
||||
*op++ = (tidataval_t) lastpixel;
|
||||
}
|
||||
if (n == -1)
|
||||
*--op &= 0xf0;
|
||||
lastpixel &= 0xf;
|
||||
@@ -128,7 +130,7 @@ ThunderDecode(TIFF* tif, tidata_t op, tsize_t maxpixels)
|
||||
return (1);
|
||||
}
|
||||
|
||||
static int LINKAGEMODE
|
||||
static int
|
||||
ThunderDecodeRow(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
|
||||
{
|
||||
tidata_t row = buf;
|
||||
|
@@ -31,6 +31,32 @@
|
||||
*/
|
||||
#include "tiffiop.h"
|
||||
|
||||
static uint32
|
||||
summarize(TIFF* tif, size_t summand1, size_t summand2, const char* where)
|
||||
{
|
||||
uint32 bytes = summand1 + summand2;
|
||||
|
||||
if (bytes - summand1 != summand2) {
|
||||
TIFFError(tif->tif_name, "Integer overflow in %s", where);
|
||||
bytes = 0;
|
||||
}
|
||||
|
||||
return (bytes);
|
||||
}
|
||||
|
||||
static uint32
|
||||
multiply(TIFF* tif, size_t nmemb, size_t elem_size, const char* where)
|
||||
{
|
||||
uint32 bytes = nmemb * elem_size;
|
||||
|
||||
if (elem_size && bytes / elem_size != nmemb) {
|
||||
TIFFError(tif->tif_name, "Integer overflow in %s", where);
|
||||
bytes = 0;
|
||||
}
|
||||
|
||||
return (bytes);
|
||||
}
|
||||
|
||||
/*
|
||||
* Compute which tile an (x,y,z,s) value is in.
|
||||
*/
|
||||
@@ -62,7 +88,7 @@ TIFFComputeTile(TIFF* tif, uint32 x, uint32 y, uint32 z, tsample_t s)
|
||||
xpt*(y/dy) +
|
||||
x/dx;
|
||||
else
|
||||
tile = (xpt*ypt)*(z/dz) + xpt*(y/dy) + x/dx + s;
|
||||
tile = (xpt*ypt)*(z/dz) + xpt*(y/dy) + x/dx;
|
||||
}
|
||||
return (tile);
|
||||
}
|
||||
@@ -119,11 +145,13 @@ TIFFNumberOfTiles(TIFF* tif)
|
||||
if (dz == (uint32) -1)
|
||||
dz = td->td_imagedepth;
|
||||
ntiles = (dx == 0 || dy == 0 || dz == 0) ? 0 :
|
||||
(TIFFhowmany(td->td_imagewidth, dx) *
|
||||
TIFFhowmany(td->td_imagelength, dy) *
|
||||
TIFFhowmany(td->td_imagedepth, dz));
|
||||
multiply(tif, multiply(tif, TIFFhowmany(td->td_imagewidth, dx),
|
||||
TIFFhowmany(td->td_imagelength, dy),
|
||||
"TIFFNumberOfTiles"),
|
||||
TIFFhowmany(td->td_imagedepth, dz), "TIFFNumberOfTiles");
|
||||
if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
|
||||
ntiles *= td->td_samplesperpixel;
|
||||
ntiles = multiply(tif, ntiles, td->td_samplesperpixel,
|
||||
"TIFFNumberOfTiles");
|
||||
return (ntiles);
|
||||
}
|
||||
|
||||
@@ -138,10 +166,12 @@ TIFFTileRowSize(TIFF* tif)
|
||||
|
||||
if (td->td_tilelength == 0 || td->td_tilewidth == 0)
|
||||
return ((tsize_t) 0);
|
||||
rowsize = td->td_bitspersample * td->td_tilewidth;
|
||||
rowsize = multiply(tif, td->td_bitspersample, td->td_tilewidth,
|
||||
"TIFFTileRowSize");
|
||||
if (td->td_planarconfig == PLANARCONFIG_CONTIG)
|
||||
rowsize *= td->td_samplesperpixel;
|
||||
return ((tsize_t) TIFFhowmany(rowsize, 8));
|
||||
rowsize = multiply(tif, rowsize, td->td_samplesperpixel,
|
||||
"TIFFTileRowSize");
|
||||
return ((tsize_t) TIFFhowmany8(rowsize));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -170,16 +200,24 @@ TIFFVTileSize(TIFF* tif, uint32 nrows)
|
||||
*/
|
||||
tsize_t w =
|
||||
TIFFroundup(td->td_tilewidth, td->td_ycbcrsubsampling[0]);
|
||||
tsize_t rowsize = TIFFhowmany(w*td->td_bitspersample, 8);
|
||||
tsize_t rowsize =
|
||||
TIFFhowmany8(multiply(tif, w, td->td_bitspersample,
|
||||
"TIFFVTileSize"));
|
||||
tsize_t samplingarea =
|
||||
td->td_ycbcrsubsampling[0]*td->td_ycbcrsubsampling[1];
|
||||
nrows = TIFFroundup(nrows, td->td_ycbcrsubsampling[1]);
|
||||
/* NB: don't need TIFFhowmany here 'cuz everything is rounded */
|
||||
tilesize = nrows*rowsize + 2*(nrows*rowsize / samplingarea);
|
||||
tilesize = multiply(tif, nrows, rowsize, "TIFFVTileSize");
|
||||
tilesize = summarize(tif, tilesize,
|
||||
multiply(tif, 2, tilesize / samplingarea,
|
||||
"TIFFVTileSize"),
|
||||
"TIFFVTileSize");
|
||||
} else
|
||||
#endif
|
||||
tilesize = nrows * TIFFTileRowSize(tif);
|
||||
return ((tsize_t)(tilesize * td->td_tiledepth));
|
||||
tilesize = multiply(tif, nrows, TIFFTileRowSize(tif),
|
||||
"TIFFVTileSize");
|
||||
return ((tsize_t)
|
||||
multiply(tif, tilesize, td->td_tiledepth, "TIFFVTileSize"));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -47,7 +47,11 @@ _tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size)
|
||||
static toff_t
|
||||
_tiffSeekProc(thandle_t fd, toff_t off, int whence)
|
||||
{
|
||||
#if USE_64BIT_API == 1
|
||||
return ((toff_t) lseek64((int) fd, (off64_t) off, whence));
|
||||
#else
|
||||
return ((toff_t) lseek((int) fd, (off_t) off, whence));
|
||||
#endif
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -64,10 +68,15 @@ _tiffSizeProc(thandle_t fd)
|
||||
#ifdef _AM29K
|
||||
long fsize;
|
||||
return ((fsize = lseek((int) fd, 0, SEEK_END)) < 0 ? 0 : fsize);
|
||||
#else
|
||||
#if USE_64BIT_API == 1
|
||||
struct stat64 sb;
|
||||
return (toff_t) (fstat64((int) fd, &sb) < 0 ? 0 : sb.st_size);
|
||||
#else
|
||||
struct stat sb;
|
||||
return (toff_t) (fstat((int) fd, &sb) < 0 ? 0 : sb.st_size);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef HAVE_MMAP
|
||||
@@ -147,8 +156,12 @@ TIFFOpen(const char* name, const char* mode)
|
||||
|
||||
#ifdef _AM29K
|
||||
fd = open(name, m);
|
||||
#else
|
||||
#if USE_64BIT_API == 1
|
||||
fd = open(name, m | O_LARGEFILE, 0666);
|
||||
#else
|
||||
fd = open(name, m, 0666);
|
||||
#endif
|
||||
#endif
|
||||
if (fd < 0) {
|
||||
TIFFError(module, "%s: Cannot open", name);
|
||||
|
@@ -24,9 +24,7 @@
|
||||
*/
|
||||
#include "tiffiop.h"
|
||||
|
||||
#define VERSION "LIBTIFF, Version 3.5.201\nCopyright (c) 1988-1996 Sam Leffler\nCopyright (c) 1991-1996 Silicon Graphics, Inc."
|
||||
|
||||
static const char TIFFVersion[] = VERSION;
|
||||
static const char TIFFVersion[] = TIFFLIB_VERSION_STR;
|
||||
|
||||
const char*
|
||||
TIFFGetVersion(void)
|
||||
|
@@ -52,23 +52,30 @@ _tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size)
|
||||
static toff_t
|
||||
_tiffSeekProc(thandle_t fd, toff_t off, int whence)
|
||||
{
|
||||
DWORD dwMoveMethod;
|
||||
DWORD dwMoveMethod, dwMoveHigh;
|
||||
|
||||
/* we use this as a special code, so avoid accepting it */
|
||||
if( off == 0xFFFFFFFF )
|
||||
return 0xFFFFFFFF;
|
||||
|
||||
switch(whence)
|
||||
{
|
||||
case 0:
|
||||
case SEEK_SET:
|
||||
dwMoveMethod = FILE_BEGIN;
|
||||
break;
|
||||
case 1:
|
||||
case SEEK_CUR:
|
||||
dwMoveMethod = FILE_CURRENT;
|
||||
break;
|
||||
case 2:
|
||||
case SEEK_END:
|
||||
dwMoveMethod = FILE_END;
|
||||
break;
|
||||
default:
|
||||
dwMoveMethod = FILE_BEGIN;
|
||||
break;
|
||||
}
|
||||
return ((toff_t)SetFilePointer(fd, off, NULL, dwMoveMethod));
|
||||
dwMoveHigh = 0;
|
||||
return ((toff_t)SetFilePointer(fd, (LONG) off, (PLONG)&dwMoveHigh,
|
||||
dwMoveMethod));
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -83,6 +90,9 @@ _tiffSizeProc(thandle_t fd)
|
||||
return ((toff_t)GetFileSize(fd, NULL));
|
||||
}
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma argsused
|
||||
#endif
|
||||
static int
|
||||
_tiffDummyMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize)
|
||||
{
|
||||
@@ -106,7 +116,7 @@ _tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize)
|
||||
toff_t size;
|
||||
HANDLE hMapFile;
|
||||
|
||||
if ((size = _tiffSizeProc(fd)) == (toff_t)-1)
|
||||
if ((size = _tiffSizeProc(fd)) == 0xFFFFFFFF)
|
||||
return (0);
|
||||
hMapFile = CreateFileMapping(fd, NULL, PAGE_READONLY, 0, size, NULL);
|
||||
if (hMapFile == NULL)
|
||||
@@ -119,6 +129,9 @@ _tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize)
|
||||
return(1);
|
||||
}
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma argsused
|
||||
#endif
|
||||
static void
|
||||
_tiffDummyUnmapProc(thandle_t fd, tdata_t base, toff_t size)
|
||||
{
|
||||
@@ -139,7 +152,7 @@ TIFF*
|
||||
TIFFFdOpen(int ifd, const char* name, const char* mode)
|
||||
{
|
||||
TIFF* tif;
|
||||
BOOL fSuppressMap = (mode[1] == 'u' || mode[2] == 'u');
|
||||
BOOL fSuppressMap = (mode[1] == 'u' || (mode[1]!=0 && mode[2] == 'u'));
|
||||
|
||||
tif = TIFFClientOpen(name, mode,
|
||||
(thandle_t)ifd,
|
||||
@@ -211,14 +224,23 @@ _TIFFfree(tdata_t p)
|
||||
tdata_t
|
||||
_TIFFrealloc(tdata_t p, tsize_t s)
|
||||
{
|
||||
void* pvTmp;
|
||||
if ((pvTmp = GlobalReAlloc(p, s, 0)) == NULL) {
|
||||
if ((pvTmp = GlobalAlloc(GMEM_FIXED, s)) != NULL) {
|
||||
CopyMemory(pvTmp, p, GlobalSize(p));
|
||||
GlobalFree(p);
|
||||
}
|
||||
}
|
||||
return ((tdata_t)pvTmp);
|
||||
void* pvTmp;
|
||||
tsize_t old=GlobalSize(p);
|
||||
if (old>=s)
|
||||
{
|
||||
if ((pvTmp = GlobalAlloc(GMEM_FIXED, s)) != NULL) {
|
||||
CopyMemory(pvTmp, p, s);
|
||||
GlobalFree(p);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((pvTmp = GlobalAlloc(GMEM_FIXED, s)) != NULL) {
|
||||
CopyMemory(pvTmp, p, old);
|
||||
GlobalFree(p);
|
||||
}
|
||||
}
|
||||
return ((tdata_t)pvTmp);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -236,8 +258,8 @@ _TIFFmemcpy(void* d, const tdata_t s, tsize_t c)
|
||||
int
|
||||
_TIFFmemcmp(const tdata_t p1, const tdata_t p2, tsize_t c)
|
||||
{
|
||||
register const BYTE *pb1 = p1;
|
||||
register const BYTE *pb2 = p2;
|
||||
register const BYTE *pb1 = (const BYTE *) p1;
|
||||
register const BYTE *pb2 = (const BYTE *) p2;
|
||||
register DWORD dwTmp = c;
|
||||
register int iTmp;
|
||||
for (iTmp = 0; dwTmp-- && !iTmp; iTmp = (int)*pb1++ - (int)*pb2++)
|
||||
|
@@ -33,6 +33,8 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define REWRITE_HACK
|
||||
|
||||
#define STRIPINCR 20 /* expansion factor on strip array */
|
||||
|
||||
#define WRITECHECKSTRIPS(tif, module) \
|
||||
@@ -40,13 +42,11 @@
|
||||
#define WRITECHECKTILES(tif, module) \
|
||||
(((tif)->tif_flags&TIFF_BEENWRITING) || TIFFWriteCheck((tif),1,module))
|
||||
#define BUFFERCHECK(tif) \
|
||||
(((tif)->tif_flags & TIFF_BUFFERSETUP) || \
|
||||
((((tif)->tif_flags & TIFF_BUFFERSETUP) && tif->tif_rawdata) || \
|
||||
TIFFWriteBufferSetup((tif), NULL, (tsize_t) -1))
|
||||
|
||||
static int TIFFWriteCheck(TIFF*, int, const char*);
|
||||
static int TIFFGrowStrips(TIFF*, int, const char*);
|
||||
static int TIFFAppendToStrip(TIFF*, tstrip_t, tidata_t, tsize_t);
|
||||
static int TIFFSetupStrips(TIFF*);
|
||||
|
||||
int
|
||||
TIFFWriteScanline(TIFF* tif, tdata_t buf, uint32 row, tsample_t sample)
|
||||
@@ -152,9 +152,15 @@ TIFFWriteScanline(TIFF* tif, tdata_t buf, uint32 row, tsample_t sample)
|
||||
return (-1);
|
||||
tif->tif_row = row;
|
||||
}
|
||||
|
||||
/* swab if needed - note that source buffer will be altered */
|
||||
tif->tif_postdecode( tif, (tidata_t) buf, tif->tif_scanlinesize );
|
||||
|
||||
status = (*tif->tif_encoderow)(tif, (tidata_t) buf,
|
||||
tif->tif_scanlinesize, sample);
|
||||
tif->tif_row++;
|
||||
|
||||
/* we are now poised at the beginning of the next row */
|
||||
tif->tif_row = row + 1;
|
||||
return (status);
|
||||
}
|
||||
|
||||
@@ -208,10 +214,29 @@ TIFFWriteEncodedStrip(TIFF* tif, tstrip_t strip, tdata_t data, tsize_t cc)
|
||||
return ((tsize_t) -1);
|
||||
tif->tif_flags |= TIFF_CODERSETUP;
|
||||
}
|
||||
|
||||
#ifdef REWRITE_HACK
|
||||
tif->tif_rawcc = 0;
|
||||
tif->tif_rawcp = tif->tif_rawdata;
|
||||
|
||||
if( td->td_stripbytecount[strip] > 0 )
|
||||
{
|
||||
/* if we are writing over existing tiles, zero length. */
|
||||
td->td_stripbytecount[strip] = 0;
|
||||
|
||||
/* this forces TIFFAppendToStrip() to do a seek */
|
||||
tif->tif_curoff = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
tif->tif_flags &= ~TIFF_POSTENCODE;
|
||||
sample = (tsample_t)(strip / td->td_stripsperimage);
|
||||
if (!(*tif->tif_preencode)(tif, sample))
|
||||
return ((tsize_t) -1);
|
||||
|
||||
/* swab if needed - note that source buffer will be altered */
|
||||
tif->tif_postdecode( tif, (tidata_t) data, cc );
|
||||
|
||||
if (!(*tif->tif_encodestrip)(tif, (tidata_t) data, cc, sample))
|
||||
return ((tsize_t) 0);
|
||||
if (!(*tif->tif_postencode)(tif))
|
||||
@@ -329,6 +354,21 @@ TIFFWriteEncodedTile(TIFF* tif, ttile_t tile, tdata_t data, tsize_t cc)
|
||||
if (!BUFFERCHECK(tif))
|
||||
return ((tsize_t) -1);
|
||||
tif->tif_curtile = tile;
|
||||
|
||||
#ifdef REWRITE_HACK
|
||||
tif->tif_rawcc = 0;
|
||||
tif->tif_rawcp = tif->tif_rawdata;
|
||||
|
||||
if( td->td_stripbytecount[tile] > 0 )
|
||||
{
|
||||
/* if we are writing over existing tiles, zero length. */
|
||||
td->td_stripbytecount[tile] = 0;
|
||||
|
||||
/* this forces TIFFAppendToStrip() to do a seek */
|
||||
tif->tif_curoff = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Compute tiles per row & per column to compute
|
||||
* current row and column
|
||||
@@ -352,8 +392,12 @@ TIFFWriteEncodedTile(TIFF* tif, ttile_t tile, tdata_t data, tsize_t cc)
|
||||
* done so that callers can pass in some large number
|
||||
* (e.g. -1) and have the tile size used instead.
|
||||
*/
|
||||
if ((uint32) cc > tif->tif_tilesize)
|
||||
if ( cc < 1 || cc > tif->tif_tilesize)
|
||||
cc = tif->tif_tilesize;
|
||||
|
||||
/* swab if needed - note that source buffer will be altered */
|
||||
tif->tif_postdecode( tif, (tidata_t) data, cc );
|
||||
|
||||
if (!(*tif->tif_encodetile)(tif, (tidata_t) data, cc, sample))
|
||||
return ((tsize_t) 0);
|
||||
if (!(*tif->tif_postencode)(tif))
|
||||
@@ -398,7 +442,7 @@ TIFFWriteRawTile(TIFF* tif, ttile_t tile, tdata_t data, tsize_t cc)
|
||||
#define isUnspecified(tif, f) \
|
||||
(TIFFFieldSet(tif,f) && (tif)->tif_dir.td_imagelength == 0)
|
||||
|
||||
static int
|
||||
int
|
||||
TIFFSetupStrips(TIFF* tif)
|
||||
{
|
||||
TIFFDirectory* td = &tif->tif_dir;
|
||||
@@ -438,7 +482,7 @@ TIFFSetupStrips(TIFF* tif)
|
||||
* we also "freeze" the state of the directory so
|
||||
* that important information is not changed.
|
||||
*/
|
||||
static int
|
||||
int
|
||||
TIFFWriteCheck(TIFF* tif, int tiles, const char* module)
|
||||
{
|
||||
if (tif->tif_mode == O_RDONLY) {
|
||||
@@ -452,6 +496,24 @@ TIFFWriteCheck(TIFF* tif, int tiles, const char* module)
|
||||
"Can not write scanlines to a tiled image");
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* While we allow compressed TIFF files to be opened in update mode,
|
||||
* we don't allow writing any image blocks in an existing compressed
|
||||
* image. Eventually we could do so, by moving blocks that grow
|
||||
* to the end of the file, but we don't for now.
|
||||
*/
|
||||
if (tif->tif_dir.td_stripoffset != NULL
|
||||
&& tif->tif_dir.td_compression != COMPRESSION_NONE )
|
||||
{
|
||||
TIFFError( module,
|
||||
"%s:\n"
|
||||
"In place update to compressed TIFF images not "
|
||||
"supported.",
|
||||
tif->tif_name );
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* On the first write verify all the required information
|
||||
* has been setup and initialize any data structures that
|
||||
@@ -480,7 +542,11 @@ TIFFWriteCheck(TIFF* tif, int tiles, const char* module)
|
||||
tif->tif_name, isTiled(tif) ? "tile" : "strip");
|
||||
return (0);
|
||||
}
|
||||
tif->tif_tilesize = TIFFTileSize(tif);
|
||||
if (isTiled(tif))
|
||||
tif->tif_tilesize = TIFFTileSize(tif);
|
||||
else
|
||||
tif->tif_tilesize = (tsize_t) -1;
|
||||
|
||||
tif->tif_scanlinesize = TIFFScanlineSize(tif);
|
||||
tif->tif_flags |= TIFF_BEENWRITING;
|
||||
return (1);
|
||||
@@ -535,21 +601,30 @@ TIFFWriteBufferSetup(TIFF* tif, tdata_t bp, tsize_t size)
|
||||
static int
|
||||
TIFFGrowStrips(TIFF* tif, int delta, const char* module)
|
||||
{
|
||||
TIFFDirectory *td = &tif->tif_dir;
|
||||
TIFFDirectory *td = &tif->tif_dir;
|
||||
uint32 *new_stripoffset, *new_stripbytecount;
|
||||
|
||||
assert(td->td_planarconfig == PLANARCONFIG_CONTIG);
|
||||
td->td_stripoffset = (uint32*)_TIFFrealloc(td->td_stripoffset,
|
||||
(td->td_nstrips + delta) * sizeof (uint32));
|
||||
td->td_stripbytecount = (uint32*)_TIFFrealloc(td->td_stripbytecount,
|
||||
(td->td_nstrips + delta) * sizeof (uint32));
|
||||
if (td->td_stripoffset == NULL || td->td_stripbytecount == NULL) {
|
||||
new_stripoffset = (uint32*)_TIFFrealloc(td->td_stripoffset,
|
||||
(td->td_nstrips + delta) * sizeof (uint32));
|
||||
new_stripbytecount = (uint32*)_TIFFrealloc(td->td_stripbytecount,
|
||||
(td->td_nstrips + delta) * sizeof (uint32));
|
||||
if (new_stripoffset == NULL || new_stripbytecount == NULL) {
|
||||
if (new_stripoffset)
|
||||
_TIFFfree(new_stripoffset);
|
||||
if (new_stripbytecount)
|
||||
_TIFFfree(new_stripbytecount);
|
||||
td->td_nstrips = 0;
|
||||
TIFFError(module, "%s: No space to expand strip arrays",
|
||||
tif->tif_name);
|
||||
tif->tif_name);
|
||||
return (0);
|
||||
}
|
||||
_TIFFmemset(td->td_stripoffset+td->td_nstrips, 0, delta*sizeof (uint32));
|
||||
_TIFFmemset(td->td_stripbytecount+td->td_nstrips, 0, delta*sizeof (uint32));
|
||||
td->td_stripoffset = new_stripoffset;
|
||||
td->td_stripbytecount = new_stripbytecount;
|
||||
_TIFFmemset(td->td_stripoffset + td->td_nstrips,
|
||||
0, delta*sizeof (uint32));
|
||||
_TIFFmemset(td->td_stripbytecount + td->td_nstrips,
|
||||
0, delta*sizeof (uint32));
|
||||
td->td_nstrips += delta;
|
||||
return (1);
|
||||
}
|
||||
|
@@ -46,13 +46,7 @@
|
||||
* directory ftp://ftp.uu.net/pub/archiving/zip/doc. The library was
|
||||
* last found at ftp://ftp.uu.net/pub/archiving/zip/zlib/zlib-0.99.tar.gz.
|
||||
*/
|
||||
/* Watcom C++ (or its make utility) doesn't like long filenames */
|
||||
#ifdef __WATCOMC__
|
||||
#include "tif_pred.h"
|
||||
#else
|
||||
#include "tif_predict.h"
|
||||
#endif
|
||||
|
||||
#include "zlib.h"
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -234,7 +228,8 @@ ZIPPostEncode(TIFF* tif)
|
||||
switch (state) {
|
||||
case Z_STREAM_END:
|
||||
case Z_OK:
|
||||
if (sp->stream.avail_out != tif->tif_rawdatasize) {
|
||||
if ((int)sp->stream.avail_out != (int)tif->tif_rawdatasize)
|
||||
{
|
||||
tif->tif_rawcc =
|
||||
tif->tif_rawdatasize - sp->stream.avail_out;
|
||||
TIFFFlushData1(tif);
|
||||
@@ -318,7 +313,7 @@ TIFFInitZIP(TIFF* tif, int scheme)
|
||||
{
|
||||
ZIPState* sp;
|
||||
|
||||
assert(scheme == COMPRESSION_DEFLATE);
|
||||
assert( (scheme == COMPRESSION_DEFLATE) || (scheme == COMPRESSION_ADOBE_DEFLATE));
|
||||
|
||||
/*
|
||||
* Allocate state block so tag methods have storage to record values.
|
||||
@@ -337,10 +332,10 @@ TIFFInitZIP(TIFF* tif, int scheme)
|
||||
* override parent get/set field methods.
|
||||
*/
|
||||
_TIFFMergeFieldInfo(tif, zipFieldInfo, N(zipFieldInfo));
|
||||
sp->vgetparent = tif->tif_vgetfield;
|
||||
tif->tif_vgetfield = ZIPVGetField; /* hook for codec tags */
|
||||
sp->vsetparent = tif->tif_vsetfield;
|
||||
tif->tif_vsetfield = ZIPVSetField; /* hook for codec tags */
|
||||
sp->vgetparent = tif->tif_tagmethods.vgetfield;
|
||||
tif->tif_tagmethods.vgetfield = ZIPVGetField; /* hook for codec tags */
|
||||
sp->vsetparent = tif->tif_tagmethods.vsetfield;
|
||||
tif->tif_tagmethods.vsetfield = ZIPVSetField; /* hook for codec tags */
|
||||
|
||||
/* Default values for codec-specific fields */
|
||||
sp->zipquality = Z_DEFAULT_COMPRESSION; /* default comp. level */
|
||||
|
@@ -133,6 +133,22 @@ SOURCE=.\tif_codec.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\tif_color.c
|
||||
|
||||
!IF "$(CFG)" == "tiff - Win32 Release"
|
||||
|
||||
# ADD CPP /I ".."
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "tiff - Win32 Debug"
|
||||
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\tif_compress.c
|
||||
|
||||
!IF "$(CFG)" == "tiff - Win32 Release"
|
||||
|
@@ -42,8 +42,24 @@
|
||||
#define TIFF_BIGENDIAN 0x4d4d
|
||||
#define TIFF_LITTLEENDIAN 0x4949
|
||||
|
||||
#ifndef _TIFF_DATA_TYPEDEFS_
|
||||
/*
|
||||
* The so called TIFF types conflict with definitions from inttypes.h
|
||||
* included from sys/types.h on AIX (at least using VisualAge compiler).
|
||||
* We try to work around this by detecting this case. Defining
|
||||
* _TIFF_DATA_TYPEDEFS_ short circuits the later definitions in tiff.h, and
|
||||
* we will in the holes not provided for by inttypes.h.
|
||||
*
|
||||
* See http://bugzilla.remotesensing.org/show_bug.cgi?id=39
|
||||
*/
|
||||
#if defined(_H_INTTYPES) && defined(_ALL_SOURCE) && defined(USING_VISUALAGE)
|
||||
|
||||
#define _TIFF_DATA_TYPEDEFS_
|
||||
typedef unsigned char uint8;
|
||||
typedef unsigned short uint16;
|
||||
typedef unsigned int uint32;
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Intrinsic data types required by the file format:
|
||||
*
|
||||
@@ -52,23 +68,22 @@
|
||||
* 32-bit quantities int32/uint32
|
||||
* strings unsigned char*
|
||||
*/
|
||||
#ifndef _AIX43 /* int{8,16,32} already defined on AIX */
|
||||
#ifndef _TIFF_DATA_TYPEDEFS_
|
||||
#define _TIFF_DATA_TYPEDEFS_
|
||||
|
||||
#ifdef __STDC__
|
||||
typedef signed char int8; /* NB: non-ANSI compilers may not grok */
|
||||
#else
|
||||
typedef char int8;
|
||||
#endif
|
||||
typedef short int16;
|
||||
#endif
|
||||
typedef unsigned char uint8;
|
||||
typedef short int16;
|
||||
typedef unsigned short uint16; /* sizeof (uint16) must == 2 */
|
||||
#if defined(__alpha) || (defined(_MIPS_SZLONG) && _MIPS_SZLONG == 64)
|
||||
#if defined(__alpha) || (defined(_MIPS_SZLONG) && _MIPS_SZLONG == 64) || defined(__LP64__) || defined(__arch64__)
|
||||
typedef int int32;
|
||||
typedef unsigned int uint32; /* sizeof (uint32) must == 4 */
|
||||
#else
|
||||
#ifndef _AIX43
|
||||
typedef long int32;
|
||||
#endif
|
||||
typedef unsigned long uint32; /* sizeof (uint32) must == 4 */
|
||||
#endif
|
||||
#endif /* _TIFF_DATA_TYPEDEFS_ */
|
||||
@@ -101,10 +116,10 @@ typedef struct {
|
||||
* offset field.
|
||||
*/
|
||||
typedef struct {
|
||||
uint16 tdir_tag; /* see below */
|
||||
uint16 tdir_type; /* data type; see below */
|
||||
uint32 tdir_count; /* number of items; length in spec */
|
||||
uint32 tdir_offset; /* byte offset to field data */
|
||||
uint16 tdir_tag; /* see below */
|
||||
uint16 tdir_type; /* data type; see below */
|
||||
uint32 tdir_count; /* number of items; length in spec */
|
||||
uint32 tdir_offset; /* byte offset to field data */
|
||||
} TIFFDirEntry;
|
||||
|
||||
/*
|
||||
@@ -133,7 +148,8 @@ typedef enum {
|
||||
TIFF_SLONG = 9, /* !32-bit signed integer */
|
||||
TIFF_SRATIONAL = 10, /* !64-bit signed fraction */
|
||||
TIFF_FLOAT = 11, /* !32-bit IEEE floating point */
|
||||
TIFF_DOUBLE = 12 /* !64-bit IEEE floating point */
|
||||
TIFF_DOUBLE = 12, /* !64-bit IEEE floating point */
|
||||
TIFF_IFD = 13 /* %32-bit unsigned integer (offset) */
|
||||
} TIFFDataType;
|
||||
|
||||
/*
|
||||
@@ -154,15 +170,17 @@ typedef enum {
|
||||
#define COMPRESSION_NONE 1 /* dump mode */
|
||||
#define COMPRESSION_CCITTRLE 2 /* CCITT modified Huffman RLE */
|
||||
#define COMPRESSION_CCITTFAX3 3 /* CCITT Group 3 fax encoding */
|
||||
#define COMPRESSION_CCITT_T4 3 /* CCITT T.4 (TIFF 6 name) */
|
||||
#define COMPRESSION_CCITTFAX4 4 /* CCITT Group 4 fax encoding */
|
||||
#define COMPRESSION_LZW 5 /* Lempel-Ziv & Welch */
|
||||
#define COMPRESSION_CCITT_T6 4 /* CCITT T.6 (TIFF 6 name) */
|
||||
#define COMPRESSION_LZW 5 /* Lempel-Ziv & Welch */
|
||||
#define COMPRESSION_OJPEG 6 /* !6.0 JPEG */
|
||||
#define COMPRESSION_JPEG 7 /* %JPEG DCT compression */
|
||||
#define COMPRESSION_NEXT 32766 /* NeXT 2-bit RLE */
|
||||
#define COMPRESSION_CCITTRLEW 32771 /* #1 w/ word alignment */
|
||||
#define COMPRESSION_PACKBITS 32773 /* Macintosh RLE */
|
||||
#define COMPRESSION_THUNDERSCAN 32809 /* ThunderScan RLE */
|
||||
/* codes 32895-32898 are reserved for ANSI IT8 TIFF/IT <dkelly@etsinc.com) */
|
||||
/* codes 32895-32898 are reserved for ANSI IT8 TIFF/IT <dkelly@apago.com) */
|
||||
#define COMPRESSION_IT8CTPAD 32895 /* IT8 CT w/padding */
|
||||
#define COMPRESSION_IT8LW 32896 /* IT8 Linework RLE */
|
||||
#define COMPRESSION_IT8MP 32897 /* IT8 Monochrome picture */
|
||||
@@ -171,11 +189,13 @@ typedef enum {
|
||||
#define COMPRESSION_PIXARFILM 32908 /* Pixar companded 10bit LZW */
|
||||
#define COMPRESSION_PIXARLOG 32909 /* Pixar companded 11bit ZIP */
|
||||
#define COMPRESSION_DEFLATE 32946 /* Deflate compression */
|
||||
#define COMPRESSION_ADOBE_DEFLATE 8 /* Deflate compression, as recognized by Adobe */
|
||||
/* compression code 32947 is reserved for Oceana Matrix <dev@oceana.com> */
|
||||
#define COMPRESSION_DCS 32947 /* Kodak DCS encoding */
|
||||
#define COMPRESSION_JBIG 34661 /* ISO JBIG */
|
||||
#define COMPRESSION_SGILOG 34676 /* SGI Log Luminance RLE */
|
||||
#define COMPRESSION_SGILOG24 34677 /* SGI Log 24-bit packed */
|
||||
#define COMPRESSION_JP2000 34712 /* Leadtools JPEG2000 */
|
||||
#define TIFFTAG_PHOTOMETRIC 262 /* photometric interpretation */
|
||||
#define PHOTOMETRIC_MINISWHITE 0 /* min value is white */
|
||||
#define PHOTOMETRIC_MINISBLACK 1 /* min value is black */
|
||||
@@ -185,6 +205,8 @@ typedef enum {
|
||||
#define PHOTOMETRIC_SEPARATED 5 /* !color separations */
|
||||
#define PHOTOMETRIC_YCBCR 6 /* !CCIR 601 */
|
||||
#define PHOTOMETRIC_CIELAB 8 /* !1976 CIE L*a*b* */
|
||||
#define PHOTOMETRIC_ICCLAB 9 /* ICC L*a*b* [Adobe TIFF Technote 4] */
|
||||
#define PHOTOMETRIC_ITULAB 10 /* ITU L*a*b* */
|
||||
#define PHOTOMETRIC_LOGL 32844 /* CIE Log2(L) */
|
||||
#define PHOTOMETRIC_LOGLUV 32845 /* CIE Log2(L) (u',v') */
|
||||
#define TIFFTAG_THRESHHOLDING 263 /* +thresholding used on data */
|
||||
@@ -233,10 +255,12 @@ typedef enum {
|
||||
#define GRAYRESPONSEUNIT_100000S 5 /* hundred-thousandths */
|
||||
#define TIFFTAG_GRAYRESPONSECURVE 291 /* $gray scale response curve */
|
||||
#define TIFFTAG_GROUP3OPTIONS 292 /* 32 flag bits */
|
||||
#define TIFFTAG_T4OPTIONS 292 /* TIFF 6.0 proper name alias */
|
||||
#define GROUP3OPT_2DENCODING 0x1 /* 2-dimensional coding */
|
||||
#define GROUP3OPT_UNCOMPRESSED 0x2 /* data not compressed */
|
||||
#define GROUP3OPT_FILLBITS 0x4 /* fill to byte boundary */
|
||||
#define TIFFTAG_GROUP4OPTIONS 293 /* 32 flag bits */
|
||||
#define TIFFTAG_T6OPTIONS 293 /* TIFF 6.0 proper name */
|
||||
#define GROUP4OPT_UNCOMPRESSED 0x2 /* data not compressed */
|
||||
#define TIFFTAG_RESOLUTIONUNIT 296 /* units of resolutions */
|
||||
#define RESUNIT_NONE 1 /* no meaningful units */
|
||||
@@ -271,7 +295,8 @@ typedef enum {
|
||||
#define TIFFTAG_CONSECUTIVEBADFAXLINES 328 /* max consecutive bad lines */
|
||||
#define TIFFTAG_SUBIFD 330 /* subimage descriptors */
|
||||
#define TIFFTAG_INKSET 332 /* !inks in separated image */
|
||||
#define INKSET_CMYK 1 /* !cyan-magenta-yellow-black */
|
||||
#define INKSET_CMYK 1 /* !cyan-magenta-yellow-black color */
|
||||
#define INKSET_MULTIINK 2 /* !multi-ink or hi-fi color */
|
||||
#define TIFFTAG_INKNAMES 333 /* !ascii names of inks */
|
||||
#define TIFFTAG_NUMBEROFINKS 334 /* !number of inks */
|
||||
#define TIFFTAG_DOTRANGE 336 /* !0% and 100% dot codes */
|
||||
@@ -285,9 +310,16 @@ typedef enum {
|
||||
#define SAMPLEFORMAT_INT 2 /* !signed integer data */
|
||||
#define SAMPLEFORMAT_IEEEFP 3 /* !IEEE floating point data */
|
||||
#define SAMPLEFORMAT_VOID 4 /* !untyped data */
|
||||
#define SAMPLEFORMAT_COMPLEXINT 5 /* !complex signed int */
|
||||
#define SAMPLEFORMAT_COMPLEXIEEEFP 6 /* !complex ieee floating */
|
||||
#define TIFFTAG_SMINSAMPLEVALUE 340 /* !variable MinSampleValue */
|
||||
#define TIFFTAG_SMAXSAMPLEVALUE 341 /* !variable MaxSampleValue */
|
||||
#define TIFFTAG_CLIPPATH 343 /* %ClipPath [Adobe TIFF technote 2] */
|
||||
#define TIFFTAG_XCLIPPATHUNITS 344 /* %XClipPathUnits [Adobe TIFF technote 2] */
|
||||
#define TIFFTAG_YCLIPPATHUNITS 344 /* %YClipPathUnits [Adobe TIFF technote 2] */
|
||||
#define TIFFTAG_INDEXED 345 /* %Indexed [Adobe TIFF Technote 3] */
|
||||
#define TIFFTAG_JPEGTABLES 347 /* %JPEG table stream */
|
||||
#define TIFFTAG_OPIPROXY 351 /* %OPI Proxy [Adobe TIFF technote] */
|
||||
/*
|
||||
* Tags 512-521 are obsoleted by Technical Note #2
|
||||
* which specifies a revised JPEG-in-TIFF scheme.
|
||||
@@ -309,6 +341,8 @@ typedef enum {
|
||||
#define YCBCRPOSITION_CENTERED 1 /* !as in PostScript Level 2 */
|
||||
#define YCBCRPOSITION_COSITED 2 /* !as in CCIR 601-1 */
|
||||
#define TIFFTAG_REFERENCEBLACKWHITE 532 /* !colorimetry info */
|
||||
#define TIFFTAG_XMLPACKET 700 /* %XML packet [Adobe XMP technote 9-14-02] (dkelly@apago.com) */
|
||||
#define TIFFTAG_OPIIMAGEID 32781 /* %OPI ImageID [Adobe TIFF technote] */
|
||||
/* tags 32952-32956 are private tags registered to Island Graphics */
|
||||
#define TIFFTAG_REFPTS 32953 /* image reference points */
|
||||
#define TIFFTAG_REGIONTACKPOINT 32954 /* region-xform tack point */
|
||||
@@ -329,13 +363,21 @@ typedef enum {
|
||||
*/
|
||||
#define TIFFTAG_PIXAR_IMAGEFULLWIDTH 33300 /* full image size in x */
|
||||
#define TIFFTAG_PIXAR_IMAGEFULLLENGTH 33301 /* full image size in y */
|
||||
/* Tags 33302-33306 are used to identify special image modes and data
|
||||
* used by Pixar's texture formats.
|
||||
*/
|
||||
#define TIFFTAG_PIXAR_TEXTUREFORMAT 33302 /* texture map format */
|
||||
#define TIFFTAG_PIXAR_WRAPMODES 33303 /* s & t wrap modes */
|
||||
#define TIFFTAG_PIXAR_FOVCOT 33304 /* cotan(fov) for env. maps */
|
||||
#define TIFFTAG_PIXAR_MATRIX_WORLDTOSCREEN 33305
|
||||
#define TIFFTAG_PIXAR_MATRIX_WORLDTOCAMERA 33306
|
||||
/* tag 33405 is a private tag registered to Eastman Kodak */
|
||||
#define TIFFTAG_WRITERSERIALNUMBER 33405 /* device serial number */
|
||||
/* tag 33432 is listed in the 6.0 spec w/ unknown ownership */
|
||||
#define TIFFTAG_COPYRIGHT 33432 /* copyright string */
|
||||
/* IPTC TAG from RichTIFF specifications */
|
||||
#define TIFFTAG_RICHTIFFIPTC 33723
|
||||
/* 34016-34029 are reserved for ANSI IT8 TIFF/IT <dkelly@etsinc.com) */
|
||||
/* 34016-34029 are reserved for ANSI IT8 TIFF/IT <dkelly@apago.com) */
|
||||
#define TIFFTAG_IT8SITE 34016 /* site name */
|
||||
#define TIFFTAG_IT8COLORSEQUENCE 34017 /* color seq. [RGB,CMYK,etc] */
|
||||
#define TIFFTAG_IT8HEADER 34018 /* DDES Header */
|
||||
@@ -350,6 +392,9 @@ typedef enum {
|
||||
#define TIFFTAG_IT8PIXELINTENSITYRANGE 34027 /* MP pixel intensity value */
|
||||
#define TIFFTAG_IT8TRANSPARENCYINDICATOR 34028 /* HC transparency switch */
|
||||
#define TIFFTAG_IT8COLORCHARACTERIZATION 34029 /* color character. table */
|
||||
#define TIFFTAG_IT8HCUSAGE 34030 /* HC usage indicator */
|
||||
#define TIFFTAG_IT8TRAPINDICATOR 34031 /* Trapping indicator (untrapped=0, trapped=1) */
|
||||
#define TIFFTAG_IT8CMYKEQUIVALENT 34032 /* CMYK color equivalents */
|
||||
/* tags 34232-34236 are private tags registered to Texas Instruments */
|
||||
#define TIFFTAG_FRAMECOUNT 34232 /* Sequence Frame Count */
|
||||
/* tag 34750 is a private tag registered to Adobe? */
|
||||
@@ -431,4 +476,7 @@ typedef enum {
|
||||
#define SGILOGDATAFMT_16BIT 1 /* 16-bit samples */
|
||||
#define SGILOGDATAFMT_RAW 2 /* uninterpreted data */
|
||||
#define SGILOGDATAFMT_8BIT 3 /* 8-bit RGB monitor values */
|
||||
#define TIFFTAG_SGILOGENCODE 65561 /* SGILog data encoding control*/
|
||||
#define SGILOGENCODE_NODITHER 0 /* do not dither encoded values*/
|
||||
#define SGILOGENCODE_RANDITHER 1 /* randomly dither encd values */
|
||||
#endif /* _TIFF_ */
|
||||
|
@@ -52,21 +52,13 @@
|
||||
#endif
|
||||
|
||||
#if defined(__MWERKS__) || defined(THINK_C)
|
||||
#ifdef __MACH__
|
||||
#include <sys/types.h>
|
||||
#else
|
||||
#include <unix.h>
|
||||
#include <math.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined (__SC__) && !defined (__DMC__)
|
||||
#define __SYMANTEC__
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(__PPCC__) || defined(__SYMANTEC__) || defined(__MRC__)
|
||||
#if defined(__PPCC__) || defined(__SC__) || defined(__MRC__)
|
||||
#include <types.h>
|
||||
#elif !defined(__MWERKS__) && !defined(THINK_C) && !defined(__acornriscos) && !defined(applec)
|
||||
#include <sys/types.h>
|
||||
@@ -87,16 +79,12 @@
|
||||
* additional includes are also done to pull in the
|
||||
* appropriate definitions we're looking for.
|
||||
*/
|
||||
#if defined(__MWERKS__) || defined(THINK_C) || defined(__PPCC__) || defined(__SYMANTEC__) || defined(__MRC__)
|
||||
#if defined(__MWERKS__) || defined(THINK_C) || defined(__PPCC__) || defined(__SC__) || defined(__MRC__)
|
||||
#include <stdlib.h>
|
||||
#ifndef __MACH__
|
||||
#define BSDTYPES
|
||||
#endif
|
||||
#define HAVE_UNISTD_H 0
|
||||
#elif defined(_WINDOWS) || defined(__WIN32__) || defined(_Windows)
|
||||
#define BSDTYPES
|
||||
#elif defined(__DJGPP__)
|
||||
#define BSDTYPES
|
||||
#elif (defined(_WINDOWS) || defined(__WIN32__) || defined(_Windows) || defined(_WIN32)) && !defined(unix)
|
||||
#define BSDTYPES
|
||||
#elif defined(OS2_16) || defined(OS2_32)
|
||||
#define BSDTYPES
|
||||
#elif defined(__acornriscos)
|
||||
@@ -131,11 +119,17 @@
|
||||
* then define BSDTYPES in your Makefile.
|
||||
*/
|
||||
#if defined(BSDTYPES)
|
||||
# ifndef _BSDTYPES_DEFINED
|
||||
# ifndef __u_char_defined
|
||||
typedef unsigned char u_char;
|
||||
typedef unsigned short u_short;
|
||||
typedef unsigned int u_int;
|
||||
typedef unsigned long u_long;
|
||||
#endif
|
||||
# define __u_char_defined
|
||||
# endif /* __u_char_defined */
|
||||
# define _BSDTYPES_DEFINED
|
||||
# endif /* _BSDTYPES_DEFINED */
|
||||
#endif /* BSDTYPES */
|
||||
|
||||
/*
|
||||
* dblparam_t is the type that a double precision
|
||||
@@ -143,7 +137,7 @@ typedef unsigned long u_long;
|
||||
* stack (when coerced by the compiler).
|
||||
*/
|
||||
/* Note: on MacPowerPC "extended" is undefined. So only use it for 68K-Macs */
|
||||
#if defined(__SYMANTEC__) || defined(THINK_C)
|
||||
#if defined(__SC__) || defined(THINK_C)
|
||||
typedef extended dblparam_t;
|
||||
#else
|
||||
typedef double dblparam_t;
|
||||
|
@@ -33,7 +33,7 @@
|
||||
* #defines on the command line, this file can be edited to
|
||||
* configure the library. Otherwise, one can override portability
|
||||
* and configuration-related definitions from a Makefile or command
|
||||
* line by defining FEATURE_SUPPORT and COMPRESSION_SUPPORT (see below).
|
||||
* line by defining COMPRESSION_SUPPORT (see below).
|
||||
*/
|
||||
|
||||
/*
|
||||
@@ -51,6 +51,8 @@
|
||||
* HOST_BIGENDIAN native cpu byte order: 1 if big-endian (Motorola)
|
||||
* or 0 if little-endian (Intel); this may be used
|
||||
* in codecs to optimize code
|
||||
* USE_64BIT_API set to 1 if tif_unix.c should use lseek64(),
|
||||
* fstat64() and stat64 allowing 2-4GB files.
|
||||
*/
|
||||
#ifndef HAVE_IEEEFP
|
||||
#define HAVE_IEEEFP 1
|
||||
@@ -62,24 +64,9 @@
|
||||
#define HOST_BIGENDIAN 1
|
||||
#endif
|
||||
|
||||
#ifndef FEATURE_SUPPORT
|
||||
/*
|
||||
* Feature support definitions:
|
||||
*
|
||||
* COLORIMETRY_SUPPORT enable support for 6.0 colorimetry tags
|
||||
* YCBCR_SUPPORT enable support for 6.0 YCbCr tags
|
||||
* CMYK_SUPPORT enable support for 6.0 CMYK tags
|
||||
* ICC_SUPPORT enable support for ICC profile tag
|
||||
* PHOTOSHOP_SUPPORT enable support for PHOTOSHOP resource tag
|
||||
* IPTC_SUPPORT enable support for RichTIFF IPTC tag
|
||||
*/
|
||||
#define COLORIMETRY_SUPPORT
|
||||
#define YCBCR_SUPPORT
|
||||
#define CMYK_SUPPORT
|
||||
#define ICC_SUPPORT
|
||||
#define PHOTOSHOP_SUPPORT
|
||||
#define IPTC_SUPPORT
|
||||
#endif /* FEATURE_SUPPORT */
|
||||
#ifndef USE_64BIT_API
|
||||
# define USE_64BIT_API 0
|
||||
#endif
|
||||
|
||||
#ifndef COMPRESSION_SUPPORT
|
||||
/*
|
||||
@@ -91,7 +78,7 @@
|
||||
* THUNDER_SUPPORT enable support for ThunderScan 4-bit RLE algorithm
|
||||
* NEXT_SUPPORT enable support for NeXT 2-bit RLE algorithm
|
||||
* OJPEG_SUPPORT enable support for 6.0-style JPEG DCT algorithms
|
||||
* (no builtin support, only a codec hook)
|
||||
* (requires IJG software)
|
||||
* JPEG_SUPPORT enable support for post-6.0-style JPEG DCT algorithms
|
||||
* (requires freely available IJG software, see tif_jpeg.c)
|
||||
* ZIP_SUPPORT enable support for Deflate algorithm
|
||||
@@ -127,6 +114,16 @@
|
||||
* or not to convert single-strip uncompressed images
|
||||
* to mutiple strips of ~8Kb--to reduce memory use)
|
||||
* SUBIFD_SUPPORT enable support for SubIFD tag (thumbnails and such)
|
||||
* DEFAULT_EXTRASAMPLE_AS_ALPHA
|
||||
* The RGBA interface will treat a fourth sample with
|
||||
* no EXTRASAMPLE_ value as being ASSOCALPHA. Many
|
||||
* packages produce RGBA files but don't mark the alpha
|
||||
* properly.
|
||||
* CHECK_JPEG_YCBCR_SUBSAMPLING
|
||||
* Enable picking up YCbCr subsampling info from the
|
||||
* JPEG data stream to support files lacking the tag.
|
||||
* See Bug 168 in Bugzilla, and JPEGFixupTestSubsampling()
|
||||
* for details.
|
||||
*/
|
||||
#ifndef STRIPCHOP_DEFAULT
|
||||
#define STRIPCHOP_DEFAULT TIFF_STRIPCHOP /* default is to enable */
|
||||
@@ -134,4 +131,23 @@
|
||||
#ifndef SUBIFD_SUPPORT
|
||||
#define SUBIFD_SUPPORT 1 /* enable SubIFD tag (330) support */
|
||||
#endif
|
||||
#ifndef DEFAULT_EXTRASAMPLE_AS_ALPHA
|
||||
#define DEFAULT_EXTRASAMPLE_AS_ALPHA 1
|
||||
#endif
|
||||
#ifndef CHECK_JPEG_YCBCR_SUBSAMPLING
|
||||
#define CHECK_JPEG_YCBCR_SUBSAMPLING 1
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Feature support definitions.
|
||||
* XXX: These macros are obsoleted. Don't use them in your apps!
|
||||
* Macros stays here for backward compatibility and should be always defined.
|
||||
*/
|
||||
#define COLORIMETRY_SUPPORT
|
||||
#define YCBCR_SUPPORT
|
||||
#define CMYK_SUPPORT
|
||||
#define ICC_SUPPORT
|
||||
#define PHOTOSHOP_SUPPORT
|
||||
#define IPTC_SUPPORT
|
||||
|
||||
#endif /* _TIFFCONF_ */
|
||||
|
@@ -4,23 +4,23 @@
|
||||
* Copyright (c) 1988-1997 Sam Leffler
|
||||
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* its documentation for any purpose is hereby granted without fee, provided
|
||||
* that (i) the above copyright notices and this permission notice appear in
|
||||
* all copies of the software and related documentation, and (ii) the names of
|
||||
* Sam Leffler and Silicon Graphics may not be used in any advertising or
|
||||
* publicity relating to the software without the specific, prior written
|
||||
* permission of Sam Leffler and Silicon Graphics.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
|
||||
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
|
||||
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
||||
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
||||
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
@@ -31,15 +31,7 @@
|
||||
* TIFF I/O Library Definitions.
|
||||
*/
|
||||
#include "tiff.h"
|
||||
|
||||
/*
|
||||
* This define can be used in code that requires
|
||||
* compilation-related definitions specific to a
|
||||
* version or versions of the library. Runtime
|
||||
* version checking should be done based on the
|
||||
* string returned by TIFFGetVersion.
|
||||
*/
|
||||
#define TIFFLIB_VERSION 19970127 /* January 27, 1997 */
|
||||
#include "tiffvers.h"
|
||||
|
||||
/*
|
||||
* TIFF is defined as an incomplete type to hide the
|
||||
@@ -63,7 +55,8 @@ typedef struct tiff TIFF;
|
||||
* NB: tsize_t is int32 and not uint32 because some functions
|
||||
* return -1.
|
||||
* NB: toff_t is not off_t for many reasons; TIFFs max out at
|
||||
* 32-bit file offsets being the most important
|
||||
* 32-bit file offsets being the most important, and to ensure
|
||||
* that it is unsigned, rather than signed.
|
||||
*/
|
||||
typedef uint32 ttag_t; /* directory tag */
|
||||
typedef uint16 tdir_t; /* directory index */
|
||||
@@ -72,12 +65,27 @@ typedef uint32 tstrip_t; /* strip number */
|
||||
typedef uint32 ttile_t; /* tile number */
|
||||
typedef int32 tsize_t; /* i/o size in bytes */
|
||||
typedef void* tdata_t; /* image data ref */
|
||||
typedef int32 toff_t; /* file offset */
|
||||
typedef uint32 toff_t; /* file offset */
|
||||
|
||||
#if !defined(__WIN32__) && (defined(_WIN32) || defined(WIN32))
|
||||
#define __WIN32__
|
||||
#endif
|
||||
|
||||
/*
|
||||
* On windows you should define USE_WIN32_FILEIO if you are using tif_win32.c
|
||||
* or AVOID_WIN32_FILEIO if you are using something else (like tif_unix.c).
|
||||
*
|
||||
* By default tif_win32.c is assumed on windows if not using the cygwin
|
||||
* environment.
|
||||
*/
|
||||
|
||||
#if defined(_WINDOWS) || defined(__WIN32__) || defined(_Windows)
|
||||
# if !defined(__CYGWIN) && !defined(AVOID_WIN32_FILEIO) && !defined(USE_WIN32_FILIO)
|
||||
# define USE_WIN32_FILEIO
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(USE_WIN32_FILEIO)
|
||||
#include <windows.h>
|
||||
#ifdef __WIN32__
|
||||
DECLARE_HANDLE(thandle_t); /* Win32 file handle */
|
||||
@@ -88,12 +96,6 @@ typedef HFILE thandle_t; /* client data handle */
|
||||
typedef void* thandle_t; /* client data handle */
|
||||
#endif
|
||||
|
||||
#if defined(__VISAGECPP__)
|
||||
#define LINKAGEMODE _Optlink
|
||||
#else
|
||||
#define LINKAGEMODE
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#endif
|
||||
@@ -112,39 +114,92 @@ typedef void* thandle_t; /* client data handle */
|
||||
#define TIFFPRINT_JPEGACTABLES 0x200 /* JPEG AC tables */
|
||||
#define TIFFPRINT_JPEGDCTABLES 0x200 /* JPEG DC tables */
|
||||
|
||||
/*
|
||||
* RGBA-style image support.
|
||||
/*
|
||||
* Colour conversion stuff
|
||||
*/
|
||||
|
||||
/* reference white */
|
||||
#define D65_X0 (95.0470F)
|
||||
#define D65_Y0 (100.0F)
|
||||
#define D65_Z0 (108.8827F)
|
||||
|
||||
#define D50_X0 (96.4250F)
|
||||
#define D50_Y0 (100.0F)
|
||||
#define D50_Z0 (82.4680F)
|
||||
|
||||
/* Structure for holding information about a display device. */
|
||||
|
||||
typedef unsigned char TIFFRGBValue; /* 8-bit samples */
|
||||
typedef struct _TIFFRGBAImage TIFFRGBAImage;
|
||||
/*
|
||||
* The image reading and conversion routines invoke
|
||||
* ``put routines'' to copy/image/whatever tiles of
|
||||
* raw image data. A default set of routines are
|
||||
* provided to convert/copy raw image data to 8-bit
|
||||
* packed ABGR format rasters. Applications can supply
|
||||
* alternate routines that unpack the data into a
|
||||
* different format or, for example, unpack the data
|
||||
* and draw the unpacked raster on the display.
|
||||
*/
|
||||
typedef void (LINKAGEMODE *tileContigRoutine)
|
||||
(TIFFRGBAImage*, uint32*, uint32, uint32, uint32, uint32, int32, int32,
|
||||
unsigned char*);
|
||||
typedef void (LINKAGEMODE *tileSeparateRoutine)
|
||||
(TIFFRGBAImage*, uint32*, uint32, uint32, uint32, uint32, int32, int32,
|
||||
unsigned char*, unsigned char*, unsigned char*, unsigned char*);
|
||||
/*
|
||||
* RGBA-reader state.
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
float d_mat[3][3]; /* XYZ -> luminance matrix */
|
||||
float d_YCR; /* Light o/p for reference white */
|
||||
float d_YCG;
|
||||
float d_YCB;
|
||||
uint32 d_Vrwr; /* Pixel values for ref. white */
|
||||
uint32 d_Vrwg;
|
||||
uint32 d_Vrwb;
|
||||
float d_Y0R; /* Residual light for black pixel */
|
||||
float d_Y0G;
|
||||
float d_Y0B;
|
||||
float d_gammaR; /* Gamma values for the three guns */
|
||||
float d_gammaG;
|
||||
float d_gammaB;
|
||||
} TIFFDisplay;
|
||||
|
||||
typedef struct { /* YCbCr->RGB support */
|
||||
TIFFRGBValue* clamptab; /* range clamping table */
|
||||
int* Cr_r_tab;
|
||||
int* Cb_b_tab;
|
||||
int32* Cr_g_tab;
|
||||
int32* Cb_g_tab;
|
||||
float coeffs[3]; /* cached for repeated use */
|
||||
int32* Y_tab;
|
||||
} TIFFYCbCrToRGB;
|
||||
|
||||
typedef struct { /* CIE Lab 1976->RGB support */
|
||||
int range; /* Size of conversion table */
|
||||
#define CIELABTORGB_TABLE_RANGE 1500
|
||||
float rstep, gstep, bstep;
|
||||
float X0, Y0, Z0; /* Reference white point */
|
||||
TIFFDisplay display;
|
||||
float Yr2r[CIELABTORGB_TABLE_RANGE + 1]; /* Conversion of Yr to r */
|
||||
float Yg2g[CIELABTORGB_TABLE_RANGE + 1]; /* Conversion of Yg to g */
|
||||
float Yb2b[CIELABTORGB_TABLE_RANGE + 1]; /* Conversion of Yb to b */
|
||||
} TIFFCIELabToRGB;
|
||||
|
||||
extern int TIFFCIELabToRGBInit(TIFFCIELabToRGB*, TIFFDisplay *, float*);
|
||||
extern void TIFFCIELabToXYZ(TIFFCIELabToRGB *, uint32, int32, int32,
|
||||
float *, float *, float *);
|
||||
extern void TIFFXYZToRGB(TIFFCIELabToRGB *, float, float, float,
|
||||
uint32 *, uint32 *, uint32 *);
|
||||
|
||||
extern int TIFFYCbCrToRGBInit(TIFFYCbCrToRGB*, float*, float*);
|
||||
extern void TIFFYCbCrtoRGB(TIFFYCbCrToRGB *, uint32, int32, int32,
|
||||
uint32 *, uint32 *, uint32 *);
|
||||
|
||||
/*
|
||||
* RGBA-style image support.
|
||||
*/
|
||||
typedef struct _TIFFRGBAImage TIFFRGBAImage;
|
||||
/*
|
||||
* The image reading and conversion routines invoke
|
||||
* ``put routines'' to copy/image/whatever tiles of
|
||||
* raw image data. A default set of routines are
|
||||
* provided to convert/copy raw image data to 8-bit
|
||||
* packed ABGR format rasters. Applications can supply
|
||||
* alternate routines that unpack the data into a
|
||||
* different format or, for example, unpack the data
|
||||
* and draw the unpacked raster on the display.
|
||||
*/
|
||||
typedef void (*tileContigRoutine)
|
||||
(TIFFRGBAImage*, uint32*, uint32, uint32, uint32, uint32, int32, int32,
|
||||
unsigned char*);
|
||||
typedef void (*tileSeparateRoutine)
|
||||
(TIFFRGBAImage*, uint32*, uint32, uint32, uint32, uint32, int32, int32,
|
||||
unsigned char*, unsigned char*, unsigned char*, unsigned char*);
|
||||
/*
|
||||
* RGBA-reader state.
|
||||
*/
|
||||
struct _TIFFRGBAImage {
|
||||
TIFF* tif; /* image handle */
|
||||
int stoponerr; /* stop on read error */
|
||||
@@ -155,12 +210,13 @@ struct _TIFFRGBAImage {
|
||||
uint16 bitspersample; /* image bits/sample */
|
||||
uint16 samplesperpixel; /* image samples/pixel */
|
||||
uint16 orientation; /* image orientation */
|
||||
uint16 req_orientation; /* requested orientation */
|
||||
uint16 photometric; /* image photometric interp */
|
||||
uint16* redcmap; /* colormap pallete */
|
||||
uint16* greencmap;
|
||||
uint16* bluecmap;
|
||||
/* get image data routine */
|
||||
int (LINKAGEMODE *get)(TIFFRGBAImage*, uint32*, uint32, uint32);
|
||||
int (*get)(TIFFRGBAImage*, uint32*, uint32, uint32);
|
||||
union {
|
||||
void (*any)(TIFFRGBAImage*);
|
||||
tileContigRoutine contig;
|
||||
@@ -170,6 +226,7 @@ struct _TIFFRGBAImage {
|
||||
uint32** BWmap; /* black&white map */
|
||||
uint32** PALmap; /* palette image map */
|
||||
TIFFYCbCrToRGB* ycbcr; /* YCbCr conversion state */
|
||||
TIFFCIELabToRGB* cielab; /* CIE L*a*b conversion state */
|
||||
|
||||
int row_offset;
|
||||
int col_offset;
|
||||
@@ -191,7 +248,7 @@ struct _TIFFRGBAImage {
|
||||
* More codecs may be registered through calls to the library
|
||||
* and/or the builtin implementations may be overridden.
|
||||
*/
|
||||
typedef int (LINKAGEMODE *TIFFInitMethod)(TIFF*, int);
|
||||
typedef int (*TIFFInitMethod)(TIFF*, int);
|
||||
typedef struct {
|
||||
char* name;
|
||||
uint16 scheme;
|
||||
@@ -201,23 +258,29 @@ typedef struct {
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
/* share internal LogLuv conversion routines? */
|
||||
#ifndef LOGLUV_PUBLIC
|
||||
#define LOGLUV_PUBLIC 1
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
typedef void (LINKAGEMODE *TIFFErrorHandler)(const char*, const char*, va_list);
|
||||
typedef tsize_t (LINKAGEMODE *TIFFReadWriteProc)(thandle_t, tdata_t, tsize_t);
|
||||
typedef toff_t (LINKAGEMODE *TIFFSeekProc)(thandle_t, toff_t, int);
|
||||
typedef int (LINKAGEMODE *TIFFCloseProc)(thandle_t);
|
||||
typedef toff_t (LINKAGEMODE *TIFFSizeProc)(thandle_t);
|
||||
typedef int (LINKAGEMODE *TIFFMapFileProc)(thandle_t, tdata_t*, toff_t*);
|
||||
typedef void (LINKAGEMODE *TIFFUnmapFileProc)(thandle_t, tdata_t, toff_t);
|
||||
typedef void (LINKAGEMODE *TIFFExtendProc)(TIFF*);
|
||||
typedef void (*TIFFErrorHandler)(const char*, const char*, va_list);
|
||||
typedef tsize_t (*TIFFReadWriteProc)(thandle_t, tdata_t, tsize_t);
|
||||
typedef toff_t (*TIFFSeekProc)(thandle_t, toff_t, int);
|
||||
typedef int (*TIFFCloseProc)(thandle_t);
|
||||
typedef toff_t (*TIFFSizeProc)(thandle_t);
|
||||
typedef int (*TIFFMapFileProc)(thandle_t, tdata_t*, toff_t*);
|
||||
typedef void (*TIFFUnmapFileProc)(thandle_t, tdata_t, toff_t);
|
||||
typedef void (*TIFFExtendProc)(TIFF*);
|
||||
|
||||
extern const char* TIFFGetVersion(void);
|
||||
|
||||
extern const TIFFCodec* TIFFFindCODEC(uint16);
|
||||
extern TIFFCodec* TIFFRegisterCODEC(uint16, const char*, TIFFInitMethod);
|
||||
extern void TIFFUnRegisterCODEC(TIFFCodec*);
|
||||
extern int TIFFIsCODECConfigured(uint16);
|
||||
|
||||
extern tdata_t _TIFFmalloc(tsize_t);
|
||||
extern tdata_t _TIFFrealloc(tdata_t, tsize_t);
|
||||
@@ -237,6 +300,7 @@ extern int TIFFReadDirectory(TIFF*);
|
||||
extern tsize_t TIFFScanlineSize(TIFF*);
|
||||
extern tsize_t TIFFRasterScanlineSize(TIFF*);
|
||||
extern tsize_t TIFFStripSize(TIFF*);
|
||||
extern tsize_t TIFFRawStripSize(TIFF*, tstrip_t);
|
||||
extern tsize_t TIFFVStripSize(TIFF*, uint32);
|
||||
extern tsize_t TIFFTileRowSize(TIFF*);
|
||||
extern tsize_t TIFFTileSize(TIFF*);
|
||||
@@ -257,6 +321,9 @@ extern tstrip_t TIFFCurrentStrip(TIFF*);
|
||||
extern ttile_t TIFFCurrentTile(TIFF*);
|
||||
extern int TIFFReadBufferSetup(TIFF*, tdata_t, tsize_t);
|
||||
extern int TIFFWriteBufferSetup(TIFF*, tdata_t, tsize_t);
|
||||
extern int TIFFSetupStrips(TIFF *);
|
||||
extern int TIFFWriteCheck(TIFF*, int, const char *);
|
||||
extern int TIFFCreateDirectory(TIFF*);
|
||||
extern int TIFFLastDirectory(TIFF*);
|
||||
extern int TIFFSetDirectory(TIFF*, tdir_t);
|
||||
extern int TIFFSetSubDirectory(TIFF*, uint32);
|
||||
@@ -264,6 +331,8 @@ extern int TIFFUnlinkDirectory(TIFF*, tdir_t);
|
||||
extern int TIFFSetField(TIFF*, ttag_t, ...);
|
||||
extern int TIFFVSetField(TIFF*, ttag_t, va_list);
|
||||
extern int TIFFWriteDirectory(TIFF *);
|
||||
extern int TIFFCheckpointDirectory(TIFF *);
|
||||
extern int TIFFRewriteDirectory(TIFF *);
|
||||
extern int TIFFReassignTagToIgnore(enum TIFFIgnoreSense, int);
|
||||
|
||||
#if defined(c_plusplus) || defined(__cplusplus)
|
||||
@@ -271,11 +340,14 @@ extern void TIFFPrintDirectory(TIFF*, FILE*, long = 0);
|
||||
extern int TIFFReadScanline(TIFF*, tdata_t, uint32, tsample_t = 0);
|
||||
extern int TIFFWriteScanline(TIFF*, tdata_t, uint32, tsample_t = 0);
|
||||
extern int TIFFReadRGBAImage(TIFF*, uint32, uint32, uint32*, int = 0);
|
||||
extern int TIFFReadRGBAImageOriented(TIFF*, uint32, uint32, uint32*,
|
||||
int = ORIENTATION_BOTLEFT, int = 0);
|
||||
#else
|
||||
extern void TIFFPrintDirectory(TIFF*, FILE*, long);
|
||||
extern int TIFFReadScanline(TIFF*, tdata_t, uint32, tsample_t);
|
||||
extern int TIFFWriteScanline(TIFF*, tdata_t, uint32, tsample_t);
|
||||
extern int TIFFReadRGBAImage(TIFF*, uint32, uint32, uint32*, int);
|
||||
extern int TIFFReadRGBAImageOriented(TIFF*, uint32, uint32, uint32*, int, int);
|
||||
#endif
|
||||
|
||||
extern int TIFFReadRGBAStrip(TIFF*, tstrip_t, uint32 * );
|
||||
@@ -315,6 +387,7 @@ extern tsize_t TIFFWriteEncodedStrip(TIFF*, tstrip_t, tdata_t, tsize_t);
|
||||
extern tsize_t TIFFWriteRawStrip(TIFF*, tstrip_t, tdata_t, tsize_t);
|
||||
extern tsize_t TIFFWriteEncodedTile(TIFF*, ttile_t, tdata_t, tsize_t);
|
||||
extern tsize_t TIFFWriteRawTile(TIFF*, ttile_t, tdata_t, tsize_t);
|
||||
extern int TIFFDataWidth(TIFFDataType); /* table of tag datatype widths */
|
||||
extern void TIFFSetWriteOffset(TIFF*, toff_t);
|
||||
extern void TIFFSwabShort(uint16*);
|
||||
extern void TIFFSwabLong(uint32*);
|
||||
@@ -324,6 +397,80 @@ extern void TIFFSwabArrayOfLong(uint32*, unsigned long);
|
||||
extern void TIFFSwabArrayOfDouble(double*, unsigned long);
|
||||
extern void TIFFReverseBits(unsigned char *, unsigned long);
|
||||
extern const unsigned char* TIFFGetBitRevTable(int);
|
||||
|
||||
#ifdef LOGLUV_PUBLIC
|
||||
#define U_NEU 0.210526316
|
||||
#define V_NEU 0.473684211
|
||||
#define UVSCALE 410.
|
||||
extern double LogL16toY(int);
|
||||
extern double LogL10toY(int);
|
||||
extern void XYZtoRGB24(float*, uint8*);
|
||||
extern int uv_decode(double*, double*, int);
|
||||
extern void LogLuv24toXYZ(uint32, float*);
|
||||
extern void LogLuv32toXYZ(uint32, float*);
|
||||
#if defined(c_plusplus) || defined(__cplusplus)
|
||||
extern int LogL16fromY(double, int = SGILOGENCODE_NODITHER);
|
||||
extern int LogL10fromY(double, int = SGILOGENCODE_NODITHER);
|
||||
extern int uv_encode(double, double, int = SGILOGENCODE_NODITHER);
|
||||
extern uint32 LogLuv24fromXYZ(float*, int = SGILOGENCODE_NODITHER);
|
||||
extern uint32 LogLuv32fromXYZ(float*, int = SGILOGENCODE_NODITHER);
|
||||
#else
|
||||
extern int LogL16fromY(double, int);
|
||||
extern int LogL10fromY(double, int);
|
||||
extern int uv_encode(double, double, int);
|
||||
extern uint32 LogLuv24fromXYZ(float*, int);
|
||||
extern uint32 LogLuv32fromXYZ(float*, int);
|
||||
#endif
|
||||
#endif /* LOGLUV_PUBLIC */
|
||||
|
||||
/*
|
||||
** New stuff going public in 3.6.x.
|
||||
*/
|
||||
extern int TIFFGetTagListCount( TIFF * );
|
||||
extern ttag_t TIFFGetTagListEntry( TIFF *, int tag_index );
|
||||
|
||||
#define TIFF_ANY TIFF_NOTYPE /* for field descriptor searching */
|
||||
#define TIFF_VARIABLE -1 /* marker for variable length tags */
|
||||
#define TIFF_SPP -2 /* marker for SamplesPerPixel tags */
|
||||
#define TIFF_VARIABLE2 -3 /* marker for uint32 var-length tags */
|
||||
|
||||
#define FIELD_CUSTOM 65
|
||||
|
||||
typedef struct {
|
||||
ttag_t field_tag; /* field's tag */
|
||||
short field_readcount; /* read count/TIFF_VARIABLE/TIFF_SPP */
|
||||
short field_writecount; /* write count/TIFF_VARIABLE */
|
||||
TIFFDataType field_type; /* type of associated data */
|
||||
unsigned short field_bit; /* bit in fieldsset bit vector */
|
||||
unsigned char field_oktochange; /* if true, can change while writing */
|
||||
unsigned char field_passcount; /* if true, pass dir count on set */
|
||||
char *field_name; /* ASCII name */
|
||||
} TIFFFieldInfo;
|
||||
|
||||
typedef struct _TIFFTagValue {
|
||||
const TIFFFieldInfo *info;
|
||||
int count;
|
||||
void *value;
|
||||
} TIFFTagValue;
|
||||
|
||||
extern void TIFFMergeFieldInfo(TIFF*, const TIFFFieldInfo[], int);
|
||||
extern const TIFFFieldInfo* TIFFFindFieldInfo(TIFF*, ttag_t, TIFFDataType);
|
||||
extern const TIFFFieldInfo* TIFFFieldWithTag(TIFF*, ttag_t);
|
||||
|
||||
typedef int (*TIFFVSetMethod)(TIFF*, ttag_t, va_list);
|
||||
typedef int (*TIFFVGetMethod)(TIFF*, ttag_t, va_list);
|
||||
typedef void (*TIFFPrintMethod)(TIFF*, FILE*, long);
|
||||
|
||||
typedef struct {
|
||||
TIFFVSetMethod vsetfield; /* tag set routine */
|
||||
TIFFVGetMethod vgetfield; /* tag get routine */
|
||||
TIFFPrintMethod printdir; /* directory print routine */
|
||||
} TIFFTagMethods;
|
||||
|
||||
extern TIFFTagMethods *TIFFAccessTagMethods( TIFF * );
|
||||
extern void *TIFFGetClientInfo( TIFF *, const char * );
|
||||
extern void TIFFSetClientInfo( TIFF *, void *, const char * );
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
@@ -4,23 +4,23 @@
|
||||
* Copyright (c) 1988-1997 Sam Leffler
|
||||
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* Permission to use, copy, modify, distribute, and sell this software and
|
||||
* its documentation for any purpose is hereby granted without fee, provided
|
||||
* that (i) the above copyright notices and this permission notice appear in
|
||||
* all copies of the software and related documentation, and (ii) the names of
|
||||
* Sam Leffler and Silicon Graphics may not be used in any advertising or
|
||||
* publicity relating to the software without the specific, prior written
|
||||
* permission of Sam Leffler and Silicon Graphics.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
|
||||
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
|
||||
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
||||
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
||||
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
* a port.h file that reflects the system capabilities.
|
||||
* Doing this obviates all the dreck done in tiffcomp.h.
|
||||
*/
|
||||
#if (defined(unix) || defined(__unix)) && !defined(__DJGPP__)
|
||||
#if defined(unix) || defined(__unix)
|
||||
#include "port.h"
|
||||
#include "tiffconf.h"
|
||||
#else
|
||||
@@ -49,6 +49,12 @@
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
typedef struct client_info {
|
||||
struct client_info *next;
|
||||
void *data;
|
||||
char *name;
|
||||
} TIFFClientInfoLink;
|
||||
|
||||
/*
|
||||
* Typedefs for ``method pointers'' used internally.
|
||||
*/
|
||||
@@ -58,14 +64,11 @@ typedef tidataval_t* tidata_t; /* reference to internal image data */
|
||||
typedef void (*TIFFVoidMethod)(TIFF*);
|
||||
typedef int (*TIFFBoolMethod)(TIFF*);
|
||||
typedef int (*TIFFPreMethod)(TIFF*, tsample_t);
|
||||
typedef int (LINKAGEMODE *TIFFCodeMethod)(TIFF*, tidata_t, tsize_t, tsample_t);
|
||||
typedef int (LINKAGEMODE *TIFFSeekMethod)(TIFF*, uint32);
|
||||
typedef void (LINKAGEMODE *TIFFPostMethod)(TIFF*, tidata_t, tsize_t);
|
||||
typedef int (*TIFFVSetMethod)(TIFF*, ttag_t, va_list);
|
||||
typedef int (*TIFFVGetMethod)(TIFF*, ttag_t, va_list);
|
||||
typedef void (LINKAGEMODE *TIFFPrintMethod)(TIFF*, FILE*, long);
|
||||
typedef uint32 (LINKAGEMODE *TIFFStripMethod)(TIFF*, uint32);
|
||||
typedef void (LINKAGEMODE *TIFFTileMethod)(TIFF*, uint32*, uint32*);
|
||||
typedef int (*TIFFCodeMethod)(TIFF*, tidata_t, tsize_t, tsample_t);
|
||||
typedef int (*TIFFSeekMethod)(TIFF*, uint32);
|
||||
typedef void (*TIFFPostMethod)(TIFF*, tidata_t, tsize_t);
|
||||
typedef uint32 (*TIFFStripMethod)(TIFF*, uint32);
|
||||
typedef void (*TIFFTileMethod)(TIFF*, uint32*, uint32*);
|
||||
|
||||
struct tiff {
|
||||
char* tif_name; /* name of open file */
|
||||
@@ -85,13 +88,15 @@ struct tiff {
|
||||
#define TIFF_MAPPED 0x0800 /* file is mapped into memory */
|
||||
#define TIFF_POSTENCODE 0x1000 /* need call to postencode routine */
|
||||
#define TIFF_INSUBIFD 0x2000 /* currently writing a subifd */
|
||||
#define TIFF_UPSAMPLED 0x4000 /* library is doing data up-sampling */
|
||||
#define TIFF_UPSAMPLED 0x4000 /* library is doing data up-sampling */
|
||||
#define TIFF_STRIPCHOP 0x8000 /* enable strip chopping support */
|
||||
toff_t tif_diroff; /* file offset of current directory */
|
||||
toff_t tif_nextdiroff; /* file offset of following directory */
|
||||
toff_t* tif_dirlist; /* list of offsets to already seen */
|
||||
/* directories to prevent IFD looping */
|
||||
uint16 tif_dirnumber; /* number of already seen directories */
|
||||
TIFFDirectory tif_dir; /* internal rep of current directory */
|
||||
TIFFHeader tif_header; /* file's header block */
|
||||
tidata_t tif_clientdir; /* client TIFF directory */
|
||||
const int* tif_typeshift; /* data type shift counts */
|
||||
const long* tif_typemask; /* data type masks */
|
||||
uint32 tif_row; /* current scanline */
|
||||
@@ -108,9 +113,11 @@ struct tiff {
|
||||
ttile_t tif_curtile; /* current tile for read/write */
|
||||
tsize_t tif_tilesize; /* # of bytes in a tile */
|
||||
/* compression scheme hooks */
|
||||
int tif_decodestatus;
|
||||
TIFFBoolMethod tif_setupdecode;/* called once before predecode */
|
||||
TIFFPreMethod tif_predecode; /* pre- row/strip/tile decoding */
|
||||
TIFFBoolMethod tif_setupencode;/* called once before preencode */
|
||||
int tif_encodestatus;
|
||||
TIFFPreMethod tif_preencode; /* pre- row/strip/tile encoding */
|
||||
TIFFBoolMethod tif_postencode; /* post- row/strip/tile encoding */
|
||||
TIFFCodeMethod tif_decoderow; /* scanline decoding routine */
|
||||
@@ -149,9 +156,8 @@ struct tiff {
|
||||
/* tag support */
|
||||
TIFFFieldInfo** tif_fieldinfo; /* sorted table of registered tags */
|
||||
int tif_nfields; /* # entries in registered tag table */
|
||||
TIFFVSetMethod tif_vsetfield; /* tag set routine */
|
||||
TIFFVGetMethod tif_vgetfield; /* tag get routine */
|
||||
TIFFPrintMethod tif_printdir; /* directory print routine */
|
||||
TIFFTagMethods tif_tagmethods; /* tag get/set/print routines */
|
||||
TIFFClientInfoLink *tif_clientinfo; /* extra client information. */
|
||||
};
|
||||
|
||||
#define isPseudoTag(t) (t > 0xffff) /* is tag value normal or pseudo */
|
||||
@@ -180,7 +186,7 @@ struct tiff {
|
||||
*/
|
||||
#ifndef ReadOK
|
||||
#define ReadOK(tif, buf, size) \
|
||||
(TIFFReadFile(tif, (tdata_t) buf, (tsize_t) size) == (tsize_t) size)
|
||||
(TIFFReadFile(tif, (tdata_t) buf, (tsize_t)(size)) == (tsize_t)(size))
|
||||
#endif
|
||||
#ifndef SeekOK
|
||||
#define SeekOK(tif, off) \
|
||||
@@ -192,8 +198,12 @@ struct tiff {
|
||||
#endif
|
||||
|
||||
/* NB: the uint32 casts are to silence certain ANSI-C compilers */
|
||||
#define TIFFhowmany(x, y) ((((uint32)(x))+(((uint32)(y))-1))/((uint32)(y)))
|
||||
#define TIFFroundup(x, y) (TIFFhowmany(x,y)*((uint32)(y)))
|
||||
#define TIFFhowmany(x, y) ((((uint32)(x))+(((uint32)(y))-1))/((uint32)(y)))
|
||||
#define TIFFhowmany8(x) (((x)&0x07)?((uint32)(x)>>3)+1:(uint32)(x)>>3)
|
||||
#define TIFFroundup(x, y) (TIFFhowmany(x,y)*(y))
|
||||
|
||||
#define TIFFmax(A,B) ((A)>(B)?(A):(B))
|
||||
#define TIFFmin(A,B) ((A)<(B)?(A):(B))
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
@@ -206,15 +216,16 @@ extern int _TIFFNoRowDecode(TIFF*, tidata_t, tsize_t, tsample_t);
|
||||
extern int _TIFFNoStripDecode(TIFF*, tidata_t, tsize_t, tsample_t);
|
||||
extern int _TIFFNoTileDecode(TIFF*, tidata_t, tsize_t, tsample_t);
|
||||
extern void _TIFFNoPostDecode(TIFF*, tidata_t, tsize_t);
|
||||
extern int _TIFFNoPreCode (TIFF*, tsample_t);
|
||||
extern int _TIFFNoSeek(TIFF*, uint32);
|
||||
extern void _TIFFSwab16BitData(TIFF*, tidata_t, tsize_t);
|
||||
extern void _TIFFSwab32BitData(TIFF*, tidata_t, tsize_t);
|
||||
extern void _TIFFSwab64BitData(TIFF*, tidata_t, tsize_t);
|
||||
extern int TIFFFlushData1(TIFF*);
|
||||
extern void TIFFFreeDirectory(TIFF*);
|
||||
extern int TIFFDefaultDirectory(TIFF*);
|
||||
extern int TIFFSetCompressionScheme(TIFF*, uint16);
|
||||
extern int TIFFSetDefaultCompressionState(TIFF*);
|
||||
extern int TIFFFlushData1(TIFF*);
|
||||
extern void TIFFFreeDirectory(TIFF*);
|
||||
extern int TIFFDefaultDirectory(TIFF*);
|
||||
extern int TIFFSetCompressionScheme(TIFF*, int);
|
||||
extern int TIFFSetDefaultCompressionState(TIFF*);
|
||||
extern uint32 _TIFFDefaultStripSize(TIFF*, uint32);
|
||||
extern void _TIFFDefaultTileSize(TIFF*, uint32*, uint32*);
|
||||
|
||||
@@ -231,7 +242,7 @@ extern void _TIFFprintAsciiTag(FILE*, const char*, const char*);
|
||||
GLOBALDATA(TIFFErrorHandler,_TIFFwarningHandler);
|
||||
GLOBALDATA(TIFFErrorHandler,_TIFFerrorHandler);
|
||||
|
||||
extern int TIFFInitDumpMode(TIFF*, int);
|
||||
extern int TIFFInitDumpMode(TIFF*, int);
|
||||
#ifdef PACKBITS_SUPPORT
|
||||
extern int TIFFInitPackBits(TIFF*, int);
|
||||
#endif
|
||||
|
@@ -1,173 +1,173 @@
|
||||
/* Version 1.0 generated April 7, 1997 by Greg Ward Larson, SGI */
|
||||
#define UV_SQSIZ 0.003500
|
||||
#define UV_SQSIZ (float)0.003500
|
||||
#define UV_NDIVS 16289
|
||||
#define UV_VSTART 0.016940
|
||||
#define UV_VSTART (float)0.016940
|
||||
#define UV_NVS 163
|
||||
static struct {
|
||||
float ustart;
|
||||
short nus, ncum;
|
||||
} uv_row[UV_NVS] = {
|
||||
{ 0.247663, 4, 0 },
|
||||
{ 0.243779, 6, 4 },
|
||||
{ 0.241684, 7, 10 },
|
||||
{ 0.237874, 9, 17 },
|
||||
{ 0.235906, 10, 26 },
|
||||
{ 0.232153, 12, 36 },
|
||||
{ 0.228352, 14, 48 },
|
||||
{ 0.226259, 15, 62 },
|
||||
{ 0.222371, 17, 77 },
|
||||
{ 0.220410, 18, 94 },
|
||||
{ 0.214710, 21, 112 },
|
||||
{ 0.212714, 22, 133 },
|
||||
{ 0.210721, 23, 155 },
|
||||
{ 0.204976, 26, 178 },
|
||||
{ 0.202986, 27, 204 },
|
||||
{ 0.199245, 29, 231 },
|
||||
{ 0.195525, 31, 260 },
|
||||
{ 0.193560, 32, 291 },
|
||||
{ 0.189878, 34, 323 },
|
||||
{ 0.186216, 36, 357 },
|
||||
{ 0.186216, 36, 393 },
|
||||
{ 0.182592, 38, 429 },
|
||||
{ 0.179003, 40, 467 },
|
||||
{ 0.175466, 42, 507 },
|
||||
{ 0.172001, 44, 549 },
|
||||
{ 0.172001, 44, 593 },
|
||||
{ 0.168612, 46, 637 },
|
||||
{ 0.168612, 46, 683 },
|
||||
{ 0.163575, 49, 729 },
|
||||
{ 0.158642, 52, 778 },
|
||||
{ 0.158642, 52, 830 },
|
||||
{ 0.158642, 52, 882 },
|
||||
{ 0.153815, 55, 934 },
|
||||
{ 0.153815, 55, 989 },
|
||||
{ 0.149097, 58, 1044 },
|
||||
{ 0.149097, 58, 1102 },
|
||||
{ 0.142746, 62, 1160 },
|
||||
{ 0.142746, 62, 1222 },
|
||||
{ 0.142746, 62, 1284 },
|
||||
{ 0.138270, 65, 1346 },
|
||||
{ 0.138270, 65, 1411 },
|
||||
{ 0.138270, 65, 1476 },
|
||||
{ 0.132166, 69, 1541 },
|
||||
{ 0.132166, 69, 1610 },
|
||||
{ 0.126204, 73, 1679 },
|
||||
{ 0.126204, 73, 1752 },
|
||||
{ 0.126204, 73, 1825 },
|
||||
{ 0.120381, 77, 1898 },
|
||||
{ 0.120381, 77, 1975 },
|
||||
{ 0.120381, 77, 2052 },
|
||||
{ 0.120381, 77, 2129 },
|
||||
{ 0.112962, 82, 2206 },
|
||||
{ 0.112962, 82, 2288 },
|
||||
{ 0.112962, 82, 2370 },
|
||||
{ 0.107450, 86, 2452 },
|
||||
{ 0.107450, 86, 2538 },
|
||||
{ 0.107450, 86, 2624 },
|
||||
{ 0.107450, 86, 2710 },
|
||||
{ 0.100343, 91, 2796 },
|
||||
{ 0.100343, 91, 2887 },
|
||||
{ 0.100343, 91, 2978 },
|
||||
{ 0.095126, 95, 3069 },
|
||||
{ 0.095126, 95, 3164 },
|
||||
{ 0.095126, 95, 3259 },
|
||||
{ 0.095126, 95, 3354 },
|
||||
{ 0.088276, 100, 3449 },
|
||||
{ 0.088276, 100, 3549 },
|
||||
{ 0.088276, 100, 3649 },
|
||||
{ 0.088276, 100, 3749 },
|
||||
{ 0.081523, 105, 3849 },
|
||||
{ 0.081523, 105, 3954 },
|
||||
{ 0.081523, 105, 4059 },
|
||||
{ 0.081523, 105, 4164 },
|
||||
{ 0.074861, 110, 4269 },
|
||||
{ 0.074861, 110, 4379 },
|
||||
{ 0.074861, 110, 4489 },
|
||||
{ 0.074861, 110, 4599 },
|
||||
{ 0.068290, 115, 4709 },
|
||||
{ 0.068290, 115, 4824 },
|
||||
{ 0.068290, 115, 4939 },
|
||||
{ 0.068290, 115, 5054 },
|
||||
{ 0.063573, 119, 5169 },
|
||||
{ 0.063573, 119, 5288 },
|
||||
{ 0.063573, 119, 5407 },
|
||||
{ 0.063573, 119, 5526 },
|
||||
{ 0.057219, 124, 5645 },
|
||||
{ 0.057219, 124, 5769 },
|
||||
{ 0.057219, 124, 5893 },
|
||||
{ 0.057219, 124, 6017 },
|
||||
{ 0.050985, 129, 6141 },
|
||||
{ 0.050985, 129, 6270 },
|
||||
{ 0.050985, 129, 6399 },
|
||||
{ 0.050985, 129, 6528 },
|
||||
{ 0.050985, 129, 6657 },
|
||||
{ 0.044859, 134, 6786 },
|
||||
{ 0.044859, 134, 6920 },
|
||||
{ 0.044859, 134, 7054 },
|
||||
{ 0.044859, 134, 7188 },
|
||||
{ 0.040571, 138, 7322 },
|
||||
{ 0.040571, 138, 7460 },
|
||||
{ 0.040571, 138, 7598 },
|
||||
{ 0.040571, 138, 7736 },
|
||||
{ 0.036339, 142, 7874 },
|
||||
{ 0.036339, 142, 8016 },
|
||||
{ 0.036339, 142, 8158 },
|
||||
{ 0.036339, 142, 8300 },
|
||||
{ 0.032139, 146, 8442 },
|
||||
{ 0.032139, 146, 8588 },
|
||||
{ 0.032139, 146, 8734 },
|
||||
{ 0.032139, 146, 8880 },
|
||||
{ 0.027947, 150, 9026 },
|
||||
{ 0.027947, 150, 9176 },
|
||||
{ 0.027947, 150, 9326 },
|
||||
{ 0.023739, 154, 9476 },
|
||||
{ 0.023739, 154, 9630 },
|
||||
{ 0.023739, 154, 9784 },
|
||||
{ 0.023739, 154, 9938 },
|
||||
{ 0.019504, 158, 10092 },
|
||||
{ 0.019504, 158, 10250 },
|
||||
{ 0.019504, 158, 10408 },
|
||||
{ 0.016976, 161, 10566 },
|
||||
{ 0.016976, 161, 10727 },
|
||||
{ 0.016976, 161, 10888 },
|
||||
{ 0.016976, 161, 11049 },
|
||||
{ 0.012639, 165, 11210 },
|
||||
{ 0.012639, 165, 11375 },
|
||||
{ 0.012639, 165, 11540 },
|
||||
{ 0.009991, 168, 11705 },
|
||||
{ 0.009991, 168, 11873 },
|
||||
{ 0.009991, 168, 12041 },
|
||||
{ 0.009016, 170, 12209 },
|
||||
{ 0.009016, 170, 12379 },
|
||||
{ 0.009016, 170, 12549 },
|
||||
{ 0.006217, 173, 12719 },
|
||||
{ 0.006217, 173, 12892 },
|
||||
{ 0.005097, 175, 13065 },
|
||||
{ 0.005097, 175, 13240 },
|
||||
{ 0.005097, 175, 13415 },
|
||||
{ 0.003909, 177, 13590 },
|
||||
{ 0.003909, 177, 13767 },
|
||||
{ 0.002340, 177, 13944 },
|
||||
{ 0.002389, 170, 14121 },
|
||||
{ 0.001068, 164, 14291 },
|
||||
{ 0.001653, 157, 14455 },
|
||||
{ 0.000717, 150, 14612 },
|
||||
{ 0.001614, 143, 14762 },
|
||||
{ 0.000270, 136, 14905 },
|
||||
{ 0.000484, 129, 15041 },
|
||||
{ 0.001103, 123, 15170 },
|
||||
{ 0.001242, 115, 15293 },
|
||||
{ 0.001188, 109, 15408 },
|
||||
{ 0.001011, 103, 15517 },
|
||||
{ 0.000709, 97, 15620 },
|
||||
{ 0.000301, 89, 15717 },
|
||||
{ 0.002416, 82, 15806 },
|
||||
{ 0.003251, 76, 15888 },
|
||||
{ 0.003246, 69, 15964 },
|
||||
{ 0.004141, 62, 16033 },
|
||||
{ 0.005963, 55, 16095 },
|
||||
{ 0.008839, 47, 16150 },
|
||||
{ 0.010490, 40, 16197 },
|
||||
{ 0.016994, 31, 16237 },
|
||||
{ 0.023659, 21, 16268 },
|
||||
(float)0.247663, 4, 0,
|
||||
(float)0.243779, 6, 4,
|
||||
(float)0.241684, 7, 10,
|
||||
(float)0.237874, 9, 17,
|
||||
(float)0.235906, 10, 26,
|
||||
(float)0.232153, 12, 36,
|
||||
(float)0.228352, 14, 48,
|
||||
(float)0.226259, 15, 62,
|
||||
(float)0.222371, 17, 77,
|
||||
(float)0.220410, 18, 94,
|
||||
(float)0.214710, 21, 112,
|
||||
(float)0.212714, 22, 133,
|
||||
(float)0.210721, 23, 155,
|
||||
(float)0.204976, 26, 178,
|
||||
(float)0.202986, 27, 204,
|
||||
(float)0.199245, 29, 231,
|
||||
(float)0.195525, 31, 260,
|
||||
(float)0.193560, 32, 291,
|
||||
(float)0.189878, 34, 323,
|
||||
(float)0.186216, 36, 357,
|
||||
(float)0.186216, 36, 393,
|
||||
(float)0.182592, 38, 429,
|
||||
(float)0.179003, 40, 467,
|
||||
(float)0.175466, 42, 507,
|
||||
(float)0.172001, 44, 549,
|
||||
(float)0.172001, 44, 593,
|
||||
(float)0.168612, 46, 637,
|
||||
(float)0.168612, 46, 683,
|
||||
(float)0.163575, 49, 729,
|
||||
(float)0.158642, 52, 778,
|
||||
(float)0.158642, 52, 830,
|
||||
(float)0.158642, 52, 882,
|
||||
(float)0.153815, 55, 934,
|
||||
(float)0.153815, 55, 989,
|
||||
(float)0.149097, 58, 1044,
|
||||
(float)0.149097, 58, 1102,
|
||||
(float)0.142746, 62, 1160,
|
||||
(float)0.142746, 62, 1222,
|
||||
(float)0.142746, 62, 1284,
|
||||
(float)0.138270, 65, 1346,
|
||||
(float)0.138270, 65, 1411,
|
||||
(float)0.138270, 65, 1476,
|
||||
(float)0.132166, 69, 1541,
|
||||
(float)0.132166, 69, 1610,
|
||||
(float)0.126204, 73, 1679,
|
||||
(float)0.126204, 73, 1752,
|
||||
(float)0.126204, 73, 1825,
|
||||
(float)0.120381, 77, 1898,
|
||||
(float)0.120381, 77, 1975,
|
||||
(float)0.120381, 77, 2052,
|
||||
(float)0.120381, 77, 2129,
|
||||
(float)0.112962, 82, 2206,
|
||||
(float)0.112962, 82, 2288,
|
||||
(float)0.112962, 82, 2370,
|
||||
(float)0.107450, 86, 2452,
|
||||
(float)0.107450, 86, 2538,
|
||||
(float)0.107450, 86, 2624,
|
||||
(float)0.107450, 86, 2710,
|
||||
(float)0.100343, 91, 2796,
|
||||
(float)0.100343, 91, 2887,
|
||||
(float)0.100343, 91, 2978,
|
||||
(float)0.095126, 95, 3069,
|
||||
(float)0.095126, 95, 3164,
|
||||
(float)0.095126, 95, 3259,
|
||||
(float)0.095126, 95, 3354,
|
||||
(float)0.088276, 100, 3449,
|
||||
(float)0.088276, 100, 3549,
|
||||
(float)0.088276, 100, 3649,
|
||||
(float)0.088276, 100, 3749,
|
||||
(float)0.081523, 105, 3849,
|
||||
(float)0.081523, 105, 3954,
|
||||
(float)0.081523, 105, 4059,
|
||||
(float)0.081523, 105, 4164,
|
||||
(float)0.074861, 110, 4269,
|
||||
(float)0.074861, 110, 4379,
|
||||
(float)0.074861, 110, 4489,
|
||||
(float)0.074861, 110, 4599,
|
||||
(float)0.068290, 115, 4709,
|
||||
(float)0.068290, 115, 4824,
|
||||
(float)0.068290, 115, 4939,
|
||||
(float)0.068290, 115, 5054,
|
||||
(float)0.063573, 119, 5169,
|
||||
(float)0.063573, 119, 5288,
|
||||
(float)0.063573, 119, 5407,
|
||||
(float)0.063573, 119, 5526,
|
||||
(float)0.057219, 124, 5645,
|
||||
(float)0.057219, 124, 5769,
|
||||
(float)0.057219, 124, 5893,
|
||||
(float)0.057219, 124, 6017,
|
||||
(float)0.050985, 129, 6141,
|
||||
(float)0.050985, 129, 6270,
|
||||
(float)0.050985, 129, 6399,
|
||||
(float)0.050985, 129, 6528,
|
||||
(float)0.050985, 129, 6657,
|
||||
(float)0.044859, 134, 6786,
|
||||
(float)0.044859, 134, 6920,
|
||||
(float)0.044859, 134, 7054,
|
||||
(float)0.044859, 134, 7188,
|
||||
(float)0.040571, 138, 7322,
|
||||
(float)0.040571, 138, 7460,
|
||||
(float)0.040571, 138, 7598,
|
||||
(float)0.040571, 138, 7736,
|
||||
(float)0.036339, 142, 7874,
|
||||
(float)0.036339, 142, 8016,
|
||||
(float)0.036339, 142, 8158,
|
||||
(float)0.036339, 142, 8300,
|
||||
(float)0.032139, 146, 8442,
|
||||
(float)0.032139, 146, 8588,
|
||||
(float)0.032139, 146, 8734,
|
||||
(float)0.032139, 146, 8880,
|
||||
(float)0.027947, 150, 9026,
|
||||
(float)0.027947, 150, 9176,
|
||||
(float)0.027947, 150, 9326,
|
||||
(float)0.023739, 154, 9476,
|
||||
(float)0.023739, 154, 9630,
|
||||
(float)0.023739, 154, 9784,
|
||||
(float)0.023739, 154, 9938,
|
||||
(float)0.019504, 158, 10092,
|
||||
(float)0.019504, 158, 10250,
|
||||
(float)0.019504, 158, 10408,
|
||||
(float)0.016976, 161, 10566,
|
||||
(float)0.016976, 161, 10727,
|
||||
(float)0.016976, 161, 10888,
|
||||
(float)0.016976, 161, 11049,
|
||||
(float)0.012639, 165, 11210,
|
||||
(float)0.012639, 165, 11375,
|
||||
(float)0.012639, 165, 11540,
|
||||
(float)0.009991, 168, 11705,
|
||||
(float)0.009991, 168, 11873,
|
||||
(float)0.009991, 168, 12041,
|
||||
(float)0.009016, 170, 12209,
|
||||
(float)0.009016, 170, 12379,
|
||||
(float)0.009016, 170, 12549,
|
||||
(float)0.006217, 173, 12719,
|
||||
(float)0.006217, 173, 12892,
|
||||
(float)0.005097, 175, 13065,
|
||||
(float)0.005097, 175, 13240,
|
||||
(float)0.005097, 175, 13415,
|
||||
(float)0.003909, 177, 13590,
|
||||
(float)0.003909, 177, 13767,
|
||||
(float)0.002340, 177, 13944,
|
||||
(float)0.002389, 170, 14121,
|
||||
(float)0.001068, 164, 14291,
|
||||
(float)0.001653, 157, 14455,
|
||||
(float)0.000717, 150, 14612,
|
||||
(float)0.001614, 143, 14762,
|
||||
(float)0.000270, 136, 14905,
|
||||
(float)0.000484, 129, 15041,
|
||||
(float)0.001103, 123, 15170,
|
||||
(float)0.001242, 115, 15293,
|
||||
(float)0.001188, 109, 15408,
|
||||
(float)0.001011, 103, 15517,
|
||||
(float)0.000709, 97, 15620,
|
||||
(float)0.000301, 89, 15717,
|
||||
(float)0.002416, 82, 15806,
|
||||
(float)0.003251, 76, 15888,
|
||||
(float)0.003246, 69, 15964,
|
||||
(float)0.004141, 62, 16033,
|
||||
(float)0.005963, 55, 16095,
|
||||
(float)0.008839, 47, 16150,
|
||||
(float)0.010490, 40, 16197,
|
||||
(float)0.016994, 31, 16237,
|
||||
(float)0.023659, 21, 16268,
|
||||
};
|
||||
|
Reference in New Issue
Block a user