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 <ImfCheckedArithmetic.h>
50
51 namespace Imf {
52
53 using Imath::Box2i;
54
55
Compressor(const Header & hdr)56 Compressor::Compressor (const Header &hdr): _header (hdr) {}
57
58
~Compressor()59 Compressor::~Compressor () {}
60
61
62 Compressor::Format
format() const63 Compressor::format () const
64 {
65 return XDR;
66 }
67
68
69 int
compressTile(const char * inPtr,int inSize,Box2i range,const char * & outPtr)70 Compressor::compressTile (const char *inPtr,
71 int inSize,
72 Box2i range,
73 const char *&outPtr)
74 {
75 return compress (inPtr, inSize, range.min.y, outPtr);
76 }
77
78
79 int
uncompressTile(const char * inPtr,int inSize,Box2i range,const char * & outPtr)80 Compressor::uncompressTile (const char *inPtr,
81 int inSize,
82 Box2i range,
83 const char *&outPtr)
84 {
85 return uncompress (inPtr, inSize, range.min.y, outPtr);
86 }
87
88
89 bool
isValidCompression(Compression c)90 isValidCompression (Compression c)
91 {
92 switch (c)
93 {
94 case NO_COMPRESSION:
95 case RLE_COMPRESSION:
96 case ZIPS_COMPRESSION:
97 case ZIP_COMPRESSION:
98 case PIZ_COMPRESSION:
99 case PXR24_COMPRESSION:
100 case B44_COMPRESSION:
101 case B44A_COMPRESSION:
102
103 return true;
104
105 default:
106
107 return false;
108 }
109 }
110
111
112 Compressor *
newCompressor(Compression c,size_t maxScanLineSize,const Header & hdr)113 newCompressor (Compression c, size_t maxScanLineSize, const Header &hdr)
114 {
115 switch (c)
116 {
117 case RLE_COMPRESSION:
118
119 return new RleCompressor (hdr, maxScanLineSize);
120
121 case ZIPS_COMPRESSION:
122
123 return new ZipCompressor (hdr, maxScanLineSize, 1);
124
125 case ZIP_COMPRESSION:
126
127 return new ZipCompressor (hdr, maxScanLineSize, 16);
128
129 case PIZ_COMPRESSION:
130
131 return new PizCompressor (hdr, maxScanLineSize, 32);
132
133 case PXR24_COMPRESSION:
134
135 return new Pxr24Compressor (hdr, maxScanLineSize, 16);
136
137 case B44_COMPRESSION:
138
139 return new B44Compressor (hdr, maxScanLineSize, 32, false);
140
141 case B44A_COMPRESSION:
142
143 return new B44Compressor (hdr, maxScanLineSize, 32, true);
144
145 default:
146
147 return 0;
148 }
149 }
150
151
152 Compressor *
newTileCompressor(Compression c,size_t tileLineSize,size_t numTileLines,const Header & hdr)153 newTileCompressor (Compression c,
154 size_t tileLineSize,
155 size_t numTileLines,
156 const Header &hdr)
157 {
158 switch (c)
159 {
160 case RLE_COMPRESSION:
161
162 return new RleCompressor (hdr, uiMult (tileLineSize, numTileLines));
163
164 case ZIPS_COMPRESSION:
165 case ZIP_COMPRESSION:
166
167 return new ZipCompressor (hdr, tileLineSize, numTileLines);
168
169 case PIZ_COMPRESSION:
170
171 return new PizCompressor (hdr, tileLineSize, numTileLines);
172
173 case PXR24_COMPRESSION:
174
175 return new Pxr24Compressor (hdr, tileLineSize, numTileLines);
176
177 case B44_COMPRESSION:
178
179 return new B44Compressor (hdr, tileLineSize, numTileLines, false);
180
181 case B44A_COMPRESSION:
182
183 return new B44Compressor (hdr, tileLineSize, numTileLines, true);
184
185 default:
186
187 return 0;
188 }
189 }
190
191
192 } // namespace Imf
193