LibTIFF 4.7.2
TIFF library public API and implementation reference
Loading...
Searching...
No Matches
tif_codec.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 1988-1997 Sam Leffler
3 * Copyright (c) 1991-1997 Silicon Graphics, Inc.
4 *
5 * Permission to use, copy, modify, distribute, and sell this software and
6 * its documentation for any purpose is hereby granted without fee, provided
7 * that (i) the above copyright notices and this permission notice appear in
8 * all copies of the software and related documentation, and (ii) the names of
9 * Sam Leffler and Silicon Graphics may not be used in any advertising or
10 * publicity relating to the software without the specific, prior written
11 * permission of Sam Leffler and Silicon Graphics.
12 *
13 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
14 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
16 *
17 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
18 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22 * OF THIS SOFTWARE.
23 */
24
25/*
26 * TIFF Library
27 *
28 * Builtin Compression Scheme Configuration Support.
29 */
35#include "tiffiop.h"
36
37static int NotConfigured(TIFF *, int);
38
39#ifndef LZW_SUPPORT
40#define TIFFInitLZW NotConfigured
41#endif
42#ifndef PACKBITS_SUPPORT
43#define TIFFInitPackBits NotConfigured
44#endif
45#ifndef THUNDER_SUPPORT
46#define TIFFInitThunderScan NotConfigured
47#endif
48#ifndef NEXT_SUPPORT
49#define TIFFInitNeXT NotConfigured
50#endif
51#ifndef JPEG_SUPPORT
52#define TIFFInitJPEG NotConfigured
53#endif
54#ifndef OJPEG_SUPPORT
55#define TIFFInitOJPEG NotConfigured
56#endif
57#ifndef CCITT_SUPPORT
58#define TIFFInitCCITTRLE NotConfigured
59#define TIFFInitCCITTRLEW NotConfigured
60#define TIFFInitCCITTFax3 NotConfigured
61#define TIFFInitCCITTFax4 NotConfigured
62#endif
63#ifndef JBIG_SUPPORT
64#define TIFFInitJBIG NotConfigured
65#endif
66#ifndef ZIP_SUPPORT
67#define TIFFInitZIP NotConfigured
68#endif
69#ifndef PIXARLOG_SUPPORT
70#define TIFFInitPixarLog NotConfigured
71#endif
72#ifndef LOGLUV_SUPPORT
73#define TIFFInitSGILog NotConfigured
74#endif
75#ifndef LERC_SUPPORT
76#define TIFFInitLERC NotConfigured
77#endif
78#ifndef LZMA_SUPPORT
79#define TIFFInitLZMA NotConfigured
80#endif
81#ifndef ZSTD_SUPPORT
82#define TIFFInitZSTD NotConfigured
83#endif
84#ifndef WEBP_SUPPORT
85#define TIFFInitWebP NotConfigured
86#endif
87
88/*
89 * Compression schemes statically built into the library.
90 */
98 {"Old-style JPEG", COMPRESSION_OJPEG, TIFFInitOJPEG},
101 {"CCITT Group 3", COMPRESSION_CCITTFAX3, TIFFInitCCITTFax3},
102 {"CCITT Group 4", COMPRESSION_CCITTFAX4, TIFFInitCCITTFax4},
103 {"ISO JBIG", COMPRESSION_JBIG, TIFFInitJBIG},
104 {"Deflate", COMPRESSION_DEFLATE, TIFFInitZIP},
105 {"AdobeDeflate", COMPRESSION_ADOBE_DEFLATE, TIFFInitZIP},
113 {NULL, 0, NULL}};
114
126static int _notConfigured(TIFF *tif)
127{
129 char compression_code[20];
130
131 snprintf(compression_code, sizeof(compression_code), "%" PRIu16,
133 TIFFErrorExtR(tif, tif->tif_name,
134 "%s compression support is not configured",
135 c ? c->name : compression_code);
136 return (0);
137}
138
153static int NotConfigured(TIFF *tif, int scheme)
154{
155 (void)scheme;
156
158 tif->tif_decodestatus = FALSE;
160 tif->tif_encodestatus = FALSE;
162 return (1);
163}
164
165/************************************************************************/
166/* TIFFIsCODECConfigured() */
167/************************************************************************/
168
169/* The public contract is documented with the declaration in tiffio.h. */
170
171int TIFFIsCODECConfigured(uint16_t scheme)
172{
173 const TIFFCodec *codec = TIFFFindCODEC(scheme);
174
175 if (codec == NULL)
176 {
177 return 0;
178 }
179 if (codec->init == NULL)
180 {
181 return 0;
182 }
183 if (codec->init != NotConfigured)
184 {
185 return 1;
186 }
187 return 0;
188}
189
int TIFFInitThunderScan(TIFF *tif, int scheme)
Install ThunderScan transfer callbacks.
int TIFFInitPackBits(TIFF *tif, int scheme)
Install PackBits transfer callbacks.
int TIFFInitNeXT(TIFF *tif, int scheme)
Install NeXT transfer callbacks.
Definition tif_next.c:262
int TIFFInitDumpMode(TIFF *tif, int scheme)
Install uncompressed transfer callbacks.
static int NotConfigured(TIFF *, int)
Install unavailable-codec setup methods while accepting metadata access.
Definition tif_codec.c:153
static int _notConfigured(TIFF *tif)
Report that the current compression support was not built.
Definition tif_codec.c:126
const TIFFCodec _TIFFBuiltinCODECS[]
Describe built-in compression names and initialisers.
Definition tif_codec.c:91
int TIFFInitZIP(TIFF *tif, int scheme)
Install predictor-aware Deflate codec and allocator hooks.
Definition tif_zip.c:1018
int TIFFInitCCITTRLE(TIFF *tif, int scheme)
Install CCITTRLE fax callbacks and default mode.
Definition tif_fax3.c:2674
int TIFFInitCCITTRLEW(TIFF *tif, int scheme)
Install CCITTRLEW fax callbacks and default mode.
Definition tif_fax3.c:2693
int TIFFInitCCITTFax4(TIFF *tif, int scheme)
Install CCITTFax4 fax callbacks and default mode.
Definition tif_fax3.c:2512
int TIFFInitCCITTFax3(TIFF *tif, int scheme)
Install CCITTFax3 fax callbacks and default mode.
Definition tif_fax3.c:2263
int TIFFInitJBIG(TIFF *tif, int scheme)
Install single-strip JBIG callbacks and mutable raw-input policy.
Definition tif_jbig.c:387
int TIFFInitJPEG(TIFF *tif, int scheme)
Allocate JPEG-in-TIFF codec state and install method chains.
Definition tif_jpeg.c:4724
int TIFFInitLERC(TIFF *tif, int scheme)
Allocate LERC staging state and install frame callbacks and pseudo-tags.
Definition tif_lerc.c:1863
int TIFFInitLZMA(TIFF *tif, int scheme)
Allocate predictor-aware LZMA2 codec state and install callbacks.
Definition tif_lzma.c:741
int TIFFInitLZW(TIFF *tif, int scheme)
Allocate LZW codec state and install predictor-aware methods.
Definition tif_lzw.c:1742
int TIFFInitOJPEG(TIFF *tif, int scheme)
Install the decode-only old-style JPEG codec.
Definition tif_ojpeg.c:1020
int TIFFInitPixarLog(TIFF *tif, int scheme)
Install PixarLog codec state methods and companding tables.
int TIFFInitSGILog(TIFF *tif, int scheme)
Allocate SGILog codec state and install row dispatch and tag hooks.
Definition tif_luv.c:2981
#define FALSE
Represent the legacy internal false value.
Definition tiffiop.h:136
int TIFFInitWebP(TIFF *tif, int scheme)
Allocate WebP codec state and install buffered frame callbacks.
Definition tif_webp.c:1167
int TIFFInitZSTD(TIFF *tif, int scheme)
Allocate ZSTD state and install predictor-aware streaming methods.
Definition tif_zstd.c:603
const TIFFCodec * TIFFFindCODEC(uint16_t scheme)
Find the highest-priority descriptor for a compression scheme.
int TIFFIsCODECConfigured(uint16_t scheme)
Check whether the selected descriptor has a configured initialiser.
Definition tif_codec.c:171
void TIFFErrorExtR(TIFF *tif, const char *module, const char *fmt,...)
Dispatch a error diagnostic to the configured handlers.
Definition tif_error.c:112
#define COMPRESSION_NONE
Dump mode.
Definition tiff.h:302
#define COMPRESSION_PIXARLOG
Pixar companded 11bit ZIP.
Definition tiff.h:347
#define COMPRESSION_ZSTD
Zstandard compression; not registered in the Adobe-maintained registry.
Definition tiff.h:372
#define COMPRESSION_CCITTFAX3
CCITT Group 3 fax encoding.
Definition tiff.h:306
#define COMPRESSION_CCITTRLE
CCITT modified Huffman RLE.
Definition tiff.h:304
#define COMPRESSION_OJPEG
6.0 JPEG (introduced in TIFF 6.0).
Definition tiff.h:316
#define COMPRESSION_DEFLATE
Deflate compression, legacy tag.
Definition tiff.h:349
#define COMPRESSION_SGILOG
SGI Log Luminance RLE.
Definition tiff.h:358
#define COMPRESSION_CCITTRLEW
CCITT modified Huffman RLE with word alignment.
Definition tiff.h:329
#define COMPRESSION_LZMA
LZMA2.
Definition tiff.h:367
#define COMPRESSION_WEBP
WebP compression; not registered in the Adobe-maintained registry.
Definition tiff.h:374
#define COMPRESSION_JBIG
ISO JBIG.
Definition tiff.h:356
#define COMPRESSION_LERC
ESRI LERC compression.
Definition tiff.h:364
#define COMPRESSION_ADOBE_DEFLATE
Deflate compression, as recognized by Adobe.
Definition tiff.h:351
#define COMPRESSION_PACKBITS
Macintosh RLE.
Definition tiff.h:331
#define COMPRESSION_LZW
Lempel-Ziv & Welch.
Definition tiff.h:314
#define COMPRESSION_SGILOG24
SGI Log 24-bit packed.
Definition tiff.h:360
#define COMPRESSION_CCITTFAX4
CCITT Group 4 fax encoding.
Definition tiff.h:310
#define COMPRESSION_NEXT
NeXT 2-bit RLE.
Definition tiff.h:327
#define COMPRESSION_JPEG
JPEG DCT compression (introduced after TIFF 6.0).
Definition tiff.h:318
#define COMPRESSION_THUNDERSCAN
ThunderScan RLE.
Definition tiff.h:333
Describe a named compression scheme and its initialiser.
Definition tiffio.h:706
const char * name
Codec name; storage lifetime follows the API supplying this descriptor.
Definition tiffio.h:711
TIFFInitMethod init
Callback that installs the codec on a TIFF handle.
Definition tiffio.h:715
uint16_t td_compression
COMPRESSION_* codec identifier.
Definition tif_dir.h:172
Hold private state for one open TIFF library instance.
Definition tiffiop.h:389
TIFFBoolMethod tif_fixuptags
Codec callback for directory-dependent tag corrections.
Definition tiffiop.h:626
char * tif_name
Current filename pointer; may refer to inline or client-supplied storage.
Definition tiffiop.h:394
TIFFBoolMethod tif_setupencode
Codec setup callback run before preencode.
Definition tiffiop.h:632
TIFFDirectory tif_dir
Inline representation of the current image directory.
Definition tiffiop.h:572
int tif_decodestatus
Nonzero unless the selected scheme is a known but unconfigured codec; not a setup result.
Definition tiffiop.h:624
int tif_encodestatus
Nonzero unless the selected scheme is a known but unconfigured codec; never read.
Definition tiffiop.h:637
TIFFBoolMethod tif_setupdecode
Codec setup callback run before predecode.
Definition tiffiop.h:628
Declare private library state, callbacks, and implementation helpers.