1///////////////////////////////////////////////////////////////////////////
2//
3// Copyright (c) 2004, Industrial Light & Magic, a division of Lucas
4// Digital Ltd. LLC
5//
6// All rights reserved.
7//
8// Redistribution and use in source and binary forms, with or without
9// modification, are permitted provided that the following conditions are
10// met:
11// *       Redistributions of source code must retain the above copyright
12// notice, this list of conditions and the following disclaimer.
13// *       Redistributions in binary form must reproduce the above
14// copyright notice, this list of conditions and the following disclaimer
15// in the documentation and/or other materials provided with the
16// distribution.
17// *       Neither the name of Industrial Light & Magic nor the names of
18// its contributors may be used to endorse or promote products derived
19// from this software without specific prior written permission.
20//
21// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32//
33///////////////////////////////////////////////////////////////////////////
34
35
36
37//-----------------------------------------------------------------------------
38//
39//	class Compressor
40//
41//-----------------------------------------------------------------------------
42
43#include <ImfCompressor.h>
44#include <ImfRleCompressor.h>
45#include <ImfZipCompressor.h>
46#include <ImfPizCompressor.h>
47#include <ImfPxr24Compressor.h>
48#include <ImfB44Compressor.h>
49
50namespace Imf {
51
52using Imath::Box2i;
53
54
55Compressor::Compressor (const Header &hdr): _header (hdr) {}
56
57
58Compressor::~Compressor () {}
59
60
61Compressor::Format
62Compressor::format () const
63{
64    return XDR;
65}
66
67
68int
69Compressor::compressTile (const char *inPtr,
70			  int inSize,
71			  Box2i range,
72			  const char *&outPtr)
73{
74    return compress (inPtr, inSize, range.min.y, outPtr);
75}
76
77
78int
79Compressor::uncompressTile (const char *inPtr,
80			    int inSize,
81			    Box2i range,
82			    const char *&outPtr)
83{
84    return uncompress (inPtr, inSize, range.min.y, outPtr);
85}
86
87
88bool
89isValidCompression (Compression c)
90{
91    switch (c)
92    {
93      case NO_COMPRESSION:
94      case RLE_COMPRESSION:
95      case ZIPS_COMPRESSION:
96      case ZIP_COMPRESSION:
97      case PIZ_COMPRESSION:
98      case PXR24_COMPRESSION:
99      case B44_COMPRESSION:
100      case B44A_COMPRESSION:
101
102	return true;
103
104      default:
105
106	return false;
107    }
108}
109
110
111Compressor *
112newCompressor (Compression c, int maxScanLineSize, const Header &hdr)
113{
114    switch (c)
115    {
116      case RLE_COMPRESSION:
117
118	return new RleCompressor (hdr, maxScanLineSize);
119
120      case ZIPS_COMPRESSION:
121
122	return new ZipCompressor (hdr, maxScanLineSize, 1);
123
124      case ZIP_COMPRESSION:
125
126	return new ZipCompressor (hdr, maxScanLineSize, 16);
127
128      case PIZ_COMPRESSION:
129
130	return new PizCompressor (hdr, maxScanLineSize, 32);
131
132      case PXR24_COMPRESSION:
133
134	return new Pxr24Compressor (hdr, maxScanLineSize, 16);
135
136      case B44_COMPRESSION:
137
138	return new B44Compressor (hdr, maxScanLineSize, 32, false);
139
140      case B44A_COMPRESSION:
141
142	return new B44Compressor (hdr, maxScanLineSize, 32, true);
143
144      default:
145
146	return 0;
147    }
148}
149
150
151Compressor *
152newTileCompressor (Compression c,
153		   int tileLineSize,
154		   int numTileLines,
155		   const Header &hdr)
156{
157    switch (c)
158    {
159      case RLE_COMPRESSION:
160
161	return new RleCompressor (hdr, tileLineSize * numTileLines);
162
163      case ZIPS_COMPRESSION:
164      case ZIP_COMPRESSION:
165
166	return new ZipCompressor (hdr, tileLineSize, numTileLines);
167
168      case PIZ_COMPRESSION:
169
170	return new PizCompressor (hdr, tileLineSize, numTileLines);
171
172      case PXR24_COMPRESSION:
173
174	return new Pxr24Compressor (hdr, tileLineSize, numTileLines);
175
176      case B44_COMPRESSION:
177
178	return new B44Compressor (hdr, tileLineSize, numTileLines, false);
179
180      case B44A_COMPRESSION:
181
182	return new B44Compressor (hdr, tileLineSize, numTileLines, true);
183
184      default:
185
186	return 0;
187    }
188}
189
190
191} // namespace Imf
192