1 /* PDFlib GmbH cvsid:
2 * $Id: tif_codec.c,v 1.8 2005/12/21 13:22:05 rjs Exp $ */
3
4 /*
5 * Copyright (c) 1988-1997 Sam Leffler
6 * Copyright (c) 1991-1997 Silicon Graphics, Inc.
7 *
8 * Permission to use, copy, modify, distribute, and sell this software and
9 * its documentation for any purpose is hereby granted without fee, provided
10 * that (i) the above copyright notices and this permission notice appear in
11 * all copies of the software and related documentation, and (ii) the names of
12 * Sam Leffler and Silicon Graphics may not be used in any advertising or
13 * publicity relating to the software without the specific, prior written
14 * permission of Sam Leffler and Silicon Graphics.
15 *
16 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
18 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
19 *
20 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
21 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
22 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
23 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
24 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
25 * OF THIS SOFTWARE.
26 */
27
28 /*
29 * TIFF Library
30 *
31 * Builtin Compression Scheme Configuration Support.
32 */
33 #include "tiffiop.h"
34
35 static int NotConfigured(TIFF*, int);
36
37 #ifndef LZW_SUPPORT
38 #define TIFFInitLZW NotConfigured
39 #endif
40 #ifndef PACKBITS_SUPPORT
41 #define TIFFInitPackbits NotConfigured
42 #endif
43 #ifndef THUNDER_SUPPORT
44 #define TIFFInitThunderScan NotConfigured
45 #endif
46 #ifndef NEXT_SUPPORT
47 #define TIFFInitNeXT NotConfigured
48 #endif
49 #ifndef JPEG_SUPPORT
50 #define TIFFInitJPEG NotConfigured
51 #endif
52 #ifndef OJPEG_SUPPORT
53 #define TIFFInitOJPEG NotConfigured
54 #endif
55 #ifndef CCITT_SUPPORT
56 #define TIFFInitCCITTRLE NotConfigured
57 #define TIFFInitCCITTRLEW NotConfigured
58 #define TIFFInitCCITTFax3 NotConfigured
59 #define TIFFInitCCITTFax4 NotConfigured
60 #endif
61 #ifndef JBIG_SUPPORT
62 #define TIFFInitJBIG NotConfigured
63 #endif
64 #ifndef ZIP_SUPPORT
65 #define TIFFInitZIP NotConfigured
66 #endif
67 #ifndef PIXARLOG_SUPPORT
68 #define TIFFInitPixarLog NotConfigured
69 #endif
70 #ifndef LOGLUV_SUPPORT
71 #define TIFFInitSGILog NotConfigured
72 #endif
73
74 /*
75 * Compression schemes statically built into the library.
76 */
77 #ifdef VMS
78 const TIFFCodec _TIFFBuiltinCODECS[] = {
79 #else
80 TIFFCodec _TIFFBuiltinCODECS[] = {
81 #endif
82 { "None", COMPRESSION_NONE, TIFFInitDumpMode },
83 { "LZW", COMPRESSION_LZW, TIFFInitLZW },
84 { "PackBits", COMPRESSION_PACKBITS, TIFFInitPackBits },
85 { "ThunderScan", COMPRESSION_THUNDERSCAN,TIFFInitThunderScan },
86 { "NeXT", COMPRESSION_NEXT, TIFFInitNeXT },
87 { "JPEG", COMPRESSION_JPEG, TIFFInitJPEG },
88 { "Old-style JPEG", COMPRESSION_OJPEG, TIFFInitOJPEG },
89 { "CCITT RLE", COMPRESSION_CCITTRLE, TIFFInitCCITTRLE },
90 { "CCITT RLE/W", COMPRESSION_CCITTRLEW, TIFFInitCCITTRLEW },
91 { "CCITT Group 3", COMPRESSION_CCITTFAX3, TIFFInitCCITTFax3 },
92 { "CCITT Group 4", COMPRESSION_CCITTFAX4, TIFFInitCCITTFax4 },
93 { "ISO JBIG", COMPRESSION_JBIG, TIFFInitJBIG },
94 { "Deflate", COMPRESSION_DEFLATE, TIFFInitZIP },
95 { "AdobeDeflate", COMPRESSION_ADOBE_DEFLATE , TIFFInitZIP },
96 { "PixarLog", COMPRESSION_PIXARLOG, TIFFInitPixarLog },
97 { "SGILog", COMPRESSION_SGILOG, TIFFInitSGILog },
98 { "SGILog24", COMPRESSION_SGILOG24, TIFFInitSGILog },
99 { NULL }
100 };
101
102 static int
_notConfigured(TIFF * tif)103 _notConfigured(TIFF* tif)
104 {
105 const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression);
106
107 _TIFFError(tif, tif->tif_name,
108 "%s compression support is not configured", c->name);
109 return (0);
110 }
111
112 static int
NotConfigured(TIFF * tif,int scheme)113 NotConfigured(TIFF* tif, int scheme)
114 {
115 (void) scheme;
116
117 tif->tif_decodestatus = FALSE;
118 tif->tif_setupdecode = _notConfigured;
119 tif->tif_encodestatus = FALSE;
120 tif->tif_setupencode = _notConfigured;
121 return (1);
122 }
123
124 /************************************************************************/
125 /* TIFFIsCODECConfigured() */
126 /************************************************************************/
127
128 /**
129 * Check whether we have working codec for the specific coding scheme.
130 *
131 * @return returns 1 if the codec is configured and working. Otherwise
132 * 0 will be returned.
133 */
134
135 int
TIFFIsCODECConfigured(uint16 scheme)136 TIFFIsCODECConfigured(uint16 scheme)
137 {
138 const TIFFCodec* codec = TIFFFindCODEC(scheme);
139
140 if(codec == NULL) {
141 return 0;
142 }
143 if(codec->init == NULL) {
144 return 0;
145 }
146 if(codec->init != NotConfigured){
147 return 1;
148 }
149 return 0;
150 }
151
152