]>
git.saurik.com Git - wxWidgets.git/blob - src/tiff/libtiff/tif_compress.c
e92fcd5d39a400536a162ab07c9bc6289ec88c84
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
, uint8
* pp
, tmsize_t cc
, uint16 s
)
54 (void) pp
; (void) cc
; (void) s
;
55 return (TIFFNoEncode(tif
, "scanline"));
59 _TIFFNoStripEncode(TIFF
* tif
, uint8
* pp
, tmsize_t cc
, uint16 s
)
61 (void) pp
; (void) cc
; (void) s
;
62 return (TIFFNoEncode(tif
, "strip"));
66 _TIFFNoTileEncode(TIFF
* tif
, uint8
* pp
, tmsize_t cc
, uint16 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 _TIFFNoFixupTags(TIFF
* tif
)
96 _TIFFNoRowDecode(TIFF
* tif
, uint8
* pp
, tmsize_t cc
, uint16 s
)
98 (void) pp
; (void) cc
; (void) s
;
99 return (TIFFNoDecode(tif
, "scanline"));
103 _TIFFNoStripDecode(TIFF
* tif
, uint8
* pp
, tmsize_t cc
, uint16 s
)
105 (void) pp
; (void) cc
; (void) s
;
106 return (TIFFNoDecode(tif
, "strip"));
110 _TIFFNoTileDecode(TIFF
* tif
, uint8
* pp
, tmsize_t cc
, uint16 s
)
112 (void) pp
; (void) cc
; (void) s
;
113 return (TIFFNoDecode(tif
, "tile"));
117 _TIFFNoSeek(TIFF
* tif
, uint32 off
)
120 TIFFErrorExt(tif
->tif_clientdata
, tif
->tif_name
,
121 "Compression algorithm does not support random access");
126 _TIFFNoPreCode(TIFF
* tif
, uint16 s
)
128 (void) tif
; (void) s
;
132 static int _TIFFtrue(TIFF
* tif
) { (void) tif
; return (1); }
133 static void _TIFFvoid(TIFF
* tif
) { (void) tif
; }
136 _TIFFSetDefaultCompressionState(TIFF
* tif
)
138 tif
->tif_fixuptags
= _TIFFNoFixupTags
;
139 tif
->tif_decodestatus
= TRUE
;
140 tif
->tif_setupdecode
= _TIFFtrue
;
141 tif
->tif_predecode
= _TIFFNoPreCode
;
142 tif
->tif_decoderow
= _TIFFNoRowDecode
;
143 tif
->tif_decodestrip
= _TIFFNoStripDecode
;
144 tif
->tif_decodetile
= _TIFFNoTileDecode
;
145 tif
->tif_encodestatus
= TRUE
;
146 tif
->tif_setupencode
= _TIFFtrue
;
147 tif
->tif_preencode
= _TIFFNoPreCode
;
148 tif
->tif_postencode
= _TIFFtrue
;
149 tif
->tif_encoderow
= _TIFFNoRowEncode
;
150 tif
->tif_encodestrip
= _TIFFNoStripEncode
;
151 tif
->tif_encodetile
= _TIFFNoTileEncode
;
152 tif
->tif_close
= _TIFFvoid
;
153 tif
->tif_seek
= _TIFFNoSeek
;
154 tif
->tif_cleanup
= _TIFFvoid
;
155 tif
->tif_defstripsize
= _TIFFDefaultStripSize
;
156 tif
->tif_deftilesize
= _TIFFDefaultTileSize
;
157 tif
->tif_flags
&= ~(TIFF_NOBITREV
|TIFF_NOREADRAW
);
161 TIFFSetCompressionScheme(TIFF
* tif
, int scheme
)
163 const TIFFCodec
*c
= TIFFFindCODEC((uint16
) scheme
);
165 _TIFFSetDefaultCompressionState(tif
);
167 * Don't treat an unknown compression scheme as an error.
168 * This permits applications to open files with data that
169 * the library does not have builtin support for, but which
170 * may still be meaningful.
172 return (c
? (*c
->init
)(tif
, scheme
) : 1);
176 * Other compression schemes may be registered. Registered
177 * schemes can also override the builtin versions provided
180 typedef struct _codec
{
184 static codec_t
* registeredCODECS
= NULL
;
187 TIFFFindCODEC(uint16 scheme
)
192 for (cd
= registeredCODECS
; cd
; cd
= cd
->next
)
193 if (cd
->info
->scheme
== scheme
)
194 return ((const TIFFCodec
*) cd
->info
);
195 for (c
= _TIFFBuiltinCODECS
; c
->name
; c
++)
196 if (c
->scheme
== scheme
)
198 return ((const TIFFCodec
*) 0);
202 TIFFRegisterCODEC(uint16 scheme
, const char* name
, TIFFInitMethod init
)
204 codec_t
* cd
= (codec_t
*)
205 _TIFFmalloc((tmsize_t
)(sizeof (codec_t
) + sizeof (TIFFCodec
) + strlen(name
)+1));
208 cd
->info
= (TIFFCodec
*) ((uint8
*) cd
+ sizeof (codec_t
));
209 cd
->info
->name
= (char*)
210 ((uint8
*) cd
->info
+ sizeof (TIFFCodec
));
211 strcpy(cd
->info
->name
, name
);
212 cd
->info
->scheme
= scheme
;
213 cd
->info
->init
= init
;
214 cd
->next
= registeredCODECS
;
215 registeredCODECS
= cd
;
217 TIFFErrorExt(0, "TIFFRegisterCODEC",
218 "No space to register compression scheme %s", name
);
225 TIFFUnRegisterCODEC(TIFFCodec
* c
)
230 for (pcd
= ®isteredCODECS
; (cd
= *pcd
); pcd
= &cd
->next
)
236 TIFFErrorExt(0, "TIFFUnRegisterCODEC",
237 "Cannot remove compression scheme %s; not registered", c
->name
);
240 /************************************************************************/
241 /* TIFFGetConfisuredCODECs() */
242 /************************************************************************/
245 * Get list of configured codecs, both built-in and registered by user.
246 * Caller is responsible to free this structure.
248 * @return returns array of TIFFCodec records (the last record should be NULL)
249 * or NULL if function failed.
253 TIFFGetConfiguredCODECs()
258 TIFFCodec
* codecs
= NULL
;
259 TIFFCodec
* new_codecs
;
261 for (cd
= registeredCODECS
; cd
; cd
= cd
->next
) {
262 new_codecs
= (TIFFCodec
*)
263 _TIFFrealloc(codecs
, i
* sizeof(TIFFCodec
));
269 _TIFFmemcpy(codecs
+ i
- 1, cd
, sizeof(TIFFCodec
));
272 for (c
= _TIFFBuiltinCODECS
; c
->name
; c
++) {
273 if (TIFFIsCODECConfigured(c
->scheme
)) {
274 new_codecs
= (TIFFCodec
*)
275 _TIFFrealloc(codecs
, i
* sizeof(TIFFCodec
));
281 _TIFFmemcpy(codecs
+ i
- 1, (const void*)c
, sizeof(TIFFCodec
));
286 new_codecs
= (TIFFCodec
*) _TIFFrealloc(codecs
, i
* sizeof(TIFFCodec
));
292 _TIFFmemset(codecs
+ i
- 1, 0, sizeof(TIFFCodec
));
297 /* vim: set ts=8 sts=8 sw=8 noet: */