Blame IlmImf/ImfMisc.h

Packit 0d464f
///////////////////////////////////////////////////////////////////////////
Packit 0d464f
//
Packit 0d464f
// Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
Packit 0d464f
// Digital Ltd. LLC
Packit 0d464f
// 
Packit 0d464f
// All rights reserved.
Packit 0d464f
// 
Packit 0d464f
// Redistribution and use in source and binary forms, with or without
Packit 0d464f
// modification, are permitted provided that the following conditions are
Packit 0d464f
// met:
Packit 0d464f
// *       Redistributions of source code must retain the above copyright
Packit 0d464f
// notice, this list of conditions and the following disclaimer.
Packit 0d464f
// *       Redistributions in binary form must reproduce the above
Packit 0d464f
// copyright notice, this list of conditions and the following disclaimer
Packit 0d464f
// in the documentation and/or other materials provided with the
Packit 0d464f
// distribution.
Packit 0d464f
// *       Neither the name of Industrial Light & Magic nor the names of
Packit 0d464f
// its contributors may be used to endorse or promote products derived
Packit 0d464f
// from this software without specific prior written permission. 
Packit 0d464f
// 
Packit 0d464f
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit 0d464f
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit 0d464f
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Packit 0d464f
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
Packit 0d464f
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Packit 0d464f
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Packit 0d464f
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Packit 0d464f
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Packit 0d464f
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Packit 0d464f
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit 0d464f
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 0d464f
//
Packit 0d464f
///////////////////////////////////////////////////////////////////////////
Packit 0d464f
Packit 0d464f
Packit 0d464f
Packit 0d464f
#ifndef INCLUDED_IMF_MISC_H
Packit 0d464f
#define INCLUDED_IMF_MISC_H
Packit 0d464f
Packit 0d464f
//-----------------------------------------------------------------------------
Packit 0d464f
//
Packit 0d464f
//	Miscellaneous helper functions for OpenEXR image file I/O
Packit 0d464f
//
Packit 0d464f
//-----------------------------------------------------------------------------
Packit 0d464f
Packit 0d464f
#include "ImfPixelType.h"
Packit 0d464f
#include "ImfCompressor.h"
Packit 0d464f
#include "ImfArray.h"
Packit 0d464f
#include "ImfNamespace.h"
Packit 0d464f
#include "ImfExport.h"
Packit 0d464f
#include "ImfForward.h"
Packit 0d464f
Packit 0d464f
#include <cstddef>
Packit 0d464f
#include <vector>
Packit 0d464f
Packit 0d464f
Packit 0d464f
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Packit 0d464f
Packit 0d464f
Packit 0d464f
//
Packit 0d464f
// Return the size of a single value of the indicated type,
Packit 0d464f
// in the machine's native format.
Packit 0d464f
//
Packit 0d464f
Packit 0d464f
IMF_EXPORT
Packit 0d464f
int	pixelTypeSize (PixelType type);
Packit 0d464f
Packit 0d464f
Packit 0d464f
//
Packit 0d464f
// Return the number of samples a channel with subsampling rate
Packit 0d464f
// s has in the interval [a, b].  For example, a channel with
Packit 0d464f
// subsampling rate 2 (and samples at 0, 2, 4, 6, 8, etc.) has
Packit 0d464f
// 2 samples in the interval [1, 5] and three samples in the
Packit 0d464f
// interval [2, 6].
Packit 0d464f
//
Packit 0d464f
Packit 0d464f
IMF_EXPORT
Packit 0d464f
int	numSamples (int s, int a, int b);
Packit 0d464f
Packit 0d464f
Packit 0d464f
//
Packit 0d464f
// Build a table that lists, for each scanline in a file's
Packit 0d464f
// data window, how many bytes are required to store all
Packit 0d464f
// pixels in all channels in that scanline (assuming that
Packit 0d464f
// the pixel data are tightly packed).
Packit 0d464f
//
Packit 0d464f
Packit 0d464f
IMF_EXPORT
Packit 0d464f
size_t	bytesPerLineTable (const Header &header,
Packit 0d464f
		           std::vector<size_t> &bytesPerLine);
Packit 0d464f
Packit 0d464f
Packit 0d464f
//
Packit 0d464f
// Get the sample count for pixel (x, y) using the array base
Packit 0d464f
// pointer, xStride and yStride.
Packit 0d464f
//
Packit 0d464f
Packit 0d464f
IMF_EXPORT
Packit 0d464f
int&
Packit 0d464f
sampleCount(char* base, int xStride, int yStride, int x, int y);
Packit 0d464f
Packit 0d464f
Packit 0d464f
IMF_EXPORT
Packit 0d464f
const int&
Packit 0d464f
sampleCount(const char* base, int xStride, int yStride, int x, int y);
Packit 0d464f
Packit 0d464f
//
Packit 0d464f
// Build a table that lists, for each scanline in a DEEP file's
Packit 0d464f
// data window, how many bytes are required to store all
Packit 0d464f
// pixels in all channels in scanlines ranged in [minY, maxY]
Packit 0d464f
// (assuming that the pixel data are tightly packed).
Packit 0d464f
//
Packit 0d464f
Packit 0d464f
IMF_EXPORT
Packit 0d464f
size_t bytesPerDeepLineTable (const Header &header,
Packit 0d464f
                              int minY, int maxY,
Packit 0d464f
                              const char* base,
Packit 0d464f
                              int xStride,
Packit 0d464f
                              int yStride,
Packit 0d464f
                              std::vector<size_t> &bytesPerLine);
Packit 0d464f
Packit 0d464f
Packit 0d464f
//
Packit 0d464f
// Build a table that lists, for each scanline in a DEEP file's
Packit 0d464f
// data window, how many bytes are required to store all
Packit 0d464f
// pixels in all channels in every scanline (assuming that
Packit 0d464f
// the pixel data are tightly packed).
Packit 0d464f
//
Packit 0d464f
Packit 0d464f
IMF_EXPORT
Packit 0d464f
size_t bytesPerDeepLineTable (const Header &header,
Packit 0d464f
                              char* base,
Packit 0d464f
                              int xStride,
Packit 0d464f
                              int yStride,
Packit 0d464f
                              std::vector<size_t> &bytesPerLine);
Packit 0d464f
Packit 0d464f
Packit 0d464f
//
Packit 0d464f
// For scanline-based files, pixels are read or written in
Packit 0d464f
// in multi-scanline blocks.  Internally, class OutputFile
Packit 0d464f
// and class ScanLineInputFile store a block of scan lines
Packit 0d464f
// in a "line buffer".  Function offsetInLineBufferTable()
Packit 0d464f
// builds a table that lists, scanlines within range
Packit 0d464f
// [scanline1, scanline2], the location of the pixel data
Packit 0d464f
// for the scanline relative to the beginning of the line buffer,
Packit 0d464f
// where scanline1 = 0 represents the first line in the DATA WINDOW.
Packit 0d464f
// The one without specifying the range will make scanline1 = 0
Packit 0d464f
// and scanline2 = bytesPerLine.size().
Packit 0d464f
//
Packit 0d464f
Packit 0d464f
IMF_EXPORT
Packit 0d464f
void    offsetInLineBufferTable (const std::vector<size_t> &bytesPerLine,
Packit 0d464f
                                 int scanline1, int scanline2,
Packit 0d464f
                                 int linesInLineBuffer,
Packit 0d464f
                                 std::vector<size_t> &offsetInLineBuffer);
Packit 0d464f
Packit 0d464f
IMF_EXPORT
Packit 0d464f
void	offsetInLineBufferTable (const std::vector<size_t> &bytesPerLine,
Packit 0d464f
				 int linesInLineBuffer,
Packit 0d464f
				 std::vector<size_t> &offsetInLineBuffer);
Packit 0d464f
Packit 0d464f
//
Packit 0d464f
// For a scanline-based file, compute the range of scanlines
Packit 0d464f
// that occupy the same line buffer as a given scanline, y.
Packit 0d464f
// (minY is the minimum y coordinate of the file's data window.)
Packit 0d464f
//
Packit 0d464f
Packit 0d464f
IMF_EXPORT int	lineBufferMinY (int y, int minY, int linesInLineBuffer);
Packit 0d464f
IMF_EXPORT int	lineBufferMaxY (int y, int minY, int linesInLineBuffer);
Packit 0d464f
Packit 0d464f
Packit 0d464f
//
Packit 0d464f
// Return a compressor's data format (Compressor::NATIVE or Compressor::XDR).
Packit 0d464f
// If compressor is 0, return Compressor::XDR.
Packit 0d464f
//
Packit 0d464f
Packit 0d464f
IMF_EXPORT
Packit 0d464f
Compressor::Format defaultFormat (Compressor *compressor);
Packit 0d464f
Packit 0d464f
Packit 0d464f
//
Packit 0d464f
// Return the number of scan lines a compressor wants to compress
Packit 0d464f
// or uncompress at once.  If compressor is 0, return 1.
Packit 0d464f
//
Packit 0d464f
Packit 0d464f
IMF_EXPORT
Packit 0d464f
int     numLinesInBuffer (Compressor *compressor);
Packit 0d464f
Packit 0d464f
Packit 0d464f
//
Packit 0d464f
// Copy a single channel of a horizontal row of pixels from an
Packit 0d464f
// input file's internal line buffer or tile buffer into a
Packit 0d464f
// frame buffer slice.  If necessary, perform on-the-fly data
Packit 0d464f
// type conversion.
Packit 0d464f
//
Packit 0d464f
//    readPtr		initially points to the beginning of the
Packit 0d464f
//			data in the line or tile buffer. readPtr
Packit 0d464f
//			is advanced as the pixel data are copied;
Packit 0d464f
//			when copyIntoFrameBuffer() returns,
Packit 0d464f
//			readPtr points just past the end of the
Packit 0d464f
//			copied data.
Packit 0d464f
//
Packit 0d464f
//    writePtr, endPtr	point to the lefmost and rightmost pixels
Packit 0d464f
//			in the frame buffer slice
Packit 0d464f
//
Packit 0d464f
//    xStride		the xStride for the frame buffer slice
Packit 0d464f
//
Packit 0d464f
//    format		indicates if the line or tile buffer is
Packit 0d464f
//			in NATIVE or XDR format.
Packit 0d464f
//
Packit 0d464f
//    typeInFrameBuffer the pixel data type of the frame buffer slice
Packit 0d464f
//
Packit 0d464f
//    typeInFile        the pixel data type in the input file's channel
Packit 0d464f
//
Packit 0d464f
Packit 0d464f
IMF_EXPORT
Packit 0d464f
void    copyIntoFrameBuffer (const char *&readPtr,
Packit 0d464f
			     char *writePtr,
Packit 0d464f
                             char *endPtr,
Packit 0d464f
			     size_t xStride,
Packit 0d464f
			     bool fill,
Packit 0d464f
                             double fillValue,
Packit 0d464f
			     Compressor::Format format,
Packit 0d464f
                             PixelType typeInFrameBuffer,
Packit 0d464f
                             PixelType typeInFile);
Packit 0d464f
Packit 0d464f
Packit 0d464f
//
Packit 0d464f
// Copy a single channel of a horizontal row of pixels from an
Packit 0d464f
// input file's internal line buffer or tile buffer into a
Packit 0d464f
// frame buffer slice.  If necessary, perform on-the-fly data
Packit 0d464f
// type conversion.
Packit 0d464f
//
Packit 0d464f
//    readPtr             initially points to the beginning of the
Packit 0d464f
//                        data in the line or tile buffer. readPtr
Packit 0d464f
//                        is advanced as the pixel data are copied;
Packit 0d464f
//                        when copyIntoFrameBuffer() returns,
Packit 0d464f
//                        readPtr points just past the end of the
Packit 0d464f
//                        copied data.
Packit 0d464f
//
Packit 0d464f
//    base                point to each pixel in the framebuffer
Packit 0d464f
//
Packit 0d464f
//    sampleCountBase,    provide the number of samples in each pixel
Packit 0d464f
//    sampleCountXStride,
Packit 0d464f
//    sampleCountYStride
Packit 0d464f
//
Packit 0d464f
//    y                   the scanline to copy. The coordinate is
Packit 0d464f
//                        relative to the datawindow.min.y.
Packit 0d464f
//
Packit 0d464f
//    minX, maxX          used to indicate which pixels in the scanline
Packit 0d464f
//                        will be copied.
Packit 0d464f
//
Packit 0d464f
//    xOffsetForSampleCount,    used to offset the sample count array
Packit 0d464f
//    yOffsetForSampleCount,    and the base array.
Packit 0d464f
//    xOffsetForData,
Packit 0d464f
//    yOffsetForData
Packit 0d464f
//
Packit 0d464f
//    xStride             the xStride for the frame buffer slice
Packit 0d464f
//
Packit 0d464f
//    format              indicates if the line or tile buffer is
Packit 0d464f
//                        in NATIVE or XDR format.
Packit 0d464f
//
Packit 0d464f
//    typeInFrameBuffer   the pixel data type of the frame buffer slice
Packit 0d464f
//
Packit 0d464f
//    typeInFile          the pixel data type in the input file's channel
Packit 0d464f
//
Packit 0d464f
Packit 0d464f
IMF_EXPORT
Packit 0d464f
void    copyIntoDeepFrameBuffer (const char *& readPtr,
Packit 0d464f
                                 char * base,
Packit 0d464f
                                 const char* sampleCountBase,
Packit 0d464f
                                 ptrdiff_t sampleCountXStride,
Packit 0d464f
                                 ptrdiff_t sampleCountYStride,
Packit 0d464f
                                 int y, int minX, int maxX,
Packit 0d464f
                                 int xOffsetForSampleCount,
Packit 0d464f
                                 int yOffsetForSampleCount,
Packit 0d464f
                                 int xOffsetForData,
Packit 0d464f
                                 int yOffsetForData,
Packit 0d464f
                                 ptrdiff_t xStride,
Packit 0d464f
                                 ptrdiff_t xPointerStride,
Packit 0d464f
                                 ptrdiff_t yPointerStride,
Packit 0d464f
                                 bool fill,
Packit 0d464f
                                 double fillValue,
Packit 0d464f
                                 Compressor::Format format,
Packit 0d464f
                                 PixelType typeInFrameBuffer,
Packit 0d464f
                                 PixelType typeInFile);
Packit 0d464f
Packit 0d464f
Packit 0d464f
//
Packit 0d464f
// Given a pointer into a an input file's line buffer or tile buffer,
Packit 0d464f
// skip over the data for xSize pixels of type typeInFile.
Packit 0d464f
// readPtr initially points to the beginning of the data to be skipped;
Packit 0d464f
// when skipChannel() returns, readPtr points just past the end of the
Packit 0d464f
// skipped data.
Packit 0d464f
//
Packit 0d464f
Packit 0d464f
IMF_EXPORT
Packit 0d464f
void    skipChannel (const char *&readPtr,
Packit 0d464f
		     PixelType typeInFile,
Packit 0d464f
		     size_t xSize);
Packit 0d464f
Packit 0d464f
//
Packit 0d464f
// Convert an array of pixel data from the machine's native
Packit 0d464f
// representation to XDR format.
Packit 0d464f
//
Packit 0d464f
//    toPtr, fromPtr	initially point to the beginning of the input
Packit 0d464f
//			and output pixel data arrays; when convertInPlace()
Packit 0d464f
//			returns, toPtr and fromPtr point just past the
Packit 0d464f
//			end of the input and output arrays.
Packit 0d464f
// 			If the native representation of the data has the
Packit 0d464f
//			same size as the XDR data, then the conversion
Packit 0d464f
//			can take in place, without an intermediate
Packit 0d464f
//			temporary buffer (toPtr and fromPtr can point
Packit 0d464f
//			to the same location).
Packit 0d464f
//
Packit 0d464f
//    type		the pixel data type
Packit 0d464f
//
Packit 0d464f
//    numPixels		number of pixels in the input and output arrays
Packit 0d464f
// 
Packit 0d464f
Packit 0d464f
IMF_EXPORT
Packit 0d464f
void    convertInPlace (char *&toPtr,
Packit 0d464f
			const char *&fromPtr,
Packit 0d464f
			PixelType type,
Packit 0d464f
                        size_t numPixels);
Packit 0d464f
Packit 0d464f
//
Packit 0d464f
// Copy a single channel of a horizontal row of pixels from a
Packit 0d464f
// a frame buffer into an output file's internal line buffer or
Packit 0d464f
// tile buffer.
Packit 0d464f
//
Packit 0d464f
//    writePtr		initially points to the beginning of the
Packit 0d464f
//			data in the line or tile buffer. writePtr
Packit 0d464f
//			is advanced as the pixel data are copied;
Packit 0d464f
//			when copyFromFrameBuffer() returns,
Packit 0d464f
//			writePtr points just past the end of the
Packit 0d464f
//			copied data.
Packit 0d464f
//
Packit 0d464f
//    readPtr, endPtr	point to the lefmost and rightmost pixels
Packit 0d464f
//			in the frame buffer slice
Packit 0d464f
//
Packit 0d464f
//    xStride		the xStride for the frame buffer slice
Packit 0d464f
//
Packit 0d464f
//    format		indicates if the line or tile buffer is
Packit 0d464f
//			in NATIVE or XDR format.
Packit 0d464f
//
Packit 0d464f
//    type              the pixel data type in the frame buffer
Packit 0d464f
//			and in the output file's channel (function
Packit 0d464f
//			copyFromFrameBuffer() doesn't do on-the-fly
Packit 0d464f
//			data type conversion)
Packit 0d464f
//
Packit 0d464f
Packit 0d464f
IMF_EXPORT
Packit 0d464f
void    copyFromFrameBuffer (char *&writePtr,
Packit 0d464f
			     const char *&readPtr,
Packit 0d464f
                             const char *endPtr,
Packit 0d464f
			     size_t xStride,
Packit 0d464f
                             Compressor::Format format,
Packit 0d464f
			     PixelType type);
Packit 0d464f
Packit 0d464f
//
Packit 0d464f
// Copy a single channel of a horizontal row of pixels from a
Packit 0d464f
// a frame buffer in a deep data file into an output file's
Packit 0d464f
// internal line buffer or tile buffer.
Packit 0d464f
//
Packit 0d464f
//    writePtr                  initially points to the beginning of the
Packit 0d464f
//                              data in the line or tile buffer. writePtr
Packit 0d464f
//                              is advanced as the pixel data are copied;
Packit 0d464f
//                              when copyFromDeepFrameBuffer() returns,
Packit 0d464f
//                              writePtr points just past the end of the
Packit 0d464f
//                              copied data.
Packit 0d464f
//
Packit 0d464f
//    base                      the start pointer of each pixel in this channel.
Packit 0d464f
//                              It points to the real data in FrameBuffer.
Packit 0d464f
//                              It is different for different channels.
Packit 0d464f
//                              dataWindowMinX and dataWindowMinY are involved in
Packit 0d464f
//                              locating for base.
Packit 0d464f
//
Packit 0d464f
//    sampleCountBase,          used to locate the position to get
Packit 0d464f
//    sampleCountXStride,       the number of samples for each pixel.
Packit 0d464f
//    sampleCountYStride        Used to determine how far we should
Packit 0d464f
//                              read based on the pointer provided by base.
Packit 0d464f
//
Packit 0d464f
//    y                         the scanline to copy. If we are dealing
Packit 0d464f
//                              with a tiled deep file, then probably a portion
Packit 0d464f
//                              of the scanline is copied.
Packit 0d464f
//
Packit 0d464f
//    xMin, xMax                used to indicate which pixels in the scanline
Packit 0d464f
//                              will be copied.
Packit 0d464f
//
Packit 0d464f
//    xOffsetForSampleCount,    used to offset the sample count array
Packit 0d464f
//    yOffsetForSampleCount,    and the base array.
Packit 0d464f
//    xOffsetForData,
Packit 0d464f
//    yOffsetForData
Packit 0d464f
//
Packit 0d464f
//    xStride                   the xStride for the frame buffer slice
Packit 0d464f
//
Packit 0d464f
//    format                    indicates if the line or tile buffer is
Packit 0d464f
//                              in NATIVE or XDR format.
Packit 0d464f
//
Packit 0d464f
//    type                      the pixel data type in the frame buffer
Packit 0d464f
//                              and in the output file's channel (function
Packit 0d464f
//                              copyFromFrameBuffer() doesn't do on-the-fly
Packit 0d464f
//                              data type conversion)
Packit 0d464f
//
Packit 0d464f
Packit 0d464f
IMF_EXPORT
Packit 0d464f
void    copyFromDeepFrameBuffer (char *& writePtr,
Packit 0d464f
                                 const char * base,
Packit 0d464f
                                 char* sampleCountBase,
Packit 0d464f
                                 ptrdiff_t sampleCountXStride,
Packit 0d464f
                                 ptrdiff_t sampleCountYStride,
Packit 0d464f
                                 int y, int xMin, int xMax,
Packit 0d464f
                                 int xOffsetForSampleCount,
Packit 0d464f
                                 int yOffsetForSampleCount,
Packit 0d464f
                                 int xOffsetForData,
Packit 0d464f
                                 int yOffsetForData,
Packit 0d464f
                                 ptrdiff_t sampleStride,
Packit 0d464f
                                 ptrdiff_t xStrideForData,
Packit 0d464f
                                 ptrdiff_t yStrideForData,
Packit 0d464f
                                 Compressor::Format format,
Packit 0d464f
                                 PixelType type);
Packit 0d464f
Packit 0d464f
//
Packit 0d464f
// Fill part of an output file's line buffer or tile buffer with
Packit 0d464f
// zeroes.  This routine is called when an output file contains
Packit 0d464f
// a channel for which the frame buffer contains no corresponding
Packit 0d464f
// slice.
Packit 0d464f
//
Packit 0d464f
//    writePtr		initially points to the beginning of the
Packit 0d464f
//			data in the line or tile buffer.  When
Packit 0d464f
//			fillChannelWithZeroes() returns, writePtr
Packit 0d464f
//			points just past the end of the zeroed
Packit 0d464f
//			data.
Packit 0d464f
//
Packit 0d464f
//    format		indicates if the line or tile buffer is
Packit 0d464f
//			in NATIVE or XDR format.
Packit 0d464f
//
Packit 0d464f
//    type              the pixel data type in the line or frame buffer.
Packit 0d464f
//
Packit 0d464f
//    xSize             number of pixels to be filled with zeroes.
Packit 0d464f
//
Packit 0d464f
Packit 0d464f
IMF_EXPORT
Packit 0d464f
void    fillChannelWithZeroes (char *&writePtr,
Packit 0d464f
			       Compressor::Format format,
Packit 0d464f
			       PixelType type,
Packit 0d464f
			       size_t xSize);
Packit 0d464f
Packit 0d464f
IMF_EXPORT
Packit 0d464f
bool usesLongNames (const Header &header);
Packit 0d464f
Packit 0d464f
Packit 0d464f
//
Packit 0d464f
// compute size of chunk offset table - if ignore_attribute set to true
Packit 0d464f
// will compute from the image size and layout, rather than the attribute
Packit 0d464f
// The default behaviour is to read the attribute
Packit 0d464f
//
Packit 0d464f
Packit 0d464f
IMF_EXPORT
Packit 0d464f
int getChunkOffsetTableSize(const Header& header,bool ignore_attribute=false);
Packit 0d464f
Packit 0d464f
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Packit 0d464f
Packit 0d464f
Packit 0d464f
#endif