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 */
30 #include "tiffiop.h"
31
32 static int NotConfigured(TIFF*, int);
33
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
70 #ifndef LZMA_SUPPORT
71 #define TIFFInitLZMA NotConfigured
72 #endif
73 #ifndef ZSTD_SUPPORT
74 #define TIFFInitZSTD NotConfigured
75 #endif
76 #ifndef WEBP_SUPPORT
77 #define TIFFInitWebP NotConfigured
78 #endif
79
80 /*
81 * Compression schemes statically built into the library.
82 */
83 #ifdef VMS
84 const TIFFCodec _TIFFBuiltinCODECS[] = {
85 #else
86 TIFFCodec _TIFFBuiltinCODECS[] = {
87 #endif
88 { "None", COMPRESSION_NONE, TIFFInitDumpMode },
89 { "LZW", COMPRESSION_LZW, TIFFInitLZW },
90 { "PackBits", COMPRESSION_PACKBITS, TIFFInitPackBits },
91 { "ThunderScan", COMPRESSION_THUNDERSCAN,TIFFInitThunderScan },
92 { "NeXT", COMPRESSION_NEXT, TIFFInitNeXT },
93 { "JPEG", COMPRESSION_JPEG, TIFFInitJPEG },
94 { "Old-style JPEG", COMPRESSION_OJPEG, TIFFInitOJPEG },
95 { "CCITT RLE", COMPRESSION_CCITTRLE, TIFFInitCCITTRLE },
96 { "CCITT RLE/W", COMPRESSION_CCITTRLEW, TIFFInitCCITTRLEW },
97 { "CCITT Group 3", COMPRESSION_CCITTFAX3, TIFFInitCCITTFax3 },
98 { "CCITT Group 4", COMPRESSION_CCITTFAX4, TIFFInitCCITTFax4 },
99 { "ISO JBIG", COMPRESSION_JBIG, TIFFInitJBIG },
100 { "Deflate", COMPRESSION_DEFLATE, TIFFInitZIP },
101 { "AdobeDeflate", COMPRESSION_ADOBE_DEFLATE , TIFFInitZIP },
102 { "PixarLog", COMPRESSION_PIXARLOG, TIFFInitPixarLog },
103 { "SGILog", COMPRESSION_SGILOG, TIFFInitSGILog },
104 { "SGILog24", COMPRESSION_SGILOG24, TIFFInitSGILog },
105 { "LZMA", COMPRESSION_LZMA, TIFFInitLZMA },
106 { "ZSTD", COMPRESSION_ZSTD, TIFFInitZSTD },
107 { "WEBP", COMPRESSION_WEBP, TIFFInitWebP },
108 { NULL, 0, NULL }
109 };
110
111 static int
_notConfigured(TIFF * tif)112 _notConfigured(TIFF* tif)
113 {
114 const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression);
115 char compression_code[20];
116
117 sprintf(compression_code, "%d",tif->tif_dir.td_compression );
118 TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
119 "%s compression support is not configured",
120 c ? c->name : compression_code );
121 return (0);
122 }
123
124 static int
NotConfigured(TIFF * tif,int scheme)125 NotConfigured(TIFF* tif, int scheme)
126 {
127 (void) scheme;
128
129 tif->tif_fixuptags = _notConfigured;
130 tif->tif_decodestatus = FALSE;
131 tif->tif_setupdecode = _notConfigured;
132 tif->tif_encodestatus = FALSE;
133 tif->tif_setupencode = _notConfigured;
134 return (1);
135 }
136
137 /************************************************************************/
138 /* TIFFIsCODECConfigured() */
139 /************************************************************************/
140
141 /**
142 * Check whether we have working codec for the specific coding scheme.
143 *
144 * @return returns 1 if the codec is configured and working. Otherwise
145 * 0 will be returned.
146 */
147
148 int
TIFFIsCODECConfigured(uint16 scheme)149 TIFFIsCODECConfigured(uint16 scheme)
150 {
151 const TIFFCodec* codec = TIFFFindCODEC(scheme);
152
153 if(codec == NULL) {
154 return 0;
155 }
156 if(codec->init == NULL) {
157 return 0;
158 }
159 if(codec->init != NotConfigured){
160 return 1;
161 }
162 return 0;
163 }
164
165 /*
166 * Local Variables:
167 * mode: c
168 * c-basic-offset: 8
169 * fill-column: 78
170 * End:
171 */
172