| Bsoft 1.9 Bernard's software package

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

tif_compress.c
Go to the documentation of this file.
1 /* $Id: tif_compress.c,v 1.13.2.1 2010-06-08 18:50:41 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 * Compression Scheme Configuration Support.
31 */
32 #include "tiffiop.h"
33
34 static int
35 TIFFNoEncode(TIFF* tif, const char* method)
36 {
37 const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression);
38
39 if (c) {
40 TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
41 "%s %s encoding is not implemented",
42 c->name, method);
43 } else {
44 TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
45 "Compression scheme %u %s encoding is not implemented",
46 tif->tif_dir.td_compression, method);
47 }
48 return (-1);
49 }
50
51 int
52 _TIFFNoRowEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
53 {
54 (void) pp; (void) cc; (void) s;
55 return (TIFFNoEncode(tif, "scanline"));
56 }
57
58 int
59 _TIFFNoStripEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
60 {
61 (void) pp; (void) cc; (void) s;
62 return (TIFFNoEncode(tif, "strip"));
63 }
64
65 int
66 _TIFFNoTileEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
67 {
68 (void) pp; (void) cc; (void) s;
69 return (TIFFNoEncode(tif, "tile"));
70 }
71
72 static int
73 TIFFNoDecode(TIFF* tif, const char* method)
74 {
75 const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression);
76
77 if (c)
78 TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
79 "%s %s decoding is not implemented",
80 c->name, method);
81 else
82 TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
83 "Compression scheme %u %s decoding is not implemented",
84 tif->tif_dir.td_compression, method);
85 return (-1);
86 }
87
88 int
89 _TIFFNoRowDecode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
90 {
91 (void) pp; (void) cc; (void) s;
92 return (TIFFNoDecode(tif, "scanline"));
93 }
94
95 int
96 _TIFFNoStripDecode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
97 {
98 (void) pp; (void) cc; (void) s;
99 return (TIFFNoDecode(tif, "strip"));
100 }
101
102 int
103 _TIFFNoTileDecode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
104 {
105 (void) pp; (void) cc; (void) s;
106 return (TIFFNoDecode(tif, "tile"));
107 }
108
109 int
110 _TIFFNoSeek(TIFF* tif, uint32 off)
111 {
112 (void) off;
113 TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
114 "Compression algorithm does not support random access");
115 return (0);
116 }
117
118 int
119 _TIFFNoPreCode(TIFF* tif, tsample_t s)
120 {
121 (void) tif; (void) s;
122 return (1);
123 }
124
125 static int _TIFFtrue(TIFF* tif) { (void) tif; return (1); }
126 static void _TIFFvoid(TIFF* tif) { (void) tif; }
127
128 void
129 _TIFFSetDefaultCompressionState(TIFF* tif)
130 {
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);
150 }
151
152 int
153 TIFFSetCompressionScheme(TIFF* tif, int scheme)
154 {
155 const TIFFCodec *c = TIFFFindCODEC((uint16) scheme);
156
157 _TIFFSetDefaultCompressionState(tif);
158 /*
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.
163 */
164 return (c ? (*c->init)(tif, scheme) : 1);
165 }
166
167 /*
168 * Other compression schemes may be registered. Registered
169 * schemes can also override the builtin versions provided
170 * by this library.
171 */
172 typedef struct _codec {
173 struct _codec* next;
174 TIFFCodec* info;
175 } codec_t;
176 static codec_t* registeredCODECS = NULL;
177
178 const TIFFCodec*
179 TIFFFindCODEC(uint16 scheme)
180 {
181 const TIFFCodec* c;
182 codec_t* cd;
183
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)
189 return (c);
190 return ((const TIFFCodec*) 0);
191 }
192
193 TIFFCodec*
194 TIFFRegisterCODEC(uint16 scheme, const char* name, TIFFInitMethod init)
195 {
196 codec_t* cd = (codec_t*)
197 _TIFFmalloc(sizeof (codec_t) + sizeof (TIFFCodec) + strlen(name)+1);
198
199 if (cd != NULL) {
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;
208 } else {
209 TIFFErrorExt(0, "TIFFRegisterCODEC",
210 "No space to register compression scheme %s", name);
211 return NULL;
212 }
213 return (cd->info);
214 }
215
216 void
217 TIFFUnRegisterCODEC(TIFFCodec* c)
218 {
219 codec_t* cd;
220 codec_t** pcd;
221
222 for (pcd = &registeredCODECS; (cd = *pcd); pcd = &cd->next)
223 if (cd->info == c) {
224 *pcd = cd->next;
225 _TIFFfree(cd);
226 return;
227 }
228 TIFFErrorExt(0, "TIFFUnRegisterCODEC",
229 "Cannot remove compression scheme %s; not registered", c->name);
230 }
231
232 /************************************************************************/
233 /* TIFFGetConfisuredCODECs() */
234 /************************************************************************/
235
244 TIFFCodec*
245 TIFFGetConfiguredCODECs()
246 {
247 int i = 1;
248 codec_t *cd;
249 const TIFFCodec *c;
250 TIFFCodec *codecs = NULL, *new_codecs;
251
252 for (cd = registeredCODECS; cd; cd = cd->next) {
253 new_codecs = (TIFFCodec *)
254 _TIFFrealloc(codecs, i * sizeof(TIFFCodec));
255 if (!new_codecs) {
256 _TIFFfree (codecs);
257 return NULL;
258 }
259 codecs = new_codecs;
260 _TIFFmemcpy(codecs + i - 1, cd, sizeof(TIFFCodec));
261 i++;
262 }
263 for (c = _TIFFBuiltinCODECS; c->name; c++) {
264 if (TIFFIsCODECConfigured(c->scheme)) {
265 new_codecs = (TIFFCodec *)
266 _TIFFrealloc(codecs, i * sizeof(TIFFCodec));
267 if (!new_codecs) {
268 _TIFFfree (codecs);
269 return NULL;
270 }
271 codecs = new_codecs;
272 _TIFFmemcpy(codecs + i - 1, (const tdata_t)c, sizeof(TIFFCodec));
273 i++;
274 }
275 }
276
277 new_codecs = (TIFFCodec *) _TIFFrealloc(codecs, i * sizeof(TIFFCodec));
278 if (!new_codecs) {
279 _TIFFfree (codecs);
280 return NULL;
281 }
282 codecs = new_codecs;
283 _TIFFmemset(codecs + i - 1, 0, sizeof(TIFFCodec));
284
285 return codecs;
286 }
287
288 /* vim: set ts=8 sts=8 sw=8 noet: */
289 /*
290 * Local Variables:
291 * mode: c
292 * c-basic-offset: 8
293 * fill-column: 78
294 * End:
295 */
TRUE
#define TRUE
Definition: twiddle.c:33
tsize_t
int32 tsize_t
Definition: tiffio.h:67
TIFFCodec::scheme
uint16 scheme
Definition: tiffio.h:242
tsample_t
uint16 tsample_t
Definition: tiffio.h:63
tiff::tif_decoderow
TIFFCodeMethod tif_decoderow
Definition: tiffiop.h:159
tdata_t
void * tdata_t
Definition: tiffio.h:68
_TIFFNoStripEncode
int _TIFFNoStripEncode(TIFF *tif, tidata_t pp, tsize_t cc, tsample_t s)
Definition: tif_compress.c:59
tiff::tif_predecode
TIFFPreMethod tif_predecode
Definition: tiffiop.h:154
TIFFCodec
Definition: tiffio.h:240
_TIFFBuiltinCODECS
TIFFCodec _TIFFBuiltinCODECS[]
Definition: tif_codec.c:79
tiff::tif_encodestrip
TIFFCodeMethod tif_encodestrip
Definition: tiffiop.h:162
TIFFCodec::init
TIFFInitMethod init
Definition: tiffio.h:243
TIFF_NOREADRAW
#define TIFF_NOREADRAW
Definition: tiffiop.h:124
tiff::tif_encoderow
TIFFCodeMethod tif_encoderow
Definition: tiffiop.h:160
tiff::tif_close
TIFFVoidMethod tif_close
Definition: tiffiop.h:165
TIFFInitMethod
int(* TIFFInitMethod)(TIFF *, int)
Definition: tiffio.h:239
_TIFFNoRowEncode
int _TIFFNoRowEncode(TIFF *tif, tidata_t pp, tsize_t cc, tsample_t s)
Definition: tif_compress.c:52
tiff::tif_clientdata
thandle_t tif_clientdata
Definition: tiffiop.h:185
_TIFFNoSeek
int _TIFFNoSeek(TIFF *tif, uint32 off)
Definition: tif_compress.c:110
tiffiop.h
_TIFFNoTileEncode
int _TIFFNoTileEncode(TIFF *tif, tidata_t pp, tsize_t cc, tsample_t s)
Definition: tif_compress.c:66
tiff::tif_name
char * tif_name
Definition: tiffiop.h:103
tiff
Definition: tiffiop.h:102
_TIFFmemcpy
void _TIFFmemcpy(tdata_t d, const tdata_t s, tsize_t c)
Definition: tif_acorn.c:485
TIFFCodec::name
char * name
Definition: tiffio.h:241
TIFFRegisterCODEC
TIFFCodec * TIFFRegisterCODEC(uint16 scheme, const char *name, TIFFInitMethod init)
Definition: tif_compress.c:194
_codec
Definition: tif_compress.c:172
_TIFFNoStripDecode
int _TIFFNoStripDecode(TIFF *tif, tidata_t pp, tsize_t cc, tsample_t s)
Definition: tif_compress.c:96
tiff::tif_flags
uint32 tif_flags
Definition: tiffiop.h:106
tiff::tif_encodestatus
int tif_encodestatus
Definition: tiffiop.h:156
tiff::tif_decodestrip
TIFFCodeMethod tif_decodestrip
Definition: tiffiop.h:161
tiff::tif_encodetile
TIFFCodeMethod tif_encodetile
Definition: tiffiop.h:164
tiff::tif_seek
TIFFSeekMethod tif_seek
Definition: tiffiop.h:166
_TIFFNoPreCode
int _TIFFNoPreCode(TIFF *tif, tsample_t s)
Definition: tif_compress.c:119
tiff::tif_deftilesize
TIFFTileMethod tif_deftilesize
Definition: tiffiop.h:169
tiff::tif_preencode
TIFFPreMethod tif_preencode
Definition: tiffiop.h:157
_TIFFDefaultStripSize
uint32 _TIFFDefaultStripSize(TIFF *tif, uint32 s)
Definition: tif_strip.c:204
uint16
unsigned short uint16
Definition: tiff.h:71
tiff::tif_postencode
TIFFBoolMethod tif_postencode
Definition: tiffiop.h:158
_TIFFNoTileDecode
int _TIFFNoTileDecode(TIFF *tif, tidata_t pp, tsize_t cc, tsample_t s)
Definition: tif_compress.c:103
_TIFFrealloc
void * _TIFFrealloc(tdata_t p, tsize_t s)
Definition: tif_acorn.c:473
_TIFFNoRowDecode
int _TIFFNoRowDecode(TIFF *tif, tidata_t pp, tsize_t cc, tsample_t s)
Definition: tif_compress.c:89
TIFFErrorExt
void TIFFErrorExt(thandle_t fd, const char *module, const char *fmt,...)
Definition: tif_error.c:63
TIFFGetConfiguredCODECs
TIFFCodec * TIFFGetConfiguredCODECs()
Definition: tif_compress.c:245
tiff::tif_decodetile
TIFFCodeMethod tif_decodetile
Definition: tiffiop.h:163
TIFFFindCODEC
const TIFFCodec * TIFFFindCODEC(uint16 scheme)
Definition: tif_compress.c:179
TIFF_NOBITREV
#define TIFF_NOBITREV
Definition: tiffiop.h:114
tiff::tif_cleanup
TIFFVoidMethod tif_cleanup
Definition: tiffiop.h:167
_TIFFmemset
void _TIFFmemset(tdata_t p, int v, tsize_t c)
Definition: tif_acorn.c:479
_TIFFSetDefaultCompressionState
void _TIFFSetDefaultCompressionState(TIFF *tif)
Definition: tif_compress.c:129
_TIFFDefaultTileSize
void _TIFFDefaultTileSize(TIFF *tif, uint32 *tw, uint32 *th)
Definition: tif_tile.c:259
tidata_t
tidataval_t * tidata_t
Definition: tiffiop.h:91
TIFFUnRegisterCODEC
void TIFFUnRegisterCODEC(TIFFCodec *c)
Definition: tif_compress.c:217
tiff::tif_decodestatus
int tif_decodestatus
Definition: tiffiop.h:152
tiff::tif_dir
TIFFDirectory tif_dir
Definition: tiffiop.h:133
TIFFSetCompressionScheme
int TIFFSetCompressionScheme(TIFF *tif, int scheme)
Definition: tif_compress.c:153
_codec::next
struct _codec * next
Definition: tif_compress.c:173
TIFFDirectory::td_compression
uint16 td_compression
Definition: tif_dir.h:46
TIFFIsCODECConfigured
int TIFFIsCODECConfigured(uint16 scheme)
Definition: tif_codec.c:138
_TIFFmalloc
void * _TIFFmalloc(tsize_t s)
Definition: tif_acorn.c:461
codec_t
struct _codec codec_t
_TIFFfree
void _TIFFfree(tdata_t p)
Definition: tif_acorn.c:467
tiff::tif_setupencode
TIFFBoolMethod tif_setupencode
Definition: tiffiop.h:155
tiff::tif_defstripsize
TIFFStripMethod tif_defstripsize
Definition: tiffiop.h:168
_codec::info
TIFFCodec * info
Definition: tif_compress.c:174
tiff::tif_setupdecode
TIFFBoolMethod tif_setupdecode
Definition: tiffiop.h:153