Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/tiff/libtiff/tif_codec.c
4391 views
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 LERC_SUPPORT
71
#define TIFFInitLERC NotConfigured
72
#endif
73
#ifndef LZMA_SUPPORT
74
#define TIFFInitLZMA NotConfigured
75
#endif
76
#ifndef ZSTD_SUPPORT
77
#define TIFFInitZSTD NotConfigured
78
#endif
79
#ifndef WEBP_SUPPORT
80
#define TIFFInitWebP NotConfigured
81
#endif
82
83
/*
84
* Compression schemes statically built into the library.
85
*/
86
const TIFFCodec _TIFFBuiltinCODECS[] = {
87
{"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}};
109
110
static int _notConfigured(TIFF *tif)
111
{
112
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);
121
}
122
123
static int NotConfigured(TIFF *tif, int scheme)
124
{
125
(void)scheme;
126
127
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);
133
}
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
146
int TIFFIsCODECConfigured(uint16_t scheme)
147
{
148
const TIFFCodec *codec = TIFFFindCODEC(scheme);
149
150
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;
163
}
164
165