Visualization Library 2.0.0-b5

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
tif_compress.c
Go to the documentation of this file.
1 /* $Id: tif_compress.c,v 1.11 2005/12/21 12:23:13 joris Exp $ */
2 
3 /*
4  * Copyright (c) 1988-1997 Sam Leffler
5  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
6  *
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.
14  *
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.
18  *
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
24  * OF THIS SOFTWARE.
25  */
26 
27 /*
28  * TIFF Library
29  *
30  * Compression Scheme Configuration Support.
31  */
32 #include "tiffiop.h"
33 
34 static int
35 TIFFNoEncode(TIFF* tif, const char* method)
36 {
38 
39  if (c) {
40  TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "%s %s encoding is not implemented",
41  c->name, method);
42  } else {
44  "Compression scheme %u %s encoding is not implemented",
45  tif->tif_dir.td_compression, method);
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)
77  TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "%s %s decoding is not implemented",
78  c->name, method);
79  else
81  "Compression scheme %u %s decoding is not implemented",
82  tif->tif_dir.td_compression, method);
83  return (-1);
84 }
85 
86 int
88 {
89  (void) pp; (void) cc; (void) s;
90  return (TIFFNoDecode(tif, "scanline"));
91 }
92 
93 int
95 {
96  (void) pp; (void) cc; (void) s;
97  return (TIFFNoDecode(tif, "strip"));
98 }
99 
100 int
102 {
103  (void) pp; (void) cc; (void) s;
104  return (TIFFNoDecode(tif, "tile"));
105 }
106 
107 int
109 {
110  (void) off;
112  "Compression algorithm does not support random access");
113  return (0);
114 }
115 
116 int
118 {
119  (void) tif; (void) s;
120  return (1);
121 }
122 
123 static int _TIFFtrue(TIFF* tif) { (void) tif; return (1); }
124 static void _TIFFvoid(TIFF* tif) { (void) tif; }
125 
126 void
128 {
129  tif->tif_decodestatus = TRUE;
130  tif->tif_setupdecode = _TIFFtrue;
135  tif->tif_encodestatus = TRUE;
136  tif->tif_setupencode = _TIFFtrue;
138  tif->tif_postencode = _TIFFtrue;
142  tif->tif_close = _TIFFvoid;
143  tif->tif_seek = _TIFFNoSeek;
144  tif->tif_cleanup = _TIFFvoid;
147  tif->tif_flags &= ~TIFF_NOBITREV;
148 }
149 
150 int
152 {
153  const TIFFCodec *c = TIFFFindCODEC((uint16) scheme);
154 
156  /*
157  * Don't treat an unknown compression scheme as an error.
158  * This permits applications to open files with data that
159  * the library does not have builtin support for, but which
160  * may still be meaningful.
161  */
162  return (c ? (*c->init)(tif, scheme) : 1);
163 }
164 
165 /*
166  * Other compression schemes may be registered. Registered
167  * schemes can also override the builtin versions provided
168  * by this library.
169  */
170 typedef struct _codec {
171  struct _codec* next;
172  TIFFCodec* info;
173 } codec_t;
174 static codec_t* registeredCODECS = NULL;
175 
176 const TIFFCodec*
178 {
179  const TIFFCodec* c;
180  codec_t* cd;
181 
182  for (cd = registeredCODECS; cd; cd = cd->next)
183  if (cd->info->scheme == scheme)
184  return ((const TIFFCodec*) cd->info);
185  for (c = _TIFFBuiltinCODECS; c->name; c++)
186  if (c->scheme == scheme)
187  return (c);
188  return ((const TIFFCodec*) 0);
189 }
190 
191 TIFFCodec*
192 TIFFRegisterCODEC(uint16 scheme, const char* name, TIFFInitMethod init)
193 {
194  codec_t* cd = (codec_t*)
195  _TIFFmalloc(sizeof (codec_t) + sizeof (TIFFCodec) + strlen(name)+1);
196 
197  if (cd != NULL) {
198  cd->info = (TIFFCodec*) ((tidata_t) cd + sizeof (codec_t));
199  cd->info->name = (char*)
200  ((tidata_t) cd->info + sizeof (TIFFCodec));
201  strcpy(cd->info->name, name);
202  cd->info->scheme = scheme;
203  cd->info->init = init;
204  cd->next = registeredCODECS;
205  registeredCODECS = cd;
206  } else {
207  TIFFErrorExt(0, "TIFFRegisterCODEC",
208  "No space to register compression scheme %s", name);
209  return NULL;
210  }
211  return (cd->info);
212 }
213 
214 void
216 {
217  codec_t* cd;
218  codec_t** pcd;
219 
220  for (pcd = &registeredCODECS; (cd = *pcd); pcd = &cd->next)
221  if (cd->info == c) {
222  *pcd = cd->next;
223  _TIFFfree(cd);
224  return;
225  }
226  TIFFErrorExt(0, "TIFFUnRegisterCODEC",
227  "Cannot remove compression scheme %s; not registered", c->name);
228 }
229 
230 /************************************************************************/
231 /* TIFFGetConfisuredCODECs() */
232 /************************************************************************/
233 
242 TIFFCodec*
244 {
245  int i = 1;
246  codec_t *cd;
247  const TIFFCodec *c;
248  TIFFCodec *codecs = NULL, *new_codecs;
249 
250  for (cd = registeredCODECS; cd; cd = cd->next) {
251  new_codecs = (TIFFCodec *)
252  _TIFFrealloc(codecs, i * sizeof(TIFFCodec));
253  if (!new_codecs) {
254  _TIFFfree (codecs);
255  return NULL;
256  }
257  codecs = new_codecs;
258  _TIFFmemcpy(codecs + i - 1, cd, sizeof(TIFFCodec));
259  i++;
260  }
261  for (c = _TIFFBuiltinCODECS; c->name; c++) {
262  if (TIFFIsCODECConfigured(c->scheme)) {
263  new_codecs = (TIFFCodec *)
264  _TIFFrealloc(codecs, i * sizeof(TIFFCodec));
265  if (!new_codecs) {
266  _TIFFfree (codecs);
267  return NULL;
268  }
269  codecs = new_codecs;
270  _TIFFmemcpy(codecs + i - 1, (const tdata_t)c, sizeof(TIFFCodec));
271  i++;
272  }
273  }
274 
275  new_codecs = (TIFFCodec *) _TIFFrealloc(codecs, i * sizeof(TIFFCodec));
276  if (!new_codecs) {
277  _TIFFfree (codecs);
278  return NULL;
279  }
280  codecs = new_codecs;
281  _TIFFmemset(codecs + i - 1, 0, sizeof(TIFFCodec));
282 
283  return codecs;
284 }
285 
286 /* vim: set ts=8 sts=8 sw=8 noet: */
int32 tsize_t
Definition: tiffio.h:66
uint16 scheme
Definition: tiffio.h:244
uint16 tsample_t
Definition: tiffio.h:63
TIFFCodeMethod tif_decoderow
Definition: tiffiop.h:146
void * tdata_t
Definition: tiffio.h:67
int _TIFFNoStripEncode(TIFF *tif, tidata_t pp, tsize_t cc, tsample_t s)
Definition: tif_compress.c:58
TIFFPreMethod tif_predecode
Definition: tiffiop.h:141
#define NULL
Definition: ftobjs.h:61
TIFFCodeMethod tif_encodestrip
Definition: tiffiop.h:149
TIFFInitMethod init
Definition: tiffio.h:245
TIFFCodeMethod tif_encoderow
Definition: tiffiop.h:147
TIFFVoidMethod tif_close
Definition: tiffiop.h:152
int(* TIFFInitMethod)(TIFF *, int)
Definition: tiffio.h:241
int _TIFFNoRowEncode(TIFF *tif, tidata_t pp, tsize_t cc, tsample_t s)
Definition: tif_compress.c:51
thandle_t tif_clientdata
Definition: tiffiop.h:171
int _TIFFNoSeek(TIFF *tif, uint32 off)
Definition: tif_compress.c:108
int _TIFFNoTileEncode(TIFF *tif, tidata_t pp, tsize_t cc, tsample_t s)
Definition: tif_compress.c:65
typedef void(APIENTRY *GLDEBUGPROCARB)(GLenum source
char * tif_name
Definition: tiffiop.h:96
Definition: tiffiop.h:95
png_uint_32 i
Definition: png.h:2640
void _TIFFmemcpy(tdata_t d, const tdata_t s, tsize_t c)
Definition: tif_acorn.c:485
char * name
Definition: tiffio.h:243
TIFFCodec * TIFFRegisterCODEC(uint16 scheme, const char *name, TIFFInitMethod init)
Definition: tif_compress.c:192
int _TIFFNoStripDecode(TIFF *tif, tidata_t pp, tsize_t cc, tsample_t s)
Definition: tif_compress.c:94
uint32 tif_flags
Definition: tiffiop.h:99
int tif_encodestatus
Definition: tiffiop.h:143
TIFFCodeMethod tif_decodestrip
Definition: tiffiop.h:148
TIFFCodeMethod tif_encodetile
Definition: tiffiop.h:151
TIFFSeekMethod tif_seek
Definition: tiffiop.h:153
int _TIFFNoPreCode(TIFF *tif, tsample_t s)
Definition: tif_compress.c:117
TIFFTileMethod tif_deftilesize
Definition: tiffiop.h:156
TIFFPreMethod tif_preencode
Definition: tiffiop.h:144
int method
Definition: png.h:1717
uint32 _TIFFDefaultStripSize(TIFF *tif, uint32 s)
Definition: tif_strip.c:204
unsigned short uint16
Definition: tiff.h:71
TIFFBoolMethod tif_postencode
Definition: tiffiop.h:145
int _TIFFNoTileDecode(TIFF *tif, tidata_t pp, tsize_t cc, tsample_t s)
Definition: tif_compress.c:101
const GLubyte * c
void * _TIFFrealloc(tdata_t p, tsize_t s)
Definition: tif_acorn.c:473
int _TIFFNoRowDecode(TIFF *tif, tidata_t pp, tsize_t cc, tsample_t s)
Definition: tif_compress.c:87
void TIFFErrorExt(thandle_t fd, const char *module, const char *fmt,...)
Definition: tif_error.c:63
TIFFCodec * TIFFGetConfiguredCODECs()
Get list of configured codecs, both built-in and registered by user.
Definition: tif_compress.c:243
TIFFCodeMethod tif_decodetile
Definition: tiffiop.h:150
const TIFFCodec * TIFFFindCODEC(uint16 scheme)
Definition: tif_compress.c:177
#define TIFF_NOBITREV
Definition: tiffiop.h:107
TIFFVoidMethod tif_cleanup
Definition: tiffiop.h:154
void _TIFFmemset(tdata_t p, int v, tsize_t c)
Definition: tif_acorn.c:479
void _TIFFSetDefaultCompressionState(TIFF *tif)
Definition: tif_compress.c:127
void _TIFFDefaultTileSize(TIFF *tif, uint32 *tw, uint32 *th)
Definition: tif_tile.c:259
GLuint const GLchar * name
TIFFCodec _TIFFBuiltinCODECS[]
Definition: tif_codec.c:79
unsigned long uint32
Definition: md5.h:41
tidataval_t * tidata_t
Definition: tiffiop.h:84
void TIFFUnRegisterCODEC(TIFFCodec *c)
Definition: tif_compress.c:215
backing_store_ptr info
Definition: jmemsys.h:181
int tif_decodestatus
Definition: tiffiop.h:139
TIFFDirectory tif_dir
Definition: tiffiop.h:122
int TIFFSetCompressionScheme(TIFF *tif, int scheme)
Definition: tif_compress.c:151
GLdouble s
uint16 td_compression
Definition: tif_dir.h:46
int TIFFIsCODECConfigured(uint16 scheme)
Check whether we have working codec for the specific coding scheme.
Definition: tif_codec.c:135
void * _TIFFmalloc(tsize_t s)
Definition: tif_acorn.c:461
struct _codec codec_t
void _TIFFfree(tdata_t p)
Definition: tif_acorn.c:467
TIFFBoolMethod tif_setupencode
Definition: tiffiop.h:142
TIFFStripMethod tif_defstripsize
Definition: tiffiop.h:155
#define TRUE
Definition: ftobjs.h:53
TIFFBoolMethod tif_setupdecode
Definition: tiffiop.h:140