/src/opencv/3rdparty/openexr/IlmImf/ImfCompressor.h
Line | Count | Source |
1 | | /////////////////////////////////////////////////////////////////////////// |
2 | | // |
3 | | // Copyright (c) 2002, 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 | | #ifndef INCLUDED_IMF_COMPRESSOR_H |
38 | | #define INCLUDED_IMF_COMPRESSOR_H |
39 | | |
40 | | //----------------------------------------------------------------------------- |
41 | | // |
42 | | // class Compressor |
43 | | // |
44 | | //----------------------------------------------------------------------------- |
45 | | |
46 | | #include "ImfCompression.h" |
47 | | #include "ImathBox.h" |
48 | | #include "ImfNamespace.h" |
49 | | #include "ImfExport.h" |
50 | | #include "ImfForward.h" |
51 | | |
52 | | #include <stdlib.h> |
53 | | |
54 | | |
55 | | OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER |
56 | | |
57 | | |
58 | | class Compressor |
59 | | { |
60 | | public: |
61 | | |
62 | | //--------------------------------------------- |
63 | | // Constructor -- hdr is the header of the file |
64 | | // that will be compressed or uncompressed |
65 | | //--------------------------------------------- |
66 | | |
67 | | IMF_EXPORT |
68 | | Compressor (const Header &hdr); |
69 | | |
70 | | |
71 | | //----------- |
72 | | // Destructor |
73 | | //----------- |
74 | | |
75 | | IMF_EXPORT |
76 | | virtual ~Compressor (); |
77 | | |
78 | | |
79 | | //---------------------------------------------- |
80 | | // Maximum number of scan lines processed by |
81 | | // a single call to compress() and uncompress(). |
82 | | //---------------------------------------------- |
83 | | |
84 | | IMF_EXPORT |
85 | | virtual int numScanLines () const = 0; |
86 | | |
87 | | |
88 | | //-------------------------------------------- |
89 | | // Format of the pixel data read and written |
90 | | // by the compress() and uncompress() methods. |
91 | | // The default implementation of format() |
92 | | // returns XDR. |
93 | | //-------------------------------------------- |
94 | | |
95 | | enum Format |
96 | | { |
97 | | NATIVE, // the machine's native format |
98 | | XDR // Xdr format |
99 | | }; |
100 | | |
101 | | IMF_EXPORT |
102 | | virtual Format format () const; |
103 | | |
104 | | |
105 | | //---------------------------- |
106 | | // Access to the file's header |
107 | | //---------------------------- |
108 | | |
109 | 0 | const Header & header () const {return _header;} |
110 | | |
111 | | |
112 | | //------------------------------------------------------------------------- |
113 | | // Compress an array of bytes that represents the contents of up to |
114 | | // numScanLines() scan lines: |
115 | | // |
116 | | // inPtr Input buffer (uncompressed data). |
117 | | // |
118 | | // inSize Number of bytes in the input buffer |
119 | | // |
120 | | // minY Minimum y coordinate of the scan lines to |
121 | | // be compressed |
122 | | // |
123 | | // outPtr Pointer to output buffer |
124 | | // |
125 | | // return value Size of compressed data in output buffer |
126 | | // |
127 | | // Arrangement of uncompressed pixel data in the input buffer: |
128 | | // |
129 | | // Before calling |
130 | | // |
131 | | // compress (buf, size, minY, ...); |
132 | | // |
133 | | // the InputFile::writePixels() method gathers pixel data from the |
134 | | // frame buffer, fb, and places them in buffer buf, like this: |
135 | | // |
136 | | // char *endOfBuf = buf; |
137 | | // |
138 | | // for (int y = minY; |
139 | | // y <= min (minY + numScanLines() - 1, header().dataWindow().max.y); |
140 | | // ++y) |
141 | | // { |
142 | | // for (ChannelList::ConstIterator c = header().channels().begin(); |
143 | | // c != header().channels().end(); |
144 | | // ++c) |
145 | | // { |
146 | | // if (modp (y, c.channel().ySampling) != 0) |
147 | | // continue; |
148 | | // |
149 | | // for (int x = header().dataWindow().min.x; |
150 | | // x <= header().dataWindow().max.x; |
151 | | // ++x) |
152 | | // { |
153 | | // if (modp (x, c.channel().xSampling) != 0) |
154 | | // continue; |
155 | | // |
156 | | // Xdr::write<CharPtrIO> (endOfBuf, fb.pixel (c, x, y)); |
157 | | // } |
158 | | // } |
159 | | // } |
160 | | // |
161 | | // int size = endOfBuf - buf; |
162 | | // |
163 | | //------------------------------------------------------------------------- |
164 | | |
165 | | IMF_EXPORT |
166 | | virtual int compress (const char *inPtr, |
167 | | int inSize, |
168 | | int minY, |
169 | | const char *&outPtr) = 0; |
170 | | |
171 | | IMF_EXPORT |
172 | | virtual int compressTile (const char *inPtr, |
173 | | int inSize, |
174 | | IMATH_NAMESPACE::Box2i range, |
175 | | const char *&outPtr); |
176 | | |
177 | | //------------------------------------------------------------------------- |
178 | | // Uncompress an array of bytes that has been compressed by compress(): |
179 | | // |
180 | | // inPtr Input buffer (compressed data). |
181 | | // |
182 | | // inSize Number of bytes in the input buffer |
183 | | // |
184 | | // minY Minimum y coordinate of the scan lines to |
185 | | // be uncompressed |
186 | | // |
187 | | // outPtr Pointer to output buffer |
188 | | // |
189 | | // return value Size of uncompressed data in output buffer |
190 | | // |
191 | | //------------------------------------------------------------------------- |
192 | | |
193 | | IMF_EXPORT |
194 | | virtual int uncompress (const char *inPtr, |
195 | | int inSize, |
196 | | int minY, |
197 | | const char *&outPtr) = 0; |
198 | | |
199 | | IMF_EXPORT |
200 | | virtual int uncompressTile (const char *inPtr, |
201 | | int inSize, |
202 | | IMATH_NAMESPACE::Box2i range, |
203 | | const char *&outPtr); |
204 | | |
205 | | private: |
206 | | |
207 | | const Header & _header; |
208 | | }; |
209 | | |
210 | | |
211 | | //-------------------------------------- |
212 | | // Test if c is a valid compression type |
213 | | //-------------------------------------- |
214 | | |
215 | | IMF_EXPORT |
216 | | bool isValidCompression (Compression c); |
217 | | |
218 | | //-------------------------------------- |
219 | | // Test if c is valid for deep data |
220 | | //-------------------------------------- |
221 | | |
222 | | IMF_EXPORT |
223 | | bool isValidDeepCompression (Compression c); |
224 | | |
225 | | |
226 | | //----------------------------------------------------------------- |
227 | | // Construct a Compressor for compression type c: |
228 | | // |
229 | | // maxScanLineSize Maximum number of bytes per uncompressed |
230 | | // scan line. |
231 | | // |
232 | | // header Header of the input or output file whose |
233 | | // pixels will be compressed or uncompressed. |
234 | | // |
235 | | // return value A pointer to a new Compressor object (it |
236 | | // is the caller's responsibility to delete |
237 | | // the object), or 0 (if c is NO_COMPRESSION). |
238 | | // |
239 | | //----------------------------------------------------------------- |
240 | | |
241 | | IMF_EXPORT |
242 | | Compressor * newCompressor (Compression c, |
243 | | size_t maxScanLineSize, |
244 | | const Header &hdr); |
245 | | |
246 | | |
247 | | //----------------------------------------------------------------- |
248 | | // Construct a Compressor for compression type c for a tiled image: |
249 | | // |
250 | | // tileLineSize Maximum number of bytes per uncompressed |
251 | | // line in a tile. |
252 | | // |
253 | | // numTileLines Maximum number of lines in a tile. |
254 | | // |
255 | | // header Header of the input or output file whose |
256 | | // pixels will be compressed or uncompressed. |
257 | | // |
258 | | // return value A pointer to a new Compressor object (it |
259 | | // is the caller's responsibility to delete |
260 | | // the object), or 0 (if c is NO_COMPRESSION). |
261 | | // |
262 | | //----------------------------------------------------------------- |
263 | | |
264 | | IMF_EXPORT |
265 | | Compressor * newTileCompressor (Compression c, |
266 | | size_t tileLineSize, |
267 | | size_t numTileLines, |
268 | | const Header &hdr); |
269 | | |
270 | | |
271 | | OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT |
272 | | |
273 | | #endif |