home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 February / PCWorld_2002-02_cd.bin / Software / Vyzkuste / pdflib / pdflib-4.0.1.sit / pdflib-4.0.1 / tiff / tif_compress.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-07-04  |  4.0 KB  |  149 lines  |  [TEXT/CWIE]

  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. /* $Id: tif_compress.c,v 1.5 2001/03/21 17:16:25 rjs Exp $ */
  32.  
  33. #include "tiffiop.h"
  34.  
  35. static int
  36. TIFFNoDecode(TIFF* tif, char* method)
  37. {
  38.     const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression);
  39.  
  40.     if (c)
  41.         TIFFError(tif->tif_name, "%s %s decoding is not implemented",
  42.             c->name, method);
  43.     else
  44.         TIFFError(tif->tif_name,
  45.             "Compression scheme %u %s decoding is not implemented",
  46.             tif->tif_dir.td_compression, method);
  47.     return (-1);
  48. }
  49.  
  50. int
  51. _TIFFNoRowDecode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
  52. {
  53.     (void) pp; (void) cc; (void) s;
  54.     return (TIFFNoDecode(tif, "scanline"));
  55. }
  56.  
  57. int
  58. _TIFFNoStripDecode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
  59. {
  60.     (void) pp; (void) cc; (void) s;
  61.     return (TIFFNoDecode(tif, "strip"));
  62. }
  63.  
  64. int
  65. _TIFFNoTileDecode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
  66. {
  67.     (void) pp; (void) cc; (void) s;
  68.     return (TIFFNoDecode(tif, "tile"));
  69. }
  70.  
  71. int
  72. _TIFFNoSeek(TIFF* tif, uint32 off)
  73. {
  74.     (void) off;
  75.     TIFFError(tif->tif_name,
  76.         "Compression algorithm does not support random access");
  77.     return (0);
  78. }
  79.  
  80. int
  81. _TIFFNoPreCode(TIFF* tif, tsample_t s)
  82. {
  83.     (void) tif; (void) s;
  84.     return (1);
  85. }
  86.  
  87. static int _TIFFtrue(TIFF* tif) { (void) tif; return (1); }
  88. static void _TIFFvoid(TIFF* tif) { (void) tif; }
  89.  
  90. void
  91. _TIFFSetDefaultCompressionState(TIFF* tif)
  92. {
  93.     tif->tif_setupdecode = _TIFFtrue;
  94.     tif->tif_predecode = _TIFFNoPreCode;
  95.     tif->tif_decoderow = _TIFFNoRowDecode;
  96.     tif->tif_decodestrip = _TIFFNoStripDecode;
  97.     tif->tif_decodetile = _TIFFNoTileDecode;
  98.     tif->tif_setupencode = _TIFFtrue;
  99.     tif->tif_preencode = _TIFFNoPreCode;
  100.     tif->tif_postencode = _TIFFtrue;
  101.     tif->tif_close = _TIFFvoid;
  102.     tif->tif_seek = _TIFFNoSeek;
  103.     tif->tif_cleanup = _TIFFvoid;
  104.     tif->tif_defstripsize = _TIFFDefaultStripSize;
  105.     tif->tif_deftilesize = _TIFFDefaultTileSize;
  106.     tif->tif_flags &= ~TIFF_NOBITREV;
  107. }
  108.  
  109. int
  110. TIFFSetCompressionScheme(TIFF* tif, int scheme)
  111. {
  112.     const TIFFCodec *c = TIFFFindCODEC((uint16) scheme);
  113.  
  114.     _TIFFSetDefaultCompressionState(tif);
  115.     /*
  116.      * Don't treat an unknown compression scheme as an error.
  117.      * This permits applications to open files with data that
  118.      * the library does not have builtin support for, but which
  119.      * may still be meaningful.
  120.      */
  121.     return (c ? (*c->init)(tif, scheme) : 1);
  122. }
  123.  
  124. /*
  125.  * Other compression schemes may be registered.  Registered
  126.  * schemes can also override the builtin versions provided
  127.  * by this library.
  128.  */
  129. typedef struct _codec {
  130.     struct _codec*    next;
  131.     TIFFCodec*    info;
  132. } codec_t;
  133. static    codec_t* registeredCODECS = NULL;
  134.  
  135. const TIFFCodec*
  136. TIFFFindCODEC(uint16 scheme)
  137. {
  138.     const TIFFCodec* c;
  139.     codec_t* cd;
  140.  
  141.     for (cd = registeredCODECS; cd; cd = cd->next)
  142.         if (cd->info->scheme == scheme)
  143.             return ((const TIFFCodec*) cd->info);
  144.     for (c = _TIFFBuiltinCODECS; c->name; c++)
  145.         if (c->scheme == scheme)
  146.             return (c);
  147.     return ((const TIFFCodec*) 0);
  148. }
  149.