/src/opencv/3rdparty/openexr/IlmImf/ImfMisc.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_MISC_H |
38 | | #define INCLUDED_IMF_MISC_H |
39 | | |
40 | | //----------------------------------------------------------------------------- |
41 | | // |
42 | | // Miscellaneous helper functions for OpenEXR image file I/O |
43 | | // |
44 | | //----------------------------------------------------------------------------- |
45 | | |
46 | | #include "ImfPixelType.h" |
47 | | #include "ImfCompressor.h" |
48 | | #include "ImfArray.h" |
49 | | #include "ImfNamespace.h" |
50 | | #include "ImfExport.h" |
51 | | #include "ImfForward.h" |
52 | | |
53 | | #include <cstddef> |
54 | | #include <vector> |
55 | | |
56 | | |
57 | | OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER |
58 | | |
59 | | |
60 | | // |
61 | | // Return the size of a single value of the indicated type, |
62 | | // in the machine's native format. |
63 | | // |
64 | | |
65 | | IMF_EXPORT |
66 | | int pixelTypeSize (PixelType type); |
67 | | |
68 | | |
69 | | // |
70 | | // Return the number of samples a channel with subsampling rate |
71 | | // s has in the interval [a, b]. For example, a channel with |
72 | | // subsampling rate 2 (and samples at 0, 2, 4, 6, 8, etc.) has |
73 | | // 2 samples in the interval [1, 5] and three samples in the |
74 | | // interval [2, 6]. |
75 | | // |
76 | | |
77 | | IMF_EXPORT |
78 | | int numSamples (int s, int a, int b); |
79 | | |
80 | | |
81 | | // |
82 | | // Build a table that lists, for each scanline in a file's |
83 | | // data window, how many bytes are required to store all |
84 | | // pixels in all channels in that scanline (assuming that |
85 | | // the pixel data are tightly packed). |
86 | | // |
87 | | |
88 | | IMF_EXPORT |
89 | | size_t bytesPerLineTable (const Header &header, |
90 | | std::vector<size_t> &bytesPerLine); |
91 | | |
92 | | |
93 | | // |
94 | | // Get the sample count for pixel (x, y) using the array base |
95 | | // pointer, xStride and yStride. |
96 | | // |
97 | | |
98 | | inline |
99 | | int& |
100 | | sampleCount(char* base, int xStride, int yStride, int x, int y) |
101 | 0 | { |
102 | 0 | char* ptr = base + y * yStride + x * xStride; |
103 | 0 | int* intPtr = (int*) ptr; |
104 | |
|
105 | 0 | return *intPtr; |
106 | 0 | } |
107 | | |
108 | | |
109 | | inline |
110 | | const int& |
111 | | sampleCount(const char* base, int xStride, int yStride, int x, int y) |
112 | 0 | { |
113 | 0 | const char* ptr = base + y * yStride + x * xStride; |
114 | 0 | int* intPtr = (int*) ptr; |
115 | | |
116 | 0 | return *intPtr; |
117 | 0 | } |
118 | | |
119 | | // |
120 | | // Build a table that lists, for each scanline in a DEEP file's |
121 | | // data window, how many bytes are required to store all |
122 | | // pixels in all channels in scanlines ranged in [minY, maxY] |
123 | | // (assuming that the pixel data are tightly packed). |
124 | | // |
125 | | |
126 | | IMF_EXPORT |
127 | | size_t bytesPerDeepLineTable (const Header &header, |
128 | | int minY, int maxY, |
129 | | const char* base, |
130 | | int xStride, |
131 | | int yStride, |
132 | | std::vector<size_t> &bytesPerLine); |
133 | | |
134 | | |
135 | | // |
136 | | // Build a table that lists, for each scanline in a DEEP file's |
137 | | // data window, how many bytes are required to store all |
138 | | // pixels in all channels in every scanline (assuming that |
139 | | // the pixel data are tightly packed). |
140 | | // |
141 | | |
142 | | IMF_EXPORT |
143 | | size_t bytesPerDeepLineTable (const Header &header, |
144 | | char* base, |
145 | | int xStride, |
146 | | int yStride, |
147 | | std::vector<size_t> &bytesPerLine); |
148 | | |
149 | | |
150 | | // |
151 | | // For scanline-based files, pixels are read or written in |
152 | | // in multi-scanline blocks. Internally, class OutputFile |
153 | | // and class ScanLineInputFile store a block of scan lines |
154 | | // in a "line buffer". Function offsetInLineBufferTable() |
155 | | // builds a table that lists, scanlines within range |
156 | | // [scanline1, scanline2], the location of the pixel data |
157 | | // for the scanline relative to the beginning of the line buffer, |
158 | | // where scanline1 = 0 represents the first line in the DATA WINDOW. |
159 | | // The one without specifying the range will make scanline1 = 0 |
160 | | // and scanline2 = bytesPerLine.size(). |
161 | | // |
162 | | |
163 | | IMF_EXPORT |
164 | | void offsetInLineBufferTable (const std::vector<size_t> &bytesPerLine, |
165 | | int scanline1, int scanline2, |
166 | | int linesInLineBuffer, |
167 | | std::vector<size_t> &offsetInLineBuffer); |
168 | | |
169 | | IMF_EXPORT |
170 | | void offsetInLineBufferTable (const std::vector<size_t> &bytesPerLine, |
171 | | int linesInLineBuffer, |
172 | | std::vector<size_t> &offsetInLineBuffer); |
173 | | |
174 | | // |
175 | | // For a scanline-based file, compute the range of scanlines |
176 | | // that occupy the same line buffer as a given scanline, y. |
177 | | // (minY is the minimum y coordinate of the file's data window.) |
178 | | // |
179 | | |
180 | | IMF_EXPORT int lineBufferMinY (int y, int minY, int linesInLineBuffer); |
181 | | IMF_EXPORT int lineBufferMaxY (int y, int minY, int linesInLineBuffer); |
182 | | |
183 | | |
184 | | // |
185 | | // Return a compressor's data format (Compressor::NATIVE or Compressor::XDR). |
186 | | // If compressor is 0, return Compressor::XDR. |
187 | | // |
188 | | |
189 | | IMF_EXPORT |
190 | | Compressor::Format defaultFormat (Compressor *compressor); |
191 | | |
192 | | |
193 | | // |
194 | | // Return the number of scan lines a compressor wants to compress |
195 | | // or uncompress at once. If compressor is 0, return 1. |
196 | | // |
197 | | |
198 | | IMF_EXPORT |
199 | | int numLinesInBuffer (Compressor *compressor); |
200 | | |
201 | | |
202 | | // |
203 | | // Copy a single channel of a horizontal row of pixels from an |
204 | | // input file's internal line buffer or tile buffer into a |
205 | | // frame buffer slice. If necessary, perform on-the-fly data |
206 | | // type conversion. |
207 | | // |
208 | | // readPtr initially points to the beginning of the |
209 | | // data in the line or tile buffer. readPtr |
210 | | // is advanced as the pixel data are copied; |
211 | | // when copyIntoFrameBuffer() returns, |
212 | | // readPtr points just past the end of the |
213 | | // copied data. |
214 | | // |
215 | | // writePtr, endPtr point to the lefmost and rightmost pixels |
216 | | // in the frame buffer slice |
217 | | // |
218 | | // xStride the xStride for the frame buffer slice |
219 | | // |
220 | | // format indicates if the line or tile buffer is |
221 | | // in NATIVE or XDR format. |
222 | | // |
223 | | // typeInFrameBuffer the pixel data type of the frame buffer slice |
224 | | // |
225 | | // typeInFile the pixel data type in the input file's channel |
226 | | // |
227 | | |
228 | | IMF_EXPORT |
229 | | void copyIntoFrameBuffer (const char *&readPtr, |
230 | | char *writePtr, |
231 | | char *endPtr, |
232 | | size_t xStride, |
233 | | bool fill, |
234 | | double fillValue, |
235 | | Compressor::Format format, |
236 | | PixelType typeInFrameBuffer, |
237 | | PixelType typeInFile); |
238 | | |
239 | | |
240 | | // |
241 | | // Copy a single channel of a horizontal row of pixels from an |
242 | | // input file's internal line buffer or tile buffer into a |
243 | | // frame buffer slice. If necessary, perform on-the-fly data |
244 | | // type conversion. |
245 | | // |
246 | | // readPtr initially points to the beginning of the |
247 | | // data in the line or tile buffer. readPtr |
248 | | // is advanced as the pixel data are copied; |
249 | | // when copyIntoFrameBuffer() returns, |
250 | | // readPtr points just past the end of the |
251 | | // copied data. |
252 | | // |
253 | | // base point to each pixel in the framebuffer |
254 | | // |
255 | | // sampleCountBase, provide the number of samples in each pixel |
256 | | // sampleCountXStride, |
257 | | // sampleCountYStride |
258 | | // |
259 | | // y the scanline to copy. The coordinate is |
260 | | // relative to the datawindow.min.y. |
261 | | // |
262 | | // minX, maxX used to indicate which pixels in the scanline |
263 | | // will be copied. |
264 | | // |
265 | | // xOffsetForSampleCount, used to offset the sample count array |
266 | | // yOffsetForSampleCount, and the base array. |
267 | | // xOffsetForData, |
268 | | // yOffsetForData |
269 | | // |
270 | | // xStride the xStride for the frame buffer slice |
271 | | // |
272 | | // format indicates if the line or tile buffer is |
273 | | // in NATIVE or XDR format. |
274 | | // |
275 | | // typeInFrameBuffer the pixel data type of the frame buffer slice |
276 | | // |
277 | | // typeInFile the pixel data type in the input file's channel |
278 | | // |
279 | | |
280 | | IMF_EXPORT |
281 | | void copyIntoDeepFrameBuffer (const char *& readPtr, |
282 | | char * base, |
283 | | const char* sampleCountBase, |
284 | | ptrdiff_t sampleCountXStride, |
285 | | ptrdiff_t sampleCountYStride, |
286 | | int y, int minX, int maxX, |
287 | | int xOffsetForSampleCount, |
288 | | int yOffsetForSampleCount, |
289 | | int xOffsetForData, |
290 | | int yOffsetForData, |
291 | | ptrdiff_t xStride, |
292 | | ptrdiff_t xPointerStride, |
293 | | ptrdiff_t yPointerStride, |
294 | | bool fill, |
295 | | double fillValue, |
296 | | Compressor::Format format, |
297 | | PixelType typeInFrameBuffer, |
298 | | PixelType typeInFile); |
299 | | |
300 | | |
301 | | // |
302 | | // Given a pointer into a an input file's line buffer or tile buffer, |
303 | | // skip over the data for xSize pixels of type typeInFile. |
304 | | // readPtr initially points to the beginning of the data to be skipped; |
305 | | // when skipChannel() returns, readPtr points just past the end of the |
306 | | // skipped data. |
307 | | // |
308 | | |
309 | | IMF_EXPORT |
310 | | void skipChannel (const char *&readPtr, |
311 | | PixelType typeInFile, |
312 | | size_t xSize); |
313 | | |
314 | | // |
315 | | // Convert an array of pixel data from the machine's native |
316 | | // representation to XDR format. |
317 | | // |
318 | | // toPtr, fromPtr initially point to the beginning of the input |
319 | | // and output pixel data arrays; when convertInPlace() |
320 | | // returns, toPtr and fromPtr point just past the |
321 | | // end of the input and output arrays. |
322 | | // If the native representation of the data has the |
323 | | // same size as the XDR data, then the conversion |
324 | | // can take in place, without an intermediate |
325 | | // temporary buffer (toPtr and fromPtr can point |
326 | | // to the same location). |
327 | | // |
328 | | // type the pixel data type |
329 | | // |
330 | | // numPixels number of pixels in the input and output arrays |
331 | | // |
332 | | |
333 | | IMF_EXPORT |
334 | | void convertInPlace (char *&toPtr, |
335 | | const char *&fromPtr, |
336 | | PixelType type, |
337 | | size_t numPixels); |
338 | | |
339 | | // |
340 | | // Copy a single channel of a horizontal row of pixels from a |
341 | | // a frame buffer into an output file's internal line buffer or |
342 | | // tile buffer. |
343 | | // |
344 | | // writePtr initially points to the beginning of the |
345 | | // data in the line or tile buffer. writePtr |
346 | | // is advanced as the pixel data are copied; |
347 | | // when copyFromFrameBuffer() returns, |
348 | | // writePtr points just past the end of the |
349 | | // copied data. |
350 | | // |
351 | | // readPtr, endPtr point to the lefmost and rightmost pixels |
352 | | // in the frame buffer slice |
353 | | // |
354 | | // xStride the xStride for the frame buffer slice |
355 | | // |
356 | | // format indicates if the line or tile buffer is |
357 | | // in NATIVE or XDR format. |
358 | | // |
359 | | // type the pixel data type in the frame buffer |
360 | | // and in the output file's channel (function |
361 | | // copyFromFrameBuffer() doesn't do on-the-fly |
362 | | // data type conversion) |
363 | | // |
364 | | |
365 | | IMF_EXPORT |
366 | | void copyFromFrameBuffer (char *&writePtr, |
367 | | const char *&readPtr, |
368 | | const char *endPtr, |
369 | | size_t xStride, |
370 | | Compressor::Format format, |
371 | | PixelType type); |
372 | | |
373 | | // |
374 | | // Copy a single channel of a horizontal row of pixels from a |
375 | | // a frame buffer in a deep data file into an output file's |
376 | | // internal line buffer or tile buffer. |
377 | | // |
378 | | // writePtr initially points to the beginning of the |
379 | | // data in the line or tile buffer. writePtr |
380 | | // is advanced as the pixel data are copied; |
381 | | // when copyFromDeepFrameBuffer() returns, |
382 | | // writePtr points just past the end of the |
383 | | // copied data. |
384 | | // |
385 | | // base the start pointer of each pixel in this channel. |
386 | | // It points to the real data in FrameBuffer. |
387 | | // It is different for different channels. |
388 | | // dataWindowMinX and dataWindowMinY are involved in |
389 | | // locating for base. |
390 | | // |
391 | | // sampleCountBase, used to locate the position to get |
392 | | // sampleCountXStride, the number of samples for each pixel. |
393 | | // sampleCountYStride Used to determine how far we should |
394 | | // read based on the pointer provided by base. |
395 | | // |
396 | | // y the scanline to copy. If we are dealing |
397 | | // with a tiled deep file, then probably a portion |
398 | | // of the scanline is copied. |
399 | | // |
400 | | // xMin, xMax used to indicate which pixels in the scanline |
401 | | // will be copied. |
402 | | // |
403 | | // xOffsetForSampleCount, used to offset the sample count array |
404 | | // yOffsetForSampleCount, and the base array. |
405 | | // xOffsetForData, |
406 | | // yOffsetForData |
407 | | // |
408 | | // xStride the xStride for the frame buffer slice |
409 | | // |
410 | | // format indicates if the line or tile buffer is |
411 | | // in NATIVE or XDR format. |
412 | | // |
413 | | // type the pixel data type in the frame buffer |
414 | | // and in the output file's channel (function |
415 | | // copyFromFrameBuffer() doesn't do on-the-fly |
416 | | // data type conversion) |
417 | | // |
418 | | |
419 | | IMF_EXPORT |
420 | | void copyFromDeepFrameBuffer (char *& writePtr, |
421 | | const char * base, |
422 | | char* sampleCountBase, |
423 | | ptrdiff_t sampleCountXStride, |
424 | | ptrdiff_t sampleCountYStride, |
425 | | int y, int xMin, int xMax, |
426 | | int xOffsetForSampleCount, |
427 | | int yOffsetForSampleCount, |
428 | | int xOffsetForData, |
429 | | int yOffsetForData, |
430 | | ptrdiff_t sampleStride, |
431 | | ptrdiff_t xStrideForData, |
432 | | ptrdiff_t yStrideForData, |
433 | | Compressor::Format format, |
434 | | PixelType type); |
435 | | |
436 | | // |
437 | | // Fill part of an output file's line buffer or tile buffer with |
438 | | // zeroes. This routine is called when an output file contains |
439 | | // a channel for which the frame buffer contains no corresponding |
440 | | // slice. |
441 | | // |
442 | | // writePtr initially points to the beginning of the |
443 | | // data in the line or tile buffer. When |
444 | | // fillChannelWithZeroes() returns, writePtr |
445 | | // points just past the end of the zeroed |
446 | | // data. |
447 | | // |
448 | | // format indicates if the line or tile buffer is |
449 | | // in NATIVE or XDR format. |
450 | | // |
451 | | // type the pixel data type in the line or frame buffer. |
452 | | // |
453 | | // xSize number of pixels to be filled with zeroes. |
454 | | // |
455 | | |
456 | | IMF_EXPORT |
457 | | void fillChannelWithZeroes (char *&writePtr, |
458 | | Compressor::Format format, |
459 | | PixelType type, |
460 | | size_t xSize); |
461 | | |
462 | | IMF_EXPORT |
463 | | bool usesLongNames (const Header &header); |
464 | | |
465 | | |
466 | | // |
467 | | // compute size of chunk offset table - if ignore_attribute set to true |
468 | | // will compute from the image size and layout, rather than the attribute |
469 | | // The default behaviour is to read the attribute |
470 | | // |
471 | | |
472 | | IMF_EXPORT |
473 | | int getChunkOffsetTableSize(const Header& header,bool ignore_attribute=false); |
474 | | |
475 | | OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT |
476 | | |
477 | | |
478 | | #endif |