ReactOS  0.4.14-dev-317-g96040ec
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 
33 static int
34 TIFFNoEncode(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 
50 int
52 {
53  (void) pp; (void) cc; (void) s;
54  return (TIFFNoEncode(tif, "scanline"));
55 }
56 
57 int
59 {
60  (void) pp; (void) cc; (void) s;
61  return (TIFFNoEncode(tif, "strip"));
62 }
63 
64 int
66 {
67  (void) pp; (void) cc; (void) s;
68  return (TIFFNoEncode(tif, "tile"));
69 }
70 
71 static int
72 TIFFNoDecode(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 
87 static int
89 {
90  (void) tif;
91  return (1);
92 }
93 
94 int
96 {
97  (void) pp; (void) cc; (void) s;
98  return (TIFFNoDecode(tif, "scanline"));
99 }
100 
101 int
103 {
104  (void) pp; (void) cc; (void) s;
105  return (TIFFNoDecode(tif, "strip"));
106 }
107 
108 int
110 {
111  (void) pp; (void) cc; (void) s;
112  return (TIFFNoDecode(tif, "tile"));
113 }
114 
115 int
117 {
118  (void) off;
120  "Compression algorithm does not support random access");
121  return (0);
122 }
123 
124 int
126 {
127  (void) tif; (void) s;
128  return (1);
129 }
130 
131 static int _TIFFtrue(TIFF* tif) { (void) tif; return (1); }
132 static void _TIFFvoid(TIFF* tif) { (void) tif; }
133 
134 void
136 {
138  tif->tif_decodestatus = TRUE;
139  tif->tif_setupdecode = _TIFFtrue;
144  tif->tif_encodestatus = TRUE;
145  tif->tif_setupencode = _TIFFtrue;
147  tif->tif_postencode = _TIFFtrue;
151  tif->tif_close = _TIFFvoid;
152  tif->tif_seek = _TIFFNoSeek;
153  tif->tif_cleanup = _TIFFvoid;
157 }
158 
159 int
161 {
162  const TIFFCodec *c = TIFFFindCODEC((uint16) scheme);
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  */
179 typedef struct _codec {
180  struct _codec* next;
182 } codec_t;
184 
185 const 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 
200 TIFFCodec*
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 
223 void
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 
251 TIFFCodec*
253 {
254  int i = 1;
255  codec_t *cd;
256  const TIFFCodec* c;
257  TIFFCodec* codecs = NULL;
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) {
264  _TIFFfree (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) {
276  _TIFFfree (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) {
287  _TIFFfree (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  */
TIFFCodeMethod tif_decoderow
Definition: tiffiop.h:164
void _TIFFmemset(void *p, int v, tmsize_t c)
Definition: tif_unix.c:338
#define TRUE
Definition: types.h:120
TIFFPreMethod tif_predecode
Definition: tiffiop.h:159
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
int _TIFFNoTileDecode(TIFF *tif, uint8 *pp, tmsize_t cc, uint16 s)
Definition: tif_compress.c:109
static const struct image_codec codecs[NUM_CODECS]
Definition: image.c:4235
static int _TIFFtrue(TIFF *tif)
Definition: tif_compress.c:131
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static void _TIFFvoid(TIFF *tif)
Definition: tif_compress.c:132
TIFFCodeMethod tif_encodestrip
Definition: tiffiop.h:167
int _TIFFNoPreCode(TIFF *tif, uint16 s)
Definition: tif_compress.c:125
static struct cd_image cd
Definition: cdmake.c:182
unsigned int uint32
Definition: types.h:32
#define TIFF_NOREADRAW
Definition: tiffiop.h:123
TIFFCodeMethod tif_encoderow
Definition: tiffiop.h:165
DWORD scheme
TIFFVoidMethod tif_close
Definition: tiffiop.h:170
int(* TIFFInitMethod)(TIFF *, int)
Definition: tiffio.h:254
thandle_t tif_clientdata
Definition: tiffiop.h:191
int _TIFFNoSeek(TIFF *tif, uint32 off)
Definition: tif_compress.c:116
static int _TIFFNoFixupTags(TIFF *tif)
Definition: tif_compress.c:88
static int init
Definition: wintirpc.c:33
char * tif_name
Definition: tiffiop.h:103
Definition: tiffiop.h:102
static codec_t * registeredCODECS
Definition: tif_compress.c:183
static int TIFFNoDecode(TIFF *tif, const char *method)
Definition: tif_compress.c:72
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
TIFFCodec * TIFFRegisterCODEC(uint16 scheme, const char *name, TIFFInitMethod init)
Definition: tif_compress.c:201
TIFF_SSIZE_T tmsize_t
Definition: tiffio.h:65
int _TIFFNoTileEncode(TIFF *tif, uint8 *pp, tmsize_t cc, uint16 s)
Definition: tif_compress.c:65
#define pp
Definition: hlsl.yy.c:1208
int _TIFFNoRowDecode(TIFF *tif, uint8 *pp, tmsize_t cc, uint16 s)
Definition: tif_compress.c:95
uint32 tif_flags
Definition: tiffiop.h:106
smooth NULL
Definition: ftsmooth.c:416
int tif_encodestatus
Definition: tiffiop.h:161
TIFFCodeMethod tif_decodestrip
Definition: tiffiop.h:166
TIFFCodeMethod tif_encodetile
Definition: tiffiop.h:169
void * _TIFFmalloc(tmsize_t s)
Definition: tif_unix.c:309
TIFFSeekMethod tif_seek
Definition: tiffiop.h:171
int _TIFFNoStripEncode(TIFF *tif, uint8 *pp, tmsize_t cc, uint16 s)
Definition: tif_compress.c:58
TIFFTileMethod tif_deftilesize
Definition: tiffiop.h:174
TIFFPreMethod tif_preencode
Definition: tiffiop.h:162
uint32 _TIFFDefaultStripSize(TIFF *tif, uint32 s)
Definition: tif_strip.c:239
TIFFBoolMethod tif_postencode
Definition: tiffiop.h:163
int _TIFFNoRowEncode(TIFF *tif, uint8 *pp, tmsize_t cc, uint16 s)
Definition: tif_compress.c:51
const GLubyte * c
Definition: glext.h:8905
unsigned char uint8
Definition: types.h:28
void TIFFErrorExt(thandle_t fd, const char *module, const char *fmt,...)
Definition: tif_error.c:65
TIFFCodec * TIFFGetConfiguredCODECs()
Definition: tif_compress.c:252
method
Definition: dragdrop.c:53
TIFFCodeMethod tif_decodetile
Definition: tiffiop.h:168
void * _TIFFrealloc(void *p, tmsize_t s)
Definition: tif_unix.c:332
const TIFFCodec * TIFFFindCODEC(uint16 scheme)
Definition: tif_compress.c:186
#define TIFF_NOBITREV
Definition: tiffiop.h:114
TIFFVoidMethod tif_cleanup
Definition: tiffiop.h:172
GLdouble s
Definition: gl.h:2039
void _TIFFSetDefaultCompressionState(TIFF *tif)
Definition: tif_compress.c:135
void _TIFFDefaultTileSize(TIFF *tif, uint32 *tw, uint32 *th)
Definition: tif_tile.c:300
TIFFCodec _TIFFBuiltinCODECS[]
Definition: tif_codec.c:87
void TIFFUnRegisterCODEC(TIFFCodec *c)
Definition: tif_compress.c:224
uint32_t cc
Definition: isohybrid.c:75
int _TIFFNoStripDecode(TIFF *tif, uint8 *pp, tmsize_t cc, uint16 s)
Definition: tif_compress.c:102
int tif_decodestatus
Definition: tiffiop.h:156
unsigned short uint16
Definition: types.h:30
TIFFBoolMethod tif_fixuptags
Definition: tiffiop.h:157
TIFFDirectory tif_dir
Definition: tiffiop.h:135
int TIFFSetCompressionScheme(TIFF *tif, int scheme)
Definition: tif_compress.c:160
struct _codec * next
Definition: tif_compress.c:180
int TIFFIsCODECConfigured(uint16 scheme)
Definition: tif_codec.c:150
Definition: name.c:36
struct _codec codec_t
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define c
Definition: ke_i.h:80
char * name
Definition: tiffio.h:256
static int TIFFNoEncode(TIFF *tif, const char *method)
Definition: tif_compress.c:34
uint16 td_compression
Definition: tif_dir.h:76
void _TIFFfree(void *p)
Definition: tif_unix.c:326
TIFFBoolMethod tif_setupencode
Definition: tiffiop.h:160
TIFFStripMethod tif_defstripsize
Definition: tiffiop.h:173
TIFFCodec * info
Definition: tif_compress.c:181
void _TIFFmemcpy(void *d, const void *s, tmsize_t c)
Definition: tif_unix.c:344
off
Definition: i386-dis.c:3909
TIFFBoolMethod tif_setupdecode
Definition: tiffiop.h:158