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 #include "ImfDwaCompressor.h"
50 #include "ImfCheckedArithmetic.h"
51 #include "ImfNamespace.h"
52
53 OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER
54
55 using IMATH_NAMESPACE::Box2i;
56
57
Compressor(const Header & hdr)58 Compressor::Compressor (const Header &hdr): _header (hdr) {}
59
60
~Compressor()61 Compressor::~Compressor () {}
62
63
64 Compressor::Format
format() const65 Compressor::format () const
66 {
67 return XDR;
68 }
69
70
71 int
compressTile(const char * inPtr,int inSize,Box2i range,const char * & outPtr)72 Compressor::compressTile (const char *inPtr,
73 int inSize,
74 Box2i range,
75 const char *&outPtr)
76 {
77 return compress (inPtr, inSize, range.min.y, outPtr);
78 }
79
80
81 int
uncompressTile(const char * inPtr,int inSize,Box2i range,const char * & outPtr)82 Compressor::uncompressTile (const char *inPtr,
83 int inSize,
84 Box2i range,
85 const char *&outPtr)
86 {
87 return uncompress (inPtr, inSize, range.min.y, outPtr);
88 }
89
90
91 bool
isValidCompression(Compression c)92 isValidCompression (Compression c)
93 {
94 switch (c)
95 {
96 case NO_COMPRESSION:
97 case RLE_COMPRESSION:
98 case ZIPS_COMPRESSION:
99 case ZIP_COMPRESSION:
100 case PIZ_COMPRESSION:
101 case PXR24_COMPRESSION:
102 case B44_COMPRESSION:
103 case B44A_COMPRESSION:
104 case DWAA_COMPRESSION:
105 case DWAB_COMPRESSION:
106
107 return true;
108
109 default:
110
111 return false;
112 }
113 }
114
isValidDeepCompression(Compression c)115 bool isValidDeepCompression(Compression c)
116 {
117 switch(c)
118 {
119 case NO_COMPRESSION:
120 case RLE_COMPRESSION:
121 case ZIPS_COMPRESSION:
122 return true;
123 default :
124 return false;
125 }
126 }
127
128
129 Compressor *
newCompressor(Compression c,size_t maxScanLineSize,const Header & hdr)130 newCompressor (Compression c, size_t maxScanLineSize, const Header &hdr)
131 {
132 switch (c)
133 {
134 case RLE_COMPRESSION:
135
136 return new RleCompressor (hdr, maxScanLineSize);
137
138 case ZIPS_COMPRESSION:
139
140 return new ZipCompressor (hdr, maxScanLineSize, 1);
141
142 case ZIP_COMPRESSION:
143
144 return new ZipCompressor (hdr, maxScanLineSize, 16);
145
146 case PIZ_COMPRESSION:
147
148 return new PizCompressor (hdr, maxScanLineSize, 32);
149
150 case PXR24_COMPRESSION:
151
152 return new Pxr24Compressor (hdr, maxScanLineSize, 16);
153
154 case B44_COMPRESSION:
155
156 return new B44Compressor (hdr, maxScanLineSize, 32, false);
157
158 case B44A_COMPRESSION:
159
160 return new B44Compressor (hdr, maxScanLineSize, 32, true);
161
162 case DWAA_COMPRESSION:
163
164 return new DwaCompressor (hdr, maxScanLineSize, 32,
165 DwaCompressor::STATIC_HUFFMAN);
166
167 case DWAB_COMPRESSION:
168
169 return new DwaCompressor (hdr, maxScanLineSize, 256,
170 DwaCompressor::STATIC_HUFFMAN);
171
172 default:
173
174 return 0;
175 }
176 }
177
178
179 Compressor *
newTileCompressor(Compression c,size_t tileLineSize,size_t numTileLines,const Header & hdr)180 newTileCompressor (Compression c,
181 size_t tileLineSize,
182 size_t numTileLines,
183 const Header &hdr)
184 {
185 switch (c)
186 {
187 case RLE_COMPRESSION:
188
189 return new RleCompressor (hdr, uiMult (tileLineSize, numTileLines));
190
191 case ZIPS_COMPRESSION:
192 case ZIP_COMPRESSION:
193
194 return new ZipCompressor (hdr, tileLineSize, numTileLines);
195
196 case PIZ_COMPRESSION:
197
198 return new PizCompressor (hdr, tileLineSize, numTileLines);
199
200 case PXR24_COMPRESSION:
201
202 return new Pxr24Compressor (hdr, tileLineSize, numTileLines);
203
204 case B44_COMPRESSION:
205
206 return new B44Compressor (hdr, tileLineSize, numTileLines, false);
207
208 case B44A_COMPRESSION:
209
210 return new B44Compressor (hdr, tileLineSize, numTileLines, true);
211
212 case DWAA_COMPRESSION:
213 case DWAB_COMPRESSION:
214
215 return new DwaCompressor (hdr, tileLineSize, numTileLines,
216 DwaCompressor::DEFLATE);
217
218 default:
219
220 return 0;
221 }
222 }
223
224
225 OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT
226
227