Blame IlmImf/ImfOutputFile.h

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