1793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/* $Id: tif_codec.c,v 1.15 2010-12-14 12:53:00 dron Exp $ */
2793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
3793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/*
4793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Copyright (c) 1988-1997 Sam Leffler
5793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Copyright (c) 1991-1997 Silicon Graphics, Inc.
6793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *
7793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Permission to use, copy, modify, distribute, and sell this software and
8793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * its documentation for any purpose is hereby granted without fee, provided
9793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * that (i) the above copyright notices and this permission notice appear in
10793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * all copies of the software and related documentation, and (ii) the names of
11793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Sam Leffler and Silicon Graphics may not be used in any advertising or
12793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * publicity relating to the software without the specific, prior written
13793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * permission of Sam Leffler and Silicon Graphics.
14793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *
15793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
16793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
17793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
18793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *
19793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
20793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
21793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
22793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
23793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * OF THIS SOFTWARE.
25793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
26793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
27793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/*
28793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * TIFF Library
29793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *
30793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Builtin Compression Scheme Configuration Support.
31793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
32793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "tiffiop.h"
33793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
34793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerstatic int NotConfigured(TIFF*, int);
35793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
36793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#ifndef LZW_SUPPORT
37793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define TIFFInitLZW NotConfigured
38793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#endif
39793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#ifndef PACKBITS_SUPPORT
40793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define TIFFInitPackBits NotConfigured
41793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#endif
42793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#ifndef THUNDER_SUPPORT
43793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define TIFFInitThunderScan NotConfigured
44793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#endif
45793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#ifndef NEXT_SUPPORT
46793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define TIFFInitNeXT NotConfigured
47793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#endif
48793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#ifndef JPEG_SUPPORT
49793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define TIFFInitJPEG NotConfigured
50793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#endif
51793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#ifndef OJPEG_SUPPORT
52793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define TIFFInitOJPEG NotConfigured
53793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#endif
54793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#ifndef CCITT_SUPPORT
55793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define TIFFInitCCITTRLE NotConfigured
56793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define TIFFInitCCITTRLEW NotConfigured
57793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define TIFFInitCCITTFax3 NotConfigured
58793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define TIFFInitCCITTFax4 NotConfigured
59793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#endif
60793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#ifndef JBIG_SUPPORT
61793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define TIFFInitJBIG NotConfigured
62793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#endif
63793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#ifndef ZIP_SUPPORT
64793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define TIFFInitZIP NotConfigured
65793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#endif
66793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#ifndef PIXARLOG_SUPPORT
67793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define TIFFInitPixarLog NotConfigured
68793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#endif
69793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#ifndef LOGLUV_SUPPORT
70793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define TIFFInitSGILog NotConfigured
71793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#endif
72793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#ifndef LZMA_SUPPORT
73793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define TIFFInitLZMA NotConfigured
74793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#endif
75793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
76793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/*
77793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Compression schemes statically built into the library.
78793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
79793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#ifdef VMS
80793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerconst TIFFCodec _TIFFBuiltinCODECS[] = {
81793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#else
82793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerTIFFCodec _TIFFBuiltinCODECS[] = {
83793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#endif
84793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    { "None",		COMPRESSION_NONE,	TIFFInitDumpMode },
85793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    { "LZW",		COMPRESSION_LZW,	TIFFInitLZW },
86793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    { "PackBits",	COMPRESSION_PACKBITS,	TIFFInitPackBits },
87793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    { "ThunderScan",	COMPRESSION_THUNDERSCAN,TIFFInitThunderScan },
88793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    { "NeXT",		COMPRESSION_NEXT,	TIFFInitNeXT },
89793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    { "JPEG",		COMPRESSION_JPEG,	TIFFInitJPEG },
90793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    { "Old-style JPEG",	COMPRESSION_OJPEG,	TIFFInitOJPEG },
91793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    { "CCITT RLE",	COMPRESSION_CCITTRLE,	TIFFInitCCITTRLE },
92793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    { "CCITT RLE/W",	COMPRESSION_CCITTRLEW,	TIFFInitCCITTRLEW },
93793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    { "CCITT Group 3",	COMPRESSION_CCITTFAX3,	TIFFInitCCITTFax3 },
94793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    { "CCITT Group 4",	COMPRESSION_CCITTFAX4,	TIFFInitCCITTFax4 },
95793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    { "ISO JBIG",	COMPRESSION_JBIG,	TIFFInitJBIG },
96793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    { "Deflate",	COMPRESSION_DEFLATE,	TIFFInitZIP },
97793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    { "AdobeDeflate",   COMPRESSION_ADOBE_DEFLATE , TIFFInitZIP },
98793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    { "PixarLog",	COMPRESSION_PIXARLOG,	TIFFInitPixarLog },
99793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    { "SGILog",		COMPRESSION_SGILOG,	TIFFInitSGILog },
100793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    { "SGILog24",	COMPRESSION_SGILOG24,	TIFFInitSGILog },
101793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    { "LZMA",		COMPRESSION_LZMA,	TIFFInitLZMA },
102793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    { NULL,             0,                      NULL }
103793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler};
104793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
105793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerstatic int
106793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler_notConfigured(TIFF* tif)
107793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{
108793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression);
109793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        char compression_code[20];
110793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
111793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        sprintf( compression_code, "%d", tif->tif_dir.td_compression );
112793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
113793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                     "%s compression support is not configured",
114793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler                     c ? c->name : compression_code );
115793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    return (0);
116793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler}
117793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
118793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerstatic int
119793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerNotConfigured(TIFF* tif, int scheme)
120793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{
121793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    (void) scheme;
122793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
123793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    tif->tif_fixuptags = _notConfigured;
124793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    tif->tif_decodestatus = FALSE;
125793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    tif->tif_setupdecode = _notConfigured;
126793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    tif->tif_encodestatus = FALSE;
127793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    tif->tif_setupencode = _notConfigured;
128793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    return (1);
129793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler}
130793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
131793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/************************************************************************/
132793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/*                       TIFFIsCODECConfigured()                        */
133793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/************************************************************************/
134793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
135793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/**
136793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Check whether we have working codec for the specific coding scheme.
137793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler *
138793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * @return returns 1 if the codec is configured and working. Otherwise
139793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * 0 will be returned.
140793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
141793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
142793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerint
143793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerTIFFIsCODECConfigured(uint16 scheme)
144793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{
145793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    const TIFFCodec* codec = TIFFFindCODEC(scheme);
146793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
147793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    if(codec == NULL) {
148793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        return 0;
149793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    }
150793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    if(codec->init == NULL) {
151793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        return 0;
152793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    }
153793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    if(codec->init != NotConfigured){
154793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler        return 1;
155793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    }
156793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler    return 0;
157793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler}
158793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler
159793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/*
160793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * Local Variables:
161793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * mode: c
162793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * c-basic-offset: 8
163793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * fill-column: 78
164793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler * End:
165793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler */
166