1 /* $Header: /usr/people/sam/tiff/libtiff/RCS/tif_compress.c,v 1.35 1994/07/26 16:45:49 sam Exp $ */
2
3 /*
4 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994 Sam Leffler
5 * Copyright (c) 1991, 1992, 1993, 1994 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 typedef struct {
35 char* name;
36 int scheme;
37 TIFFBoolMethod init;
38 } cscheme_t;
39 static const cscheme_t CompressionSchemes[] = {
40 { "Null", COMPRESSION_NONE, TIFFInitDumpMode },
41 #ifdef LZW_SUPPORT
42 { "LZW", COMPRESSION_LZW, TIFFInitLZW },
43 #endif
44 #ifdef PACKBITS_SUPPORT
45 { "PackBits", COMPRESSION_PACKBITS, TIFFInitPackBits },
46 #endif
47 #ifdef THUNDER_SUPPORT
48 { "ThunderScan", COMPRESSION_THUNDERSCAN,TIFFInitThunderScan },
49 #endif
50 #ifdef NEXT_SUPPORT
51 { "NeXT", COMPRESSION_NEXT, TIFFInitNeXT },
52 #endif
53 #ifdef JPEG_SUPPORT
54 { "JPEG", COMPRESSION_JPEG, TIFFInitJPEG },
55 #endif
56 #ifdef CCITT_SUPPORT
57 { "CCITT RLE", COMPRESSION_CCITTRLE, TIFFInitCCITTRLE },
58 { "CCITT RLE/W", COMPRESSION_CCITTRLEW, TIFFInitCCITTRLEW },
59 { "CCITT Group3", COMPRESSION_CCITTFAX3, TIFFInitCCITTFax3 },
60 { "CCITT Group4", COMPRESSION_CCITTFAX4, TIFFInitCCITTFax4 },
61 #endif
62 };
63 #define NSCHEMES (sizeof (CompressionSchemes) / sizeof (CompressionSchemes[0]))
64
65 static const cscheme_t *
findScheme(int scheme)66 findScheme(int scheme)
67 {
68 register const cscheme_t *c;
69
70 for (c = CompressionSchemes; c < &CompressionSchemes[NSCHEMES]; c++)
71 if (c->scheme == scheme)
72 return (c);
73 return ((const cscheme_t *)0);
74 }
75
76 static int
TIFFNoEncode(TIFF * tif,char * method)77 TIFFNoEncode(TIFF* tif, char* method)
78 {
79 const cscheme_t *c = findScheme(tif->tif_dir.td_compression);
80 TIFFError(tif->tif_name,
81 "%s %s encoding is not implemented", c->name, method);
82 return (-1);
83 }
84
85 int
TIFFNoRowEncode(TIFF * tif,tidata_t pp,tsize_t cc,tsample_t s)86 TIFFNoRowEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
87 {
88 return (TIFFNoEncode(tif, "scanline"));
89 }
90
91 int
TIFFNoStripEncode(TIFF * tif,tidata_t pp,tsize_t cc,tsample_t s)92 TIFFNoStripEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
93 {
94 return (TIFFNoEncode(tif, "strip"));
95 }
96
97 int
TIFFNoTileEncode(TIFF * tif,tidata_t pp,tsize_t cc,tsample_t s)98 TIFFNoTileEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
99 {
100 return (TIFFNoEncode(tif, "tile"));
101 }
102
103 static int
TIFFNoDecode(TIFF * tif,char * method)104 TIFFNoDecode(TIFF* tif, char* method)
105 {
106 const cscheme_t *c = findScheme(tif->tif_dir.td_compression);
107 TIFFError(tif->tif_name,
108 "%s %s decoding is not implemented", c->name, method);
109 return (-1);
110 }
111
112 int
TIFFNoRowDecode(TIFF * tif,tidata_t pp,tsize_t cc,tsample_t s)113 TIFFNoRowDecode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
114 {
115 return (TIFFNoDecode(tif, "scanline"));
116 }
117
118 int
TIFFNoStripDecode(TIFF * tif,tidata_t pp,tsize_t cc,tsample_t s)119 TIFFNoStripDecode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
120 {
121 return (TIFFNoDecode(tif, "strip"));
122 }
123
124 int
TIFFNoTileDecode(TIFF * tif,tidata_t pp,tsize_t cc,tsample_t s)125 TIFFNoTileDecode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
126 {
127 return (TIFFNoDecode(tif, "tile"));
128 }
129
130 int
TIFFSetCompressionScheme(TIFF * tif,int scheme)131 TIFFSetCompressionScheme(TIFF* tif, int scheme)
132 {
133 const cscheme_t *c = findScheme(scheme);
134
135 if (!c) {
136 TIFFError(tif->tif_name,
137 "Unknown data compression algorithm %u (0x%x)",
138 scheme, scheme);
139 return (0);
140 }
141 tif->tif_predecode = NULL;
142 tif->tif_decoderow = TIFFNoRowDecode;
143 tif->tif_decodestrip = TIFFNoStripDecode;
144 tif->tif_decodetile = TIFFNoTileDecode;
145 tif->tif_preencode = NULL;
146 tif->tif_postencode = NULL;
147 tif->tif_encoderow = TIFFNoRowEncode;
148 tif->tif_encodestrip = TIFFNoStripEncode;
149 tif->tif_encodetile = TIFFNoTileEncode;
150 tif->tif_close = NULL;
151 tif->tif_seek = NULL;
152 tif->tif_cleanup = NULL;
153 tif->tif_flags &= ~TIFF_NOBITREV;
154 tif->tif_options = 0;
155 return ((*c->init)(tif));
156 }
157