]>
git.saurik.com Git - wxWidgets.git/blob - src/tiff/tif_compress.c
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 if (! strncmp(c
->name
, "LZW", 3) ){
41 TIFFError(tif
->tif_name
,
42 "%s %s encoding is no longer implemented due to Unisys patent enforcement",
45 TIFFError(tif
->tif_name
, "%s %s encoding is not implemented",
50 TIFFError(tif
->tif_name
,
51 "Compression scheme %u %s encoding is not implemented",
52 tif
->tif_dir
.td_compression
, method
);
58 _TIFFNoRowEncode(TIFF
* tif
, tidata_t pp
, tsize_t cc
, tsample_t s
)
60 (void) pp
; (void) cc
; (void) s
;
61 return (TIFFNoEncode(tif
, "scanline"));
65 _TIFFNoStripEncode(TIFF
* tif
, tidata_t pp
, tsize_t cc
, tsample_t s
)
67 (void) pp
; (void) cc
; (void) s
;
68 return (TIFFNoEncode(tif
, "strip"));
72 _TIFFNoTileEncode(TIFF
* tif
, tidata_t pp
, tsize_t cc
, tsample_t s
)
74 (void) pp
; (void) cc
; (void) s
;
75 return (TIFFNoEncode(tif
, "tile"));
79 TIFFNoDecode(TIFF
* tif
, char* method
)
81 const TIFFCodec
* c
= TIFFFindCODEC(tif
->tif_dir
.td_compression
);
84 TIFFError(tif
->tif_name
, "%s %s decoding is not implemented",
87 TIFFError(tif
->tif_name
,
88 "Compression scheme %u %s decoding is not implemented",
89 tif
->tif_dir
.td_compression
, method
);
94 _TIFFNoRowDecode(TIFF
* tif
, tidata_t pp
, tsize_t cc
, tsample_t s
)
96 (void) pp
; (void) cc
; (void) s
;
97 return (TIFFNoDecode(tif
, "scanline"));
101 _TIFFNoStripDecode(TIFF
* tif
, tidata_t pp
, tsize_t cc
, tsample_t s
)
103 (void) pp
; (void) cc
; (void) s
;
104 return (TIFFNoDecode(tif
, "strip"));
108 _TIFFNoTileDecode(TIFF
* tif
, tidata_t pp
, tsize_t cc
, tsample_t s
)
110 (void) pp
; (void) cc
; (void) s
;
111 return (TIFFNoDecode(tif
, "tile"));
115 _TIFFNoSeek(TIFF
* tif
, uint32 off
)
118 TIFFError(tif
->tif_name
,
119 "Compression algorithm does not support random access");
124 _TIFFNoPreCode(TIFF
* tif
, tsample_t s
)
126 (void) tif
; (void) s
;
130 static int _TIFFtrue(TIFF
* tif
) { (void) tif
; return (1); }
131 static void _TIFFvoid(TIFF
* tif
) { (void) tif
; }
134 _TIFFSetDefaultCompressionState(TIFF
* tif
)
136 tif
->tif_decodestatus
= TRUE
;
137 tif
->tif_setupdecode
= _TIFFtrue
;
138 tif
->tif_predecode
= _TIFFNoPreCode
;
139 tif
->tif_decoderow
= _TIFFNoRowDecode
;
140 tif
->tif_decodestrip
= _TIFFNoStripDecode
;
141 tif
->tif_decodetile
= _TIFFNoTileDecode
;
142 tif
->tif_encodestatus
= TRUE
;
143 tif
->tif_setupencode
= _TIFFtrue
;
144 tif
->tif_preencode
= _TIFFNoPreCode
;
145 tif
->tif_postencode
= _TIFFtrue
;
146 tif
->tif_encoderow
= _TIFFNoRowEncode
;
147 tif
->tif_encodestrip
= _TIFFNoStripEncode
;
148 tif
->tif_encodetile
= _TIFFNoTileEncode
;
149 tif
->tif_close
= _TIFFvoid
;
150 tif
->tif_seek
= _TIFFNoSeek
;
151 tif
->tif_cleanup
= _TIFFvoid
;
152 tif
->tif_defstripsize
= _TIFFDefaultStripSize
;
153 tif
->tif_deftilesize
= _TIFFDefaultTileSize
;
154 tif
->tif_flags
&= ~TIFF_NOBITREV
;
158 TIFFSetCompressionScheme(TIFF
* tif
, int scheme
)
160 const TIFFCodec
*c
= TIFFFindCODEC((uint16
) scheme
);
162 _TIFFSetDefaultCompressionState(tif
);
164 * Don't treat an unknown compression scheme as an error.
165 * This permits applications to open files with data that
166 * the library does not have builtin support for, but which
167 * may still be meaningful.
169 return (c
? (*c
->init
)(tif
, scheme
) : 1);
173 * Other compression schemes may be registered. Registered
174 * schemes can also override the builtin versions provided
177 typedef struct _codec
{
181 static codec_t
* registeredCODECS
= NULL
;
184 TIFFFindCODEC(uint16 scheme
)
189 for (cd
= registeredCODECS
; cd
; cd
= cd
->next
)
190 if (cd
->info
->scheme
== scheme
)
191 return ((const TIFFCodec
*) cd
->info
);
192 for (c
= _TIFFBuiltinCODECS
; c
->name
; c
++)
193 if (c
->scheme
== scheme
)
195 return ((const TIFFCodec
*) 0);
199 TIFFRegisterCODEC(uint16 scheme
, const char* name
, TIFFInitMethod init
)
201 codec_t
* cd
= (codec_t
*)
202 _TIFFmalloc(sizeof (codec_t
) + sizeof (TIFFCodec
) + strlen(name
)+1);
205 cd
->info
= (TIFFCodec
*) ((tidata_t
) cd
+ sizeof (codec_t
));
206 cd
->info
->name
= (char*)
207 ((tidata_t
) cd
->info
+ sizeof (TIFFCodec
));
208 strcpy(cd
->info
->name
, name
);
209 cd
->info
->scheme
= scheme
;
210 cd
->info
->init
= init
;
211 cd
->next
= registeredCODECS
;
212 registeredCODECS
= cd
;
214 TIFFError("TIFFRegisterCODEC",
215 "No space to register compression scheme %s", name
);
222 TIFFUnRegisterCODEC(TIFFCodec
* c
)
227 for (pcd
= ®isteredCODECS
; (cd
= *pcd
); pcd
= &cd
->next
)
233 TIFFError("TIFFUnRegisterCODEC",
234 "Cannot remove compression scheme %s; not registered", c
->name
);