Blame IlmImf/ImfDeepScanLineInputFile.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_SCAN_LINE_INPUT_FILE_H
Packit 0d464f
#define INCLUDED_IMF_DEEP_SCAN_LINE_INPUT_FILE_H
Packit 0d464f
Packit 0d464f
//-----------------------------------------------------------------------------
Packit 0d464f
//
Packit 0d464f
//      class DeepScanLineInputFile
Packit 0d464f
//
Packit 0d464f
//-----------------------------------------------------------------------------
Packit 0d464f
Packit 0d464f
#include "ImfThreading.h"
Packit 0d464f
#include "ImfGenericInputFile.h"
Packit 0d464f
#include "ImfNamespace.h"
Packit 0d464f
#include "ImfForward.h"
Packit 0d464f
#include "ImfExport.h"
Packit 0d464f
#include "ImfDeepScanLineOutputFile.h"
Packit 0d464f
Packit 0d464f
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Packit 0d464f
Packit 0d464f
Packit 0d464f
class IMF_EXPORT DeepScanLineInputFile : public GenericInputFile
Packit 0d464f
{
Packit 0d464f
  public:
Packit 0d464f
Packit 0d464f
    //------------
Packit 0d464f
    // Constructor
Packit 0d464f
    //------------
Packit 0d464f
Packit 0d464f
    DeepScanLineInputFile (const char fileName[],
Packit 0d464f
                           int numThreads = globalThreadCount());
Packit 0d464f
Packit 0d464f
    DeepScanLineInputFile (const Header &header, OPENEXR_IMF_INTERNAL_NAMESPACE::IStream *is,
Packit 0d464f
                           int version, /*version field from file*/
Packit 0d464f
                           int numThreads = globalThreadCount());
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //-----------------------------------------
Packit 0d464f
    // Destructor -- deallocates internal data
Packit 0d464f
    // structures, but does not close the file.
Packit 0d464f
    //-----------------------------------------
Packit 0d464f
Packit 0d464f
    virtual ~DeepScanLineInputFile ();
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 InputFile 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 readPixels() is called.
Packit 0d464f
    // The current frame buffer can be changed after each call
Packit 0d464f
    // to readPixels().
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 are
Packit 0d464f
    // present in the input file, or false if any pixels are missing.
Packit 0d464f
    // (Another program may still be busy writing the file, or file
Packit 0d464f
    // writing may have been aborted prematurely.)
Packit 0d464f
    //---------------------------------------------------------------
Packit 0d464f
Packit 0d464f
    bool                isComplete () const;
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //---------------------------------------------------------------
Packit 0d464f
    // Read pixel data:
Packit 0d464f
    //
Packit 0d464f
    // readPixels(s1,s2) reads all scan lines with y coordinates
Packit 0d464f
    // in the interval [min (s1, s2), max (s1, s2)] from the file,
Packit 0d464f
    // and stores them in the current frame buffer.
Packit 0d464f
    //
Packit 0d464f
    // Both s1 and s2 must be within the interval
Packit 0d464f
    // [header().dataWindow().min.y, header.dataWindow().max.y]
Packit 0d464f
    //
Packit 0d464f
    // The scan lines can be read from the file in random order, and
Packit 0d464f
    // individual scan lines may be skipped or read multiple times.
Packit 0d464f
    // For maximum efficiency, the scan lines should be read in the
Packit 0d464f
    // order in which they were written to the file.
Packit 0d464f
    //
Packit 0d464f
    // readPixels(s) calls readPixels(s,s).
Packit 0d464f
    //
Packit 0d464f
    // If threading is enabled, readPixels (s1, s2) tries to perform
Packit 0d464f
    // decopmression of multiple scanlines in parallel.
Packit 0d464f
    //
Packit 0d464f
    //---------------------------------------------------------------
Packit 0d464f
Packit 0d464f
    void                readPixels (int scanLine1, int scanLine2);
Packit 0d464f
    void                readPixels (int scanLine);
Packit 0d464f
Packit 0d464f
    
Packit 0d464f
  
Packit 0d464f
    //---------------------------------------------------------------
Packit 0d464f
    // Extract pixel data from pre-read block
Packit 0d464f
    //
Packit 0d464f
    // readPixels(rawPixelData,frameBuffer,s1,s2) reads all scan lines with y coordinates
Packit 0d464f
    // in the interval [min (s1, s2), max (s1, s2)] from the data provided and
Packit 0d464f
    // stores them in the provided frameBuffer.
Packit 0d464f
    // the data can be obtained from a call to rawPixelData()
Packit 0d464f
    //
Packit 0d464f
    //
Packit 0d464f
    // Both s1 and s2 must be within the data specified
Packit 0d464f
    //
Packit 0d464f
    // you must provide a frameBuffer with a samplecountslice, which must have been read
Packit 0d464f
    // and the data valid - readPixels uses your sample count buffer to compute
Packit 0d464f
    // offsets to the data it needs
Packit 0d464f
    //
Packit 0d464f
    // This call does not block, and is thread safe for clients with an existing
Packit 0d464f
    // threading model. The InputFile's frameBuffer is not used in this call.
Packit 0d464f
    //
Packit 0d464f
    // This call is only provided for clients which have an existing threading model in place
Packit 0d464f
    // and unpredictable access patterns to the data.
Packit 0d464f
    // The fastest way to read an entire image is to enable threading,use setFrameBuffer then
Packit 0d464f
    // readPixels(header().dataWindow().min.y, header.dataWindow().max.y)
Packit 0d464f
    //
Packit 0d464f
    //---------------------------------------------------------------
Packit 0d464f
    
Packit 0d464f
    void                readPixels (const char * rawPixelData,
Packit 0d464f
                                    const DeepFrameBuffer & frameBuffer,
Packit 0d464f
                                    int scanLine1,
Packit 0d464f
                                    int scanLine2) const;
Packit 0d464f
Packit 0d464f
    //----------------------------------------------
Packit 0d464f
    // Read a block of raw pixel data from the file,
Packit 0d464f
    // without uncompressing it (this function is
Packit 0d464f
    // used to implement OutputFile::copyPixels()).
Packit 0d464f
    // note: returns the entire payload of the relevant chunk of data, not including part number
Packit 0d464f
    // including compressed and uncompressed sizes
Packit 0d464f
    // on entry, if pixelDataSize is insufficiently large, no bytes are read (pixelData can safely be NULL)
Packit 0d464f
    // on exit, pixelDataSize is the number of bytes required to read the chunk
Packit 0d464f
    // 
Packit 0d464f
    //----------------------------------------------
Packit 0d464f
Packit 0d464f
    void                rawPixelData (int firstScanLine,
Packit 0d464f
                                      char * pixelData,
Packit 0d464f
                                      Int64 &pixelDataSize);
Packit 0d464f
Packit 0d464f
                                      
Packit 0d464f
    //-------------------------------------------------
Packit 0d464f
    // firstScanLineInChunk() returns the row number of the first row that's stored in the
Packit 0d464f
    // same chunk as scanline y. Depending on the compression mode, this may not be the same as y
Packit 0d464f
    //
Packit 0d464f
    // lastScanLineInChunk() returns the row number of the last row that's stored in the same
Packit 0d464f
    // chunk as scanline y.  Depending on the compression mode, this may not be the same as y.
Packit 0d464f
    // The last chunk in the file may be smaller than all the others
Packit 0d464f
    //
Packit 0d464f
    //------------------------------------------------
Packit 0d464f
    int                 firstScanLineInChunk(int y) const;
Packit 0d464f
    int                 lastScanLineInChunk (int y) const;
Packit 0d464f
                                      
Packit 0d464f
    //-----------------------------------------------------------
Packit 0d464f
    // Read pixel sample counts into a slice in the frame buffer.
Packit 0d464f
    //
Packit 0d464f
    // readPixelSampleCounts(s1, s2) reads all the counts of
Packit 0d464f
    // pixel samples with y coordinates in the interval
Packit 0d464f
    // [min (s1, s2), max (s1, s2)] from the file, and stores
Packit 0d464f
    // them in the slice naming "sample count".
Packit 0d464f
    //
Packit 0d464f
    // Both s1 and s2 must be within the interval
Packit 0d464f
    // [header().dataWindow().min.y, header.dataWindow().max.y]
Packit 0d464f
    //
Packit 0d464f
    // readPixelSampleCounts(s) calls readPixelSampleCounts(s,s).
Packit 0d464f
    // 
Packit 0d464f
    //-----------------------------------------------------------
Packit 0d464f
Packit 0d464f
    void                readPixelSampleCounts (int scanline1,
Packit 0d464f
                                               int scanline2);
Packit 0d464f
    void                readPixelSampleCounts (int scanline);
Packit 0d464f
    
Packit 0d464f
    
Packit 0d464f
    //----------------------------------------------------------
Packit 0d464f
    // Read pixel sample counts into the provided frameBuffer
Packit 0d464f
    // using a block read of data read by rawPixelData    
Packit 0d464f
    // for multi-scanline compression schemes, you must decode the entire block
Packit 0d464f
    // so scanline1=firstScanLineInChunk(y) and scanline2=lastScanLineInChunk(y)
Packit 0d464f
    // 
Packit 0d464f
    // This call does not block, and is thread safe for clients with an existing
Packit 0d464f
    // threading model. The InputFile's frameBuffer is not used in this call.
Packit 0d464f
    //
Packit 0d464f
    // The fastest way to read an entire image is to enable threading in OpenEXR, use setFrameBuffer then
Packit 0d464f
    // readPixelSampleCounts(header().dataWindow().min.y, header.dataWindow().max.y)
Packit 0d464f
    //
Packit 0d464f
    //----------------------------------------------------------
Packit 0d464f
    void                readPixelSampleCounts (const char * rawdata , 
Packit 0d464f
                                               const DeepFrameBuffer & frameBuffer,
Packit 0d464f
                                               int scanLine1 , 
Packit 0d464f
                                               int scanLine2) const;
Packit 0d464f
Packit 0d464f
    struct Data;
Packit 0d464f
Packit 0d464f
  private:
Packit 0d464f
Packit 0d464f
    Data *              _data;
Packit 0d464f
Packit 0d464f
    DeepScanLineInputFile   (InputPartData* part);
Packit 0d464f
Packit 0d464f
    void                initialize(const Header& header);
Packit 0d464f
    void compatibilityInitialize(OPENEXR_IMF_INTERNAL_NAMESPACE::IStream & is);
Packit 0d464f
    void multiPartInitialize(InputPartData* part);
Packit 0d464f
Packit 0d464f
    friend class         InputFile;
Packit 0d464f
    friend class MultiPartInputFile;
Packit 0d464f
    friend void DeepScanLineOutputFile::copyPixels(DeepScanLineInputFile &);
Packit 0d464f
};
Packit 0d464f
Packit 0d464f
Packit 0d464f
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Packit 0d464f
Packit 0d464f
#endif