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