blob: d499b63a584f99d1d5923028f7d1a2fae8c8a457 [file] [log] [blame]
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -08001/*
2 * Copyright (c) 1988-1997 Sam Leffler
3 * Copyright (c) 1991-1997 Silicon Graphics, Inc.
4 *
kumarashishg826308d2023-06-23 13:21:22 +00005 * Permission to use, copy, modify, distribute, and sell this software and
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -08006 * 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.
kumarashishg826308d2023-06-23 13:21:22 +000012 *
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 *
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080017 * 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,
kumarashishg826308d2023-06-23 13:21:22 +000020 * 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
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080022 * OF THIS SOFTWARE.
23 */
24
25/*
26 * TIFF Library
27 *
28 * Builtin Compression Scheme Configuration Support.
29 */
30#include "tiffiop.h"
31
kumarashishg826308d2023-06-23 13:21:22 +000032static int NotConfigured(TIFF *, int);
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080033
34#ifndef LZW_SUPPORT
35#define TIFFInitLZW NotConfigured
36#endif
37#ifndef PACKBITS_SUPPORT
38#define TIFFInitPackBits NotConfigured
39#endif
40#ifndef THUNDER_SUPPORT
41#define TIFFInitThunderScan NotConfigured
42#endif
43#ifndef NEXT_SUPPORT
44#define TIFFInitNeXT NotConfigured
45#endif
46#ifndef JPEG_SUPPORT
47#define TIFFInitJPEG NotConfigured
48#endif
49#ifndef OJPEG_SUPPORT
50#define TIFFInitOJPEG NotConfigured
51#endif
52#ifndef CCITT_SUPPORT
53#define TIFFInitCCITTRLE NotConfigured
54#define TIFFInitCCITTRLEW NotConfigured
55#define TIFFInitCCITTFax3 NotConfigured
56#define TIFFInitCCITTFax4 NotConfigured
57#endif
58#ifndef JBIG_SUPPORT
59#define TIFFInitJBIG NotConfigured
60#endif
61#ifndef ZIP_SUPPORT
62#define TIFFInitZIP NotConfigured
63#endif
64#ifndef PIXARLOG_SUPPORT
65#define TIFFInitPixarLog NotConfigured
66#endif
67#ifndef LOGLUV_SUPPORT
68#define TIFFInitSGILog NotConfigured
69#endif
kumarashishg826308d2023-06-23 13:21:22 +000070#ifndef LERC_SUPPORT
71#define TIFFInitLERC NotConfigured
72#endif
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080073#ifndef LZMA_SUPPORT
74#define TIFFInitLZMA NotConfigured
75#endif
Haibo Huang49cc9302020-04-27 16:14:24 -070076#ifndef ZSTD_SUPPORT
77#define TIFFInitZSTD NotConfigured
78#endif
79#ifndef WEBP_SUPPORT
80#define TIFFInitWebP NotConfigured
81#endif
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080082
83/*
84 * Compression schemes statically built into the library.
85 */
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080086const TIFFCodec _TIFFBuiltinCODECS[] = {
kumarashishg826308d2023-06-23 13:21:22 +000087 {"None", COMPRESSION_NONE, TIFFInitDumpMode},
88 {"LZW", COMPRESSION_LZW, TIFFInitLZW},
89 {"PackBits", COMPRESSION_PACKBITS, TIFFInitPackBits},
90 {"ThunderScan", COMPRESSION_THUNDERSCAN, TIFFInitThunderScan},
91 {"NeXT", COMPRESSION_NEXT, TIFFInitNeXT},
92 {"JPEG", COMPRESSION_JPEG, TIFFInitJPEG},
93 {"Old-style JPEG", COMPRESSION_OJPEG, TIFFInitOJPEG},
94 {"CCITT RLE", COMPRESSION_CCITTRLE, TIFFInitCCITTRLE},
95 {"CCITT RLE/W", COMPRESSION_CCITTRLEW, TIFFInitCCITTRLEW},
96 {"CCITT Group 3", COMPRESSION_CCITTFAX3, TIFFInitCCITTFax3},
97 {"CCITT Group 4", COMPRESSION_CCITTFAX4, TIFFInitCCITTFax4},
98 {"ISO JBIG", COMPRESSION_JBIG, TIFFInitJBIG},
99 {"Deflate", COMPRESSION_DEFLATE, TIFFInitZIP},
100 {"AdobeDeflate", COMPRESSION_ADOBE_DEFLATE, TIFFInitZIP},
101 {"PixarLog", COMPRESSION_PIXARLOG, TIFFInitPixarLog},
102 {"SGILog", COMPRESSION_SGILOG, TIFFInitSGILog},
103 {"SGILog24", COMPRESSION_SGILOG24, TIFFInitSGILog},
104 {"LZMA", COMPRESSION_LZMA, TIFFInitLZMA},
105 {"ZSTD", COMPRESSION_ZSTD, TIFFInitZSTD},
106 {"WEBP", COMPRESSION_WEBP, TIFFInitWebP},
107 {"LERC", COMPRESSION_LERC, TIFFInitLERC},
108 {NULL, 0, NULL}};
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800109
kumarashishg826308d2023-06-23 13:21:22 +0000110static int _notConfigured(TIFF *tif)
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800111{
kumarashishg826308d2023-06-23 13:21:22 +0000112 const TIFFCodec *c = TIFFFindCODEC(tif->tif_dir.td_compression);
113 char compression_code[20];
114
115 snprintf(compression_code, sizeof(compression_code), "%" PRIu16,
116 tif->tif_dir.td_compression);
117 TIFFErrorExtR(tif, tif->tif_name,
118 "%s compression support is not configured",
119 c ? c->name : compression_code);
120 return (0);
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800121}
122
kumarashishg826308d2023-06-23 13:21:22 +0000123static int NotConfigured(TIFF *tif, int scheme)
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800124{
kumarashishg826308d2023-06-23 13:21:22 +0000125 (void)scheme;
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800126
kumarashishg826308d2023-06-23 13:21:22 +0000127 tif->tif_fixuptags = _notConfigured;
128 tif->tif_decodestatus = FALSE;
129 tif->tif_setupdecode = _notConfigured;
130 tif->tif_encodestatus = FALSE;
131 tif->tif_setupencode = _notConfigured;
132 return (1);
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800133}
134
135/************************************************************************/
136/* TIFFIsCODECConfigured() */
137/************************************************************************/
138
139/**
140 * Check whether we have working codec for the specific coding scheme.
141 *
142 * @return returns 1 if the codec is configured and working. Otherwise
143 * 0 will be returned.
144 */
145
kumarashishg826308d2023-06-23 13:21:22 +0000146int TIFFIsCODECConfigured(uint16_t scheme)
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800147{
kumarashishg826308d2023-06-23 13:21:22 +0000148 const TIFFCodec *codec = TIFFFindCODEC(scheme);
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800149
kumarashishg826308d2023-06-23 13:21:22 +0000150 if (codec == NULL)
151 {
152 return 0;
153 }
154 if (codec->init == NULL)
155 {
156 return 0;
157 }
158 if (codec->init != NotConfigured)
159 {
160 return 1;
161 }
162 return 0;
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800163}