PBRT
/home/felix/UBC/projects/AdaptiveLightfieldSampling/pbrt_v2/src/3rdparty/openexr-1.7.0/ImfMisc.h
00001 
00002 //
00003 // Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
00004 // Digital Ltd. LLC
00005 // 
00006 // All rights reserved.
00007 // 
00008 // Redistribution and use in source and binary forms, with or without
00009 // modification, are permitted provided that the following conditions are
00010 // met:
00011 // *       Redistributions of source code must retain the above copyright
00012 // notice, this list of conditions and the following disclaimer.
00013 // *       Redistributions in binary form must reproduce the above
00014 // copyright notice, this list of conditions and the following disclaimer
00015 // in the documentation and/or other materials provided with the
00016 // distribution.
00017 // *       Neither the name of Industrial Light & Magic nor the names of
00018 // its contributors may be used to endorse or promote products derived
00019 // from this software without specific prior written permission. 
00020 // 
00021 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00024 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00025 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00026 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00027 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00028 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00029 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00030 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00031 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032 //
00034 
00035 
00036 
00037 #ifndef INCLUDED_IMF_MISC_H
00038 #define INCLUDED_IMF_MISC_H
00039 
00040 //-----------------------------------------------------------------------------
00041 //
00042 //      Miscellaneous helper functions for OpenEXR image file I/O
00043 //
00044 //-----------------------------------------------------------------------------
00045 
00046 #include <ImfPixelType.h>
00047 #include <vector>
00048 #include <ImfCompressor.h>
00049 
00050 namespace Imf {
00051 
00052 class Header;
00053 
00054 //
00055 // Return the size of a single value of the indicated type,
00056 // in the machine's native format.
00057 //
00058 
00059 int     pixelTypeSize (PixelType type);
00060 
00061 
00062 //
00063 // Return the number of samples a channel with subsampling rate
00064 // s has in the interval [a, b].  For example, a channel with
00065 // subsampling rate 2 (and samples at 0, 2, 4, 6, 8, etc.) has
00066 // 2 samples in the interval [1, 5] and three samples in the
00067 // interval [2, 6].
00068 //
00069 
00070 int     numSamples (int s, int a, int b);
00071 
00072 
00073 //
00074 // Build a table that lists, for each scanline in a file's
00075 // data window, how many bytes are required to store all
00076 // pixels in all channels in that scanline (assuming that
00077 // the pixel data are tightly packed).
00078 //
00079 
00080 size_t  bytesPerLineTable (const Header &header,
00081                            std::vector<size_t> &bytesPerLine);
00082 
00083 //
00084 // For scanline-based files, pixels are read or written in
00085 // in multi-scanline blocks.  Internally, class OutputFile
00086 // and class ScanLineInputFile store a block of scan lines
00087 // in a "line buffer".  Function offsetInLineBufferTable()
00088 // builds a table that lists, for each scan line in a file's
00089 // data window, the location of the pixel data for the scanline
00090 // relative to the beginning of the line buffer.
00091 //
00092 
00093 void    offsetInLineBufferTable (const std::vector<size_t> &bytesPerLine,
00094                                  int linesInLineBuffer,
00095                                  std::vector<size_t> &offsetInLineBuffer);
00096 
00097 //
00098 // For a scanline-based file, compute the range of scanlines
00099 // that occupy the same line buffer as a given scanline, y.
00100 // (minY is the minimum y coordinate of the file's data window.)
00101 //
00102 
00103 int     lineBufferMinY (int y, int minY, int linesInLineBuffer);
00104 int     lineBufferMaxY (int y, int minY, int linesInLineBuffer);
00105 
00106 
00107 //
00108 // Return a compressor's data format (Compressor::NATIVE or Compressor::XDR).
00109 // If compressor is 0, return Compressor::XDR.
00110 //
00111 
00112 Compressor::Format defaultFormat (Compressor *compressor);
00113 
00114 
00115 //
00116 // Return the number of scan lines a compressor wants to compress
00117 // or uncompress at once.  If compressor is 0, return 1.
00118 //
00119 
00120 int     numLinesInBuffer (Compressor *compressor);
00121 
00122 
00123 //
00124 // Copy a single channel of a horizontal row of pixels from an
00125 // input file's internal line buffer or tile buffer into a
00126 // frame buffer slice.  If necessary, perform on-the-fly data
00127 // type conversion.
00128 //
00129 //    readPtr           initially points to the beginning of the
00130 //                      data in the line or tile buffer. readPtr
00131 //                      is advanced as the pixel data are copied;
00132 //                      when copyIntoFrameBuffer() returns,
00133 //                      readPtr points just past the end of the
00134 //                      copied data.
00135 //
00136 //    writePtr, endPtr  point to the lefmost and rightmost pixels
00137 //                      in the frame buffer slice
00138 //
00139 //    xStride           the xStride for the frame buffer slice
00140 //
00141 //    format            indicates if the line or tile buffer is
00142 //                      in NATIVE or XDR format.
00143 //
00144 //    typeInFrameBuffer the pixel data type of the frame buffer slice
00145 //
00146 //    typeInFile        the pixel data type in the input file's channel
00147 //
00148 
00149 void    copyIntoFrameBuffer (const char *&readPtr,
00150                              char *writePtr,
00151                              char *endPtr,
00152                              size_t xStride,
00153                              bool fill,
00154                              double fillValue,
00155                              Compressor::Format format,
00156                              PixelType typeInFrameBuffer,
00157                              PixelType typeInFile);
00158 
00159 //
00160 // Given a pointer into a an input file's line buffer or tile buffer,
00161 // skip over the data for xSize pixels of type typeInFile.
00162 // readPtr initially points to the beginning of the data to be skipped;
00163 // when skipChannel() returns, readPtr points just past the end of the
00164 // skipped data.
00165 //
00166 
00167 void    skipChannel (const char *&readPtr,
00168                      PixelType typeInFile,
00169                      size_t xSize);
00170 
00171 //
00172 // Convert an array of pixel data from the machine's native
00173 // representation to XDR format.
00174 //
00175 //    toPtr, fromPtr    initially point to the beginning of the input
00176 //                      and output pixel data arrays; when convertInPlace()
00177 //                      returns, toPtr and fromPtr point just past the
00178 //                      end of the input and output arrays.
00179 //                      If the native representation of the data has the
00180 //                      same size as the XDR data, then the conversion
00181 //                      can take in place, without an intermediate
00182 //                      temporary buffer (toPtr and fromPtr can point
00183 //                      to the same location).
00184 //
00185 //    type              the pixel data type
00186 //
00187 //    numPixels         number of pixels in the input and output arrays
00188 // 
00189 
00190 void    convertInPlace (char *&toPtr,
00191                         const char *&fromPtr,
00192                         PixelType type,
00193                         size_t numPixels);
00194 
00195 //
00196 // Copy a single channel of a horizontal row of pixels from a
00197 // a frame buffer into an output file's internal line buffer or
00198 // tile buffer.
00199 //
00200 //    writePtr          initially points to the beginning of the
00201 //                      data in the line or tile buffer. writePtr
00202 //                      is advanced as the pixel data are copied;
00203 //                      when copyFromFrameBuffer() returns,
00204 //                      writePtr points just past the end of the
00205 //                      copied data.
00206 //
00207 //    readPtr, endPtr   point to the lefmost and rightmost pixels
00208 //                      in the frame buffer slice
00209 //
00210 //    xStride           the xStride for the frame buffer slice
00211 //
00212 //    format            indicates if the line or tile buffer is
00213 //                      in NATIVE or XDR format.
00214 //
00215 //    type              the pixel data type in the frame buffer
00216 //                      and in the output file's channel (function
00217 //                      copyFromFrameBuffer() doesn't do on-the-fly
00218 //                      data type conversion)
00219 //
00220 
00221 void    copyFromFrameBuffer (char *&writePtr,
00222                              const char *&readPtr,
00223                              const char *endPtr,
00224                              size_t xStride,
00225                              Compressor::Format format,
00226                              PixelType type);
00227 
00228 //
00229 // Fill part of an output file's line buffer or tile buffer with
00230 // zeroes.  This routine is called when an output file contains
00231 // a channel for which the frame buffer contains no corresponding
00232 // slice.
00233 //
00234 //    writePtr          initially points to the beginning of the
00235 //                      data in the line or tile buffer.  When
00236 //                      fillChannelWithZeroes() returns, writePtr
00237 //                      points just past the end of the zeroed
00238 //                      data.
00239 //
00240 //    format            indicates if the line or tile buffer is
00241 //                      in NATIVE or XDR format.
00242 //
00243 //    type              the pixel data type in the line or frame buffer.
00244 //
00245 //    xSize             number of pixels to be filled with zeroes.
00246 //
00247 
00248 void    fillChannelWithZeroes (char *&writePtr,
00249                                Compressor::Format format,
00250                                PixelType type,
00251                                size_t xSize);
00252 
00253 } // namespace Imf
00254 
00255 #endif