Commit 913dad52 authored by Alexandre Julliard's avatar Alexandre Julliard

libs: Import upstream code from libtiff 4.3.0.

parent a6ac035a
......@@ -705,6 +705,8 @@ XMKMF
PTHREAD_LIBS
ZLIB_PE_LIBS
ZLIB_PE_CFLAGS
TIFF_PE_LIBS
TIFF_PE_CFLAGS
PNG_PE_LIBS
PNG_PE_CFLAGS
JPEG_PE_LIBS
......@@ -1789,6 +1791,7 @@ enable_jpeg
enable_mfuuid
enable_png
enable_strmiids
enable_tiff
enable_uuid
enable_wbemuuid
enable_wine
......@@ -1928,6 +1931,8 @@ JPEG_PE_CFLAGS
JPEG_PE_LIBS
PNG_PE_CFLAGS
PNG_PE_LIBS
TIFF_PE_CFLAGS
TIFF_PE_LIBS
ZLIB_PE_CFLAGS
ZLIB_PE_LIBS
XMKMF
......@@ -2718,6 +2723,10 @@ Some influential environment variables:
PNG_PE_CFLAGS
C compiler flags for the PE png, overriding the bundled version
PNG_PE_LIBS Linker flags for the PE png, overriding the bundled version
TIFF_PE_CFLAGS
C compiler flags for the PE tiff, overriding the bundled version
TIFF_PE_LIBS
Linker flags for the PE tiff, overriding the bundled version
ZLIB_PE_CFLAGS
C compiler flags for the PE zlib, overriding the bundled version
ZLIB_PE_LIBS
......@@ -10738,6 +10747,19 @@ fi
$as_echo "$as_me:${as_lineno-$LINENO}: png cflags: $PNG_PE_CFLAGS" >&5
$as_echo "$as_me:${as_lineno-$LINENO}: png libs: $PNG_PE_LIBS" >&5
if ${TIFF_PE_CFLAGS:+false} :; then :
TIFF_PE_CFLAGS="-I\$(top_srcdir)/libs/tiff/libtiff"
else
enable_tiff=no
fi
if ${TIFF_PE_LIBS:+false} :; then :
TIFF_PE_LIBS=tiff
else
enable_tiff=no
fi
$as_echo "$as_me:${as_lineno-$LINENO}: tiff cflags: $TIFF_PE_CFLAGS" >&5
$as_echo "$as_me:${as_lineno-$LINENO}: tiff libs: $TIFF_PE_LIBS" >&5
if ${ZLIB_PE_CFLAGS:+false} :; then :
ZLIB_PE_CFLAGS="-I\$(top_srcdir)/libs/zlib -DFAR= -DZ_SOLO"
else
......@@ -19583,6 +19605,8 @@ JPEG_PE_CFLAGS = $JPEG_PE_CFLAGS
JPEG_PE_LIBS = $JPEG_PE_LIBS
PNG_PE_CFLAGS = $PNG_PE_CFLAGS
PNG_PE_LIBS = $PNG_PE_LIBS
TIFF_PE_CFLAGS = $TIFF_PE_CFLAGS
TIFF_PE_LIBS = $TIFF_PE_LIBS
ZLIB_PE_CFLAGS = $ZLIB_PE_CFLAGS
ZLIB_PE_LIBS = $ZLIB_PE_LIBS
PTHREAD_LIBS = $PTHREAD_LIBS
......@@ -20879,6 +20903,7 @@ wine_fn_config_makefile libs/jpeg enable_jpeg
wine_fn_config_makefile libs/mfuuid enable_mfuuid
wine_fn_config_makefile libs/png enable_png
wine_fn_config_makefile libs/strmiids enable_strmiids
wine_fn_config_makefile libs/tiff enable_tiff
wine_fn_config_makefile libs/uuid enable_uuid
wine_fn_config_makefile libs/wbemuuid enable_wbemuuid
wine_fn_config_makefile libs/wine enable_wine
......
......@@ -1064,6 +1064,7 @@ dnl **** External libraries ****
WINE_EXTLIB_FLAGS(JPEG, jpeg, jpeg, "-I\$(top_srcdir)/libs/jpeg")
WINE_EXTLIB_FLAGS(PNG, png, "png \$(ZLIB_PE_LIBS)", "-I\$(top_srcdir)/libs/png")
WINE_EXTLIB_FLAGS(TIFF, tiff, tiff, "-I\$(top_srcdir)/libs/tiff/libtiff")
WINE_EXTLIB_FLAGS(ZLIB, zlib, z, "-I\$(top_srcdir)/libs/zlib -DFAR= -DZ_SOLO")
dnl **** Check for pthread ****
......@@ -3797,6 +3798,7 @@ WINE_CONFIG_MAKEFILE(libs/jpeg)
WINE_CONFIG_MAKEFILE(libs/mfuuid)
WINE_CONFIG_MAKEFILE(libs/png)
WINE_CONFIG_MAKEFILE(libs/strmiids)
WINE_CONFIG_MAKEFILE(libs/tiff)
WINE_CONFIG_MAKEFILE(libs/uuid)
WINE_CONFIG_MAKEFILE(libs/wbemuuid)
WINE_CONFIG_MAKEFILE(libs/wine)
......
Copyright (c) 1988-1997 Sam Leffler
Copyright (c) 1991-1997 Silicon Graphics, Inc.
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.
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
OF THIS SOFTWARE.
EXTLIB = libtiff.a
EXTRAINCL = -I$(srcdir)/libtiff $(JPEG_PE_CFLAGS) $(ZLIB_PE_CFLAGS)
C_SRCS = \
libtiff/tif_aux.c \
libtiff/tif_close.c \
libtiff/tif_codec.c \
libtiff/tif_compress.c \
libtiff/tif_dir.c \
libtiff/tif_dirinfo.c \
libtiff/tif_dirread.c \
libtiff/tif_dirwrite.c \
libtiff/tif_dumpmode.c \
libtiff/tif_error.c \
libtiff/tif_fax3.c \
libtiff/tif_fax3sm.c \
libtiff/tif_flush.c \
libtiff/tif_jpeg.c \
libtiff/tif_luv.c \
libtiff/tif_lzw.c \
libtiff/tif_next.c \
libtiff/tif_open.c \
libtiff/tif_packbits.c \
libtiff/tif_pixarlog.c \
libtiff/tif_predict.c \
libtiff/tif_read.c \
libtiff/tif_strip.c \
libtiff/tif_swab.c \
libtiff/tif_thunder.c \
libtiff/tif_tile.c \
libtiff/tif_warning.c \
libtiff/tif_win32.c \
libtiff/tif_write.c \
libtiff/tif_zip.c
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
*
* 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.
*
* 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
* OF THIS SOFTWARE.
*/
/*
* TIFF Library.
*/
#include "tiffiop.h"
#include <string.h>
/************************************************************************/
/* TIFFCleanup() */
/************************************************************************/
/**
* Auxiliary function to free the TIFF structure. Given structure will be
* completely freed, so you should save opened file handle and pointer
* to the close procedure in external variables before calling
* _TIFFCleanup(), if you will need these ones to close the file.
*
* @param tif A TIFF pointer.
*/
void
TIFFCleanup(TIFF* tif)
{
/*
* Flush buffered data and directory (if dirty).
*/
if (tif->tif_mode != O_RDONLY)
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 *psLink = tif->tif_clientinfo;
tif->tif_clientinfo = psLink->next;
_TIFFfree( psLink->name );
_TIFFfree( psLink );
}
if (tif->tif_rawdata && (tif->tif_flags&TIFF_MYBUFFER))
_TIFFfree(tif->tif_rawdata);
if (isMapped(tif))
TIFFUnmapFileContents(tif, tif->tif_base, (toff_t)tif->tif_size);
/*
* Clean up custom fields.
*/
if (tif->tif_fields && tif->tif_nfields > 0) {
uint32_t i;
for (i = 0; i < tif->tif_nfields; i++) {
TIFFField *fld = tif->tif_fields[i];
if (fld->field_bit == FIELD_CUSTOM &&
strncmp("Tag ", fld->field_name, 4) == 0) {
_TIFFfree(fld->field_name);
_TIFFfree(fld);
}
}
_TIFFfree(tif->tif_fields);
}
if (tif->tif_nfieldscompat > 0) {
uint32_t i;
for (i = 0; i < tif->tif_nfieldscompat; i++) {
if (tif->tif_fieldscompat[i].allocated_size)
_TIFFfree(tif->tif_fieldscompat[i].fields);
}
_TIFFfree(tif->tif_fieldscompat);
}
_TIFFfree(tif);
}
/************************************************************************/
/* TIFFClose() */
/************************************************************************/
/**
* Close a previously opened TIFF file.
*
* TIFFClose closes a file that was previously opened with TIFFOpen().
* Any buffered data are flushed to the file, including the contents of
* the current directory (if modified); and all resources are reclaimed.
*
* @param tif A TIFF pointer.
*/
void
TIFFClose(TIFF* tif)
{
TIFFCloseProc closeproc = tif->tif_closeproc;
thandle_t fd = tif->tif_clientdata;
TIFFCleanup(tif);
(void) (*closeproc)(fd);
}
/* vim: set ts=8 sts=8 sw=8 noet: */
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
*
* 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.
*
* 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
* OF THIS SOFTWARE.
*/
/*
* TIFF Library
*
* Builtin Compression Scheme Configuration Support.
*/
#include "tiffiop.h"
static int NotConfigured(TIFF*, int);
#ifndef LZW_SUPPORT
#define TIFFInitLZW NotConfigured
#endif
#ifndef PACKBITS_SUPPORT
#define TIFFInitPackBits NotConfigured
#endif
#ifndef THUNDER_SUPPORT
#define TIFFInitThunderScan NotConfigured
#endif
#ifndef NEXT_SUPPORT
#define TIFFInitNeXT NotConfigured
#endif
#ifndef JPEG_SUPPORT
#define TIFFInitJPEG NotConfigured
#endif
#ifndef OJPEG_SUPPORT
#define TIFFInitOJPEG NotConfigured
#endif
#ifndef CCITT_SUPPORT
#define TIFFInitCCITTRLE NotConfigured
#define TIFFInitCCITTRLEW NotConfigured
#define TIFFInitCCITTFax3 NotConfigured
#define TIFFInitCCITTFax4 NotConfigured
#endif
#ifndef JBIG_SUPPORT
#define TIFFInitJBIG NotConfigured
#endif
#ifndef ZIP_SUPPORT
#define TIFFInitZIP NotConfigured
#endif
#ifndef PIXARLOG_SUPPORT
#define TIFFInitPixarLog NotConfigured
#endif
#ifndef LOGLUV_SUPPORT
#define TIFFInitSGILog NotConfigured
#endif
#ifndef LERC_SUPPORT
#define TIFFInitLERC NotConfigured
#endif
#ifndef LZMA_SUPPORT
#define TIFFInitLZMA NotConfigured
#endif
#ifndef ZSTD_SUPPORT
#define TIFFInitZSTD NotConfigured
#endif
#ifndef WEBP_SUPPORT
#define TIFFInitWebP NotConfigured
#endif
/*
* Compression schemes statically built into the library.
*/
const TIFFCodec _TIFFBuiltinCODECS[] = {
{ "None", COMPRESSION_NONE, TIFFInitDumpMode },
{ "LZW", COMPRESSION_LZW, TIFFInitLZW },
{ "PackBits", COMPRESSION_PACKBITS, TIFFInitPackBits },
{ "ThunderScan", COMPRESSION_THUNDERSCAN,TIFFInitThunderScan },
{ "NeXT", COMPRESSION_NEXT, TIFFInitNeXT },
{ "JPEG", COMPRESSION_JPEG, TIFFInitJPEG },
{ "Old-style JPEG", COMPRESSION_OJPEG, TIFFInitOJPEG },
{ "CCITT RLE", COMPRESSION_CCITTRLE, TIFFInitCCITTRLE },
{ "CCITT RLE/W", COMPRESSION_CCITTRLEW, TIFFInitCCITTRLEW },
{ "CCITT Group 3", COMPRESSION_CCITTFAX3, TIFFInitCCITTFax3 },
{ "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 },
{ "LZMA", COMPRESSION_LZMA, TIFFInitLZMA },
{ "ZSTD", COMPRESSION_ZSTD, TIFFInitZSTD },
{ "WEBP", COMPRESSION_WEBP, TIFFInitWebP },
{ "LERC", COMPRESSION_LERC, TIFFInitLERC },
{ NULL, 0, NULL }
};
static int
_notConfigured(TIFF* tif)
{
const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression);
char compression_code[20];
sprintf(compression_code, "%"PRIu16, tif->tif_dir.td_compression );
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
"%s compression support is not configured",
c ? c->name : compression_code );
return (0);
}
static int
NotConfigured(TIFF* tif, int scheme)
{
(void) scheme;
tif->tif_fixuptags = _notConfigured;
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_t 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;
}
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
*
* 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.
*
* 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
* OF THIS SOFTWARE.
*/
/*
* TIFF Library
*
* Compression Scheme Configuration Support.
*/
#include "tiffiop.h"
static int
TIFFNoEncode(TIFF* tif, const char* method)
{
const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression);
if (c) {
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
"%s %s encoding is not implemented",
c->name, method);
} else {
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
"Compression scheme %"PRIu16" %s encoding is not implemented",
tif->tif_dir.td_compression, method);
}
return (-1);
}
int
_TIFFNoRowEncode(TIFF* tif, uint8_t* pp, tmsize_t cc, uint16_t s)
{
(void) pp; (void) cc; (void) s;
return (TIFFNoEncode(tif, "scanline"));
}
int
_TIFFNoStripEncode(TIFF* tif, uint8_t* pp, tmsize_t cc, uint16_t s)
{
(void) pp; (void) cc; (void) s;
return (TIFFNoEncode(tif, "strip"));
}
int
_TIFFNoTileEncode(TIFF* tif, uint8_t* pp, tmsize_t cc, uint16_t s)
{
(void) pp; (void) cc; (void) s;
return (TIFFNoEncode(tif, "tile"));
}
static int
TIFFNoDecode(TIFF* tif, const char* method)
{
const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression);
if (c)
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
"%s %s decoding is not implemented",
c->name, method);
else
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
"Compression scheme %"PRIu16" %s decoding is not implemented",
tif->tif_dir.td_compression, method);
return (0);
}
static int
_TIFFNoFixupTags(TIFF* tif)
{
(void) tif;
return (1);
}
int
_TIFFNoRowDecode(TIFF* tif, uint8_t* pp, tmsize_t cc, uint16_t s)
{
(void) pp; (void) cc; (void) s;
return (TIFFNoDecode(tif, "scanline"));
}
int
_TIFFNoStripDecode(TIFF* tif, uint8_t* pp, tmsize_t cc, uint16_t s)
{
(void) pp; (void) cc; (void) s;
return (TIFFNoDecode(tif, "strip"));
}
int
_TIFFNoTileDecode(TIFF* tif, uint8_t* pp, tmsize_t cc, uint16_t s)
{
(void) pp; (void) cc; (void) s;
return (TIFFNoDecode(tif, "tile"));
}
int
_TIFFNoSeek(TIFF* tif, uint32_t off)
{
(void) off;
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
"Compression algorithm does not support random access");
return (0);
}
int
_TIFFNoPreCode(TIFF* tif, uint16_t s)
{
(void) tif; (void) s;
return (1);
}
static int _TIFFtrue(TIFF* tif) { (void) tif; return (1); }
static void _TIFFvoid(TIFF* tif) { (void) tif; }
void
_TIFFSetDefaultCompressionState(TIFF* tif)
{
tif->tif_fixuptags = _TIFFNoFixupTags;
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;
tif->tif_encoderow = _TIFFNoRowEncode;
tif->tif_encodestrip = _TIFFNoStripEncode;
tif->tif_encodetile = _TIFFNoTileEncode;
tif->tif_close = _TIFFvoid;
tif->tif_seek = _TIFFNoSeek;
tif->tif_cleanup = _TIFFvoid;
tif->tif_defstripsize = _TIFFDefaultStripSize;
tif->tif_deftilesize = _TIFFDefaultTileSize;
tif->tif_flags &= ~(TIFF_NOBITREV|TIFF_NOREADRAW);
}
int
TIFFSetCompressionScheme(TIFF* tif, int scheme)
{
const TIFFCodec *c = TIFFFindCODEC((uint16_t) scheme);
_TIFFSetDefaultCompressionState(tif);
/*
* Don't treat an unknown compression scheme as an error.
* This permits applications to open files with data that
* the library does not have builtin support for, but which
* may still be meaningful.
*/
return (c ? (*c->init)(tif, scheme) : 1);
}
/*
* Other compression schemes may be registered. Registered
* schemes can also override the builtin versions provided
* by this library.
*/
typedef struct _codec {
struct _codec* next;
TIFFCodec* info;
} codec_t;
static codec_t* registeredCODECS = NULL;
const TIFFCodec*
TIFFFindCODEC(uint16_t scheme)
{
const TIFFCodec* c;
codec_t* cd;
for (cd = registeredCODECS; cd; cd = cd->next)
if (cd->info->scheme == scheme)
return ((const TIFFCodec*) cd->info);
for (c = _TIFFBuiltinCODECS; c->name; c++)
if (c->scheme == scheme)
return (c);
return ((const TIFFCodec*) 0);
}
TIFFCodec*
TIFFRegisterCODEC(uint16_t scheme, const char* name, TIFFInitMethod init)
{
codec_t* cd = (codec_t*)
_TIFFmalloc((tmsize_t)(sizeof (codec_t) + sizeof (TIFFCodec) + strlen(name)+1));
if (cd != NULL) {
cd->info = (TIFFCodec*) ((uint8_t*) cd + sizeof (codec_t));
cd->info->name = (char*)
((uint8_t*) cd->info + sizeof (TIFFCodec));
strcpy(cd->info->name, name);
cd->info->scheme = scheme;
cd->info->init = init;
cd->next = registeredCODECS;
registeredCODECS = cd;
} else {
TIFFErrorExt(0, "TIFFRegisterCODEC",
"No space to register compression scheme %s", name);
return NULL;
}
return (cd->info);
}
void
TIFFUnRegisterCODEC(TIFFCodec* c)
{
codec_t* cd;
codec_t** pcd;
for (pcd = &registeredCODECS; (cd = *pcd) != NULL; pcd = &cd->next)
if (cd->info == c) {
*pcd = cd->next;
_TIFFfree(cd);
return;
}
TIFFErrorExt(0, "TIFFUnRegisterCODEC",
"Cannot remove compression scheme %s; not registered", c->name);
}
/************************************************************************/
/* TIFFGetConfisuredCODECs() */
/************************************************************************/
/**
* Get list of configured codecs, both built-in and registered by user.
* Caller is responsible to free this structure.
*
* @return returns array of TIFFCodec records (the last record should be NULL)
* or NULL if function failed.
*/
TIFFCodec*
TIFFGetConfiguredCODECs()
{
int i = 1;
codec_t *cd;
const TIFFCodec* c;
TIFFCodec* codecs = NULL;
TIFFCodec* new_codecs;
for (cd = registeredCODECS; cd; cd = cd->next) {
new_codecs = (TIFFCodec *)
_TIFFrealloc(codecs, i * sizeof(TIFFCodec));
if (!new_codecs) {
_TIFFfree (codecs);
return NULL;
}
codecs = new_codecs;
_TIFFmemcpy(codecs + i - 1, cd->info, sizeof(TIFFCodec));
i++;
}
for (c = _TIFFBuiltinCODECS; c->name; c++) {
if (TIFFIsCODECConfigured(c->scheme)) {
new_codecs = (TIFFCodec *)
_TIFFrealloc(codecs, i * sizeof(TIFFCodec));
if (!new_codecs) {
_TIFFfree (codecs);
return NULL;
}
codecs = new_codecs;
_TIFFmemcpy(codecs + i - 1, (const void*)c, sizeof(TIFFCodec));
i++;
}
}
new_codecs = (TIFFCodec *) _TIFFrealloc(codecs, i * sizeof(TIFFCodec));
if (!new_codecs) {
_TIFFfree (codecs);
return NULL;
}
codecs = new_codecs;
_TIFFmemset(codecs + i - 1, 0, sizeof(TIFFCodec));
return codecs;
}
/* vim: set ts=8 sts=8 sw=8 noet: */
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
/* libtiff/tif_config.h. Generated from tif_config.h.in by configure. */
/* libtiff/tif_config.h.in. Not generated, but originated from autoheader. */
#include "tiffconf.h"
/* Support CCITT Group 3 & 4 algorithms */
#define CCITT_SUPPORT 1
/* Pick up YCbCr subsampling info from the JPEG data stream to support files
lacking the tag (default enabled). */
#define CHECK_JPEG_YCBCR_SUBSAMPLING 1
/* enable partial strip reading for large strips (experimental) */
/* #undef CHUNKY_STRIP_READ_SUPPORT */
/* Support C++ stream API (requires C++ compiler) */
/* #undef CXX_SUPPORT */
/* enable deferred strip/tile offset/size loading */
/* #undef DEFER_STRILE_LOAD */
/* Define to 1 if you have the <assert.h> header file. */
#define HAVE_ASSERT_H 1
/* Define to 1 if you have the declaration of `optarg', and to 0 if you don't.
*/
/* #undef HAVE_DECL_OPTARG */
/* Define to 1 if you have the <fcntl.h> header file. */
#define HAVE_FCNTL_H 1
/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */
#define HAVE_FSEEKO 1
/* Define to 1 if you have the `getopt' function. */
/* #undef HAVE_GETOPT */
/* Define to 1 if you have the <GLUT/glut.h> header file. */
/* #undef HAVE_GLUT_GLUT_H */
/* Define to 1 if you have the <GL/glut.h> header file. */
/* #undef HAVE_GL_GLUT_H */
/* Define to 1 if you have the <GL/glu.h> header file. */
#define HAVE_GL_GLU_H 1
/* Define to 1 if you have the <GL/gl.h> header file. */
#define HAVE_GL_GL_H 1
/* Define to 1 if you have the <io.h> header file. */
#define HAVE_IO_H 1
/* Define to 1 if you have the `jbg_newlen' function. */
/* #undef HAVE_JBG_NEWLEN */
/* Define to 1 if you have the `mmap' function. */
/* #undef HAVE_MMAP */
/* Define to 1 if you have the <OpenGL/glu.h> header file. */
/* #undef HAVE_OPENGL_GLU_H */
/* Define to 1 if you have the <OpenGL/gl.h> header file. */
/* #undef HAVE_OPENGL_GL_H */
/* Define to 1 if you have the `setmode' function. */
#define HAVE_SETMODE 1
/* Define to 1 if you have the `snprintf' function. */
/* #undef HAVE_SNPRINTF */
/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
/* 8/12 bit libjpeg dual mode enabled */
/* #undef JPEG_DUAL_MODE_8_12 */
/* Support LERC compression */
/* #undef LERC_SUPPORT */
/* 12bit libjpeg primary include file with path */
/* #undef LIBJPEG_12_PATH */
/* Support LZMA2 compression */
/* #undef LZMA_SUPPORT */
/* Name of package */
#define PACKAGE "tiff"
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "tiff@lists.maptools.org"
/* Define to the full name of this package. */
#define PACKAGE_NAME "LibTIFF Software"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "LibTIFF Software 4.3.0"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "tiff"
/* Define to the home page for this package. */
#define PACKAGE_URL ""
/* Define to the version of this package. */
#define PACKAGE_VERSION "4.3.0"
/* The size of `size_t', as computed by sizeof. */
/* #undef SIZEOF_SIZE_T */
/* Default size of the strip in bytes (when strip chopping enabled) */
#define STRIP_SIZE_DEFAULT 8192
/* define to use win32 IO system */
#define USE_WIN32_FILEIO 1
/* Version number of package */
#define VERSION "4.3.0"
/* Support webp compression */
/* #undef WEBP_SUPPORT */
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
significant byte first (like Motorola and SPARC, unlike Intel). */
#if defined AC_APPLE_UNIVERSAL_BUILD
# if defined __BIG_ENDIAN__
# define WORDS_BIGENDIAN 1
# endif
#else
# ifndef WORDS_BIGENDIAN
/* # undef WORDS_BIGENDIAN */
# endif
#endif
/* Support zstd compression */
/* #undef ZSTD_SUPPORT */
/* Enable large inode numbers on Mac OS X 10.5. */
#ifndef _DARWIN_USE_64_BIT_INODE
# define _DARWIN_USE_64_BIT_INODE 1
#endif
/* Number of bits in a file offset, on hosts where this is settable. */
#define _FILE_OFFSET_BITS 64
/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
/* #undef _LARGEFILE_SOURCE */
/* Define for large files, on AIX-style hosts. */
/* #undef _LARGE_FILES */
#if !defined(__MINGW32__)
# define TIFF_SIZE_FORMAT "zu"
# define TIFF_SSIZE_FORMAT "zd"
#else
# define TIFF_SIZE_FORMAT "Iu"
# define TIFF_SSIZE_FORMAT "Id"
#endif
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
*
* 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.
*
* 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
* OF THIS SOFTWARE.
*/
/*
* TIFF Library.
*
* "Null" Compression Algorithm Support.
*/
#include "tiffiop.h"
static int
DumpFixupTags(TIFF* tif)
{
(void) tif;
return (1);
}
/*
* Encode a hunk of pixels.
*/
static int
DumpModeEncode(TIFF* tif, uint8_t* pp, tmsize_t cc, uint16_t s)
{
(void) s;
while (cc > 0) {
tmsize_t n;
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.
*/
if (tif->tif_rawcp != pp)
_TIFFmemcpy(tif->tif_rawcp, pp, n);
tif->tif_rawcp += n;
tif->tif_rawcc += n;
pp += n;
cc -= n;
if (tif->tif_rawcc >= tif->tif_rawdatasize &&
!TIFFFlushData1(tif))
return (0);
}
return (1);
}
/*
* Decode a hunk of pixels.
*/
static int
DumpModeDecode(TIFF* tif, uint8_t* buf, tmsize_t cc, uint16_t s)
{
static const char module[] = "DumpModeDecode";
(void) s;
if (tif->tif_rawcc < cc) {
TIFFErrorExt(tif->tif_clientdata, module,
"Not enough data for scanline %"PRIu32", expected a request for at most %"TIFF_SSIZE_FORMAT" bytes, got a request for %"TIFF_SSIZE_FORMAT" bytes",
tif->tif_row,
tif->tif_rawcc,
cc);
return (0);
}
/*
* Avoid copy if client has setup raw
* data buffer to avoid extra copy.
*/
if (tif->tif_rawcp != buf)
_TIFFmemcpy(buf, tif->tif_rawcp, cc);
tif->tif_rawcp += cc;
tif->tif_rawcc -= cc;
return (1);
}
/*
* Seek forwards nrows in the current strip.
*/
static int
DumpModeSeek(TIFF* tif, uint32_t nrows)
{
tif->tif_rawcp += nrows * tif->tif_scanlinesize;
tif->tif_rawcc -= nrows * tif->tif_scanlinesize;
return (1);
}
/*
* Initialize dump mode.
*/
int
TIFFInitDumpMode(TIFF* tif, int scheme)
{
(void) scheme;
tif->tif_fixuptags = DumpFixupTags;
tif->tif_decoderow = DumpModeDecode;
tif->tif_decodestrip = DumpModeDecode;
tif->tif_decodetile = DumpModeDecode;
tif->tif_encoderow = DumpModeEncode;
tif->tif_encodestrip = DumpModeEncode;
tif->tif_encodetile = DumpModeEncode;
tif->tif_seek = DumpModeSeek;
return (1);
}
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
*
* 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.
*
* 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
* OF THIS SOFTWARE.
*/
/*
* TIFF Library.
*/
#include "tiffiop.h"
TIFFErrorHandlerExt _TIFFerrorHandlerExt = NULL;
TIFFErrorHandler
TIFFSetErrorHandler(TIFFErrorHandler handler)
{
TIFFErrorHandler prev = _TIFFerrorHandler;
_TIFFerrorHandler = handler;
return (prev);
}
TIFFErrorHandlerExt
TIFFSetErrorHandlerExt(TIFFErrorHandlerExt handler)
{
TIFFErrorHandlerExt prev = _TIFFerrorHandlerExt;
_TIFFerrorHandlerExt = handler;
return (prev);
}
void WINAPIV
TIFFError(const char* module, const char* fmt, ...)
{
va_list ap;
if (_TIFFerrorHandler) {
va_start(ap, fmt);
(*_TIFFerrorHandler)(module, fmt, ap);
va_end(ap);
}
if (_TIFFerrorHandlerExt) {
va_start(ap, fmt);
(*_TIFFerrorHandlerExt)(0, module, fmt, ap);
va_end(ap);
}
}
void WINAPIV
TIFFErrorExt(thandle_t fd, const char* module, const char* fmt, ...)
{
va_list ap;
if (_TIFFerrorHandler) {
va_start(ap, fmt);
(*_TIFFerrorHandler)(module, fmt, ap);
va_end(ap);
}
if (_TIFFerrorHandlerExt) {
va_start(ap, fmt);
(*_TIFFerrorHandlerExt)(fd, module, fmt, ap);
va_end(ap);
}
}
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
This source diff could not be displayed because it is too large. You can view the blob instead.
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
*
* 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.
*
* 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
* OF THIS SOFTWARE.
*/
/*
* TIFF Library.
*/
#include "tiffiop.h"
int
TIFFFlush(TIFF* tif)
{
if( tif->tif_mode == O_RDONLY )
return 1;
if (!TIFFFlushData(tif))
return (0);
/* In update (r+) mode we try to detect the case where
only the strip/tile map has been altered, and we try to
rewrite only that portion of the directory without
making any other changes */
if( (tif->tif_flags & TIFF_DIRTYSTRIP)
&& !(tif->tif_flags & TIFF_DIRTYDIRECT)
&& tif->tif_mode == O_RDWR )
{
if( TIFFForceStrileArrayWriting(tif) )
return 1;
}
if ((tif->tif_flags & (TIFF_DIRTYDIRECT|TIFF_DIRTYSTRIP))
&& !TIFFRewriteDirectory(tif))
return (0);
return (1);
}
/*
* This is an advanced writing function that must be used in a particular
* sequence, and together with TIFFDeferStrileArrayWriting(),
* to make its intended effect. Its aim is to force the writing of
* the [Strip/Tile][Offsets/ByteCounts] arrays at the end of the file, when
* they have not yet been rewritten.
*
* The typical sequence of calls is:
* TIFFOpen()
* [ TIFFCreateDirectory(tif) ]
* Set fields with calls to TIFFSetField(tif, ...)
* TIFFDeferStrileArrayWriting(tif)
* TIFFWriteCheck(tif, ...)
* TIFFWriteDirectory(tif)
* ... potentially create other directories and come back to the above directory
* TIFFForceStrileArrayWriting(tif)
*
* Returns 1 in case of success, 0 otherwise.
*/
int TIFFForceStrileArrayWriting(TIFF* tif)
{
static const char module[] = "TIFFForceStrileArrayWriting";
const int isTiled = TIFFIsTiled(tif);
if (tif->tif_mode == O_RDONLY)
{
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
"File opened in read-only mode");
return 0;
}
if( tif->tif_diroff == 0 )
{
TIFFErrorExt(tif->tif_clientdata, module,
"Directory has not yet been written");
return 0;
}
if( (tif->tif_flags & TIFF_DIRTYDIRECT) != 0 )
{
TIFFErrorExt(tif->tif_clientdata, module,
"Directory has changes other than the strile arrays. "
"TIFFRewriteDirectory() should be called instead");
return 0;
}
if( !(tif->tif_flags & TIFF_DIRTYSTRIP) )
{
if( !(tif->tif_dir.td_stripoffset_entry.tdir_tag != 0 &&
tif->tif_dir.td_stripoffset_entry.tdir_count == 0 &&
tif->tif_dir.td_stripoffset_entry.tdir_type == 0 &&
tif->tif_dir.td_stripoffset_entry.tdir_offset.toff_long8 == 0 &&
tif->tif_dir.td_stripbytecount_entry.tdir_tag != 0 &&
tif->tif_dir.td_stripbytecount_entry.tdir_count == 0 &&
tif->tif_dir.td_stripbytecount_entry.tdir_type == 0 &&
tif->tif_dir.td_stripbytecount_entry.tdir_offset.toff_long8 == 0) )
{
TIFFErrorExt(tif->tif_clientdata, module,
"Function not called together with "
"TIFFDeferStrileArrayWriting()");
return 0;
}
if (tif->tif_dir.td_stripoffset_p == NULL && !TIFFSetupStrips(tif))
return 0;
}
if( _TIFFRewriteField( tif,
isTiled ? TIFFTAG_TILEOFFSETS :
TIFFTAG_STRIPOFFSETS,
TIFF_LONG8,
tif->tif_dir.td_nstrips,
tif->tif_dir.td_stripoffset_p )
&& _TIFFRewriteField( tif,
isTiled ? TIFFTAG_TILEBYTECOUNTS :
TIFFTAG_STRIPBYTECOUNTS,
TIFF_LONG8,
tif->tif_dir.td_nstrips,
tif->tif_dir.td_stripbytecount_p ) )
{
tif->tif_flags &= ~TIFF_DIRTYSTRIP;
tif->tif_flags &= ~TIFF_BEENWRITING;
return 1;
}
return 0;
}
/*
* 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)
{
if ((tif->tif_flags & TIFF_BEENWRITING) == 0)
return (1);
if (tif->tif_flags & TIFF_POSTENCODE) {
tif->tif_flags &= ~TIFF_POSTENCODE;
if (!(*tif->tif_postencode)(tif))
return (0);
}
return (TIFFFlushData1(tif));
}
/* vim: set ts=8 sts=8 sw=8 noet: */
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
*
* 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.
*
* 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
* OF THIS SOFTWARE.
*/
#include "tiffiop.h"
#ifdef NEXT_SUPPORT
/*
* TIFF Library.
*
* NeXT 2-bit Grey Scale Compression Algorithm Support
*/
#define SETPIXEL(op, v) { \
switch (npixels++ & 3) { \
case 0: op[0] = (unsigned char) ((v) << 6); break; \
case 1: op[0] |= (v) << 4; break; \
case 2: op[0] |= (v) << 2; break; \
case 3: *op++ |= (v); op_offset++; break; \
} \
}
#define LITERALROW 0x00
#define LITERALSPAN 0x40
#define WHITE ((1<<2)-1)
static int
NeXTDecode(TIFF* tif, uint8_t* buf, tmsize_t occ, uint16_t s)
{
static const char module[] = "NeXTDecode";
unsigned char *bp, *op;
tmsize_t cc;
uint8_t* row;
tmsize_t scanline, n;
(void) s;
/*
* Each scanline is assumed to start off as all
* white (we assume a PhotometricInterpretation
* of ``min-is-black'').
*/
for (op = (unsigned char*) buf, cc = occ; cc-- > 0;)
*op++ = 0xff;
bp = (unsigned char *)tif->tif_rawcp;
cc = tif->tif_rawcc;
scanline = tif->tif_scanlinesize;
if (occ % scanline)
{
TIFFErrorExt(tif->tif_clientdata, module, "Fractional scanlines cannot be read");
return (0);
}
for (row = buf; cc > 0 && occ > 0; occ -= scanline, row += scanline) {
n = *bp++;
cc--;
switch (n) {
case LITERALROW:
/*
* The entire scanline is given as literal values.
*/
if (cc < scanline)
goto bad;
_TIFFmemcpy(row, bp, scanline);
bp += scanline;
cc -= scanline;
break;
case LITERALSPAN: {
tmsize_t off;
/*
* The scanline has a literal span that begins at some
* offset.
*/
if( cc < 4 )
goto bad;
off = (bp[0] * 256) + bp[1];
n = (bp[2] * 256) + bp[3];
if (cc < 4+n || off+n > scanline)
goto bad;
_TIFFmemcpy(row+off, bp+4, n);
bp += 4+n;
cc -= 4+n;
break;
}
default: {
uint32_t npixels = 0, grey;
tmsize_t op_offset = 0;
uint32_t imagewidth = tif->tif_dir.td_imagewidth;
if( isTiled(tif) )
imagewidth = tif->tif_dir.td_tilewidth;
/*
* The scanline is composed of a sequence of constant
* color ``runs''. We shift into ``run mode'' and
* interpret bytes as codes of the form
* <color><npixels> until we've filled the scanline.
*/
op = row;
for (;;) {
grey = (uint32_t)((n >> 6) & 0x3);
n &= 0x3f;
/*
* Ensure the run does not exceed the scanline
* bounds, potentially resulting in a security
* issue.
*/
while (n-- > 0 && npixels < imagewidth && op_offset < scanline)
SETPIXEL(op, grey);
if (npixels >= imagewidth)
break;
if (op_offset >= scanline ) {
TIFFErrorExt(tif->tif_clientdata, module, "Invalid data for scanline %"PRIu32,
tif->tif_row);
return (0);
}
if (cc == 0)
goto bad;
n = *bp++;
cc--;
}
break;
}
}
}
tif->tif_rawcp = (uint8_t*) bp;
tif->tif_rawcc = cc;
return (1);
bad:
TIFFErrorExt(tif->tif_clientdata, module, "Not enough data for scanline %"PRIu32,
tif->tif_row);
return (0);
}
static int
NeXTPreDecode(TIFF* tif, uint16_t s)
{
static const char module[] = "NeXTPreDecode";
TIFFDirectory *td = &tif->tif_dir;
(void)s;
if( td->td_bitspersample != 2 )
{
TIFFErrorExt(tif->tif_clientdata, module, "Unsupported BitsPerSample = %"PRIu16,
td->td_bitspersample);
return (0);
}
return (1);
}
int
TIFFInitNeXT(TIFF* tif, int scheme)
{
(void) scheme;
tif->tif_predecode = NeXTPreDecode;
tif->tif_decoderow = NeXTDecode;
tif->tif_decodestrip = NeXTDecode;
tif->tif_decodetile = NeXTDecode;
return (1);
}
#endif /* NEXT_SUPPORT */
/* vim: set ts=8 sts=8 sw=8 noet: */
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
*
* 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.
*
* 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
* OF THIS SOFTWARE.
*/
#include "tiffiop.h"
#ifdef PACKBITS_SUPPORT
/*
* TIFF Library.
*
* PackBits Compression Algorithm Support
*/
#include <stdio.h>
static int
PackBitsPreEncode(TIFF* tif, uint16_t s)
{
(void) s;
tif->tif_data = (uint8_t*)_TIFFmalloc(sizeof(tmsize_t));
if (tif->tif_data == NULL)
return (0);
/*
* Calculate the scanline/tile-width size in bytes.
*/
if (isTiled(tif))
*(tmsize_t*)tif->tif_data = TIFFTileRowSize(tif);
else
*(tmsize_t*)tif->tif_data = TIFFScanlineSize(tif);
return (1);
}
static int
PackBitsPostEncode(TIFF* tif)
{
if (tif->tif_data)
_TIFFfree(tif->tif_data);
return (1);
}
/*
* Encode a run of pixels.
*/
static int
PackBitsEncode(TIFF* tif, uint8_t* buf, tmsize_t cc, uint16_t s)
{
unsigned char* bp = (unsigned char*) buf;
uint8_t* op;
uint8_t* ep;
uint8_t* lastliteral;
long n, slop;
int b;
enum { BASE, LITERAL, RUN, LITERAL_RUN } state;
(void) s;
op = tif->tif_rawcp;
ep = tif->tif_rawdata + tif->tif_rawdatasize;
state = BASE;
lastliteral = 0;
while (cc > 0) {
/*
* Find the longest string of identical bytes.
*/
b = *bp++;
cc--;
n = 1;
for (; cc > 0 && b == *bp; cc--, bp++)
n++;
again:
if (op + 2 >= ep) { /* insure space for new data */
/*
* Be careful about writing the last
* literal. Must write up to that point
* and then copy the remainder to the
* front of the buffer.
*/
if (state == LITERAL || state == LITERAL_RUN) {
slop = (long)(op - lastliteral);
tif->tif_rawcc += (tmsize_t)(lastliteral - tif->tif_rawcp);
if (!TIFFFlushData1(tif))
return (0);
op = tif->tif_rawcp;
while (slop-- > 0)
*op++ = *lastliteral++;
lastliteral = tif->tif_rawcp;
} else {
tif->tif_rawcc += (tmsize_t)(op - tif->tif_rawcp);
if (!TIFFFlushData1(tif))
return (0);
op = tif->tif_rawcp;
}
}
switch (state) {
case BASE: /* initial state, set run/literal */
if (n > 1) {
state = RUN;
if (n > 128) {
*op++ = (uint8_t) -127;
*op++ = (uint8_t) b;
n -= 128;
goto again;
}
*op++ = (uint8_t)(-(n - 1));
*op++ = (uint8_t) b;
} else {
lastliteral = op;
*op++ = 0;
*op++ = (uint8_t) b;
state = LITERAL;
}
break;
case LITERAL: /* last object was literal string */
if (n > 1) {
state = LITERAL_RUN;
if (n > 128) {
*op++ = (uint8_t) -127;
*op++ = (uint8_t) b;
n -= 128;
goto again;
}
*op++ = (uint8_t)(-(n - 1)); /* encode run */
*op++ = (uint8_t) b;
} else { /* extend literal */
if (++(*lastliteral) == 127)
state = BASE;
*op++ = (uint8_t) b;
}
break;
case RUN: /* last object was run */
if (n > 1) {
if (n > 128) {
*op++ = (uint8_t) -127;
*op++ = (uint8_t) b;
n -= 128;
goto again;
}
*op++ = (uint8_t)(-(n - 1));
*op++ = (uint8_t) b;
} else {
lastliteral = op;
*op++ = 0;
*op++ = (uint8_t) b;
state = LITERAL;
}
break;
case LITERAL_RUN: /* literal followed by a run */
/*
* Check to see if previous run should
* be converted to a literal, in which
* case we convert literal-run-literal
* to a single literal.
*/
if (n == 1 && op[-2] == (uint8_t) -1 &&
*lastliteral < 126) {
state = (((*lastliteral) += 2) == 127 ?
BASE : LITERAL);
op[-2] = op[-1]; /* replicate */
} else
state = RUN;
goto again;
}
}
tif->tif_rawcc += (tmsize_t)(op - tif->tif_rawcp);
tif->tif_rawcp = op;
return (1);
}
/*
* Encode a rectangular chunk of pixels. We break it up
* into row-sized pieces to insure that encoded runs do
* not span rows. Otherwise, there can be problems with
* the decoder if data is read, for example, by scanlines
* when it was encoded by strips.
*/
static int
PackBitsEncodeChunk(TIFF* tif, uint8_t* bp, tmsize_t cc, uint16_t s)
{
tmsize_t rowsize = *(tmsize_t*)tif->tif_data;
while (cc > 0) {
tmsize_t chunk = rowsize;
if( cc < chunk )
chunk = cc;
if (PackBitsEncode(tif, bp, chunk, s) < 0)
return (-1);
bp += chunk;
cc -= chunk;
}
return (1);
}
static int
PackBitsDecode(TIFF* tif, uint8_t* op, tmsize_t occ, uint16_t s)
{
static const char module[] = "PackBitsDecode";
char *bp;
tmsize_t cc;
long n;
int b;
(void) s;
bp = (char*) tif->tif_rawcp;
cc = tif->tif_rawcc;
while (cc > 0 && occ > 0) {
n = (long) *bp++;
cc--;
/*
* Watch out for compilers that
* don't sign extend chars...
*/
if (n >= 128)
n -= 256;
if (n < 0) { /* replicate next byte -n+1 times */
if (n == -128) /* nop */
continue;
n = -n + 1;
if( occ < (tmsize_t)n )
{
TIFFWarningExt(tif->tif_clientdata, module,
"Discarding %"TIFF_SSIZE_FORMAT" bytes to avoid buffer overrun",
(tmsize_t)n - occ);
n = (long)occ;
}
if( cc == 0 )
{
TIFFWarningExt(tif->tif_clientdata, module,
"Terminating PackBitsDecode due to lack of data.");
break;
}
occ -= n;
b = *bp++;
cc--;
while (n-- > 0)
*op++ = (uint8_t) b;
} else { /* copy next n+1 bytes literally */
if (occ < (tmsize_t)(n + 1))
{
TIFFWarningExt(tif->tif_clientdata, module,
"Discarding %"TIFF_SSIZE_FORMAT" bytes to avoid buffer overrun",
(tmsize_t)n - occ + 1);
n = (long)occ - 1;
}
if (cc < (tmsize_t) (n+1))
{
TIFFWarningExt(tif->tif_clientdata, module,
"Terminating PackBitsDecode due to lack of data.");
break;
}
_TIFFmemcpy(op, bp, ++n);
op += n; occ -= n;
bp += n; cc -= n;
}
}
tif->tif_rawcp = (uint8_t*) bp;
tif->tif_rawcc = cc;
if (occ > 0) {
TIFFErrorExt(tif->tif_clientdata, module,
"Not enough data for scanline %"PRIu32,
tif->tif_row);
return (0);
}
return (1);
}
int
TIFFInitPackBits(TIFF* tif, int scheme)
{
(void) scheme;
tif->tif_decoderow = PackBitsDecode;
tif->tif_decodestrip = PackBitsDecode;
tif->tif_decodetile = PackBitsDecode;
tif->tif_preencode = PackBitsPreEncode;
tif->tif_postencode = PackBitsPostEncode;
tif->tif_encoderow = PackBitsEncode;
tif->tif_encodestrip = PackBitsEncodeChunk;
tif->tif_encodetile = PackBitsEncodeChunk;
return (1);
}
#endif /* PACKBITS_SUPPORT */
/* vim: set ts=8 sts=8 sw=8 noet: */
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
/*
* Copyright (c) 1995-1997 Sam Leffler
* Copyright (c) 1995-1997 Silicon Graphics, Inc.
*
* 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.
*
* 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
* OF THIS SOFTWARE.
*/
#ifndef _TIFFPREDICT_
#define _TIFFPREDICT_
#include "tiffio.h"
#include "tiffiop.h"
/*
* ``Library-private'' Support for the Predictor Tag
*/
typedef int (*TIFFEncodeDecodeMethod)(TIFF* tif, uint8_t* buf, tmsize_t size);
/*
* Codecs that want to support the Predictor tag must place
* this structure first in their private state block so that
* the predictor code can cast tif_data to find its state.
*/
typedef struct {
int predictor; /* predictor tag value */
tmsize_t stride; /* sample stride over data */
tmsize_t rowsize; /* tile/strip row size */
TIFFCodeMethod encoderow; /* parent codec encode/decode row */
TIFFCodeMethod encodestrip; /* parent codec encode/decode strip */
TIFFCodeMethod encodetile; /* parent codec encode/decode tile */
TIFFEncodeDecodeMethod encodepfunc; /* horizontal differencer */
TIFFCodeMethod decoderow; /* parent codec encode/decode row */
TIFFCodeMethod decodestrip; /* parent codec encode/decode strip */
TIFFCodeMethod decodetile; /* parent codec encode/decode tile */
TIFFEncodeDecodeMethod decodepfunc; /* horizontal accumulator */
TIFFVGetMethod vgetparent; /* super-class method */
TIFFVSetMethod vsetparent; /* super-class method */
TIFFPrintMethod printdir; /* super-class method */
TIFFBoolMethod setupdecode; /* super-class method */
TIFFBoolMethod setupencode; /* super-class method */
} TIFFPredictorState;
#if defined(__cplusplus)
extern "C" {
#endif
extern int TIFFPredictorInit(TIFF*);
extern int TIFFPredictorCleanup(TIFF*);
#if defined(__cplusplus)
}
#endif
#endif /* _TIFFPREDICT_ */
/* vim: set ts=8 sts=8 sw=8 noet: */
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
*
* 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.
*
* 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
* OF THIS SOFTWARE.
*/
/*
* TIFF Library Bit & Byte Swapping Support.
*
* XXX We assume short = 16-bits and long = 32-bits XXX
*/
#include "tiffiop.h"
#if defined(DISABLE_CHECK_TIFFSWABMACROS) || !defined(TIFFSwabShort)
void
TIFFSwabShort(uint16_t* wp)
{
register unsigned char* cp = (unsigned char*) wp;
unsigned char t;
assert(sizeof(uint16_t) == 2);
t = cp[1]; cp[1] = cp[0]; cp[0] = t;
}
#endif
#if defined(DISABLE_CHECK_TIFFSWABMACROS) || !defined(TIFFSwabLong)
void
TIFFSwabLong(uint32_t* lp)
{
register unsigned char* cp = (unsigned char*) lp;
unsigned char t;
assert(sizeof(uint32_t) == 4);
t = cp[3]; cp[3] = cp[0]; cp[0] = t;
t = cp[2]; cp[2] = cp[1]; cp[1] = t;
}
#endif
#if defined(DISABLE_CHECK_TIFFSWABMACROS) || !defined(TIFFSwabLong8)
void
TIFFSwabLong8(uint64_t* lp)
{
register unsigned char* cp = (unsigned char*) lp;
unsigned char t;
assert(sizeof(uint64_t) == 8);
t = cp[7]; cp[7] = cp[0]; cp[0] = t;
t = cp[6]; cp[6] = cp[1]; cp[1] = t;
t = cp[5]; cp[5] = cp[2]; cp[2] = t;
t = cp[4]; cp[4] = cp[3]; cp[3] = t;
}
#endif
#if defined(DISABLE_CHECK_TIFFSWABMACROS) || !defined(TIFFSwabArrayOfShort)
void
TIFFSwabArrayOfShort(register uint16_t* wp, tmsize_t n)
{
register unsigned char* cp;
register unsigned char t;
assert(sizeof(uint16_t) == 2);
/* XXX unroll loop some */
while (n-- > 0) {
cp = (unsigned char*) wp;
t = cp[1]; cp[1] = cp[0]; cp[0] = t;
wp++;
}
}
#endif
#if defined(DISABLE_CHECK_TIFFSWABMACROS) || !defined(TIFFSwabArrayOfTriples)
void
TIFFSwabArrayOfTriples(register uint8_t* tp, tmsize_t n)
{
unsigned char* cp;
unsigned char t;
/* XXX unroll loop some */
while (n-- > 0) {
cp = (unsigned char*) tp;
t = cp[2]; cp[2] = cp[0]; cp[0] = t;
tp += 3;
}
}
#endif
#if defined(DISABLE_CHECK_TIFFSWABMACROS) || !defined(TIFFSwabArrayOfLong)
void
TIFFSwabArrayOfLong(register uint32_t* lp, tmsize_t n)
{
register unsigned char *cp;
register unsigned char t;
assert(sizeof(uint32_t) == 4);
/* XXX unroll loop some */
while (n-- > 0) {
cp = (unsigned char *)lp;
t = cp[3]; cp[3] = cp[0]; cp[0] = t;
t = cp[2]; cp[2] = cp[1]; cp[1] = t;
lp++;
}
}
#endif
#if defined(DISABLE_CHECK_TIFFSWABMACROS) || !defined(TIFFSwabArrayOfLong8)
void
TIFFSwabArrayOfLong8(register uint64_t* lp, tmsize_t n)
{
register unsigned char *cp;
register unsigned char t;
assert(sizeof(uint64_t) == 8);
/* XXX unroll loop some */
while (n-- > 0) {
cp = (unsigned char *)lp;
t = cp[7]; cp[7] = cp[0]; cp[0] = t;
t = cp[6]; cp[6] = cp[1]; cp[1] = t;
t = cp[5]; cp[5] = cp[2]; cp[2] = t;
t = cp[4]; cp[4] = cp[3]; cp[3] = t;
lp++;
}
}
#endif
#if defined(DISABLE_CHECK_TIFFSWABMACROS) || !defined(TIFFSwabFloat)
void
TIFFSwabFloat(float* fp)
{
register unsigned char* cp = (unsigned char*) fp;
unsigned char t;
assert(sizeof(float)==4);
t = cp[3]; cp[3] = cp[0]; cp[0] = t;
t = cp[2]; cp[2] = cp[1]; cp[1] = t;
}
#endif
#if defined(DISABLE_CHECK_TIFFSWABMACROS) || !defined(TIFFSwabArrayOfFloat)
void
TIFFSwabArrayOfFloat(register float* fp, tmsize_t n)
{
register unsigned char *cp;
register unsigned char t;
assert(sizeof(float)==4);
/* XXX unroll loop some */
while (n-- > 0) {
cp = (unsigned char *)fp;
t = cp[3]; cp[3] = cp[0]; cp[0] = t;
t = cp[2]; cp[2] = cp[1]; cp[1] = t;
fp++;
}
}
#endif
#if defined(DISABLE_CHECK_TIFFSWABMACROS) || !defined(TIFFSwabDouble)
void
TIFFSwabDouble(double *dp)
{
register unsigned char* cp = (unsigned char*) dp;
unsigned char t;
assert(sizeof(double)==8);
t = cp[7]; cp[7] = cp[0]; cp[0] = t;
t = cp[6]; cp[6] = cp[1]; cp[1] = t;
t = cp[5]; cp[5] = cp[2]; cp[2] = t;
t = cp[4]; cp[4] = cp[3]; cp[3] = t;
}
#endif
#if defined(DISABLE_CHECK_TIFFSWABMACROS) || !defined(TIFFSwabArrayOfDouble)
void
TIFFSwabArrayOfDouble(double* dp, tmsize_t n)
{
register unsigned char *cp;
register unsigned char t;
assert(sizeof(double)==8);
/* XXX unroll loop some */
while (n-- > 0) {
cp = (unsigned char *)dp;
t = cp[7]; cp[7] = cp[0]; cp[0] = t;
t = cp[6]; cp[6] = cp[1]; cp[1] = t;
t = cp[5]; cp[5] = cp[2]; cp[2] = t;
t = cp[4]; cp[4] = cp[3]; cp[3] = t;
dp++;
}
}
#endif
/*
* Bit reversal tables. TIFFBitRevTable[<byte>] gives
* the bit reversed value of <byte>. Used in various
* places in the library when the FillOrder requires
* bit reversal of byte values (e.g. CCITT Fax 3
* encoding/decoding). TIFFNoBitRevTable is provided
* for algorithms that want an equivalent table that
* do not reverse bit values.
*/
static const unsigned char TIFFBitRevTable[256] = {
0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
};
static const unsigned char TIFFNoBitRevTable[256] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
};
const unsigned char*
TIFFGetBitRevTable(int reversed)
{
return (reversed ? TIFFBitRevTable : TIFFNoBitRevTable);
}
void
TIFFReverseBits(uint8_t* cp, tmsize_t n)
{
for (; n > 8; n -= 8) {
cp[0] = TIFFBitRevTable[cp[0]];
cp[1] = TIFFBitRevTable[cp[1]];
cp[2] = TIFFBitRevTable[cp[2]];
cp[3] = TIFFBitRevTable[cp[3]];
cp[4] = TIFFBitRevTable[cp[4]];
cp[5] = TIFFBitRevTable[cp[5]];
cp[6] = TIFFBitRevTable[cp[6]];
cp[7] = TIFFBitRevTable[cp[7]];
cp += 8;
}
while (n-- > 0) {
*cp = TIFFBitRevTable[*cp];
cp++;
}
}
/* vim: set ts=8 sts=8 sw=8 noet: */
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
*
* 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.
*
* 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
* OF THIS SOFTWARE.
*/
#include "tiffiop.h"
#include <assert.h>
#ifdef THUNDER_SUPPORT
/*
* TIFF Library.
*
* ThunderScan 4-bit Compression Algorithm Support
*/
/*
* ThunderScan uses an encoding scheme designed for
* 4-bit pixel values. Data is encoded in bytes, with
* each byte split into a 2-bit code word and a 6-bit
* data value. The encoding gives raw data, runs of
* pixels, or pixel values encoded as a delta from the
* previous pixel value. For the latter, either 2-bit
* or 3-bit delta values are used, with the deltas packed
* into a single byte.
*/
#define THUNDER_DATA 0x3f /* mask for 6-bit data */
#define THUNDER_CODE 0xc0 /* mask for 2-bit code word */
/* code values */
#define THUNDER_RUN 0x00 /* run of pixels w/ encoded count */
#define THUNDER_2BITDELTAS 0x40 /* 3 pixels w/ encoded 2-bit deltas */
#define DELTA2_SKIP 2 /* skip code for 2-bit deltas */
#define THUNDER_3BITDELTAS 0x80 /* 2 pixels w/ encoded 3-bit deltas */
#define DELTA3_SKIP 4 /* skip code for 3-bit deltas */
#define THUNDER_RAW 0xc0 /* raw data encoded */
static const int twobitdeltas[4] = { 0, 1, 0, -1 };
static const int threebitdeltas[8] = { 0, 1, 2, 3, 0, -3, -2, -1 };
#define SETPIXEL(op, v) { \
lastpixel = (v) & 0xf; \
if ( npixels < maxpixels ) \
{ \
if (npixels++ & 1) \
*op++ |= lastpixel; \
else \
op[0] = (uint8_t) (lastpixel << 4); \
} \
}
static int
ThunderSetupDecode(TIFF* tif)
{
static const char module[] = "ThunderSetupDecode";
if( tif->tif_dir.td_bitspersample != 4 )
{
TIFFErrorExt(tif->tif_clientdata, module,
"Wrong bitspersample value (%d), Thunder decoder only supports 4bits per sample.",
(int) tif->tif_dir.td_bitspersample );
return 0;
}
return (1);
}
static int
ThunderDecode(TIFF* tif, uint8_t* op, tmsize_t maxpixels)
{
static const char module[] = "ThunderDecode";
register unsigned char *bp;
register tmsize_t cc;
unsigned int lastpixel;
tmsize_t npixels;
bp = (unsigned char *)tif->tif_rawcp;
cc = tif->tif_rawcc;
lastpixel = 0;
npixels = 0;
while (cc > 0 && npixels < maxpixels) {
int n, delta;
n = *bp++;
cc--;
switch (n & THUNDER_CODE) {
case THUNDER_RUN: /* pixel run */
/*
* Replicate the last pixel n times,
* where n is the lower-order 6 bits.
*/
if (npixels & 1) {
op[0] |= lastpixel;
lastpixel = *op++; npixels++; n--;
} else
lastpixel |= lastpixel << 4;
npixels += n;
if (npixels < maxpixels) {
for (; n > 0; n -= 2)
*op++ = (uint8_t) lastpixel;
}
if (n == -1)
*--op &= 0xf0;
lastpixel &= 0xf;
break;
case THUNDER_2BITDELTAS: /* 2-bit deltas */
if ((delta = ((n >> 4) & 3)) != DELTA2_SKIP)
SETPIXEL(op, (unsigned)((int)lastpixel + twobitdeltas[delta]));
if ((delta = ((n >> 2) & 3)) != DELTA2_SKIP)
SETPIXEL(op, (unsigned)((int)lastpixel + twobitdeltas[delta]));
if ((delta = (n & 3)) != DELTA2_SKIP)
SETPIXEL(op, (unsigned)((int)lastpixel + twobitdeltas[delta]));
break;
case THUNDER_3BITDELTAS: /* 3-bit deltas */
if ((delta = ((n >> 3) & 7)) != DELTA3_SKIP)
SETPIXEL(op, (unsigned)((int)lastpixel + threebitdeltas[delta]));
if ((delta = (n & 7)) != DELTA3_SKIP)
SETPIXEL(op, (unsigned)((int)lastpixel + threebitdeltas[delta]));
break;
case THUNDER_RAW: /* raw data */
SETPIXEL(op, n);
break;
}
}
tif->tif_rawcp = (uint8_t*) bp;
tif->tif_rawcc = cc;
if (npixels != maxpixels) {
TIFFErrorExt(tif->tif_clientdata, module,
"%s data at scanline %lu (%"PRIu64" != %"PRIu64")",
npixels < maxpixels ? "Not enough" : "Too much",
(unsigned long) tif->tif_row,
(uint64_t) npixels,
(uint64_t) maxpixels);
return (0);
}
return (1);
}
static int
ThunderDecodeRow(TIFF* tif, uint8_t* buf, tmsize_t occ, uint16_t s)
{
static const char module[] = "ThunderDecodeRow";
uint8_t* row = buf;
(void) s;
if (occ % tif->tif_scanlinesize)
{
TIFFErrorExt(tif->tif_clientdata, module, "Fractional scanlines cannot be read");
return (0);
}
while (occ > 0) {
if (!ThunderDecode(tif, row, tif->tif_dir.td_imagewidth))
return (0);
occ -= tif->tif_scanlinesize;
row += tif->tif_scanlinesize;
}
return (1);
}
int
TIFFInitThunderScan(TIFF* tif, int scheme)
{
(void) scheme;
tif->tif_setupdecode = ThunderSetupDecode;
tif->tif_decoderow = ThunderDecodeRow;
tif->tif_decodestrip = ThunderDecodeRow;
return (1);
}
#endif /* THUNDER_SUPPORT */
/* vim: set ts=8 sts=8 sw=8 noet: */
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
/*
* Copyright (c) 1991-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
*
* 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.
*
* 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
* OF THIS SOFTWARE.
*/
/*
* TIFF Library.
*
* Tiled Image Support Routines.
*/
#include "tiffiop.h"
/*
* Compute which tile an (x,y,z,s) value is in.
*/
uint32_t
TIFFComputeTile(TIFF* tif, uint32_t x, uint32_t y, uint32_t z, uint16_t s)
{
TIFFDirectory *td = &tif->tif_dir;
uint32_t dx = td->td_tilewidth;
uint32_t dy = td->td_tilelength;
uint32_t dz = td->td_tiledepth;
uint32_t tile = 1;
if (td->td_imagedepth == 1)
z = 0;
if (dx == (uint32_t) -1)
dx = td->td_imagewidth;
if (dy == (uint32_t) -1)
dy = td->td_imagelength;
if (dz == (uint32_t) -1)
dz = td->td_imagedepth;
if (dx != 0 && dy != 0 && dz != 0) {
uint32_t xpt = TIFFhowmany_32(td->td_imagewidth, dx);
uint32_t ypt = TIFFhowmany_32(td->td_imagelength, dy);
uint32_t zpt = TIFFhowmany_32(td->td_imagedepth, dz);
if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
tile = (xpt*ypt*zpt)*s +
(xpt*ypt)*(z/dz) +
xpt*(y/dy) +
x/dx;
else
tile = (xpt*ypt)*(z/dz) + xpt*(y/dy) + x/dx;
}
return (tile);
}
/*
* Check an (x,y,z,s) coordinate
* against the image bounds.
*/
int
TIFFCheckTile(TIFF* tif, uint32_t x, uint32_t y, uint32_t z, uint16_t s)
{
TIFFDirectory *td = &tif->tif_dir;
if (x >= td->td_imagewidth) {
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
"%lu: Col out of range, max %lu",
(unsigned long) x,
(unsigned long) (td->td_imagewidth - 1));
return (0);
}
if (y >= td->td_imagelength) {
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
"%lu: Row out of range, max %lu",
(unsigned long) y,
(unsigned long) (td->td_imagelength - 1));
return (0);
}
if (z >= td->td_imagedepth) {
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
"%lu: Depth out of range, max %lu",
(unsigned long) z,
(unsigned long) (td->td_imagedepth - 1));
return (0);
}
if (td->td_planarconfig == PLANARCONFIG_SEPARATE &&
s >= td->td_samplesperpixel) {
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
"%lu: Sample out of range, max %lu",
(unsigned long) s,
(unsigned long) (td->td_samplesperpixel - 1));
return (0);
}
return (1);
}
/*
* Compute how many tiles are in an image.
*/
uint32_t
TIFFNumberOfTiles(TIFF* tif)
{
TIFFDirectory *td = &tif->tif_dir;
uint32_t dx = td->td_tilewidth;
uint32_t dy = td->td_tilelength;
uint32_t dz = td->td_tiledepth;
uint32_t ntiles;
if (dx == (uint32_t) -1)
dx = td->td_imagewidth;
if (dy == (uint32_t) -1)
dy = td->td_imagelength;
if (dz == (uint32_t) -1)
dz = td->td_imagedepth;
ntiles = (dx == 0 || dy == 0 || dz == 0) ? 0 :
_TIFFMultiply32(tif, _TIFFMultiply32(tif, TIFFhowmany_32(td->td_imagewidth, dx),
TIFFhowmany_32(td->td_imagelength, dy),
"TIFFNumberOfTiles"),
TIFFhowmany_32(td->td_imagedepth, dz), "TIFFNumberOfTiles");
if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
ntiles = _TIFFMultiply32(tif, ntiles, td->td_samplesperpixel,
"TIFFNumberOfTiles");
return (ntiles);
}
/*
* Compute the # bytes in each row of a tile.
*/
uint64_t
TIFFTileRowSize64(TIFF* tif)
{
static const char module[] = "TIFFTileRowSize64";
TIFFDirectory *td = &tif->tif_dir;
uint64_t rowsize;
uint64_t tilerowsize;
if (td->td_tilelength == 0)
{
TIFFErrorExt(tif->tif_clientdata,module,"Tile length is zero");
return 0;
}
if (td->td_tilewidth == 0)
{
TIFFErrorExt(tif->tif_clientdata,module,"Tile width is zero");
return (0);
}
rowsize = _TIFFMultiply64(tif, td->td_bitspersample, td->td_tilewidth,
"TIFFTileRowSize");
if (td->td_planarconfig == PLANARCONFIG_CONTIG)
{
if (td->td_samplesperpixel == 0)
{
TIFFErrorExt(tif->tif_clientdata,module,"Samples per pixel is zero");
return 0;
}
rowsize = _TIFFMultiply64(tif, rowsize, td->td_samplesperpixel,
"TIFFTileRowSize");
}
tilerowsize=TIFFhowmany8_64(rowsize);
if (tilerowsize == 0)
{
TIFFErrorExt(tif->tif_clientdata,module,"Computed tile row size is zero");
return 0;
}
return (tilerowsize);
}
tmsize_t
TIFFTileRowSize(TIFF* tif)
{
static const char module[] = "TIFFTileRowSize";
uint64_t m;
m=TIFFTileRowSize64(tif);
return _TIFFCastUInt64ToSSize(tif, m, module);
}
/*
* Compute the # bytes in a variable length, row-aligned tile.
*/
uint64_t
TIFFVTileSize64(TIFF* tif, uint32_t nrows)
{
static const char module[] = "TIFFVTileSize64";
TIFFDirectory *td = &tif->tif_dir;
if (td->td_tilelength == 0 || td->td_tilewidth == 0 ||
td->td_tiledepth == 0)
return (0);
if ((td->td_planarconfig==PLANARCONFIG_CONTIG)&&
(td->td_photometric==PHOTOMETRIC_YCBCR)&&
(td->td_samplesperpixel==3)&&
(!isUpSampled(tif)))
{
/*
* Packed YCbCr data contain one Cb+Cr for every
* HorizontalSampling*VerticalSampling Y values.
* Must also roundup width and height when calculating
* since images that are not a multiple of the
* horizontal/vertical subsampling area include
* YCbCr data for the extended image.
*/
uint16_t ycbcrsubsampling[2];
uint16_t samplingblock_samples;
uint32_t samplingblocks_hor;
uint32_t samplingblocks_ver;
uint64_t samplingrow_samples;
uint64_t samplingrow_size;
TIFFGetFieldDefaulted(tif,TIFFTAG_YCBCRSUBSAMPLING,ycbcrsubsampling+0,
ycbcrsubsampling+1);
if ((ycbcrsubsampling[0] != 1 && ycbcrsubsampling[0] != 2 && ycbcrsubsampling[0] != 4)
||(ycbcrsubsampling[1] != 1 && ycbcrsubsampling[1] != 2 && ycbcrsubsampling[1] != 4))
{
TIFFErrorExt(tif->tif_clientdata,module,
"Invalid YCbCr subsampling (%dx%d)",
ycbcrsubsampling[0],
ycbcrsubsampling[1] );
return 0;
}
samplingblock_samples=ycbcrsubsampling[0]*ycbcrsubsampling[1]+2;
samplingblocks_hor=TIFFhowmany_32(td->td_tilewidth,ycbcrsubsampling[0]);
samplingblocks_ver=TIFFhowmany_32(nrows,ycbcrsubsampling[1]);
samplingrow_samples=_TIFFMultiply64(tif,samplingblocks_hor,samplingblock_samples,module);
samplingrow_size=TIFFhowmany8_64(_TIFFMultiply64(tif,samplingrow_samples,td->td_bitspersample,module));
return(_TIFFMultiply64(tif,samplingrow_size,samplingblocks_ver,module));
}
else
return(_TIFFMultiply64(tif,nrows,TIFFTileRowSize64(tif),module));
}
tmsize_t
TIFFVTileSize(TIFF* tif, uint32_t nrows)
{
static const char module[] = "TIFFVTileSize";
uint64_t m;
m=TIFFVTileSize64(tif,nrows);
return _TIFFCastUInt64ToSSize(tif, m, module);
}
/*
* Compute the # bytes in a row-aligned tile.
*/
uint64_t
TIFFTileSize64(TIFF* tif)
{
return (TIFFVTileSize64(tif, tif->tif_dir.td_tilelength));
}
tmsize_t
TIFFTileSize(TIFF* tif)
{
static const char module[] = "TIFFTileSize";
uint64_t m;
m=TIFFTileSize64(tif);
return _TIFFCastUInt64ToSSize(tif, m, module);
}
/*
* Compute a default tile size based on the image
* characteristics and a requested value. If a
* request is <1 then we choose a size according
* to certain heuristics.
*/
void
TIFFDefaultTileSize(TIFF* tif, uint32_t* tw, uint32_t* th)
{
(*tif->tif_deftilesize)(tif, tw, th);
}
void
_TIFFDefaultTileSize(TIFF* tif, uint32_t* tw, uint32_t* th)
{
(void) tif;
if (*(int32_t*) tw < 1)
*tw = 256;
if (*(int32_t*) th < 1)
*th = 256;
/* roundup to a multiple of 16 per the spec */
if (*tw & 0xf)
*tw = TIFFroundup_32(*tw, 16);
if (*th & 0xf)
*th = TIFFroundup_32(*th, 16);
}
/* vim: set ts=8 sts=8 sw=8 noet: */
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
*
* 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.
*
* 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
* OF THIS SOFTWARE.
*/
/*
* TIFF Library.
*/
#include "tiffiop.h"
TIFFErrorHandlerExt _TIFFwarningHandlerExt = NULL;
TIFFErrorHandler
TIFFSetWarningHandler(TIFFErrorHandler handler)
{
TIFFErrorHandler prev = _TIFFwarningHandler;
_TIFFwarningHandler = handler;
return (prev);
}
TIFFErrorHandlerExt
TIFFSetWarningHandlerExt(TIFFErrorHandlerExt handler)
{
TIFFErrorHandlerExt prev = _TIFFwarningHandlerExt;
_TIFFwarningHandlerExt = handler;
return (prev);
}
void WINAPIV
TIFFWarning(const char* module, const char* fmt, ...)
{
va_list ap;
if (_TIFFwarningHandler) {
va_start(ap, fmt);
(*_TIFFwarningHandler)(module, fmt, ap);
va_end(ap);
}
if (_TIFFwarningHandlerExt) {
va_start(ap, fmt);
(*_TIFFwarningHandlerExt)(0, module, fmt, ap);
va_end(ap);
}
}
void WINAPIV
TIFFWarningExt(thandle_t fd, const char* module, const char* fmt, ...)
{
va_list ap;
if (_TIFFwarningHandler) {
va_start(ap, fmt);
(*_TIFFwarningHandler)(module, fmt, ap);
va_end(ap);
}
if (_TIFFwarningHandlerExt) {
va_start(ap, fmt);
(*_TIFFwarningHandlerExt)(fd, module, fmt, ap);
va_end(ap);
}
}
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
/* libtiff/tiffconf.h. Generated from tiffconf.h.in by configure. */
/*
Configuration defines for installed libtiff.
This file maintained for backward compatibility. Do not use definitions
from this file in your programs.
*/
#ifndef _TIFFCONF_
#define _TIFFCONF_
#include <stddef.h>
#include <stdint.h>
#include <inttypes.h>
/* Signed 16-bit type */
/* #undef TIFF_INT16_T */
/* Signed 32-bit type */
/* #undef TIFF_INT32_T */
/* Signed 64-bit type */
/* #undef TIFF_INT64_T */
/* Signed 8-bit type */
/* #undef TIFF_INT8_T */
/* Unsigned 16-bit type */
/* #undef TIFF_UINT16_T */
/* Unsigned 32-bit type */
/* #undef TIFF_UINT32_T */
/* Unsigned 64-bit type */
/* #undef TIFF_UINT64_T */
/* Unsigned 8-bit type */
/* #undef TIFF_UINT8_T */
/* Signed size type */
#define TIFF_SSIZE_T ssize_t
/* Compatibility stuff. */
/* Define as 0 or 1 according to the floating point format supported by the
machine */
#define HAVE_IEEEFP 1
/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */
#define HOST_FILLORDER FILLORDER_LSB2MSB
/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian
(Intel) */
#define HOST_BIGENDIAN 0
/* Support CCITT Group 3 & 4 algorithms */
#define CCITT_SUPPORT 1
/* Support JPEG compression (requires IJG JPEG library) */
#define JPEG_SUPPORT 1
/* Support JBIG compression (requires JBIG-KIT library) */
/* #undef JBIG_SUPPORT */
/* Support LERC compression */
/* #undef LERC_SUPPORT */
/* Support LogLuv high dynamic range encoding */
#define LOGLUV_SUPPORT 1
/* Support LZW algorithm */
#define LZW_SUPPORT 1
/* Support NeXT 2-bit RLE algorithm */
#define NEXT_SUPPORT 1
/* Support Old JPEG compresson (read contrib/ojpeg/README first! Compilation
fails with unpatched IJG JPEG library) */
/* #undef OJPEG_SUPPORT */
/* Support Macintosh PackBits algorithm */
#define PACKBITS_SUPPORT 1
/* Support Pixar log-format algorithm (requires Zlib) */
#define PIXARLOG_SUPPORT 1
/* Support ThunderScan 4-bit RLE algorithm */
#define THUNDER_SUPPORT 1
/* Support Deflate compression */
#define ZIP_SUPPORT 1
/* Support libdeflate enhanced compression */
/* #undef LIBDEFLATE_SUPPORT */
/* Support strip chopping (whether or not to convert single-strip uncompressed
images to multiple strips of ~8Kb to reduce memory usage) */
#define STRIPCHOP_DEFAULT TIFF_STRIPCHOP
/* Enable SubIFD tag (330) support */
#define SUBIFD_SUPPORT 1
/* Treat extra sample as alpha (default enabled). 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. */
#define DEFAULT_EXTRASAMPLE_AS_ALPHA 1
/* Pick up YCbCr subsampling info from the JPEG data stream to support files
lacking the tag (default enabled). */
#define CHECK_JPEG_YCBCR_SUBSAMPLING 1
/* Support MS MDI magic number files as TIFF */
#define MDI_SUPPORT 1
/*
* 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_ */
#define TIFFLIB_VERSION_STR "LIBTIFF, Version 4.3.0\nCopyright (c) 1988-1996 Sam Leffler\nCopyright (c) 1991-1996 Silicon Graphics, Inc."
/*
* 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 20210416
/* Version 1.0 generated April 7, 1997 by Greg Ward Larson, SGI */
#define UV_SQSIZ (float)0.003500
#define UV_NDIVS 16289
#define UV_VSTART (float)0.016940
#define UV_NVS 163
static const struct {
float ustart;
short nus, ncum;
} uv_row[UV_NVS] = {
{ (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 },
};
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment