Blame IlmImf/ImfDeepTiledInputFile.h

Packit 0d464f
///////////////////////////////////////////////////////////////////////////
Packit 0d464f
//
Packit 0d464f
// Copyright (c) 2011, 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
#ifndef INCLUDED_IMF_DEEP_TILED_INPUT_FILE_H
Packit 0d464f
#define INCLUDED_IMF_DEEP_TILED_INPUT_FILE_H
Packit 0d464f
Packit 0d464f
//-----------------------------------------------------------------------------
Packit 0d464f
//
Packit 0d464f
//      class DeepTiledInputFile
Packit 0d464f
//
Packit 0d464f
//-----------------------------------------------------------------------------
Packit 0d464f
Packit 0d464f
#include "ImfHeader.h"
Packit 0d464f
#include "ImfFrameBuffer.h"
Packit 0d464f
#include "ImathBox.h"
Packit 0d464f
#include "ImfTileDescription.h"
Packit 0d464f
#include "ImfThreading.h"
Packit 0d464f
#include "ImfGenericInputFile.h"
Packit 0d464f
#include "ImfDeepFrameBuffer.h"
Packit 0d464f
#include "ImfDeepTiledOutputFile.h"
Packit 0d464f
#include "ImfForward.h"
Packit 0d464f
#include "ImfNamespace.h"
Packit 0d464f
#include "ImfExport.h"
Packit 0d464f
Packit 0d464f
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Packit 0d464f
Packit 0d464f
class IMF_EXPORT DeepTiledInputFile : public GenericInputFile
Packit 0d464f
{
Packit 0d464f
  public:
Packit 0d464f
Packit 0d464f
    //--------------------------------------------------------------------
Packit 0d464f
    // A constructor that opens the file with the specified name, and
Packit 0d464f
    // reads the file header.  The constructor throws an IEX_NAMESPACE::ArgExc
Packit 0d464f
    // exception if the file is not tiled.
Packit 0d464f
    // The numThreads parameter specifies how many worker threads this
Packit 0d464f
    // file will try to keep busy when decompressing individual tiles.
Packit 0d464f
    // Destroying TiledInputFile objects constructed with this constructor
Packit 0d464f
    // automatically closes the corresponding files.
Packit 0d464f
    //--------------------------------------------------------------------
Packit 0d464f
Packit 0d464f
    DeepTiledInputFile (const char fileName[],
Packit 0d464f
                    int numThreads = globalThreadCount ());
Packit 0d464f
Packit 0d464f
Packit 0d464f
    // ----------------------------------------------------------
Packit 0d464f
    // A constructor that attaches the new TiledInputFile object
Packit 0d464f
    // to a file that has already been opened.
Packit 0d464f
    // Destroying TiledInputFile objects constructed with this
Packit 0d464f
    // constructor does not automatically close the corresponding
Packit 0d464f
    // files.
Packit 0d464f
    // ----------------------------------------------------------
Packit 0d464f
Packit 0d464f
    DeepTiledInputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is, int numThreads = globalThreadCount ());
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //-----------
Packit 0d464f
    // Destructor
Packit 0d464f
    //-----------
Packit 0d464f
Packit 0d464f
    virtual ~DeepTiledInputFile ();
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //------------------------
Packit 0d464f
    // Access to the file name
Packit 0d464f
    //------------------------
Packit 0d464f
Packit 0d464f
    const char *        fileName () const;
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //--------------------------
Packit 0d464f
    // Access to the file header
Packit 0d464f
    //--------------------------
Packit 0d464f
Packit 0d464f
    const Header &      header () const;
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //----------------------------------
Packit 0d464f
    // Access to the file format version
Packit 0d464f
    //----------------------------------
Packit 0d464f
Packit 0d464f
    int                 version () const;
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //-----------------------------------------------------------
Packit 0d464f
    // Set the current frame buffer -- copies the FrameBuffer
Packit 0d464f
    // object into the TiledInputFile object.
Packit 0d464f
    //
Packit 0d464f
    // The current frame buffer is the destination for the pixel
Packit 0d464f
    // data read from the file.  The current frame buffer must be
Packit 0d464f
    // set at least once before readTile() is called.
Packit 0d464f
    // The current frame buffer can be changed after each call
Packit 0d464f
    // to readTile().
Packit 0d464f
    //-----------------------------------------------------------
Packit 0d464f
Packit 0d464f
    void                setFrameBuffer (const DeepFrameBuffer &frameBuffer);
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //-----------------------------------
Packit 0d464f
    // Access to the current frame buffer
Packit 0d464f
    //-----------------------------------
Packit 0d464f
Packit 0d464f
    const DeepFrameBuffer & frameBuffer () const;
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //------------------------------------------------------------
Packit 0d464f
    // Check if the file is complete:
Packit 0d464f
    //
Packit 0d464f
    // isComplete() returns true if all pixels in the data window
Packit 0d464f
    // (in all levels) are present in the input file, or false if
Packit 0d464f
    // any pixels are missing.  (Another program may still be busy
Packit 0d464f
    // writing the file, or file writing may have been aborted
Packit 0d464f
    // prematurely.)
Packit 0d464f
    //------------------------------------------------------------
Packit 0d464f
Packit 0d464f
    bool                isComplete () const;
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //--------------------------------------------------
Packit 0d464f
    // Utility functions:
Packit 0d464f
    //--------------------------------------------------
Packit 0d464f
Packit 0d464f
    //---------------------------------------------------------
Packit 0d464f
    // Multiresolution mode and tile size:
Packit 0d464f
    // The following functions return the xSize, ySize and mode
Packit 0d464f
    // fields of the file header's TileDescriptionAttribute.
Packit 0d464f
    //---------------------------------------------------------
Packit 0d464f
Packit 0d464f
    unsigned int        tileXSize () const;
Packit 0d464f
    unsigned int        tileYSize () const;
Packit 0d464f
    LevelMode           levelMode () const;
Packit 0d464f
    LevelRoundingMode   levelRoundingMode () const;
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //--------------------------------------------------------------------
Packit 0d464f
    // Number of levels:
Packit 0d464f
    //
Packit 0d464f
    // numXLevels() returns the file's number of levels in x direction.
Packit 0d464f
    //
Packit 0d464f
    //  if levelMode() == ONE_LEVEL:
Packit 0d464f
    //      return value is: 1
Packit 0d464f
    //
Packit 0d464f
    //  if levelMode() == MIPMAP_LEVELS:
Packit 0d464f
    //      return value is: rfunc (log (max (w, h)) / log (2)) + 1
Packit 0d464f
    //
Packit 0d464f
    //  if levelMode() == RIPMAP_LEVELS:
Packit 0d464f
    //      return value is: rfunc (log (w) / log (2)) + 1
Packit 0d464f
    //
Packit 0d464f
    //  where
Packit 0d464f
    //      w is the width of the image's data window,  max.x - min.x + 1,
Packit 0d464f
    //      y is the height of the image's data window, max.y - min.y + 1,
Packit 0d464f
    //      and rfunc(x) is either floor(x), or ceil(x), depending on
Packit 0d464f
    //      whether levelRoundingMode() returns ROUND_DOWN or ROUND_UP.
Packit 0d464f
    //
Packit 0d464f
    // numYLevels() returns the file's number of levels in y direction.
Packit 0d464f
    //
Packit 0d464f
    //  if levelMode() == ONE_LEVEL or levelMode() == MIPMAP_LEVELS:
Packit 0d464f
    //      return value is the same as for numXLevels()
Packit 0d464f
    //
Packit 0d464f
    //  if levelMode() == RIPMAP_LEVELS:
Packit 0d464f
    //      return value is: rfunc (log (h) / log (2)) + 1
Packit 0d464f
    //
Packit 0d464f
    //
Packit 0d464f
    // numLevels() is a convenience function for use with
Packit 0d464f
    // MIPMAP_LEVELS files.
Packit 0d464f
    //
Packit 0d464f
    //  if levelMode() == ONE_LEVEL or levelMode() == MIPMAP_LEVELS:
Packit 0d464f
    //      return value is the same as for numXLevels()
Packit 0d464f
    //
Packit 0d464f
    //  if levelMode() == RIPMAP_LEVELS:
Packit 0d464f
    //      an IEX_NAMESPACE::LogicExc exception is thrown
Packit 0d464f
    //
Packit 0d464f
    // isValidLevel(lx, ly) returns true if the file contains
Packit 0d464f
    // a level with level number (lx, ly), false if not.
Packit 0d464f
    //
Packit 0d464f
    // totalTiles() returns the total number of tiles in the image
Packit 0d464f
    //
Packit 0d464f
    //--------------------------------------------------------------------
Packit 0d464f
Packit 0d464f
    int                 numLevels () const;
Packit 0d464f
    int                 numXLevels () const;
Packit 0d464f
    int                 numYLevels () const;
Packit 0d464f
    bool                isValidLevel (int lx, int ly) const;
Packit 0d464f
    size_t              totalTiles() const;
Packit 0d464f
Packit 0d464f
    //----------------------------------------------------------
Packit 0d464f
    // Dimensions of a level:
Packit 0d464f
    //
Packit 0d464f
    // levelWidth(lx) returns the width of a level with level
Packit 0d464f
    // number (lx, *), where * is any number.
Packit 0d464f
    //
Packit 0d464f
    //  return value is:
Packit 0d464f
    //      max (1, rfunc (w / pow (2, lx)))
Packit 0d464f
    //
Packit 0d464f
    //
Packit 0d464f
    // levelHeight(ly) returns the height of a level with level
Packit 0d464f
    // number (*, ly), where * is any number.
Packit 0d464f
    //
Packit 0d464f
    //  return value is:
Packit 0d464f
    //      max (1, rfunc (h / pow (2, ly)))
Packit 0d464f
    //
Packit 0d464f
    //----------------------------------------------------------
Packit 0d464f
Packit 0d464f
    int                 levelWidth  (int lx) const;
Packit 0d464f
    int                 levelHeight (int ly) const;
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //--------------------------------------------------------------
Packit 0d464f
    // Number of tiles:
Packit 0d464f
    //
Packit 0d464f
    // numXTiles(lx) returns the number of tiles in x direction
Packit 0d464f
    // that cover a level with level number (lx, *), where * is
Packit 0d464f
    // any number.
Packit 0d464f
    //
Packit 0d464f
    //  return value is:
Packit 0d464f
    //      (levelWidth(lx) + tileXSize() - 1) / tileXSize()
Packit 0d464f
    //
Packit 0d464f
    //
Packit 0d464f
    // numYTiles(ly) returns the number of tiles in y direction
Packit 0d464f
    // that cover a level with level number (*, ly), where * is
Packit 0d464f
    // any number.
Packit 0d464f
    //
Packit 0d464f
    //  return value is:
Packit 0d464f
    //      (levelHeight(ly) + tileXSize() - 1) / tileXSize()
Packit 0d464f
    //
Packit 0d464f
    //--------------------------------------------------------------
Packit 0d464f
Packit 0d464f
    int                 numXTiles (int lx = 0) const;
Packit 0d464f
    int                 numYTiles (int ly = 0) const;
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //---------------------------------------------------------------
Packit 0d464f
    // Level pixel ranges:
Packit 0d464f
    //
Packit 0d464f
    // dataWindowForLevel(lx, ly) returns a 2-dimensional region of
Packit 0d464f
    // valid pixel coordinates for a level with level number (lx, ly)
Packit 0d464f
    //
Packit 0d464f
    //  return value is a Box2i with min value:
Packit 0d464f
    //      (dataWindow.min.x, dataWindow.min.y)
Packit 0d464f
    //
Packit 0d464f
    //  and max value:
Packit 0d464f
    //      (dataWindow.min.x + levelWidth(lx) - 1,
Packit 0d464f
    //       dataWindow.min.y + levelHeight(ly) - 1)
Packit 0d464f
    //
Packit 0d464f
    // dataWindowForLevel(level) is a convenience function used
Packit 0d464f
    // for ONE_LEVEL and MIPMAP_LEVELS files.  It returns
Packit 0d464f
    // dataWindowForLevel(level, level).
Packit 0d464f
    //
Packit 0d464f
    //---------------------------------------------------------------
Packit 0d464f
Packit 0d464f
    IMATH_NAMESPACE::Box2i        dataWindowForLevel (int l = 0) const;
Packit 0d464f
    IMATH_NAMESPACE::Box2i        dataWindowForLevel (int lx, int ly) const;
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //-------------------------------------------------------------------
Packit 0d464f
    // Tile pixel ranges:
Packit 0d464f
    //
Packit 0d464f
    // dataWindowForTile(dx, dy, lx, ly) returns a 2-dimensional
Packit 0d464f
    // region of valid pixel coordinates for a tile with tile coordinates
Packit 0d464f
    // (dx,dy) and level number (lx, ly).
Packit 0d464f
    //
Packit 0d464f
    //  return value is a Box2i with min value:
Packit 0d464f
    //      (dataWindow.min.x + dx * tileXSize(),
Packit 0d464f
    //       dataWindow.min.y + dy * tileYSize())
Packit 0d464f
    //
Packit 0d464f
    //  and max value:
Packit 0d464f
    //      (dataWindow.min.x + (dx + 1) * tileXSize() - 1,
Packit 0d464f
    //       dataWindow.min.y + (dy + 1) * tileYSize() - 1)
Packit 0d464f
    //
Packit 0d464f
    // dataWindowForTile(dx, dy, level) is a convenience function
Packit 0d464f
    // used for ONE_LEVEL and MIPMAP_LEVELS files.  It returns
Packit 0d464f
    // dataWindowForTile(dx, dy, level, level).
Packit 0d464f
    //
Packit 0d464f
    //-------------------------------------------------------------------
Packit 0d464f
Packit 0d464f
    IMATH_NAMESPACE::Box2i        dataWindowForTile (int dx, int dy, int l = 0) const;
Packit 0d464f
Packit 0d464f
    IMATH_NAMESPACE::Box2i        dataWindowForTile (int dx, int dy,
Packit 0d464f
                                           int lx, int ly) const;
Packit 0d464f
Packit 0d464f
    //------------------------------------------------------------
Packit 0d464f
    // Read pixel data:
Packit 0d464f
    //
Packit 0d464f
    // readTile(dx, dy, lx, ly) reads the tile with tile
Packit 0d464f
    // coordinates (dx, dy), and level number (lx, ly),
Packit 0d464f
    // and stores it in the current frame buffer.
Packit 0d464f
    //
Packit 0d464f
    //   dx must lie in the interval [0, numXTiles(lx)-1]
Packit 0d464f
    //   dy must lie in the interval [0, numYTiles(ly)-1]
Packit 0d464f
    //
Packit 0d464f
    //   lx must lie in the interval [0, numXLevels()-1]
Packit 0d464f
    //   ly must lie in the inverval [0, numYLevels()-1]
Packit 0d464f
    //
Packit 0d464f
    // readTile(dx, dy, level) is a convenience function used
Packit 0d464f
    // for ONE_LEVEL and MIPMAP_LEVELS files.  It calls
Packit 0d464f
    // readTile(dx, dy, level, level).
Packit 0d464f
    //
Packit 0d464f
    // The two readTiles(dx1, dx2, dy1, dy2, ...) functions allow
Packit 0d464f
    // reading multiple tiles at once.  If multi-threading is used
Packit 0d464f
    // the multiple tiles are read concurrently.
Packit 0d464f
    //
Packit 0d464f
    // Pixels that are outside the pixel coordinate range for the
Packit 0d464f
    // tile's level, are never accessed by readTile().
Packit 0d464f
    //
Packit 0d464f
    // Attempting to access a tile that is not present in the file
Packit 0d464f
    // throws an InputExc exception.
Packit 0d464f
    //
Packit 0d464f
    //------------------------------------------------------------
Packit 0d464f
Packit 0d464f
    void                readTile  (int dx, int dy, int l = 0);
Packit 0d464f
    void                readTile  (int dx, int dy, int lx, int ly);
Packit 0d464f
Packit 0d464f
    void                readTiles (int dx1, int dx2, int dy1, int dy2,
Packit 0d464f
                                   int lx, int ly);
Packit 0d464f
Packit 0d464f
    void                readTiles (int dx1, int dx2, int dy1, int dy2,
Packit 0d464f
                                   int l = 0);
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //--------------------------------------------------
Packit 0d464f
    // Read a tile of raw pixel data from the file,
Packit 0d464f
    // without uncompressing it (this function is
Packit 0d464f
    // used to implement TiledOutputFile::copyPixels()).
Packit 0d464f
    //--------------------------------------------------
Packit 0d464f
Packit 0d464f
    void                rawTileData (int &dx, int &dy,
Packit 0d464f
                                     int &lx, int &ly,
Packit 0d464f
                                     char *pixelData,
Packit 0d464f
                                     Int64 &dataSize) const;
Packit 0d464f
Packit 0d464f
    //------------------------------------------------------------------
Packit 0d464f
    // Read pixel sample counts into a slice in the frame buffer.
Packit 0d464f
    //
Packit 0d464f
    // readPixelSampleCount(dx, dy, lx, ly) reads the sample counts
Packit 0d464f
    // for tile (dx, dy) in level (lx, ly).
Packit 0d464f
    //
Packit 0d464f
    // readPixelSampleCount(dx, dy, l) calls
Packit 0d464f
    // readPixelSampleCount(dx, dy, lx = l, ly = l)
Packit 0d464f
    //
Packit 0d464f
    // dx must lie in the interval [0, numXTiles(lx)-1]
Packit 0d464f
    // dy must lie in the interval [0, numYTiles(ly)-1]
Packit 0d464f
    //
Packit 0d464f
    // lx must lie in the interval [0, numXLevels()-1]
Packit 0d464f
    // ly must lie in the inverval [0, numYLevels()-1]
Packit 0d464f
    //
Packit 0d464f
    // readPixelSampleCounts(dx1, dx2, dy1, dy2, lx, ly) reads all
Packit 0d464f
    // the sample counts for tiles within range
Packit 0d464f
    // [(min(dx1, dx2), min(dy1, dy2))...(max(dx1, dx2), max(dy1, dy2)],
Packit 0d464f
    // and on level (lx, ly)
Packit 0d464f
    //
Packit 0d464f
    // readPixelSampleCounts(dx1, dx2, dy1, dy2, l) calls
Packit 0d464f
    // readPixelSampleCounts(dx1, dx2, dy1, dy2, lx = l, ly = l).
Packit 0d464f
    //------------------------------------------------------------------
Packit 0d464f
Packit 0d464f
    void                readPixelSampleCount  (int dx, int dy, int l = 0);
Packit 0d464f
    void                readPixelSampleCount  (int dx, int dy, int lx, int ly);
Packit 0d464f
Packit 0d464f
    void                readPixelSampleCounts (int dx1, int dx2,
Packit 0d464f
                                              int dy1, int dy2,
Packit 0d464f
                                              int lx, int ly);
Packit 0d464f
Packit 0d464f
    void                readPixelSampleCounts (int dx1, int dx2,
Packit 0d464f
                                              int dy1, int dy2,
Packit 0d464f
                                              int l = 0);
Packit 0d464f
Packit 0d464f
    struct Data;
Packit 0d464f
Packit 0d464f
    
Packit 0d464f
    
Packit 0d464f
  private:
Packit 0d464f
Packit 0d464f
    friend class InputFile;
Packit 0d464f
    friend class MultiPartInputFile;
Packit 0d464f
Packit 0d464f
    DeepTiledInputFile (InputPartData* part);
Packit 0d464f
Packit 0d464f
    DeepTiledInputFile (const DeepTiledInputFile &);              // not implemented
Packit 0d464f
    DeepTiledInputFile & operator = (const DeepTiledInputFile &); // not implemented
Packit 0d464f
Packit 0d464f
    DeepTiledInputFile (const Header &header, OPENEXR_IMF_INTERNAL_NAMESPACE::IStream *is, int version,
Packit 0d464f
                    int numThreads);
Packit 0d464f
Packit 0d464f
    void                initialize ();
Packit 0d464f
    void                multiPartInitialize(InputPartData* part);
Packit 0d464f
    void                compatibilityInitialize(OPENEXR_IMF_INTERNAL_NAMESPACE::IStream& is);
Packit 0d464f
Packit 0d464f
    bool                isValidTile (int dx, int dy,
Packit 0d464f
                                     int lx, int ly) const;
Packit 0d464f
Packit 0d464f
    size_t              bytesPerLineForTile (int dx, int dy,
Packit 0d464f
                                             int lx, int ly) const;
Packit 0d464f
           
Packit 0d464f
                                                
Packit 0d464f
    void                getTileOrder(int dx[],int dy[],int lx[],int ly[]) const;
Packit 0d464f
                                             
Packit 0d464f
    
Packit 0d464f
    Data *              _data;
Packit 0d464f
Packit 0d464f
Packit 0d464f
    // needed for copyPixels
Packit 0d464f
    friend void DeepTiledOutputFile::copyPixels(DeepTiledInputFile &);
Packit 0d464f
};
Packit 0d464f
Packit 0d464f
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Packit 0d464f
Packit 0d464f
#endif