|
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_RGBA_FILE_H
|
|
Packit |
0d464f |
#define INCLUDED_IMF_RGBA_FILE_H
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
//-----------------------------------------------------------------------------
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
// Simplified RGBA image I/O
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
// class RgbaOutputFile
|
|
Packit |
0d464f |
// class RgbaInputFile
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
//-----------------------------------------------------------------------------
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
#include "ImfHeader.h"
|
|
Packit |
0d464f |
#include "ImfFrameBuffer.h"
|
|
Packit |
0d464f |
#include "ImfRgba.h"
|
|
Packit |
0d464f |
#include "ImathVec.h"
|
|
Packit |
0d464f |
#include "ImathBox.h"
|
|
Packit |
0d464f |
#include "half.h"
|
|
Packit |
0d464f |
#include "ImfThreading.h"
|
|
Packit |
0d464f |
#include <string>
|
|
Packit |
0d464f |
#include "ImfNamespace.h"
|
|
Packit |
0d464f |
#include "ImfForward.h"
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
// RGBA output file.
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
class IMF_EXPORT RgbaOutputFile
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
public:
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
//---------------------------------------------------
|
|
Packit |
0d464f |
// Constructor -- header is constructed by the caller
|
|
Packit |
0d464f |
//---------------------------------------------------
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
RgbaOutputFile (const char name[],
|
|
Packit |
0d464f |
const Header &header,
|
|
Packit |
0d464f |
RgbaChannels rgbaChannels = WRITE_RGBA,
|
|
Packit |
0d464f |
int numThreads = globalThreadCount());
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
//----------------------------------------------------
|
|
Packit |
0d464f |
// Constructor -- header is constructed by the caller,
|
|
Packit |
0d464f |
// file is opened by the caller, destructor will not
|
|
Packit |
0d464f |
// automatically close the file.
|
|
Packit |
0d464f |
//----------------------------------------------------
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
RgbaOutputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &os,
|
|
Packit |
0d464f |
const Header &header,
|
|
Packit |
0d464f |
RgbaChannels rgbaChannels = WRITE_RGBA,
|
|
Packit |
0d464f |
int numThreads = globalThreadCount());
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
//----------------------------------------------------------------
|
|
Packit |
0d464f |
// Constructor -- header data are explicitly specified as function
|
|
Packit |
0d464f |
// call arguments (empty dataWindow means "same as displayWindow")
|
|
Packit |
0d464f |
//----------------------------------------------------------------
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
RgbaOutputFile (const char name[],
|
|
Packit |
0d464f |
const IMATH_NAMESPACE::Box2i &displayWindow,
|
|
Packit |
0d464f |
const IMATH_NAMESPACE::Box2i &dataWindow = IMATH_NAMESPACE::Box2i(),
|
|
Packit |
0d464f |
RgbaChannels rgbaChannels = WRITE_RGBA,
|
|
Packit |
0d464f |
float pixelAspectRatio = 1,
|
|
Packit |
0d464f |
const IMATH_NAMESPACE::V2f screenWindowCenter = IMATH_NAMESPACE::V2f (0, 0),
|
|
Packit |
0d464f |
float screenWindowWidth = 1,
|
|
Packit |
0d464f |
LineOrder lineOrder = INCREASING_Y,
|
|
Packit |
0d464f |
Compression compression = PIZ_COMPRESSION,
|
|
Packit |
0d464f |
int numThreads = globalThreadCount());
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
//-----------------------------------------------
|
|
Packit |
0d464f |
// Constructor -- like the previous one, but both
|
|
Packit |
0d464f |
// the display window and the data window are
|
|
Packit |
0d464f |
// Box2i (V2i (0, 0), V2i (width - 1, height -1))
|
|
Packit |
0d464f |
//-----------------------------------------------
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
RgbaOutputFile (const char name[],
|
|
Packit |
0d464f |
int width,
|
|
Packit |
0d464f |
int height,
|
|
Packit |
0d464f |
RgbaChannels rgbaChannels = WRITE_RGBA,
|
|
Packit |
0d464f |
float pixelAspectRatio = 1,
|
|
Packit |
0d464f |
const IMATH_NAMESPACE::V2f screenWindowCenter = IMATH_NAMESPACE::V2f (0, 0),
|
|
Packit |
0d464f |
float screenWindowWidth = 1,
|
|
Packit |
0d464f |
LineOrder lineOrder = INCREASING_Y,
|
|
Packit |
0d464f |
Compression compression = PIZ_COMPRESSION,
|
|
Packit |
0d464f |
int numThreads = globalThreadCount());
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
//-----------
|
|
Packit |
0d464f |
// Destructor
|
|
Packit |
0d464f |
//-----------
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
virtual ~RgbaOutputFile ();
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
//------------------------------------------------
|
|
Packit |
0d464f |
// Define a frame buffer as the pixel data source:
|
|
Packit |
0d464f |
// Pixel (x, y) is at address
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
// base + x * xStride + y * yStride
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
//------------------------------------------------
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
void setFrameBuffer (const Rgba *base,
|
|
Packit |
0d464f |
size_t xStride,
|
|
Packit |
0d464f |
size_t yStride);
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
//---------------------------------------------
|
|
Packit |
0d464f |
// Write pixel data (see class Imf::OutputFile)
|
|
Packit |
0d464f |
//---------------------------------------------
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
void writePixels (int numScanLines = 1);
|
|
Packit |
0d464f |
int currentScanLine () 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 |
const FrameBuffer & frameBuffer () const;
|
|
Packit |
0d464f |
const IMATH_NAMESPACE::Box2i & displayWindow () const;
|
|
Packit |
0d464f |
const IMATH_NAMESPACE::Box2i & dataWindow () const;
|
|
Packit |
0d464f |
float pixelAspectRatio () const;
|
|
Packit |
0d464f |
const IMATH_NAMESPACE::V2f screenWindowCenter () const;
|
|
Packit |
0d464f |
float screenWindowWidth () const;
|
|
Packit |
0d464f |
LineOrder lineOrder () const;
|
|
Packit |
0d464f |
Compression compression () const;
|
|
Packit |
0d464f |
RgbaChannels channels () const;
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
// --------------------------------------------------------------------
|
|
Packit |
0d464f |
// Update the preview image (see Imf::OutputFile::updatePreviewImage())
|
|
Packit |
0d464f |
// --------------------------------------------------------------------
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
void updatePreviewImage (const PreviewRgba[]);
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
//-----------------------------------------------------------------------
|
|
Packit |
0d464f |
// Rounding control for luminance/chroma images:
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
// If the output file contains luminance and chroma channels (WRITE_YC
|
|
Packit |
0d464f |
// or WRITE_YCA), then the the significands of the luminance and
|
|
Packit |
0d464f |
// chroma values are rounded to roundY and roundC bits respectively (see
|
|
Packit |
0d464f |
// function half::round()). Rounding improves compression with minimal
|
|
Packit |
0d464f |
// image degradation, usually much less than the degradation caused by
|
|
Packit |
0d464f |
// chroma subsampling. By default, roundY is 7, and roundC is 5.
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
// If the output file contains RGB channels or a luminance channel,
|
|
Packit |
0d464f |
// without chroma, then no rounding is performed.
|
|
Packit |
0d464f |
//-----------------------------------------------------------------------
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
void setYCRounding (unsigned int roundY,
|
|
Packit |
0d464f |
unsigned int roundC);
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
//----------------------------------------------------
|
|
Packit |
0d464f |
// Break a scan line -- for testing and debugging only
|
|
Packit |
0d464f |
// (see Imf::OutputFile::updatePreviewImage()
|
|
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,
|
|
Packit |
0d464f |
int offset,
|
|
Packit |
0d464f |
int length,
|
|
Packit |
0d464f |
char c);
|
|
Packit |
0d464f |
private:
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
RgbaOutputFile (const RgbaOutputFile &); // not implemented
|
|
Packit |
0d464f |
RgbaOutputFile & operator = (const RgbaOutputFile &); // not implemented
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
class ToYca;
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
OutputFile * _outputFile;
|
|
Packit |
0d464f |
ToYca * _toYca;
|
|
Packit |
0d464f |
};
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
// RGBA input file
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
class IMF_EXPORT RgbaInputFile
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
public:
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
//-------------------------------------------------------
|
|
Packit |
0d464f |
// Constructor -- opens the file with the specified name,
|
|
Packit |
0d464f |
// destructor will automatically close the file.
|
|
Packit |
0d464f |
//-------------------------------------------------------
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
RgbaInputFile (const char name[], int numThreads = globalThreadCount());
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
//-----------------------------------------------------------
|
|
Packit |
0d464f |
// Constructor -- attaches the new RgbaInputFile object to a
|
|
Packit |
0d464f |
// file that has already been opened by the caller.
|
|
Packit |
0d464f |
// Destroying the RgbaInputFile object will not automatically
|
|
Packit |
0d464f |
// close the file.
|
|
Packit |
0d464f |
//-----------------------------------------------------------
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
RgbaInputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is, int numThreads = globalThreadCount());
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
//--------------------------------------------------------------
|
|
Packit |
0d464f |
// Constructors -- the same as the previous two, but the names
|
|
Packit |
0d464f |
// of the red, green, blue, alpha, luminance and chroma channels
|
|
Packit |
0d464f |
// are expected to be layerName.R, layerName.G, etc.
|
|
Packit |
0d464f |
//--------------------------------------------------------------
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
RgbaInputFile (const char name[],
|
|
Packit |
0d464f |
const std::string &layerName,
|
|
Packit |
0d464f |
int numThreads = globalThreadCount());
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
RgbaInputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is,
|
|
Packit |
0d464f |
const std::string &layerName,
|
|
Packit |
0d464f |
int numThreads = globalThreadCount());
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
//-----------
|
|
Packit |
0d464f |
// Destructor
|
|
Packit |
0d464f |
//-----------
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
virtual ~RgbaInputFile ();
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
//-----------------------------------------------------
|
|
Packit |
0d464f |
// Define a frame buffer as the pixel data destination:
|
|
Packit |
0d464f |
// Pixel (x, y) is at address
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
// base + x * xStride + y * yStride
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
//-----------------------------------------------------
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
void setFrameBuffer (Rgba *base,
|
|
Packit |
0d464f |
size_t xStride,
|
|
Packit |
0d464f |
size_t yStride);
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
//----------------------------------------------------------------
|
|
Packit |
0d464f |
// Switch to a different layer -- subsequent calls to readPixels()
|
|
Packit |
0d464f |
// will read channels layerName.R, layerName.G, etc.
|
|
Packit |
0d464f |
// After each call to setLayerName(), setFrameBuffer() must be
|
|
Packit |
0d464f |
// called at least once before the next call to readPixels().
|
|
Packit |
0d464f |
//----------------------------------------------------------------
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
void setLayerName (const std::string &layerName);
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
//-------------------------------------------
|
|
Packit |
0d464f |
// Read pixel data (see class Imf::InputFile)
|
|
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 |
// Access to the file header
|
|
Packit |
0d464f |
//--------------------------
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
const Header & header () const;
|
|
Packit |
0d464f |
const FrameBuffer & frameBuffer () const;
|
|
Packit |
0d464f |
const IMATH_NAMESPACE::Box2i & displayWindow () const;
|
|
Packit |
0d464f |
const IMATH_NAMESPACE::Box2i & dataWindow () const;
|
|
Packit |
0d464f |
float pixelAspectRatio () const;
|
|
Packit |
0d464f |
const IMATH_NAMESPACE::V2f screenWindowCenter () const;
|
|
Packit |
0d464f |
float screenWindowWidth () const;
|
|
Packit |
0d464f |
LineOrder lineOrder () const;
|
|
Packit |
0d464f |
Compression compression () const;
|
|
Packit |
0d464f |
RgbaChannels channels () const;
|
|
Packit |
0d464f |
const char * fileName () const;
|
|
Packit |
0d464f |
bool isComplete () 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 |
private:
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
RgbaInputFile (const RgbaInputFile &); // not implemented
|
|
Packit |
0d464f |
RgbaInputFile & operator = (const RgbaInputFile &); // not implemented
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
class FromYca;
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
InputFile * _inputFile;
|
|
Packit |
0d464f |
FromYca * _fromYca;
|
|
Packit |
0d464f |
std::string _channelNamePrefix;
|
|
Packit |
0d464f |
};
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
#endif
|