ReactOS 0.4.15-dev-8096-ga0eec98
tif_compress.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 1988-1997 Sam Leffler
3 * Copyright (c) 1991-1997 Silicon Graphics, Inc.
4 *
5 * Permission to use, copy, modify, distribute, and sell this software and
6 * its documentation for any purpose is hereby granted without fee, provided
7 * that (i) the above copyright notices and this permission notice appear in
8 * all copies of the software and related documentation, and (ii) the names of
9 * Sam Leffler and Silicon Graphics may not be used in any advertising or
10 * publicity relating to the software without the specific, prior written
11 * permission of Sam Leffler and Silicon Graphics.
12 *
13 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
14 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
16 *
17 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
18 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22 * OF THIS SOFTWARE.
23 */
24
25/*
26 * TIFF Library
27 *
28 * Compression Scheme Configuration Support.
29 */
30
31#include <precomp.h>
32
33static int
34TIFFNoEncode(TIFF* tif, const char* method)
35{
37
38 if (c) {
40 "%s %s encoding is not implemented",
41 c->name, method);
42 } else {
44 "Compression scheme %u %s encoding is not implemented",
46 }
47 return (-1);
48}
49
50int
52{
53 (void) pp; (void) cc; (void) s;
54 return (TIFFNoEncode(tif, "scanline"));
55}
56
57int
59{
60 (void) pp; (void) cc; (void) s;
61 return (TIFFNoEncode(tif, "strip"));
62}
63
64int
66{
67 (void) pp; (void) cc; (void) s;
68 return (TIFFNoEncode(tif, "tile"));
69}
70
71static int
72TIFFNoDecode(TIFF* tif, const char* method)
73{
75
76 if (c)
78 "%s %s decoding is not implemented",
79 c->name, method);
80 else
82 "Compression scheme %u %s decoding is not implemented",
84 return (0);
85}
86
87static int
89{
90 (void) tif;
91 return (1);
92}
93
94int
96{
97 (void) pp; (void) cc; (void) s;
98 return (TIFFNoDecode(tif, "scanline"));
99}
100
101int
103{
104 (void) pp; (void) cc; (void) s;
105 return (TIFFNoDecode(tif, "strip"));
106}
107
108int
110{
111 (void) pp; (void) cc; (void) s;
112 return (TIFFNoDecode(tif, "tile"));
113}
114
115int
117{
118 (void) off;
120 "Compression algorithm does not support random access");
121 return (0);
122}
123
124int
126{
127 (void) tif; (void) s;
128 return (1);
129}
130
131static int _TIFFtrue(TIFF* tif) { (void) tif; return (1); }
132static void _TIFFvoid(TIFF* tif) { (void) tif; }
133
134void
136{
138 tif->tif_decodestatus = TRUE;
144 tif->tif_encodestatus = TRUE;
151 tif->tif_close = _TIFFvoid;
152 tif->tif_seek = _TIFFNoSeek;
153 tif->tif_cleanup = _TIFFvoid;
157}
158
159int
161{
163
165 /*
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.
170 */
171 return (c ? (*c->init)(tif, scheme) : 1);
172}
173
174/*
175 * Other compression schemes may be registered. Registered
176 * schemes can also override the builtin versions provided
177 * by this library.
178 */
179typedef struct _codec {
180 struct _codec* next;
184
185const TIFFCodec*
187{
188 const TIFFCodec* c;
189 codec_t* cd;
190
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)
196 return (c);
197 return ((const TIFFCodec*) 0);
198}
199
202{
203 codec_t* cd = (codec_t*)
204 _TIFFmalloc((tmsize_t)(sizeof (codec_t) + sizeof (TIFFCodec) + strlen(name)+1));
205
206 if (cd != NULL) {
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;
215 } else {
216 TIFFErrorExt(0, "TIFFRegisterCODEC",
217 "No space to register compression scheme %s", name);
218 return NULL;
219 }
220 return (cd->info);
221}
222
223void
225{
226 codec_t* cd;
227 codec_t** pcd;
228
229 for (pcd = &registeredCODECS; (cd = *pcd) != NULL; pcd = &cd->next)
230 if (cd->info == c) {
231 *pcd = cd->next;
232 _TIFFfree(cd);
233 return;
234 }
235 TIFFErrorExt(0, "TIFFUnRegisterCODEC",
236 "Cannot remove compression scheme %s; not registered", c->name);
237}
238
239/************************************************************************/
240/* TIFFGetConfisuredCODECs() */
241/************************************************************************/
242
253{
254 int i = 1;
255 codec_t *cd;
256 const TIFFCodec* c;
258 TIFFCodec* new_codecs;
259
260 for (cd = registeredCODECS; cd; cd = cd->next) {
261 new_codecs = (TIFFCodec *)
262 _TIFFrealloc(codecs, i * sizeof(TIFFCodec));
263 if (!new_codecs) {
265 return NULL;
266 }
267 codecs = new_codecs;
268 _TIFFmemcpy(codecs + i - 1, cd, sizeof(TIFFCodec));
269 i++;
270 }
271 for (c = _TIFFBuiltinCODECS; c->name; c++) {
272 if (TIFFIsCODECConfigured(c->scheme)) {
273 new_codecs = (TIFFCodec *)
274 _TIFFrealloc(codecs, i * sizeof(TIFFCodec));
275 if (!new_codecs) {
277 return NULL;
278 }
279 codecs = new_codecs;
280 _TIFFmemcpy(codecs + i - 1, (const void*)c, sizeof(TIFFCodec));
281 i++;
282 }
283 }
284
285 new_codecs = (TIFFCodec *) _TIFFrealloc(codecs, i * sizeof(TIFFCodec));
286 if (!new_codecs) {
288 return NULL;
289 }
290 codecs = new_codecs;
291 _TIFFmemset(codecs + i - 1, 0, sizeof(TIFFCodec));
292
293 return codecs;
294}
295
296/* vim: set ts=8 sts=8 sw=8 noet: */
297/*
298 * Local Variables:
299 * mode: c
300 * c-basic-offset: 8
301 * fill-column: 78
302 * End:
303 */
InitDirComponents & cd
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
unsigned short uint16
Definition: types.h:30
unsigned int uint32
Definition: types.h:32
unsigned char uint8
Definition: types.h:28
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
static const struct image_codec codecs[NUM_CODECS]
Definition: image.c:4283
method
Definition: dragdrop.c:54
GLdouble s
Definition: gl.h:2039
const GLubyte * c
Definition: glext.h:8905
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
uint32_t cc
Definition: isohybrid.c:75
#define c
Definition: ke_i.h:80
DWORD scheme
char * name
Definition: tiffio.h:251
uint16 td_compression
Definition: tif_dir.h:77
TIFFCodec * info
Definition: tif_compress.c:181
struct _codec * next
Definition: tif_compress.c:180
Definition: name.c:39
Definition: tiffiop.h:115
TIFFTileMethod tif_deftilesize
Definition: tiffiop.h:190
TIFFCodeMethod tif_encodestrip
Definition: tiffiop.h:183
TIFFSeekMethod tif_seek
Definition: tiffiop.h:187
TIFFCodeMethod tif_encodetile
Definition: tiffiop.h:185
TIFFPreMethod tif_preencode
Definition: tiffiop.h:178
TIFFBoolMethod tif_fixuptags
Definition: tiffiop.h:173
TIFFPreMethod tif_predecode
Definition: tiffiop.h:175
TIFFCodeMethod tif_decodestrip
Definition: tiffiop.h:182
thandle_t tif_clientdata
Definition: tiffiop.h:207
TIFFStripMethod tif_defstripsize
Definition: tiffiop.h:189
char * tif_name
Definition: tiffiop.h:116
uint32 tif_flags
Definition: tiffiop.h:119
TIFFCodeMethod tif_decoderow
Definition: tiffiop.h:180
TIFFBoolMethod tif_setupencode
Definition: tiffiop.h:176
TIFFDirectory tif_dir
Definition: tiffiop.h:151
TIFFBoolMethod tif_postencode
Definition: tiffiop.h:179
TIFFCodeMethod tif_encoderow
Definition: tiffiop.h:181
TIFFVoidMethod tif_close
Definition: tiffiop.h:186
int tif_decodestatus
Definition: tiffiop.h:172
int tif_encodestatus
Definition: tiffiop.h:177
TIFFVoidMethod tif_cleanup
Definition: tiffiop.h:188
TIFFBoolMethod tif_setupdecode
Definition: tiffiop.h:174
TIFFCodeMethod tif_decodetile
Definition: tiffiop.h:184
int TIFFIsCODECConfigured(uint16 scheme)
Definition: tif_codec.c:150
TIFFCodec _TIFFBuiltinCODECS[]
Definition: tif_codec.c:87
int _TIFFNoPreCode(TIFF *tif, uint16 s)
Definition: tif_compress.c:125
int _TIFFNoSeek(TIFF *tif, uint32 off)
Definition: tif_compress.c:116
TIFFCodec * TIFFRegisterCODEC(uint16 scheme, const char *name, TIFFInitMethod init)
Definition: tif_compress.c:201
static void _TIFFvoid(TIFF *tif)
Definition: tif_compress.c:132
int _TIFFNoStripDecode(TIFF *tif, uint8 *pp, tmsize_t cc, uint16 s)
Definition: tif_compress.c:102
int TIFFSetCompressionScheme(TIFF *tif, int scheme)
Definition: tif_compress.c:160
static int TIFFNoEncode(TIFF *tif, const char *method)
Definition: tif_compress.c:34
void _TIFFSetDefaultCompressionState(TIFF *tif)
Definition: tif_compress.c:135
int _TIFFNoTileEncode(TIFF *tif, uint8 *pp, tmsize_t cc, uint16 s)
Definition: tif_compress.c:65
static int _TIFFtrue(TIFF *tif)
Definition: tif_compress.c:131
struct _codec codec_t
static codec_t * registeredCODECS
Definition: tif_compress.c:183
static int _TIFFNoFixupTags(TIFF *tif)
Definition: tif_compress.c:88
const TIFFCodec * TIFFFindCODEC(uint16 scheme)
Definition: tif_compress.c:186
int _TIFFNoRowEncode(TIFF *tif, uint8 *pp, tmsize_t cc, uint16 s)
Definition: tif_compress.c:51
static int TIFFNoDecode(TIFF *tif, const char *method)
Definition: tif_compress.c:72
int _TIFFNoStripEncode(TIFF *tif, uint8 *pp, tmsize_t cc, uint16 s)
Definition: tif_compress.c:58
int _TIFFNoTileDecode(TIFF *tif, uint8 *pp, tmsize_t cc, uint16 s)
Definition: tif_compress.c:109
int _TIFFNoRowDecode(TIFF *tif, uint8 *pp, tmsize_t cc, uint16 s)
Definition: tif_compress.c:95
TIFFCodec * TIFFGetConfiguredCODECs()
Definition: tif_compress.c:252
void TIFFUnRegisterCODEC(TIFFCodec *c)
Definition: tif_compress.c:224
void TIFFErrorExt(thandle_t fd, const char *module, const char *fmt,...)
Definition: tif_error.c:65
uint32 _TIFFDefaultStripSize(TIFF *tif, uint32 s)
Definition: tif_strip.c:223
void _TIFFDefaultTileSize(TIFF *tif, uint32 *tw, uint32 *th)
Definition: tif_tile.c:278
void _TIFFfree(void *p)
Definition: tif_unix.c:326
void _TIFFmemset(void *p, int v, tmsize_t c)
Definition: tif_unix.c:338
void * _TIFFmalloc(tmsize_t s)
Definition: tif_unix.c:309
void _TIFFmemcpy(void *d, const void *s, tmsize_t c)
Definition: tif_unix.c:344
void * _TIFFrealloc(void *p, tmsize_t s)
Definition: tif_unix.c:332
TIFF_SSIZE_T tmsize_t
Definition: tiffio.h:65
int(* TIFFInitMethod)(TIFF *, int)
Definition: tiffio.h:249
#define TIFF_NOREADRAW
Definition: tiffiop.h:136
#define TIFF_NOBITREV
Definition: tiffiop.h:127
static int init
Definition: wintirpc.c:33