Path: blob/master/3rdparty/openexr/IlmImf/ImfAcesFile.h
16337 views
///////////////////////////////////////////////////////////////////////////1//2// Copyright (c) 2007, Industrial Light & Magic, a division of Lucas3// Digital Ltd. LLC4//5// All rights reserved.6//7// Redistribution and use in source and binary forms, with or without8// modification, are permitted provided that the following conditions are9// met:10// * Redistributions of source code must retain the above copyright11// notice, this list of conditions and the following disclaimer.12// * Redistributions in binary form must reproduce the above13// copyright notice, this list of conditions and the following disclaimer14// in the documentation and/or other materials provided with the15// distribution.16// * Neither the name of Industrial Light & Magic nor the names of17// its contributors may be used to endorse or promote products derived18// from this software without specific prior written permission.19//20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS21// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT22// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR23// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT24// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT26// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,27// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY28// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT29// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE30// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.31//32///////////////////////////////////////////////////////////////////////////33343536#ifndef INCLUDED_IMF_ACES_FILE_H37#define INCLUDED_IMF_ACES_FILE_H383940//-----------------------------------------------------------------------------41//42// ACES image file I/O.43//44// This header file declares two classes that directly support45// image file input and output according to the Academy Image46// Interchange Framework.47//48// The Academy Image Interchange file format is a subset of OpenEXR:49//50// - Images are stored as scanlines. Tiles are not allowed.51//52// - Images contain three color channels, either53// R, G, B (red, green, blue) or54// Y, RY, BY (luminance, sub-sampled chroma)55//56// - Images may optionally contain an alpha channel.57//58// - Only three compression types are allowed:59// - NO_COMPRESSION (file is not compressed)60// - PIZ_COMPRESSION (lossless)61// - B44A_COMPRESSION (lossy)62//63// - The "chromaticities" header attribute must specify64// the ACES RGB primaries and white point.65//66// class AcesOutputFile writes an OpenEXR file, enforcing the67// restrictions listed above. Pixel data supplied by application68// software must already be in the ACES RGB space.69//70// class AcesInputFile reads an OpenEXR file. Pixel data delivered71// to application software is guaranteed to be in the ACES RGB space.72// If the RGB space of the file is not the same as the ACES space,73// then the pixels are automatically converted: the pixels are74// converted to CIE XYZ, a color adaptation transform shifts the75// white point, and the result is converted to ACES RGB.76//77//-----------------------------------------------------------------------------7879#include <ImfHeader.h>80#include <ImfRgba.h>81#include "ImathVec.h"82#include "ImathBox.h"83#include <ImfThreading.h>84#include <string>8586namespace Imf {878889class RgbaOutputFile;90class RgbaInputFile;91struct PreviewRgba;92struct Chromaticities;9394//95// ACES red, green, blue and white-point chromaticities.96//9798const Chromaticities & acesChromaticities ();99100101//102// ACES output file.103//104105class AcesOutputFile106{107public:108109//---------------------------------------------------110// Constructor -- header is constructed by the caller111//---------------------------------------------------112113AcesOutputFile (const std::string &name,114const Header &header,115RgbaChannels rgbaChannels = WRITE_RGBA,116int numThreads = globalThreadCount());117118119//----------------------------------------------------120// Constructor -- header is constructed by the caller,121// file is opened by the caller, destructor will not122// automatically close the file.123//----------------------------------------------------124125AcesOutputFile (OStream &os,126const Header &header,127RgbaChannels rgbaChannels = WRITE_RGBA,128int numThreads = globalThreadCount());129130131//----------------------------------------------------------------132// Constructor -- header data are explicitly specified as function133// call arguments (empty dataWindow means "same as displayWindow")134//----------------------------------------------------------------135136AcesOutputFile (const std::string &name,137const Imath::Box2i &displayWindow,138const Imath::Box2i &dataWindow = Imath::Box2i(),139RgbaChannels rgbaChannels = WRITE_RGBA,140float pixelAspectRatio = 1,141const Imath::V2f screenWindowCenter = Imath::V2f (0, 0),142float screenWindowWidth = 1,143LineOrder lineOrder = INCREASING_Y,144Compression compression = PIZ_COMPRESSION,145int numThreads = globalThreadCount());146147148//-----------------------------------------------149// Constructor -- like the previous one, but both150// the display window and the data window are151// Box2i (V2i (0, 0), V2i (width - 1, height -1))152//-----------------------------------------------153154AcesOutputFile (const std::string &name,155int width,156int height,157RgbaChannels rgbaChannels = WRITE_RGBA,158float pixelAspectRatio = 1,159const Imath::V2f screenWindowCenter = Imath::V2f (0, 0),160float screenWindowWidth = 1,161LineOrder lineOrder = INCREASING_Y,162Compression compression = PIZ_COMPRESSION,163int numThreads = globalThreadCount());164165166//-----------167// Destructor168//-----------169170virtual ~AcesOutputFile ();171172173//------------------------------------------------174// Define a frame buffer as the pixel data source:175// Pixel (x, y) is at address176//177// base + x * xStride + y * yStride178//179//------------------------------------------------180181void setFrameBuffer (const Rgba *base,182size_t xStride,183size_t yStride);184185186//-------------------------------------------------187// Write pixel data (see class Imf::OutputFile)188// The pixels are assumed to contain ACES RGB data.189//-------------------------------------------------190191void writePixels (int numScanLines = 1);192int currentScanLine () const;193194195//--------------------------196// Access to the file header197//--------------------------198199const Header & header () const;200const Imath::Box2i & displayWindow () const;201const Imath::Box2i & dataWindow () const;202float pixelAspectRatio () const;203const Imath::V2f screenWindowCenter () const;204float screenWindowWidth () const;205LineOrder lineOrder () const;206Compression compression () const;207RgbaChannels channels () const;208209210// --------------------------------------------------------------------211// Update the preview image (see Imf::OutputFile::updatePreviewImage())212// --------------------------------------------------------------------213214void updatePreviewImage (const PreviewRgba[]);215216217private:218219AcesOutputFile (const AcesOutputFile &); // not implemented220AcesOutputFile & operator = (const AcesOutputFile &); // not implemented221222class Data;223224Data * _data;225};226227228//229// ACES input file230//231232class AcesInputFile233{234public:235236//-------------------------------------------------------237// Constructor -- opens the file with the specified name,238// destructor will automatically close the file.239//-------------------------------------------------------240241AcesInputFile (const std::string &name,242int numThreads = globalThreadCount());243244245//-----------------------------------------------------------246// Constructor -- attaches the new AcesInputFile object to a247// file that has already been opened by the caller.248// Destroying the AcesInputFile object will not automatically249// close the file.250//-----------------------------------------------------------251252AcesInputFile (IStream &is,253int numThreads = globalThreadCount());254255256//-----------257// Destructor258//-----------259260virtual ~AcesInputFile ();261262263//-----------------------------------------------------264// Define a frame buffer as the pixel data destination:265// Pixel (x, y) is at address266//267// base + x * xStride + y * yStride268//269//-----------------------------------------------------270271void setFrameBuffer (Rgba *base,272size_t xStride,273size_t yStride);274275276//--------------------------------------------277// Read pixel data (see class Imf::InputFile)278// Pixels returned will contain ACES RGB data.279//--------------------------------------------280281void readPixels (int scanLine1, int scanLine2);282void readPixels (int scanLine);283284285//--------------------------286// Access to the file header287//--------------------------288289const Header & header () const;290const Imath::Box2i & displayWindow () const;291const Imath::Box2i & dataWindow () const;292float pixelAspectRatio () const;293const Imath::V2f screenWindowCenter () const;294float screenWindowWidth () const;295LineOrder lineOrder () const;296Compression compression () const;297RgbaChannels channels () const;298const char * fileName () const;299bool isComplete () const;300301302//----------------------------------303// Access to the file format version304//----------------------------------305306int version () const;307308private:309310AcesInputFile (const AcesInputFile &); // not implemented311AcesInputFile & operator = (const AcesInputFile &); // not implemented312313class Data;314315Data * _data;316};317318319} // namespace Imf320321#endif322323324