xref: /reactos/dll/3rdparty/libtiff/tif_codec.c (revision c2c66aff)
1 /* $Id: tif_codec.c,v 1.17 2015-08-19 02:31:04 bfriesen Exp $ */
2 
3 /*
4  * Copyright (c) 1988-1997 Sam Leffler
5  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
6  *
7  * Permission to use, copy, modify, distribute, and sell this software and
8  * its documentation for any purpose is hereby granted without fee, provided
9  * that (i) the above copyright notices and this permission notice appear in
10  * all copies of the software and related documentation, and (ii) the names of
11  * Sam Leffler and Silicon Graphics may not be used in any advertising or
12  * publicity relating to the software without the specific, prior written
13  * permission of Sam Leffler and Silicon Graphics.
14  *
15  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
17  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
18  *
19  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
20  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
21  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
22  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
23  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24  * OF THIS SOFTWARE.
25  */
26 
27 /*
28  * TIFF Library
29  *
30  * Builtin Compression Scheme Configuration Support.
31  */
32 
33 #include <precomp.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 #ifndef LZMA_SUPPORT
74 #define TIFFInitLZMA NotConfigured
75 #endif
76 
77 /*
78  * Compression schemes statically built into the library.
79  */
80 #ifdef VMS
81 const TIFFCodec _TIFFBuiltinCODECS[] = {
82 #else
83 TIFFCodec _TIFFBuiltinCODECS[] = {
84 #endif
85     { "None",		COMPRESSION_NONE,	TIFFInitDumpMode },
86     { "LZW",		COMPRESSION_LZW,	TIFFInitLZW },
87     { "PackBits",	COMPRESSION_PACKBITS,	TIFFInitPackBits },
88     { "ThunderScan",	COMPRESSION_THUNDERSCAN,TIFFInitThunderScan },
89     { "NeXT",		COMPRESSION_NEXT,	TIFFInitNeXT },
90     { "JPEG",		COMPRESSION_JPEG,	TIFFInitJPEG },
91     { "Old-style JPEG",	COMPRESSION_OJPEG,	TIFFInitOJPEG },
92     { "CCITT RLE",	COMPRESSION_CCITTRLE,	TIFFInitCCITTRLE },
93     { "CCITT RLE/W",	COMPRESSION_CCITTRLEW,	TIFFInitCCITTRLEW },
94     { "CCITT Group 3",	COMPRESSION_CCITTFAX3,	TIFFInitCCITTFax3 },
95     { "CCITT Group 4",	COMPRESSION_CCITTFAX4,	TIFFInitCCITTFax4 },
96     { "ISO JBIG",	COMPRESSION_JBIG,	TIFFInitJBIG },
97     { "Deflate",	COMPRESSION_DEFLATE,	TIFFInitZIP },
98     { "AdobeDeflate",   COMPRESSION_ADOBE_DEFLATE , TIFFInitZIP },
99     { "PixarLog",	COMPRESSION_PIXARLOG,	TIFFInitPixarLog },
100     { "SGILog",		COMPRESSION_SGILOG,	TIFFInitSGILog },
101     { "SGILog24",	COMPRESSION_SGILOG24,	TIFFInitSGILog },
102     { "LZMA",		COMPRESSION_LZMA,	TIFFInitLZMA },
103     { NULL,             0,                      NULL }
104 };
105 
106 static int
107 _notConfigured(TIFF* tif)
108 {
109 	const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression);
110         char compression_code[20];
111 
112         sprintf(compression_code, "%d",tif->tif_dir.td_compression );
113 	TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
114                      "%s compression support is not configured",
115                      c ? c->name : compression_code );
116 	return (0);
117 }
118 
119 static int
120 NotConfigured(TIFF* tif, int scheme)
121 {
122 	(void) scheme;
123 
124 	tif->tif_fixuptags = _notConfigured;
125 	tif->tif_decodestatus = FALSE;
126 	tif->tif_setupdecode = _notConfigured;
127 	tif->tif_encodestatus = FALSE;
128 	tif->tif_setupencode = _notConfigured;
129 	return (1);
130 }
131 
132 /************************************************************************/
133 /*                       TIFFIsCODECConfigured()                        */
134 /************************************************************************/
135 
136 /**
137  * Check whether we have working codec for the specific coding scheme.
138  *
139  * @return returns 1 if the codec is configured and working. Otherwise
140  * 0 will be returned.
141  */
142 
143 int
144 TIFFIsCODECConfigured(uint16 scheme)
145 {
146 	const TIFFCodec* codec = TIFFFindCODEC(scheme);
147 
148 	if(codec == NULL) {
149 		return 0;
150 	}
151 	if(codec->init == NULL) {
152 		return 0;
153 	}
154 	if(codec->init != NotConfigured){
155 		return 1;
156 	}
157 	return 0;
158 }
159 
160 /*
161  * Local Variables:
162  * mode: c
163  * c-basic-offset: 8
164  * fill-column: 78
165  * End:
166  */
167