Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygentif_compress.c
Go to the documentation of this file.
00001 /* $Id: tif_compress.c,v 1.13.2.1 2010-06-08 18:50:41 bfriesen Exp $ */ 00002 00003 /* 00004 * Copyright (c) 1988-1997 Sam Leffler 00005 * Copyright (c) 1991-1997 Silicon Graphics, Inc. 00006 * 00007 * Permission to use, copy, modify, distribute, and sell this software and 00008 * its documentation for any purpose is hereby granted without fee, provided 00009 * that (i) the above copyright notices and this permission notice appear in 00010 * all copies of the software and related documentation, and (ii) the names of 00011 * Sam Leffler and Silicon Graphics may not be used in any advertising or 00012 * publicity relating to the software without the specific, prior written 00013 * permission of Sam Leffler and Silicon Graphics. 00014 * 00015 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 00016 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 00017 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 00018 * 00019 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR 00020 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, 00021 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 00022 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 00023 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 00024 * OF THIS SOFTWARE. 00025 */ 00026 00027 /* 00028 * TIFF Library 00029 * 00030 * Compression Scheme Configuration Support. 00031 */ 00032 #include "tiffiop.h" 00033 00034 static int 00035 TIFFNoEncode(TIFF* tif, const char* method) 00036 { 00037 const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression); 00038 00039 if (c) { 00040 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 00041 "%s %s encoding is not implemented", 00042 c->name, method); 00043 } else { 00044 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 00045 "Compression scheme %u %s encoding is not implemented", 00046 tif->tif_dir.td_compression, method); 00047 } 00048 return (-1); 00049 } 00050 00051 int 00052 _TIFFNoRowEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s) 00053 { 00054 (void) pp; (void) cc; (void) s; 00055 return (TIFFNoEncode(tif, "scanline")); 00056 } 00057 00058 int 00059 _TIFFNoStripEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s) 00060 { 00061 (void) pp; (void) cc; (void) s; 00062 return (TIFFNoEncode(tif, "strip")); 00063 } 00064 00065 int 00066 _TIFFNoTileEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s) 00067 { 00068 (void) pp; (void) cc; (void) s; 00069 return (TIFFNoEncode(tif, "tile")); 00070 } 00071 00072 static int 00073 TIFFNoDecode(TIFF* tif, const char* method) 00074 { 00075 const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression); 00076 00077 if (c) 00078 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 00079 "%s %s decoding is not implemented", 00080 c->name, method); 00081 else 00082 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 00083 "Compression scheme %u %s decoding is not implemented", 00084 tif->tif_dir.td_compression, method); 00085 return (-1); 00086 } 00087 00088 int 00089 _TIFFNoRowDecode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s) 00090 { 00091 (void) pp; (void) cc; (void) s; 00092 return (TIFFNoDecode(tif, "scanline")); 00093 } 00094 00095 int 00096 _TIFFNoStripDecode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s) 00097 { 00098 (void) pp; (void) cc; (void) s; 00099 return (TIFFNoDecode(tif, "strip")); 00100 } 00101 00102 int 00103 _TIFFNoTileDecode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s) 00104 { 00105 (void) pp; (void) cc; (void) s; 00106 return (TIFFNoDecode(tif, "tile")); 00107 } 00108 00109 int 00110 _TIFFNoSeek(TIFF* tif, uint32 off) 00111 { 00112 (void) off; 00113 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 00114 "Compression algorithm does not support random access"); 00115 return (0); 00116 } 00117 00118 int 00119 _TIFFNoPreCode(TIFF* tif, tsample_t s) 00120 { 00121 (void) tif; (void) s; 00122 return (1); 00123 } 00124 00125 static int _TIFFtrue(TIFF* tif) { (void) tif; return (1); } 00126 static void _TIFFvoid(TIFF* tif) { (void) tif; } 00127 00128 void 00129 _TIFFSetDefaultCompressionState(TIFF* tif) 00130 { 00131 tif->tif_decodestatus = TRUE; 00132 tif->tif_setupdecode = _TIFFtrue; 00133 tif->tif_predecode = _TIFFNoPreCode; 00134 tif->tif_decoderow = _TIFFNoRowDecode; 00135 tif->tif_decodestrip = _TIFFNoStripDecode; 00136 tif->tif_decodetile = _TIFFNoTileDecode; 00137 tif->tif_encodestatus = TRUE; 00138 tif->tif_setupencode = _TIFFtrue; 00139 tif->tif_preencode = _TIFFNoPreCode; 00140 tif->tif_postencode = _TIFFtrue; 00141 tif->tif_encoderow = _TIFFNoRowEncode; 00142 tif->tif_encodestrip = _TIFFNoStripEncode; 00143 tif->tif_encodetile = _TIFFNoTileEncode; 00144 tif->tif_close = _TIFFvoid; 00145 tif->tif_seek = _TIFFNoSeek; 00146 tif->tif_cleanup = _TIFFvoid; 00147 tif->tif_defstripsize = _TIFFDefaultStripSize; 00148 tif->tif_deftilesize = _TIFFDefaultTileSize; 00149 tif->tif_flags &= ~(TIFF_NOBITREV|TIFF_NOREADRAW); 00150 } 00151 00152 int 00153 TIFFSetCompressionScheme(TIFF* tif, int scheme) 00154 { 00155 const TIFFCodec *c = TIFFFindCODEC((uint16) scheme); 00156 00157 _TIFFSetDefaultCompressionState(tif); 00158 /* 00159 * Don't treat an unknown compression scheme as an error. 00160 * This permits applications to open files with data that 00161 * the library does not have builtin support for, but which 00162 * may still be meaningful. 00163 */ 00164 return (c ? (*c->init)(tif, scheme) : 1); 00165 } 00166 00167 /* 00168 * Other compression schemes may be registered. Registered 00169 * schemes can also override the builtin versions provided 00170 * by this library. 00171 */ 00172 typedef struct _codec { 00173 struct _codec* next; 00174 TIFFCodec* info; 00175 } codec_t; 00176 static codec_t* registeredCODECS = NULL; 00177 00178 const TIFFCodec* 00179 TIFFFindCODEC(uint16 scheme) 00180 { 00181 const TIFFCodec* c; 00182 codec_t* cd; 00183 00184 for (cd = registeredCODECS; cd; cd = cd->next) 00185 if (cd->info->scheme == scheme) 00186 return ((const TIFFCodec*) cd->info); 00187 for (c = _TIFFBuiltinCODECS; c->name; c++) 00188 if (c->scheme == scheme) 00189 return (c); 00190 return ((const TIFFCodec*) 0); 00191 } 00192 00193 TIFFCodec* 00194 TIFFRegisterCODEC(uint16 scheme, const char* name, TIFFInitMethod init) 00195 { 00196 codec_t* cd = (codec_t*) 00197 _TIFFmalloc(sizeof (codec_t) + sizeof (TIFFCodec) + strlen(name)+1); 00198 00199 if (cd != NULL) { 00200 cd->info = (TIFFCodec*) ((tidata_t) cd + sizeof (codec_t)); 00201 cd->info->name = (char*) 00202 ((tidata_t) cd->info + sizeof (TIFFCodec)); 00203 strcpy(cd->info->name, name); 00204 cd->info->scheme = scheme; 00205 cd->info->init = init; 00206 cd->next = registeredCODECS; 00207 registeredCODECS = cd; 00208 } else { 00209 TIFFErrorExt(0, "TIFFRegisterCODEC", 00210 "No space to register compression scheme %s", name); 00211 return NULL; 00212 } 00213 return (cd->info); 00214 } 00215 00216 void 00217 TIFFUnRegisterCODEC(TIFFCodec* c) 00218 { 00219 codec_t* cd; 00220 codec_t** pcd; 00221 00222 for (pcd = ®isteredCODECS; (cd = *pcd); pcd = &cd->next) 00223 if (cd->info == c) { 00224 *pcd = cd->next; 00225 _TIFFfree(cd); 00226 return; 00227 } 00228 TIFFErrorExt(0, "TIFFUnRegisterCODEC", 00229 "Cannot remove compression scheme %s; not registered", c->name); 00230 } 00231 00232 /************************************************************************/ 00233 /* TIFFGetConfisuredCODECs() */ 00234 /************************************************************************/ 00235 00244 TIFFCodec* 00245 TIFFGetConfiguredCODECs() 00246 { 00247 int i = 1; 00248 codec_t *cd; 00249 const TIFFCodec *c; 00250 TIFFCodec *codecs = NULL, *new_codecs; 00251 00252 for (cd = registeredCODECS; cd; cd = cd->next) { 00253 new_codecs = (TIFFCodec *) 00254 _TIFFrealloc(codecs, i * sizeof(TIFFCodec)); 00255 if (!new_codecs) { 00256 _TIFFfree (codecs); 00257 return NULL; 00258 } 00259 codecs = new_codecs; 00260 _TIFFmemcpy(codecs + i - 1, cd, sizeof(TIFFCodec)); 00261 i++; 00262 } 00263 for (c = _TIFFBuiltinCODECS; c->name; c++) { 00264 if (TIFFIsCODECConfigured(c->scheme)) { 00265 new_codecs = (TIFFCodec *) 00266 _TIFFrealloc(codecs, i * sizeof(TIFFCodec)); 00267 if (!new_codecs) { 00268 _TIFFfree (codecs); 00269 return NULL; 00270 } 00271 codecs = new_codecs; 00272 _TIFFmemcpy(codecs + i - 1, (const tdata_t)c, sizeof(TIFFCodec)); 00273 i++; 00274 } 00275 } 00276 00277 new_codecs = (TIFFCodec *) _TIFFrealloc(codecs, i * sizeof(TIFFCodec)); 00278 if (!new_codecs) { 00279 _TIFFfree (codecs); 00280 return NULL; 00281 } 00282 codecs = new_codecs; 00283 _TIFFmemset(codecs + i - 1, 0, sizeof(TIFFCodec)); 00284 00285 return codecs; 00286 } 00287 00288 /* vim: set ts=8 sts=8 sw=8 noet: */ 00289 /* 00290 * Local Variables: 00291 * mode: c 00292 * c-basic-offset: 8 00293 * fill-column: 78 00294 * End: 00295 */ Generated on Thu May 24 2012 04:19:43 for ReactOS by
1.7.6.1
|