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