📄 imfheader.cpp
字号:
/////////////////////////////////////////////////////////////////////////////// Copyright (c) 2004, Industrial Light & Magic, a division of Lucas// Digital Ltd. LLC// // All rights reserved.// // Redistribution and use in source and binary forms, with or without// modification, are permitted provided that the following conditions are// met:// * Redistributions of source code must retain the above copyright// notice, this list of conditions and the following disclaimer.// * Redistributions in binary form must reproduce the above// copyright notice, this list of conditions and the following disclaimer// in the documentation and/or other materials provided with the// distribution.// * Neither the name of Industrial Light & Magic nor the names of// its contributors may be used to endorse or promote products derived// from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.///////////////////////////////////////////////////////////////////////////////-----------------------------------------------------------------------------//// class Header////-----------------------------------------------------------------------------#include <ImfHeader.h>#include <ImfStdIO.h>#include <ImfVersion.h>#include <ImfCompressor.h>#include <ImfMisc.h>#include <ImfBoxAttribute.h>#include <ImfChannelListAttribute.h>#include <ImfChromaticitiesAttribute.h>#include <ImfCompressionAttribute.h>#include <ImfDoubleAttribute.h>#include <ImfEnvmapAttribute.h>#include <ImfFloatAttribute.h>#include <ImfIntAttribute.h>#include <ImfKeyCodeAttribute.h>#include <ImfLineOrderAttribute.h>#include <ImfMatrixAttribute.h>#include <ImfOpaqueAttribute.h>#include <ImfPreviewImageAttribute.h>#include <ImfRationalAttribute.h>#include <ImfStringAttribute.h>#include <ImfTileDescriptionAttribute.h>#include <ImfTimeCodeAttribute.h>#include <ImfVecAttribute.h>#include "IlmThreadMutex.h"#include "Iex.h"#include <sstream>#include <stdlib.h>#include <time.h>namespace Imf {using Imath::Box2i;using Imath::V2i;using Imath::V2f;using IlmThread::Mutex;using IlmThread::Lock;namespace {int maxImageWidth = 0;int maxImageHeight = 0;int maxTileWidth = 0;int maxTileHeight = 0;voidinitialize (Header &header, const Box2i &displayWindow, const Box2i &dataWindow, float pixelAspectRatio, const V2f &screenWindowCenter, float screenWindowWidth, LineOrder lineOrder, Compression compression){ header.insert ("displayWindow", Box2iAttribute (displayWindow)); header.insert ("dataWindow", Box2iAttribute (dataWindow)); header.insert ("pixelAspectRatio", FloatAttribute (pixelAspectRatio)); header.insert ("screenWindowCenter", V2fAttribute (screenWindowCenter)); header.insert ("screenWindowWidth", FloatAttribute (screenWindowWidth)); header.insert ("lineOrder", LineOrderAttribute (lineOrder)); header.insert ("compression", CompressionAttribute (compression)); header.insert ("channels", ChannelListAttribute ());}} // namespaceHeader::Header (int width, int height, float pixelAspectRatio, const V2f &screenWindowCenter, float screenWindowWidth, LineOrder lineOrder, Compression compression): _map(){ staticInitialize(); Box2i displayWindow (V2i (0, 0), V2i (width - 1, height - 1)); initialize (*this, displayWindow, displayWindow, pixelAspectRatio, screenWindowCenter, screenWindowWidth, lineOrder, compression);}Header::Header (int width, int height, const Box2i &dataWindow, float pixelAspectRatio, const V2f &screenWindowCenter, float screenWindowWidth, LineOrder lineOrder, Compression compression): _map(){ staticInitialize(); Box2i displayWindow (V2i (0, 0), V2i (width - 1, height - 1)); initialize (*this, displayWindow, dataWindow, pixelAspectRatio, screenWindowCenter, screenWindowWidth, lineOrder, compression);}Header::Header (const Box2i &displayWindow, const Box2i &dataWindow, float pixelAspectRatio, const V2f &screenWindowCenter, float screenWindowWidth, LineOrder lineOrder, Compression compression): _map(){ staticInitialize(); initialize (*this, displayWindow, dataWindow, pixelAspectRatio, screenWindowCenter, screenWindowWidth, lineOrder, compression);}Header::Header (const Header &other): _map(){ for (AttributeMap::const_iterator i = other._map.begin(); i != other._map.end(); ++i) { insert (*i->first, *i->second); }}Header::~Header (){ for (AttributeMap::iterator i = _map.begin(); i != _map.end(); ++i) { delete i->second; }}Header & Header::operator = (const Header &other){ if (this != &other) { for (AttributeMap::iterator i = _map.begin(); i != _map.end(); ++i) { delete i->second; } _map.erase (_map.begin(), _map.end()); for (AttributeMap::const_iterator i = other._map.begin(); i != other._map.end(); ++i) { insert (*i->first, *i->second); } } return *this;}voidHeader::insert (const char name[], const Attribute &attribute){ if (name[0] == 0) THROW (Iex::ArgExc, "Image attribute name cannot be an empty string."); AttributeMap::iterator i = _map.find (name); if (i == _map.end()) { Attribute *tmp = attribute.copy(); try { _map[name] = tmp; } catch (...) { delete tmp; throw; } } else { if (strcmp (i->second->typeName(), attribute.typeName())) THROW (Iex::TypeExc, "Cannot assign a value of " "type \"" << attribute.typeName() << "\" " "to image attribute \"" << name << "\" of " "type \"" << i->second->typeName() << "\"."); Attribute *tmp = attribute.copy(); delete i->second; i->second = tmp; }}Attribute & Header::operator [] (const char name[]){ AttributeMap::iterator i = _map.find (name); if (i == _map.end()) THROW (Iex::ArgExc, "Cannot find image attribute \"" << name << "\"."); return *i->second;}const Attribute & Header::operator [] (const char name[]) const{ AttributeMap::const_iterator i = _map.find (name); if (i == _map.end()) THROW (Iex::ArgExc, "Cannot find image attribute \"" << name << "\"."); return *i->second;}Header::IteratorHeader::begin (){ return _map.begin();}Header::ConstIteratorHeader::begin () const{ return _map.begin();}Header::IteratorHeader::end (){ return _map.end();}Header::ConstIteratorHeader::end () const{ return _map.end();}Header::IteratorHeader::find (const char name[]){ return _map.find (name);}Header::ConstIteratorHeader::find (const char name[]) const{ return _map.find (name);}Imath::Box2i & Header::displayWindow (){ return static_cast <Box2iAttribute &> ((*this)["displayWindow"]).value();}const Imath::Box2i &Header::displayWindow () const{ return static_cast <const Box2iAttribute &> ((*this)["displayWindow"]).value();}Imath::Box2i & Header::dataWindow (){ return static_cast <Box2iAttribute &> ((*this)["dataWindow"]).value();}const Imath::Box2i &Header::dataWindow () const{ return static_cast <const Box2iAttribute &> ((*this)["dataWindow"]).value();}float & Header::pixelAspectRatio (){ return static_cast <FloatAttribute &> ((*this)["pixelAspectRatio"]).value();}const float & Header::pixelAspectRatio () const{ return static_cast <const FloatAttribute &> ((*this)["pixelAspectRatio"]).value();}Imath::V2f & Header::screenWindowCenter (){ return static_cast <V2fAttribute &> ((*this)["screenWindowCenter"]).value();}const Imath::V2f & Header::screenWindowCenter () const{ return static_cast <const V2fAttribute &> ((*this)["screenWindowCenter"]).value();}float & Header::screenWindowWidth (){ return static_cast <FloatAttribute &> ((*this)["screenWindowWidth"]).value();}const float & Header::screenWindowWidth () const{ return static_cast <const FloatAttribute &> ((*this)["screenWindowWidth"]).value();}ChannelList & Header::channels (){ return static_cast <ChannelListAttribute &> ((*this)["channels"]).value();}const ChannelList & Header::channels () const{ return static_cast <const ChannelListAttribute &> ((*this)["channels"]).value();}LineOrder &Header::lineOrder (){ return static_cast <LineOrderAttribute &> ((*this)["lineOrder"]).value();}const LineOrder &Header::lineOrder () const{ return static_cast <const LineOrderAttribute &> ((*this)["lineOrder"]).value();}Compression &Header::compression (){ return static_cast <CompressionAttribute &> ((*this)["compression"]).value();}const Compression &Header::compression () const{ return static_cast <const CompressionAttribute &> ((*this)["compression"]).value();}voidHeader::setTileDescription(const TileDescription& td){ insert ("tiles", TileDescriptionAttribute (td));}boolHeader::hasTileDescription() const{ return findTypedAttribute <TileDescriptionAttribute> ("tiles") != 0;}TileDescription &Header::tileDescription (){ return typedAttribute <TileDescriptionAttribute> ("tiles").value();}const TileDescription &Header::tileDescription () const{ return typedAttribute <TileDescriptionAttribute> ("tiles").value();}void Header::setPreviewImage (const PreviewImage &pi){ insert ("preview", PreviewImageAttribute (pi));}PreviewImage &Header::previewImage (){ return typedAttribute <PreviewImageAttribute> ("preview").value();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -