1
/* $Id: tif_compress.c,v 1.20 2007/11/10 18:40:51 drolon 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, const char* method)
37
const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression);
40
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
41
"%s %s encoding is not implemented",
44
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
45
"Compression scheme %u %s encoding is not implemented",
46
tif->tif_dir.td_compression, method);
52
_TIFFNoRowEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
54
(void) pp; (void) cc; (void) s;
55
return (TIFFNoEncode(tif, "scanline"));
59
_TIFFNoStripEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
61
(void) pp; (void) cc; (void) s;
62
return (TIFFNoEncode(tif, "strip"));
66
_TIFFNoTileEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
68
(void) pp; (void) cc; (void) s;
69
return (TIFFNoEncode(tif, "tile"));
73
TIFFNoDecode(TIFF* tif, const char* method)
75
const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression);
78
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
79
"%s %s decoding is not implemented",
82
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
83
"Compression scheme %u %s decoding is not implemented",
84
tif->tif_dir.td_compression, method);
89
_TIFFNoRowDecode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
91
(void) pp; (void) cc; (void) s;
92
return (TIFFNoDecode(tif, "scanline"));
96
_TIFFNoStripDecode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
98
(void) pp; (void) cc; (void) s;
99
return (TIFFNoDecode(tif, "strip"));
103
_TIFFNoTileDecode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
105
(void) pp; (void) cc; (void) s;
106
return (TIFFNoDecode(tif, "tile"));
110
_TIFFNoSeek(TIFF* tif, uint32 off)
113
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
114
"Compression algorithm does not support random access");
119
_TIFFNoPreCode(TIFF* tif, tsample_t s)
121
(void) tif; (void) s;
125
static int _TIFFtrue(TIFF* tif) { (void) tif; return (1); }
126
static void _TIFFvoid(TIFF* tif) { (void) tif; }
129
_TIFFSetDefaultCompressionState(TIFF* tif)
131
tif->tif_decodestatus = TRUE;
132
tif->tif_setupdecode = _TIFFtrue;
133
tif->tif_predecode = _TIFFNoPreCode;
134
tif->tif_decoderow = _TIFFNoRowDecode;
135
tif->tif_decodestrip = _TIFFNoStripDecode;
136
tif->tif_decodetile = _TIFFNoTileDecode;
137
tif->tif_encodestatus = TRUE;
138
tif->tif_setupencode = _TIFFtrue;
139
tif->tif_preencode = _TIFFNoPreCode;
140
tif->tif_postencode = _TIFFtrue;
141
tif->tif_encoderow = _TIFFNoRowEncode;
142
tif->tif_encodestrip = _TIFFNoStripEncode;
143
tif->tif_encodetile = _TIFFNoTileEncode;
144
tif->tif_close = _TIFFvoid;
145
tif->tif_seek = _TIFFNoSeek;
146
tif->tif_cleanup = _TIFFvoid;
147
tif->tif_defstripsize = _TIFFDefaultStripSize;
148
tif->tif_deftilesize = _TIFFDefaultTileSize;
149
tif->tif_flags &= ~(TIFF_NOBITREV|TIFF_NOREADRAW);
153
TIFFSetCompressionScheme(TIFF* tif, int scheme)
155
const TIFFCodec *c = TIFFFindCODEC((uint16) scheme);
157
_TIFFSetDefaultCompressionState(tif);
159
* Don't treat an unknown compression scheme as an error.
160
* This permits applications to open files with data that
161
* the library does not have builtin support for, but which
162
* may still be meaningful.
164
return (c ? (*c->init)(tif, scheme) : 1);
168
* Other compression schemes may be registered. Registered
169
* schemes can also override the builtin versions provided
172
typedef struct _codec {
176
static codec_t* registeredCODECS = NULL;
179
TIFFFindCODEC(uint16 scheme)
184
for (cd = registeredCODECS; cd; cd = cd->next)
185
if (cd->info->scheme == scheme)
186
return ((const TIFFCodec*) cd->info);
187
for (c = _TIFFBuiltinCODECS; c->name; c++)
188
if (c->scheme == scheme)
190
return ((const TIFFCodec*) 0);
194
TIFFRegisterCODEC(uint16 scheme, const char* name, TIFFInitMethod init)
196
codec_t* cd = (codec_t*)
197
_TIFFmalloc(sizeof (codec_t) + sizeof (TIFFCodec) + strlen(name)+1);
200
cd->info = (TIFFCodec*) ((tidata_t) cd + sizeof (codec_t));
201
cd->info->name = (char*)
202
((tidata_t) cd->info + sizeof (TIFFCodec));
203
strcpy(cd->info->name, name);
204
cd->info->scheme = scheme;
205
cd->info->init = init;
206
cd->next = registeredCODECS;
207
registeredCODECS = cd;
209
TIFFErrorExt(0, "TIFFRegisterCODEC",
210
"No space to register compression scheme %s", name);
217
TIFFUnRegisterCODEC(TIFFCodec* c)
222
for (pcd = ®isteredCODECS; (cd = *pcd); pcd = &cd->next)
228
TIFFErrorExt(0, "TIFFUnRegisterCODEC",
229
"Cannot remove compression scheme %s; not registered", c->name);
232
/************************************************************************/
233
/* TIFFGetConfisuredCODECs() */
234
/************************************************************************/
237
* Get list of configured codecs, both built-in and registered by user.
238
* Caller is responsible to free this structure.
240
* @return returns array of TIFFCodec records (the last record should be NULL)
241
* or NULL if function failed.
245
TIFFGetConfiguredCODECs()
250
TIFFCodec *codecs = NULL, *new_codecs;
252
for (cd = registeredCODECS; cd; cd = cd->next) {
253
new_codecs = (TIFFCodec *)
254
_TIFFrealloc(codecs, i * sizeof(TIFFCodec));
260
_TIFFmemcpy(codecs + i - 1, cd, sizeof(TIFFCodec));
263
for (c = _TIFFBuiltinCODECS; c->name; c++) {
264
if (TIFFIsCODECConfigured(c->scheme)) {
265
new_codecs = (TIFFCodec *)
266
_TIFFrealloc(codecs, i * sizeof(TIFFCodec));
272
_TIFFmemcpy(codecs + i - 1, (const tdata_t)c, sizeof(TIFFCodec));
277
new_codecs = (TIFFCodec *) _TIFFrealloc(codecs, i * sizeof(TIFFCodec));
283
_TIFFmemset(codecs + i - 1, 0, sizeof(TIFFCodec));
288
/* vim: set ts=8 sts=8 sw=8 noet: */
1
/* $Id: tif_compress.c,v 1.13.2.1 2010-06-08 18:50:41 bfriesen 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, const char* method)
37
const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression);
40
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
41
"%s %s encoding is not implemented",
44
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
45
"Compression scheme %u %s encoding is not implemented",
46
tif->tif_dir.td_compression, method);
52
_TIFFNoRowEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
54
(void) pp; (void) cc; (void) s;
55
return (TIFFNoEncode(tif, "scanline"));
59
_TIFFNoStripEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
61
(void) pp; (void) cc; (void) s;
62
return (TIFFNoEncode(tif, "strip"));
66
_TIFFNoTileEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
68
(void) pp; (void) cc; (void) s;
69
return (TIFFNoEncode(tif, "tile"));
73
TIFFNoDecode(TIFF* tif, const char* method)
75
const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression);
78
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
79
"%s %s decoding is not implemented",
82
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
83
"Compression scheme %u %s decoding is not implemented",
84
tif->tif_dir.td_compression, method);
89
_TIFFNoRowDecode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
91
(void) pp; (void) cc; (void) s;
92
return (TIFFNoDecode(tif, "scanline"));
96
_TIFFNoStripDecode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
98
(void) pp; (void) cc; (void) s;
99
return (TIFFNoDecode(tif, "strip"));
103
_TIFFNoTileDecode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
105
(void) pp; (void) cc; (void) s;
106
return (TIFFNoDecode(tif, "tile"));
110
_TIFFNoSeek(TIFF* tif, uint32 off)
113
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
114
"Compression algorithm does not support random access");
119
_TIFFNoPreCode(TIFF* tif, tsample_t s)
121
(void) tif; (void) s;
125
static int _TIFFtrue(TIFF* tif) { (void) tif; return (1); }
126
static void _TIFFvoid(TIFF* tif) { (void) tif; }
129
_TIFFSetDefaultCompressionState(TIFF* tif)
131
tif->tif_decodestatus = TRUE;
132
tif->tif_setupdecode = _TIFFtrue;
133
tif->tif_predecode = _TIFFNoPreCode;
134
tif->tif_decoderow = _TIFFNoRowDecode;
135
tif->tif_decodestrip = _TIFFNoStripDecode;
136
tif->tif_decodetile = _TIFFNoTileDecode;
137
tif->tif_encodestatus = TRUE;
138
tif->tif_setupencode = _TIFFtrue;
139
tif->tif_preencode = _TIFFNoPreCode;
140
tif->tif_postencode = _TIFFtrue;
141
tif->tif_encoderow = _TIFFNoRowEncode;
142
tif->tif_encodestrip = _TIFFNoStripEncode;
143
tif->tif_encodetile = _TIFFNoTileEncode;
144
tif->tif_close = _TIFFvoid;
145
tif->tif_seek = _TIFFNoSeek;
146
tif->tif_cleanup = _TIFFvoid;
147
tif->tif_defstripsize = _TIFFDefaultStripSize;
148
tif->tif_deftilesize = _TIFFDefaultTileSize;
149
tif->tif_flags &= ~(TIFF_NOBITREV|TIFF_NOREADRAW);
153
TIFFSetCompressionScheme(TIFF* tif, int scheme)
155
const TIFFCodec *c = TIFFFindCODEC((uint16) scheme);
157
_TIFFSetDefaultCompressionState(tif);
159
* Don't treat an unknown compression scheme as an error.
160
* This permits applications to open files with data that
161
* the library does not have builtin support for, but which
162
* may still be meaningful.
164
return (c ? (*c->init)(tif, scheme) : 1);
168
* Other compression schemes may be registered. Registered
169
* schemes can also override the builtin versions provided
172
typedef struct _codec {
176
static codec_t* registeredCODECS = NULL;
179
TIFFFindCODEC(uint16 scheme)
184
for (cd = registeredCODECS; cd; cd = cd->next)
185
if (cd->info->scheme == scheme)
186
return ((const TIFFCodec*) cd->info);
187
for (c = _TIFFBuiltinCODECS; c->name; c++)
188
if (c->scheme == scheme)
190
return ((const TIFFCodec*) 0);
194
TIFFRegisterCODEC(uint16 scheme, const char* name, TIFFInitMethod init)
196
codec_t* cd = (codec_t*)
197
_TIFFmalloc(sizeof (codec_t) + sizeof (TIFFCodec) + strlen(name)+1);
200
cd->info = (TIFFCodec*) ((tidata_t) cd + sizeof (codec_t));
201
cd->info->name = (char*)
202
((tidata_t) cd->info + sizeof (TIFFCodec));
203
strcpy(cd->info->name, name);
204
cd->info->scheme = scheme;
205
cd->info->init = init;
206
cd->next = registeredCODECS;
207
registeredCODECS = cd;
209
TIFFErrorExt(0, "TIFFRegisterCODEC",
210
"No space to register compression scheme %s", name);
217
TIFFUnRegisterCODEC(TIFFCodec* c)
222
for (pcd = ®isteredCODECS; (cd = *pcd); pcd = &cd->next)
228
TIFFErrorExt(0, "TIFFUnRegisterCODEC",
229
"Cannot remove compression scheme %s; not registered", c->name);
232
/************************************************************************/
233
/* TIFFGetConfisuredCODECs() */
234
/************************************************************************/
237
* Get list of configured codecs, both built-in and registered by user.
238
* Caller is responsible to free this structure.
240
* @return returns array of TIFFCodec records (the last record should be NULL)
241
* or NULL if function failed.
245
TIFFGetConfiguredCODECs()
250
TIFFCodec *codecs = NULL, *new_codecs;
252
for (cd = registeredCODECS; cd; cd = cd->next) {
253
new_codecs = (TIFFCodec *)
254
_TIFFrealloc(codecs, i * sizeof(TIFFCodec));
260
_TIFFmemcpy(codecs + i - 1, cd, sizeof(TIFFCodec));
263
for (c = _TIFFBuiltinCODECS; c->name; c++) {
264
if (TIFFIsCODECConfigured(c->scheme)) {
265
new_codecs = (TIFFCodec *)
266
_TIFFrealloc(codecs, i * sizeof(TIFFCodec));
272
_TIFFmemcpy(codecs + i - 1, (const tdata_t)c, sizeof(TIFFCodec));
277
new_codecs = (TIFFCodec *) _TIFFrealloc(codecs, i * sizeof(TIFFCodec));
283
_TIFFmemset(codecs + i - 1, 0, sizeof(TIFFCodec));
288
/* vim: set ts=8 sts=8 sw=8 noet: */