Home | History | Annotate | Download | only in IlmImf
      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 <vector>
     48 #include <ImfCompressor.h>
     49 
     50 namespace Imf {
     51 
     52 class Header;
     53 
     54 //
     55 // Return the size of a single value of the indicated type,
     56 // in the machine's native format.
     57 //
     58 
     59 int	pixelTypeSize (PixelType type);
     60 
     61 
     62 //
     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
     67 // interval [2, 6].
     68 //
     69 
     70 int	numSamples (int s, int a, int b);
     71 
     72 
     73 //
     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).
     78 //
     79 
     80 size_t	bytesPerLineTable (const Header &header,
     81                    std::vector<size_t> &bytesPerLine);
     82 
     83 //
     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.
     91 //
     92 
     93 void	offsetInLineBufferTable (const std::vector<size_t> &bytesPerLine,
     94                  int linesInLineBuffer,
     95                  std::vector<size_t> &offsetInLineBuffer);
     96 
     97 //
     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.)
    101 //
    102 
    103 int	lineBufferMinY (int y, int minY, int linesInLineBuffer);
    104 int	lineBufferMaxY (int y, int minY, int linesInLineBuffer);
    105 
    106 
    107 //
    108 // Return a compressor's data format (Compressor::NATIVE or Compressor::XDR).
    109 // If compressor is 0, return Compressor::XDR.
    110 //
    111 
    112 Compressor::Format defaultFormat (Compressor *compressor);
    113 
    114 
    115 //
    116 // Return the number of scan lines a compressor wants to compress
    117 // or uncompress at once.  If compressor is 0, return 1.
    118 //
    119 
    120 int     numLinesInBuffer (Compressor *compressor);
    121 
    122 
    123 //
    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
    127 // type conversion.
    128 //
    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
    134 //			copied data.
    135 //
    136 //    writePtr, endPtr	point to the lefmost and rightmost pixels
    137 //			in the frame buffer slice
    138 //
    139 //    xStride		the xStride for the frame buffer slice
    140 //
    141 //    format		indicates if the line or tile buffer is
    142 //			in NATIVE or XDR format.
    143 //
    144 //    typeInFrameBuffer the pixel data type of the frame buffer slice
    145 //
    146 //    typeInFile        the pixel data type in the input file's channel
    147 //
    148 
    149 void    copyIntoFrameBuffer (const char *&readPtr,
    150                  char *writePtr,
    151                              char *endPtr,
    152                  size_t xStride,
    153                  bool fill,
    154                              double fillValue,
    155                  Compressor::Format format,
    156                              PixelType typeInFrameBuffer,
    157                              PixelType typeInFile);
    158 
    159 //
    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
    164 // skipped data.
    165 //
    166 
    167 void    skipChannel (const char *&readPtr,
    168              PixelType typeInFile,
    169              size_t xSize);
    170 
    171 //
    172 // Convert an array of pixel data from the machine's native
    173 // representation to XDR format.
    174 //
    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).
    184 //
    185 //    type		the pixel data type
    186 //
    187 //    numPixels		number of pixels in the input and output arrays
    188 //
    189 
    190 void    convertInPlace (char *&toPtr,
    191             const char *&fromPtr,
    192             PixelType type,
    193                         size_t numPixels);
    194 
    195 //
    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
    198 // tile buffer.
    199 //
    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
    205 //			copied data.
    206 //
    207 //    readPtr, endPtr	point to the lefmost and rightmost pixels
    208 //			in the frame buffer slice
    209 //
    210 //    xStride		the xStride for the frame buffer slice
    211 //
    212 //    format		indicates if the line or tile buffer is
    213 //			in NATIVE or XDR format.
    214 //
    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)
    219 //
    220 
    221 void    copyFromFrameBuffer (char *&writePtr,
    222                  const char *&readPtr,
    223                              const char *endPtr,
    224                  size_t xStride,
    225                              Compressor::Format format,
    226                  PixelType type);
    227 
    228 //
    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
    232 // slice.
    233 //
    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
    238 //			data.
    239 //
    240 //    format		indicates if the line or tile buffer is
    241 //			in NATIVE or XDR format.
    242 //
    243 //    type              the pixel data type in the line or frame buffer.
    244 //
    245 //    xSize             number of pixels to be filled with zeroes.
    246 //
    247 
    248 void    fillChannelWithZeroes (char *&writePtr,
    249                    Compressor::Format format,
    250                    PixelType type,
    251                    size_t xSize);
    252 
    253 } // namespace Imf
    254 
    255 #endif
    256