1 /* $Id: tif_compress.c,v 1.1 2005/06/17 13:54:52 vp153 Exp $ */
4 * Copyright (c) 1988-1997 Sam Leffler
5 * Copyright (c) 1991-1997 Silicon Graphics, Inc.
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.
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.
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
30 * Compression Scheme Configuration Support.
35 TIFFNoEncode(TIFF* tif, char* method)
37 const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression);
40 TIFFError(tif->tif_name, "%s %s encoding is not implemented",
43 TIFFError(tif->tif_name,
44 "Compression scheme %u %s encoding is not implemented",
45 tif->tif_dir.td_compression, method);
51 _TIFFNoRowEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
53 (void) pp; (void) cc; (void) s;
54 return (TIFFNoEncode(tif, "scanline"));
58 _TIFFNoStripEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
60 (void) pp; (void) cc; (void) s;
61 return (TIFFNoEncode(tif, "strip"));
65 _TIFFNoTileEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
67 (void) pp; (void) cc; (void) s;
68 return (TIFFNoEncode(tif, "tile"));
72 TIFFNoDecode(TIFF* tif, char* method)
74 const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression);
77 TIFFError(tif->tif_name, "%s %s decoding is not implemented",
80 TIFFError(tif->tif_name,
81 "Compression scheme %u %s decoding is not implemented",
82 tif->tif_dir.td_compression, method);
87 _TIFFNoRowDecode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
89 (void) pp; (void) cc; (void) s;
90 return (TIFFNoDecode(tif, "scanline"));
94 _TIFFNoStripDecode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
96 (void) pp; (void) cc; (void) s;
97 return (TIFFNoDecode(tif, "strip"));
101 _TIFFNoTileDecode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
103 (void) pp; (void) cc; (void) s;
104 return (TIFFNoDecode(tif, "tile"));
108 _TIFFNoSeek(TIFF* tif, uint32 off)
111 TIFFError(tif->tif_name,
112 "Compression algorithm does not support random access");
117 _TIFFNoPreCode(TIFF* tif, tsample_t s)
119 (void) tif; (void) s;
123 static int _TIFFtrue(TIFF* tif) { (void) tif; return (1); }
124 static void _TIFFvoid(TIFF* tif) { (void) tif; }
127 _TIFFSetDefaultCompressionState(TIFF* tif)
129 tif->tif_decodestatus = TRUE;
130 tif->tif_setupdecode = _TIFFtrue;
131 tif->tif_predecode = _TIFFNoPreCode;
132 tif->tif_decoderow = _TIFFNoRowDecode;
133 tif->tif_decodestrip = _TIFFNoStripDecode;
134 tif->tif_decodetile = _TIFFNoTileDecode;
135 tif->tif_encodestatus = TRUE;
136 tif->tif_setupencode = _TIFFtrue;
137 tif->tif_preencode = _TIFFNoPreCode;
138 tif->tif_postencode = _TIFFtrue;
139 tif->tif_encoderow = _TIFFNoRowEncode;
140 tif->tif_encodestrip = _TIFFNoStripEncode;
141 tif->tif_encodetile = _TIFFNoTileEncode;
142 tif->tif_close = _TIFFvoid;
143 tif->tif_seek = _TIFFNoSeek;
144 tif->tif_cleanup = _TIFFvoid;
145 tif->tif_defstripsize = _TIFFDefaultStripSize;
146 tif->tif_deftilesize = _TIFFDefaultTileSize;
147 tif->tif_flags &= ~TIFF_NOBITREV;
151 TIFFSetCompressionScheme(TIFF* tif, int scheme)
153 const TIFFCodec *c = TIFFFindCODEC((uint16) scheme);
155 _TIFFSetDefaultCompressionState(tif);
157 * Don't treat an unknown compression scheme as an error.
158 * This permits applications to open files with data that
159 * the library does not have builtin support for, but which
160 * may still be meaningful.
162 return (c ? (*c->init)(tif, scheme) : 1);
166 * Other compression schemes may be registered. Registered
167 * schemes can also override the builtin versions provided
170 typedef struct _codec {
174 static codec_t* registeredCODECS = NULL;
177 TIFFFindCODEC(uint16 scheme)
182 for (cd = registeredCODECS; cd; cd = cd->next)
183 if (cd->info->scheme == scheme)
184 return ((const TIFFCodec*) cd->info);
185 for (c = _TIFFBuiltinCODECS; c->name; c++)
186 if (c->scheme == scheme)
188 return ((const TIFFCodec*) 0);
192 TIFFRegisterCODEC(uint16 scheme, const char* name, TIFFInitMethod init)
194 codec_t* cd = (codec_t*)
195 _TIFFmalloc(sizeof (codec_t) + sizeof (TIFFCodec) + strlen(name)+1);
198 cd->info = (TIFFCodec*) ((tidata_t) cd + sizeof (codec_t));
199 cd->info->name = (char*)
200 ((tidata_t) cd->info + sizeof (TIFFCodec));
201 strcpy(cd->info->name, name);
202 cd->info->scheme = scheme;
203 cd->info->init = init;
204 cd->next = registeredCODECS;
205 registeredCODECS = cd;
207 TIFFError("TIFFRegisterCODEC",
208 "No space to register compression scheme %s", name);
215 TIFFUnRegisterCODEC(TIFFCodec* c)
220 for (pcd = ®isteredCODECS; (cd = *pcd); pcd = &cd->next)
226 TIFFError("TIFFUnRegisterCODEC",
227 "Cannot remove compression scheme %s; not registered", c->name);
230 /************************************************************************/
231 /* TIFFGetConfisuredCODECs() */
232 /************************************************************************/
235 * Get list of configured codecs, both built-in and registered by user.
236 * Caller is responsible to free this structure.
238 * @return returns array of TIFFCodec records (the last record should be NULL)
239 * or NULL if function failed.
243 TIFFGetConfiguredCODECs()
248 TIFFCodec *codecs = NULL, *new_codecs;
250 for (cd = registeredCODECS; cd; cd = cd->next) {
251 new_codecs = _TIFFrealloc(codecs, i * sizeof(TIFFCodec));
257 _TIFFmemcpy(codecs + i - 1, cd, sizeof(TIFFCodec));
260 for (c = _TIFFBuiltinCODECS; c->name; c++) {
261 if (TIFFIsCODECConfigured(c->scheme)) {
262 new_codecs = _TIFFrealloc(codecs, i * sizeof(TIFFCodec));
268 _TIFFmemcpy(codecs + i - 1, (const tdata_t)c, sizeof(TIFFCodec));
273 new_codecs = _TIFFrealloc(codecs, i * sizeof(TIFFCodec));
279 _TIFFmemset(codecs + i - 1, 0, sizeof(TIFFCodec));
284 /* vim: set ts=8 sts=8 sw=8 noet: */