]>
git.saurik.com Git - wxWidgets.git/blob - src/tiff/libtiff/tif_compress.c
3 * Copyright (c) 1988-1997 Sam Leffler
4 * Copyright (c) 1991-1997 Silicon Graphics, Inc.
6 * Permission to use, copy, modify, distribute, and sell this software and
7 * its documentation for any purpose is hereby granted without fee, provided
8 * that (i) the above copyright notices and this permission notice appear in
9 * all copies of the software and related documentation, and (ii) the names of
10 * Sam Leffler and Silicon Graphics may not be used in any advertising or
11 * publicity relating to the software without the specific, prior written
12 * permission of Sam Leffler and Silicon Graphics.
14 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
16 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
18 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
19 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
20 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
21 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
22 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
29 * Compression Scheme Configuration Support.
34 TIFFNoEncode(TIFF
* tif
, const char* method
)
36 const TIFFCodec
* c
= TIFFFindCODEC(tif
->tif_dir
.td_compression
);
39 TIFFErrorExt(tif
->tif_clientdata
, tif
->tif_name
,
40 "%s %s encoding is not implemented",
43 TIFFErrorExt(tif
->tif_clientdata
, tif
->tif_name
,
44 "Compression scheme %u %s encoding is not implemented",
45 tif
->tif_dir
.td_compression
, method
);
51 _TIFFNoRowEncode(TIFF
* tif
, uint8
* pp
, tmsize_t cc
, uint16 s
)
53 (void) pp
; (void) cc
; (void) s
;
54 return (TIFFNoEncode(tif
, "scanline"));
58 _TIFFNoStripEncode(TIFF
* tif
, uint8
* pp
, tmsize_t cc
, uint16 s
)
60 (void) pp
; (void) cc
; (void) s
;
61 return (TIFFNoEncode(tif
, "strip"));
65 _TIFFNoTileEncode(TIFF
* tif
, uint8
* pp
, tmsize_t cc
, uint16 s
)
67 (void) pp
; (void) cc
; (void) s
;
68 return (TIFFNoEncode(tif
, "tile"));
72 TIFFNoDecode(TIFF
* tif
, const char* method
)
74 const TIFFCodec
* c
= TIFFFindCODEC(tif
->tif_dir
.td_compression
);
77 TIFFErrorExt(tif
->tif_clientdata
, tif
->tif_name
,
78 "%s %s decoding is not implemented",
81 TIFFErrorExt(tif
->tif_clientdata
, tif
->tif_name
,
82 "Compression scheme %u %s decoding is not implemented",
83 tif
->tif_dir
.td_compression
, method
);
88 _TIFFNoFixupTags(TIFF
* tif
)
95 _TIFFNoRowDecode(TIFF
* tif
, uint8
* pp
, tmsize_t cc
, uint16 s
)
97 (void) pp
; (void) cc
; (void) s
;
98 return (TIFFNoDecode(tif
, "scanline"));
102 _TIFFNoStripDecode(TIFF
* tif
, uint8
* pp
, tmsize_t cc
, uint16 s
)
104 (void) pp
; (void) cc
; (void) s
;
105 return (TIFFNoDecode(tif
, "strip"));
109 _TIFFNoTileDecode(TIFF
* tif
, uint8
* pp
, tmsize_t cc
, uint16 s
)
111 (void) pp
; (void) cc
; (void) s
;
112 return (TIFFNoDecode(tif
, "tile"));
116 _TIFFNoSeek(TIFF
* tif
, uint32 off
)
119 TIFFErrorExt(tif
->tif_clientdata
, tif
->tif_name
,
120 "Compression algorithm does not support random access");
125 _TIFFNoPreCode(TIFF
* tif
, uint16 s
)
127 (void) tif
; (void) s
;
131 static int _TIFFtrue(TIFF
* tif
) { (void) tif
; return (1); }
132 static void _TIFFvoid(TIFF
* tif
) { (void) tif
; }
135 _TIFFSetDefaultCompressionState(TIFF
* tif
)
137 tif
->tif_fixuptags
= _TIFFNoFixupTags
;
138 tif
->tif_decodestatus
= TRUE
;
139 tif
->tif_setupdecode
= _TIFFtrue
;
140 tif
->tif_predecode
= _TIFFNoPreCode
;
141 tif
->tif_decoderow
= _TIFFNoRowDecode
;
142 tif
->tif_decodestrip
= _TIFFNoStripDecode
;
143 tif
->tif_decodetile
= _TIFFNoTileDecode
;
144 tif
->tif_encodestatus
= TRUE
;
145 tif
->tif_setupencode
= _TIFFtrue
;
146 tif
->tif_preencode
= _TIFFNoPreCode
;
147 tif
->tif_postencode
= _TIFFtrue
;
148 tif
->tif_encoderow
= _TIFFNoRowEncode
;
149 tif
->tif_encodestrip
= _TIFFNoStripEncode
;
150 tif
->tif_encodetile
= _TIFFNoTileEncode
;
151 tif
->tif_close
= _TIFFvoid
;
152 tif
->tif_seek
= _TIFFNoSeek
;
153 tif
->tif_cleanup
= _TIFFvoid
;
154 tif
->tif_defstripsize
= _TIFFDefaultStripSize
;
155 tif
->tif_deftilesize
= _TIFFDefaultTileSize
;
156 tif
->tif_flags
&= ~(TIFF_NOBITREV
|TIFF_NOREADRAW
);
160 TIFFSetCompressionScheme(TIFF
* tif
, int scheme
)
162 const TIFFCodec
*c
= TIFFFindCODEC((uint16
) scheme
);
164 _TIFFSetDefaultCompressionState(tif
);
166 * Don't treat an unknown compression scheme as an error.
167 * This permits applications to open files with data that
168 * the library does not have builtin support for, but which
169 * may still be meaningful.
171 return (c
? (*c
->init
)(tif
, scheme
) : 1);
175 * Other compression schemes may be registered. Registered
176 * schemes can also override the builtin versions provided
179 typedef struct _codec
{
183 static codec_t
* registeredCODECS
= NULL
;
186 TIFFFindCODEC(uint16 scheme
)
191 for (cd
= registeredCODECS
; cd
; cd
= cd
->next
)
192 if (cd
->info
->scheme
== scheme
)
193 return ((const TIFFCodec
*) cd
->info
);
194 for (c
= _TIFFBuiltinCODECS
; c
->name
; c
++)
195 if (c
->scheme
== scheme
)
197 return ((const TIFFCodec
*) 0);
201 TIFFRegisterCODEC(uint16 scheme
, const char* name
, TIFFInitMethod init
)
203 codec_t
* cd
= (codec_t
*)
204 _TIFFmalloc((tmsize_t
)(sizeof (codec_t
) + sizeof (TIFFCodec
) + strlen(name
)+1));
207 cd
->info
= (TIFFCodec
*) ((uint8
*) cd
+ sizeof (codec_t
));
208 cd
->info
->name
= (char*)
209 ((uint8
*) cd
->info
+ sizeof (TIFFCodec
));
210 strcpy(cd
->info
->name
, name
);
211 cd
->info
->scheme
= scheme
;
212 cd
->info
->init
= init
;
213 cd
->next
= registeredCODECS
;
214 registeredCODECS
= cd
;
216 TIFFErrorExt(0, "TIFFRegisterCODEC",
217 "No space to register compression scheme %s", name
);
224 TIFFUnRegisterCODEC(TIFFCodec
* c
)
229 for (pcd
= ®isteredCODECS
; (cd
= *pcd
); pcd
= &cd
->next
)
235 TIFFErrorExt(0, "TIFFUnRegisterCODEC",
236 "Cannot remove compression scheme %s; not registered", c
->name
);
239 /************************************************************************/
240 /* TIFFGetConfisuredCODECs() */
241 /************************************************************************/
244 * Get list of configured codecs, both built-in and registered by user.
245 * Caller is responsible to free this structure.
247 * @return returns array of TIFFCodec records (the last record should be NULL)
248 * or NULL if function failed.
252 TIFFGetConfiguredCODECs()
257 TIFFCodec
* codecs
= NULL
;
258 TIFFCodec
* new_codecs
;
260 for (cd
= registeredCODECS
; cd
; cd
= cd
->next
) {
261 new_codecs
= (TIFFCodec
*)
262 _TIFFrealloc(codecs
, i
* sizeof(TIFFCodec
));
268 _TIFFmemcpy(codecs
+ i
- 1, cd
, sizeof(TIFFCodec
));
271 for (c
= _TIFFBuiltinCODECS
; c
->name
; c
++) {
272 if (TIFFIsCODECConfigured(c
->scheme
)) {
273 new_codecs
= (TIFFCodec
*)
274 _TIFFrealloc(codecs
, i
* sizeof(TIFFCodec
));
280 _TIFFmemcpy(codecs
+ i
- 1, (const void*)c
, sizeof(TIFFCodec
));
285 new_codecs
= (TIFFCodec
*) _TIFFrealloc(codecs
, i
* sizeof(TIFFCodec
));
291 _TIFFmemset(codecs
+ i
- 1, 0, sizeof(TIFFCodec
));
296 /* vim: set ts=8 sts=8 sw=8 noet: */