1
///////////////////////////////////////////////////////////////////////////
3
// Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
6
// All rights reserved.
8
// Redistribution and use in source and binary forms, with or without
9
// modification, are permitted provided that the following conditions are
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
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.
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.
33
///////////////////////////////////////////////////////////////////////////
37
#ifndef INCLUDED_IMF_MISC_H
38
#define INCLUDED_IMF_MISC_H
40
//-----------------------------------------------------------------------------
42
// Miscellaneous helper functions for OpenEXR image file I/O
44
//-----------------------------------------------------------------------------
46
#include <ImfPixelType.h>
48
#include <ImfCompressor.h>
55
// Return the size of a single value of the indicated type,
56
// in the machine's native format.
59
int pixelTypeSize (PixelType type);
63
// Return the number of samples a channel with subsampling rate
64
// s has in the interval [a, b]. For example, a channel with
65
// subsampling rate 2 (and samples at 0, 2, 4, 6, 8, etc.) has
66
// 2 samples in the interval [1, 5] and three samples in the
70
int numSamples (int s, int a, int b);
74
// Build a table that lists, for each scanline in a file's
75
// data window, how many bytes are required to store all
76
// pixels in all channels in that scanline (assuming that
77
// the pixel data are tightly packed).
80
size_t bytesPerLineTable (const Header &header,
81
std::vector<size_t> &bytesPerLine);
84
// For scanline-based files, pixels are read or written in
85
// in multi-scanline blocks. Internally, class OutputFile
86
// and class ScanLineInputFile store a block of scan lines
87
// in a "line buffer". Function offsetInLineBufferTable()
88
// builds a table that lists, for each scan line in a file's
89
// data window, the location of the pixel data for the scanline
90
// relative to the beginning of the line buffer.
93
void offsetInLineBufferTable (const std::vector<size_t> &bytesPerLine,
94
int linesInLineBuffer,
95
std::vector<size_t> &offsetInLineBuffer);
98
// For a scanline-based file, compute the range of scanlines
99
// that occupy the same line buffer as a given scanline, y.
100
// (minY is the minimum y coordinate of the file's data window.)
103
int lineBufferMinY (int y, int minY, int linesInLineBuffer);
104
int lineBufferMaxY (int y, int minY, int linesInLineBuffer);
108
// Return a compressor's data format (Compressor::NATIVE or Compressor::XDR).
109
// If compressor is 0, return Compressor::XDR.
112
Compressor::Format defaultFormat (Compressor *compressor);
116
// Return the number of scan lines a compressor wants to compress
117
// or uncompress at once. If compressor is 0, return 1.
120
int numLinesInBuffer (Compressor *compressor);
124
// Copy a single channel of a horizontal row of pixels from an
125
// input file's internal line buffer or tile buffer into a
126
// frame buffer slice. If necessary, perform on-the-fly data
129
// readPtr initially points to the beginning of the
130
// data in the line or tile buffer. readPtr
131
// is advanced as the pixel data are copied;
132
// when copyIntoFrameBuffer() returns,
133
// readPtr points just past the end of the
136
// writePtr, endPtr point to the lefmost and rightmost pixels
137
// in the frame buffer slice
139
// xStride the xStride for the frame buffer slice
141
// format indicates if the line or tile buffer is
142
// in NATIVE or XDR format.
144
// typeInFrameBuffer the pixel data type of the frame buffer slice
146
// typeInFile the pixel data type in the input file's channel
149
void copyIntoFrameBuffer (const char *&readPtr,
155
Compressor::Format format,
156
PixelType typeInFrameBuffer,
157
PixelType typeInFile);
160
// Given a pointer into a an input file's line buffer or tile buffer,
161
// skip over the data for xSize pixels of type typeInFile.
162
// readPtr initially points to the beginning of the data to be skipped;
163
// when skipChannel() returns, readPtr points just past the end of the
167
void skipChannel (const char *&readPtr,
168
PixelType typeInFile,
172
// Convert an array of pixel data from the machine's native
173
// representation to XDR format.
175
// toPtr, fromPtr initially point to the beginning of the input
176
// and output pixel data arrays; when convertInPlace()
177
// returns, toPtr and fromPtr point just past the
178
// end of the input and output arrays.
179
// If the native representation of the data has the
180
// same size as the XDR data, then the conversion
181
// can take in place, without an intermediate
182
// temporary buffer (toPtr and fromPtr can point
183
// to the same location).
185
// type the pixel data type
187
// numPixels number of pixels in the input and output arrays
190
void convertInPlace (char *&toPtr,
191
const char *&fromPtr,
196
// Copy a single channel of a horizontal row of pixels from a
197
// a frame buffer into an output file's internal line buffer or
200
// writePtr initially points to the beginning of the
201
// data in the line or tile buffer. writePtr
202
// is advanced as the pixel data are copied;
203
// when copyFromFrameBuffer() returns,
204
// writePtr points just past the end of the
207
// readPtr, endPtr point to the lefmost and rightmost pixels
208
// in the frame buffer slice
210
// xStride the xStride for the frame buffer slice
212
// format indicates if the line or tile buffer is
213
// in NATIVE or XDR format.
215
// type the pixel data type in the frame buffer
216
// and in the output file's channel (function
217
// copyFromFrameBuffer() doesn't do on-the-fly
218
// data type conversion)
221
void copyFromFrameBuffer (char *&writePtr,
222
const char *&readPtr,
225
Compressor::Format format,
229
// Fill part of an output file's line buffer or tile buffer with
230
// zeroes. This routine is called when an output file contains
231
// a channel for which the frame buffer contains no corresponding
234
// writePtr initially points to the beginning of the
235
// data in the line or tile buffer. When
236
// fillChannelWithZeroes() returns, writePtr
237
// points just past the end of the zeroed
240
// format indicates if the line or tile buffer is
241
// in NATIVE or XDR format.
243
// type the pixel data type in the line or frame buffer.
245
// xSize number of pixels to be filled with zeroes.
248
void fillChannelWithZeroes (char *&writePtr,
249
Compressor::Format format,
1
///////////////////////////////////////////////////////////////////////////
3
// Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
6
// All rights reserved.
8
// Redistribution and use in source and binary forms, with or without
9
// modification, are permitted provided that the following conditions are
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
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.
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.
33
///////////////////////////////////////////////////////////////////////////
37
#ifndef INCLUDED_IMF_MISC_H
38
#define INCLUDED_IMF_MISC_H
40
//-----------------------------------------------------------------------------
42
// Miscellaneous helper functions for OpenEXR image file I/O
44
//-----------------------------------------------------------------------------
46
#include <ImfPixelType.h>
48
#include <ImfCompressor.h>
55
// Return the size of a single value of the indicated type,
56
// in the machine's native format.
59
int pixelTypeSize (PixelType type);
63
// Return the number of samples a channel with subsampling rate
64
// s has in the interval [a, b]. For example, a channel with
65
// subsampling rate 2 (and samples at 0, 2, 4, 6, 8, etc.) has
66
// 2 samples in the interval [1, 5] and three samples in the
70
int numSamples (int s, int a, int b);
74
// Build a table that lists, for each scanline in a file's
75
// data window, how many bytes are required to store all
76
// pixels in all channels in that scanline (assuming that
77
// the pixel data are tightly packed).
80
size_t bytesPerLineTable (const Header &header,
81
std::vector<size_t> &bytesPerLine);
84
// For scanline-based files, pixels are read or written in
85
// in multi-scanline blocks. Internally, class OutputFile
86
// and class ScanLineInputFile store a block of scan lines
87
// in a "line buffer". Function offsetInLineBufferTable()
88
// builds a table that lists, for each scan line in a file's
89
// data window, the location of the pixel data for the scanline
90
// relative to the beginning of the line buffer.
93
void offsetInLineBufferTable (const std::vector<size_t> &bytesPerLine,
94
int linesInLineBuffer,
95
std::vector<size_t> &offsetInLineBuffer);
98
// For a scanline-based file, compute the range of scanlines
99
// that occupy the same line buffer as a given scanline, y.
100
// (minY is the minimum y coordinate of the file's data window.)
103
int lineBufferMinY (int y, int minY, int linesInLineBuffer);
104
int lineBufferMaxY (int y, int minY, int linesInLineBuffer);
108
// Return a compressor's data format (Compressor::NATIVE or Compressor::XDR).
109
// If compressor is 0, return Compressor::XDR.
112
Compressor::Format defaultFormat (Compressor *compressor);
116
// Return the number of scan lines a compressor wants to compress
117
// or uncompress at once. If compressor is 0, return 1.
120
int numLinesInBuffer (Compressor *compressor);
124
// Copy a single channel of a horizontal row of pixels from an
125
// input file's internal line buffer or tile buffer into a
126
// frame buffer slice. If necessary, perform on-the-fly data
129
// readPtr initially points to the beginning of the
130
// data in the line or tile buffer. readPtr
131
// is advanced as the pixel data are copied;
132
// when copyIntoFrameBuffer() returns,
133
// readPtr points just past the end of the
136
// writePtr, endPtr point to the lefmost and rightmost pixels
137
// in the frame buffer slice
139
// xStride the xStride for the frame buffer slice
141
// format indicates if the line or tile buffer is
142
// in NATIVE or XDR format.
144
// typeInFrameBuffer the pixel data type of the frame buffer slice
146
// typeInFile the pixel data type in the input file's channel
149
void copyIntoFrameBuffer (const char *&readPtr,
155
Compressor::Format format,
156
PixelType typeInFrameBuffer,
157
PixelType typeInFile);
160
// Given a pointer into a an input file's line buffer or tile buffer,
161
// skip over the data for xSize pixels of type typeInFile.
162
// readPtr initially points to the beginning of the data to be skipped;
163
// when skipChannel() returns, readPtr points just past the end of the
167
void skipChannel (const char *&readPtr,
168
PixelType typeInFile,
172
// Convert an array of pixel data from the machine's native
173
// representation to XDR format.
175
// toPtr, fromPtr initially point to the beginning of the input
176
// and output pixel data arrays; when convertInPlace()
177
// returns, toPtr and fromPtr point just past the
178
// end of the input and output arrays.
179
// If the native representation of the data has the
180
// same size as the XDR data, then the conversion
181
// can take in place, without an intermediate
182
// temporary buffer (toPtr and fromPtr can point
183
// to the same location).
185
// type the pixel data type
187
// numPixels number of pixels in the input and output arrays
190
void convertInPlace (char *&toPtr,
191
const char *&fromPtr,
196
// Copy a single channel of a horizontal row of pixels from a
197
// a frame buffer into an output file's internal line buffer or
200
// writePtr initially points to the beginning of the
201
// data in the line or tile buffer. writePtr
202
// is advanced as the pixel data are copied;
203
// when copyFromFrameBuffer() returns,
204
// writePtr points just past the end of the
207
// readPtr, endPtr point to the lefmost and rightmost pixels
208
// in the frame buffer slice
210
// xStride the xStride for the frame buffer slice
212
// format indicates if the line or tile buffer is
213
// in NATIVE or XDR format.
215
// type the pixel data type in the frame buffer
216
// and in the output file's channel (function
217
// copyFromFrameBuffer() doesn't do on-the-fly
218
// data type conversion)
221
void copyFromFrameBuffer (char *&writePtr,
222
const char *&readPtr,
225
Compressor::Format format,
229
// Fill part of an output file's line buffer or tile buffer with
230
// zeroes. This routine is called when an output file contains
231
// a channel for which the frame buffer contains no corresponding
234
// writePtr initially points to the beginning of the
235
// data in the line or tile buffer. When
236
// fillChannelWithZeroes() returns, writePtr
237
// points just past the end of the zeroed
240
// format indicates if the line or tile buffer is
241
// in NATIVE or XDR format.
243
// type the pixel data type in the line or frame buffer.
245
// xSize number of pixels to be filled with zeroes.
248
void fillChannelWithZeroes (char *&writePtr,
249
Compressor::Format format,