Blame IlmImf/ImfDeepScanLineInputFile.h

Packit c2c737
///////////////////////////////////////////////////////////////////////////
Packit c2c737
//
Packit c2c737
// Copyright (c) 2011, Industrial Light & Magic, a division of Lucas
Packit c2c737
// Digital Ltd. LLC
Packit c2c737
//
Packit c2c737
// All rights reserved.
Packit c2c737
//
Packit c2c737
// Redistribution and use in source and binary forms, with or without
Packit c2c737
// modification, are permitted provided that the following conditions are
Packit c2c737
// met:
Packit c2c737
// *       Redistributions of source code must retain the above copyright
Packit c2c737
// notice, this list of conditions and the following disclaimer.
Packit c2c737
// *       Redistributions in binary form must reproduce the above
Packit c2c737
// copyright notice, this list of conditions and the following disclaimer
Packit c2c737
// in the documentation and/or other materials provided with the
Packit c2c737
// distribution.
Packit c2c737
// *       Neither the name of Industrial Light & Magic nor the names of
Packit c2c737
// its contributors may be used to endorse or promote products derived
Packit c2c737
// from this software without specific prior written permission.
Packit c2c737
//
Packit c2c737
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit c2c737
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit c2c737
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Packit c2c737
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
Packit c2c737
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Packit c2c737
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Packit c2c737
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Packit c2c737
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Packit c2c737
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Packit c2c737
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit c2c737
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit c2c737
//
Packit c2c737
///////////////////////////////////////////////////////////////////////////
Packit c2c737
Packit c2c737
Packit c2c737
#ifndef INCLUDED_IMF_DEEP_SCAN_LINE_INPUT_FILE_H
Packit c2c737
#define INCLUDED_IMF_DEEP_SCAN_LINE_INPUT_FILE_H
Packit c2c737
Packit c2c737
//-----------------------------------------------------------------------------
Packit c2c737
//
Packit c2c737
//      class DeepScanLineInputFile
Packit c2c737
//
Packit c2c737
//-----------------------------------------------------------------------------
Packit c2c737
Packit c2c737
#include "ImfThreading.h"
Packit c2c737
#include "ImfGenericInputFile.h"
Packit c2c737
#include "ImfNamespace.h"
Packit c2c737
#include "ImfForward.h"
Packit c2c737
#include "ImfExport.h"
Packit c2c737
#include "ImfDeepScanLineOutputFile.h"
Packit c2c737
Packit c2c737
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Packit c2c737
Packit c2c737
Packit c2c737
class IMF_EXPORT DeepScanLineInputFile : public GenericInputFile
Packit c2c737
{
Packit c2c737
  public:
Packit c2c737
Packit c2c737
    //------------
Packit c2c737
    // Constructor
Packit c2c737
    //------------
Packit c2c737
Packit c2c737
    DeepScanLineInputFile (const char fileName[],
Packit c2c737
                           int numThreads = globalThreadCount());
Packit c2c737
Packit c2c737
    DeepScanLineInputFile (const Header &header, OPENEXR_IMF_INTERNAL_NAMESPACE::IStream *is,
Packit c2c737
                           int version, /*version field from file*/
Packit c2c737
                           int numThreads = globalThreadCount());
Packit c2c737
Packit c2c737
Packit c2c737
    //-----------------------------------------
Packit c2c737
    // Destructor -- deallocates internal data
Packit c2c737
    // structures, but does not close the file.
Packit c2c737
    //-----------------------------------------
Packit c2c737
Packit c2c737
    virtual ~DeepScanLineInputFile ();
Packit c2c737
Packit c2c737
Packit c2c737
    //------------------------
Packit c2c737
    // Access to the file name
Packit c2c737
    //------------------------
Packit c2c737
Packit c2c737
    const char *        fileName () const;
Packit c2c737
Packit c2c737
Packit c2c737
    //--------------------------
Packit c2c737
    // Access to the file header
Packit c2c737
    //--------------------------
Packit c2c737
Packit c2c737
    const Header &      header () const;
Packit c2c737
Packit c2c737
Packit c2c737
    //----------------------------------
Packit c2c737
    // Access to the file format version
Packit c2c737
    //----------------------------------
Packit c2c737
Packit c2c737
    int                 version () const;
Packit c2c737
Packit c2c737
Packit c2c737
    //-----------------------------------------------------------
Packit c2c737
    // Set the current frame buffer -- copies the FrameBuffer
Packit c2c737
    // object into the InputFile object.
Packit c2c737
    //
Packit c2c737
    // The current frame buffer is the destination for the pixel
Packit c2c737
    // data read from the file.  The current frame buffer must be
Packit c2c737
    // set at least once before readPixels() is called.
Packit c2c737
    // The current frame buffer can be changed after each call
Packit c2c737
    // to readPixels().
Packit c2c737
    //-----------------------------------------------------------
Packit c2c737
Packit c2c737
    void                setFrameBuffer (const DeepFrameBuffer &frameBuffer);
Packit c2c737
Packit c2c737
Packit c2c737
    //-----------------------------------
Packit c2c737
    // Access to the current frame buffer
Packit c2c737
    //-----------------------------------
Packit c2c737
Packit c2c737
    const DeepFrameBuffer & frameBuffer () const;
Packit c2c737
Packit c2c737
Packit c2c737
    //---------------------------------------------------------------
Packit c2c737
    // Check if the file is complete:
Packit c2c737
    //
Packit c2c737
    // isComplete() returns true if all pixels in the data window are
Packit c2c737
    // present in the input file, or false if any pixels are missing.
Packit c2c737
    // (Another program may still be busy writing the file, or file
Packit c2c737
    // writing may have been aborted prematurely.)
Packit c2c737
    //---------------------------------------------------------------
Packit c2c737
Packit c2c737
    bool                isComplete () const;
Packit c2c737
Packit c2c737
Packit c2c737
    //---------------------------------------------------------------
Packit c2c737
    // Read pixel data:
Packit c2c737
    //
Packit c2c737
    // readPixels(s1,s2) reads all scan lines with y coordinates
Packit c2c737
    // in the interval [min (s1, s2), max (s1, s2)] from the file,
Packit c2c737
    // and stores them in the current frame buffer.
Packit c2c737
    //
Packit c2c737
    // Both s1 and s2 must be within the interval
Packit c2c737
    // [header().dataWindow().min.y, header.dataWindow().max.y]
Packit c2c737
    //
Packit c2c737
    // The scan lines can be read from the file in random order, and
Packit c2c737
    // individual scan lines may be skipped or read multiple times.
Packit c2c737
    // For maximum efficiency, the scan lines should be read in the
Packit c2c737
    // order in which they were written to the file.
Packit c2c737
    //
Packit c2c737
    // readPixels(s) calls readPixels(s,s).
Packit c2c737
    //
Packit c2c737
    // If threading is enabled, readPixels (s1, s2) tries to perform
Packit c2c737
    // decopmression of multiple scanlines in parallel.
Packit c2c737
    //
Packit c2c737
    //---------------------------------------------------------------
Packit c2c737
Packit c2c737
    void                readPixels (int scanLine1, int scanLine2);
Packit c2c737
    void                readPixels (int scanLine);
Packit c2c737
Packit c2c737
    
Packit c2c737
  
Packit c2c737
    //---------------------------------------------------------------
Packit c2c737
    // Extract pixel data from pre-read block
Packit c2c737
    //
Packit c2c737
    // readPixels(rawPixelData,frameBuffer,s1,s2) reads all scan lines with y coordinates
Packit c2c737
    // in the interval [min (s1, s2), max (s1, s2)] from the data provided and
Packit c2c737
    // stores them in the provided frameBuffer.
Packit c2c737
    // the data can be obtained from a call to rawPixelData()
Packit c2c737
    //
Packit c2c737
    //
Packit c2c737
    // Both s1 and s2 must be within the data specified
Packit c2c737
    //
Packit c2c737
    // you must provide a frameBuffer with a samplecountslice, which must have been read
Packit c2c737
    // and the data valid - readPixels uses your sample count buffer to compute
Packit c2c737
    // offsets to the data it needs
Packit c2c737
    //
Packit c2c737
    // This call does not block, and is thread safe for clients with an existing
Packit c2c737
    // threading model. The InputFile's frameBuffer is not used in this call.
Packit c2c737
    //
Packit c2c737
    // This call is only provided for clients which have an existing threading model in place
Packit c2c737
    // and unpredictable access patterns to the data.
Packit c2c737
    // The fastest way to read an entire image is to enable threading,use setFrameBuffer then
Packit c2c737
    // readPixels(header().dataWindow().min.y, header.dataWindow().max.y)
Packit c2c737
    //
Packit c2c737
    //---------------------------------------------------------------
Packit c2c737
    
Packit c2c737
    void                readPixels (const char * rawPixelData,
Packit c2c737
                                    const DeepFrameBuffer & frameBuffer,
Packit c2c737
                                    int scanLine1,
Packit c2c737
                                    int scanLine2) const;
Packit c2c737
Packit c2c737
    //----------------------------------------------
Packit c2c737
    // Read a block of raw pixel data from the file,
Packit c2c737
    // without uncompressing it (this function is
Packit c2c737
    // used to implement OutputFile::copyPixels()).
Packit c2c737
    // note: returns the entire payload of the relevant chunk of data, not including part number
Packit c2c737
    // including compressed and uncompressed sizes
Packit c2c737
    // on entry, if pixelDataSize is insufficiently large, no bytes are read (pixelData can safely be NULL)
Packit c2c737
    // on exit, pixelDataSize is the number of bytes required to read the chunk
Packit c2c737
    // 
Packit c2c737
    //----------------------------------------------
Packit c2c737
Packit c2c737
    void                rawPixelData (int firstScanLine,
Packit c2c737
                                      char * pixelData,
Packit c2c737
                                      Int64 &pixelDataSize);
Packit c2c737
Packit c2c737
                                      
Packit c2c737
    //-------------------------------------------------
Packit c2c737
    // firstScanLineInChunk() returns the row number of the first row that's stored in the
Packit c2c737
    // same chunk as scanline y. Depending on the compression mode, this may not be the same as y
Packit c2c737
    //
Packit c2c737
    // lastScanLineInChunk() returns the row number of the last row that's stored in the same
Packit c2c737
    // chunk as scanline y.  Depending on the compression mode, this may not be the same as y.
Packit c2c737
    // The last chunk in the file may be smaller than all the others
Packit c2c737
    //
Packit c2c737
    //------------------------------------------------
Packit c2c737
    int                 firstScanLineInChunk(int y) const;
Packit c2c737
    int                 lastScanLineInChunk (int y) const;
Packit c2c737
                                      
Packit c2c737
    //-----------------------------------------------------------
Packit c2c737
    // Read pixel sample counts into a slice in the frame buffer.
Packit c2c737
    //
Packit c2c737
    // readPixelSampleCounts(s1, s2) reads all the counts of
Packit c2c737
    // pixel samples with y coordinates in the interval
Packit c2c737
    // [min (s1, s2), max (s1, s2)] from the file, and stores
Packit c2c737
    // them in the slice naming "sample count".
Packit c2c737
    //
Packit c2c737
    // Both s1 and s2 must be within the interval
Packit c2c737
    // [header().dataWindow().min.y, header.dataWindow().max.y]
Packit c2c737
    //
Packit c2c737
    // readPixelSampleCounts(s) calls readPixelSampleCounts(s,s).
Packit c2c737
    // 
Packit c2c737
    //-----------------------------------------------------------
Packit c2c737
Packit c2c737
    void                readPixelSampleCounts (int scanline1,
Packit c2c737
                                               int scanline2);
Packit c2c737
    void                readPixelSampleCounts (int scanline);
Packit c2c737
    
Packit c2c737
    
Packit c2c737
    //----------------------------------------------------------
Packit c2c737
    // Read pixel sample counts into the provided frameBuffer
Packit c2c737
    // using a block read of data read by rawPixelData    
Packit c2c737
    // for multi-scanline compression schemes, you must decode the entire block
Packit c2c737
    // so scanline1=firstScanLineInChunk(y) and scanline2=lastScanLineInChunk(y)
Packit c2c737
    // 
Packit c2c737
    // This call does not block, and is thread safe for clients with an existing
Packit c2c737
    // threading model. The InputFile's frameBuffer is not used in this call.
Packit c2c737
    //
Packit c2c737
    // The fastest way to read an entire image is to enable threading in OpenEXR, use setFrameBuffer then
Packit c2c737
    // readPixelSampleCounts(header().dataWindow().min.y, header.dataWindow().max.y)
Packit c2c737
    //
Packit c2c737
    //----------------------------------------------------------
Packit c2c737
    void                readPixelSampleCounts (const char * rawdata , 
Packit c2c737
                                               const DeepFrameBuffer & frameBuffer,
Packit c2c737
                                               int scanLine1 , 
Packit c2c737
                                               int scanLine2) const;
Packit c2c737
Packit c2c737
    struct Data;
Packit c2c737
Packit c2c737
  private:
Packit c2c737
Packit c2c737
    Data *              _data;
Packit c2c737
Packit c2c737
    DeepScanLineInputFile   (InputPartData* part);
Packit c2c737
Packit c2c737
    void                initialize(const Header& header);
Packit c2c737
    void compatibilityInitialize(OPENEXR_IMF_INTERNAL_NAMESPACE::IStream & is);
Packit c2c737
    void multiPartInitialize(InputPartData* part);
Packit c2c737
Packit c2c737
    friend class         InputFile;
Packit c2c737
    friend class MultiPartInputFile;
Packit c2c737
    friend void DeepScanLineOutputFile::copyPixels(DeepScanLineInputFile &);
Packit c2c737
};
Packit c2c737
Packit c2c737
Packit c2c737
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Packit c2c737
Packit c2c737
#endif