Blame IlmImf/ImfDeepScanLineOutputFile.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
Packit c2c737
#ifndef INCLUDED_IMF_DEEP_SCAN_LINE_OUTPUT_FILE_H
Packit c2c737
#define INCLUDED_IMF_DEEP_SCAN_LINE_OUTPUT_FILE_H
Packit c2c737
Packit c2c737
//-----------------------------------------------------------------------------
Packit c2c737
//
Packit c2c737
//      class DeepScanLineOutputFile
Packit c2c737
//
Packit c2c737
//-----------------------------------------------------------------------------
Packit c2c737
Packit c2c737
#include "ImfHeader.h"
Packit c2c737
#include "ImfFrameBuffer.h"
Packit c2c737
#include "ImfThreading.h"
Packit c2c737
#include "ImfGenericOutputFile.h"
Packit c2c737
#include "ImfNamespace.h"
Packit c2c737
#include "ImfForward.h"
Packit c2c737
#include "ImfExport.h"
Packit c2c737
Packit c2c737
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Packit c2c737
Packit c2c737
Packit c2c737
struct PreviewRgba;
Packit c2c737
Packit c2c737
class IMF_EXPORT DeepScanLineOutputFile : public GenericOutputFile
Packit c2c737
{
Packit c2c737
  public:
Packit c2c737
Packit c2c737
    //-----------------------------------------------------------
Packit c2c737
    // Constructor -- opens the file and writes the file header.
Packit c2c737
    // The file header is also copied into the DeepScanLineOutputFile
Packit c2c737
    // object, and can later be accessed via the header() method.
Packit c2c737
    // Destroying this DeepScanLineOutputFile object automatically closes
Packit c2c737
    // the file.
Packit c2c737
    //
Packit c2c737
    // numThreads determines the number of threads that will be
Packit c2c737
    // used to write the file (see ImfThreading.h).
Packit c2c737
    //-----------------------------------------------------------
Packit c2c737
Packit c2c737
    DeepScanLineOutputFile (const char fileName[], const Header &header,
Packit c2c737
                int numThreads = globalThreadCount());
Packit c2c737
Packit c2c737
Packit c2c737
    //------------------------------------------------------------
Packit c2c737
    // Constructor -- attaches the new DeepScanLineOutputFile object
Packit c2c737
    // to a file that has already been opened, and writes the file header.
Packit c2c737
    // The file header is also copied into the DeepScanLineOutputFile
Packit c2c737
    // object, and can later be accessed via the header() method.
Packit c2c737
    // Destroying this DeepScanLineOutputFile object does not automatically
Packit c2c737
    // close the file.
Packit c2c737
    //
Packit c2c737
    // numThreads determines the number of threads that will be
Packit c2c737
    // used to write the file (see ImfThreading.h).
Packit c2c737
    //------------------------------------------------------------
Packit c2c737
Packit c2c737
    DeepScanLineOutputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &os, const Header &header,
Packit c2c737
                int numThreads = globalThreadCount());
Packit c2c737
Packit c2c737
Packit c2c737
    //-------------------------------------------------
Packit c2c737
    // Destructor
Packit c2c737
    //
Packit c2c737
    // Destroying the DeepScanLineOutputFile object
Packit c2c737
    // before writing all scan lines within the data
Packit c2c737
    // window results in an incomplete file.
Packit c2c737
    //-------------------------------------------------
Packit c2c737
Packit c2c737
    virtual ~DeepScanLineOutputFile ();
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
    // Set the current frame buffer -- copies the FrameBuffer
Packit c2c737
    // object into the OutputFile object.
Packit c2c737
    //
Packit c2c737
    // The current frame buffer is the source of the pixel
Packit c2c737
    // data written to the file.  The current frame buffer
Packit c2c737
    // must be set at least once before writePixels() is
Packit c2c737
    // called.  The current frame buffer can be changed
Packit c2c737
    // after each call to writePixels.
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
    // Write pixel data:
Packit c2c737
    //
Packit c2c737
    // writePixels(n) retrieves the next n scan lines worth of data from
Packit c2c737
    // the current frame buffer, starting with the scan line indicated by
Packit c2c737
    // currentScanLine(), and stores the data in the output file, and
Packit c2c737
    // progressing in the direction indicated by header.lineOrder().
Packit c2c737
    //
Packit c2c737
    // To produce a complete and correct file, exactly m scan lines must
Packit c2c737
    // be written, where m is equal to
Packit c2c737
    // header().dataWindow().max.y - header().dataWindow().min.y + 1.
Packit c2c737
    //-------------------------------------------------------------------
Packit c2c737
Packit c2c737
    void                writePixels (int numScanLines = 1);
Packit c2c737
Packit c2c737
Packit c2c737
    //------------------------------------------------------------------
Packit c2c737
    // Access to the current scan line:
Packit c2c737
    //
Packit c2c737
    // currentScanLine() returns the y coordinate of the first scan line
Packit c2c737
    // that will be read from the current frame buffer during the next
Packit c2c737
    // call to writePixels().
Packit c2c737
    //
Packit c2c737
    // If header.lineOrder() == INCREASING_Y:
Packit c2c737
    //
Packit c2c737
    //  The current scan line before the first call to writePixels()
Packit c2c737
    //  is header().dataWindow().min.y.  After writing each scan line,
Packit c2c737
    //  the current scan line is incremented by 1.
Packit c2c737
    //
Packit c2c737
    // If header.lineOrder() == DECREASING_Y:
Packit c2c737
    //
Packit c2c737
    //  The current scan line before the first call to writePixels()
Packit c2c737
    //  is header().dataWindow().max.y.  After writing each scan line,
Packit c2c737
    //  the current scan line is decremented by 1.
Packit c2c737
    //
Packit c2c737
    //------------------------------------------------------------------
Packit c2c737
Packit c2c737
    int                 currentScanLine () const;
Packit c2c737
Packit c2c737
Packit c2c737
    //--------------------------------------------------------------
Packit c2c737
    // Shortcut to copy all pixels from an InputFile into this file,
Packit c2c737
    // without uncompressing and then recompressing the pixel data.
Packit c2c737
    // This file's header must be compatible with the InputFile's
Packit c2c737
    // header:  The two header's "dataWindow", "compression",
Packit c2c737
    // "lineOrder" and "channels" attributes must be the same.
Packit c2c737
    //--------------------------------------------------------------
Packit c2c737
Packit c2c737
    void                copyPixels (DeepScanLineInputFile &in);
Packit c2c737
    
Packit c2c737
    // --------------------------------------------------------------
Packit c2c737
    // Shortcut to copy pixels from a given part of a multipart file
Packit c2c737
    // --------------------------------------------------------------
Packit c2c737
    void                copyPixels (DeepScanLineInputPart &in);
Packit c2c737
Packit c2c737
Packit c2c737
    //--------------------------------------------------------------
Packit c2c737
    // Updating the preview image:
Packit c2c737
    //
Packit c2c737
    // updatePreviewImage() supplies a new set of pixels for the
Packit c2c737
    // preview image attribute in the file's header.  If the header
Packit c2c737
    // does not contain a preview image, updatePreviewImage() throws
Packit c2c737
    // an IEX_NAMESPACE::LogicExc.
Packit c2c737
    //
Packit c2c737
    // Note: updatePreviewImage() is necessary because images are
Packit c2c737
    // often stored in a file incrementally, a few scan lines at a
Packit c2c737
    // time, while the image is being generated.  Since the preview
Packit c2c737
    // image is an attribute in the file's header, it gets stored in
Packit c2c737
    // the file as soon as the file is opened, but we may not know
Packit c2c737
    // what the preview image should look like until we have written
Packit c2c737
    // the last scan line of the main image.
Packit c2c737
    //
Packit c2c737
    //--------------------------------------------------------------
Packit c2c737
Packit c2c737
    void                updatePreviewImage (const PreviewRgba newPixels[]);
Packit c2c737
Packit c2c737
Packit c2c737
    struct Data;
Packit c2c737
Packit c2c737
  private:
Packit c2c737
Packit c2c737
    //------------------------------------------------------------
Packit c2c737
    // Constructor -- attaches the OutputStreamMutex to the
Packit c2c737
    // given one from MultiPartOutputFile. Set the previewPosition
Packit c2c737
    // and lineOffsetsPosition which have been acquired from
Packit c2c737
    // the constructor of MultiPartOutputFile as well.
Packit c2c737
    //------------------------------------------------------------
Packit c2c737
    DeepScanLineOutputFile (const OutputPartData* part);
Packit c2c737
Packit c2c737
    DeepScanLineOutputFile (const DeepScanLineOutputFile &);                    // not implemented
Packit c2c737
    DeepScanLineOutputFile & operator = (const DeepScanLineOutputFile &);       // not implemented
Packit c2c737
Packit c2c737
    void                initialize (const Header &header);
Packit c2c737
    void                initializeLineBuffer();
Packit c2c737
Packit c2c737
    Data *              _data;
Packit c2c737
Packit c2c737
Packit c2c737
Packit c2c737
    friend class MultiPartOutputFile;
Packit c2c737
};
Packit c2c737
Packit c2c737
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Packit c2c737
Packit c2c737
#endif