diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..43de5ff --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +CXXFLAGS=-std=c++1y -Wall -Wno-sign-compare -O2 -g +LDFLAGS=-lIlmImf -g +CC=g++ + +all: exrflatten +exrflatten: exrflatten.o + diff --git a/OpenEXR/include/OpenEXR/Iex.h b/OpenEXR/include/OpenEXR/Iex.h new file mode 100644 index 0000000..a0fd31d --- /dev/null +++ b/OpenEXR/include/OpenEXR/Iex.h @@ -0,0 +1,60 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IEX_H +#define INCLUDED_IEX_H + + +//-------------------------------- +// +// Exception handling +// +//-------------------------------- + + +#include "IexMacros.h" +#include "IexBaseExc.h" +#include "IexMathExc.h" +#include "IexThrowErrnoExc.h" + +// Note that we do not include file IexErrnoExc.h here. That file +// defines over 150 classes and significantly slows down compilation. +// If you throw ErrnoExc exceptions using the throwErrnoExc() function, +// you don't need IexErrnoExc.h. You have to include IexErrnoExc.h +// only if you want to catch specific subclasses of ErrnoExc. + + +#endif diff --git a/OpenEXR/include/OpenEXR/IexBaseExc.h b/OpenEXR/include/OpenEXR/IexBaseExc.h new file mode 100644 index 0000000..bf016f7 --- /dev/null +++ b/OpenEXR/include/OpenEXR/IexBaseExc.h @@ -0,0 +1,264 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IEXBASEEXC_H +#define INCLUDED_IEXBASEEXC_H + +#include "IexNamespace.h" +#include "IexExport.h" + +//---------------------------------------------------------- +// +// A general exception base class, and a few +// useful exceptions derived from the base class. +// +//---------------------------------------------------------- + +#include +#include +#include + +IEX_INTERNAL_NAMESPACE_HEADER_ENTER + + +//------------------------------- +// Our most basic exception class +//------------------------------- + +class BaseExc: public std::string, public std::exception +{ + public: + + //---------------------------- + // Constructors and destructor + //---------------------------- + + IEX_EXPORT BaseExc (const char *s = 0) throw(); // std::string (s) + IEX_EXPORT BaseExc (const std::string &s) throw(); // std::string (s) + IEX_EXPORT BaseExc (std::stringstream &s) throw(); // std::string (s.str()) + + IEX_EXPORT BaseExc (const BaseExc &be) throw(); + IEX_EXPORT virtual ~BaseExc () throw (); + + //-------------------------------------------- + // what() method -- e.what() returns e.c_str() + //-------------------------------------------- + + IEX_EXPORT virtual const char * what () const throw (); + + + //-------------------------------------------------- + // Convenient methods to change the exception's text + //-------------------------------------------------- + + IEX_EXPORT BaseExc & assign (std::stringstream &s); // assign (s.str()) + IEX_EXPORT BaseExc & operator = (std::stringstream &s); + + IEX_EXPORT BaseExc & append (std::stringstream &s); // append (s.str()) + IEX_EXPORT BaseExc & operator += (std::stringstream &s); + + + //-------------------------------------------------- + // These methods from the base class get obscured by + // the definitions above. + //-------------------------------------------------- + + IEX_EXPORT BaseExc & assign (const char *s); + IEX_EXPORT BaseExc & operator = (const char *s); + + IEX_EXPORT BaseExc & append (const char *s); + IEX_EXPORT BaseExc & operator += (const char *s); + + + //-------------------------------------------------- + // Stack trace for the point at which the exception + // was thrown. The stack trace will be an empty + // string unless a working stack-tracing routine + // has been installed (see below, setStackTracer()). + //-------------------------------------------------- + + IEX_EXPORT const std::string & stackTrace () const; + + private: + + std::string _stackTrace; +}; + + +//----------------------------------------------------- +// A macro to save typing when declararing an exception +// class derived directly or indirectly from BaseExc: +//----------------------------------------------------- + +#define DEFINE_EXC_EXP(exp, name, base) \ + class exp name: public base \ + { \ + public: \ + name() throw(): base (0) {} \ + name (const char* text) throw(): base (text) {} \ + name (const std::string &text) throw(): base (text) {} \ + name (std::stringstream &text) throw(): base (text) {} \ + ~name() throw() { } \ + }; + +// For backward compatibility. +#define DEFINE_EXC(name, base) DEFINE_EXC_EXP(, name, base) + + +//-------------------------------------------------------- +// Some exceptions which should be useful in most programs +//-------------------------------------------------------- +DEFINE_EXC_EXP (IEX_EXPORT, ArgExc, BaseExc) // Invalid arguments to a function call + +DEFINE_EXC_EXP (IEX_EXPORT, LogicExc, BaseExc) // General error in a program's logic, + // for example, a function was called + // in a context where the call does + // not make sense. + +DEFINE_EXC_EXP (IEX_EXPORT, InputExc, BaseExc) // Invalid input data, e.g. from a file + +DEFINE_EXC_EXP (IEX_EXPORT, IoExc, BaseExc) // Input or output operation failed + +DEFINE_EXC_EXP (IEX_EXPORT, MathExc, BaseExc) // Arithmetic exception; more specific + // exceptions derived from this class + // are defined in ExcMath.h + +DEFINE_EXC_EXP (IEX_EXPORT, ErrnoExc, BaseExc) // Base class for exceptions corresponding + // to errno values (see errno.h); more + // specific exceptions derived from this + // class are defined in ExcErrno.h + +DEFINE_EXC_EXP (IEX_EXPORT, NoImplExc, BaseExc) // Missing method exception e.g. from a + // call to a method that is only partially + // or not at all implemented. A reminder + // to lazy software people to get back + // to work. + +DEFINE_EXC_EXP (IEX_EXPORT, NullExc, BaseExc) // A pointer is inappropriately null. + +DEFINE_EXC_EXP (IEX_EXPORT, TypeExc, BaseExc) // An object is an inappropriate type, + // i.e. a dynamnic_cast failed. + + +//---------------------------------------------------------------------- +// Stack-tracing support: +// +// setStackTracer(st) +// +// installs a stack-tracing routine, st, which will be called from +// class BaseExc's constructor every time an exception derived from +// BaseExc is thrown. The stack-tracing routine should return a +// string that contains a printable representation of the program's +// current call stack. This string will be stored in the BaseExc +// object; the string is accesible via the BaseExc::stackTrace() +// method. +// +// setStackTracer(0) +// +// removes the current stack tracing routine. When an exception +// derived from BaseExc is thrown, the stack trace string stored +// in the BaseExc object will be empty. +// +// stackTracer() +// +// returns a pointer to the current stack-tracing routine, or 0 +// if there is no current stack stack-tracing routine. +// +//---------------------------------------------------------------------- + +typedef std::string (* StackTracer) (); + +IEX_EXPORT void setStackTracer (StackTracer stackTracer); +IEX_EXPORT StackTracer stackTracer (); + + +//----------------- +// Inline functions +//----------------- + +inline BaseExc & +BaseExc::operator = (std::stringstream &s) +{ + return assign (s); +} + + +inline BaseExc & +BaseExc::operator += (std::stringstream &s) +{ + return append (s); +} + + +inline BaseExc & +BaseExc::assign (const char *s) +{ + std::string::assign(s); + return *this; +} + + +inline BaseExc & +BaseExc::operator = (const char *s) +{ + return assign(s); +} + + +inline BaseExc & +BaseExc::append (const char *s) +{ + std::string::append(s); + return *this; +} + + +inline BaseExc & +BaseExc::operator += (const char *s) +{ + return append(s); +} + + +inline const std::string & +BaseExc::stackTrace () const +{ + return _stackTrace; +} + + +IEX_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_IEXBASEEXC_H diff --git a/OpenEXR/include/OpenEXR/IexErrnoExc.h b/OpenEXR/include/OpenEXR/IexErrnoExc.h new file mode 100644 index 0000000..027c7a4 --- /dev/null +++ b/OpenEXR/include/OpenEXR/IexErrnoExc.h @@ -0,0 +1,208 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IEXERRNOEXC_H +#define INCLUDED_IEXERRNOEXC_H + +//---------------------------------------------------------------- +// +// Exceptions which correspond to "errno" error codes. +// +//---------------------------------------------------------------- + +#include "IexBaseExc.h" + +IEX_INTERNAL_NAMESPACE_HEADER_ENTER + +DEFINE_EXC (EpermExc, ErrnoExc) +DEFINE_EXC (EnoentExc, ErrnoExc) +DEFINE_EXC (EsrchExc, ErrnoExc) +DEFINE_EXC (EintrExc, ErrnoExc) +DEFINE_EXC (EioExc, ErrnoExc) +DEFINE_EXC (EnxioExc, ErrnoExc) +DEFINE_EXC (E2bigExc, ErrnoExc) +DEFINE_EXC (EnoexecExc, ErrnoExc) +DEFINE_EXC (EbadfExc, ErrnoExc) +DEFINE_EXC (EchildExc, ErrnoExc) +DEFINE_EXC (EagainExc, ErrnoExc) +DEFINE_EXC (EnomemExc, ErrnoExc) +DEFINE_EXC (EaccesExc, ErrnoExc) +DEFINE_EXC (EfaultExc, ErrnoExc) +DEFINE_EXC (EnotblkExc, ErrnoExc) +DEFINE_EXC (EbusyExc, ErrnoExc) +DEFINE_EXC (EexistExc, ErrnoExc) +DEFINE_EXC (ExdevExc, ErrnoExc) +DEFINE_EXC (EnodevExc, ErrnoExc) +DEFINE_EXC (EnotdirExc, ErrnoExc) +DEFINE_EXC (EisdirExc, ErrnoExc) +DEFINE_EXC (EinvalExc, ErrnoExc) +DEFINE_EXC (EnfileExc, ErrnoExc) +DEFINE_EXC (EmfileExc, ErrnoExc) +DEFINE_EXC (EnottyExc, ErrnoExc) +DEFINE_EXC (EtxtbsyExc, ErrnoExc) +DEFINE_EXC (EfbigExc, ErrnoExc) +DEFINE_EXC (EnospcExc, ErrnoExc) +DEFINE_EXC (EspipeExc, ErrnoExc) +DEFINE_EXC (ErofsExc, ErrnoExc) +DEFINE_EXC (EmlinkExc, ErrnoExc) +DEFINE_EXC (EpipeExc, ErrnoExc) +DEFINE_EXC (EdomExc, ErrnoExc) +DEFINE_EXC (ErangeExc, ErrnoExc) +DEFINE_EXC (EnomsgExc, ErrnoExc) +DEFINE_EXC (EidrmExc, ErrnoExc) +DEFINE_EXC (EchrngExc, ErrnoExc) +DEFINE_EXC (El2nsyncExc, ErrnoExc) +DEFINE_EXC (El3hltExc, ErrnoExc) +DEFINE_EXC (El3rstExc, ErrnoExc) +DEFINE_EXC (ElnrngExc, ErrnoExc) +DEFINE_EXC (EunatchExc, ErrnoExc) +DEFINE_EXC (EnocsiExc, ErrnoExc) +DEFINE_EXC (El2hltExc, ErrnoExc) +DEFINE_EXC (EdeadlkExc, ErrnoExc) +DEFINE_EXC (EnolckExc, ErrnoExc) +DEFINE_EXC (EbadeExc, ErrnoExc) +DEFINE_EXC (EbadrExc, ErrnoExc) +DEFINE_EXC (ExfullExc, ErrnoExc) +DEFINE_EXC (EnoanoExc, ErrnoExc) +DEFINE_EXC (EbadrqcExc, ErrnoExc) +DEFINE_EXC (EbadsltExc, ErrnoExc) +DEFINE_EXC (EdeadlockExc, ErrnoExc) +DEFINE_EXC (EbfontExc, ErrnoExc) +DEFINE_EXC (EnostrExc, ErrnoExc) +DEFINE_EXC (EnodataExc, ErrnoExc) +DEFINE_EXC (EtimeExc, ErrnoExc) +DEFINE_EXC (EnosrExc, ErrnoExc) +DEFINE_EXC (EnonetExc, ErrnoExc) +DEFINE_EXC (EnopkgExc, ErrnoExc) +DEFINE_EXC (EremoteExc, ErrnoExc) +DEFINE_EXC (EnolinkExc, ErrnoExc) +DEFINE_EXC (EadvExc, ErrnoExc) +DEFINE_EXC (EsrmntExc, ErrnoExc) +DEFINE_EXC (EcommExc, ErrnoExc) +DEFINE_EXC (EprotoExc, ErrnoExc) +DEFINE_EXC (EmultihopExc, ErrnoExc) +DEFINE_EXC (EbadmsgExc, ErrnoExc) +DEFINE_EXC (EnametoolongExc, ErrnoExc) +DEFINE_EXC (EoverflowExc, ErrnoExc) +DEFINE_EXC (EnotuniqExc, ErrnoExc) +DEFINE_EXC (EbadfdExc, ErrnoExc) +DEFINE_EXC (EremchgExc, ErrnoExc) +DEFINE_EXC (ElibaccExc, ErrnoExc) +DEFINE_EXC (ElibbadExc, ErrnoExc) +DEFINE_EXC (ElibscnExc, ErrnoExc) +DEFINE_EXC (ElibmaxExc, ErrnoExc) +DEFINE_EXC (ElibexecExc, ErrnoExc) +DEFINE_EXC (EilseqExc, ErrnoExc) +DEFINE_EXC (EnosysExc, ErrnoExc) +DEFINE_EXC (EloopExc, ErrnoExc) +DEFINE_EXC (ErestartExc, ErrnoExc) +DEFINE_EXC (EstrpipeExc, ErrnoExc) +DEFINE_EXC (EnotemptyExc, ErrnoExc) +DEFINE_EXC (EusersExc, ErrnoExc) +DEFINE_EXC (EnotsockExc, ErrnoExc) +DEFINE_EXC (EdestaddrreqExc, ErrnoExc) +DEFINE_EXC (EmsgsizeExc, ErrnoExc) +DEFINE_EXC (EprototypeExc, ErrnoExc) +DEFINE_EXC (EnoprotooptExc, ErrnoExc) +DEFINE_EXC (EprotonosupportExc, ErrnoExc) +DEFINE_EXC (EsocktnosupportExc, ErrnoExc) +DEFINE_EXC (EopnotsuppExc, ErrnoExc) +DEFINE_EXC (EpfnosupportExc, ErrnoExc) +DEFINE_EXC (EafnosupportExc, ErrnoExc) +DEFINE_EXC (EaddrinuseExc, ErrnoExc) +DEFINE_EXC (EaddrnotavailExc, ErrnoExc) +DEFINE_EXC (EnetdownExc, ErrnoExc) +DEFINE_EXC (EnetunreachExc, ErrnoExc) +DEFINE_EXC (EnetresetExc, ErrnoExc) +DEFINE_EXC (EconnabortedExc, ErrnoExc) +DEFINE_EXC (EconnresetExc, ErrnoExc) +DEFINE_EXC (EnobufsExc, ErrnoExc) +DEFINE_EXC (EisconnExc, ErrnoExc) +DEFINE_EXC (EnotconnExc, ErrnoExc) +DEFINE_EXC (EshutdownExc, ErrnoExc) +DEFINE_EXC (EtoomanyrefsExc, ErrnoExc) +DEFINE_EXC (EtimedoutExc, ErrnoExc) +DEFINE_EXC (EconnrefusedExc, ErrnoExc) +DEFINE_EXC (EhostdownExc, ErrnoExc) +DEFINE_EXC (EhostunreachExc, ErrnoExc) +DEFINE_EXC (EalreadyExc, ErrnoExc) +DEFINE_EXC (EinprogressExc, ErrnoExc) +DEFINE_EXC (EstaleExc, ErrnoExc) +DEFINE_EXC (EioresidExc, ErrnoExc) +DEFINE_EXC (EucleanExc, ErrnoExc) +DEFINE_EXC (EnotnamExc, ErrnoExc) +DEFINE_EXC (EnavailExc, ErrnoExc) +DEFINE_EXC (EisnamExc, ErrnoExc) +DEFINE_EXC (EremoteioExc, ErrnoExc) +DEFINE_EXC (EinitExc, ErrnoExc) +DEFINE_EXC (EremdevExc, ErrnoExc) +DEFINE_EXC (EcanceledExc, ErrnoExc) +DEFINE_EXC (EnolimfileExc, ErrnoExc) +DEFINE_EXC (EproclimExc, ErrnoExc) +DEFINE_EXC (EdisjointExc, ErrnoExc) +DEFINE_EXC (EnologinExc, ErrnoExc) +DEFINE_EXC (EloginlimExc, ErrnoExc) +DEFINE_EXC (EgrouploopExc, ErrnoExc) +DEFINE_EXC (EnoattachExc, ErrnoExc) +DEFINE_EXC (EnotsupExc, ErrnoExc) +DEFINE_EXC (EnoattrExc, ErrnoExc) +DEFINE_EXC (EdircorruptedExc, ErrnoExc) +DEFINE_EXC (EdquotExc, ErrnoExc) +DEFINE_EXC (EnfsremoteExc, ErrnoExc) +DEFINE_EXC (EcontrollerExc, ErrnoExc) +DEFINE_EXC (EnotcontrollerExc, ErrnoExc) +DEFINE_EXC (EenqueuedExc, ErrnoExc) +DEFINE_EXC (EnotenqueuedExc, ErrnoExc) +DEFINE_EXC (EjoinedExc, ErrnoExc) +DEFINE_EXC (EnotjoinedExc, ErrnoExc) +DEFINE_EXC (EnoprocExc, ErrnoExc) +DEFINE_EXC (EmustrunExc, ErrnoExc) +DEFINE_EXC (EnotstoppedExc, ErrnoExc) +DEFINE_EXC (EclockcpuExc, ErrnoExc) +DEFINE_EXC (EinvalstateExc, ErrnoExc) +DEFINE_EXC (EnoexistExc, ErrnoExc) +DEFINE_EXC (EendofminorExc, ErrnoExc) +DEFINE_EXC (EbufsizeExc, ErrnoExc) +DEFINE_EXC (EemptyExc, ErrnoExc) +DEFINE_EXC (EnointrgroupExc, ErrnoExc) +DEFINE_EXC (EinvalmodeExc, ErrnoExc) +DEFINE_EXC (EcantextentExc, ErrnoExc) +DEFINE_EXC (EinvaltimeExc, ErrnoExc) +DEFINE_EXC (EdestroyedExc, ErrnoExc) + +IEX_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/IexExport.h b/OpenEXR/include/OpenEXR/IexExport.h new file mode 100644 index 0000000..270c1cf --- /dev/null +++ b/OpenEXR/include/OpenEXR/IexExport.h @@ -0,0 +1,51 @@ +#ifndef IEXEXPORT_H +#define IEXEXPORT_H + +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + +#if defined(OPENEXR_DLL) + #if defined(IEX_EXPORTS) + #define IEX_EXPORT __declspec(dllexport) + #else + #define IEX_EXPORT __declspec(dllimport) + #endif + #define IEX_EXPORT_CONST +#else + #define IEX_EXPORT + #define IEX_EXPORT_CONST const +#endif + +#endif // #ifndef IEXEXPORT_H + diff --git a/OpenEXR/include/OpenEXR/IexForward.h b/OpenEXR/include/OpenEXR/IexForward.h new file mode 100644 index 0000000..743771c --- /dev/null +++ b/OpenEXR/include/OpenEXR/IexForward.h @@ -0,0 +1,229 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDED_IEXFORWARD_H +#define INCLUDED_IEXFORWARD_H + +#include "IexNamespace.h" + +IEX_INTERNAL_NAMESPACE_HEADER_ENTER + +// +// Base exceptions. +// + +class BaseExc; +class ArgExc; +class LogicExc; +class InputExc; +class IoExc; +class MathExc; +class ErrnoExc; +class NoImplExc; +class NullExc; +class TypeExc; + +// +// Math exceptions. +// + +class OverflowExc; +class UnderflowExc; +class DivzeroExc; +class InexactExc; +class InvalidFpOpExc; + +// +// Errno exceptions. +// + +class EpermExc; +class EnoentExc; +class EsrchExc; +class EintrExc; +class EioExc; +class EnxioExc; +class E2bigExc; +class EnoexecExc; +class EbadfExc; +class EchildExc; +class EagainExc; +class EnomemExc; +class EaccesExc; +class EfaultExc; +class EnotblkExc; +class EbusyExc; +class EexistExc; +class ExdevExc; +class EnodevExc; +class EnotdirExc; +class EisdirExc; +class EinvalExc; +class EnfileExc; +class EmfileExc; +class EnottyExc; +class EtxtbsyExc; +class EfbigExc; +class EnospcExc; +class EspipeExc; +class ErofsExc; +class EmlinkExc; +class EpipeExc; +class EdomExc; +class ErangeExc; +class EnomsgExc; +class EidrmExc; +class EchrngExc; +class El2nsyncExc; +class El3hltExc; +class El3rstExc; +class ElnrngExc; +class EunatchExc; +class EnocsiExc; +class El2hltExc; +class EdeadlkExc; +class EnolckExc; +class EbadeExc; +class EbadrExc; +class ExfullExc; +class EnoanoExc; +class EbadrqcExc; +class EbadsltExc; +class EdeadlockExc; +class EbfontExc; +class EnostrExc; +class EnodataExc; +class EtimeExc; +class EnosrExc; +class EnonetExc; +class EnopkgExc; +class EremoteExc; +class EnolinkExc; +class EadvExc; +class EsrmntExc; +class EcommExc; +class EprotoExc; +class EmultihopExc; +class EbadmsgExc; +class EnametoolongExc; +class EoverflowExc; +class EnotuniqExc; +class EbadfdExc; +class EremchgExc; +class ElibaccExc; +class ElibbadExc; +class ElibscnExc; +class ElibmaxExc; +class ElibexecExc; +class EilseqExc; +class EnosysExc; +class EloopExc; +class ErestartExc; +class EstrpipeExc; +class EnotemptyExc; +class EusersExc; +class EnotsockExc; +class EdestaddrreqExc; +class EmsgsizeExc; +class EprototypeExc; +class EnoprotooptExc; +class EprotonosupportExc; +class EsocktnosupportExc; +class EopnotsuppExc; +class EpfnosupportExc; +class EafnosupportExc; +class EaddrinuseExc; +class EaddrnotavailExc; +class EnetdownExc; +class EnetunreachExc; +class EnetresetExc; +class EconnabortedExc; +class EconnresetExc; +class EnobufsExc; +class EisconnExc; +class EnotconnExc; +class EshutdownExc; +class EtoomanyrefsExc; +class EtimedoutExc; +class EconnrefusedExc; +class EhostdownExc; +class EhostunreachExc; +class EalreadyExc; +class EinprogressExc; +class EstaleExc; +class EioresidExc; +class EucleanExc; +class EnotnamExc; +class EnavailExc; +class EisnamExc; +class EremoteioExc; +class EinitExc; +class EremdevExc; +class EcanceledExc; +class EnolimfileExc; +class EproclimExc; +class EdisjointExc; +class EnologinExc; +class EloginlimExc; +class EgrouploopExc; +class EnoattachExc; +class EnotsupExc; +class EnoattrExc; +class EdircorruptedExc; +class EdquotExc; +class EnfsremoteExc; +class EcontrollerExc; +class EnotcontrollerExc; +class EenqueuedExc; +class EnotenqueuedExc; +class EjoinedExc; +class EnotjoinedExc; +class EnoprocExc; +class EmustrunExc; +class EnotstoppedExc; +class EclockcpuExc; +class EinvalstateExc; +class EnoexistExc; +class EendofminorExc; +class EbufsizeExc; +class EemptyExc; +class EnointrgroupExc; +class EinvalmodeExc; +class EcantextentExc; +class EinvaltimeExc; +class EdestroyedExc; + +IEX_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_IEXFORWARD_H diff --git a/OpenEXR/include/OpenEXR/IexMacros.h b/OpenEXR/include/OpenEXR/IexMacros.h new file mode 100644 index 0000000..18d37bd --- /dev/null +++ b/OpenEXR/include/OpenEXR/IexMacros.h @@ -0,0 +1,170 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IEXMACROS_H +#define INCLUDED_IEXMACROS_H + +//-------------------------------------------------------------------- +// +// Macros which make throwing exceptions more convenient +// +//-------------------------------------------------------------------- + +#include + + +//---------------------------------------------------------------------------- +// A macro to throw exceptions whose text is assembled using stringstreams. +// +// Example: +// +// THROW (InputExc, "Syntax error in line " << line ", " << file << "."); +// +//---------------------------------------------------------------------------- + +#include "IexExport.h" +#include "IexForward.h" + +IEX_EXPORT void iex_debugTrap(); + +#define THROW(type, text) \ + do \ + { \ + iex_debugTrap(); \ + std::stringstream s; \ + s << text; \ + throw type (s); \ + } \ + while (0) + + +//---------------------------------------------------------------------------- +// Macros to add to or to replace the text of an exception. +// The new text is assembled using stringstreams. +// +// Examples: +// +// Append to end of an exception's text: +// +// catch (BaseExc &e) +// { +// APPEND_EXC (e, " Directory " << name << " does not exist."); +// throw; +// } +// +// Replace an exception's text: +// +// catch (BaseExc &e) +// { +// REPLACE_EXC (e, "Directory " << name << " does not exist. " << e); +// throw; +// } +//---------------------------------------------------------------------------- + +#define APPEND_EXC(exc, text) \ + do \ + { \ + std::stringstream s; \ + s << text; \ + exc.append (s); \ + } \ + while (0) + +#define REPLACE_EXC(exc, text) \ + do \ + { \ + std::stringstream s; \ + s << text; \ + exc.assign (s); \ + } \ + while (0) + + +//------------------------------------------------------------- +// A macro to throw ErrnoExc exceptions whose text is assembled +// using stringstreams: +// +// Example: +// +// THROW_ERRNO ("Cannot open file " << name << " (%T)."); +// +//------------------------------------------------------------- + +#define THROW_ERRNO(text) \ + do \ + { \ + std::stringstream s; \ + s << text; \ + ::IEX_NAMESPACE::throwErrnoExc (s.str()); \ + } \ + while (0) + + +//------------------------------------------------------------- +// A macro to throw exceptions if an assertion is false. +// +// Example: +// +// ASSERT (ptr != 0, NullExc, "Null pointer" ); +// +//------------------------------------------------------------- + +#define ASSERT(assertion, type, text) \ + do \ + { \ + if( (assertion) == false ) \ + { \ + THROW( type, text ); \ + } \ + } \ + while (0) + +//------------------------------------------------------------- +// A macro to throw an IEX_NAMESPACE::LogicExc if an assertion is false, +// with the text composed from the source code file, line number, +// and assertion argument text. +// +// Example: +// +// LOGIC_ASSERT (i < n); +// +//------------------------------------------------------------- +#define LOGIC_ASSERT(assertion) \ + ASSERT(assertion, \ + IEX_NAMESPACE::LogicExc, \ + __FILE__ << "(" << __LINE__ << "): logical assertion failed: " << #assertion ) + +#endif diff --git a/OpenEXR/include/OpenEXR/IexMathExc.h b/OpenEXR/include/OpenEXR/IexMathExc.h new file mode 100644 index 0000000..795f500 --- /dev/null +++ b/OpenEXR/include/OpenEXR/IexMathExc.h @@ -0,0 +1,57 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IEXMATHEXC_H +#define INCLUDED_IEXMATHEXC_H + +#include "IexBaseExc.h" + +IEX_INTERNAL_NAMESPACE_HEADER_ENTER + +//--------------------------------------------------------- +// Exception classess which correspond to specific floating +// point exceptions. +//--------------------------------------------------------- + +DEFINE_EXC (OverflowExc, MathExc) // Overflow +DEFINE_EXC (UnderflowExc, MathExc) // Underflow +DEFINE_EXC (DivzeroExc, MathExc) // Division by zero +DEFINE_EXC (InexactExc, MathExc) // Inexact result +DEFINE_EXC (InvalidFpOpExc, MathExc) // Invalid operation + +IEX_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_IEXMATHEXC_H diff --git a/OpenEXR/include/OpenEXR/IexMathFloatExc.h b/OpenEXR/include/OpenEXR/IexMathFloatExc.h new file mode 100644 index 0000000..825dba1 --- /dev/null +++ b/OpenEXR/include/OpenEXR/IexMathFloatExc.h @@ -0,0 +1,146 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IEXMATHFLOATEXC_H +#define INCLUDED_IEXMATHFLOATEXC_H + +#ifndef IEXMATH_EXPORT_H +#define IEXMATH_EXPORT_H + +#if defined(OPENEXR_DLL) + #if defined(IEX_EXPORTS) + #define IEXMATH_EXPORT __declspec(dllexport) + #else + #define IEXMATH_EXPORT __declspec(dllimport) + #endif + #define IEXMATH_EXPORT_CONST +#else + #define IEXMATH_EXPORT + #define IEXMATH_EXPORT_CONST const +#endif + +#endif + +#include "IexNamespace.h" +#include "IexMathExc.h" +//#include +#include "IexMathIeeeExc.h" + +IEX_INTERNAL_NAMESPACE_HEADER_ENTER + + +//------------------------------------------------------------- +// Function mathExcOn() defines which floating point exceptions +// will be trapped and converted to C++ exceptions. +//------------------------------------------------------------- + +IEXMATH_EXPORT +void mathExcOn (int when = (IEEE_OVERFLOW | IEEE_DIVZERO | IEEE_INVALID)); + + +//---------------------------------------------------------------------- +// Function getMathExcOn() tells you for which floating point exceptions +// trapping and conversion to C++ exceptions is currently enabled. +//---------------------------------------------------------------------- + +IEXMATH_EXPORT +int getMathExcOn(); + + +//------------------------------------------------------------------------ +// A classs that temporarily sets floating point exception trapping +// and conversion, and later restores the previous settings. +// +// Example: +// +// float +// trickyComputation (float x) +// { +// MathExcOn meo (0); // temporarily disable floating +// // point exception trapping +// +// float result = ...; // computation which may cause +// // floating point exceptions +// +// return result; // destruction of meo restores +// } // the program's previous floating +// // point exception settings +//------------------------------------------------------------------------ + +class IEXMATH_EXPORT MathExcOn +{ + public: + + MathExcOn (int when) + : + _changed (false) + { + _saved = getMathExcOn(); + + if (_saved != when) + { + _changed = true; + mathExcOn (when); + } + } + + ~MathExcOn () + { + if (_changed) + mathExcOn (_saved); + } + + // It is possible for functions to set the exception registers + // yet not trigger a SIGFPE. Specifically, the implementation + // of pow(x, y) we're using can generates a NaN from a negative x + // and fractional y but a SIGFPE is not generated. + // This function examimes the exception registers and calls the + // fpHandler if those registers modulo the exception mask are set. + // It should be called wherever this class is commonly used where it has + // been found that certain floating point exceptions are not being thrown. + + void handleOutstandingExceptions(); + + private: + + bool _changed; + int _saved; +}; + + +IEX_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/IexMathFpu.h b/OpenEXR/include/OpenEXR/IexMathFpu.h new file mode 100644 index 0000000..df2a3e5 --- /dev/null +++ b/OpenEXR/include/OpenEXR/IexMathFpu.h @@ -0,0 +1,91 @@ +#ifndef INCLUDED_IEXMATHFPU_H +#define INCLUDED_IEXMATHFPU_H + +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 1997, 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. +// +/////////////////////////////////////////////////////////////////////////// + + +//------------------------------------------------------------------------ +// +// Functions to control floating point exceptions. +// +//------------------------------------------------------------------------ + +#include "IexMathIeeeExc.h" +#include "IexNamespace.h" + +IEX_INTERNAL_NAMESPACE_HEADER_ENTER + + +//----------------------------------------- +// setFpExceptions() defines which floating +// point exceptions cause SIGFPE signals. +//----------------------------------------- + +void setFpExceptions (int when = (IEEE_OVERFLOW | IEEE_DIVZERO | IEEE_INVALID)); + + +//---------------------------------------- +// fpExceptions() tells you which floating +// point exceptions cause SIGFPE signals. +//---------------------------------------- + +int fpExceptions (); + + +//------------------------------------------ +// setFpExceptionHandler() defines a handler +// that will be called when SIGFPE occurs. +//------------------------------------------ + +extern "C" typedef void (* FpExceptionHandler) (int type, const char explanation[]); + +void setFpExceptionHandler (FpExceptionHandler handler); + +// ----------------------------------------- +// handleExceptionsSetInRegisters() examines +// the exception registers and calls the +// floating point exception handler if the +// bits are set. This function exists to +// allow trapping of exception register states +// that can get set though no SIGFPE occurs. +// ----------------------------------------- + +void handleExceptionsSetInRegisters(); + + +IEX_INTERNAL_NAMESPACE_HEADER_EXIT + + +#endif diff --git a/OpenEXR/include/OpenEXR/IexMathIeeeExc.h b/OpenEXR/include/OpenEXR/IexMathIeeeExc.h new file mode 100644 index 0000000..efadebe --- /dev/null +++ b/OpenEXR/include/OpenEXR/IexMathIeeeExc.h @@ -0,0 +1,62 @@ +#ifndef INCLUDED_IEXMATHIEEE_EXC_H +#define INCLUDED_IEXMATHIEEE_EXC_H + +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 1997, 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. +// +/////////////////////////////////////////////////////////////////////////// + + +//--------------------------------------------------------------------------- +// +// Names for the loating point exceptions defined by IEEE standard 754 +// +//--------------------------------------------------------------------------- + +#include "IexNamespace.h" + +IEX_INTERNAL_NAMESPACE_HEADER_ENTER + + +enum IeeeExcType +{ + IEEE_OVERFLOW = 1, + IEEE_UNDERFLOW = 2, + IEEE_DIVZERO = 4, + IEEE_INEXACT = 8, + IEEE_INVALID = 16 +}; + + +IEX_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/IexNamespace.h b/OpenEXR/include/OpenEXR/IexNamespace.h new file mode 100644 index 0000000..bef1572 --- /dev/null +++ b/OpenEXR/include/OpenEXR/IexNamespace.h @@ -0,0 +1,112 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDED_IEXNAMESPACE_H +#define INCLUDED_IEXNAMESPACE_H + +// +// The purpose of this file is to make it possible to specify an +// IEX_INTERNAL_NAMESPACE as a preprocessor definition and have all of the +// Iex symbols defined within that namespace rather than the standard +// Iex namespace. Those symbols are made available to client code through +// the IEX_NAMESPACE in addition to the IEX_INTERNAL_NAMESPACE. +// +// To ensure source code compatibility, the IEX_NAMESPACE defaults to Iex +// and then "using namespace IEX_INTERNAL_NAMESPACE;" brings all of the +// declarations from the IEX_INTERNAL_NAMESPACE into the IEX_NAMESPACE. This +// means that client code can continue to use syntax like Iex::BaseExc, but +// at link time it will resolve to a mangled symbol based on the +// IEX_INTERNAL_NAMESPACE. +// +// As an example, if one needed to build against a newer version of Iex and +// have it run alongside an older version in the same application, it is now +// possible to use an internal namespace to prevent collisions between the +// older versions of Iex symbols and the newer ones. To do this, the +// following could be defined at build time: +// +// IEX_INTERNAL_NAMESPACE = Iex_v2 +// +// This means that declarations inside Iex headers look like this (after the +// preprocessor has done its work): +// +// namespace Iex_v2 { +// ... +// class declarations +// ... +// } +// +// namespace Iex { +// using namespace Iex_v2; +// } +// + +// +// Open Source version of this file pulls in the IlmBaseConfig.h file +// for the configure time options. +// +#include "IlmBaseConfig.h" + +#ifndef IEX_NAMESPACE +#define IEX_NAMESPACE Iex +#endif + +#ifndef IEX_INTERNAL_NAMESPACE +#define IEX_INTERNAL_NAMESPACE IEX_NAMESPACE +#endif + +// +// We need to be sure that we import the internal namespace into the public one. +// To do this, we use the small bit of code below which initially defines +// IEX_INTERNAL_NAMESPACE (so it can be referenced) and then defines +// IEX_NAMESPACE and pulls the internal symbols into the public namespace. +// + +namespace IEX_INTERNAL_NAMESPACE {} +namespace IEX_NAMESPACE { + using namespace IEX_INTERNAL_NAMESPACE; +} + +// +// There are identical pairs of HEADER/SOURCE ENTER/EXIT macros so that +// future extension to the namespace mechanism is possible without changing +// project source code. +// + +#define IEX_INTERNAL_NAMESPACE_HEADER_ENTER namespace IEX_INTERNAL_NAMESPACE { +#define IEX_INTERNAL_NAMESPACE_HEADER_EXIT } + +#define IEX_INTERNAL_NAMESPACE_SOURCE_ENTER namespace IEX_INTERNAL_NAMESPACE { +#define IEX_INTERNAL_NAMESPACE_SOURCE_EXIT } + +#endif // INCLUDED_IEXNAMESPACE_H diff --git a/OpenEXR/include/OpenEXR/IexThrowErrnoExc.h b/OpenEXR/include/OpenEXR/IexThrowErrnoExc.h new file mode 100644 index 0000000..224ed2b --- /dev/null +++ b/OpenEXR/include/OpenEXR/IexThrowErrnoExc.h @@ -0,0 +1,97 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IEXTHROWERRNOEXC_H +#define INCLUDED_IEXTHROWERRNOEXC_H + +//---------------------------------------------------------- +// +// A function which throws ExcErrno exceptions +// +//---------------------------------------------------------- + +#include "IexBaseExc.h" +#include "IexExport.h" + +IEX_INTERNAL_NAMESPACE_HEADER_ENTER + + +//-------------------------------------------------------------------------- +// +// Function throwErrnoExc() throws an exception which corresponds to +// error code errnum. The exception text is initialized with a copy +// of the string passed to throwErrnoExc(), where all occurrences of +// "%T" have been replaced with the output of strerror(oserror()). +// +// Example: +// +// If opening file /tmp/output failed with an ENOENT error code, +// calling +// +// throwErrnoExc (); +// +// or +// +// throwErrnoExc ("%T."); +// +// will throw an EnoentExc whose text reads +// +// No such file or directory. +// +// More detailed messages can be assembled using stringstreams: +// +// std::stringstream s; +// s << "Cannot open file " << name << " (%T)."; +// throwErrnoExc (s); +// +// The resulting exception contains the following text: +// +// Cannot open file /tmp/output (No such file or directory). +// +// Alternatively, you may want to use the THROW_ERRNO macro defined +// in IexMacros.h: +// +// THROW_ERRNO ("Cannot open file " << name << " (%T).") +// +//-------------------------------------------------------------------------- + +IEX_EXPORT void throwErrnoExc(const std::string &txt, int errnum); +IEX_EXPORT void throwErrnoExc(const std::string &txt); +IEX_EXPORT void throwErrnoExc(); + +IEX_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_IEXTHROWERRNOEXC_H diff --git a/OpenEXR/include/OpenEXR/IlmBaseConfig.h b/OpenEXR/include/OpenEXR/IlmBaseConfig.h new file mode 100644 index 0000000..b626ede --- /dev/null +++ b/OpenEXR/include/OpenEXR/IlmBaseConfig.h @@ -0,0 +1,72 @@ +/* config/IlmBaseConfig.h. Generated from IlmBaseConfig.h.in by configure. */ +// +// Define and set to 1 if the target system has POSIX thread support +// and you want IlmBase to use it for multithreaded file I/O. +// + +#define HAVE_PTHREAD 1 + +// +// Define and set to 1 if the target system supports POSIX semaphores +// and you want OpenEXR to use them; otherwise, OpenEXR will use its +// own semaphore implementation. +// + +#define HAVE_POSIX_SEMAPHORES 1 + + +#define HAVE_UCONTEXT_H 1 + + +// +// Dealing with FPEs +// +#define ILMBASE_HAVE_CONTROL_REGISTER_SUPPORT 1 + + +// +// Define and set to 1 if the target system has support for large +// stack sizes. +// + +#define ILMBASE_HAVE_LARGE_STACK 1 + +// +// Current (internal) library namepace name and corresponding public +// client namespaces. +// +#define ILMBASE_INTERNAL_NAMESPACE_CUSTOM 1 +#define IMATH_INTERNAL_NAMESPACE Imath_2_2 +#define IEX_INTERNAL_NAMESPACE Iex_2_2 +#define ILMTHREAD_INTERNAL_NAMESPACE IlmThread_2_2 + +/* #undef ILMBASE_NAMESPACE_CUSTOM */ +#define IMATH_NAMESPACE Imath +#define IEX_NAMESPACE Iex +#define ILMTHREAD_NAMESPACE IlmThread + + +// +// Define and set to 1 if the target system has support for large +// stack sizes. +// + +#define ILMBASE_HAVE_LARGE_STACK 1 + + +// +// Version information +// +#define ILMBASE_VERSION_STRING "2.2.0" +#define ILMBASE_PACKAGE_STRING "IlmBase 2.2.0" + +#define ILMBASE_VERSION_MAJOR 2 +#define ILMBASE_VERSION_MINOR 2 +#define ILMBASE_VERSION_PATCH 0 + +// Version as a single hex number, e.g. 0x01000300 == 1.0.3 +#define ILMBASE_VERSION_HEX ((ILMBASE_VERSION_MAJOR << 24) | \ + (ILMBASE_VERSION_MINOR << 16) | \ + (ILMBASE_VERSION_PATCH << 8)) + + diff --git a/OpenEXR/include/OpenEXR/IlmThread.h b/OpenEXR/include/OpenEXR/IlmThread.h new file mode 100644 index 0000000..1f6d9e6 --- /dev/null +++ b/OpenEXR/include/OpenEXR/IlmThread.h @@ -0,0 +1,143 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2005-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDED_ILM_THREAD_H +#define INCLUDED_ILM_THREAD_H + +//----------------------------------------------------------------------------- +// +// class Thread +// +// Class Thread is a portable interface to a system-dependent thread +// primitive. In order to make a thread actually do something useful, +// you must derive a subclass from class Thread and implement the +// run() function. If the operating system supports threading then +// the run() function will be executed int a new thread. +// +// The actual creation of the thread is done by the start() routine +// which then calls the run() function. In general the start() +// routine should be called from the constructor of the derived class. +// +// The base-class thread destructor will join/destroy the thread. +// +// IMPORTANT: Due to the mechanisms that encapsulate the low-level +// threading primitives in a C++ class there is a race condition +// with code resembling the following: +// +// { +// WorkerThread myThread; +// } // myThread goes out of scope, is destroyed +// // and the thread is joined +// +// The race is between the parent thread joining the child thread +// in the destructor of myThread, and the run() function in the +// child thread. If the destructor gets executed first then run() +// will be called with an invalid "this" pointer. +// +// This issue can be fixed by using a Semaphore to keep track of +// whether the run() function has already been called. You can +// include a Semaphore member variable within your derived class +// which you post() on in the run() function, and wait() on in the +// destructor before the thread is joined. Alternatively you could +// do something like this: +// +// Semaphore runStarted; +// +// void WorkerThread::run () +// { +// runStarted.post() +// // do some work +// ... +// } +// +// { +// WorkerThread myThread; +// runStarted.wait (); // ensure that we have started +// // the run function +// } // myThread goes out of scope, is destroyed +// // and the thread is joined +// +//----------------------------------------------------------------------------- + +#include "IlmBaseConfig.h" +#include "IlmThreadExport.h" +#include "IlmThreadNamespace.h" + +#if defined _WIN32 || defined _WIN64 + #ifdef NOMINMAX + #undef NOMINMAX + #endif + #define NOMINMAX + #include + #include +#elif HAVE_PTHREAD + #include +#endif + +ILMTHREAD_INTERNAL_NAMESPACE_HEADER_ENTER + +// +// Query function to determine if the current platform supports +// threads AND this library was compiled with threading enabled. +// + +ILMTHREAD_EXPORT bool supportsThreads (); + + +class ILMTHREAD_EXPORT Thread +{ + public: + + Thread (); + virtual ~Thread (); + + void start (); + virtual void run () = 0; + + private: + + #if defined _WIN32 || defined _WIN64 + HANDLE _thread; + #elif HAVE_PTHREAD + pthread_t _thread; + #endif + + void operator = (const Thread& t); // not implemented + Thread (const Thread& t); // not implemented +}; + + +ILMTHREAD_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_ILM_THREAD_H diff --git a/OpenEXR/include/OpenEXR/IlmThreadExport.h b/OpenEXR/include/OpenEXR/IlmThreadExport.h new file mode 100644 index 0000000..96d2200 --- /dev/null +++ b/OpenEXR/include/OpenEXR/IlmThreadExport.h @@ -0,0 +1,46 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + +#if defined(OPENEXR_DLL) + #if defined(ILMTHREAD_EXPORTS) + #define ILMTHREAD_EXPORT __declspec(dllexport) + #define ILMTHREAD_EXPORT_CONST extern __declspec(dllexport) + #else + #define ILMTHREAD_EXPORT __declspec(dllimport) + #define ILMTHREAD_EXPORT_CONST extern __declspec(dllimport) + #endif +#else + #define ILMTHREAD_EXPORT + #define ILMTHREAD_EXPORT_CONST extern const +#endif diff --git a/OpenEXR/include/OpenEXR/IlmThreadForward.h b/OpenEXR/include/OpenEXR/IlmThreadForward.h new file mode 100644 index 0000000..b52bdac --- /dev/null +++ b/OpenEXR/include/OpenEXR/IlmThreadForward.h @@ -0,0 +1,52 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDED_ILMTHREADFORWARD_H +#define INCLUDED_ILMTHREADFORWARD_H + +#include "IlmThreadNamespace.h" + +ILMTHREAD_INTERNAL_NAMESPACE_HEADER_ENTER + +class Thread; +class Mutex; +class Lock; +class ThreadPool; +class Task; +class TaskGroup; +class Semaphore; + +ILMTHREAD_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_ILMTHREADFORWARD_H diff --git a/OpenEXR/include/OpenEXR/IlmThreadMutex.h b/OpenEXR/include/OpenEXR/IlmThreadMutex.h new file mode 100644 index 0000000..dd42067 --- /dev/null +++ b/OpenEXR/include/OpenEXR/IlmThreadMutex.h @@ -0,0 +1,160 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2005-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDED_ILM_THREAD_MUTEX_H +#define INCLUDED_ILM_THREAD_MUTEX_H + +//----------------------------------------------------------------------------- +// +// class Mutex, class Lock +// +// Class Mutex is a wrapper for a system-dependent mutual exclusion +// mechanism. Actual locking and unlocking of a Mutex object must +// be performed using an instance of a Lock (defined below). +// +// Class lock provides safe locking and unlocking of mutexes even in +// the presence of C++ exceptions. Constructing a Lock object locks +// the mutex; destroying the Lock unlocks the mutex. +// +// Lock objects are not themselves thread-safe. You should never +// share a Lock object among multiple threads. +// +// Typical usage: +// +// Mutex mtx; // Create a Mutex object that is visible +// //to multiple threads +// +// ... // create some threads +// +// // Then, within each thread, construct a critical section like so: +// +// { +// Lock lock (mtx); // Lock constructor locks the mutex +// ... // do some computation on shared data +// } // leaving the block unlocks the mutex +// +//----------------------------------------------------------------------------- + +#include "IlmThreadExport.h" +#include "IlmBaseConfig.h" +#include "IlmThreadNamespace.h" + +#if defined _WIN32 || defined _WIN64 + #ifdef NOMINMAX + #undef NOMINMAX + #endif + #define NOMINMAX + #include +#elif HAVE_PTHREAD + #include +#endif + +ILMTHREAD_INTERNAL_NAMESPACE_HEADER_ENTER + +class Lock; + + +class ILMTHREAD_EXPORT Mutex +{ + public: + + Mutex (); + virtual ~Mutex (); + + private: + + void lock () const; + void unlock () const; + + #if defined _WIN32 || defined _WIN64 + mutable CRITICAL_SECTION _mutex; + #elif HAVE_PTHREAD + mutable pthread_mutex_t _mutex; + #endif + + void operator = (const Mutex& M); // not implemented + Mutex (const Mutex& M); // not implemented + + friend class Lock; +}; + + +class ILMTHREAD_EXPORT Lock +{ + public: + + Lock (const Mutex& m, bool autoLock = true): + _mutex (m), + _locked (false) + { + if (autoLock) + { + _mutex.lock(); + _locked = true; + } + } + + ~Lock () + { + if (_locked) + _mutex.unlock(); + } + + void acquire () + { + _mutex.lock(); + _locked = true; + } + + void release () + { + _mutex.unlock(); + _locked = false; + } + + bool locked () + { + return _locked; + } + + private: + + const Mutex & _mutex; + bool _locked; +}; + + +ILMTHREAD_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_ILM_THREAD_MUTEX_H diff --git a/OpenEXR/include/OpenEXR/IlmThreadNamespace.h b/OpenEXR/include/OpenEXR/IlmThreadNamespace.h new file mode 100644 index 0000000..a412997 --- /dev/null +++ b/OpenEXR/include/OpenEXR/IlmThreadNamespace.h @@ -0,0 +1,114 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDED_ILMTHREADNAMESPACE_H +#define INCLUDED_ILMTHREADNAMESPACE_H + +// +// The purpose of this file is to make it possible to specify an +// ILMTHREAD_INTERNAL_NAMESPACE as a preprocessor definition and have all of +// the IlmThread symbols defined within that namespace rather than the +// standard IlmThread namespace. Those symbols are made available to client +// code through the ILMTHREAD_NAMESPACE in addition to the +// ILMTHREAD_INTERNAL_NAMESPACE. +// +// To ensure source code compatibility, the ILMTHREAD_NAMESPACE defaults to +// IlmThread and then "using namespace ILMTHREAD_INTERNAL_NAMESPACE;" brings +// all of the declarations from the ILMTHREAD_INTERNAL_NAMESPACE into the +// ILMTHREAD_NAMESPACE. This means that client code can continue to use +// syntax like IlmThread::Thread, but at link time it will resolve to a +// mangled symbol based on the ILMTHREAD_INTERNAL_NAMESPACE. +// +// As an example, if one needed to build against a newer version of IlmThread +// and have it run alongside an older version in the same application, it is +// now possible to use an internal namespace to prevent collisions between +// the older versions of IlmThread symbols and the newer ones. To do this, +// the following could be defined at build time: +// +// ILMTHREAD_INTERNAL_NAMESPACE = IlmThread_v2 +// +// This means that declarations inside IlmThread headers look like this +// (after the preprocessor has done its work): +// +// namespace IlmThread_v2 { +// ... +// class declarations +// ... +// } +// +// namespace IlmThread { +// using namespace IlmThread_v2; +// } +// + +// +// Open Source version of this file pulls in the IlmBaseConfig.h file +// for the configure time options. +// +#include "IlmBaseConfig.h" + +#ifndef ILMTHREAD_NAMESPACE +#define ILMTHREAD_NAMESPACE IlmThread +#endif + +#ifndef ILMTHREAD_INTERNAL_NAMESPACE +#define ILMTHREAD_INTERNAL_NAMESPACE ILMTHREAD_NAMESPACE +#endif + +// +// We need to be sure that we import the internal namespace into the public one. +// To do this, we use the small bit of code below which initially defines +// ILMTHREAD_INTERNAL_NAMESPACE (so it can be referenced) and then defines +// ILMTHREAD_NAMESPACE and pulls the internal symbols into the public +// namespace. +// + +namespace ILMTHREAD_INTERNAL_NAMESPACE {} +namespace ILMTHREAD_NAMESPACE { + using namespace ILMTHREAD_INTERNAL_NAMESPACE; +} + +// +// There are identical pairs of HEADER/SOURCE ENTER/EXIT macros so that +// future extension to the namespace mechanism is possible without changing +// project source code. +// + +#define ILMTHREAD_INTERNAL_NAMESPACE_HEADER_ENTER namespace ILMTHREAD_INTERNAL_NAMESPACE { +#define ILMTHREAD_INTERNAL_NAMESPACE_HEADER_EXIT } + +#define ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_ENTER namespace ILMTHREAD_INTERNAL_NAMESPACE { +#define ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_EXIT } + +#endif // INCLUDED_ILMTHREADNAMESPACE_H diff --git a/OpenEXR/include/OpenEXR/IlmThreadPool.h b/OpenEXR/include/OpenEXR/IlmThreadPool.h new file mode 100644 index 0000000..d436d4e --- /dev/null +++ b/OpenEXR/include/OpenEXR/IlmThreadPool.h @@ -0,0 +1,160 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2005-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDED_ILM_THREAD_POOL_H +#define INCLUDED_ILM_THREAD_POOL_H + + +//----------------------------------------------------------------------------- +// +// class Task, class ThreadPool, class TaskGroup +// +// Class ThreadPool manages a set of worker threads and accepts +// tasks for processing. Tasks added to the thread pool are +// executed concurrently by the worker threads. +// +// Class Task provides an abstract interface for a task which +// a ThreadPool works on. Derived classes need to implement the +// execute() function which performs the actual task. +// +// Class TaskGroup allows synchronization on the completion of a set +// of tasks. Every task that is added to a ThreadPool belongs to a +// single TaskGroup. The destructor of the TaskGroup waits for all +// tasks in the group to finish. +// +// Note: if you plan to use the ThreadPool interface in your own +// applications note that the implementation of the ThreadPool calls +// operator delete on tasks as they complete. If you define a custom +// operator new for your tasks, for instance to use a custom heap, +// then you must also write an appropriate operator delete. +// +//----------------------------------------------------------------------------- + +#include "IlmThreadNamespace.h" +#include "IlmThreadExport.h" + +ILMTHREAD_INTERNAL_NAMESPACE_HEADER_ENTER + +class TaskGroup; +class Task; + + +class ILMTHREAD_EXPORT ThreadPool +{ + public: + + //------------------------------------------------------- + // Constructor -- creates numThreads worker threads which + // wait until a task is available. + //------------------------------------------------------- + + ThreadPool (unsigned numThreads = 0); + + + //----------------------------------------------------------- + // Destructor -- waits for all tasks to complete, joins all + // the threads to the calling thread, and then destroys them. + //----------------------------------------------------------- + + virtual ~ThreadPool (); + + + //-------------------------------------------------------- + // Query and set the number of worker threads in the pool. + // + // Warning: never call setNumThreads from within a worker + // thread as this will almost certainly cause a deadlock + // or crash. + //-------------------------------------------------------- + + int numThreads () const; + void setNumThreads (int count); + + + //------------------------------------------------------------ + // Add a task for processing. The ThreadPool can handle any + // number of tasks regardless of the number of worker threads. + // The tasks are first added onto a queue, and are executed + // by threads as they become available, in FIFO order. + //------------------------------------------------------------ + + void addTask (Task* task); + + + //------------------------------------------- + // Access functions for the global threadpool + //------------------------------------------- + + static ThreadPool& globalThreadPool (); + static void addGlobalTask (Task* task); + + struct Data; + + protected: + + Data * _data; +}; + + +class ILMTHREAD_EXPORT Task +{ + public: + + Task (TaskGroup* g); + virtual ~Task (); + + virtual void execute () = 0; + TaskGroup * group(); + + protected: + + TaskGroup * _group; +}; + + +class ILMTHREAD_EXPORT TaskGroup +{ + public: + + TaskGroup(); + ~TaskGroup(); + + struct Data; + Data* const _data; +}; + + +ILMTHREAD_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_ILM_THREAD_POOL_H diff --git a/OpenEXR/include/OpenEXR/IlmThreadSemaphore.h b/OpenEXR/include/OpenEXR/IlmThreadSemaphore.h new file mode 100644 index 0000000..46cfd02 --- /dev/null +++ b/OpenEXR/include/OpenEXR/IlmThreadSemaphore.h @@ -0,0 +1,112 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2005-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDED_ILM_THREAD_SEMAPHORE_H +#define INCLUDED_ILM_THREAD_SEMAPHORE_H + +//----------------------------------------------------------------------------- +// +// class Semaphore -- a wrapper class for +// system-dependent counting semaphores +// +//----------------------------------------------------------------------------- + +#include "IlmBaseConfig.h" +#include "IlmThreadExport.h" +#include "IlmThreadNamespace.h" + +#if defined _WIN32 || defined _WIN64 + #ifdef NOMINMAX + #undef NOMINMAX + #endif + #define NOMINMAX + #include +#elif HAVE_PTHREAD && !HAVE_POSIX_SEMAPHORES + #include +#elif HAVE_PTHREAD && HAVE_POSIX_SEMAPHORES + #include +#endif + +ILMTHREAD_INTERNAL_NAMESPACE_HEADER_ENTER + + +class ILMTHREAD_EXPORT Semaphore +{ + public: + + Semaphore (unsigned int value = 0); + virtual ~Semaphore(); + + void wait(); + bool tryWait(); + void post(); + int value() const; + + private: + + #if defined _WIN32 || defined _WIN64 + + mutable HANDLE _semaphore; + + #elif HAVE_PTHREAD && !HAVE_POSIX_SEMAPHORES + + // + // If the platform has Posix threads but no semapohores, + // then we implement them ourselves using condition variables + // + + struct sema_t + { + unsigned int count; + unsigned long numWaiting; + pthread_mutex_t mutex; + pthread_cond_t nonZero; + }; + + mutable sema_t _semaphore; + + #elif HAVE_PTHREAD && HAVE_POSIX_SEMAPHORES + + mutable sem_t _semaphore; + + #endif + + void operator = (const Semaphore& s); // not implemented + Semaphore (const Semaphore& s); // not implemented +}; + + +ILMTHREAD_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_ILM_THREAD_SEMAPHORE_H diff --git a/OpenEXR/include/OpenEXR/ImathBox.h b/OpenEXR/include/OpenEXR/ImathBox.h new file mode 100644 index 0000000..45165ff --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathBox.h @@ -0,0 +1,849 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2004-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMATHBOX_H +#define INCLUDED_IMATHBOX_H + +//------------------------------------------------------------------- +// +// class Imath::Box +// -------------------------------- +// +// This class imposes the following requirements on its +// parameter class: +// +// 1) The class T must implement these operators: +// + - < > <= >= = +// with the signature (T,T) and the expected +// return values for a numeric type. +// +// 2) The class T must implement operator= +// with the signature (T,float and/or double) +// +// 3) The class T must have a constructor which takes +// a float (and/or double) for use in initializing the box. +// +// 4) The class T must have a function T::dimensions() +// which returns the number of dimensions in the class +// (since its assumed its a vector) -- preferably, this +// returns a constant expression. +// +//------------------------------------------------------------------- + +#include "ImathVec.h" +#include "ImathNamespace.h" + +IMATH_INTERNAL_NAMESPACE_HEADER_ENTER + + +template +class Box +{ + public: + + //------------------------- + // Data Members are public + //------------------------- + + T min; + T max; + + //----------------------------------------------------- + // Constructors - an "empty" box is created by default + //----------------------------------------------------- + + Box (); + Box (const T &point); + Box (const T &minT, const T &maxT); + + //-------------------- + // Operators: ==, != + //-------------------- + + bool operator == (const Box &src) const; + bool operator != (const Box &src) const; + + //------------------ + // Box manipulation + //------------------ + + void makeEmpty (); + void extendBy (const T &point); + void extendBy (const Box &box); + void makeInfinite (); + + //--------------------------------------------------- + // Query functions - these compute results each time + //--------------------------------------------------- + + T size () const; + T center () const; + bool intersects (const T &point) const; + bool intersects (const Box &box) const; + + unsigned int majorAxis () const; + + //---------------- + // Classification + //---------------- + + bool isEmpty () const; + bool hasVolume () const; + bool isInfinite () const; +}; + + +//-------------------- +// Convenient typedefs +//-------------------- + +typedef Box Box2s; +typedef Box Box2i; +typedef Box Box2f; +typedef Box Box2d; +typedef Box Box3s; +typedef Box Box3i; +typedef Box Box3f; +typedef Box Box3d; + + +//---------------- +// Implementation + + +template +inline Box::Box() +{ + makeEmpty(); +} + + +template +inline Box::Box (const T &point) +{ + min = point; + max = point; +} + + +template +inline Box::Box (const T &minT, const T &maxT) +{ + min = minT; + max = maxT; +} + + +template +inline bool +Box::operator == (const Box &src) const +{ + return (min == src.min && max == src.max); +} + + +template +inline bool +Box::operator != (const Box &src) const +{ + return (min != src.min || max != src.max); +} + + +template +inline void Box::makeEmpty() +{ + min = T(T::baseTypeMax()); + max = T(T::baseTypeMin()); +} + +template +inline void Box::makeInfinite() +{ + min = T(T::baseTypeMin()); + max = T(T::baseTypeMax()); +} + + +template +inline void +Box::extendBy(const T &point) +{ + for (unsigned int i = 0; i < min.dimensions(); i++) + { + if (point[i] < min[i]) + min[i] = point[i]; + + if (point[i] > max[i]) + max[i] = point[i]; + } +} + + +template +inline void +Box::extendBy(const Box &box) +{ + for (unsigned int i = 0; i < min.dimensions(); i++) + { + if (box.min[i] < min[i]) + min[i] = box.min[i]; + + if (box.max[i] > max[i]) + max[i] = box.max[i]; + } +} + + +template +inline bool +Box::intersects(const T &point) const +{ + for (unsigned int i = 0; i < min.dimensions(); i++) + { + if (point[i] < min[i] || point[i] > max[i]) + return false; + } + + return true; +} + + +template +inline bool +Box::intersects(const Box &box) const +{ + for (unsigned int i = 0; i < min.dimensions(); i++) + { + if (box.max[i] < min[i] || box.min[i] > max[i]) + return false; + } + + return true; +} + + +template +inline T +Box::size() const +{ + if (isEmpty()) + return T (0); + + return max - min; +} + + +template +inline T +Box::center() const +{ + return (max + min) / 2; +} + + +template +inline bool +Box::isEmpty() const +{ + for (unsigned int i = 0; i < min.dimensions(); i++) + { + if (max[i] < min[i]) + return true; + } + + return false; +} + +template +inline bool +Box::isInfinite() const +{ + for (unsigned int i = 0; i < min.dimensions(); i++) + { + if (min[i] != T::baseTypeMin() || max[i] != T::baseTypeMax()) + return false; + } + + return true; +} + + +template +inline bool +Box::hasVolume() const +{ + for (unsigned int i = 0; i < min.dimensions(); i++) + { + if (max[i] <= min[i]) + return false; + } + + return true; +} + + +template +inline unsigned int +Box::majorAxis() const +{ + unsigned int major = 0; + T s = size(); + + for (unsigned int i = 1; i < min.dimensions(); i++) + { + if (s[i] > s[major]) + major = i; + } + + return major; +} + +//------------------------------------------------------------------- +// +// Partial class specializations for Imath::Vec2 and Imath::Vec3 +// +//------------------------------------------------------------------- + +template class Box; + +template +class Box > +{ + public: + + //------------------------- + // Data Members are public + //------------------------- + + Vec2 min; + Vec2 max; + + //----------------------------------------------------- + // Constructors - an "empty" box is created by default + //----------------------------------------------------- + + Box(); + Box (const Vec2 &point); + Box (const Vec2 &minT, const Vec2 &maxT); + + //-------------------- + // Operators: ==, != + //-------------------- + + bool operator == (const Box > &src) const; + bool operator != (const Box > &src) const; + + //------------------ + // Box manipulation + //------------------ + + void makeEmpty(); + void extendBy (const Vec2 &point); + void extendBy (const Box > &box); + void makeInfinite(); + + //--------------------------------------------------- + // Query functions - these compute results each time + //--------------------------------------------------- + + Vec2 size() const; + Vec2 center() const; + bool intersects (const Vec2 &point) const; + bool intersects (const Box > &box) const; + + unsigned int majorAxis() const; + + //---------------- + // Classification + //---------------- + + bool isEmpty() const; + bool hasVolume() const; + bool isInfinite() const; +}; + + +//---------------- +// Implementation + +template +inline Box >::Box() +{ + makeEmpty(); +} + + +template +inline Box >::Box (const Vec2 &point) +{ + min = point; + max = point; +} + + +template +inline Box >::Box (const Vec2 &minT, const Vec2 &maxT) +{ + min = minT; + max = maxT; +} + + +template +inline bool +Box >::operator == (const Box > &src) const +{ + return (min == src.min && max == src.max); +} + + +template +inline bool +Box >::operator != (const Box > &src) const +{ + return (min != src.min || max != src.max); +} + + +template +inline void Box >::makeEmpty() +{ + min = Vec2(Vec2::baseTypeMax()); + max = Vec2(Vec2::baseTypeMin()); +} + +template +inline void Box >::makeInfinite() +{ + min = Vec2(Vec2::baseTypeMin()); + max = Vec2(Vec2::baseTypeMax()); +} + + +template +inline void +Box >::extendBy (const Vec2 &point) +{ + if (point[0] < min[0]) + min[0] = point[0]; + + if (point[0] > max[0]) + max[0] = point[0]; + + if (point[1] < min[1]) + min[1] = point[1]; + + if (point[1] > max[1]) + max[1] = point[1]; +} + + +template +inline void +Box >::extendBy (const Box > &box) +{ + if (box.min[0] < min[0]) + min[0] = box.min[0]; + + if (box.max[0] > max[0]) + max[0] = box.max[0]; + + if (box.min[1] < min[1]) + min[1] = box.min[1]; + + if (box.max[1] > max[1]) + max[1] = box.max[1]; +} + + +template +inline bool +Box >::intersects (const Vec2 &point) const +{ + if (point[0] < min[0] || point[0] > max[0] || + point[1] < min[1] || point[1] > max[1]) + return false; + + return true; +} + + +template +inline bool +Box >::intersects (const Box > &box) const +{ + if (box.max[0] < min[0] || box.min[0] > max[0] || + box.max[1] < min[1] || box.min[1] > max[1]) + return false; + + return true; +} + + +template +inline Vec2 +Box >::size() const +{ + if (isEmpty()) + return Vec2 (0); + + return max - min; +} + + +template +inline Vec2 +Box >::center() const +{ + return (max + min) / 2; +} + + +template +inline bool +Box >::isEmpty() const +{ + if (max[0] < min[0] || + max[1] < min[1]) + return true; + + return false; +} + +template +inline bool +Box > ::isInfinite() const +{ + if (min[0] != limits::min() || max[0] != limits::max() || + min[1] != limits::min() || max[1] != limits::max()) + return false; + + return true; +} + + +template +inline bool +Box >::hasVolume() const +{ + if (max[0] <= min[0] || + max[1] <= min[1]) + return false; + + return true; +} + + +template +inline unsigned int +Box >::majorAxis() const +{ + unsigned int major = 0; + Vec2 s = size(); + + if (s[1] > s[major]) + major = 1; + + return major; +} + + +template +class Box > +{ + public: + + //------------------------- + // Data Members are public + //------------------------- + + Vec3 min; + Vec3 max; + + //----------------------------------------------------- + // Constructors - an "empty" box is created by default + //----------------------------------------------------- + + Box(); + Box (const Vec3 &point); + Box (const Vec3 &minT, const Vec3 &maxT); + + //-------------------- + // Operators: ==, != + //-------------------- + + bool operator == (const Box > &src) const; + bool operator != (const Box > &src) const; + + //------------------ + // Box manipulation + //------------------ + + void makeEmpty(); + void extendBy (const Vec3 &point); + void extendBy (const Box > &box); + void makeInfinite (); + + //--------------------------------------------------- + // Query functions - these compute results each time + //--------------------------------------------------- + + Vec3 size() const; + Vec3 center() const; + bool intersects (const Vec3 &point) const; + bool intersects (const Box > &box) const; + + unsigned int majorAxis() const; + + //---------------- + // Classification + //---------------- + + bool isEmpty() const; + bool hasVolume() const; + bool isInfinite() const; +}; + + +//---------------- +// Implementation + + +template +inline Box >::Box() +{ + makeEmpty(); +} + + +template +inline Box >::Box (const Vec3 &point) +{ + min = point; + max = point; +} + + +template +inline Box >::Box (const Vec3 &minT, const Vec3 &maxT) +{ + min = minT; + max = maxT; +} + + +template +inline bool +Box >::operator == (const Box > &src) const +{ + return (min == src.min && max == src.max); +} + + +template +inline bool +Box >::operator != (const Box > &src) const +{ + return (min != src.min || max != src.max); +} + + +template +inline void Box >::makeEmpty() +{ + min = Vec3(Vec3::baseTypeMax()); + max = Vec3(Vec3::baseTypeMin()); +} + +template +inline void Box >::makeInfinite() +{ + min = Vec3(Vec3::baseTypeMin()); + max = Vec3(Vec3::baseTypeMax()); +} + + +template +inline void +Box >::extendBy (const Vec3 &point) +{ + if (point[0] < min[0]) + min[0] = point[0]; + + if (point[0] > max[0]) + max[0] = point[0]; + + if (point[1] < min[1]) + min[1] = point[1]; + + if (point[1] > max[1]) + max[1] = point[1]; + + if (point[2] < min[2]) + min[2] = point[2]; + + if (point[2] > max[2]) + max[2] = point[2]; +} + + +template +inline void +Box >::extendBy (const Box > &box) +{ + if (box.min[0] < min[0]) + min[0] = box.min[0]; + + if (box.max[0] > max[0]) + max[0] = box.max[0]; + + if (box.min[1] < min[1]) + min[1] = box.min[1]; + + if (box.max[1] > max[1]) + max[1] = box.max[1]; + + if (box.min[2] < min[2]) + min[2] = box.min[2]; + + if (box.max[2] > max[2]) + max[2] = box.max[2]; +} + + +template +inline bool +Box >::intersects (const Vec3 &point) const +{ + if (point[0] < min[0] || point[0] > max[0] || + point[1] < min[1] || point[1] > max[1] || + point[2] < min[2] || point[2] > max[2]) + return false; + + return true; +} + + +template +inline bool +Box >::intersects (const Box > &box) const +{ + if (box.max[0] < min[0] || box.min[0] > max[0] || + box.max[1] < min[1] || box.min[1] > max[1] || + box.max[2] < min[2] || box.min[2] > max[2]) + return false; + + return true; +} + + +template +inline Vec3 +Box >::size() const +{ + if (isEmpty()) + return Vec3 (0); + + return max - min; +} + + +template +inline Vec3 +Box >::center() const +{ + return (max + min) / 2; +} + + +template +inline bool +Box >::isEmpty() const +{ + if (max[0] < min[0] || + max[1] < min[1] || + max[2] < min[2]) + return true; + + return false; +} + +template +inline bool +Box >::isInfinite() const +{ + if (min[0] != limits::min() || max[0] != limits::max() || + min[1] != limits::min() || max[1] != limits::max() || + min[2] != limits::min() || max[2] != limits::max()) + return false; + + return true; +} + + +template +inline bool +Box >::hasVolume() const +{ + if (max[0] <= min[0] || + max[1] <= min[1] || + max[2] <= min[2]) + return false; + + return true; +} + + +template +inline unsigned int +Box >::majorAxis() const +{ + unsigned int major = 0; + Vec3 s = size(); + + if (s[1] > s[major]) + major = 1; + + if (s[2] > s[major]) + major = 2; + + return major; +} + + +IMATH_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_IMATHBOX_H diff --git a/OpenEXR/include/OpenEXR/ImathBoxAlgo.h b/OpenEXR/include/OpenEXR/ImathBoxAlgo.h new file mode 100644 index 0000000..63bd2f6 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathBoxAlgo.h @@ -0,0 +1,1016 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMATHBOXALGO_H +#define INCLUDED_IMATHBOXALGO_H + + +//--------------------------------------------------------------------------- +// +// This file contains algorithms applied to or in conjunction +// with bounding boxes (Imath::Box). These algorithms require +// more headers to compile. The assumption made is that these +// functions are called much less often than the basic box +// functions or these functions require more support classes. +// +// Contains: +// +// T clip(const T& in, const Box& box) +// +// Vec3 closestPointOnBox(const Vec3&, const Box>& ) +// +// Vec3 closestPointInBox(const Vec3&, const Box>& ) +// +// Box< Vec3 > transform(const Box>&, const Matrix44&) +// Box< Vec3 > affineTransform(const Box>&, const Matrix44&) +// +// void transform(const Box>&, const Matrix44&, Box>&) +// void affineTransform(const Box>&, +// const Matrix44&, +// Box>&) +// +// bool findEntryAndExitPoints(const Line &line, +// const Box< Vec3 > &box, +// Vec3 &enterPoint, +// Vec3 &exitPoint) +// +// bool intersects(const Box> &box, +// const Line3 &ray, +// Vec3 intersectionPoint) +// +// bool intersects(const Box> &box, const Line3 &ray) +// +//--------------------------------------------------------------------------- + +#include "ImathBox.h" +#include "ImathMatrix.h" +#include "ImathLineAlgo.h" +#include "ImathPlane.h" +#include "ImathNamespace.h" + +IMATH_INTERNAL_NAMESPACE_HEADER_ENTER + + +template +inline T +clip (const T &p, const Box &box) +{ + // + // Clip the coordinates of a point, p, against a box. + // The result, q, is the closest point to p that is inside the box. + // + + T q; + + for (int i = 0; i < int (box.min.dimensions()); i++) + { + if (p[i] < box.min[i]) + q[i] = box.min[i]; + else if (p[i] > box.max[i]) + q[i] = box.max[i]; + else + q[i] = p[i]; + } + + return q; +} + + +template +inline T +closestPointInBox (const T &p, const Box &box) +{ + return clip (p, box); +} + + +template +Vec3 +closestPointOnBox (const Vec3 &p, const Box< Vec3 > &box) +{ + // + // Find the point, q, on the surface of + // the box, that is closest to point p. + // + // If the box is empty, return p. + // + + if (box.isEmpty()) + return p; + + Vec3 q = closestPointInBox (p, box); + + if (q == p) + { + Vec3 d1 = p - box.min; + Vec3 d2 = box.max - p; + + Vec3 d ((d1.x < d2.x)? d1.x: d2.x, + (d1.y < d2.y)? d1.y: d2.y, + (d1.z < d2.z)? d1.z: d2.z); + + if (d.x < d.y && d.x < d.z) + { + q.x = (d1.x < d2.x)? box.min.x: box.max.x; + } + else if (d.y < d.z) + { + q.y = (d1.y < d2.y)? box.min.y: box.max.y; + } + else + { + q.z = (d1.z < d2.z)? box.min.z: box.max.z; + } + } + + return q; +} + + +template +Box< Vec3 > +transform (const Box< Vec3 > &box, const Matrix44 &m) +{ + // + // Transform a 3D box by a matrix, and compute a new box that + // tightly encloses the transformed box. + // + // If m is an affine transform, then we use James Arvo's fast + // method as described in "Graphics Gems", Academic Press, 1990, + // pp. 548-550. + // + + // + // A transformed empty box is still empty, and a transformed infinite box + // is still infinite + // + + if (box.isEmpty() || box.isInfinite()) + return box; + + // + // If the last column of m is (0 0 0 1) then m is an affine + // transform, and we use the fast Graphics Gems trick. + // + + if (m[0][3] == 0 && m[1][3] == 0 && m[2][3] == 0 && m[3][3] == 1) + { + Box< Vec3 > newBox; + + for (int i = 0; i < 3; i++) + { + newBox.min[i] = newBox.max[i] = (S) m[3][i]; + + for (int j = 0; j < 3; j++) + { + S a, b; + + a = (S) m[j][i] * box.min[j]; + b = (S) m[j][i] * box.max[j]; + + if (a < b) + { + newBox.min[i] += a; + newBox.max[i] += b; + } + else + { + newBox.min[i] += b; + newBox.max[i] += a; + } + } + } + + return newBox; + } + + // + // M is a projection matrix. Do things the naive way: + // Transform the eight corners of the box, and find an + // axis-parallel box that encloses the transformed corners. + // + + Vec3 points[8]; + + points[0][0] = points[1][0] = points[2][0] = points[3][0] = box.min[0]; + points[4][0] = points[5][0] = points[6][0] = points[7][0] = box.max[0]; + + points[0][1] = points[1][1] = points[4][1] = points[5][1] = box.min[1]; + points[2][1] = points[3][1] = points[6][1] = points[7][1] = box.max[1]; + + points[0][2] = points[2][2] = points[4][2] = points[6][2] = box.min[2]; + points[1][2] = points[3][2] = points[5][2] = points[7][2] = box.max[2]; + + Box< Vec3 > newBox; + + for (int i = 0; i < 8; i++) + newBox.extendBy (points[i] * m); + + return newBox; +} + +template +void +transform (const Box< Vec3 > &box, + const Matrix44 &m, + Box< Vec3 > &result) +{ + // + // Transform a 3D box by a matrix, and compute a new box that + // tightly encloses the transformed box. + // + // If m is an affine transform, then we use James Arvo's fast + // method as described in "Graphics Gems", Academic Press, 1990, + // pp. 548-550. + // + + // + // A transformed empty box is still empty, and a transformed infinite + // box is still infinite + // + + if (box.isEmpty() || box.isInfinite()) + { + return; + } + + // + // If the last column of m is (0 0 0 1) then m is an affine + // transform, and we use the fast Graphics Gems trick. + // + + if (m[0][3] == 0 && m[1][3] == 0 && m[2][3] == 0 && m[3][3] == 1) + { + for (int i = 0; i < 3; i++) + { + result.min[i] = result.max[i] = (S) m[3][i]; + + for (int j = 0; j < 3; j++) + { + S a, b; + + a = (S) m[j][i] * box.min[j]; + b = (S) m[j][i] * box.max[j]; + + if (a < b) + { + result.min[i] += a; + result.max[i] += b; + } + else + { + result.min[i] += b; + result.max[i] += a; + } + } + } + + return; + } + + // + // M is a projection matrix. Do things the naive way: + // Transform the eight corners of the box, and find an + // axis-parallel box that encloses the transformed corners. + // + + Vec3 points[8]; + + points[0][0] = points[1][0] = points[2][0] = points[3][0] = box.min[0]; + points[4][0] = points[5][0] = points[6][0] = points[7][0] = box.max[0]; + + points[0][1] = points[1][1] = points[4][1] = points[5][1] = box.min[1]; + points[2][1] = points[3][1] = points[6][1] = points[7][1] = box.max[1]; + + points[0][2] = points[2][2] = points[4][2] = points[6][2] = box.min[2]; + points[1][2] = points[3][2] = points[5][2] = points[7][2] = box.max[2]; + + for (int i = 0; i < 8; i++) + result.extendBy (points[i] * m); +} + + +template +Box< Vec3 > +affineTransform (const Box< Vec3 > &box, const Matrix44 &m) +{ + // + // Transform a 3D box by a matrix whose rightmost column + // is (0 0 0 1), and compute a new box that tightly encloses + // the transformed box. + // + // As in the transform() function, above, we use James Arvo's + // fast method. + // + + if (box.isEmpty() || box.isInfinite()) + { + // + // A transformed empty or infinite box is still empty or infinite + // + + return box; + } + + Box< Vec3 > newBox; + + for (int i = 0; i < 3; i++) + { + newBox.min[i] = newBox.max[i] = (S) m[3][i]; + + for (int j = 0; j < 3; j++) + { + S a, b; + + a = (S) m[j][i] * box.min[j]; + b = (S) m[j][i] * box.max[j]; + + if (a < b) + { + newBox.min[i] += a; + newBox.max[i] += b; + } + else + { + newBox.min[i] += b; + newBox.max[i] += a; + } + } + } + + return newBox; +} + +template +void +affineTransform (const Box< Vec3 > &box, + const Matrix44 &m, + Box > &result) +{ + // + // Transform a 3D box by a matrix whose rightmost column + // is (0 0 0 1), and compute a new box that tightly encloses + // the transformed box. + // + // As in the transform() function, above, we use James Arvo's + // fast method. + // + + if (box.isEmpty()) + { + // + // A transformed empty box is still empty + // + result.makeEmpty(); + return; + } + + if (box.isInfinite()) + { + // + // A transformed infinite box is still infinite + // + result.makeInfinite(); + return; + } + + for (int i = 0; i < 3; i++) + { + result.min[i] = result.max[i] = (S) m[3][i]; + + for (int j = 0; j < 3; j++) + { + S a, b; + + a = (S) m[j][i] * box.min[j]; + b = (S) m[j][i] * box.max[j]; + + if (a < b) + { + result.min[i] += a; + result.max[i] += b; + } + else + { + result.min[i] += b; + result.max[i] += a; + } + } + } +} + + +template +bool +findEntryAndExitPoints (const Line3 &r, + const Box > &b, + Vec3 &entry, + Vec3 &exit) +{ + // + // Compute the points where a ray, r, enters and exits a box, b: + // + // findEntryAndExitPoints() returns + // + // - true if the ray starts inside the box or if the + // ray starts outside and intersects the box + // + // - false otherwise (that is, if the ray does not + // intersect the box) + // + // The entry and exit points are + // + // - points on two of the faces of the box when + // findEntryAndExitPoints() returns true + // (The entry end exit points may be on either + // side of the ray's origin) + // + // - undefined when findEntryAndExitPoints() + // returns false + // + + if (b.isEmpty()) + { + // + // No ray intersects an empty box + // + + return false; + } + + // + // The following description assumes that the ray's origin is outside + // the box, but the code below works even if the origin is inside the + // box: + // + // Between one and three "frontfacing" sides of the box are oriented + // towards the ray's origin, and between one and three "backfacing" + // sides are oriented away from the ray's origin. + // We intersect the ray with the planes that contain the sides of the + // box, and compare the distances between the ray's origin and the + // ray-plane intersections. The ray intersects the box if the most + // distant frontfacing intersection is nearer than the nearest + // backfacing intersection. If the ray does intersect the box, then + // the most distant frontfacing ray-plane intersection is the entry + // point and the nearest backfacing ray-plane intersection is the + // exit point. + // + + const T TMAX = limits::max(); + + T tFrontMax = -TMAX; + T tBackMin = TMAX; + + // + // Minimum and maximum X sides. + // + + if (r.dir.x >= 0) + { + T d1 = b.max.x - r.pos.x; + T d2 = b.min.x - r.pos.x; + + if (r.dir.x > 1 || + (abs (d1) < TMAX * r.dir.x && + abs (d2) < TMAX * r.dir.x)) + { + T t1 = d1 / r.dir.x; + T t2 = d2 / r.dir.x; + + if (tBackMin > t1) + { + tBackMin = t1; + + exit.x = b.max.x; + exit.y = clamp (r.pos.y + t1 * r.dir.y, b.min.y, b.max.y); + exit.z = clamp (r.pos.z + t1 * r.dir.z, b.min.z, b.max.z); + } + + if (tFrontMax < t2) + { + tFrontMax = t2; + + entry.x = b.min.x; + entry.y = clamp (r.pos.y + t2 * r.dir.y, b.min.y, b.max.y); + entry.z = clamp (r.pos.z + t2 * r.dir.z, b.min.z, b.max.z); + } + } + else if (r.pos.x < b.min.x || r.pos.x > b.max.x) + { + return false; + } + } + else // r.dir.x < 0 + { + T d1 = b.min.x - r.pos.x; + T d2 = b.max.x - r.pos.x; + + if (r.dir.x < -1 || + (abs (d1) < -TMAX * r.dir.x && + abs (d2) < -TMAX * r.dir.x)) + { + T t1 = d1 / r.dir.x; + T t2 = d2 / r.dir.x; + + if (tBackMin > t1) + { + tBackMin = t1; + + exit.x = b.min.x; + exit.y = clamp (r.pos.y + t1 * r.dir.y, b.min.y, b.max.y); + exit.z = clamp (r.pos.z + t1 * r.dir.z, b.min.z, b.max.z); + } + + if (tFrontMax < t2) + { + tFrontMax = t2; + + entry.x = b.max.x; + entry.y = clamp (r.pos.y + t2 * r.dir.y, b.min.y, b.max.y); + entry.z = clamp (r.pos.z + t2 * r.dir.z, b.min.z, b.max.z); + } + } + else if (r.pos.x < b.min.x || r.pos.x > b.max.x) + { + return false; + } + } + + // + // Minimum and maximum Y sides. + // + + if (r.dir.y >= 0) + { + T d1 = b.max.y - r.pos.y; + T d2 = b.min.y - r.pos.y; + + if (r.dir.y > 1 || + (abs (d1) < TMAX * r.dir.y && + abs (d2) < TMAX * r.dir.y)) + { + T t1 = d1 / r.dir.y; + T t2 = d2 / r.dir.y; + + if (tBackMin > t1) + { + tBackMin = t1; + + exit.x = clamp (r.pos.x + t1 * r.dir.x, b.min.x, b.max.x); + exit.y = b.max.y; + exit.z = clamp (r.pos.z + t1 * r.dir.z, b.min.z, b.max.z); + } + + if (tFrontMax < t2) + { + tFrontMax = t2; + + entry.x = clamp (r.pos.x + t2 * r.dir.x, b.min.x, b.max.x); + entry.y = b.min.y; + entry.z = clamp (r.pos.z + t2 * r.dir.z, b.min.z, b.max.z); + } + } + else if (r.pos.y < b.min.y || r.pos.y > b.max.y) + { + return false; + } + } + else // r.dir.y < 0 + { + T d1 = b.min.y - r.pos.y; + T d2 = b.max.y - r.pos.y; + + if (r.dir.y < -1 || + (abs (d1) < -TMAX * r.dir.y && + abs (d2) < -TMAX * r.dir.y)) + { + T t1 = d1 / r.dir.y; + T t2 = d2 / r.dir.y; + + if (tBackMin > t1) + { + tBackMin = t1; + + exit.x = clamp (r.pos.x + t1 * r.dir.x, b.min.x, b.max.x); + exit.y = b.min.y; + exit.z = clamp (r.pos.z + t1 * r.dir.z, b.min.z, b.max.z); + } + + if (tFrontMax < t2) + { + tFrontMax = t2; + + entry.x = clamp (r.pos.x + t2 * r.dir.x, b.min.x, b.max.x); + entry.y = b.max.y; + entry.z = clamp (r.pos.z + t2 * r.dir.z, b.min.z, b.max.z); + } + } + else if (r.pos.y < b.min.y || r.pos.y > b.max.y) + { + return false; + } + } + + // + // Minimum and maximum Z sides. + // + + if (r.dir.z >= 0) + { + T d1 = b.max.z - r.pos.z; + T d2 = b.min.z - r.pos.z; + + if (r.dir.z > 1 || + (abs (d1) < TMAX * r.dir.z && + abs (d2) < TMAX * r.dir.z)) + { + T t1 = d1 / r.dir.z; + T t2 = d2 / r.dir.z; + + if (tBackMin > t1) + { + tBackMin = t1; + + exit.x = clamp (r.pos.x + t1 * r.dir.x, b.min.x, b.max.x); + exit.y = clamp (r.pos.y + t1 * r.dir.y, b.min.y, b.max.y); + exit.z = b.max.z; + } + + if (tFrontMax < t2) + { + tFrontMax = t2; + + entry.x = clamp (r.pos.x + t2 * r.dir.x, b.min.x, b.max.x); + entry.y = clamp (r.pos.y + t2 * r.dir.y, b.min.y, b.max.y); + entry.z = b.min.z; + } + } + else if (r.pos.z < b.min.z || r.pos.z > b.max.z) + { + return false; + } + } + else // r.dir.z < 0 + { + T d1 = b.min.z - r.pos.z; + T d2 = b.max.z - r.pos.z; + + if (r.dir.z < -1 || + (abs (d1) < -TMAX * r.dir.z && + abs (d2) < -TMAX * r.dir.z)) + { + T t1 = d1 / r.dir.z; + T t2 = d2 / r.dir.z; + + if (tBackMin > t1) + { + tBackMin = t1; + + exit.x = clamp (r.pos.x + t1 * r.dir.x, b.min.x, b.max.x); + exit.y = clamp (r.pos.y + t1 * r.dir.y, b.min.y, b.max.y); + exit.z = b.min.z; + } + + if (tFrontMax < t2) + { + tFrontMax = t2; + + entry.x = clamp (r.pos.x + t2 * r.dir.x, b.min.x, b.max.x); + entry.y = clamp (r.pos.y + t2 * r.dir.y, b.min.y, b.max.y); + entry.z = b.max.z; + } + } + else if (r.pos.z < b.min.z || r.pos.z > b.max.z) + { + return false; + } + } + + return tFrontMax <= tBackMin; +} + + +template +bool +intersects (const Box< Vec3 > &b, const Line3 &r, Vec3 &ip) +{ + // + // Intersect a ray, r, with a box, b, and compute the intersection + // point, ip: + // + // intersect() returns + // + // - true if the ray starts inside the box or if the + // ray starts outside and intersects the box + // + // - false if the ray starts outside the box and intersects it, + // but the intersection is behind the ray's origin. + // + // - false if the ray starts outside and does not intersect it + // + // The intersection point is + // + // - the ray's origin if the ray starts inside the box + // + // - a point on one of the faces of the box if the ray + // starts outside the box + // + // - undefined when intersect() returns false + // + + if (b.isEmpty()) + { + // + // No ray intersects an empty box + // + + return false; + } + + if (b.intersects (r.pos)) + { + // + // The ray starts inside the box + // + + ip = r.pos; + return true; + } + + // + // The ray starts outside the box. Between one and three "frontfacing" + // sides of the box are oriented towards the ray, and between one and + // three "backfacing" sides are oriented away from the ray. + // We intersect the ray with the planes that contain the sides of the + // box, and compare the distances between ray's origin and the ray-plane + // intersections. + // The ray intersects the box if the most distant frontfacing intersection + // is nearer than the nearest backfacing intersection. If the ray does + // intersect the box, then the most distant frontfacing ray-plane + // intersection is the ray-box intersection. + // + + const T TMAX = limits::max(); + + T tFrontMax = -1; + T tBackMin = TMAX; + + // + // Minimum and maximum X sides. + // + + if (r.dir.x > 0) + { + if (r.pos.x > b.max.x) + return false; + + T d = b.max.x - r.pos.x; + + if (r.dir.x > 1 || d < TMAX * r.dir.x) + { + T t = d / r.dir.x; + + if (tBackMin > t) + tBackMin = t; + } + + if (r.pos.x <= b.min.x) + { + T d = b.min.x - r.pos.x; + T t = (r.dir.x > 1 || d < TMAX * r.dir.x)? d / r.dir.x: TMAX; + + if (tFrontMax < t) + { + tFrontMax = t; + + ip.x = b.min.x; + ip.y = clamp (r.pos.y + t * r.dir.y, b.min.y, b.max.y); + ip.z = clamp (r.pos.z + t * r.dir.z, b.min.z, b.max.z); + } + } + } + else if (r.dir.x < 0) + { + if (r.pos.x < b.min.x) + return false; + + T d = b.min.x - r.pos.x; + + if (r.dir.x < -1 || d > TMAX * r.dir.x) + { + T t = d / r.dir.x; + + if (tBackMin > t) + tBackMin = t; + } + + if (r.pos.x >= b.max.x) + { + T d = b.max.x - r.pos.x; + T t = (r.dir.x < -1 || d > TMAX * r.dir.x)? d / r.dir.x: TMAX; + + if (tFrontMax < t) + { + tFrontMax = t; + + ip.x = b.max.x; + ip.y = clamp (r.pos.y + t * r.dir.y, b.min.y, b.max.y); + ip.z = clamp (r.pos.z + t * r.dir.z, b.min.z, b.max.z); + } + } + } + else // r.dir.x == 0 + { + if (r.pos.x < b.min.x || r.pos.x > b.max.x) + return false; + } + + // + // Minimum and maximum Y sides. + // + + if (r.dir.y > 0) + { + if (r.pos.y > b.max.y) + return false; + + T d = b.max.y - r.pos.y; + + if (r.dir.y > 1 || d < TMAX * r.dir.y) + { + T t = d / r.dir.y; + + if (tBackMin > t) + tBackMin = t; + } + + if (r.pos.y <= b.min.y) + { + T d = b.min.y - r.pos.y; + T t = (r.dir.y > 1 || d < TMAX * r.dir.y)? d / r.dir.y: TMAX; + + if (tFrontMax < t) + { + tFrontMax = t; + + ip.x = clamp (r.pos.x + t * r.dir.x, b.min.x, b.max.x); + ip.y = b.min.y; + ip.z = clamp (r.pos.z + t * r.dir.z, b.min.z, b.max.z); + } + } + } + else if (r.dir.y < 0) + { + if (r.pos.y < b.min.y) + return false; + + T d = b.min.y - r.pos.y; + + if (r.dir.y < -1 || d > TMAX * r.dir.y) + { + T t = d / r.dir.y; + + if (tBackMin > t) + tBackMin = t; + } + + if (r.pos.y >= b.max.y) + { + T d = b.max.y - r.pos.y; + T t = (r.dir.y < -1 || d > TMAX * r.dir.y)? d / r.dir.y: TMAX; + + if (tFrontMax < t) + { + tFrontMax = t; + + ip.x = clamp (r.pos.x + t * r.dir.x, b.min.x, b.max.x); + ip.y = b.max.y; + ip.z = clamp (r.pos.z + t * r.dir.z, b.min.z, b.max.z); + } + } + } + else // r.dir.y == 0 + { + if (r.pos.y < b.min.y || r.pos.y > b.max.y) + return false; + } + + // + // Minimum and maximum Z sides. + // + + if (r.dir.z > 0) + { + if (r.pos.z > b.max.z) + return false; + + T d = b.max.z - r.pos.z; + + if (r.dir.z > 1 || d < TMAX * r.dir.z) + { + T t = d / r.dir.z; + + if (tBackMin > t) + tBackMin = t; + } + + if (r.pos.z <= b.min.z) + { + T d = b.min.z - r.pos.z; + T t = (r.dir.z > 1 || d < TMAX * r.dir.z)? d / r.dir.z: TMAX; + + if (tFrontMax < t) + { + tFrontMax = t; + + ip.x = clamp (r.pos.x + t * r.dir.x, b.min.x, b.max.x); + ip.y = clamp (r.pos.y + t * r.dir.y, b.min.y, b.max.y); + ip.z = b.min.z; + } + } + } + else if (r.dir.z < 0) + { + if (r.pos.z < b.min.z) + return false; + + T d = b.min.z - r.pos.z; + + if (r.dir.z < -1 || d > TMAX * r.dir.z) + { + T t = d / r.dir.z; + + if (tBackMin > t) + tBackMin = t; + } + + if (r.pos.z >= b.max.z) + { + T d = b.max.z - r.pos.z; + T t = (r.dir.z < -1 || d > TMAX * r.dir.z)? d / r.dir.z: TMAX; + + if (tFrontMax < t) + { + tFrontMax = t; + + ip.x = clamp (r.pos.x + t * r.dir.x, b.min.x, b.max.x); + ip.y = clamp (r.pos.y + t * r.dir.y, b.min.y, b.max.y); + ip.z = b.max.z; + } + } + } + else // r.dir.z == 0 + { + if (r.pos.z < b.min.z || r.pos.z > b.max.z) + return false; + } + + return tFrontMax <= tBackMin; +} + + +template +bool +intersects (const Box< Vec3 > &box, const Line3 &ray) +{ + Vec3 ignored; + return intersects (box, ray, ignored); +} + + +IMATH_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_IMATHBOXALGO_H diff --git a/OpenEXR/include/OpenEXR/ImathColor.h b/OpenEXR/include/OpenEXR/ImathColor.h new file mode 100644 index 0000000..743c72d --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathColor.h @@ -0,0 +1,736 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2004-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMATHCOLOR_H +#define INCLUDED_IMATHCOLOR_H + +//---------------------------------------------------- +// +// A three and four component color class template. +// +//---------------------------------------------------- + +#include "ImathVec.h" +#include "ImathNamespace.h" +#include "half.h" + +IMATH_INTERNAL_NAMESPACE_HEADER_ENTER + + +template +class Color3: public Vec3 +{ + public: + + //------------- + // Constructors + //------------- + + Color3 (); // no initialization + explicit Color3 (T a); // (a a a) + Color3 (T a, T b, T c); // (a b c) + + + //--------------------------------- + // Copy constructors and assignment + //--------------------------------- + + Color3 (const Color3 &c); + template Color3 (const Vec3 &v); + + const Color3 & operator = (const Color3 &c); + + + //------------------------ + // Component-wise addition + //------------------------ + + const Color3 & operator += (const Color3 &c); + Color3 operator + (const Color3 &c) const; + + + //--------------------------- + // Component-wise subtraction + //--------------------------- + + const Color3 & operator -= (const Color3 &c); + Color3 operator - (const Color3 &c) const; + + + //------------------------------------ + // Component-wise multiplication by -1 + //------------------------------------ + + Color3 operator - () const; + const Color3 & negate (); + + + //------------------------------ + // Component-wise multiplication + //------------------------------ + + const Color3 & operator *= (const Color3 &c); + const Color3 & operator *= (T a); + Color3 operator * (const Color3 &c) const; + Color3 operator * (T a) const; + + + //------------------------ + // Component-wise division + //------------------------ + + const Color3 & operator /= (const Color3 &c); + const Color3 & operator /= (T a); + Color3 operator / (const Color3 &c) const; + Color3 operator / (T a) const; +}; + +template class Color4 +{ + public: + + //------------------- + // Access to elements + //------------------- + + T r, g, b, a; + + T & operator [] (int i); + const T & operator [] (int i) const; + + + //------------- + // Constructors + //------------- + + Color4 (); // no initialization + explicit Color4 (T a); // (a a a a) + Color4 (T a, T b, T c, T d); // (a b c d) + + + //--------------------------------- + // Copy constructors and assignment + //--------------------------------- + + Color4 (const Color4 &v); + template Color4 (const Color4 &v); + + const Color4 & operator = (const Color4 &v); + + + //---------------------- + // Compatibility with Sb + //---------------------- + + template + void setValue (S a, S b, S c, S d); + + template + void setValue (const Color4 &v); + + template + void getValue (S &a, S &b, S &c, S &d) const; + + template + void getValue (Color4 &v) const; + + T * getValue(); + const T * getValue() const; + + + //--------- + // Equality + //--------- + + template + bool operator == (const Color4 &v) const; + + template + bool operator != (const Color4 &v) const; + + + //------------------------ + // Component-wise addition + //------------------------ + + const Color4 & operator += (const Color4 &v); + Color4 operator + (const Color4 &v) const; + + + //--------------------------- + // Component-wise subtraction + //--------------------------- + + const Color4 & operator -= (const Color4 &v); + Color4 operator - (const Color4 &v) const; + + + //------------------------------------ + // Component-wise multiplication by -1 + //------------------------------------ + + Color4 operator - () const; + const Color4 & negate (); + + + //------------------------------ + // Component-wise multiplication + //------------------------------ + + const Color4 & operator *= (const Color4 &v); + const Color4 & operator *= (T a); + Color4 operator * (const Color4 &v) const; + Color4 operator * (T a) const; + + + //------------------------ + // Component-wise division + //------------------------ + + const Color4 & operator /= (const Color4 &v); + const Color4 & operator /= (T a); + Color4 operator / (const Color4 &v) const; + Color4 operator / (T a) const; + + + //---------------------------------------------------------- + // Number of dimensions, i.e. number of elements in a Color4 + //---------------------------------------------------------- + + static unsigned int dimensions() {return 4;} + + + //------------------------------------------------- + // Limitations of type T (see also class limits) + //------------------------------------------------- + + static T baseTypeMin() {return limits::min();} + static T baseTypeMax() {return limits::max();} + static T baseTypeSmallest() {return limits::smallest();} + static T baseTypeEpsilon() {return limits::epsilon();} + + + //-------------------------------------------------------------- + // Base type -- in templates, which accept a parameter, V, which + // could be a Color4, you can refer to T as + // V::BaseType + //-------------------------------------------------------------- + + typedef T BaseType; +}; + +//-------------- +// Stream output +//-------------- + +template +std::ostream & operator << (std::ostream &s, const Color4 &v); + +//---------------------------------------------------- +// Reverse multiplication: S * Color4 +//---------------------------------------------------- + +template Color4 operator * (S a, const Color4 &v); + +//------------------------- +// Typedefs for convenience +//------------------------- + +typedef Color3 Color3f; +typedef Color3 Color3h; +typedef Color3 Color3c; +typedef Color3 C3h; +typedef Color3 C3f; +typedef Color3 C3c; +typedef Color4 Color4f; +typedef Color4 Color4h; +typedef Color4 Color4c; +typedef Color4 C4f; +typedef Color4 C4h; +typedef Color4 C4c; +typedef unsigned int PackedColor; + + +//------------------------- +// Implementation of Color3 +//------------------------- + +template +inline +Color3::Color3 (): Vec3 () +{ + // empty +} + +template +inline +Color3::Color3 (T a): Vec3 (a) +{ + // empty +} + +template +inline +Color3::Color3 (T a, T b, T c): Vec3 (a, b, c) +{ + // empty +} + +template +inline +Color3::Color3 (const Color3 &c): Vec3 (c) +{ + // empty +} + +template +template +inline +Color3::Color3 (const Vec3 &v): Vec3 (v) +{ + //empty +} + +template +inline const Color3 & +Color3::operator = (const Color3 &c) +{ + *((Vec3 *) this) = c; + return *this; +} + +template +inline const Color3 & +Color3::operator += (const Color3 &c) +{ + *((Vec3 *) this) += c; + return *this; +} + +template +inline Color3 +Color3::operator + (const Color3 &c) const +{ + return Color3 (*(Vec3 *)this + (const Vec3 &)c); +} + +template +inline const Color3 & +Color3::operator -= (const Color3 &c) +{ + *((Vec3 *) this) -= c; + return *this; +} + +template +inline Color3 +Color3::operator - (const Color3 &c) const +{ + return Color3 (*(Vec3 *)this - (const Vec3 &)c); +} + +template +inline Color3 +Color3::operator - () const +{ + return Color3 (-(*(Vec3 *)this)); +} + +template +inline const Color3 & +Color3::negate () +{ + ((Vec3 *) this)->negate(); + return *this; +} + +template +inline const Color3 & +Color3::operator *= (const Color3 &c) +{ + *((Vec3 *) this) *= c; + return *this; +} + +template +inline const Color3 & +Color3::operator *= (T a) +{ + *((Vec3 *) this) *= a; + return *this; +} + +template +inline Color3 +Color3::operator * (const Color3 &c) const +{ + return Color3 (*(Vec3 *)this * (const Vec3 &)c); +} + +template +inline Color3 +Color3::operator * (T a) const +{ + return Color3 (*(Vec3 *)this * a); +} + +template +inline const Color3 & +Color3::operator /= (const Color3 &c) +{ + *((Vec3 *) this) /= c; + return *this; +} + +template +inline const Color3 & +Color3::operator /= (T a) +{ + *((Vec3 *) this) /= a; + return *this; +} + +template +inline Color3 +Color3::operator / (const Color3 &c) const +{ + return Color3 (*(Vec3 *)this / (const Vec3 &)c); +} + +template +inline Color3 +Color3::operator / (T a) const +{ + return Color3 (*(Vec3 *)this / a); +} + +//----------------------- +// Implementation of Color4 +//----------------------- + +template +inline T & +Color4::operator [] (int i) +{ + return (&r)[i]; +} + +template +inline const T & +Color4::operator [] (int i) const +{ + return (&r)[i]; +} + +template +inline +Color4::Color4 () +{ + // empty +} + +template +inline +Color4::Color4 (T x) +{ + r = g = b = a = x; +} + +template +inline +Color4::Color4 (T x, T y, T z, T w) +{ + r = x; + g = y; + b = z; + a = w; +} + +template +inline +Color4::Color4 (const Color4 &v) +{ + r = v.r; + g = v.g; + b = v.b; + a = v.a; +} + +template +template +inline +Color4::Color4 (const Color4 &v) +{ + r = T (v.r); + g = T (v.g); + b = T (v.b); + a = T (v.a); +} + +template +inline const Color4 & +Color4::operator = (const Color4 &v) +{ + r = v.r; + g = v.g; + b = v.b; + a = v.a; + return *this; +} + +template +template +inline void +Color4::setValue (S x, S y, S z, S w) +{ + r = T (x); + g = T (y); + b = T (z); + a = T (w); +} + +template +template +inline void +Color4::setValue (const Color4 &v) +{ + r = T (v.r); + g = T (v.g); + b = T (v.b); + a = T (v.a); +} + +template +template +inline void +Color4::getValue (S &x, S &y, S &z, S &w) const +{ + x = S (r); + y = S (g); + z = S (b); + w = S (a); +} + +template +template +inline void +Color4::getValue (Color4 &v) const +{ + v.r = S (r); + v.g = S (g); + v.b = S (b); + v.a = S (a); +} + +template +inline T * +Color4::getValue() +{ + return (T *) &r; +} + +template +inline const T * +Color4::getValue() const +{ + return (const T *) &r; +} + +template +template +inline bool +Color4::operator == (const Color4 &v) const +{ + return r == v.r && g == v.g && b == v.b && a == v.a; +} + +template +template +inline bool +Color4::operator != (const Color4 &v) const +{ + return r != v.r || g != v.g || b != v.b || a != v.a; +} + +template +inline const Color4 & +Color4::operator += (const Color4 &v) +{ + r += v.r; + g += v.g; + b += v.b; + a += v.a; + return *this; +} + +template +inline Color4 +Color4::operator + (const Color4 &v) const +{ + return Color4 (r + v.r, g + v.g, b + v.b, a + v.a); +} + +template +inline const Color4 & +Color4::operator -= (const Color4 &v) +{ + r -= v.r; + g -= v.g; + b -= v.b; + a -= v.a; + return *this; +} + +template +inline Color4 +Color4::operator - (const Color4 &v) const +{ + return Color4 (r - v.r, g - v.g, b - v.b, a - v.a); +} + +template +inline Color4 +Color4::operator - () const +{ + return Color4 (-r, -g, -b, -a); +} + +template +inline const Color4 & +Color4::negate () +{ + r = -r; + g = -g; + b = -b; + a = -a; + return *this; +} + +template +inline const Color4 & +Color4::operator *= (const Color4 &v) +{ + r *= v.r; + g *= v.g; + b *= v.b; + a *= v.a; + return *this; +} + +template +inline const Color4 & +Color4::operator *= (T x) +{ + r *= x; + g *= x; + b *= x; + a *= x; + return *this; +} + +template +inline Color4 +Color4::operator * (const Color4 &v) const +{ + return Color4 (r * v.r, g * v.g, b * v.b, a * v.a); +} + +template +inline Color4 +Color4::operator * (T x) const +{ + return Color4 (r * x, g * x, b * x, a * x); +} + +template +inline const Color4 & +Color4::operator /= (const Color4 &v) +{ + r /= v.r; + g /= v.g; + b /= v.b; + a /= v.a; + return *this; +} + +template +inline const Color4 & +Color4::operator /= (T x) +{ + r /= x; + g /= x; + b /= x; + a /= x; + return *this; +} + +template +inline Color4 +Color4::operator / (const Color4 &v) const +{ + return Color4 (r / v.r, g / v.g, b / v.b, a / v.a); +} + +template +inline Color4 +Color4::operator / (T x) const +{ + return Color4 (r / x, g / x, b / x, a / x); +} + + +template +std::ostream & +operator << (std::ostream &s, const Color4 &v) +{ + return s << '(' << v.r << ' ' << v.g << ' ' << v.b << ' ' << v.a << ')'; +} + +//----------------------------------------- +// Implementation of reverse multiplication +//----------------------------------------- + +template +inline Color4 +operator * (S x, const Color4 &v) +{ + return Color4 (x * v.r, x * v.g, x * v.b, x * v.a); +} + + +IMATH_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_IMATHCOLOR_H diff --git a/OpenEXR/include/OpenEXR/ImathColorAlgo.h b/OpenEXR/include/OpenEXR/ImathColorAlgo.h new file mode 100644 index 0000000..cbc3be4 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathColorAlgo.h @@ -0,0 +1,257 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMATHCOLORALGO_H +#define INCLUDED_IMATHCOLORALGO_H + + +#include "ImathColor.h" +#include "ImathExport.h" +#include "ImathMath.h" +#include "ImathLimits.h" +#include "ImathNamespace.h" + +IMATH_INTERNAL_NAMESPACE_HEADER_ENTER + + +// +// Non-templated helper routines for color conversion. +// These routines eliminate type warnings under g++. +// + +IMATH_EXPORT Vec3 hsv2rgb_d(const Vec3 &hsv); + +IMATH_EXPORT Color4 hsv2rgb_d(const Color4 &hsv); + +IMATH_EXPORT Vec3 rgb2hsv_d(const Vec3 &rgb); + +IMATH_EXPORT Color4 rgb2hsv_d(const Color4 &rgb); + + +// +// Color conversion functions and general color algorithms +// +// hsv2rgb(), rgb2hsv(), rgb2packed(), packed2rgb() +// see each funtion definition for details. +// + +template +Vec3 +hsv2rgb(const Vec3 &hsv) +{ + if ( limits::isIntegral() ) + { + Vec3 v = Vec3(hsv.x / double(limits::max()), + hsv.y / double(limits::max()), + hsv.z / double(limits::max())); + Vec3 c = hsv2rgb_d(v); + return Vec3((T) (c.x * limits::max()), + (T) (c.y * limits::max()), + (T) (c.z * limits::max())); + } + else + { + Vec3 v = Vec3(hsv.x, hsv.y, hsv.z); + Vec3 c = hsv2rgb_d(v); + return Vec3((T) c.x, (T) c.y, (T) c.z); + } +} + + +template +Color4 +hsv2rgb(const Color4 &hsv) +{ + if ( limits::isIntegral() ) + { + Color4 v = Color4(hsv.r / float(limits::max()), + hsv.g / float(limits::max()), + hsv.b / float(limits::max()), + hsv.a / float(limits::max())); + Color4 c = hsv2rgb_d(v); + return Color4((T) (c.r * limits::max()), + (T) (c.g * limits::max()), + (T) (c.b * limits::max()), + (T) (c.a * limits::max())); + } + else + { + Color4 v = Color4(hsv.r, hsv.g, hsv.b, hsv.a); + Color4 c = hsv2rgb_d(v); + return Color4((T) c.r, (T) c.g, (T) c.b, (T) c.a); + } +} + + +template +Vec3 +rgb2hsv(const Vec3 &rgb) +{ + if ( limits::isIntegral() ) + { + Vec3 v = Vec3(rgb.x / double(limits::max()), + rgb.y / double(limits::max()), + rgb.z / double(limits::max())); + Vec3 c = rgb2hsv_d(v); + return Vec3((T) (c.x * limits::max()), + (T) (c.y * limits::max()), + (T) (c.z * limits::max())); + } + else + { + Vec3 v = Vec3(rgb.x, rgb.y, rgb.z); + Vec3 c = rgb2hsv_d(v); + return Vec3((T) c.x, (T) c.y, (T) c.z); + } +} + + +template +Color4 +rgb2hsv(const Color4 &rgb) +{ + if ( limits::isIntegral() ) + { + Color4 v = Color4(rgb.r / float(limits::max()), + rgb.g / float(limits::max()), + rgb.b / float(limits::max()), + rgb.a / float(limits::max())); + Color4 c = rgb2hsv_d(v); + return Color4((T) (c.r * limits::max()), + (T) (c.g * limits::max()), + (T) (c.b * limits::max()), + (T) (c.a * limits::max())); + } + else + { + Color4 v = Color4(rgb.r, rgb.g, rgb.b, rgb.a); + Color4 c = rgb2hsv_d(v); + return Color4((T) c.r, (T) c.g, (T) c.b, (T) c.a); + } +} + +template +PackedColor +rgb2packed(const Vec3 &c) +{ + if ( limits::isIntegral() ) + { + float x = c.x / float(limits::max()); + float y = c.y / float(limits::max()); + float z = c.z / float(limits::max()); + return rgb2packed( V3f(x,y,z) ); + } + else + { + return ( (PackedColor) (c.x * 255) | + (((PackedColor) (c.y * 255)) << 8) | + (((PackedColor) (c.z * 255)) << 16) | 0xFF000000 ); + } +} + +template +PackedColor +rgb2packed(const Color4 &c) +{ + if ( limits::isIntegral() ) + { + float r = c.r / float(limits::max()); + float g = c.g / float(limits::max()); + float b = c.b / float(limits::max()); + float a = c.a / float(limits::max()); + return rgb2packed( C4f(r,g,b,a) ); + } + else + { + return ( (PackedColor) (c.r * 255) | + (((PackedColor) (c.g * 255)) << 8) | + (((PackedColor) (c.b * 255)) << 16) | + (((PackedColor) (c.a * 255)) << 24)); + } +} + +// +// This guy can't return the result because the template +// parameter would not be in the function signiture. So instead, +// its passed in as an argument. +// + +template +void +packed2rgb(PackedColor packed, Vec3 &out) +{ + if ( limits::isIntegral() ) + { + T f = limits::max() / ((PackedColor)0xFF); + out.x = (packed & 0xFF) * f; + out.y = ((packed & 0xFF00) >> 8) * f; + out.z = ((packed & 0xFF0000) >> 16) * f; + } + else + { + T f = T(1) / T(255); + out.x = (packed & 0xFF) * f; + out.y = ((packed & 0xFF00) >> 8) * f; + out.z = ((packed & 0xFF0000) >> 16) * f; + } +} + +template +void +packed2rgb(PackedColor packed, Color4 &out) +{ + if ( limits::isIntegral() ) + { + T f = limits::max() / ((PackedColor)0xFF); + out.r = (packed & 0xFF) * f; + out.g = ((packed & 0xFF00) >> 8) * f; + out.b = ((packed & 0xFF0000) >> 16) * f; + out.a = ((packed & 0xFF000000) >> 24) * f; + } + else + { + T f = T(1) / T(255); + out.r = (packed & 0xFF) * f; + out.g = ((packed & 0xFF00) >> 8) * f; + out.b = ((packed & 0xFF0000) >> 16) * f; + out.a = ((packed & 0xFF000000) >> 24) * f; + } +} + + +IMATH_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_IMATHCOLORALGO_H diff --git a/OpenEXR/include/OpenEXR/ImathEuler.h b/OpenEXR/include/OpenEXR/ImathEuler.h new file mode 100644 index 0000000..254c76f --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathEuler.h @@ -0,0 +1,926 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMATHEULER_H +#define INCLUDED_IMATHEULER_H + +//---------------------------------------------------------------------- +// +// template class Euler +// +// This class represents euler angle orientations. The class +// inherits from Vec3 to it can be freely cast. The additional +// information is the euler priorities rep. This class is +// essentially a rip off of Ken Shoemake's GemsIV code. It has +// been modified minimally to make it more understandable, but +// hardly enough to make it easy to grok completely. +// +// There are 24 possible combonations of Euler angle +// representations of which 12 are common in CG and you will +// probably only use 6 of these which in this scheme are the +// non-relative-non-repeating types. +// +// The representations can be partitioned according to two +// criteria: +// +// 1) Are the angles measured relative to a set of fixed axis +// or relative to each other (the latter being what happens +// when rotation matrices are multiplied together and is +// almost ubiquitous in the cg community) +// +// 2) Is one of the rotations repeated (ala XYX rotation) +// +// When you construct a given representation from scratch you +// must order the angles according to their priorities. So, the +// easiest is a softimage or aerospace (yaw/pitch/roll) ordering +// of ZYX. +// +// float x_rot = 1; +// float y_rot = 2; +// float z_rot = 3; +// +// Eulerf angles(z_rot, y_rot, x_rot, Eulerf::ZYX); +// -or- +// Eulerf angles( V3f(z_rot,y_rot,z_rot), Eulerf::ZYX ); +// +// If instead, the order was YXZ for instance you would have to +// do this: +// +// float x_rot = 1; +// float y_rot = 2; +// float z_rot = 3; +// +// Eulerf angles(y_rot, x_rot, z_rot, Eulerf::YXZ); +// -or- +// Eulerf angles( V3f(y_rot,x_rot,z_rot), Eulerf::YXZ ); +// +// Notice how the order you put the angles into the three slots +// should correspond to the enum (YXZ) ordering. The input angle +// vector is called the "ijk" vector -- not an "xyz" vector. The +// ijk vector order is the same as the enum. If you treat the +// Euler<> as a Vec<> (which it inherts from) you will find the +// angles are ordered in the same way, i.e.: +// +// V3f v = angles; +// // v.x == y_rot, v.y == x_rot, v.z == z_rot +// +// If you just want the x, y, and z angles stored in a vector in +// that order, you can do this: +// +// V3f v = angles.toXYZVector() +// // v.x == x_rot, v.y == y_rot, v.z == z_rot +// +// If you want to set the Euler with an XYZVector use the +// optional layout argument: +// +// Eulerf angles(x_rot, y_rot, z_rot, +// Eulerf::YXZ, +// Eulerf::XYZLayout); +// +// This is the same as: +// +// Eulerf angles(y_rot, x_rot, z_rot, Eulerf::YXZ); +// +// Note that this won't do anything intelligent if you have a +// repeated axis in the euler angles (e.g. XYX) +// +// If you need to use the "relative" versions of these, you will +// need to use the "r" enums. +// +// The units of the rotation angles are assumed to be radians. +// +//---------------------------------------------------------------------- + + +#include "ImathMath.h" +#include "ImathVec.h" +#include "ImathQuat.h" +#include "ImathMatrix.h" +#include "ImathLimits.h" +#include "ImathNamespace.h" + +#include + +IMATH_INTERNAL_NAMESPACE_HEADER_ENTER + +#if (defined _WIN32 || defined _WIN64) && defined _MSC_VER +// Disable MS VC++ warnings about conversion from double to float +#pragma warning(disable:4244) +#endif + +template +class Euler : public Vec3 +{ + public: + + using Vec3::x; + using Vec3::y; + using Vec3::z; + + enum Order + { + // + // All 24 possible orderings + // + + XYZ = 0x0101, // "usual" orderings + XZY = 0x0001, + YZX = 0x1101, + YXZ = 0x1001, + ZXY = 0x2101, + ZYX = 0x2001, + + XZX = 0x0011, // first axis repeated + XYX = 0x0111, + YXY = 0x1011, + YZY = 0x1111, + ZYZ = 0x2011, + ZXZ = 0x2111, + + XYZr = 0x2000, // relative orderings -- not common + XZYr = 0x2100, + YZXr = 0x1000, + YXZr = 0x1100, + ZXYr = 0x0000, + ZYXr = 0x0100, + + XZXr = 0x2110, // relative first axis repeated + XYXr = 0x2010, + YXYr = 0x1110, + YZYr = 0x1010, + ZYZr = 0x0110, + ZXZr = 0x0010, + // |||| + // VVVV + // Legend: ABCD + // A -> Initial Axis (0==x, 1==y, 2==z) + // B -> Parity Even (1==true) + // C -> Initial Repeated (1==true) + // D -> Frame Static (1==true) + // + + Legal = XYZ | XZY | YZX | YXZ | ZXY | ZYX | + XZX | XYX | YXY | YZY | ZYZ | ZXZ | + XYZr| XZYr| YZXr| YXZr| ZXYr| ZYXr| + XZXr| XYXr| YXYr| YZYr| ZYZr| ZXZr, + + Min = 0x0000, + Max = 0x2111, + Default = XYZ + }; + + enum Axis { X = 0, Y = 1, Z = 2 }; + + enum InputLayout { XYZLayout, IJKLayout }; + + //-------------------------------------------------------------------- + // Constructors -- all default to ZYX non-relative ala softimage + // (where there is no argument to specify it) + // + // The Euler-from-matrix constructors assume that the matrix does + // not include shear or non-uniform scaling, but the constructors + // do not examine the matrix to verify this assumption. If necessary, + // you can adjust the matrix by calling the removeScalingAndShear() + // function, defined in ImathMatrixAlgo.h. + //-------------------------------------------------------------------- + + Euler(); + Euler(const Euler&); + Euler(Order p); + Euler(const Vec3 &v, Order o = Default, InputLayout l = IJKLayout); + Euler(T i, T j, T k, Order o = Default, InputLayout l = IJKLayout); + Euler(const Euler &euler, Order newp); + Euler(const Matrix33 &, Order o = Default); + Euler(const Matrix44 &, Order o = Default); + + //--------------------------------- + // Algebraic functions/ Operators + //--------------------------------- + + const Euler& operator= (const Euler&); + const Euler& operator= (const Vec3&); + + //-------------------------------------------------------- + // Set the euler value + // This does NOT convert the angles, but setXYZVector() + // does reorder the input vector. + //-------------------------------------------------------- + + static bool legal(Order); + + void setXYZVector(const Vec3 &); + + Order order() const; + void setOrder(Order); + + void set(Axis initial, + bool relative, + bool parityEven, + bool firstRepeats); + + //------------------------------------------------------------ + // Conversions, toXYZVector() reorders the angles so that + // the X rotation comes first, followed by the Y and Z + // in cases like XYX ordering, the repeated angle will be + // in the "z" component + // + // The Euler-from-matrix extract() functions assume that the + // matrix does not include shear or non-uniform scaling, but + // the extract() functions do not examine the matrix to verify + // this assumption. If necessary, you can adjust the matrix + // by calling the removeScalingAndShear() function, defined + // in ImathMatrixAlgo.h. + //------------------------------------------------------------ + + void extract(const Matrix33&); + void extract(const Matrix44&); + void extract(const Quat&); + + Matrix33 toMatrix33() const; + Matrix44 toMatrix44() const; + Quat toQuat() const; + Vec3 toXYZVector() const; + + //--------------------------------------------------- + // Use this function to unpack angles from ijk form + //--------------------------------------------------- + + void angleOrder(int &i, int &j, int &k) const; + + //--------------------------------------------------- + // Use this function to determine mapping from xyz to ijk + // - reshuffles the xyz to match the order + //--------------------------------------------------- + + void angleMapping(int &i, int &j, int &k) const; + + //---------------------------------------------------------------------- + // + // Utility methods for getting continuous rotations. None of these + // methods change the orientation given by its inputs (or at least + // that is the intent). + // + // angleMod() converts an angle to its equivalent in [-PI, PI] + // + // simpleXYZRotation() adjusts xyzRot so that its components differ + // from targetXyzRot by no more than +-PI + // + // nearestRotation() adjusts xyzRot so that its components differ + // from targetXyzRot by as little as possible. + // Note that xyz here really means ijk, because + // the order must be provided. + // + // makeNear() adjusts "this" Euler so that its components differ + // from target by as little as possible. This method + // might not make sense for Eulers with different order + // and it probably doesn't work for repeated axis and + // relative orderings (TODO). + // + //----------------------------------------------------------------------- + + static float angleMod (T angle); + static void simpleXYZRotation (Vec3 &xyzRot, + const Vec3 &targetXyzRot); + static void nearestRotation (Vec3 &xyzRot, + const Vec3 &targetXyzRot, + Order order = XYZ); + + void makeNear (const Euler &target); + + bool frameStatic() const { return _frameStatic; } + bool initialRepeated() const { return _initialRepeated; } + bool parityEven() const { return _parityEven; } + Axis initialAxis() const { return _initialAxis; } + + protected: + + bool _frameStatic : 1; // relative or static rotations + bool _initialRepeated : 1; // init axis repeated as last + bool _parityEven : 1; // "parity of axis permutation" +#if defined _WIN32 || defined _WIN64 + Axis _initialAxis ; // First axis of rotation +#else + Axis _initialAxis : 2; // First axis of rotation +#endif +}; + + +//-------------------- +// Convenient typedefs +//-------------------- + +typedef Euler Eulerf; +typedef Euler Eulerd; + + +//--------------- +// Implementation +//--------------- + +template +inline void + Euler::angleOrder(int &i, int &j, int &k) const +{ + i = _initialAxis; + j = _parityEven ? (i+1)%3 : (i > 0 ? i-1 : 2); + k = _parityEven ? (i > 0 ? i-1 : 2) : (i+1)%3; +} + +template +inline void + Euler::angleMapping(int &i, int &j, int &k) const +{ + int m[3]; + + m[_initialAxis] = 0; + m[(_initialAxis+1) % 3] = _parityEven ? 1 : 2; + m[(_initialAxis+2) % 3] = _parityEven ? 2 : 1; + i = m[0]; + j = m[1]; + k = m[2]; +} + +template +inline void +Euler::setXYZVector(const Vec3 &v) +{ + int i,j,k; + angleMapping(i,j,k); + (*this)[i] = v.x; + (*this)[j] = v.y; + (*this)[k] = v.z; +} + +template +inline Vec3 +Euler::toXYZVector() const +{ + int i,j,k; + angleMapping(i,j,k); + return Vec3((*this)[i],(*this)[j],(*this)[k]); +} + + +template +Euler::Euler() : + Vec3(0,0,0), + _frameStatic(true), + _initialRepeated(false), + _parityEven(true), + _initialAxis(X) +{} + +template +Euler::Euler(typename Euler::Order p) : + Vec3(0,0,0), + _frameStatic(true), + _initialRepeated(false), + _parityEven(true), + _initialAxis(X) +{ + setOrder(p); +} + +template +inline Euler::Euler( const Vec3 &v, + typename Euler::Order p, + typename Euler::InputLayout l ) +{ + setOrder(p); + if ( l == XYZLayout ) setXYZVector(v); + else { x = v.x; y = v.y; z = v.z; } +} + +template +inline Euler::Euler(const Euler &euler) +{ + operator=(euler); +} + +template +inline Euler::Euler(const Euler &euler,Order p) +{ + setOrder(p); + Matrix33 M = euler.toMatrix33(); + extract(M); +} + +template +inline Euler::Euler( T xi, T yi, T zi, + typename Euler::Order p, + typename Euler::InputLayout l) +{ + setOrder(p); + if ( l == XYZLayout ) setXYZVector(Vec3(xi,yi,zi)); + else { x = xi; y = yi; z = zi; } +} + +template +inline Euler::Euler( const Matrix33 &M, typename Euler::Order p ) +{ + setOrder(p); + extract(M); +} + +template +inline Euler::Euler( const Matrix44 &M, typename Euler::Order p ) +{ + setOrder(p); + extract(M); +} + +template +inline void Euler::extract(const Quat &q) +{ + extract(q.toMatrix33()); +} + +template +void Euler::extract(const Matrix33 &M) +{ + int i,j,k; + angleOrder(i,j,k); + + if (_initialRepeated) + { + // + // Extract the first angle, x. + // + + x = Math::atan2 (M[j][i], M[k][i]); + + // + // Remove the x rotation from M, so that the remaining + // rotation, N, is only around two axes, and gimbal lock + // cannot occur. + // + + Vec3 r (0, 0, 0); + r[i] = (_parityEven? -x: x); + + Matrix44 N; + N.rotate (r); + + N = N * Matrix44 (M[0][0], M[0][1], M[0][2], 0, + M[1][0], M[1][1], M[1][2], 0, + M[2][0], M[2][1], M[2][2], 0, + 0, 0, 0, 1); + // + // Extract the other two angles, y and z, from N. + // + + T sy = Math::sqrt (N[j][i]*N[j][i] + N[k][i]*N[k][i]); + y = Math::atan2 (sy, N[i][i]); + z = Math::atan2 (N[j][k], N[j][j]); + } + else + { + // + // Extract the first angle, x. + // + + x = Math::atan2 (M[j][k], M[k][k]); + + // + // Remove the x rotation from M, so that the remaining + // rotation, N, is only around two axes, and gimbal lock + // cannot occur. + // + + Vec3 r (0, 0, 0); + r[i] = (_parityEven? -x: x); + + Matrix44 N; + N.rotate (r); + + N = N * Matrix44 (M[0][0], M[0][1], M[0][2], 0, + M[1][0], M[1][1], M[1][2], 0, + M[2][0], M[2][1], M[2][2], 0, + 0, 0, 0, 1); + // + // Extract the other two angles, y and z, from N. + // + + T cy = Math::sqrt (N[i][i]*N[i][i] + N[i][j]*N[i][j]); + y = Math::atan2 (-N[i][k], cy); + z = Math::atan2 (-N[j][i], N[j][j]); + } + + if (!_parityEven) + *this *= -1; + + if (!_frameStatic) + { + T t = x; + x = z; + z = t; + } +} + +template +void Euler::extract(const Matrix44 &M) +{ + int i,j,k; + angleOrder(i,j,k); + + if (_initialRepeated) + { + // + // Extract the first angle, x. + // + + x = Math::atan2 (M[j][i], M[k][i]); + + // + // Remove the x rotation from M, so that the remaining + // rotation, N, is only around two axes, and gimbal lock + // cannot occur. + // + + Vec3 r (0, 0, 0); + r[i] = (_parityEven? -x: x); + + Matrix44 N; + N.rotate (r); + N = N * M; + + // + // Extract the other two angles, y and z, from N. + // + + T sy = Math::sqrt (N[j][i]*N[j][i] + N[k][i]*N[k][i]); + y = Math::atan2 (sy, N[i][i]); + z = Math::atan2 (N[j][k], N[j][j]); + } + else + { + // + // Extract the first angle, x. + // + + x = Math::atan2 (M[j][k], M[k][k]); + + // + // Remove the x rotation from M, so that the remaining + // rotation, N, is only around two axes, and gimbal lock + // cannot occur. + // + + Vec3 r (0, 0, 0); + r[i] = (_parityEven? -x: x); + + Matrix44 N; + N.rotate (r); + N = N * M; + + // + // Extract the other two angles, y and z, from N. + // + + T cy = Math::sqrt (N[i][i]*N[i][i] + N[i][j]*N[i][j]); + y = Math::atan2 (-N[i][k], cy); + z = Math::atan2 (-N[j][i], N[j][j]); + } + + if (!_parityEven) + *this *= -1; + + if (!_frameStatic) + { + T t = x; + x = z; + z = t; + } +} + +template +Matrix33 Euler::toMatrix33() const +{ + int i,j,k; + angleOrder(i,j,k); + + Vec3 angles; + + if ( _frameStatic ) angles = (*this); + else angles = Vec3(z,y,x); + + if ( !_parityEven ) angles *= -1.0; + + T ci = Math::cos(angles.x); + T cj = Math::cos(angles.y); + T ch = Math::cos(angles.z); + T si = Math::sin(angles.x); + T sj = Math::sin(angles.y); + T sh = Math::sin(angles.z); + + T cc = ci*ch; + T cs = ci*sh; + T sc = si*ch; + T ss = si*sh; + + Matrix33 M; + + if ( _initialRepeated ) + { + M[i][i] = cj; M[j][i] = sj*si; M[k][i] = sj*ci; + M[i][j] = sj*sh; M[j][j] = -cj*ss+cc; M[k][j] = -cj*cs-sc; + M[i][k] = -sj*ch; M[j][k] = cj*sc+cs; M[k][k] = cj*cc-ss; + } + else + { + M[i][i] = cj*ch; M[j][i] = sj*sc-cs; M[k][i] = sj*cc+ss; + M[i][j] = cj*sh; M[j][j] = sj*ss+cc; M[k][j] = sj*cs-sc; + M[i][k] = -sj; M[j][k] = cj*si; M[k][k] = cj*ci; + } + + return M; +} + +template +Matrix44 Euler::toMatrix44() const +{ + int i,j,k; + angleOrder(i,j,k); + + Vec3 angles; + + if ( _frameStatic ) angles = (*this); + else angles = Vec3(z,y,x); + + if ( !_parityEven ) angles *= -1.0; + + T ci = Math::cos(angles.x); + T cj = Math::cos(angles.y); + T ch = Math::cos(angles.z); + T si = Math::sin(angles.x); + T sj = Math::sin(angles.y); + T sh = Math::sin(angles.z); + + T cc = ci*ch; + T cs = ci*sh; + T sc = si*ch; + T ss = si*sh; + + Matrix44 M; + + if ( _initialRepeated ) + { + M[i][i] = cj; M[j][i] = sj*si; M[k][i] = sj*ci; + M[i][j] = sj*sh; M[j][j] = -cj*ss+cc; M[k][j] = -cj*cs-sc; + M[i][k] = -sj*ch; M[j][k] = cj*sc+cs; M[k][k] = cj*cc-ss; + } + else + { + M[i][i] = cj*ch; M[j][i] = sj*sc-cs; M[k][i] = sj*cc+ss; + M[i][j] = cj*sh; M[j][j] = sj*ss+cc; M[k][j] = sj*cs-sc; + M[i][k] = -sj; M[j][k] = cj*si; M[k][k] = cj*ci; + } + + return M; +} + +template +Quat Euler::toQuat() const +{ + Vec3 angles; + int i,j,k; + angleOrder(i,j,k); + + if ( _frameStatic ) angles = (*this); + else angles = Vec3(z,y,x); + + if ( !_parityEven ) angles.y = -angles.y; + + T ti = angles.x*0.5; + T tj = angles.y*0.5; + T th = angles.z*0.5; + T ci = Math::cos(ti); + T cj = Math::cos(tj); + T ch = Math::cos(th); + T si = Math::sin(ti); + T sj = Math::sin(tj); + T sh = Math::sin(th); + T cc = ci*ch; + T cs = ci*sh; + T sc = si*ch; + T ss = si*sh; + + T parity = _parityEven ? 1.0 : -1.0; + + Quat q; + Vec3 a; + + if ( _initialRepeated ) + { + a[i] = cj*(cs + sc); + a[j] = sj*(cc + ss) * parity, + a[k] = sj*(cs - sc); + q.r = cj*(cc - ss); + } + else + { + a[i] = cj*sc - sj*cs, + a[j] = (cj*ss + sj*cc) * parity, + a[k] = cj*cs - sj*sc; + q.r = cj*cc + sj*ss; + } + + q.v = a; + + return q; +} + +template +inline bool +Euler::legal(typename Euler::Order order) +{ + return (order & ~Legal) ? false : true; +} + +template +typename Euler::Order +Euler::order() const +{ + int foo = (_initialAxis == Z ? 0x2000 : (_initialAxis == Y ? 0x1000 : 0)); + + if (_parityEven) foo |= 0x0100; + if (_initialRepeated) foo |= 0x0010; + if (_frameStatic) foo++; + + return (Order)foo; +} + +template +inline void Euler::setOrder(typename Euler::Order p) +{ + set( p & 0x2000 ? Z : (p & 0x1000 ? Y : X), // initial axis + !(p & 0x1), // static? + !!(p & 0x100), // permutation even? + !!(p & 0x10)); // initial repeats? +} + +template +void Euler::set(typename Euler::Axis axis, + bool relative, + bool parityEven, + bool firstRepeats) +{ + _initialAxis = axis; + _frameStatic = !relative; + _parityEven = parityEven; + _initialRepeated = firstRepeats; +} + +template +const Euler& Euler::operator= (const Euler &euler) +{ + x = euler.x; + y = euler.y; + z = euler.z; + _initialAxis = euler._initialAxis; + _frameStatic = euler._frameStatic; + _parityEven = euler._parityEven; + _initialRepeated = euler._initialRepeated; + return *this; +} + +template +const Euler& Euler::operator= (const Vec3 &v) +{ + x = v.x; + y = v.y; + z = v.z; + return *this; +} + +template +std::ostream& operator << (std::ostream &o, const Euler &euler) +{ + char a[3] = { 'X', 'Y', 'Z' }; + + const char* r = euler.frameStatic() ? "" : "r"; + int i,j,k; + euler.angleOrder(i,j,k); + + if ( euler.initialRepeated() ) k = i; + + return o << "(" + << euler.x << " " + << euler.y << " " + << euler.z << " " + << a[i] << a[j] << a[k] << r << ")"; +} + +template +float +Euler::angleMod (T angle) +{ + angle = fmod(T (angle), T (2 * M_PI)); + + if (angle < -M_PI) angle += 2 * M_PI; + if (angle > +M_PI) angle -= 2 * M_PI; + + return angle; +} + +template +void +Euler::simpleXYZRotation (Vec3 &xyzRot, const Vec3 &targetXyzRot) +{ + Vec3 d = xyzRot - targetXyzRot; + xyzRot[0] = targetXyzRot[0] + angleMod(d[0]); + xyzRot[1] = targetXyzRot[1] + angleMod(d[1]); + xyzRot[2] = targetXyzRot[2] + angleMod(d[2]); +} + +template +void +Euler::nearestRotation (Vec3 &xyzRot, const Vec3 &targetXyzRot, + Order order) +{ + int i,j,k; + Euler e (0,0,0, order); + e.angleOrder(i,j,k); + + simpleXYZRotation(xyzRot, targetXyzRot); + + Vec3 otherXyzRot; + otherXyzRot[i] = M_PI+xyzRot[i]; + otherXyzRot[j] = M_PI-xyzRot[j]; + otherXyzRot[k] = M_PI+xyzRot[k]; + + simpleXYZRotation(otherXyzRot, targetXyzRot); + + Vec3 d = xyzRot - targetXyzRot; + Vec3 od = otherXyzRot - targetXyzRot; + T dMag = d.dot(d); + T odMag = od.dot(od); + + if (odMag < dMag) + { + xyzRot = otherXyzRot; + } +} + +template +void +Euler::makeNear (const Euler &target) +{ + Vec3 xyzRot = toXYZVector(); + Vec3 targetXyz; + if (order() != target.order()) + { + Euler targetSameOrder = Euler(target, order()); + targetXyz = targetSameOrder.toXYZVector(); + } + else + { + targetXyz = target.toXYZVector(); + } + + nearestRotation(xyzRot, targetXyz, order()); + + setXYZVector(xyzRot); +} + +#if (defined _WIN32 || defined _WIN64) && defined _MSC_VER +#pragma warning(default:4244) +#endif + +IMATH_INTERNAL_NAMESPACE_HEADER_EXIT + + +#endif // INCLUDED_IMATHEULER_H diff --git a/OpenEXR/include/OpenEXR/ImathExc.h b/OpenEXR/include/OpenEXR/ImathExc.h new file mode 100644 index 0000000..65af3b5 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathExc.h @@ -0,0 +1,73 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMATHEXC_H +#define INCLUDED_IMATHEXC_H + + +//----------------------------------------------- +// +// Imath library-specific exceptions +// +//----------------------------------------------- + +#include "ImathNamespace.h" +#include "IexBaseExc.h" +#include "ImathExport.h" + +IMATH_INTERNAL_NAMESPACE_HEADER_ENTER + +// Attempt to normalize null vector +DEFINE_EXC_EXP (IMATH_EXPORT, NullVecExc, ::IEX_NAMESPACE::MathExc) + +// Attempt to normalize a point at infinity +DEFINE_EXC_EXP (IMATH_EXPORT, InfPointExc, ::IEX_NAMESPACE::MathExc) + +// Attempt to normalize null quaternion +DEFINE_EXC_EXP (IMATH_EXPORT, NullQuatExc, ::IEX_NAMESPACE::MathExc) + +// Attempt to invert singular matrix +DEFINE_EXC_EXP (IMATH_EXPORT, SingMatrixExc, ::IEX_NAMESPACE::MathExc) + +// Attempt to remove zero scaling from matrix +DEFINE_EXC_EXP (IMATH_EXPORT, ZeroScaleExc, ::IEX_NAMESPACE::MathExc) + +// Attempt to normalize a vector of whose elementsare an integer type +DEFINE_EXC_EXP (IMATH_EXPORT, IntVecNormalizeExc, ::IEX_NAMESPACE::MathExc) + + +IMATH_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_IMATHEXC_H diff --git a/OpenEXR/include/OpenEXR/ImathExport.h b/OpenEXR/include/OpenEXR/ImathExport.h new file mode 100644 index 0000000..4357c12 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathExport.h @@ -0,0 +1,46 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + +#if defined(OPENEXR_DLL) + #if defined(IMATH_EXPORTS) + #define IMATH_EXPORT __declspec(dllexport) + #define IMATH_EXPORT_CONST extern __declspec(dllexport) + #else + #define IMATH_EXPORT __declspec(dllimport) + #define IMATH_EXPORT_CONST extern __declspec(dllimport) + #endif +#else + #define IMATH_EXPORT + #define IMATH_EXPORT_CONST extern const +#endif diff --git a/OpenEXR/include/OpenEXR/ImathForward.h b/OpenEXR/include/OpenEXR/ImathForward.h new file mode 100644 index 0000000..39d398c --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathForward.h @@ -0,0 +1,72 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDED_IMATHFORWARD_H +#define INCLUDED_IMATHFORWARD_H + +#include "ImathNamespace.h" + +IMATH_INTERNAL_NAMESPACE_HEADER_ENTER + +// +// Basic template type declarations. +// + +template class Box; +template class Color3; +template class Color4; +template class Euler; +template class Frustum; +template class FrustumTest; +template class Interval; +template class Line3; +template class Matrix33; +template class Matrix44; +template class Plane3; +template class Quat; +template class Shear6; +template class Sphere3; +template class TMatrix; +template class TMatrixBase; +template class TMatrixData; +template class Vec2; +template class Vec3; +template class Vec4; + +class Rand32; +class Rand48; + +IMATH_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_IMATHFORWARD_H diff --git a/OpenEXR/include/OpenEXR/ImathFrame.h b/OpenEXR/include/OpenEXR/ImathFrame.h new file mode 100644 index 0000000..95ebb66 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathFrame.h @@ -0,0 +1,192 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMATHFRAME_H +#define INCLUDED_IMATHFRAME_H + +#include "ImathNamespace.h" + +IMATH_INTERNAL_NAMESPACE_HEADER_ENTER + +template class Vec3; +template class Matrix44; + +// +// These methods compute a set of reference frames, defined by their +// transformation matrix, along a curve. It is designed so that the +// array of points and the array of matrices used to fetch these routines +// don't need to be ordered as the curve. +// +// A typical usage would be : +// +// m[0] = IMATH_INTERNAL_NAMESPACE::firstFrame( p[0], p[1], p[2] ); +// for( int i = 1; i < n - 1; i++ ) +// { +// m[i] = IMATH_INTERNAL_NAMESPACE::nextFrame( m[i-1], p[i-1], p[i], t[i-1], t[i] ); +// } +// m[n-1] = IMATH_INTERNAL_NAMESPACE::lastFrame( m[n-2], p[n-2], p[n-1] ); +// +// See Graphics Gems I for the underlying algorithm. +// + +template Matrix44 firstFrame( const Vec3&, // First point + const Vec3&, // Second point + const Vec3& ); // Third point + +template Matrix44 nextFrame( const Matrix44&, // Previous matrix + const Vec3&, // Previous point + const Vec3&, // Current point + Vec3&, // Previous tangent + Vec3& ); // Current tangent + +template Matrix44 lastFrame( const Matrix44&, // Previous matrix + const Vec3&, // Previous point + const Vec3& ); // Last point + +// +// firstFrame - Compute the first reference frame along a curve. +// +// This function returns the transformation matrix to the reference frame +// defined by the three points 'pi', 'pj' and 'pk'. Note that if the two +// vectors and are colinears, an arbitrary twist value will +// be choosen. +// +// Throw 'NullVecExc' if 'pi' and 'pj' are equals. +// + +template Matrix44 firstFrame +( + const Vec3& pi, // First point + const Vec3& pj, // Second point + const Vec3& pk ) // Third point +{ + Vec3 t = pj - pi; t.normalizeExc(); + + Vec3 n = t.cross( pk - pi ); n.normalize(); + if( n.length() == 0.0f ) + { + int i = fabs( t[0] ) < fabs( t[1] ) ? 0 : 1; + if( fabs( t[2] ) < fabs( t[i] )) i = 2; + + Vec3 v( 0.0, 0.0, 0.0 ); v[i] = 1.0; + n = t.cross( v ); n.normalize(); + } + + Vec3 b = t.cross( n ); + + Matrix44 M; + + M[0][0] = t[0]; M[0][1] = t[1]; M[0][2] = t[2]; M[0][3] = 0.0, + M[1][0] = n[0]; M[1][1] = n[1]; M[1][2] = n[2]; M[1][3] = 0.0, + M[2][0] = b[0]; M[2][1] = b[1]; M[2][2] = b[2]; M[2][3] = 0.0, + M[3][0] = pi[0]; M[3][1] = pi[1]; M[3][2] = pi[2]; M[3][3] = 1.0; + + return M; +} + +// +// nextFrame - Compute the next reference frame along a curve. +// +// This function returns the transformation matrix to the next reference +// frame defined by the previously computed transformation matrix and the +// new point and tangent vector along the curve. +// + +template Matrix44 nextFrame +( + const Matrix44& Mi, // Previous matrix + const Vec3& pi, // Previous point + const Vec3& pj, // Current point + Vec3& ti, // Previous tangent vector + Vec3& tj ) // Current tangent vector +{ + Vec3 a(0.0, 0.0, 0.0); // Rotation axis. + T r = 0.0; // Rotation angle. + + if( ti.length() != 0.0 && tj.length() != 0.0 ) + { + ti.normalize(); tj.normalize(); + T dot = ti.dot( tj ); + + // + // This is *really* necessary : + // + + if( dot > 1.0 ) dot = 1.0; + else if( dot < -1.0 ) dot = -1.0; + + r = acosf( dot ); + a = ti.cross( tj ); + } + + if( a.length() != 0.0 && r != 0.0 ) + { + Matrix44 R; R.setAxisAngle( a, r ); + Matrix44 Tj; Tj.translate( pj ); + Matrix44 Ti; Ti.translate( -pi ); + + return Mi * Ti * R * Tj; + } + else + { + Matrix44 Tr; Tr.translate( pj - pi ); + + return Mi * Tr; + } +} + +// +// lastFrame - Compute the last reference frame along a curve. +// +// This function returns the transformation matrix to the last reference +// frame defined by the previously computed transformation matrix and the +// last point along the curve. +// + +template Matrix44 lastFrame +( + const Matrix44& Mi, // Previous matrix + const Vec3& pi, // Previous point + const Vec3& pj ) // Last point +{ + Matrix44 Tr; Tr.translate( pj - pi ); + + return Mi * Tr; +} + +IMATH_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_IMATHFRAME_H diff --git a/OpenEXR/include/OpenEXR/ImathFrustum.h b/OpenEXR/include/OpenEXR/ImathFrustum.h new file mode 100644 index 0000000..4df92c9 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathFrustum.h @@ -0,0 +1,741 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMATHFRUSTUM_H +#define INCLUDED_IMATHFRUSTUM_H + + +#include "ImathVec.h" +#include "ImathPlane.h" +#include "ImathLine.h" +#include "ImathMatrix.h" +#include "ImathLimits.h" +#include "ImathFun.h" +#include "ImathNamespace.h" + +#include "IexMathExc.h" + +IMATH_INTERNAL_NAMESPACE_HEADER_ENTER + +// +// template class Frustum +// +// The frustum is always located with the eye point at the +// origin facing down -Z. This makes the Frustum class +// compatable with OpenGL (or anything that assumes a camera +// looks down -Z, hence with a right-handed coordinate system) +// but not with RenderMan which assumes the camera looks down +// +Z. Additional functions are provided for conversion from +// and from various camera coordinate spaces. +// +// nearPlane/farPlane: near/far are keywords used by Microsoft's +// compiler, so we use nearPlane/farPlane instead to avoid +// issues. + + +template +class Frustum +{ + public: + Frustum(); + Frustum(const Frustum &); + Frustum(T nearPlane, T farPlane, T left, T right, T top, T bottom, bool ortho=false); + Frustum(T nearPlane, T farPlane, T fovx, T fovy, T aspect); + virtual ~Frustum(); + + //-------------------- + // Assignment operator + //-------------------- + + const Frustum & operator = (const Frustum &); + + //-------------------- + // Operators: ==, != + //-------------------- + + bool operator == (const Frustum &src) const; + bool operator != (const Frustum &src) const; + + //-------------------------------------------------------- + // Set functions change the entire state of the Frustum + //-------------------------------------------------------- + + void set(T nearPlane, T farPlane, + T left, T right, + T top, T bottom, + bool ortho=false); + + void set(T nearPlane, T farPlane, T fovx, T fovy, T aspect); + + //------------------------------------------------------ + // These functions modify an already valid frustum state + //------------------------------------------------------ + + void modifyNearAndFar(T nearPlane, T farPlane); + void setOrthographic(bool); + + //-------------- + // Access + //-------------- + + bool orthographic() const { return _orthographic; } + T nearPlane() const { return _nearPlane; } + T hither() const { return _nearPlane; } + T farPlane() const { return _farPlane; } + T yon() const { return _farPlane; } + T left() const { return _left; } + T right() const { return _right; } + T bottom() const { return _bottom; } + T top() const { return _top; } + + //----------------------------------------------------------------------- + // Sets the planes in p to be the six bounding planes of the frustum, in + // the following order: top, right, bottom, left, near, far. + // Note that the planes have normals that point out of the frustum. + // The version of this routine that takes a matrix applies that matrix + // to transform the frustum before setting the planes. + //----------------------------------------------------------------------- + + void planes(Plane3 p[6]) const; + void planes(Plane3 p[6], const Matrix44 &M) const; + + //---------------------- + // Derived Quantities + //---------------------- + + T fovx() const; + T fovy() const; + T aspect() const; + Matrix44 projectionMatrix() const; + bool degenerate() const; + + //----------------------------------------------------------------------- + // Takes a rectangle in the screen space (i.e., -1 <= left <= right <= 1 + // and -1 <= bottom <= top <= 1) of this Frustum, and returns a new + // Frustum whose near clipping-plane window is that rectangle in local + // space. + //----------------------------------------------------------------------- + + Frustum window(T left, T right, T top, T bottom) const; + + //---------------------------------------------------------- + // Projection is in screen space / Conversion from Z-Buffer + //---------------------------------------------------------- + + Line3 projectScreenToRay( const Vec2 & ) const; + Vec2 projectPointToScreen( const Vec3 & ) const; + + T ZToDepth(long zval, long min, long max) const; + T normalizedZToDepth(T zval) const; + long DepthToZ(T depth, long zmin, long zmax) const; + + T worldRadius(const Vec3 &p, T radius) const; + T screenRadius(const Vec3 &p, T radius) const; + + + protected: + + Vec2 screenToLocal( const Vec2 & ) const; + Vec2 localToScreen( const Vec2 & ) const; + + protected: + T _nearPlane; + T _farPlane; + T _left; + T _right; + T _top; + T _bottom; + bool _orthographic; +}; + + +template +inline Frustum::Frustum() +{ + set(T (0.1), + T (1000.0), + T (-1.0), + T (1.0), + T (1.0), + T (-1.0), + false); +} + +template +inline Frustum::Frustum(const Frustum &f) +{ + *this = f; +} + +template +inline Frustum::Frustum(T n, T f, T l, T r, T t, T b, bool o) +{ + set(n,f,l,r,t,b,o); +} + +template +inline Frustum::Frustum(T nearPlane, T farPlane, T fovx, T fovy, T aspect) +{ + set(nearPlane,farPlane,fovx,fovy,aspect); +} + +template +Frustum::~Frustum() +{ +} + +template +const Frustum & +Frustum::operator = (const Frustum &f) +{ + _nearPlane = f._nearPlane; + _farPlane = f._farPlane; + _left = f._left; + _right = f._right; + _top = f._top; + _bottom = f._bottom; + _orthographic = f._orthographic; + + return *this; +} + +template +bool +Frustum::operator == (const Frustum &src) const +{ + return + _nearPlane == src._nearPlane && + _farPlane == src._farPlane && + _left == src._left && + _right == src._right && + _top == src._top && + _bottom == src._bottom && + _orthographic == src._orthographic; +} + +template +inline bool +Frustum::operator != (const Frustum &src) const +{ + return !operator== (src); +} + +template +void Frustum::set(T n, T f, T l, T r, T t, T b, bool o) +{ + _nearPlane = n; + _farPlane = f; + _left = l; + _right = r; + _bottom = b; + _top = t; + _orthographic = o; +} + +template +void Frustum::modifyNearAndFar(T n, T f) +{ + if ( _orthographic ) + { + _nearPlane = n; + } + else + { + Line3 lowerLeft( Vec3(0,0,0), Vec3(_left,_bottom,-_nearPlane) ); + Line3 upperRight( Vec3(0,0,0), Vec3(_right,_top,-_nearPlane) ); + Plane3 nearPlane( Vec3(0,0,-1), n ); + + Vec3 ll,ur; + nearPlane.intersect(lowerLeft,ll); + nearPlane.intersect(upperRight,ur); + + _left = ll.x; + _right = ur.x; + _top = ur.y; + _bottom = ll.y; + _nearPlane = n; + _farPlane = f; + } + + _farPlane = f; +} + +template +void Frustum::setOrthographic(bool ortho) +{ + _orthographic = ortho; +} + +template +void Frustum::set(T nearPlane, T farPlane, T fovx, T fovy, T aspect) +{ + if (fovx != 0 && fovy != 0) + throw IEX_NAMESPACE::ArgExc ("fovx and fovy cannot both be non-zero."); + + const T two = static_cast(2); + + if (fovx != 0) + { + _right = nearPlane * Math::tan(fovx / two); + _left = -_right; + _top = ((_right - _left) / aspect) / two; + _bottom = -_top; + } + else + { + _top = nearPlane * Math::tan(fovy / two); + _bottom = -_top; + _right = (_top - _bottom) * aspect / two; + _left = -_right; + } + _nearPlane = nearPlane; + _farPlane = farPlane; + _orthographic = false; +} + +template +T Frustum::fovx() const +{ + return Math::atan2(_right,_nearPlane) - Math::atan2(_left,_nearPlane); +} + +template +T Frustum::fovy() const +{ + return Math::atan2(_top,_nearPlane) - Math::atan2(_bottom,_nearPlane); +} + +template +T Frustum::aspect() const +{ + T rightMinusLeft = _right-_left; + T topMinusBottom = _top-_bottom; + + if (abs(topMinusBottom) < 1 && + abs(rightMinusLeft) > limits::max() * abs(topMinusBottom)) + { + throw IEX_NAMESPACE::DivzeroExc ("Bad viewing frustum: " + "aspect ratio cannot be computed."); + } + + return rightMinusLeft / topMinusBottom; +} + +template +Matrix44 Frustum::projectionMatrix() const +{ + T rightPlusLeft = _right+_left; + T rightMinusLeft = _right-_left; + + T topPlusBottom = _top+_bottom; + T topMinusBottom = _top-_bottom; + + T farPlusNear = _farPlane+_nearPlane; + T farMinusNear = _farPlane-_nearPlane; + + if ((abs(rightMinusLeft) < 1 && + abs(rightPlusLeft) > limits::max() * abs(rightMinusLeft)) || + (abs(topMinusBottom) < 1 && + abs(topPlusBottom) > limits::max() * abs(topMinusBottom)) || + (abs(farMinusNear) < 1 && + abs(farPlusNear) > limits::max() * abs(farMinusNear))) + { + throw IEX_NAMESPACE::DivzeroExc ("Bad viewing frustum: " + "projection matrix cannot be computed."); + } + + if ( _orthographic ) + { + T tx = -rightPlusLeft / rightMinusLeft; + T ty = -topPlusBottom / topMinusBottom; + T tz = -farPlusNear / farMinusNear; + + if ((abs(rightMinusLeft) < 1 && + 2 > limits::max() * abs(rightMinusLeft)) || + (abs(topMinusBottom) < 1 && + 2 > limits::max() * abs(topMinusBottom)) || + (abs(farMinusNear) < 1 && + 2 > limits::max() * abs(farMinusNear))) + { + throw IEX_NAMESPACE::DivzeroExc ("Bad viewing frustum: " + "projection matrix cannot be computed."); + } + + T A = 2 / rightMinusLeft; + T B = 2 / topMinusBottom; + T C = -2 / farMinusNear; + + return Matrix44( A, 0, 0, 0, + 0, B, 0, 0, + 0, 0, C, 0, + tx, ty, tz, 1.f ); + } + else + { + T A = rightPlusLeft / rightMinusLeft; + T B = topPlusBottom / topMinusBottom; + T C = -farPlusNear / farMinusNear; + + T farTimesNear = -2 * _farPlane * _nearPlane; + if (abs(farMinusNear) < 1 && + abs(farTimesNear) > limits::max() * abs(farMinusNear)) + { + throw IEX_NAMESPACE::DivzeroExc ("Bad viewing frustum: " + "projection matrix cannot be computed."); + } + + T D = farTimesNear / farMinusNear; + + T twoTimesNear = 2 * _nearPlane; + + if ((abs(rightMinusLeft) < 1 && + abs(twoTimesNear) > limits::max() * abs(rightMinusLeft)) || + (abs(topMinusBottom) < 1 && + abs(twoTimesNear) > limits::max() * abs(topMinusBottom))) + { + throw IEX_NAMESPACE::DivzeroExc ("Bad viewing frustum: " + "projection matrix cannot be computed."); + } + + T E = twoTimesNear / rightMinusLeft; + T F = twoTimesNear / topMinusBottom; + + return Matrix44( E, 0, 0, 0, + 0, F, 0, 0, + A, B, C, -1, + 0, 0, D, 0 ); + } +} + +template +bool Frustum::degenerate() const +{ + return (_nearPlane == _farPlane) || + (_left == _right) || + (_top == _bottom); +} + +template +Frustum Frustum::window(T l, T r, T t, T b) const +{ + // move it to 0->1 space + + Vec2 bl = screenToLocal( Vec2(l,b) ); + Vec2 tr = screenToLocal( Vec2(r,t) ); + + return Frustum(_nearPlane, _farPlane, bl.x, tr.x, tr.y, bl.y, _orthographic); +} + + +template +Vec2 Frustum::screenToLocal(const Vec2 &s) const +{ + return Vec2( _left + (_right-_left) * (1.f+s.x) / 2.f, + _bottom + (_top-_bottom) * (1.f+s.y) / 2.f ); +} + +template +Vec2 Frustum::localToScreen(const Vec2 &p) const +{ + T leftPlusRight = _left - T (2) * p.x + _right; + T leftMinusRight = _left-_right; + T bottomPlusTop = _bottom - T (2) * p.y + _top; + T bottomMinusTop = _bottom-_top; + + if ((abs(leftMinusRight) < T (1) && + abs(leftPlusRight) > limits::max() * abs(leftMinusRight)) || + (abs(bottomMinusTop) < T (1) && + abs(bottomPlusTop) > limits::max() * abs(bottomMinusTop))) + { + throw IEX_NAMESPACE::DivzeroExc + ("Bad viewing frustum: " + "local-to-screen transformation cannot be computed"); + } + + return Vec2( leftPlusRight / leftMinusRight, + bottomPlusTop / bottomMinusTop ); +} + +template +Line3 Frustum::projectScreenToRay(const Vec2 &p) const +{ + Vec2 point = screenToLocal(p); + if (orthographic()) + return Line3( Vec3(point.x,point.y, 0.0), + Vec3(point.x,point.y,-1.0)); + else + return Line3( Vec3(0, 0, 0), Vec3(point.x,point.y,-_nearPlane)); +} + +template +Vec2 Frustum::projectPointToScreen(const Vec3 &point) const +{ + if (orthographic() || point.z == T (0)) + return localToScreen( Vec2( point.x, point.y ) ); + else + return localToScreen( Vec2( point.x * _nearPlane / -point.z, + point.y * _nearPlane / -point.z ) ); +} + +template +T Frustum::ZToDepth(long zval,long zmin,long zmax) const +{ + int zdiff = zmax - zmin; + + if (zdiff == 0) + { + throw IEX_NAMESPACE::DivzeroExc + ("Bad call to Frustum::ZToDepth: zmax == zmin"); + } + + if ( zval > zmax+1 ) zval -= zdiff; + + T fzval = (T(zval) - T(zmin)) / T(zdiff); + return normalizedZToDepth(fzval); +} + +template +T Frustum::normalizedZToDepth(T zval) const +{ + T Zp = zval * 2.0 - 1; + + if ( _orthographic ) + { + return -(Zp*(_farPlane-_nearPlane) + (_farPlane+_nearPlane))/2; + } + else + { + T farTimesNear = 2 * _farPlane * _nearPlane; + T farMinusNear = Zp * (_farPlane - _nearPlane) - _farPlane - _nearPlane; + + if (abs(farMinusNear) < 1 && + abs(farTimesNear) > limits::max() * abs(farMinusNear)) + { + throw IEX_NAMESPACE::DivzeroExc + ("Frustum::normalizedZToDepth cannot be computed. The " + "near and far clipping planes of the viewing frustum " + "may be too close to each other"); + } + + return farTimesNear / farMinusNear; + } +} + +template +long Frustum::DepthToZ(T depth,long zmin,long zmax) const +{ + long zdiff = zmax - zmin; + T farMinusNear = _farPlane-_nearPlane; + + if ( _orthographic ) + { + T farPlusNear = 2*depth + _farPlane + _nearPlane; + + if (abs(farMinusNear) < 1 && + abs(farPlusNear) > limits::max() * abs(farMinusNear)) + { + throw IEX_NAMESPACE::DivzeroExc + ("Bad viewing frustum: near and far clipping planes " + "are too close to each other"); + } + + T Zp = -farPlusNear/farMinusNear; + return long(0.5*(Zp+1)*zdiff) + zmin; + } + else + { + // Perspective + + T farTimesNear = 2*_farPlane*_nearPlane; + if (abs(depth) < 1 && + abs(farTimesNear) > limits::max() * abs(depth)) + { + throw IEX_NAMESPACE::DivzeroExc + ("Bad call to DepthToZ function: value of `depth' " + "is too small"); + } + + T farPlusNear = farTimesNear/depth + _farPlane + _nearPlane; + if (abs(farMinusNear) < 1 && + abs(farPlusNear) > limits::max() * abs(farMinusNear)) + { + throw IEX_NAMESPACE::DivzeroExc + ("Bad viewing frustum: near and far clipping planes " + "are too close to each other"); + } + + T Zp = farPlusNear/farMinusNear; + return long(0.5*(Zp+1)*zdiff) + zmin; + } +} + +template +T Frustum::screenRadius(const Vec3 &p, T radius) const +{ + // Derivation: + // Consider X-Z plane. + // X coord of projection of p = xp = p.x * (-_nearPlane / p.z) + // Let q be p + (radius, 0, 0). + // X coord of projection of q = xq = (p.x - radius) * (-_nearPlane / p.z) + // X coord of projection of segment from p to q = r = xp - xq + // = radius * (-_nearPlane / p.z) + // A similar analysis holds in the Y-Z plane. + // So r is the quantity we want to return. + + if (abs(p.z) > 1 || abs(-_nearPlane) < limits::max() * abs(p.z)) + { + return radius * (-_nearPlane / p.z); + } + else + { + throw IEX_NAMESPACE::DivzeroExc + ("Bad call to Frustum::screenRadius: the magnitude of `p' " + "is too small"); + } + + return radius * (-_nearPlane / p.z); +} + +template +T Frustum::worldRadius(const Vec3 &p, T radius) const +{ + if (abs(-_nearPlane) > 1 || abs(p.z) < limits::max() * abs(-_nearPlane)) + { + return radius * (p.z / -_nearPlane); + } + else + { + throw IEX_NAMESPACE::DivzeroExc + ("Bad viewing frustum: the near clipping plane is too " + "close to zero"); + } +} + +template +void Frustum::planes(Plane3 p[6]) const +{ + // + // Plane order: Top, Right, Bottom, Left, Near, Far. + // Normals point outwards. + // + + if (! _orthographic) + { + Vec3 a( _left, _bottom, -_nearPlane); + Vec3 b( _left, _top, -_nearPlane); + Vec3 c( _right, _top, -_nearPlane); + Vec3 d( _right, _bottom, -_nearPlane); + Vec3 o(0,0,0); + + p[0].set( o, c, b ); + p[1].set( o, d, c ); + p[2].set( o, a, d ); + p[3].set( o, b, a ); + } + else + { + p[0].set( Vec3( 0, 1, 0), _top ); + p[1].set( Vec3( 1, 0, 0), _right ); + p[2].set( Vec3( 0,-1, 0),-_bottom ); + p[3].set( Vec3(-1, 0, 0),-_left ); + } + p[4].set( Vec3(0, 0, 1), -_nearPlane ); + p[5].set( Vec3(0, 0,-1), _farPlane ); +} + + +template +void Frustum::planes(Plane3 p[6], const Matrix44 &M) const +{ + // + // Plane order: Top, Right, Bottom, Left, Near, Far. + // Normals point outwards. + // + + Vec3 a = Vec3( _left, _bottom, -_nearPlane) * M; + Vec3 b = Vec3( _left, _top, -_nearPlane) * M; + Vec3 c = Vec3( _right, _top, -_nearPlane) * M; + Vec3 d = Vec3( _right, _bottom, -_nearPlane) * M; + if (! _orthographic) + { + double s = _farPlane / double(_nearPlane); + T farLeft = (T) (s * _left); + T farRight = (T) (s * _right); + T farTop = (T) (s * _top); + T farBottom = (T) (s * _bottom); + Vec3 e = Vec3( farLeft, farBottom, -_farPlane) * M; + Vec3 f = Vec3( farLeft, farTop, -_farPlane) * M; + Vec3 g = Vec3( farRight, farTop, -_farPlane) * M; + Vec3 o = Vec3(0,0,0) * M; + p[0].set( o, c, b ); + p[1].set( o, d, c ); + p[2].set( o, a, d ); + p[3].set( o, b, a ); + p[4].set( a, d, c ); + p[5].set( e, f, g ); + } + else + { + Vec3 e = Vec3( _left, _bottom, -_farPlane) * M; + Vec3 f = Vec3( _left, _top, -_farPlane) * M; + Vec3 g = Vec3( _right, _top, -_farPlane) * M; + Vec3 h = Vec3( _right, _bottom, -_farPlane) * M; + p[0].set( c, g, f ); + p[1].set( d, h, g ); + p[2].set( a, e, h ); + p[3].set( b, f, e ); + p[4].set( a, d, c ); + p[5].set( e, f, g ); + } +} + +typedef Frustum Frustumf; +typedef Frustum Frustumd; + + +IMATH_INTERNAL_NAMESPACE_HEADER_EXIT + + +#if defined _WIN32 || defined _WIN64 + #ifdef _redef_near + #define near + #endif + #ifdef _redef_far + #define far + #endif +#endif + +#endif // INCLUDED_IMATHFRUSTUM_H diff --git a/OpenEXR/include/OpenEXR/ImathFrustumTest.h b/OpenEXR/include/OpenEXR/ImathFrustumTest.h new file mode 100644 index 0000000..d9c10cc --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathFrustumTest.h @@ -0,0 +1,417 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2011-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMATHFRUSTUMTEST_H +#define INCLUDED_IMATHFRUSTUMTEST_H + +//------------------------------------------------------------------------- +// +// This file contains algorithms applied to or in conjunction with +// Frustum visibility testing (Imath::Frustum). +// +// Methods for frustum-based rejection of primitives are contained here. +// +//------------------------------------------------------------------------- + +#include "ImathFrustum.h" +#include "ImathBox.h" +#include "ImathSphere.h" +#include "ImathMatrix.h" +#include "ImathVec.h" +#include "ImathNamespace.h" + +IMATH_INTERNAL_NAMESPACE_HEADER_ENTER + +///////////////////////////////////////////////////////////////// +// FrustumTest +// +// template class FrustumTest +// +// This is a helper class, designed to accelerate the case +// where many tests are made against the same frustum. +// That's a really common case. +// +// The acceleration is achieved by pre-computing the planes of +// the frustum, along with the ablsolute values of the plane normals. +// + + + +////////////////////////////////////////////////////////////////// +// How to use this +// +// Given that you already have: +// Imath::Frustum myFrustum +// Imath::Matrix44 myCameraWorldMatrix +// +// First, make a frustum test object: +// FrustumTest myFrustumTest(myFrustum, myCameraWorldMatrix) +// +// Whenever the camera or frustum changes, call: +// myFrustumTest.setFrustum(myFrustum, myCameraWorldMatrix) +// +// For each object you want to test for visibility, call: +// myFrustumTest.isVisible(myBox) +// myFrustumTest.isVisible(mySphere) +// myFrustumTest.isVisible(myVec3) +// myFrustumTest.completelyContains(myBox) +// myFrustumTest.completelyContains(mySphere) +// + + + + +////////////////////////////////////////////////////////////////// +// Explanation of how it works +// +// +// We store six world-space Frustum planes (nx, ny, nz, offset) +// +// Points: To test a Vec3 for visibility, test it against each plane +// using the normal (v dot n - offset) method. (the result is exact) +// +// BBoxes: To test an axis-aligned bbox, test the center against each plane +// using the normal (v dot n - offset) method, but offset by the +// box extents dot the abs of the plane normal. (the result is NOT +// exact, but will not return false-negatives.) +// +// Spheres: To test a sphere, test the center against each plane +// using the normal (v dot n - offset) method, but offset by the +// sphere's radius. (the result is NOT exact, but will not return +// false-negatives.) +// +// +// SPECIAL NOTE: "Where are the dot products?" +// Actual dot products are currently slow for most SIMD architectures. +// In order to keep this code optimization-ready, the dot products +// are all performed using vector adds and multipies. +// +// In order to do this, the plane equations are stored in "transpose" +// form, with the X components grouped into an X vector, etc. +// + + +template +class FrustumTest +{ +public: + FrustumTest() + { + Frustum frust; + Matrix44 cameraMat; + cameraMat.makeIdentity(); + setFrustum(frust, cameraMat); + } + FrustumTest(const Frustum &frustum, const Matrix44 &cameraMat) + { + setFrustum(frustum, cameraMat); + } + + //////////////////////////////////////////////////////////////////// + // setFrustum() + // This updates the frustum test with a new frustum and matrix. + // This should usually be called just once per frame. + void setFrustum(const Frustum &frustum, const Matrix44 &cameraMat); + + //////////////////////////////////////////////////////////////////// + // isVisible() + // Check to see if shapes are visible. + bool isVisible(const Sphere3 &sphere) const; + bool isVisible(const Box > &box) const; + bool isVisible(const Vec3 &vec) const; + + //////////////////////////////////////////////////////////////////// + // completelyContains() + // Check to see if shapes are entirely contained. + bool completelyContains(const Sphere3 &sphere) const; + bool completelyContains(const Box > &box) const; + + // These next items are kept primarily for debugging tools. + // It's useful for drawing the culling environment, and also + // for getting an "outside view" of the culling frustum. + IMATH_INTERNAL_NAMESPACE::Matrix44 cameraMat() const {return cameraMatrix;} + IMATH_INTERNAL_NAMESPACE::Frustum currentFrustum() const {return currFrustum;} + +protected: + // To understand why the planes are stored this way, see + // the SPECIAL NOTE above. + Vec3 planeNormX[2]; // The X compunents from 6 plane equations + Vec3 planeNormY[2]; // The Y compunents from 6 plane equations + Vec3 planeNormZ[2]; // The Z compunents from 6 plane equations + + Vec3 planeOffsetVec[2]; // The distance offsets from 6 plane equations + + // The absolute values are stored to assist with bounding box tests. + Vec3 planeNormAbsX[2]; // The abs(X) compunents from 6 plane equations + Vec3 planeNormAbsY[2]; // The abs(X) compunents from 6 plane equations + Vec3 planeNormAbsZ[2]; // The abs(X) compunents from 6 plane equations + + // These are kept primarily for debugging tools. + Frustum currFrustum; + Matrix44 cameraMatrix; +}; + + +//////////////////////////////////////////////////////////////////// +// setFrustum() +// This should usually only be called once per frame, or however +// often the camera moves. +template +void FrustumTest::setFrustum(const Frustum &frustum, + const Matrix44 &cameraMat) +{ + Plane3 frustumPlanes[6]; + frustum.planes(frustumPlanes, cameraMat); + + // Here's where we effectively transpose the plane equations. + // We stuff all six X's into the two planeNormX vectors, etc. + for (int i = 0; i < 2; ++i) + { + int index = i * 3; + + planeNormX[i] = Vec3(frustumPlanes[index + 0].normal.x, + frustumPlanes[index + 1].normal.x, + frustumPlanes[index + 2].normal.x); + planeNormY[i] = Vec3(frustumPlanes[index + 0].normal.y, + frustumPlanes[index + 1].normal.y, + frustumPlanes[index + 2].normal.y); + planeNormZ[i] = Vec3(frustumPlanes[index + 0].normal.z, + frustumPlanes[index + 1].normal.z, + frustumPlanes[index + 2].normal.z); + + planeNormAbsX[i] = Vec3(IMATH_INTERNAL_NAMESPACE::abs(planeNormX[i].x), + IMATH_INTERNAL_NAMESPACE::abs(planeNormX[i].y), + IMATH_INTERNAL_NAMESPACE::abs(planeNormX[i].z)); + planeNormAbsY[i] = Vec3(IMATH_INTERNAL_NAMESPACE::abs(planeNormY[i].x), + IMATH_INTERNAL_NAMESPACE::abs(planeNormY[i].y), + IMATH_INTERNAL_NAMESPACE::abs(planeNormY[i].z)); + planeNormAbsZ[i] = Vec3(IMATH_INTERNAL_NAMESPACE::abs(planeNormZ[i].x), + IMATH_INTERNAL_NAMESPACE::abs(planeNormZ[i].y), + IMATH_INTERNAL_NAMESPACE::abs(planeNormZ[i].z)); + + planeOffsetVec[i] = Vec3(frustumPlanes[index + 0].distance, + frustumPlanes[index + 1].distance, + frustumPlanes[index + 2].distance); + } + currFrustum = frustum; + cameraMatrix = cameraMat; +} + + +//////////////////////////////////////////////////////////////////// +// isVisible(Sphere) +// Returns true if any part of the sphere is inside +// the frustum. +// The result MAY return close false-positives, but not false-negatives. +// +template +bool FrustumTest::isVisible(const Sphere3 &sphere) const +{ + Vec3 center = sphere.center; + Vec3 radiusVec = Vec3(sphere.radius, sphere.radius, sphere.radius); + + // This is a vertical dot-product on three vectors at once. + Vec3 d0 = planeNormX[0] * center.x + + planeNormY[0] * center.y + + planeNormZ[0] * center.z + - radiusVec + - planeOffsetVec[0]; + + if (d0.x >= 0 || d0.y >= 0 || d0.z >= 0) + return false; + + Vec3 d1 = planeNormX[1] * center.x + + planeNormY[1] * center.y + + planeNormZ[1] * center.z + - radiusVec + - planeOffsetVec[1]; + + if (d1.x >= 0 || d1.y >= 0 || d1.z >= 0) + return false; + + return true; +} + +//////////////////////////////////////////////////////////////////// +// completelyContains(Sphere) +// Returns true if every part of the sphere is inside +// the frustum. +// The result MAY return close false-negatives, but not false-positives. +// +template +bool FrustumTest::completelyContains(const Sphere3 &sphere) const +{ + Vec3 center = sphere.center; + Vec3 radiusVec = Vec3(sphere.radius, sphere.radius, sphere.radius); + + // This is a vertical dot-product on three vectors at once. + Vec3 d0 = planeNormX[0] * center.x + + planeNormY[0] * center.y + + planeNormZ[0] * center.z + + radiusVec + - planeOffsetVec[0]; + + if (d0.x >= 0 || d0.y >= 0 || d0.z >= 0) + return false; + + Vec3 d1 = planeNormX[1] * center.x + + planeNormY[1] * center.y + + planeNormZ[1] * center.z + + radiusVec + - planeOffsetVec[1]; + + if (d1.x >= 0 || d1.y >= 0 || d1.z >= 0) + return false; + + return true; +} + +//////////////////////////////////////////////////////////////////// +// isVisible(Box) +// Returns true if any part of the axis-aligned box +// is inside the frustum. +// The result MAY return close false-positives, but not false-negatives. +// +template +bool FrustumTest::isVisible(const Box > &box) const +{ + if (box.isEmpty()) + return false; + + Vec3 center = (box.min + box.max) / 2; + Vec3 extent = (box.max - center); + + // This is a vertical dot-product on three vectors at once. + Vec3 d0 = planeNormX[0] * center.x + + planeNormY[0] * center.y + + planeNormZ[0] * center.z + - planeNormAbsX[0] * extent.x + - planeNormAbsY[0] * extent.y + - planeNormAbsZ[0] * extent.z + - planeOffsetVec[0]; + + if (d0.x >= 0 || d0.y >= 0 || d0.z >= 0) + return false; + + Vec3 d1 = planeNormX[1] * center.x + + planeNormY[1] * center.y + + planeNormZ[1] * center.z + - planeNormAbsX[1] * extent.x + - planeNormAbsY[1] * extent.y + - planeNormAbsZ[1] * extent.z + - planeOffsetVec[1]; + + if (d1.x >= 0 || d1.y >= 0 || d1.z >= 0) + return false; + + return true; +} + +//////////////////////////////////////////////////////////////////// +// completelyContains(Box) +// Returns true if every part of the axis-aligned box +// is inside the frustum. +// The result MAY return close false-negatives, but not false-positives. +// +template +bool FrustumTest::completelyContains(const Box > &box) const +{ + if (box.isEmpty()) + return false; + + Vec3 center = (box.min + box.max) / 2; + Vec3 extent = (box.max - center); + + // This is a vertical dot-product on three vectors at once. + Vec3 d0 = planeNormX[0] * center.x + + planeNormY[0] * center.y + + planeNormZ[0] * center.z + + planeNormAbsX[0] * extent.x + + planeNormAbsY[0] * extent.y + + planeNormAbsZ[0] * extent.z + - planeOffsetVec[0]; + + if (d0.x >= 0 || d0.y >= 0 || d0.z >= 0) + return false; + + Vec3 d1 = planeNormX[1] * center.x + + planeNormY[1] * center.y + + planeNormZ[1] * center.z + + planeNormAbsX[1] * extent.x + + planeNormAbsY[1] * extent.y + + planeNormAbsZ[1] * extent.z + - planeOffsetVec[1]; + + if (d1.x >= 0 || d1.y >= 0 || d1.z >= 0) + return false; + + return true; +} + + +//////////////////////////////////////////////////////////////////// +// isVisible(Vec3) +// Returns true if the point is inside the frustum. +// +template +bool FrustumTest::isVisible(const Vec3 &vec) const +{ + // This is a vertical dot-product on three vectors at once. + Vec3 d0 = (planeNormX[0] * vec.x) + + (planeNormY[0] * vec.y) + + (planeNormZ[0] * vec.z) + - planeOffsetVec[0]; + + if (d0.x >= 0 || d0.y >= 0 || d0.z >= 0) + return false; + + Vec3 d1 = (planeNormX[1] * vec.x) + + (planeNormY[1] * vec.y) + + (planeNormZ[1] * vec.z) + - planeOffsetVec[1]; + + if (d1.x >= 0 || d1.y >= 0 || d1.z >= 0) + return false; + + return true; +} + + +typedef FrustumTest FrustumTestf; +typedef FrustumTest FrustumTestd; + +IMATH_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_IMATHFRUSTUMTEST_H diff --git a/OpenEXR/include/OpenEXR/ImathFun.h b/OpenEXR/include/OpenEXR/ImathFun.h new file mode 100644 index 0000000..068c682 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathFun.h @@ -0,0 +1,269 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMATHFUN_H +#define INCLUDED_IMATHFUN_H + +//----------------------------------------------------------------------------- +// +// Miscellaneous utility functions +// +//----------------------------------------------------------------------------- + +#include "ImathExport.h" +#include "ImathLimits.h" +#include "ImathInt64.h" +#include "ImathNamespace.h" + +IMATH_INTERNAL_NAMESPACE_HEADER_ENTER + +template +inline T +abs (T a) +{ + return (a > T(0)) ? a : -a; +} + + +template +inline int +sign (T a) +{ + return (a > T(0))? 1 : ((a < T(0)) ? -1 : 0); +} + + +template +inline T +lerp (T a, T b, Q t) +{ + return (T) (a * (1 - t) + b * t); +} + + +template +inline T +ulerp (T a, T b, Q t) +{ + return (T) ((a > b)? (a - (a - b) * t): (a + (b - a) * t)); +} + + +template +inline T +lerpfactor(T m, T a, T b) +{ + // + // Return how far m is between a and b, that is return t such that + // if: + // t = lerpfactor(m, a, b); + // then: + // m = lerp(a, b, t); + // + // If a==b, return 0. + // + + T d = b - a; + T n = m - a; + + if (abs(d) > T(1) || abs(n) < limits::max() * abs(d)) + return n / d; + + return T(0); +} + + +template +inline T +clamp (T a, T l, T h) +{ + return (a < l)? l : ((a > h)? h : a); +} + + +template +inline int +cmp (T a, T b) +{ + return IMATH_INTERNAL_NAMESPACE::sign (a - b); +} + + +template +inline int +cmpt (T a, T b, T t) +{ + return (IMATH_INTERNAL_NAMESPACE::abs (a - b) <= t)? 0 : cmp (a, b); +} + + +template +inline bool +iszero (T a, T t) +{ + return (IMATH_INTERNAL_NAMESPACE::abs (a) <= t) ? 1 : 0; +} + + +template +inline bool +equal (T1 a, T2 b, T3 t) +{ + return IMATH_INTERNAL_NAMESPACE::abs (a - b) <= t; +} + +template +inline int +floor (T x) +{ + return (x >= 0)? int (x): -(int (-x) + (-x > int (-x))); +} + + +template +inline int +ceil (T x) +{ + return -floor (-x); +} + +template +inline int +trunc (T x) +{ + return (x >= 0) ? int(x) : -int(-x); +} + + +// +// Integer division and remainder where the +// remainder of x/y has the same sign as x: +// +// divs(x,y) == (abs(x) / abs(y)) * (sign(x) * sign(y)) +// mods(x,y) == x - y * divs(x,y) +// + +inline int +divs (int x, int y) +{ + return (x >= 0)? ((y >= 0)? ( x / y): -( x / -y)): + ((y >= 0)? -(-x / y): (-x / -y)); +} + + +inline int +mods (int x, int y) +{ + return (x >= 0)? ((y >= 0)? ( x % y): ( x % -y)): + ((y >= 0)? -(-x % y): -(-x % -y)); +} + + +// +// Integer division and remainder where the +// remainder of x/y is always positive: +// +// divp(x,y) == floor (double(x) / double (y)) +// modp(x,y) == x - y * divp(x,y) +// + +inline int +divp (int x, int y) +{ + return (x >= 0)? ((y >= 0)? ( x / y): -( x / -y)): + ((y >= 0)? -((y-1-x) / y): ((-y-1-x) / -y)); +} + + +inline int +modp (int x, int y) +{ + return x - y * divp (x, y); +} + +//---------------------------------------------------------- +// Successor and predecessor for floating-point numbers: +// +// succf(f) returns float(f+e), where e is the smallest +// positive number such that float(f+e) != f. +// +// predf(f) returns float(f-e), where e is the smallest +// positive number such that float(f-e) != f. +// +// succd(d) returns double(d+e), where e is the smallest +// positive number such that double(d+e) != d. +// +// predd(d) returns double(d-e), where e is the smallest +// positive number such that double(d-e) != d. +// +// Exceptions: If the input value is an infinity or a nan, +// succf(), predf(), succd(), and predd() all +// return the input value without changing it. +// +//---------------------------------------------------------- + +IMATH_EXPORT float succf (float f); +IMATH_EXPORT float predf (float f); + +IMATH_EXPORT double succd (double d); +IMATH_EXPORT double predd (double d); + +// +// Return true if the number is not a NaN or Infinity. +// + +inline bool +finitef (float f) +{ + union {float f; int i;} u; + u.f = f; + + return (u.i & 0x7f800000) != 0x7f800000; +} + +inline bool +finited (double d) +{ + union {double d; Int64 i;} u; + u.d = d; + + return (u.i & 0x7ff0000000000000LL) != 0x7ff0000000000000LL; +} + + +IMATH_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_IMATHFUN_H diff --git a/OpenEXR/include/OpenEXR/ImathGL.h b/OpenEXR/include/OpenEXR/ImathGL.h new file mode 100644 index 0000000..e3b9405 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathGL.h @@ -0,0 +1,166 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002, 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMATHGL_H +#define INCLUDED_IMATHGL_H + +#include + +#include "ImathVec.h" +#include "ImathMatrix.h" +#include "IexMathExc.h" +#include "ImathFun.h" +#include "ImathNamespace.h" + +inline void glVertex ( const IMATH_INTERNAL_NAMESPACE::V3f &v ) { glVertex3f(v.x,v.y,v.z); } +inline void glVertex ( const IMATH_INTERNAL_NAMESPACE::V2f &v ) { glVertex2f(v.x,v.y); } +inline void glNormal ( const IMATH_INTERNAL_NAMESPACE::V3f &n ) { glNormal3f(n.x,n.y,n.z); } +inline void glColor ( const IMATH_INTERNAL_NAMESPACE::V3f &c ) { glColor3f(c.x,c.y,c.z); } +inline void glTranslate ( const IMATH_INTERNAL_NAMESPACE::V3f &t ) { glTranslatef(t.x,t.y,t.z); } + +inline void glTexCoord( const IMATH_INTERNAL_NAMESPACE::V2f &t ) +{ + glTexCoord2f(t.x,t.y); +} + +inline void glDisableTexture() +{ + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_TEXTURE_2D); + + glActiveTexture(GL_TEXTURE0); +} + +namespace { + +const float GL_FLOAT_MAX = 1.8e+19; // sqrt (FLT_MAX) + +inline bool +badFloat (float f) +{ + return !IMATH_INTERNAL_NAMESPACE::finitef (f) || f < - GL_FLOAT_MAX || f > GL_FLOAT_MAX; +} + +} // namespace + +inline void +throwBadMatrix (const IMATH_INTERNAL_NAMESPACE::M44f& m) +{ + if (badFloat (m[0][0]) || + badFloat (m[0][1]) || + badFloat (m[0][2]) || + badFloat (m[0][3]) || + badFloat (m[1][0]) || + badFloat (m[1][1]) || + badFloat (m[1][2]) || + badFloat (m[1][3]) || + badFloat (m[2][0]) || + badFloat (m[2][1]) || + badFloat (m[2][2]) || + badFloat (m[2][3]) || + badFloat (m[3][0]) || + badFloat (m[3][1]) || + badFloat (m[3][2]) || + badFloat (m[3][3])) + throw IEX_NAMESPACE::OverflowExc ("GL matrix overflow"); +} + +inline void +glMultMatrix( const IMATH_INTERNAL_NAMESPACE::M44f& m ) +{ + throwBadMatrix (m); + glMultMatrixf( (GLfloat*)m[0] ); +} + +inline void +glMultMatrix( const IMATH_INTERNAL_NAMESPACE::M44f* m ) +{ + throwBadMatrix (*m); + glMultMatrixf( (GLfloat*)(*m)[0] ); +} + +inline void +glLoadMatrix( const IMATH_INTERNAL_NAMESPACE::M44f& m ) +{ + throwBadMatrix (m); + glLoadMatrixf( (GLfloat*)m[0] ); +} + +inline void +glLoadMatrix( const IMATH_INTERNAL_NAMESPACE::M44f* m ) +{ + throwBadMatrix (*m); + glLoadMatrixf( (GLfloat*)(*m)[0] ); +} + + + + +IMATH_INTERNAL_NAMESPACE_HEADER_ENTER + + +// +// Class objects that push/pop the GL state. These objects assist with +// proper cleanup of the state when exceptions are thrown. +// + +class GLPushMatrix { + public: + + GLPushMatrix () { glPushMatrix(); } + ~GLPushMatrix() { glPopMatrix(); } +}; + +class GLPushAttrib { + public: + + GLPushAttrib (GLbitfield mask) { glPushAttrib (mask); } + ~GLPushAttrib() { glPopAttrib(); } +}; + +class GLBegin { + public: + + GLBegin (GLenum mode) { glBegin (mode); } + ~GLBegin() { glEnd(); } +}; + + + +IMATH_INTERNAL_NAMESPACE_HEADER_EXIT + + +#endif diff --git a/OpenEXR/include/OpenEXR/ImathGLU.h b/OpenEXR/include/OpenEXR/ImathGLU.h new file mode 100644 index 0000000..52a43af --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathGLU.h @@ -0,0 +1,54 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMATHGLU_H +#define INCLUDED_IMATHGLU_H + +#include +#include + +#include "ImathVec.h" + +inline +void +gluLookAt(const IMATH_INTERNAL_NAMESPACE::V3f &pos, const IMATH_INTERNAL_NAMESPACE::V3f &interest, const IMATH_INTERNAL_NAMESPACE::V3f &up) +{ + gluLookAt(pos.x, pos.y, pos.z, + interest.x, interest.y, interest.z, + up.x, up.y, up.z); +} + +#endif diff --git a/OpenEXR/include/OpenEXR/ImathHalfLimits.h b/OpenEXR/include/OpenEXR/ImathHalfLimits.h new file mode 100644 index 0000000..de54bd6 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathHalfLimits.h @@ -0,0 +1,68 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMATHHALFLIMITS_H +#define INCLUDED_IMATHHALFLIMITS_H + +//-------------------------------------------------- +// +// Imath-style limits for class half. +// +//-------------------------------------------------- + +#include "ImathLimits.h" +#include "ImathNamespace.h" + +#include "half.h" + +IMATH_INTERNAL_NAMESPACE_HEADER_ENTER + + +template <> +struct limits +{ + static float min() {return -HALF_MAX;} + static float max() {return HALF_MAX;} + static float smallest() {return HALF_MIN;} + static float epsilon() {return HALF_EPSILON;} + static bool isIntegral() {return false;} + static bool isSigned() {return true;} +}; + + +IMATH_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_IMATHHALFLIMITS_H diff --git a/OpenEXR/include/OpenEXR/ImathInt64.h b/OpenEXR/include/OpenEXR/ImathInt64.h new file mode 100644 index 0000000..3b867dc --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathInt64.h @@ -0,0 +1,62 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2006-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMATH_INT64_H +#define INCLUDED_IMATH_INT64_H + +//---------------------------------------------------------------------------- +// +// Int64 -- unsigned 64-bit integers +// +//---------------------------------------------------------------------------- + +#include "ImathNamespace.h" +#include + +IMATH_INTERNAL_NAMESPACE_HEADER_ENTER + + +#if (defined _WIN32 || defined _WIN64) && _MSC_VER >= 1300 + typedef unsigned __int64 Int64; +#elif ULONG_MAX == 18446744073709551615LU + typedef long unsigned int Int64; +#else + typedef long long unsigned int Int64; +#endif + + +IMATH_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_IMATH_INT64_H diff --git a/OpenEXR/include/OpenEXR/ImathInterval.h b/OpenEXR/include/OpenEXR/ImathInterval.h new file mode 100644 index 0000000..0062f4d --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathInterval.h @@ -0,0 +1,226 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMATHINTERVAL_H +#define INCLUDED_IMATHINTERVAL_H + + +//------------------------------------------------------------------- +// +// class Imath::Interval +// -------------------------------- +// +// An Interval has a min and a max and some miscellaneous +// functions. It is basically a Box that allows T to be +// a scalar. +// +//------------------------------------------------------------------- + +#include "ImathVec.h" +#include "ImathNamespace.h" + +IMATH_INTERNAL_NAMESPACE_HEADER_ENTER + + +template +class Interval +{ + public: + + //------------------------- + // Data Members are public + //------------------------- + + T min; + T max; + + //----------------------------------------------------- + // Constructors - an "empty" Interval is created by default + //----------------------------------------------------- + + Interval(); + Interval(const T& point); + Interval(const T& minT, const T& maxT); + + //-------------------------------- + // Operators: we get != from STL + //-------------------------------- + + bool operator == (const Interval &src) const; + + //------------------ + // Interval manipulation + //------------------ + + void makeEmpty(); + void extendBy(const T& point); + void extendBy(const Interval& interval); + + //--------------------------------------------------- + // Query functions - these compute results each time + //--------------------------------------------------- + + T size() const; + T center() const; + bool intersects(const T &point) const; + bool intersects(const Interval &interval) const; + + //---------------- + // Classification + //---------------- + + bool hasVolume() const; + bool isEmpty() const; +}; + + +//-------------------- +// Convenient typedefs +//-------------------- + + +typedef Interval Intervalf; +typedef Interval Intervald; +typedef Interval Intervals; +typedef Interval Intervali; + +//---------------- +// Implementation +//---------------- + + +template +inline Interval::Interval() +{ + makeEmpty(); +} + +template +inline Interval::Interval(const T& point) +{ + min = point; + max = point; +} + +template +inline Interval::Interval(const T& minV, const T& maxV) +{ + min = minV; + max = maxV; +} + +template +inline bool +Interval::operator == (const Interval &src) const +{ + return (min == src.min && max == src.max); +} + +template +inline void +Interval::makeEmpty() +{ + min = limits::max(); + max = limits::min(); +} + +template +inline void +Interval::extendBy(const T& point) +{ + if ( point < min ) + min = point; + + if ( point > max ) + max = point; +} + +template +inline void +Interval::extendBy(const Interval& interval) +{ + if ( interval.min < min ) + min = interval.min; + + if ( interval.max > max ) + max = interval.max; +} + +template +inline bool +Interval::intersects(const T& point) const +{ + return point >= min && point <= max; +} + +template +inline bool +Interval::intersects(const Interval& interval) const +{ + return interval.max >= min && interval.min <= max; +} + +template +inline T +Interval::size() const +{ + return max-min; +} + +template +inline T +Interval::center() const +{ + return (max+min)/2; +} + +template +inline bool +Interval::isEmpty() const +{ + return max < min; +} + +template +inline bool Interval::hasVolume() const +{ + return max > min; +} + + +IMATH_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_IMATHINTERVAL_H diff --git a/OpenEXR/include/OpenEXR/ImathLimits.h b/OpenEXR/include/OpenEXR/ImathLimits.h new file mode 100644 index 0000000..eb6f999 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathLimits.h @@ -0,0 +1,268 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMATHLIMITS_H +#define INCLUDED_IMATHLIMITS_H + +//---------------------------------------------------------------- +// +// Limitations of the basic C++ numerical data types +// +//---------------------------------------------------------------- + +#include "ImathNamespace.h" +#include +#include + +//------------------------------------------ +// In Windows, min and max are macros. Yay. +//------------------------------------------ + +#if defined _WIN32 || defined _WIN64 + #ifdef min + #undef min + #endif + #ifdef max + #undef max + #endif +#endif + +IMATH_INTERNAL_NAMESPACE_HEADER_ENTER + + +//----------------------------------------------------------------- +// +// Template class limits returns information about the limits +// of numerical data type T: +// +// min() largest possible negative value of type T +// +// max() largest possible positive value of type T +// +// smallest() smallest possible positive value of type T +// (for float and double: smallest normalized +// positive value) +// +// epsilon() smallest possible e of type T, for which +// 1 + e != 1 +// +// isIntegral() returns true if T is an integral type +// +// isSigned() returns true if T is signed +// +// Class limits is useful to implement template classes or +// functions which depend on the limits of a numerical type +// which is not known in advance; for example: +// +// template max (T x[], int n) +// { +// T m = limits::min(); +// +// for (int i = 0; i < n; i++) +// if (m < x[i]) +// m = x[i]; +// +// return m; +// } +// +// Class limits has been implemented for the following types: +// +// char, signed char, unsigned char +// short, unsigned short +// int, unsigned int +// long, unsigned long +// float +// double +// long double +// +// Class limits has only static member functions, all of which +// are implemented as inlines. No objects of type limits are +// ever created. +// +//----------------------------------------------------------------- + + +template struct limits +{ + static T min(); + static T max(); + static T smallest(); + static T epsilon(); + static bool isIntegral(); + static bool isSigned(); +}; + + +//--------------- +// Implementation +//--------------- + +template <> +struct limits +{ + static char min() {return CHAR_MIN;} + static char max() {return CHAR_MAX;} + static char smallest() {return 1;} + static char epsilon() {return 1;} + static bool isIntegral() {return true;} + static bool isSigned() {return (char) ~0 < 0;} +}; + +template <> +struct limits +{ + static signed char min() {return SCHAR_MIN;} + static signed char max() {return SCHAR_MAX;} + static signed char smallest() {return 1;} + static signed char epsilon() {return 1;} + static bool isIntegral() {return true;} + static bool isSigned() {return true;} +}; + +template <> +struct limits +{ + static unsigned char min() {return 0;} + static unsigned char max() {return UCHAR_MAX;} + static unsigned char smallest() {return 1;} + static unsigned char epsilon() {return 1;} + static bool isIntegral() {return true;} + static bool isSigned() {return false;} +}; + +template <> +struct limits +{ + static short min() {return SHRT_MIN;} + static short max() {return SHRT_MAX;} + static short smallest() {return 1;} + static short epsilon() {return 1;} + static bool isIntegral() {return true;} + static bool isSigned() {return true;} +}; + +template <> +struct limits +{ + static unsigned short min() {return 0;} + static unsigned short max() {return USHRT_MAX;} + static unsigned short smallest() {return 1;} + static unsigned short epsilon() {return 1;} + static bool isIntegral() {return true;} + static bool isSigned() {return false;} +}; + +template <> +struct limits +{ + static int min() {return INT_MIN;} + static int max() {return INT_MAX;} + static int smallest() {return 1;} + static int epsilon() {return 1;} + static bool isIntegral() {return true;} + static bool isSigned() {return true;} +}; + +template <> +struct limits +{ + static unsigned int min() {return 0;} + static unsigned int max() {return UINT_MAX;} + static unsigned int smallest() {return 1;} + static unsigned int epsilon() {return 1;} + static bool isIntegral() {return true;} + static bool isSigned() {return false;} +}; + +template <> +struct limits +{ + static long min() {return LONG_MIN;} + static long max() {return LONG_MAX;} + static long smallest() {return 1;} + static long epsilon() {return 1;} + static bool isIntegral() {return true;} + static bool isSigned() {return true;} +}; + +template <> +struct limits +{ + static unsigned long min() {return 0;} + static unsigned long max() {return ULONG_MAX;} + static unsigned long smallest() {return 1;} + static unsigned long epsilon() {return 1;} + static bool isIntegral() {return true;} + static bool isSigned() {return false;} +}; + +template <> +struct limits +{ + static float min() {return -FLT_MAX;} + static float max() {return FLT_MAX;} + static float smallest() {return FLT_MIN;} + static float epsilon() {return FLT_EPSILON;} + static bool isIntegral() {return false;} + static bool isSigned() {return true;} +}; + +template <> +struct limits +{ + static double min() {return -DBL_MAX;} + static double max() {return DBL_MAX;} + static double smallest() {return DBL_MIN;} + static double epsilon() {return DBL_EPSILON;} + static bool isIntegral() {return false;} + static bool isSigned() {return true;} +}; + +template <> +struct limits +{ + static long double min() {return -LDBL_MAX;} + static long double max() {return LDBL_MAX;} + static long double smallest() {return LDBL_MIN;} + static long double epsilon() {return LDBL_EPSILON;} + static bool isIntegral() {return false;} + static bool isSigned() {return true;} +}; + + +IMATH_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_IMATHLIMITS_H diff --git a/OpenEXR/include/OpenEXR/ImathLine.h b/OpenEXR/include/OpenEXR/ImathLine.h new file mode 100644 index 0000000..61e4508 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathLine.h @@ -0,0 +1,185 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMATHLINE_H +#define INCLUDED_IMATHLINE_H + +//------------------------------------- +// +// A 3D line class template +// +//------------------------------------- + +#include "ImathVec.h" +#include "ImathLimits.h" +#include "ImathMatrix.h" +#include "ImathNamespace.h" + +IMATH_INTERNAL_NAMESPACE_HEADER_ENTER + + +template +class Line3 +{ + public: + + Vec3 pos; + Vec3 dir; + + //------------------------------------------------------------- + // Constructors - default is normalized units along direction + //------------------------------------------------------------- + + Line3() {} + Line3(const Vec3& point1, const Vec3& point2); + + //------------------ + // State Query/Set + //------------------ + + void set(const Vec3& point1, + const Vec3& point2); + + //------- + // F(t) + //------- + + Vec3 operator() (T parameter) const; + + //--------- + // Query + //--------- + + T distanceTo(const Vec3& point) const; + T distanceTo(const Line3& line) const; + Vec3 closestPointTo(const Vec3& point) const; + Vec3 closestPointTo(const Line3& line) const; +}; + + +//-------------------- +// Convenient typedefs +//-------------------- + +typedef Line3 Line3f; +typedef Line3 Line3d; + + +//--------------- +// Implementation +//--------------- + +template +inline Line3::Line3(const Vec3 &p0, const Vec3 &p1) +{ + set(p0,p1); +} + +template +inline void Line3::set(const Vec3 &p0, const Vec3 &p1) +{ + pos = p0; dir = p1-p0; + dir.normalize(); +} + +template +inline Vec3 Line3::operator()(T parameter) const +{ + return pos + dir * parameter; +} + +template +inline T Line3::distanceTo(const Vec3& point) const +{ + return (closestPointTo(point)-point).length(); +} + +template +inline Vec3 Line3::closestPointTo(const Vec3& point) const +{ + return ((point - pos) ^ dir) * dir + pos; +} + +template +inline T Line3::distanceTo(const Line3& line) const +{ + T d = (dir % line.dir) ^ (line.pos - pos); + return (d >= 0)? d: -d; +} + +template +inline Vec3 +Line3::closestPointTo(const Line3& line) const +{ + // Assumes the lines are normalized + + Vec3 posLpos = pos - line.pos ; + T c = dir ^ posLpos; + T a = line.dir ^ dir; + T f = line.dir ^ posLpos ; + T num = c - a * f; + + T denom = a*a - 1; + + T absDenom = ((denom >= 0)? denom: -denom); + + if (absDenom < 1) + { + T absNum = ((num >= 0)? num: -num); + + if (absNum >= absDenom * limits::max()) + return pos; + } + + return pos + dir * (num / denom); +} + +template +std::ostream& operator<< (std::ostream &o, const Line3 &line) +{ + return o << "(" << line.pos << ", " << line.dir << ")"; +} + +template +inline Line3 operator * (const Line3 &line, const Matrix44 &M) +{ + return Line3( line.pos * M, (line.pos + line.dir) * M ); +} + + +IMATH_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_IMATHLINE_H diff --git a/OpenEXR/include/OpenEXR/ImathLineAlgo.h b/OpenEXR/include/OpenEXR/ImathLineAlgo.h new file mode 100644 index 0000000..b08a1ff --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathLineAlgo.h @@ -0,0 +1,288 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMATHLINEALGO_H +#define INCLUDED_IMATHLINEALGO_H + +//------------------------------------------------------------------ +// +// This file contains algorithms applied to or in conjunction +// with lines (Imath::Line). These algorithms may require +// more headers to compile. The assumption made is that these +// functions are called much less often than the basic line +// functions or these functions require more support classes +// +// Contains: +// +// bool closestPoints(const Line& line1, +// const Line& line2, +// Vec3& point1, +// Vec3& point2) +// +// bool intersect( const Line3 &line, +// const Vec3 &v0, +// const Vec3 &v1, +// const Vec3 &v2, +// Vec3 &pt, +// Vec3 &barycentric, +// bool &front) +// +// V3f +// closestVertex(const Vec3 &v0, +// const Vec3 &v1, +// const Vec3 &v2, +// const Line3 &l) +// +// V3f +// rotatePoint(const Vec3 p, Line3 l, float angle) +// +//------------------------------------------------------------------ + +#include "ImathLine.h" +#include "ImathVecAlgo.h" +#include "ImathFun.h" +#include "ImathNamespace.h" + +IMATH_INTERNAL_NAMESPACE_HEADER_ENTER + + +template +bool +closestPoints + (const Line3& line1, + const Line3& line2, + Vec3& point1, + Vec3& point2) +{ + // + // Compute point1 and point2 such that point1 is on line1, point2 + // is on line2 and the distance between point1 and point2 is minimal. + // This function returns true if point1 and point2 can be computed, + // or false if line1 and line2 are parallel or nearly parallel. + // This function assumes that line1.dir and line2.dir are normalized. + // + + Vec3 w = line1.pos - line2.pos; + T d1w = line1.dir ^ w; + T d2w = line2.dir ^ w; + T d1d2 = line1.dir ^ line2.dir; + T n1 = d1d2 * d2w - d1w; + T n2 = d2w - d1d2 * d1w; + T d = 1 - d1d2 * d1d2; + T absD = abs (d); + + if ((absD > 1) || + (abs (n1) < limits::max() * absD && + abs (n2) < limits::max() * absD)) + { + point1 = line1 (n1 / d); + point2 = line2 (n2 / d); + return true; + } + else + { + return false; + } +} + + +template +bool +intersect + (const Line3 &line, + const Vec3 &v0, + const Vec3 &v1, + const Vec3 &v2, + Vec3 &pt, + Vec3 &barycentric, + bool &front) +{ + // + // Given a line and a triangle (v0, v1, v2), the intersect() function + // finds the intersection of the line and the plane that contains the + // triangle. + // + // If the intersection point cannot be computed, either because the + // line and the triangle's plane are nearly parallel or because the + // triangle's area is very small, intersect() returns false. + // + // If the intersection point is outside the triangle, intersect + // returns false. + // + // If the intersection point, pt, is inside the triangle, intersect() + // computes a front-facing flag and the barycentric coordinates of + // the intersection point, and returns true. + // + // The front-facing flag is true if the dot product of the triangle's + // normal, (v2-v1)%(v1-v0), and the line's direction is negative. + // + // The barycentric coordinates have the following property: + // + // pt = v0 * barycentric.x + v1 * barycentric.y + v2 * barycentric.z + // + + Vec3 edge0 = v1 - v0; + Vec3 edge1 = v2 - v1; + Vec3 normal = edge1 % edge0; + + T l = normal.length(); + + if (l != 0) + normal /= l; + else + return false; // zero-area triangle + + // + // d is the distance of line.pos from the plane that contains the triangle. + // The intersection point is at line.pos + (d/nd) * line.dir. + // + + T d = normal ^ (v0 - line.pos); + T nd = normal ^ line.dir; + + if (abs (nd) > 1 || abs (d) < limits::max() * abs (nd)) + pt = line (d / nd); + else + return false; // line and plane are nearly parallel + + // + // Compute the barycentric coordinates of the intersection point. + // The intersection is inside the triangle if all three barycentric + // coordinates are between zero and one. + // + + { + Vec3 en = edge0.normalized(); + Vec3 a = pt - v0; + Vec3 b = v2 - v0; + Vec3 c = (a - en * (en ^ a)); + Vec3 d = (b - en * (en ^ b)); + T e = c ^ d; + T f = d ^ d; + + if (e >= 0 && e <= f) + barycentric.z = e / f; + else + return false; // outside + } + + { + Vec3 en = edge1.normalized(); + Vec3 a = pt - v1; + Vec3 b = v0 - v1; + Vec3 c = (a - en * (en ^ a)); + Vec3 d = (b - en * (en ^ b)); + T e = c ^ d; + T f = d ^ d; + + if (e >= 0 && e <= f) + barycentric.x = e / f; + else + return false; // outside + } + + barycentric.y = 1 - barycentric.x - barycentric.z; + + if (barycentric.y < 0) + return false; // outside + + front = ((line.dir ^ normal) < 0); + return true; +} + + +template +Vec3 +closestVertex + (const Vec3 &v0, + const Vec3 &v1, + const Vec3 &v2, + const Line3 &l) +{ + Vec3 nearest = v0; + T neardot = (v0 - l.closestPointTo(v0)).length2(); + + T tmp = (v1 - l.closestPointTo(v1)).length2(); + + if (tmp < neardot) + { + neardot = tmp; + nearest = v1; + } + + tmp = (v2 - l.closestPointTo(v2)).length2(); + if (tmp < neardot) + { + neardot = tmp; + nearest = v2; + } + + return nearest; +} + + +template +Vec3 +rotatePoint (const Vec3 p, Line3 l, T angle) +{ + // + // Rotate the point p around the line l by the given angle. + // + + // + // Form a coordinate frame with . The rotation is the in xy + // plane. + // + + Vec3 q = l.closestPointTo(p); + Vec3 x = p - q; + T radius = x.length(); + + x.normalize(); + Vec3 y = (x % l.dir).normalize(); + + T cosangle = Math::cos(angle); + T sinangle = Math::sin(angle); + + Vec3 r = q + x * radius * cosangle + y * radius * sinangle; + + return r; +} + + +IMATH_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_IMATHLINEALGO_H diff --git a/OpenEXR/include/OpenEXR/ImathMath.h b/OpenEXR/include/OpenEXR/ImathMath.h new file mode 100644 index 0000000..1961d5a --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathMath.h @@ -0,0 +1,208 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMATHMATH_H +#define INCLUDED_IMATHMATH_H + +//---------------------------------------------------------------------------- +// +// ImathMath.h +// +// This file contains template functions which call the double- +// precision math functions defined in math.h (sin(), sqrt(), +// exp() etc.), with specializations that call the faster +// single-precision versions (sinf(), sqrtf(), expf() etc.) +// when appropriate. +// +// Example: +// +// double x = Math::sqrt (3); // calls ::sqrt(double); +// float y = Math::sqrt (3); // calls ::sqrtf(float); +// +// When would I want to use this? +// +// You may be writing a template which needs to call some function +// defined in math.h, for example to extract a square root, but you +// don't know whether to call the single- or the double-precision +// version of this function (sqrt() or sqrtf()): +// +// template +// T +// glorp (T x) +// { +// return sqrt (x + 1); // should call ::sqrtf(float) +// } // if x is a float, but we +// // don't know if it is +// +// Using the templates in this file, you can make sure that +// the appropriate version of the math function is called: +// +// template +// T +// glorp (T x, T y) +// { +// return Math::sqrt (x + 1); // calls ::sqrtf(float) if x +// } // is a float, ::sqrt(double) +// // otherwise +// +//---------------------------------------------------------------------------- + +#include "ImathPlatform.h" +#include "ImathLimits.h" +#include "ImathNamespace.h" +#include + +IMATH_INTERNAL_NAMESPACE_HEADER_ENTER + + +template +struct Math +{ + static T acos (T x) {return ::acos (double(x));} + static T asin (T x) {return ::asin (double(x));} + static T atan (T x) {return ::atan (double(x));} + static T atan2 (T x, T y) {return ::atan2 (double(x), double(y));} + static T cos (T x) {return ::cos (double(x));} + static T sin (T x) {return ::sin (double(x));} + static T tan (T x) {return ::tan (double(x));} + static T cosh (T x) {return ::cosh (double(x));} + static T sinh (T x) {return ::sinh (double(x));} + static T tanh (T x) {return ::tanh (double(x));} + static T exp (T x) {return ::exp (double(x));} + static T log (T x) {return ::log (double(x));} + static T log10 (T x) {return ::log10 (double(x));} + static T modf (T x, T *iptr) + { + double ival; + T rval( ::modf (double(x),&ival)); + *iptr = ival; + return rval; + } + static T pow (T x, T y) {return ::pow (double(x), double(y));} + static T sqrt (T x) {return ::sqrt (double(x));} + static T ceil (T x) {return ::ceil (double(x));} + static T fabs (T x) {return ::fabs (double(x));} + static T floor (T x) {return ::floor (double(x));} + static T fmod (T x, T y) {return ::fmod (double(x), double(y));} + static T hypot (T x, T y) {return ::hypot (double(x), double(y));} +}; + + +template <> +struct Math +{ + static float acos (float x) {return ::acosf (x);} + static float asin (float x) {return ::asinf (x);} + static float atan (float x) {return ::atanf (x);} + static float atan2 (float x, float y) {return ::atan2f (x, y);} + static float cos (float x) {return ::cosf (x);} + static float sin (float x) {return ::sinf (x);} + static float tan (float x) {return ::tanf (x);} + static float cosh (float x) {return ::coshf (x);} + static float sinh (float x) {return ::sinhf (x);} + static float tanh (float x) {return ::tanhf (x);} + static float exp (float x) {return ::expf (x);} + static float log (float x) {return ::logf (x);} + static float log10 (float x) {return ::log10f (x);} + static float modf (float x, float *y) {return ::modff (x, y);} + static float pow (float x, float y) {return ::powf (x, y);} + static float sqrt (float x) {return ::sqrtf (x);} + static float ceil (float x) {return ::ceilf (x);} + static float fabs (float x) {return ::fabsf (x);} + static float floor (float x) {return ::floorf (x);} + static float fmod (float x, float y) {return ::fmodf (x, y);} +#if !defined(_MSC_VER) + static float hypot (float x, float y) {return ::hypotf (x, y);} +#else + static float hypot (float x, float y) {return ::sqrtf(x*x + y*y);} +#endif +}; + + +//-------------------------------------------------------------------------- +// Don Hatch's version of sin(x)/x, which is accurate for very small x. +// Returns 1 for x == 0. +//-------------------------------------------------------------------------- + +template +inline T +sinx_over_x (T x) +{ + if (x * x < limits::epsilon()) + return T (1); + else + return Math::sin (x) / x; +} + + +//-------------------------------------------------------------------------- +// Compare two numbers and test if they are "approximately equal": +// +// equalWithAbsError (x1, x2, e) +// +// Returns true if x1 is the same as x2 with an absolute error of +// no more than e, +// +// abs (x1 - x2) <= e +// +// equalWithRelError (x1, x2, e) +// +// Returns true if x1 is the same as x2 with an relative error of +// no more than e, +// +// abs (x1 - x2) <= e * x1 +// +//-------------------------------------------------------------------------- + +template +inline bool +equalWithAbsError (T x1, T x2, T e) +{ + return ((x1 > x2)? x1 - x2: x2 - x1) <= e; +} + + +template +inline bool +equalWithRelError (T x1, T x2, T e) +{ + return ((x1 > x2)? x1 - x2: x2 - x1) <= e * ((x1 > 0)? x1: -x1); +} + + +IMATH_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_IMATHMATH_H diff --git a/OpenEXR/include/OpenEXR/ImathMatrix.h b/OpenEXR/include/OpenEXR/ImathMatrix.h new file mode 100644 index 0000000..3e96c2f --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathMatrix.h @@ -0,0 +1,3441 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMATHMATRIX_H +#define INCLUDED_IMATHMATRIX_H + +//---------------------------------------------------------------- +// +// 2D (3x3) and 3D (4x4) transformation matrix templates. +// +//---------------------------------------------------------------- + +#include "ImathPlatform.h" +#include "ImathFun.h" +#include "ImathExc.h" +#include "ImathVec.h" +#include "ImathShear.h" +#include "ImathNamespace.h" + +#include +#include +#include +#include + +#if (defined _WIN32 || defined _WIN64) && defined _MSC_VER +// suppress exception specification warnings +#pragma warning(disable:4290) +#endif + + +IMATH_INTERNAL_NAMESPACE_HEADER_ENTER + +enum Uninitialized {UNINITIALIZED}; + + +template class Matrix33 +{ + public: + + //------------------- + // Access to elements + //------------------- + + T x[3][3]; + + T * operator [] (int i); + const T * operator [] (int i) const; + + + //------------- + // Constructors + //------------- + + Matrix33 (Uninitialized) {} + + Matrix33 (); + // 1 0 0 + // 0 1 0 + // 0 0 1 + + Matrix33 (T a); + // a a a + // a a a + // a a a + + Matrix33 (const T a[3][3]); + // a[0][0] a[0][1] a[0][2] + // a[1][0] a[1][1] a[1][2] + // a[2][0] a[2][1] a[2][2] + + Matrix33 (T a, T b, T c, T d, T e, T f, T g, T h, T i); + + // a b c + // d e f + // g h i + + + //-------------------------------- + // Copy constructor and assignment + //-------------------------------- + + Matrix33 (const Matrix33 &v); + template explicit Matrix33 (const Matrix33 &v); + + const Matrix33 & operator = (const Matrix33 &v); + const Matrix33 & operator = (T a); + + + //---------------------- + // Compatibility with Sb + //---------------------- + + T * getValue (); + const T * getValue () const; + + template + void getValue (Matrix33 &v) const; + template + Matrix33 & setValue (const Matrix33 &v); + + template + Matrix33 & setTheMatrix (const Matrix33 &v); + + + //--------- + // Identity + //--------- + + void makeIdentity(); + + + //--------- + // Equality + //--------- + + bool operator == (const Matrix33 &v) const; + bool operator != (const Matrix33 &v) const; + + //----------------------------------------------------------------------- + // Compare two matrices and test if they are "approximately equal": + // + // equalWithAbsError (m, e) + // + // Returns true if the coefficients of this and m are the same with + // an absolute error of no more than e, i.e., for all i, j + // + // abs (this[i][j] - m[i][j]) <= e + // + // equalWithRelError (m, e) + // + // Returns true if the coefficients of this and m are the same with + // a relative error of no more than e, i.e., for all i, j + // + // abs (this[i] - v[i][j]) <= e * abs (this[i][j]) + //----------------------------------------------------------------------- + + bool equalWithAbsError (const Matrix33 &v, T e) const; + bool equalWithRelError (const Matrix33 &v, T e) const; + + + //------------------------ + // Component-wise addition + //------------------------ + + const Matrix33 & operator += (const Matrix33 &v); + const Matrix33 & operator += (T a); + Matrix33 operator + (const Matrix33 &v) const; + + + //--------------------------- + // Component-wise subtraction + //--------------------------- + + const Matrix33 & operator -= (const Matrix33 &v); + const Matrix33 & operator -= (T a); + Matrix33 operator - (const Matrix33 &v) const; + + + //------------------------------------ + // Component-wise multiplication by -1 + //------------------------------------ + + Matrix33 operator - () const; + const Matrix33 & negate (); + + + //------------------------------ + // Component-wise multiplication + //------------------------------ + + const Matrix33 & operator *= (T a); + Matrix33 operator * (T a) const; + + + //----------------------------------- + // Matrix-times-matrix multiplication + //----------------------------------- + + const Matrix33 & operator *= (const Matrix33 &v); + Matrix33 operator * (const Matrix33 &v) const; + + + //----------------------------------------------------------------- + // Vector-times-matrix multiplication; see also the "operator *" + // functions defined below. + // + // m.multVecMatrix(src,dst) implements a homogeneous transformation + // by computing Vec3 (src.x, src.y, 1) * m and dividing by the + // result's third element. + // + // m.multDirMatrix(src,dst) multiplies src by the upper left 2x2 + // submatrix, ignoring the rest of matrix m. + //----------------------------------------------------------------- + + template + void multVecMatrix(const Vec2 &src, Vec2 &dst) const; + + template + void multDirMatrix(const Vec2 &src, Vec2 &dst) const; + + + //------------------------ + // Component-wise division + //------------------------ + + const Matrix33 & operator /= (T a); + Matrix33 operator / (T a) const; + + + //------------------ + // Transposed matrix + //------------------ + + const Matrix33 & transpose (); + Matrix33 transposed () const; + + + //------------------------------------------------------------ + // Inverse matrix: If singExc is false, inverting a singular + // matrix produces an identity matrix. If singExc is true, + // inverting a singular matrix throws a SingMatrixExc. + // + // inverse() and invert() invert matrices using determinants; + // gjInverse() and gjInvert() use the Gauss-Jordan method. + // + // inverse() and invert() are significantly faster than + // gjInverse() and gjInvert(), but the results may be slightly + // less accurate. + // + //------------------------------------------------------------ + + const Matrix33 & invert (bool singExc = false) + throw (IEX_NAMESPACE::MathExc); + + Matrix33 inverse (bool singExc = false) const + throw (IEX_NAMESPACE::MathExc); + + const Matrix33 & gjInvert (bool singExc = false) + throw (IEX_NAMESPACE::MathExc); + + Matrix33 gjInverse (bool singExc = false) const + throw (IEX_NAMESPACE::MathExc); + + + //------------------------------------------------ + // Calculate the matrix minor of the (r,c) element + //------------------------------------------------ + + T minorOf (const int r, const int c) const; + + //--------------------------------------------------- + // Build a minor using the specified rows and columns + //--------------------------------------------------- + + T fastMinor (const int r0, const int r1, + const int c0, const int c1) const; + + //------------ + // Determinant + //------------ + + T determinant() const; + + //----------------------------------------- + // Set matrix to rotation by r (in radians) + //----------------------------------------- + + template + const Matrix33 & setRotation (S r); + + + //----------------------------- + // Rotate the given matrix by r + //----------------------------- + + template + const Matrix33 & rotate (S r); + + + //-------------------------------------------- + // Set matrix to scale by given uniform factor + //-------------------------------------------- + + const Matrix33 & setScale (T s); + + + //------------------------------------ + // Set matrix to scale by given vector + //------------------------------------ + + template + const Matrix33 & setScale (const Vec2 &s); + + + //---------------------- + // Scale the matrix by s + //---------------------- + + template + const Matrix33 & scale (const Vec2 &s); + + + //------------------------------------------ + // Set matrix to translation by given vector + //------------------------------------------ + + template + const Matrix33 & setTranslation (const Vec2 &t); + + + //----------------------------- + // Return translation component + //----------------------------- + + Vec2 translation () const; + + + //-------------------------- + // Translate the matrix by t + //-------------------------- + + template + const Matrix33 & translate (const Vec2 &t); + + + //----------------------------------------------------------- + // Set matrix to shear x for each y coord. by given factor xy + //----------------------------------------------------------- + + template + const Matrix33 & setShear (const S &h); + + + //------------------------------------------------------------- + // Set matrix to shear x for each y coord. by given factor h[0] + // and to shear y for each x coord. by given factor h[1] + //------------------------------------------------------------- + + template + const Matrix33 & setShear (const Vec2 &h); + + + //----------------------------------------------------------- + // Shear the matrix in x for each y coord. by given factor xy + //----------------------------------------------------------- + + template + const Matrix33 & shear (const S &xy); + + + //----------------------------------------------------------- + // Shear the matrix in x for each y coord. by given factor xy + // and shear y for each x coord. by given factor yx + //----------------------------------------------------------- + + template + const Matrix33 & shear (const Vec2 &h); + + + //-------------------------------------------------------- + // Number of the row and column dimensions, since + // Matrix33 is a square matrix. + //-------------------------------------------------------- + + static unsigned int dimensions() {return 3;} + + + //------------------------------------------------- + // Limitations of type T (see also class limits) + //------------------------------------------------- + + static T baseTypeMin() {return limits::min();} + static T baseTypeMax() {return limits::max();} + static T baseTypeSmallest() {return limits::smallest();} + static T baseTypeEpsilon() {return limits::epsilon();} + + typedef T BaseType; + typedef Vec3 BaseVecType; + + private: + + template + struct isSameType + { + enum {value = 0}; + }; + + template + struct isSameType + { + enum {value = 1}; + }; +}; + + +template class Matrix44 +{ + public: + + //------------------- + // Access to elements + //------------------- + + T x[4][4]; + + T * operator [] (int i); + const T * operator [] (int i) const; + + + //------------- + // Constructors + //------------- + + Matrix44 (Uninitialized) {} + + Matrix44 (); + // 1 0 0 0 + // 0 1 0 0 + // 0 0 1 0 + // 0 0 0 1 + + Matrix44 (T a); + // a a a a + // a a a a + // a a a a + // a a a a + + Matrix44 (const T a[4][4]) ; + // a[0][0] a[0][1] a[0][2] a[0][3] + // a[1][0] a[1][1] a[1][2] a[1][3] + // a[2][0] a[2][1] a[2][2] a[2][3] + // a[3][0] a[3][1] a[3][2] a[3][3] + + Matrix44 (T a, T b, T c, T d, T e, T f, T g, T h, + T i, T j, T k, T l, T m, T n, T o, T p); + + // a b c d + // e f g h + // i j k l + // m n o p + + Matrix44 (Matrix33 r, Vec3 t); + // r r r 0 + // r r r 0 + // r r r 0 + // t t t 1 + + + //-------------------------------- + // Copy constructor and assignment + //-------------------------------- + + Matrix44 (const Matrix44 &v); + template explicit Matrix44 (const Matrix44 &v); + + const Matrix44 & operator = (const Matrix44 &v); + const Matrix44 & operator = (T a); + + + //---------------------- + // Compatibility with Sb + //---------------------- + + T * getValue (); + const T * getValue () const; + + template + void getValue (Matrix44 &v) const; + template + Matrix44 & setValue (const Matrix44 &v); + + template + Matrix44 & setTheMatrix (const Matrix44 &v); + + //--------- + // Identity + //--------- + + void makeIdentity(); + + + //--------- + // Equality + //--------- + + bool operator == (const Matrix44 &v) const; + bool operator != (const Matrix44 &v) const; + + //----------------------------------------------------------------------- + // Compare two matrices and test if they are "approximately equal": + // + // equalWithAbsError (m, e) + // + // Returns true if the coefficients of this and m are the same with + // an absolute error of no more than e, i.e., for all i, j + // + // abs (this[i][j] - m[i][j]) <= e + // + // equalWithRelError (m, e) + // + // Returns true if the coefficients of this and m are the same with + // a relative error of no more than e, i.e., for all i, j + // + // abs (this[i] - v[i][j]) <= e * abs (this[i][j]) + //----------------------------------------------------------------------- + + bool equalWithAbsError (const Matrix44 &v, T e) const; + bool equalWithRelError (const Matrix44 &v, T e) const; + + + //------------------------ + // Component-wise addition + //------------------------ + + const Matrix44 & operator += (const Matrix44 &v); + const Matrix44 & operator += (T a); + Matrix44 operator + (const Matrix44 &v) const; + + + //--------------------------- + // Component-wise subtraction + //--------------------------- + + const Matrix44 & operator -= (const Matrix44 &v); + const Matrix44 & operator -= (T a); + Matrix44 operator - (const Matrix44 &v) const; + + + //------------------------------------ + // Component-wise multiplication by -1 + //------------------------------------ + + Matrix44 operator - () const; + const Matrix44 & negate (); + + + //------------------------------ + // Component-wise multiplication + //------------------------------ + + const Matrix44 & operator *= (T a); + Matrix44 operator * (T a) const; + + + //----------------------------------- + // Matrix-times-matrix multiplication + //----------------------------------- + + const Matrix44 & operator *= (const Matrix44 &v); + Matrix44 operator * (const Matrix44 &v) const; + + static void multiply (const Matrix44 &a, // assumes that + const Matrix44 &b, // &a != &c and + Matrix44 &c); // &b != &c. + + + //----------------------------------------------------------------- + // Vector-times-matrix multiplication; see also the "operator *" + // functions defined below. + // + // m.multVecMatrix(src,dst) implements a homogeneous transformation + // by computing Vec4 (src.x, src.y, src.z, 1) * m and dividing by + // the result's third element. + // + // m.multDirMatrix(src,dst) multiplies src by the upper left 3x3 + // submatrix, ignoring the rest of matrix m. + //----------------------------------------------------------------- + + template + void multVecMatrix(const Vec3 &src, Vec3 &dst) const; + + template + void multDirMatrix(const Vec3 &src, Vec3 &dst) const; + + + //------------------------ + // Component-wise division + //------------------------ + + const Matrix44 & operator /= (T a); + Matrix44 operator / (T a) const; + + + //------------------ + // Transposed matrix + //------------------ + + const Matrix44 & transpose (); + Matrix44 transposed () const; + + + //------------------------------------------------------------ + // Inverse matrix: If singExc is false, inverting a singular + // matrix produces an identity matrix. If singExc is true, + // inverting a singular matrix throws a SingMatrixExc. + // + // inverse() and invert() invert matrices using determinants; + // gjInverse() and gjInvert() use the Gauss-Jordan method. + // + // inverse() and invert() are significantly faster than + // gjInverse() and gjInvert(), but the results may be slightly + // less accurate. + // + //------------------------------------------------------------ + + const Matrix44 & invert (bool singExc = false) + throw (IEX_NAMESPACE::MathExc); + + Matrix44 inverse (bool singExc = false) const + throw (IEX_NAMESPACE::MathExc); + + const Matrix44 & gjInvert (bool singExc = false) + throw (IEX_NAMESPACE::MathExc); + + Matrix44 gjInverse (bool singExc = false) const + throw (IEX_NAMESPACE::MathExc); + + + //------------------------------------------------ + // Calculate the matrix minor of the (r,c) element + //------------------------------------------------ + + T minorOf (const int r, const int c) const; + + //--------------------------------------------------- + // Build a minor using the specified rows and columns + //--------------------------------------------------- + + T fastMinor (const int r0, const int r1, const int r2, + const int c0, const int c1, const int c2) const; + + //------------ + // Determinant + //------------ + + T determinant() const; + + //-------------------------------------------------------- + // Set matrix to rotation by XYZ euler angles (in radians) + //-------------------------------------------------------- + + template + const Matrix44 & setEulerAngles (const Vec3& r); + + + //-------------------------------------------------------- + // Set matrix to rotation around given axis by given angle + //-------------------------------------------------------- + + template + const Matrix44 & setAxisAngle (const Vec3& ax, S ang); + + + //------------------------------------------- + // Rotate the matrix by XYZ euler angles in r + //------------------------------------------- + + template + const Matrix44 & rotate (const Vec3 &r); + + + //-------------------------------------------- + // Set matrix to scale by given uniform factor + //-------------------------------------------- + + const Matrix44 & setScale (T s); + + + //------------------------------------ + // Set matrix to scale by given vector + //------------------------------------ + + template + const Matrix44 & setScale (const Vec3 &s); + + + //---------------------- + // Scale the matrix by s + //---------------------- + + template + const Matrix44 & scale (const Vec3 &s); + + + //------------------------------------------ + // Set matrix to translation by given vector + //------------------------------------------ + + template + const Matrix44 & setTranslation (const Vec3 &t); + + + //----------------------------- + // Return translation component + //----------------------------- + + const Vec3 translation () const; + + + //-------------------------- + // Translate the matrix by t + //-------------------------- + + template + const Matrix44 & translate (const Vec3 &t); + + + //------------------------------------------------------------- + // Set matrix to shear by given vector h. The resulting matrix + // will shear x for each y coord. by a factor of h[0] ; + // will shear x for each z coord. by a factor of h[1] ; + // will shear y for each z coord. by a factor of h[2] . + //------------------------------------------------------------- + + template + const Matrix44 & setShear (const Vec3 &h); + + + //------------------------------------------------------------ + // Set matrix to shear by given factors. The resulting matrix + // will shear x for each y coord. by a factor of h.xy ; + // will shear x for each z coord. by a factor of h.xz ; + // will shear y for each z coord. by a factor of h.yz ; + // will shear y for each x coord. by a factor of h.yx ; + // will shear z for each x coord. by a factor of h.zx ; + // will shear z for each y coord. by a factor of h.zy . + //------------------------------------------------------------ + + template + const Matrix44 & setShear (const Shear6 &h); + + + //-------------------------------------------------------- + // Shear the matrix by given vector. The composed matrix + // will be * , where the shear matrix ... + // will shear x for each y coord. by a factor of h[0] ; + // will shear x for each z coord. by a factor of h[1] ; + // will shear y for each z coord. by a factor of h[2] . + //-------------------------------------------------------- + + template + const Matrix44 & shear (const Vec3 &h); + + //-------------------------------------------------------- + // Number of the row and column dimensions, since + // Matrix44 is a square matrix. + //-------------------------------------------------------- + + static unsigned int dimensions() {return 4;} + + + //------------------------------------------------------------ + // Shear the matrix by the given factors. The composed matrix + // will be * , where the shear matrix ... + // will shear x for each y coord. by a factor of h.xy ; + // will shear x for each z coord. by a factor of h.xz ; + // will shear y for each z coord. by a factor of h.yz ; + // will shear y for each x coord. by a factor of h.yx ; + // will shear z for each x coord. by a factor of h.zx ; + // will shear z for each y coord. by a factor of h.zy . + //------------------------------------------------------------ + + template + const Matrix44 & shear (const Shear6 &h); + + + //------------------------------------------------- + // Limitations of type T (see also class limits) + //------------------------------------------------- + + static T baseTypeMin() {return limits::min();} + static T baseTypeMax() {return limits::max();} + static T baseTypeSmallest() {return limits::smallest();} + static T baseTypeEpsilon() {return limits::epsilon();} + + typedef T BaseType; + typedef Vec4 BaseVecType; + + private: + + template + struct isSameType + { + enum {value = 0}; + }; + + template + struct isSameType + { + enum {value = 1}; + }; +}; + + +//-------------- +// Stream output +//-------------- + +template +std::ostream & operator << (std::ostream & s, const Matrix33 &m); + +template +std::ostream & operator << (std::ostream & s, const Matrix44 &m); + + +//--------------------------------------------- +// Vector-times-matrix multiplication operators +//--------------------------------------------- + +template +const Vec2 & operator *= (Vec2 &v, const Matrix33 &m); + +template +Vec2 operator * (const Vec2 &v, const Matrix33 &m); + +template +const Vec3 & operator *= (Vec3 &v, const Matrix33 &m); + +template +Vec3 operator * (const Vec3 &v, const Matrix33 &m); + +template +const Vec3 & operator *= (Vec3 &v, const Matrix44 &m); + +template +Vec3 operator * (const Vec3 &v, const Matrix44 &m); + +template +const Vec4 & operator *= (Vec4 &v, const Matrix44 &m); + +template +Vec4 operator * (const Vec4 &v, const Matrix44 &m); + +//------------------------- +// Typedefs for convenience +//------------------------- + +typedef Matrix33 M33f; +typedef Matrix33 M33d; +typedef Matrix44 M44f; +typedef Matrix44 M44d; + + +//--------------------------- +// Implementation of Matrix33 +//--------------------------- + +template +inline T * +Matrix33::operator [] (int i) +{ + return x[i]; +} + +template +inline const T * +Matrix33::operator [] (int i) const +{ + return x[i]; +} + +template +inline +Matrix33::Matrix33 () +{ + memset (x, 0, sizeof (x)); + x[0][0] = 1; + x[1][1] = 1; + x[2][2] = 1; +} + +template +inline +Matrix33::Matrix33 (T a) +{ + x[0][0] = a; + x[0][1] = a; + x[0][2] = a; + x[1][0] = a; + x[1][1] = a; + x[1][2] = a; + x[2][0] = a; + x[2][1] = a; + x[2][2] = a; +} + +template +inline +Matrix33::Matrix33 (const T a[3][3]) +{ + memcpy (x, a, sizeof (x)); +} + +template +inline +Matrix33::Matrix33 (T a, T b, T c, T d, T e, T f, T g, T h, T i) +{ + x[0][0] = a; + x[0][1] = b; + x[0][2] = c; + x[1][0] = d; + x[1][1] = e; + x[1][2] = f; + x[2][0] = g; + x[2][1] = h; + x[2][2] = i; +} + +template +inline +Matrix33::Matrix33 (const Matrix33 &v) +{ + memcpy (x, v.x, sizeof (x)); +} + +template +template +inline +Matrix33::Matrix33 (const Matrix33 &v) +{ + x[0][0] = T (v.x[0][0]); + x[0][1] = T (v.x[0][1]); + x[0][2] = T (v.x[0][2]); + x[1][0] = T (v.x[1][0]); + x[1][1] = T (v.x[1][1]); + x[1][2] = T (v.x[1][2]); + x[2][0] = T (v.x[2][0]); + x[2][1] = T (v.x[2][1]); + x[2][2] = T (v.x[2][2]); +} + +template +inline const Matrix33 & +Matrix33::operator = (const Matrix33 &v) +{ + memcpy (x, v.x, sizeof (x)); + return *this; +} + +template +inline const Matrix33 & +Matrix33::operator = (T a) +{ + x[0][0] = a; + x[0][1] = a; + x[0][2] = a; + x[1][0] = a; + x[1][1] = a; + x[1][2] = a; + x[2][0] = a; + x[2][1] = a; + x[2][2] = a; + return *this; +} + +template +inline T * +Matrix33::getValue () +{ + return (T *) &x[0][0]; +} + +template +inline const T * +Matrix33::getValue () const +{ + return (const T *) &x[0][0]; +} + +template +template +inline void +Matrix33::getValue (Matrix33 &v) const +{ + if (isSameType::value) + { + memcpy (v.x, x, sizeof (x)); + } + else + { + v.x[0][0] = x[0][0]; + v.x[0][1] = x[0][1]; + v.x[0][2] = x[0][2]; + v.x[1][0] = x[1][0]; + v.x[1][1] = x[1][1]; + v.x[1][2] = x[1][2]; + v.x[2][0] = x[2][0]; + v.x[2][1] = x[2][1]; + v.x[2][2] = x[2][2]; + } +} + +template +template +inline Matrix33 & +Matrix33::setValue (const Matrix33 &v) +{ + if (isSameType::value) + { + memcpy (x, v.x, sizeof (x)); + } + else + { + x[0][0] = v.x[0][0]; + x[0][1] = v.x[0][1]; + x[0][2] = v.x[0][2]; + x[1][0] = v.x[1][0]; + x[1][1] = v.x[1][1]; + x[1][2] = v.x[1][2]; + x[2][0] = v.x[2][0]; + x[2][1] = v.x[2][1]; + x[2][2] = v.x[2][2]; + } + + return *this; +} + +template +template +inline Matrix33 & +Matrix33::setTheMatrix (const Matrix33 &v) +{ + if (isSameType::value) + { + memcpy (x, v.x, sizeof (x)); + } + else + { + x[0][0] = v.x[0][0]; + x[0][1] = v.x[0][1]; + x[0][2] = v.x[0][2]; + x[1][0] = v.x[1][0]; + x[1][1] = v.x[1][1]; + x[1][2] = v.x[1][2]; + x[2][0] = v.x[2][0]; + x[2][1] = v.x[2][1]; + x[2][2] = v.x[2][2]; + } + + return *this; +} + +template +inline void +Matrix33::makeIdentity() +{ + memset (x, 0, sizeof (x)); + x[0][0] = 1; + x[1][1] = 1; + x[2][2] = 1; +} + +template +bool +Matrix33::operator == (const Matrix33 &v) const +{ + return x[0][0] == v.x[0][0] && + x[0][1] == v.x[0][1] && + x[0][2] == v.x[0][2] && + x[1][0] == v.x[1][0] && + x[1][1] == v.x[1][1] && + x[1][2] == v.x[1][2] && + x[2][0] == v.x[2][0] && + x[2][1] == v.x[2][1] && + x[2][2] == v.x[2][2]; +} + +template +bool +Matrix33::operator != (const Matrix33 &v) const +{ + return x[0][0] != v.x[0][0] || + x[0][1] != v.x[0][1] || + x[0][2] != v.x[0][2] || + x[1][0] != v.x[1][0] || + x[1][1] != v.x[1][1] || + x[1][2] != v.x[1][2] || + x[2][0] != v.x[2][0] || + x[2][1] != v.x[2][1] || + x[2][2] != v.x[2][2]; +} + +template +bool +Matrix33::equalWithAbsError (const Matrix33 &m, T e) const +{ + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) + if (!IMATH_INTERNAL_NAMESPACE::equalWithAbsError ((*this)[i][j], m[i][j], e)) + return false; + + return true; +} + +template +bool +Matrix33::equalWithRelError (const Matrix33 &m, T e) const +{ + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) + if (!IMATH_INTERNAL_NAMESPACE::equalWithRelError ((*this)[i][j], m[i][j], e)) + return false; + + return true; +} + +template +const Matrix33 & +Matrix33::operator += (const Matrix33 &v) +{ + x[0][0] += v.x[0][0]; + x[0][1] += v.x[0][1]; + x[0][2] += v.x[0][2]; + x[1][0] += v.x[1][0]; + x[1][1] += v.x[1][1]; + x[1][2] += v.x[1][2]; + x[2][0] += v.x[2][0]; + x[2][1] += v.x[2][1]; + x[2][2] += v.x[2][2]; + + return *this; +} + +template +const Matrix33 & +Matrix33::operator += (T a) +{ + x[0][0] += a; + x[0][1] += a; + x[0][2] += a; + x[1][0] += a; + x[1][1] += a; + x[1][2] += a; + x[2][0] += a; + x[2][1] += a; + x[2][2] += a; + + return *this; +} + +template +Matrix33 +Matrix33::operator + (const Matrix33 &v) const +{ + return Matrix33 (x[0][0] + v.x[0][0], + x[0][1] + v.x[0][1], + x[0][2] + v.x[0][2], + x[1][0] + v.x[1][0], + x[1][1] + v.x[1][1], + x[1][2] + v.x[1][2], + x[2][0] + v.x[2][0], + x[2][1] + v.x[2][1], + x[2][2] + v.x[2][2]); +} + +template +const Matrix33 & +Matrix33::operator -= (const Matrix33 &v) +{ + x[0][0] -= v.x[0][0]; + x[0][1] -= v.x[0][1]; + x[0][2] -= v.x[0][2]; + x[1][0] -= v.x[1][0]; + x[1][1] -= v.x[1][1]; + x[1][2] -= v.x[1][2]; + x[2][0] -= v.x[2][0]; + x[2][1] -= v.x[2][1]; + x[2][2] -= v.x[2][2]; + + return *this; +} + +template +const Matrix33 & +Matrix33::operator -= (T a) +{ + x[0][0] -= a; + x[0][1] -= a; + x[0][2] -= a; + x[1][0] -= a; + x[1][1] -= a; + x[1][2] -= a; + x[2][0] -= a; + x[2][1] -= a; + x[2][2] -= a; + + return *this; +} + +template +Matrix33 +Matrix33::operator - (const Matrix33 &v) const +{ + return Matrix33 (x[0][0] - v.x[0][0], + x[0][1] - v.x[0][1], + x[0][2] - v.x[0][2], + x[1][0] - v.x[1][0], + x[1][1] - v.x[1][1], + x[1][2] - v.x[1][2], + x[2][0] - v.x[2][0], + x[2][1] - v.x[2][1], + x[2][2] - v.x[2][2]); +} + +template +Matrix33 +Matrix33::operator - () const +{ + return Matrix33 (-x[0][0], + -x[0][1], + -x[0][2], + -x[1][0], + -x[1][1], + -x[1][2], + -x[2][0], + -x[2][1], + -x[2][2]); +} + +template +const Matrix33 & +Matrix33::negate () +{ + x[0][0] = -x[0][0]; + x[0][1] = -x[0][1]; + x[0][2] = -x[0][2]; + x[1][0] = -x[1][0]; + x[1][1] = -x[1][1]; + x[1][2] = -x[1][2]; + x[2][0] = -x[2][0]; + x[2][1] = -x[2][1]; + x[2][2] = -x[2][2]; + + return *this; +} + +template +const Matrix33 & +Matrix33::operator *= (T a) +{ + x[0][0] *= a; + x[0][1] *= a; + x[0][2] *= a; + x[1][0] *= a; + x[1][1] *= a; + x[1][2] *= a; + x[2][0] *= a; + x[2][1] *= a; + x[2][2] *= a; + + return *this; +} + +template +Matrix33 +Matrix33::operator * (T a) const +{ + return Matrix33 (x[0][0] * a, + x[0][1] * a, + x[0][2] * a, + x[1][0] * a, + x[1][1] * a, + x[1][2] * a, + x[2][0] * a, + x[2][1] * a, + x[2][2] * a); +} + +template +inline Matrix33 +operator * (T a, const Matrix33 &v) +{ + return v * a; +} + +template +const Matrix33 & +Matrix33::operator *= (const Matrix33 &v) +{ + Matrix33 tmp (T (0)); + + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) + for (int k = 0; k < 3; k++) + tmp.x[i][j] += x[i][k] * v.x[k][j]; + + *this = tmp; + return *this; +} + +template +Matrix33 +Matrix33::operator * (const Matrix33 &v) const +{ + Matrix33 tmp (T (0)); + + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) + for (int k = 0; k < 3; k++) + tmp.x[i][j] += x[i][k] * v.x[k][j]; + + return tmp; +} + +template +template +void +Matrix33::multVecMatrix(const Vec2 &src, Vec2 &dst) const +{ + S a, b, w; + + a = src[0] * x[0][0] + src[1] * x[1][0] + x[2][0]; + b = src[0] * x[0][1] + src[1] * x[1][1] + x[2][1]; + w = src[0] * x[0][2] + src[1] * x[1][2] + x[2][2]; + + dst.x = a / w; + dst.y = b / w; +} + +template +template +void +Matrix33::multDirMatrix(const Vec2 &src, Vec2 &dst) const +{ + S a, b; + + a = src[0] * x[0][0] + src[1] * x[1][0]; + b = src[0] * x[0][1] + src[1] * x[1][1]; + + dst.x = a; + dst.y = b; +} + +template +const Matrix33 & +Matrix33::operator /= (T a) +{ + x[0][0] /= a; + x[0][1] /= a; + x[0][2] /= a; + x[1][0] /= a; + x[1][1] /= a; + x[1][2] /= a; + x[2][0] /= a; + x[2][1] /= a; + x[2][2] /= a; + + return *this; +} + +template +Matrix33 +Matrix33::operator / (T a) const +{ + return Matrix33 (x[0][0] / a, + x[0][1] / a, + x[0][2] / a, + x[1][0] / a, + x[1][1] / a, + x[1][2] / a, + x[2][0] / a, + x[2][1] / a, + x[2][2] / a); +} + +template +const Matrix33 & +Matrix33::transpose () +{ + Matrix33 tmp (x[0][0], + x[1][0], + x[2][0], + x[0][1], + x[1][1], + x[2][1], + x[0][2], + x[1][2], + x[2][2]); + *this = tmp; + return *this; +} + +template +Matrix33 +Matrix33::transposed () const +{ + return Matrix33 (x[0][0], + x[1][0], + x[2][0], + x[0][1], + x[1][1], + x[2][1], + x[0][2], + x[1][2], + x[2][2]); +} + +template +const Matrix33 & +Matrix33::gjInvert (bool singExc) throw (IEX_NAMESPACE::MathExc) +{ + *this = gjInverse (singExc); + return *this; +} + +template +Matrix33 +Matrix33::gjInverse (bool singExc) const throw (IEX_NAMESPACE::MathExc) +{ + int i, j, k; + Matrix33 s; + Matrix33 t (*this); + + // Forward elimination + + for (i = 0; i < 2 ; i++) + { + int pivot = i; + + T pivotsize = t[i][i]; + + if (pivotsize < 0) + pivotsize = -pivotsize; + + for (j = i + 1; j < 3; j++) + { + T tmp = t[j][i]; + + if (tmp < 0) + tmp = -tmp; + + if (tmp > pivotsize) + { + pivot = j; + pivotsize = tmp; + } + } + + if (pivotsize == 0) + { + if (singExc) + throw ::IMATH_INTERNAL_NAMESPACE::SingMatrixExc ("Cannot invert singular matrix."); + + return Matrix33(); + } + + if (pivot != i) + { + for (j = 0; j < 3; j++) + { + T tmp; + + tmp = t[i][j]; + t[i][j] = t[pivot][j]; + t[pivot][j] = tmp; + + tmp = s[i][j]; + s[i][j] = s[pivot][j]; + s[pivot][j] = tmp; + } + } + + for (j = i + 1; j < 3; j++) + { + T f = t[j][i] / t[i][i]; + + for (k = 0; k < 3; k++) + { + t[j][k] -= f * t[i][k]; + s[j][k] -= f * s[i][k]; + } + } + } + + // Backward substitution + + for (i = 2; i >= 0; --i) + { + T f; + + if ((f = t[i][i]) == 0) + { + if (singExc) + throw ::IMATH_INTERNAL_NAMESPACE::SingMatrixExc ("Cannot invert singular matrix."); + + return Matrix33(); + } + + for (j = 0; j < 3; j++) + { + t[i][j] /= f; + s[i][j] /= f; + } + + for (j = 0; j < i; j++) + { + f = t[j][i]; + + for (k = 0; k < 3; k++) + { + t[j][k] -= f * t[i][k]; + s[j][k] -= f * s[i][k]; + } + } + } + + return s; +} + +template +const Matrix33 & +Matrix33::invert (bool singExc) throw (IEX_NAMESPACE::MathExc) +{ + *this = inverse (singExc); + return *this; +} + +template +Matrix33 +Matrix33::inverse (bool singExc) const throw (IEX_NAMESPACE::MathExc) +{ + if (x[0][2] != 0 || x[1][2] != 0 || x[2][2] != 1) + { + Matrix33 s (x[1][1] * x[2][2] - x[2][1] * x[1][2], + x[2][1] * x[0][2] - x[0][1] * x[2][2], + x[0][1] * x[1][2] - x[1][1] * x[0][2], + + x[2][0] * x[1][2] - x[1][0] * x[2][2], + x[0][0] * x[2][2] - x[2][0] * x[0][2], + x[1][0] * x[0][2] - x[0][0] * x[1][2], + + x[1][0] * x[2][1] - x[2][0] * x[1][1], + x[2][0] * x[0][1] - x[0][0] * x[2][1], + x[0][0] * x[1][1] - x[1][0] * x[0][1]); + + T r = x[0][0] * s[0][0] + x[0][1] * s[1][0] + x[0][2] * s[2][0]; + + if (IMATH_INTERNAL_NAMESPACE::abs (r) >= 1) + { + for (int i = 0; i < 3; ++i) + { + for (int j = 0; j < 3; ++j) + { + s[i][j] /= r; + } + } + } + else + { + T mr = IMATH_INTERNAL_NAMESPACE::abs (r) / limits::smallest(); + + for (int i = 0; i < 3; ++i) + { + for (int j = 0; j < 3; ++j) + { + if (mr > IMATH_INTERNAL_NAMESPACE::abs (s[i][j])) + { + s[i][j] /= r; + } + else + { + if (singExc) + throw SingMatrixExc ("Cannot invert " + "singular matrix."); + return Matrix33(); + } + } + } + } + + return s; + } + else + { + Matrix33 s ( x[1][1], + -x[0][1], + 0, + + -x[1][0], + x[0][0], + 0, + + 0, + 0, + 1); + + T r = x[0][0] * x[1][1] - x[1][0] * x[0][1]; + + if (IMATH_INTERNAL_NAMESPACE::abs (r) >= 1) + { + for (int i = 0; i < 2; ++i) + { + for (int j = 0; j < 2; ++j) + { + s[i][j] /= r; + } + } + } + else + { + T mr = IMATH_INTERNAL_NAMESPACE::abs (r) / limits::smallest(); + + for (int i = 0; i < 2; ++i) + { + for (int j = 0; j < 2; ++j) + { + if (mr > IMATH_INTERNAL_NAMESPACE::abs (s[i][j])) + { + s[i][j] /= r; + } + else + { + if (singExc) + throw SingMatrixExc ("Cannot invert " + "singular matrix."); + return Matrix33(); + } + } + } + } + + s[2][0] = -x[2][0] * s[0][0] - x[2][1] * s[1][0]; + s[2][1] = -x[2][0] * s[0][1] - x[2][1] * s[1][1]; + + return s; + } +} + +template +inline T +Matrix33::minorOf (const int r, const int c) const +{ + int r0 = 0 + (r < 1 ? 1 : 0); + int r1 = 1 + (r < 2 ? 1 : 0); + int c0 = 0 + (c < 1 ? 1 : 0); + int c1 = 1 + (c < 2 ? 1 : 0); + + return x[r0][c0]*x[r1][c1] - x[r1][c0]*x[r0][c1]; +} + +template +inline T +Matrix33::fastMinor( const int r0, const int r1, + const int c0, const int c1) const +{ + return x[r0][c0]*x[r1][c1] - x[r0][c1]*x[r1][c0]; +} + +template +inline T +Matrix33::determinant () const +{ + return x[0][0]*(x[1][1]*x[2][2] - x[1][2]*x[2][1]) + + x[0][1]*(x[1][2]*x[2][0] - x[1][0]*x[2][2]) + + x[0][2]*(x[1][0]*x[2][1] - x[1][1]*x[2][0]); +} + +template +template +const Matrix33 & +Matrix33::setRotation (S r) +{ + S cos_r, sin_r; + + cos_r = Math::cos (r); + sin_r = Math::sin (r); + + x[0][0] = cos_r; + x[0][1] = sin_r; + x[0][2] = 0; + + x[1][0] = -sin_r; + x[1][1] = cos_r; + x[1][2] = 0; + + x[2][0] = 0; + x[2][1] = 0; + x[2][2] = 1; + + return *this; +} + +template +template +const Matrix33 & +Matrix33::rotate (S r) +{ + *this *= Matrix33().setRotation (r); + return *this; +} + +template +const Matrix33 & +Matrix33::setScale (T s) +{ + memset (x, 0, sizeof (x)); + x[0][0] = s; + x[1][1] = s; + x[2][2] = 1; + + return *this; +} + +template +template +const Matrix33 & +Matrix33::setScale (const Vec2 &s) +{ + memset (x, 0, sizeof (x)); + x[0][0] = s[0]; + x[1][1] = s[1]; + x[2][2] = 1; + + return *this; +} + +template +template +const Matrix33 & +Matrix33::scale (const Vec2 &s) +{ + x[0][0] *= s[0]; + x[0][1] *= s[0]; + x[0][2] *= s[0]; + + x[1][0] *= s[1]; + x[1][1] *= s[1]; + x[1][2] *= s[1]; + + return *this; +} + +template +template +const Matrix33 & +Matrix33::setTranslation (const Vec2 &t) +{ + x[0][0] = 1; + x[0][1] = 0; + x[0][2] = 0; + + x[1][0] = 0; + x[1][1] = 1; + x[1][2] = 0; + + x[2][0] = t[0]; + x[2][1] = t[1]; + x[2][2] = 1; + + return *this; +} + +template +inline Vec2 +Matrix33::translation () const +{ + return Vec2 (x[2][0], x[2][1]); +} + +template +template +const Matrix33 & +Matrix33::translate (const Vec2 &t) +{ + x[2][0] += t[0] * x[0][0] + t[1] * x[1][0]; + x[2][1] += t[0] * x[0][1] + t[1] * x[1][1]; + x[2][2] += t[0] * x[0][2] + t[1] * x[1][2]; + + return *this; +} + +template +template +const Matrix33 & +Matrix33::setShear (const S &xy) +{ + x[0][0] = 1; + x[0][1] = 0; + x[0][2] = 0; + + x[1][0] = xy; + x[1][1] = 1; + x[1][2] = 0; + + x[2][0] = 0; + x[2][1] = 0; + x[2][2] = 1; + + return *this; +} + +template +template +const Matrix33 & +Matrix33::setShear (const Vec2 &h) +{ + x[0][0] = 1; + x[0][1] = h[1]; + x[0][2] = 0; + + x[1][0] = h[0]; + x[1][1] = 1; + x[1][2] = 0; + + x[2][0] = 0; + x[2][1] = 0; + x[2][2] = 1; + + return *this; +} + +template +template +const Matrix33 & +Matrix33::shear (const S &xy) +{ + // + // In this case, we don't need a temp. copy of the matrix + // because we never use a value on the RHS after we've + // changed it on the LHS. + // + + x[1][0] += xy * x[0][0]; + x[1][1] += xy * x[0][1]; + x[1][2] += xy * x[0][2]; + + return *this; +} + +template +template +const Matrix33 & +Matrix33::shear (const Vec2 &h) +{ + Matrix33 P (*this); + + x[0][0] = P[0][0] + h[1] * P[1][0]; + x[0][1] = P[0][1] + h[1] * P[1][1]; + x[0][2] = P[0][2] + h[1] * P[1][2]; + + x[1][0] = P[1][0] + h[0] * P[0][0]; + x[1][1] = P[1][1] + h[0] * P[0][1]; + x[1][2] = P[1][2] + h[0] * P[0][2]; + + return *this; +} + + +//--------------------------- +// Implementation of Matrix44 +//--------------------------- + +template +inline T * +Matrix44::operator [] (int i) +{ + return x[i]; +} + +template +inline const T * +Matrix44::operator [] (int i) const +{ + return x[i]; +} + +template +inline +Matrix44::Matrix44 () +{ + memset (x, 0, sizeof (x)); + x[0][0] = 1; + x[1][1] = 1; + x[2][2] = 1; + x[3][3] = 1; +} + +template +inline +Matrix44::Matrix44 (T a) +{ + x[0][0] = a; + x[0][1] = a; + x[0][2] = a; + x[0][3] = a; + x[1][0] = a; + x[1][1] = a; + x[1][2] = a; + x[1][3] = a; + x[2][0] = a; + x[2][1] = a; + x[2][2] = a; + x[2][3] = a; + x[3][0] = a; + x[3][1] = a; + x[3][2] = a; + x[3][3] = a; +} + +template +inline +Matrix44::Matrix44 (const T a[4][4]) +{ + memcpy (x, a, sizeof (x)); +} + +template +inline +Matrix44::Matrix44 (T a, T b, T c, T d, T e, T f, T g, T h, + T i, T j, T k, T l, T m, T n, T o, T p) +{ + x[0][0] = a; + x[0][1] = b; + x[0][2] = c; + x[0][3] = d; + x[1][0] = e; + x[1][1] = f; + x[1][2] = g; + x[1][3] = h; + x[2][0] = i; + x[2][1] = j; + x[2][2] = k; + x[2][3] = l; + x[3][0] = m; + x[3][1] = n; + x[3][2] = o; + x[3][3] = p; +} + + +template +inline +Matrix44::Matrix44 (Matrix33 r, Vec3 t) +{ + x[0][0] = r[0][0]; + x[0][1] = r[0][1]; + x[0][2] = r[0][2]; + x[0][3] = 0; + x[1][0] = r[1][0]; + x[1][1] = r[1][1]; + x[1][2] = r[1][2]; + x[1][3] = 0; + x[2][0] = r[2][0]; + x[2][1] = r[2][1]; + x[2][2] = r[2][2]; + x[2][3] = 0; + x[3][0] = t[0]; + x[3][1] = t[1]; + x[3][2] = t[2]; + x[3][3] = 1; +} + +template +inline +Matrix44::Matrix44 (const Matrix44 &v) +{ + x[0][0] = v.x[0][0]; + x[0][1] = v.x[0][1]; + x[0][2] = v.x[0][2]; + x[0][3] = v.x[0][3]; + x[1][0] = v.x[1][0]; + x[1][1] = v.x[1][1]; + x[1][2] = v.x[1][2]; + x[1][3] = v.x[1][3]; + x[2][0] = v.x[2][0]; + x[2][1] = v.x[2][1]; + x[2][2] = v.x[2][2]; + x[2][3] = v.x[2][3]; + x[3][0] = v.x[3][0]; + x[3][1] = v.x[3][1]; + x[3][2] = v.x[3][2]; + x[3][3] = v.x[3][3]; +} + +template +template +inline +Matrix44::Matrix44 (const Matrix44 &v) +{ + x[0][0] = T (v.x[0][0]); + x[0][1] = T (v.x[0][1]); + x[0][2] = T (v.x[0][2]); + x[0][3] = T (v.x[0][3]); + x[1][0] = T (v.x[1][0]); + x[1][1] = T (v.x[1][1]); + x[1][2] = T (v.x[1][2]); + x[1][3] = T (v.x[1][3]); + x[2][0] = T (v.x[2][0]); + x[2][1] = T (v.x[2][1]); + x[2][2] = T (v.x[2][2]); + x[2][3] = T (v.x[2][3]); + x[3][0] = T (v.x[3][0]); + x[3][1] = T (v.x[3][1]); + x[3][2] = T (v.x[3][2]); + x[3][3] = T (v.x[3][3]); +} + +template +inline const Matrix44 & +Matrix44::operator = (const Matrix44 &v) +{ + x[0][0] = v.x[0][0]; + x[0][1] = v.x[0][1]; + x[0][2] = v.x[0][2]; + x[0][3] = v.x[0][3]; + x[1][0] = v.x[1][0]; + x[1][1] = v.x[1][1]; + x[1][2] = v.x[1][2]; + x[1][3] = v.x[1][3]; + x[2][0] = v.x[2][0]; + x[2][1] = v.x[2][1]; + x[2][2] = v.x[2][2]; + x[2][3] = v.x[2][3]; + x[3][0] = v.x[3][0]; + x[3][1] = v.x[3][1]; + x[3][2] = v.x[3][2]; + x[3][3] = v.x[3][3]; + return *this; +} + +template +inline const Matrix44 & +Matrix44::operator = (T a) +{ + x[0][0] = a; + x[0][1] = a; + x[0][2] = a; + x[0][3] = a; + x[1][0] = a; + x[1][1] = a; + x[1][2] = a; + x[1][3] = a; + x[2][0] = a; + x[2][1] = a; + x[2][2] = a; + x[2][3] = a; + x[3][0] = a; + x[3][1] = a; + x[3][2] = a; + x[3][3] = a; + return *this; +} + +template +inline T * +Matrix44::getValue () +{ + return (T *) &x[0][0]; +} + +template +inline const T * +Matrix44::getValue () const +{ + return (const T *) &x[0][0]; +} + +template +template +inline void +Matrix44::getValue (Matrix44 &v) const +{ + if (isSameType::value) + { + memcpy (v.x, x, sizeof (x)); + } + else + { + v.x[0][0] = x[0][0]; + v.x[0][1] = x[0][1]; + v.x[0][2] = x[0][2]; + v.x[0][3] = x[0][3]; + v.x[1][0] = x[1][0]; + v.x[1][1] = x[1][1]; + v.x[1][2] = x[1][2]; + v.x[1][3] = x[1][3]; + v.x[2][0] = x[2][0]; + v.x[2][1] = x[2][1]; + v.x[2][2] = x[2][2]; + v.x[2][3] = x[2][3]; + v.x[3][0] = x[3][0]; + v.x[3][1] = x[3][1]; + v.x[3][2] = x[3][2]; + v.x[3][3] = x[3][3]; + } +} + +template +template +inline Matrix44 & +Matrix44::setValue (const Matrix44 &v) +{ + if (isSameType::value) + { + memcpy (x, v.x, sizeof (x)); + } + else + { + x[0][0] = v.x[0][0]; + x[0][1] = v.x[0][1]; + x[0][2] = v.x[0][2]; + x[0][3] = v.x[0][3]; + x[1][0] = v.x[1][0]; + x[1][1] = v.x[1][1]; + x[1][2] = v.x[1][2]; + x[1][3] = v.x[1][3]; + x[2][0] = v.x[2][0]; + x[2][1] = v.x[2][1]; + x[2][2] = v.x[2][2]; + x[2][3] = v.x[2][3]; + x[3][0] = v.x[3][0]; + x[3][1] = v.x[3][1]; + x[3][2] = v.x[3][2]; + x[3][3] = v.x[3][3]; + } + + return *this; +} + +template +template +inline Matrix44 & +Matrix44::setTheMatrix (const Matrix44 &v) +{ + if (isSameType::value) + { + memcpy (x, v.x, sizeof (x)); + } + else + { + x[0][0] = v.x[0][0]; + x[0][1] = v.x[0][1]; + x[0][2] = v.x[0][2]; + x[0][3] = v.x[0][3]; + x[1][0] = v.x[1][0]; + x[1][1] = v.x[1][1]; + x[1][2] = v.x[1][2]; + x[1][3] = v.x[1][3]; + x[2][0] = v.x[2][0]; + x[2][1] = v.x[2][1]; + x[2][2] = v.x[2][2]; + x[2][3] = v.x[2][3]; + x[3][0] = v.x[3][0]; + x[3][1] = v.x[3][1]; + x[3][2] = v.x[3][2]; + x[3][3] = v.x[3][3]; + } + + return *this; +} + +template +inline void +Matrix44::makeIdentity() +{ + memset (x, 0, sizeof (x)); + x[0][0] = 1; + x[1][1] = 1; + x[2][2] = 1; + x[3][3] = 1; +} + +template +bool +Matrix44::operator == (const Matrix44 &v) const +{ + return x[0][0] == v.x[0][0] && + x[0][1] == v.x[0][1] && + x[0][2] == v.x[0][2] && + x[0][3] == v.x[0][3] && + x[1][0] == v.x[1][0] && + x[1][1] == v.x[1][1] && + x[1][2] == v.x[1][2] && + x[1][3] == v.x[1][3] && + x[2][0] == v.x[2][0] && + x[2][1] == v.x[2][1] && + x[2][2] == v.x[2][2] && + x[2][3] == v.x[2][3] && + x[3][0] == v.x[3][0] && + x[3][1] == v.x[3][1] && + x[3][2] == v.x[3][2] && + x[3][3] == v.x[3][3]; +} + +template +bool +Matrix44::operator != (const Matrix44 &v) const +{ + return x[0][0] != v.x[0][0] || + x[0][1] != v.x[0][1] || + x[0][2] != v.x[0][2] || + x[0][3] != v.x[0][3] || + x[1][0] != v.x[1][0] || + x[1][1] != v.x[1][1] || + x[1][2] != v.x[1][2] || + x[1][3] != v.x[1][3] || + x[2][0] != v.x[2][0] || + x[2][1] != v.x[2][1] || + x[2][2] != v.x[2][2] || + x[2][3] != v.x[2][3] || + x[3][0] != v.x[3][0] || + x[3][1] != v.x[3][1] || + x[3][2] != v.x[3][2] || + x[3][3] != v.x[3][3]; +} + +template +bool +Matrix44::equalWithAbsError (const Matrix44 &m, T e) const +{ + for (int i = 0; i < 4; i++) + for (int j = 0; j < 4; j++) + if (!IMATH_INTERNAL_NAMESPACE::equalWithAbsError ((*this)[i][j], m[i][j], e)) + return false; + + return true; +} + +template +bool +Matrix44::equalWithRelError (const Matrix44 &m, T e) const +{ + for (int i = 0; i < 4; i++) + for (int j = 0; j < 4; j++) + if (!IMATH_INTERNAL_NAMESPACE::equalWithRelError ((*this)[i][j], m[i][j], e)) + return false; + + return true; +} + +template +const Matrix44 & +Matrix44::operator += (const Matrix44 &v) +{ + x[0][0] += v.x[0][0]; + x[0][1] += v.x[0][1]; + x[0][2] += v.x[0][2]; + x[0][3] += v.x[0][3]; + x[1][0] += v.x[1][0]; + x[1][1] += v.x[1][1]; + x[1][2] += v.x[1][2]; + x[1][3] += v.x[1][3]; + x[2][0] += v.x[2][0]; + x[2][1] += v.x[2][1]; + x[2][2] += v.x[2][2]; + x[2][3] += v.x[2][3]; + x[3][0] += v.x[3][0]; + x[3][1] += v.x[3][1]; + x[3][2] += v.x[3][2]; + x[3][3] += v.x[3][3]; + + return *this; +} + +template +const Matrix44 & +Matrix44::operator += (T a) +{ + x[0][0] += a; + x[0][1] += a; + x[0][2] += a; + x[0][3] += a; + x[1][0] += a; + x[1][1] += a; + x[1][2] += a; + x[1][3] += a; + x[2][0] += a; + x[2][1] += a; + x[2][2] += a; + x[2][3] += a; + x[3][0] += a; + x[3][1] += a; + x[3][2] += a; + x[3][3] += a; + + return *this; +} + +template +Matrix44 +Matrix44::operator + (const Matrix44 &v) const +{ + return Matrix44 (x[0][0] + v.x[0][0], + x[0][1] + v.x[0][1], + x[0][2] + v.x[0][2], + x[0][3] + v.x[0][3], + x[1][0] + v.x[1][0], + x[1][1] + v.x[1][1], + x[1][2] + v.x[1][2], + x[1][3] + v.x[1][3], + x[2][0] + v.x[2][0], + x[2][1] + v.x[2][1], + x[2][2] + v.x[2][2], + x[2][3] + v.x[2][3], + x[3][0] + v.x[3][0], + x[3][1] + v.x[3][1], + x[3][2] + v.x[3][2], + x[3][3] + v.x[3][3]); +} + +template +const Matrix44 & +Matrix44::operator -= (const Matrix44 &v) +{ + x[0][0] -= v.x[0][0]; + x[0][1] -= v.x[0][1]; + x[0][2] -= v.x[0][2]; + x[0][3] -= v.x[0][3]; + x[1][0] -= v.x[1][0]; + x[1][1] -= v.x[1][1]; + x[1][2] -= v.x[1][2]; + x[1][3] -= v.x[1][3]; + x[2][0] -= v.x[2][0]; + x[2][1] -= v.x[2][1]; + x[2][2] -= v.x[2][2]; + x[2][3] -= v.x[2][3]; + x[3][0] -= v.x[3][0]; + x[3][1] -= v.x[3][1]; + x[3][2] -= v.x[3][2]; + x[3][3] -= v.x[3][3]; + + return *this; +} + +template +const Matrix44 & +Matrix44::operator -= (T a) +{ + x[0][0] -= a; + x[0][1] -= a; + x[0][2] -= a; + x[0][3] -= a; + x[1][0] -= a; + x[1][1] -= a; + x[1][2] -= a; + x[1][3] -= a; + x[2][0] -= a; + x[2][1] -= a; + x[2][2] -= a; + x[2][3] -= a; + x[3][0] -= a; + x[3][1] -= a; + x[3][2] -= a; + x[3][3] -= a; + + return *this; +} + +template +Matrix44 +Matrix44::operator - (const Matrix44 &v) const +{ + return Matrix44 (x[0][0] - v.x[0][0], + x[0][1] - v.x[0][1], + x[0][2] - v.x[0][2], + x[0][3] - v.x[0][3], + x[1][0] - v.x[1][0], + x[1][1] - v.x[1][1], + x[1][2] - v.x[1][2], + x[1][3] - v.x[1][3], + x[2][0] - v.x[2][0], + x[2][1] - v.x[2][1], + x[2][2] - v.x[2][2], + x[2][3] - v.x[2][3], + x[3][0] - v.x[3][0], + x[3][1] - v.x[3][1], + x[3][2] - v.x[3][2], + x[3][3] - v.x[3][3]); +} + +template +Matrix44 +Matrix44::operator - () const +{ + return Matrix44 (-x[0][0], + -x[0][1], + -x[0][2], + -x[0][3], + -x[1][0], + -x[1][1], + -x[1][2], + -x[1][3], + -x[2][0], + -x[2][1], + -x[2][2], + -x[2][3], + -x[3][0], + -x[3][1], + -x[3][2], + -x[3][3]); +} + +template +const Matrix44 & +Matrix44::negate () +{ + x[0][0] = -x[0][0]; + x[0][1] = -x[0][1]; + x[0][2] = -x[0][2]; + x[0][3] = -x[0][3]; + x[1][0] = -x[1][0]; + x[1][1] = -x[1][1]; + x[1][2] = -x[1][2]; + x[1][3] = -x[1][3]; + x[2][0] = -x[2][0]; + x[2][1] = -x[2][1]; + x[2][2] = -x[2][2]; + x[2][3] = -x[2][3]; + x[3][0] = -x[3][0]; + x[3][1] = -x[3][1]; + x[3][2] = -x[3][2]; + x[3][3] = -x[3][3]; + + return *this; +} + +template +const Matrix44 & +Matrix44::operator *= (T a) +{ + x[0][0] *= a; + x[0][1] *= a; + x[0][2] *= a; + x[0][3] *= a; + x[1][0] *= a; + x[1][1] *= a; + x[1][2] *= a; + x[1][3] *= a; + x[2][0] *= a; + x[2][1] *= a; + x[2][2] *= a; + x[2][3] *= a; + x[3][0] *= a; + x[3][1] *= a; + x[3][2] *= a; + x[3][3] *= a; + + return *this; +} + +template +Matrix44 +Matrix44::operator * (T a) const +{ + return Matrix44 (x[0][0] * a, + x[0][1] * a, + x[0][2] * a, + x[0][3] * a, + x[1][0] * a, + x[1][1] * a, + x[1][2] * a, + x[1][3] * a, + x[2][0] * a, + x[2][1] * a, + x[2][2] * a, + x[2][3] * a, + x[3][0] * a, + x[3][1] * a, + x[3][2] * a, + x[3][3] * a); +} + +template +inline Matrix44 +operator * (T a, const Matrix44 &v) +{ + return v * a; +} + +template +inline const Matrix44 & +Matrix44::operator *= (const Matrix44 &v) +{ + Matrix44 tmp (T (0)); + + multiply (*this, v, tmp); + *this = tmp; + return *this; +} + +template +inline Matrix44 +Matrix44::operator * (const Matrix44 &v) const +{ + Matrix44 tmp (T (0)); + + multiply (*this, v, tmp); + return tmp; +} + +template +void +Matrix44::multiply (const Matrix44 &a, + const Matrix44 &b, + Matrix44 &c) +{ + register const T * IMATH_RESTRICT ap = &a.x[0][0]; + register const T * IMATH_RESTRICT bp = &b.x[0][0]; + register T * IMATH_RESTRICT cp = &c.x[0][0]; + + register T a0, a1, a2, a3; + + a0 = ap[0]; + a1 = ap[1]; + a2 = ap[2]; + a3 = ap[3]; + + cp[0] = a0 * bp[0] + a1 * bp[4] + a2 * bp[8] + a3 * bp[12]; + cp[1] = a0 * bp[1] + a1 * bp[5] + a2 * bp[9] + a3 * bp[13]; + cp[2] = a0 * bp[2] + a1 * bp[6] + a2 * bp[10] + a3 * bp[14]; + cp[3] = a0 * bp[3] + a1 * bp[7] + a2 * bp[11] + a3 * bp[15]; + + a0 = ap[4]; + a1 = ap[5]; + a2 = ap[6]; + a3 = ap[7]; + + cp[4] = a0 * bp[0] + a1 * bp[4] + a2 * bp[8] + a3 * bp[12]; + cp[5] = a0 * bp[1] + a1 * bp[5] + a2 * bp[9] + a3 * bp[13]; + cp[6] = a0 * bp[2] + a1 * bp[6] + a2 * bp[10] + a3 * bp[14]; + cp[7] = a0 * bp[3] + a1 * bp[7] + a2 * bp[11] + a3 * bp[15]; + + a0 = ap[8]; + a1 = ap[9]; + a2 = ap[10]; + a3 = ap[11]; + + cp[8] = a0 * bp[0] + a1 * bp[4] + a2 * bp[8] + a3 * bp[12]; + cp[9] = a0 * bp[1] + a1 * bp[5] + a2 * bp[9] + a3 * bp[13]; + cp[10] = a0 * bp[2] + a1 * bp[6] + a2 * bp[10] + a3 * bp[14]; + cp[11] = a0 * bp[3] + a1 * bp[7] + a2 * bp[11] + a3 * bp[15]; + + a0 = ap[12]; + a1 = ap[13]; + a2 = ap[14]; + a3 = ap[15]; + + cp[12] = a0 * bp[0] + a1 * bp[4] + a2 * bp[8] + a3 * bp[12]; + cp[13] = a0 * bp[1] + a1 * bp[5] + a2 * bp[9] + a3 * bp[13]; + cp[14] = a0 * bp[2] + a1 * bp[6] + a2 * bp[10] + a3 * bp[14]; + cp[15] = a0 * bp[3] + a1 * bp[7] + a2 * bp[11] + a3 * bp[15]; +} + +template template +void +Matrix44::multVecMatrix(const Vec3 &src, Vec3 &dst) const +{ + S a, b, c, w; + + a = src[0] * x[0][0] + src[1] * x[1][0] + src[2] * x[2][0] + x[3][0]; + b = src[0] * x[0][1] + src[1] * x[1][1] + src[2] * x[2][1] + x[3][1]; + c = src[0] * x[0][2] + src[1] * x[1][2] + src[2] * x[2][2] + x[3][2]; + w = src[0] * x[0][3] + src[1] * x[1][3] + src[2] * x[2][3] + x[3][3]; + + dst.x = a / w; + dst.y = b / w; + dst.z = c / w; +} + +template template +void +Matrix44::multDirMatrix(const Vec3 &src, Vec3 &dst) const +{ + S a, b, c; + + a = src[0] * x[0][0] + src[1] * x[1][0] + src[2] * x[2][0]; + b = src[0] * x[0][1] + src[1] * x[1][1] + src[2] * x[2][1]; + c = src[0] * x[0][2] + src[1] * x[1][2] + src[2] * x[2][2]; + + dst.x = a; + dst.y = b; + dst.z = c; +} + +template +const Matrix44 & +Matrix44::operator /= (T a) +{ + x[0][0] /= a; + x[0][1] /= a; + x[0][2] /= a; + x[0][3] /= a; + x[1][0] /= a; + x[1][1] /= a; + x[1][2] /= a; + x[1][3] /= a; + x[2][0] /= a; + x[2][1] /= a; + x[2][2] /= a; + x[2][3] /= a; + x[3][0] /= a; + x[3][1] /= a; + x[3][2] /= a; + x[3][3] /= a; + + return *this; +} + +template +Matrix44 +Matrix44::operator / (T a) const +{ + return Matrix44 (x[0][0] / a, + x[0][1] / a, + x[0][2] / a, + x[0][3] / a, + x[1][0] / a, + x[1][1] / a, + x[1][2] / a, + x[1][3] / a, + x[2][0] / a, + x[2][1] / a, + x[2][2] / a, + x[2][3] / a, + x[3][0] / a, + x[3][1] / a, + x[3][2] / a, + x[3][3] / a); +} + +template +const Matrix44 & +Matrix44::transpose () +{ + Matrix44 tmp (x[0][0], + x[1][0], + x[2][0], + x[3][0], + x[0][1], + x[1][1], + x[2][1], + x[3][1], + x[0][2], + x[1][2], + x[2][2], + x[3][2], + x[0][3], + x[1][3], + x[2][3], + x[3][3]); + *this = tmp; + return *this; +} + +template +Matrix44 +Matrix44::transposed () const +{ + return Matrix44 (x[0][0], + x[1][0], + x[2][0], + x[3][0], + x[0][1], + x[1][1], + x[2][1], + x[3][1], + x[0][2], + x[1][2], + x[2][2], + x[3][2], + x[0][3], + x[1][3], + x[2][3], + x[3][3]); +} + +template +const Matrix44 & +Matrix44::gjInvert (bool singExc) throw (IEX_NAMESPACE::MathExc) +{ + *this = gjInverse (singExc); + return *this; +} + +template +Matrix44 +Matrix44::gjInverse (bool singExc) const throw (IEX_NAMESPACE::MathExc) +{ + int i, j, k; + Matrix44 s; + Matrix44 t (*this); + + // Forward elimination + + for (i = 0; i < 3 ; i++) + { + int pivot = i; + + T pivotsize = t[i][i]; + + if (pivotsize < 0) + pivotsize = -pivotsize; + + for (j = i + 1; j < 4; j++) + { + T tmp = t[j][i]; + + if (tmp < 0) + tmp = -tmp; + + if (tmp > pivotsize) + { + pivot = j; + pivotsize = tmp; + } + } + + if (pivotsize == 0) + { + if (singExc) + throw ::IMATH_INTERNAL_NAMESPACE::SingMatrixExc ("Cannot invert singular matrix."); + + return Matrix44(); + } + + if (pivot != i) + { + for (j = 0; j < 4; j++) + { + T tmp; + + tmp = t[i][j]; + t[i][j] = t[pivot][j]; + t[pivot][j] = tmp; + + tmp = s[i][j]; + s[i][j] = s[pivot][j]; + s[pivot][j] = tmp; + } + } + + for (j = i + 1; j < 4; j++) + { + T f = t[j][i] / t[i][i]; + + for (k = 0; k < 4; k++) + { + t[j][k] -= f * t[i][k]; + s[j][k] -= f * s[i][k]; + } + } + } + + // Backward substitution + + for (i = 3; i >= 0; --i) + { + T f; + + if ((f = t[i][i]) == 0) + { + if (singExc) + throw ::IMATH_INTERNAL_NAMESPACE::SingMatrixExc ("Cannot invert singular matrix."); + + return Matrix44(); + } + + for (j = 0; j < 4; j++) + { + t[i][j] /= f; + s[i][j] /= f; + } + + for (j = 0; j < i; j++) + { + f = t[j][i]; + + for (k = 0; k < 4; k++) + { + t[j][k] -= f * t[i][k]; + s[j][k] -= f * s[i][k]; + } + } + } + + return s; +} + +template +const Matrix44 & +Matrix44::invert (bool singExc) throw (IEX_NAMESPACE::MathExc) +{ + *this = inverse (singExc); + return *this; +} + +template +Matrix44 +Matrix44::inverse (bool singExc) const throw (IEX_NAMESPACE::MathExc) +{ + if (x[0][3] != 0 || x[1][3] != 0 || x[2][3] != 0 || x[3][3] != 1) + return gjInverse(singExc); + + Matrix44 s (x[1][1] * x[2][2] - x[2][1] * x[1][2], + x[2][1] * x[0][2] - x[0][1] * x[2][2], + x[0][1] * x[1][2] - x[1][1] * x[0][2], + 0, + + x[2][0] * x[1][2] - x[1][0] * x[2][2], + x[0][0] * x[2][2] - x[2][0] * x[0][2], + x[1][0] * x[0][2] - x[0][0] * x[1][2], + 0, + + x[1][0] * x[2][1] - x[2][0] * x[1][1], + x[2][0] * x[0][1] - x[0][0] * x[2][1], + x[0][0] * x[1][1] - x[1][0] * x[0][1], + 0, + + 0, + 0, + 0, + 1); + + T r = x[0][0] * s[0][0] + x[0][1] * s[1][0] + x[0][2] * s[2][0]; + + if (IMATH_INTERNAL_NAMESPACE::abs (r) >= 1) + { + for (int i = 0; i < 3; ++i) + { + for (int j = 0; j < 3; ++j) + { + s[i][j] /= r; + } + } + } + else + { + T mr = IMATH_INTERNAL_NAMESPACE::abs (r) / limits::smallest(); + + for (int i = 0; i < 3; ++i) + { + for (int j = 0; j < 3; ++j) + { + if (mr > IMATH_INTERNAL_NAMESPACE::abs (s[i][j])) + { + s[i][j] /= r; + } + else + { + if (singExc) + throw SingMatrixExc ("Cannot invert singular matrix."); + + return Matrix44(); + } + } + } + } + + s[3][0] = -x[3][0] * s[0][0] - x[3][1] * s[1][0] - x[3][2] * s[2][0]; + s[3][1] = -x[3][0] * s[0][1] - x[3][1] * s[1][1] - x[3][2] * s[2][1]; + s[3][2] = -x[3][0] * s[0][2] - x[3][1] * s[1][2] - x[3][2] * s[2][2]; + + return s; +} + +template +inline T +Matrix44::fastMinor( const int r0, const int r1, const int r2, + const int c0, const int c1, const int c2) const +{ + return x[r0][c0] * (x[r1][c1]*x[r2][c2] - x[r1][c2]*x[r2][c1]) + + x[r0][c1] * (x[r1][c2]*x[r2][c0] - x[r1][c0]*x[r2][c2]) + + x[r0][c2] * (x[r1][c0]*x[r2][c1] - x[r1][c1]*x[r2][c0]); +} + +template +inline T +Matrix44::minorOf (const int r, const int c) const +{ + int r0 = 0 + (r < 1 ? 1 : 0); + int r1 = 1 + (r < 2 ? 1 : 0); + int r2 = 2 + (r < 3 ? 1 : 0); + int c0 = 0 + (c < 1 ? 1 : 0); + int c1 = 1 + (c < 2 ? 1 : 0); + int c2 = 2 + (c < 3 ? 1 : 0); + + Matrix33 working (x[r0][c0],x[r1][c0],x[r2][c0], + x[r0][c1],x[r1][c1],x[r2][c1], + x[r0][c2],x[r1][c2],x[r2][c2]); + + return working.determinant(); +} + +template +inline T +Matrix44::determinant () const +{ + T sum = (T)0; + + if (x[0][3] != 0.) sum -= x[0][3] * fastMinor(1,2,3,0,1,2); + if (x[1][3] != 0.) sum += x[1][3] * fastMinor(0,2,3,0,1,2); + if (x[2][3] != 0.) sum -= x[2][3] * fastMinor(0,1,3,0,1,2); + if (x[3][3] != 0.) sum += x[3][3] * fastMinor(0,1,2,0,1,2); + + return sum; +} + +template +template +const Matrix44 & +Matrix44::setEulerAngles (const Vec3& r) +{ + S cos_rz, sin_rz, cos_ry, sin_ry, cos_rx, sin_rx; + + cos_rz = Math::cos (r[2]); + cos_ry = Math::cos (r[1]); + cos_rx = Math::cos (r[0]); + + sin_rz = Math::sin (r[2]); + sin_ry = Math::sin (r[1]); + sin_rx = Math::sin (r[0]); + + x[0][0] = cos_rz * cos_ry; + x[0][1] = sin_rz * cos_ry; + x[0][2] = -sin_ry; + x[0][3] = 0; + + x[1][0] = -sin_rz * cos_rx + cos_rz * sin_ry * sin_rx; + x[1][1] = cos_rz * cos_rx + sin_rz * sin_ry * sin_rx; + x[1][2] = cos_ry * sin_rx; + x[1][3] = 0; + + x[2][0] = sin_rz * sin_rx + cos_rz * sin_ry * cos_rx; + x[2][1] = -cos_rz * sin_rx + sin_rz * sin_ry * cos_rx; + x[2][2] = cos_ry * cos_rx; + x[2][3] = 0; + + x[3][0] = 0; + x[3][1] = 0; + x[3][2] = 0; + x[3][3] = 1; + + return *this; +} + +template +template +const Matrix44 & +Matrix44::setAxisAngle (const Vec3& axis, S angle) +{ + Vec3 unit (axis.normalized()); + S sine = Math::sin (angle); + S cosine = Math::cos (angle); + + x[0][0] = unit[0] * unit[0] * (1 - cosine) + cosine; + x[0][1] = unit[0] * unit[1] * (1 - cosine) + unit[2] * sine; + x[0][2] = unit[0] * unit[2] * (1 - cosine) - unit[1] * sine; + x[0][3] = 0; + + x[1][0] = unit[0] * unit[1] * (1 - cosine) - unit[2] * sine; + x[1][1] = unit[1] * unit[1] * (1 - cosine) + cosine; + x[1][2] = unit[1] * unit[2] * (1 - cosine) + unit[0] * sine; + x[1][3] = 0; + + x[2][0] = unit[0] * unit[2] * (1 - cosine) + unit[1] * sine; + x[2][1] = unit[1] * unit[2] * (1 - cosine) - unit[0] * sine; + x[2][2] = unit[2] * unit[2] * (1 - cosine) + cosine; + x[2][3] = 0; + + x[3][0] = 0; + x[3][1] = 0; + x[3][2] = 0; + x[3][3] = 1; + + return *this; +} + +template +template +const Matrix44 & +Matrix44::rotate (const Vec3 &r) +{ + S cos_rz, sin_rz, cos_ry, sin_ry, cos_rx, sin_rx; + S m00, m01, m02; + S m10, m11, m12; + S m20, m21, m22; + + cos_rz = Math::cos (r[2]); + cos_ry = Math::cos (r[1]); + cos_rx = Math::cos (r[0]); + + sin_rz = Math::sin (r[2]); + sin_ry = Math::sin (r[1]); + sin_rx = Math::sin (r[0]); + + m00 = cos_rz * cos_ry; + m01 = sin_rz * cos_ry; + m02 = -sin_ry; + m10 = -sin_rz * cos_rx + cos_rz * sin_ry * sin_rx; + m11 = cos_rz * cos_rx + sin_rz * sin_ry * sin_rx; + m12 = cos_ry * sin_rx; + m20 = -sin_rz * -sin_rx + cos_rz * sin_ry * cos_rx; + m21 = cos_rz * -sin_rx + sin_rz * sin_ry * cos_rx; + m22 = cos_ry * cos_rx; + + Matrix44 P (*this); + + x[0][0] = P[0][0] * m00 + P[1][0] * m01 + P[2][0] * m02; + x[0][1] = P[0][1] * m00 + P[1][1] * m01 + P[2][1] * m02; + x[0][2] = P[0][2] * m00 + P[1][2] * m01 + P[2][2] * m02; + x[0][3] = P[0][3] * m00 + P[1][3] * m01 + P[2][3] * m02; + + x[1][0] = P[0][0] * m10 + P[1][0] * m11 + P[2][0] * m12; + x[1][1] = P[0][1] * m10 + P[1][1] * m11 + P[2][1] * m12; + x[1][2] = P[0][2] * m10 + P[1][2] * m11 + P[2][2] * m12; + x[1][3] = P[0][3] * m10 + P[1][3] * m11 + P[2][3] * m12; + + x[2][0] = P[0][0] * m20 + P[1][0] * m21 + P[2][0] * m22; + x[2][1] = P[0][1] * m20 + P[1][1] * m21 + P[2][1] * m22; + x[2][2] = P[0][2] * m20 + P[1][2] * m21 + P[2][2] * m22; + x[2][3] = P[0][3] * m20 + P[1][3] * m21 + P[2][3] * m22; + + return *this; +} + +template +const Matrix44 & +Matrix44::setScale (T s) +{ + memset (x, 0, sizeof (x)); + x[0][0] = s; + x[1][1] = s; + x[2][2] = s; + x[3][3] = 1; + + return *this; +} + +template +template +const Matrix44 & +Matrix44::setScale (const Vec3 &s) +{ + memset (x, 0, sizeof (x)); + x[0][0] = s[0]; + x[1][1] = s[1]; + x[2][2] = s[2]; + x[3][3] = 1; + + return *this; +} + +template +template +const Matrix44 & +Matrix44::scale (const Vec3 &s) +{ + x[0][0] *= s[0]; + x[0][1] *= s[0]; + x[0][2] *= s[0]; + x[0][3] *= s[0]; + + x[1][0] *= s[1]; + x[1][1] *= s[1]; + x[1][2] *= s[1]; + x[1][3] *= s[1]; + + x[2][0] *= s[2]; + x[2][1] *= s[2]; + x[2][2] *= s[2]; + x[2][3] *= s[2]; + + return *this; +} + +template +template +const Matrix44 & +Matrix44::setTranslation (const Vec3 &t) +{ + x[0][0] = 1; + x[0][1] = 0; + x[0][2] = 0; + x[0][3] = 0; + + x[1][0] = 0; + x[1][1] = 1; + x[1][2] = 0; + x[1][3] = 0; + + x[2][0] = 0; + x[2][1] = 0; + x[2][2] = 1; + x[2][3] = 0; + + x[3][0] = t[0]; + x[3][1] = t[1]; + x[3][2] = t[2]; + x[3][3] = 1; + + return *this; +} + +template +inline const Vec3 +Matrix44::translation () const +{ + return Vec3 (x[3][0], x[3][1], x[3][2]); +} + +template +template +const Matrix44 & +Matrix44::translate (const Vec3 &t) +{ + x[3][0] += t[0] * x[0][0] + t[1] * x[1][0] + t[2] * x[2][0]; + x[3][1] += t[0] * x[0][1] + t[1] * x[1][1] + t[2] * x[2][1]; + x[3][2] += t[0] * x[0][2] + t[1] * x[1][2] + t[2] * x[2][2]; + x[3][3] += t[0] * x[0][3] + t[1] * x[1][3] + t[2] * x[2][3]; + + return *this; +} + +template +template +const Matrix44 & +Matrix44::setShear (const Vec3 &h) +{ + x[0][0] = 1; + x[0][1] = 0; + x[0][2] = 0; + x[0][3] = 0; + + x[1][0] = h[0]; + x[1][1] = 1; + x[1][2] = 0; + x[1][3] = 0; + + x[2][0] = h[1]; + x[2][1] = h[2]; + x[2][2] = 1; + x[2][3] = 0; + + x[3][0] = 0; + x[3][1] = 0; + x[3][2] = 0; + x[3][3] = 1; + + return *this; +} + +template +template +const Matrix44 & +Matrix44::setShear (const Shear6 &h) +{ + x[0][0] = 1; + x[0][1] = h.yx; + x[0][2] = h.zx; + x[0][3] = 0; + + x[1][0] = h.xy; + x[1][1] = 1; + x[1][2] = h.zy; + x[1][3] = 0; + + x[2][0] = h.xz; + x[2][1] = h.yz; + x[2][2] = 1; + x[2][3] = 0; + + x[3][0] = 0; + x[3][1] = 0; + x[3][2] = 0; + x[3][3] = 1; + + return *this; +} + +template +template +const Matrix44 & +Matrix44::shear (const Vec3 &h) +{ + // + // In this case, we don't need a temp. copy of the matrix + // because we never use a value on the RHS after we've + // changed it on the LHS. + // + + for (int i=0; i < 4; i++) + { + x[2][i] += h[1] * x[0][i] + h[2] * x[1][i]; + x[1][i] += h[0] * x[0][i]; + } + + return *this; +} + +template +template +const Matrix44 & +Matrix44::shear (const Shear6 &h) +{ + Matrix44 P (*this); + + for (int i=0; i < 4; i++) + { + x[0][i] = P[0][i] + h.yx * P[1][i] + h.zx * P[2][i]; + x[1][i] = h.xy * P[0][i] + P[1][i] + h.zy * P[2][i]; + x[2][i] = h.xz * P[0][i] + h.yz * P[1][i] + P[2][i]; + } + + return *this; +} + + +//-------------------------------- +// Implementation of stream output +//-------------------------------- + +template +std::ostream & +operator << (std::ostream &s, const Matrix33 &m) +{ + std::ios_base::fmtflags oldFlags = s.flags(); + int width; + + if (s.flags() & std::ios_base::fixed) + { + s.setf (std::ios_base::showpoint); + width = s.precision() + 5; + } + else + { + s.setf (std::ios_base::scientific); + s.setf (std::ios_base::showpoint); + width = s.precision() + 8; + } + + s << "(" << std::setw (width) << m[0][0] << + " " << std::setw (width) << m[0][1] << + " " << std::setw (width) << m[0][2] << "\n" << + + " " << std::setw (width) << m[1][0] << + " " << std::setw (width) << m[1][1] << + " " << std::setw (width) << m[1][2] << "\n" << + + " " << std::setw (width) << m[2][0] << + " " << std::setw (width) << m[2][1] << + " " << std::setw (width) << m[2][2] << ")\n"; + + s.flags (oldFlags); + return s; +} + +template +std::ostream & +operator << (std::ostream &s, const Matrix44 &m) +{ + std::ios_base::fmtflags oldFlags = s.flags(); + int width; + + if (s.flags() & std::ios_base::fixed) + { + s.setf (std::ios_base::showpoint); + width = s.precision() + 5; + } + else + { + s.setf (std::ios_base::scientific); + s.setf (std::ios_base::showpoint); + width = s.precision() + 8; + } + + s << "(" << std::setw (width) << m[0][0] << + " " << std::setw (width) << m[0][1] << + " " << std::setw (width) << m[0][2] << + " " << std::setw (width) << m[0][3] << "\n" << + + " " << std::setw (width) << m[1][0] << + " " << std::setw (width) << m[1][1] << + " " << std::setw (width) << m[1][2] << + " " << std::setw (width) << m[1][3] << "\n" << + + " " << std::setw (width) << m[2][0] << + " " << std::setw (width) << m[2][1] << + " " << std::setw (width) << m[2][2] << + " " << std::setw (width) << m[2][3] << "\n" << + + " " << std::setw (width) << m[3][0] << + " " << std::setw (width) << m[3][1] << + " " << std::setw (width) << m[3][2] << + " " << std::setw (width) << m[3][3] << ")\n"; + + s.flags (oldFlags); + return s; +} + + +//--------------------------------------------------------------- +// Implementation of vector-times-matrix multiplication operators +//--------------------------------------------------------------- + +template +inline const Vec2 & +operator *= (Vec2 &v, const Matrix33 &m) +{ + S x = S(v.x * m[0][0] + v.y * m[1][0] + m[2][0]); + S y = S(v.x * m[0][1] + v.y * m[1][1] + m[2][1]); + S w = S(v.x * m[0][2] + v.y * m[1][2] + m[2][2]); + + v.x = x / w; + v.y = y / w; + + return v; +} + +template +inline Vec2 +operator * (const Vec2 &v, const Matrix33 &m) +{ + S x = S(v.x * m[0][0] + v.y * m[1][0] + m[2][0]); + S y = S(v.x * m[0][1] + v.y * m[1][1] + m[2][1]); + S w = S(v.x * m[0][2] + v.y * m[1][2] + m[2][2]); + + return Vec2 (x / w, y / w); +} + + +template +inline const Vec3 & +operator *= (Vec3 &v, const Matrix33 &m) +{ + S x = S(v.x * m[0][0] + v.y * m[1][0] + v.z * m[2][0]); + S y = S(v.x * m[0][1] + v.y * m[1][1] + v.z * m[2][1]); + S z = S(v.x * m[0][2] + v.y * m[1][2] + v.z * m[2][2]); + + v.x = x; + v.y = y; + v.z = z; + + return v; +} + +template +inline Vec3 +operator * (const Vec3 &v, const Matrix33 &m) +{ + S x = S(v.x * m[0][0] + v.y * m[1][0] + v.z * m[2][0]); + S y = S(v.x * m[0][1] + v.y * m[1][1] + v.z * m[2][1]); + S z = S(v.x * m[0][2] + v.y * m[1][2] + v.z * m[2][2]); + + return Vec3 (x, y, z); +} + + +template +inline const Vec3 & +operator *= (Vec3 &v, const Matrix44 &m) +{ + S x = S(v.x * m[0][0] + v.y * m[1][0] + v.z * m[2][0] + m[3][0]); + S y = S(v.x * m[0][1] + v.y * m[1][1] + v.z * m[2][1] + m[3][1]); + S z = S(v.x * m[0][2] + v.y * m[1][2] + v.z * m[2][2] + m[3][2]); + S w = S(v.x * m[0][3] + v.y * m[1][3] + v.z * m[2][3] + m[3][3]); + + v.x = x / w; + v.y = y / w; + v.z = z / w; + + return v; +} + +template +inline Vec3 +operator * (const Vec3 &v, const Matrix44 &m) +{ + S x = S(v.x * m[0][0] + v.y * m[1][0] + v.z * m[2][0] + m[3][0]); + S y = S(v.x * m[0][1] + v.y * m[1][1] + v.z * m[2][1] + m[3][1]); + S z = S(v.x * m[0][2] + v.y * m[1][2] + v.z * m[2][2] + m[3][2]); + S w = S(v.x * m[0][3] + v.y * m[1][3] + v.z * m[2][3] + m[3][3]); + + return Vec3 (x / w, y / w, z / w); +} + + +template +inline const Vec4 & +operator *= (Vec4 &v, const Matrix44 &m) +{ + S x = S(v.x * m[0][0] + v.y * m[1][0] + v.z * m[2][0] + v.w * m[3][0]); + S y = S(v.x * m[0][1] + v.y * m[1][1] + v.z * m[2][1] + v.w * m[3][1]); + S z = S(v.x * m[0][2] + v.y * m[1][2] + v.z * m[2][2] + v.w * m[3][2]); + S w = S(v.x * m[0][3] + v.y * m[1][3] + v.z * m[2][3] + v.w * m[3][3]); + + v.x = x; + v.y = y; + v.z = z; + v.w = w; + + return v; +} + +template +inline Vec4 +operator * (const Vec4 &v, const Matrix44 &m) +{ + S x = S(v.x * m[0][0] + v.y * m[1][0] + v.z * m[2][0] + v.w * m[3][0]); + S y = S(v.x * m[0][1] + v.y * m[1][1] + v.z * m[2][1] + v.w * m[3][1]); + S z = S(v.x * m[0][2] + v.y * m[1][2] + v.z * m[2][2] + v.w * m[3][2]); + S w = S(v.x * m[0][3] + v.y * m[1][3] + v.z * m[2][3] + v.w * m[3][3]); + + return Vec4 (x, y, z, w); +} + +IMATH_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_IMATHMATRIX_H diff --git a/OpenEXR/include/OpenEXR/ImathMatrixAlgo.h b/OpenEXR/include/OpenEXR/ImathMatrixAlgo.h new file mode 100644 index 0000000..8e90b02 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathMatrixAlgo.h @@ -0,0 +1,1425 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMATHMATRIXALGO_H +#define INCLUDED_IMATHMATRIXALGO_H + +//------------------------------------------------------------------------- +// +// This file contains algorithms applied to or in conjunction with +// transformation matrices (Imath::Matrix33 and Imath::Matrix44). +// The assumption made is that these functions are called much less +// often than the basic point functions or these functions require +// more support classes. +// +// This file also defines a few predefined constant matrices. +// +//------------------------------------------------------------------------- + +#include "ImathExport.h" +#include "ImathMatrix.h" +#include "ImathQuat.h" +#include "ImathEuler.h" +#include "ImathExc.h" +#include "ImathVec.h" +#include "ImathLimits.h" +#include "ImathNamespace.h" +#include + +IMATH_INTERNAL_NAMESPACE_HEADER_ENTER + +//------------------ +// Identity matrices +//------------------ + +IMATH_EXPORT_CONST M33f identity33f; +IMATH_EXPORT_CONST M44f identity44f; +IMATH_EXPORT_CONST M33d identity33d; +IMATH_EXPORT_CONST M44d identity44d; + +//---------------------------------------------------------------------- +// Extract scale, shear, rotation, and translation values from a matrix: +// +// Notes: +// +// This implementation follows the technique described in the paper by +// Spencer W. Thomas in the Graphics Gems II article: "Decomposing a +// Matrix into Simple Transformations", p. 320. +// +// - Some of the functions below have an optional exc parameter +// that determines the functions' behavior when the matrix' +// scaling is very close to zero: +// +// If exc is true, the functions throw an Imath::ZeroScale exception. +// +// If exc is false: +// +// extractScaling (m, s) returns false, s is invalid +// sansScaling (m) returns m +// removeScaling (m) returns false, m is unchanged +// sansScalingAndShear (m) returns m +// removeScalingAndShear (m) returns false, m is unchanged +// extractAndRemoveScalingAndShear (m, s, h) +// returns false, m is unchanged, +// (sh) are invalid +// checkForZeroScaleInRow () returns false +// extractSHRT (m, s, h, r, t) returns false, (shrt) are invalid +// +// - Functions extractEuler(), extractEulerXYZ() and extractEulerZYX() +// assume that the matrix does not include shear or non-uniform scaling, +// but they do not examine the matrix to verify this assumption. +// Matrices with shear or non-uniform scaling are likely to produce +// meaningless results. Therefore, you should use the +// removeScalingAndShear() routine, if necessary, prior to calling +// extractEuler...() . +// +// - All functions assume that the matrix does not include perspective +// transformation(s), but they do not examine the matrix to verify +// this assumption. Matrices with perspective transformations are +// likely to produce meaningless results. +// +//---------------------------------------------------------------------- + + +// +// Declarations for 4x4 matrix. +// + +template bool extractScaling + (const Matrix44 &mat, + Vec3 &scl, + bool exc = true); + +template Matrix44 sansScaling (const Matrix44 &mat, + bool exc = true); + +template bool removeScaling + (Matrix44 &mat, + bool exc = true); + +template bool extractScalingAndShear + (const Matrix44 &mat, + Vec3 &scl, + Vec3 &shr, + bool exc = true); + +template Matrix44 sansScalingAndShear + (const Matrix44 &mat, + bool exc = true); + +template void sansScalingAndShear + (Matrix44 &result, + const Matrix44 &mat, + bool exc = true); + +template bool removeScalingAndShear + (Matrix44 &mat, + bool exc = true); + +template bool extractAndRemoveScalingAndShear + (Matrix44 &mat, + Vec3 &scl, + Vec3 &shr, + bool exc = true); + +template void extractEulerXYZ + (const Matrix44 &mat, + Vec3 &rot); + +template void extractEulerZYX + (const Matrix44 &mat, + Vec3 &rot); + +template Quat extractQuat (const Matrix44 &mat); + +template bool extractSHRT + (const Matrix44 &mat, + Vec3 &s, + Vec3 &h, + Vec3 &r, + Vec3 &t, + bool exc /*= true*/, + typename Euler::Order rOrder); + +template bool extractSHRT + (const Matrix44 &mat, + Vec3 &s, + Vec3 &h, + Vec3 &r, + Vec3 &t, + bool exc = true); + +template bool extractSHRT + (const Matrix44 &mat, + Vec3 &s, + Vec3 &h, + Euler &r, + Vec3 &t, + bool exc = true); + +// +// Internal utility function. +// + +template bool checkForZeroScaleInRow + (const T &scl, + const Vec3 &row, + bool exc = true); + +template Matrix44 outerProduct + ( const Vec4 &a, + const Vec4 &b); + + +// +// Returns a matrix that rotates "fromDirection" vector to "toDirection" +// vector. +// + +template Matrix44 rotationMatrix (const Vec3 &fromDirection, + const Vec3 &toDirection); + + + +// +// Returns a matrix that rotates the "fromDir" vector +// so that it points towards "toDir". You may also +// specify that you want the up vector to be pointing +// in a certain direction "upDir". +// + +template Matrix44 rotationMatrixWithUpDir + (const Vec3 &fromDir, + const Vec3 &toDir, + const Vec3 &upDir); + + +// +// Constructs a matrix that rotates the z-axis so that it +// points towards "targetDir". You must also specify +// that you want the up vector to be pointing in a +// certain direction "upDir". +// +// Notes: The following degenerate cases are handled: +// (a) when the directions given by "toDir" and "upDir" +// are parallel or opposite; +// (the direction vectors must have a non-zero cross product) +// (b) when any of the given direction vectors have zero length +// + +template void alignZAxisWithTargetDir + (Matrix44 &result, + Vec3 targetDir, + Vec3 upDir); + + +// Compute an orthonormal direct frame from : a position, an x axis direction and a normal to the y axis +// If the x axis and normal are perpendicular, then the normal will have the same direction as the z axis. +// Inputs are : +// -the position of the frame +// -the x axis direction of the frame +// -a normal to the y axis of the frame +// Return is the orthonormal frame +template Matrix44 computeLocalFrame( const Vec3& p, + const Vec3& xDir, + const Vec3& normal); + +// Add a translate/rotate/scale offset to an input frame +// and put it in another frame of reference +// Inputs are : +// - input frame +// - translate offset +// - rotate offset in degrees +// - scale offset +// - frame of reference +// Output is the offsetted frame +template Matrix44 addOffset( const Matrix44& inMat, + const Vec3& tOffset, + const Vec3& rOffset, + const Vec3& sOffset, + const Vec3& ref); + +// Compute Translate/Rotate/Scale matrix from matrix A with the Rotate/Scale of Matrix B +// Inputs are : +// -keepRotateA : if true keep rotate from matrix A, use B otherwise +// -keepScaleA : if true keep scale from matrix A, use B otherwise +// -Matrix A +// -Matrix B +// Return Matrix A with tweaked rotation/scale +template Matrix44 computeRSMatrix( bool keepRotateA, + bool keepScaleA, + const Matrix44& A, + const Matrix44& B); + + +//---------------------------------------------------------------------- + + +// +// Declarations for 3x3 matrix. +// + + +template bool extractScaling + (const Matrix33 &mat, + Vec2 &scl, + bool exc = true); + +template Matrix33 sansScaling (const Matrix33 &mat, + bool exc = true); + +template bool removeScaling + (Matrix33 &mat, + bool exc = true); + +template bool extractScalingAndShear + (const Matrix33 &mat, + Vec2 &scl, + T &h, + bool exc = true); + +template Matrix33 sansScalingAndShear + (const Matrix33 &mat, + bool exc = true); + +template bool removeScalingAndShear + (Matrix33 &mat, + bool exc = true); + +template bool extractAndRemoveScalingAndShear + (Matrix33 &mat, + Vec2 &scl, + T &shr, + bool exc = true); + +template void extractEuler + (const Matrix33 &mat, + T &rot); + +template bool extractSHRT (const Matrix33 &mat, + Vec2 &s, + T &h, + T &r, + Vec2 &t, + bool exc = true); + +template bool checkForZeroScaleInRow + (const T &scl, + const Vec2 &row, + bool exc = true); + +template Matrix33 outerProduct + ( const Vec3 &a, + const Vec3 &b); + + +//----------------------------------------------------------------------------- +// Implementation for 4x4 Matrix +//------------------------------ + + +template +bool +extractScaling (const Matrix44 &mat, Vec3 &scl, bool exc) +{ + Vec3 shr; + Matrix44 M (mat); + + if (! extractAndRemoveScalingAndShear (M, scl, shr, exc)) + return false; + + return true; +} + + +template +Matrix44 +sansScaling (const Matrix44 &mat, bool exc) +{ + Vec3 scl; + Vec3 shr; + Vec3 rot; + Vec3 tran; + + if (! extractSHRT (mat, scl, shr, rot, tran, exc)) + return mat; + + Matrix44 M; + + M.translate (tran); + M.rotate (rot); + M.shear (shr); + + return M; +} + + +template +bool +removeScaling (Matrix44 &mat, bool exc) +{ + Vec3 scl; + Vec3 shr; + Vec3 rot; + Vec3 tran; + + if (! extractSHRT (mat, scl, shr, rot, tran, exc)) + return false; + + mat.makeIdentity (); + mat.translate (tran); + mat.rotate (rot); + mat.shear (shr); + + return true; +} + + +template +bool +extractScalingAndShear (const Matrix44 &mat, + Vec3 &scl, Vec3 &shr, bool exc) +{ + Matrix44 M (mat); + + if (! extractAndRemoveScalingAndShear (M, scl, shr, exc)) + return false; + + return true; +} + + +template +Matrix44 +sansScalingAndShear (const Matrix44 &mat, bool exc) +{ + Vec3 scl; + Vec3 shr; + Matrix44 M (mat); + + if (! extractAndRemoveScalingAndShear (M, scl, shr, exc)) + return mat; + + return M; +} + + +template +void +sansScalingAndShear (Matrix44 &result, const Matrix44 &mat, bool exc) +{ + Vec3 scl; + Vec3 shr; + + if (! extractAndRemoveScalingAndShear (result, scl, shr, exc)) + result = mat; +} + + +template +bool +removeScalingAndShear (Matrix44 &mat, bool exc) +{ + Vec3 scl; + Vec3 shr; + + if (! extractAndRemoveScalingAndShear (mat, scl, shr, exc)) + return false; + + return true; +} + + +template +bool +extractAndRemoveScalingAndShear (Matrix44 &mat, + Vec3 &scl, Vec3 &shr, bool exc) +{ + // + // This implementation follows the technique described in the paper by + // Spencer W. Thomas in the Graphics Gems II article: "Decomposing a + // Matrix into Simple Transformations", p. 320. + // + + Vec3 row[3]; + + row[0] = Vec3 (mat[0][0], mat[0][1], mat[0][2]); + row[1] = Vec3 (mat[1][0], mat[1][1], mat[1][2]); + row[2] = Vec3 (mat[2][0], mat[2][1], mat[2][2]); + + T maxVal = 0; + for (int i=0; i < 3; i++) + for (int j=0; j < 3; j++) + if (IMATH_INTERNAL_NAMESPACE::abs (row[i][j]) > maxVal) + maxVal = IMATH_INTERNAL_NAMESPACE::abs (row[i][j]); + + // + // We normalize the 3x3 matrix here. + // It was noticed that this can improve numerical stability significantly, + // especially when many of the upper 3x3 matrix's coefficients are very + // close to zero; we correct for this step at the end by multiplying the + // scaling factors by maxVal at the end (shear and rotation are not + // affected by the normalization). + + if (maxVal != 0) + { + for (int i=0; i < 3; i++) + if (! checkForZeroScaleInRow (maxVal, row[i], exc)) + return false; + else + row[i] /= maxVal; + } + + // Compute X scale factor. + scl.x = row[0].length (); + if (! checkForZeroScaleInRow (scl.x, row[0], exc)) + return false; + + // Normalize first row. + row[0] /= scl.x; + + // An XY shear factor will shear the X coord. as the Y coord. changes. + // There are 6 combinations (XY, XZ, YZ, YX, ZX, ZY), although we only + // extract the first 3 because we can effect the last 3 by shearing in + // XY, XZ, YZ combined rotations and scales. + // + // shear matrix < 1, YX, ZX, 0, + // XY, 1, ZY, 0, + // XZ, YZ, 1, 0, + // 0, 0, 0, 1 > + + // Compute XY shear factor and make 2nd row orthogonal to 1st. + shr[0] = row[0].dot (row[1]); + row[1] -= shr[0] * row[0]; + + // Now, compute Y scale. + scl.y = row[1].length (); + if (! checkForZeroScaleInRow (scl.y, row[1], exc)) + return false; + + // Normalize 2nd row and correct the XY shear factor for Y scaling. + row[1] /= scl.y; + shr[0] /= scl.y; + + // Compute XZ and YZ shears, orthogonalize 3rd row. + shr[1] = row[0].dot (row[2]); + row[2] -= shr[1] * row[0]; + shr[2] = row[1].dot (row[2]); + row[2] -= shr[2] * row[1]; + + // Next, get Z scale. + scl.z = row[2].length (); + if (! checkForZeroScaleInRow (scl.z, row[2], exc)) + return false; + + // Normalize 3rd row and correct the XZ and YZ shear factors for Z scaling. + row[2] /= scl.z; + shr[1] /= scl.z; + shr[2] /= scl.z; + + // At this point, the upper 3x3 matrix in mat is orthonormal. + // Check for a coordinate system flip. If the determinant + // is less than zero, then negate the matrix and the scaling factors. + if (row[0].dot (row[1].cross (row[2])) < 0) + for (int i=0; i < 3; i++) + { + scl[i] *= -1; + row[i] *= -1; + } + + // Copy over the orthonormal rows into the returned matrix. + // The upper 3x3 matrix in mat is now a rotation matrix. + for (int i=0; i < 3; i++) + { + mat[i][0] = row[i][0]; + mat[i][1] = row[i][1]; + mat[i][2] = row[i][2]; + } + + // Correct the scaling factors for the normalization step that we + // performed above; shear and rotation are not affected by the + // normalization. + scl *= maxVal; + + return true; +} + + +template +void +extractEulerXYZ (const Matrix44 &mat, Vec3 &rot) +{ + // + // Normalize the local x, y and z axes to remove scaling. + // + + Vec3 i (mat[0][0], mat[0][1], mat[0][2]); + Vec3 j (mat[1][0], mat[1][1], mat[1][2]); + Vec3 k (mat[2][0], mat[2][1], mat[2][2]); + + i.normalize(); + j.normalize(); + k.normalize(); + + Matrix44 M (i[0], i[1], i[2], 0, + j[0], j[1], j[2], 0, + k[0], k[1], k[2], 0, + 0, 0, 0, 1); + + // + // Extract the first angle, rot.x. + // + + rot.x = Math::atan2 (M[1][2], M[2][2]); + + // + // Remove the rot.x rotation from M, so that the remaining + // rotation, N, is only around two axes, and gimbal lock + // cannot occur. + // + + Matrix44 N; + N.rotate (Vec3 (-rot.x, 0, 0)); + N = N * M; + + // + // Extract the other two angles, rot.y and rot.z, from N. + // + + T cy = Math::sqrt (N[0][0]*N[0][0] + N[0][1]*N[0][1]); + rot.y = Math::atan2 (-N[0][2], cy); + rot.z = Math::atan2 (-N[1][0], N[1][1]); +} + + +template +void +extractEulerZYX (const Matrix44 &mat, Vec3 &rot) +{ + // + // Normalize the local x, y and z axes to remove scaling. + // + + Vec3 i (mat[0][0], mat[0][1], mat[0][2]); + Vec3 j (mat[1][0], mat[1][1], mat[1][2]); + Vec3 k (mat[2][0], mat[2][1], mat[2][2]); + + i.normalize(); + j.normalize(); + k.normalize(); + + Matrix44 M (i[0], i[1], i[2], 0, + j[0], j[1], j[2], 0, + k[0], k[1], k[2], 0, + 0, 0, 0, 1); + + // + // Extract the first angle, rot.x. + // + + rot.x = -Math::atan2 (M[1][0], M[0][0]); + + // + // Remove the x rotation from M, so that the remaining + // rotation, N, is only around two axes, and gimbal lock + // cannot occur. + // + + Matrix44 N; + N.rotate (Vec3 (0, 0, -rot.x)); + N = N * M; + + // + // Extract the other two angles, rot.y and rot.z, from N. + // + + T cy = Math::sqrt (N[2][2]*N[2][2] + N[2][1]*N[2][1]); + rot.y = -Math::atan2 (-N[2][0], cy); + rot.z = -Math::atan2 (-N[1][2], N[1][1]); +} + + +template +Quat +extractQuat (const Matrix44 &mat) +{ + Matrix44 rot; + + T tr, s; + T q[4]; + int i, j, k; + Quat quat; + + int nxt[3] = {1, 2, 0}; + tr = mat[0][0] + mat[1][1] + mat[2][2]; + + // check the diagonal + if (tr > 0.0) { + s = Math::sqrt (tr + T(1.0)); + quat.r = s / T(2.0); + s = T(0.5) / s; + + quat.v.x = (mat[1][2] - mat[2][1]) * s; + quat.v.y = (mat[2][0] - mat[0][2]) * s; + quat.v.z = (mat[0][1] - mat[1][0]) * s; + } + else { + // diagonal is negative + i = 0; + if (mat[1][1] > mat[0][0]) + i=1; + if (mat[2][2] > mat[i][i]) + i=2; + + j = nxt[i]; + k = nxt[j]; + s = Math::sqrt ((mat[i][i] - (mat[j][j] + mat[k][k])) + T(1.0)); + + q[i] = s * T(0.5); + if (s != T(0.0)) + s = T(0.5) / s; + + q[3] = (mat[j][k] - mat[k][j]) * s; + q[j] = (mat[i][j] + mat[j][i]) * s; + q[k] = (mat[i][k] + mat[k][i]) * s; + + quat.v.x = q[0]; + quat.v.y = q[1]; + quat.v.z = q[2]; + quat.r = q[3]; + } + + return quat; +} + +template +bool +extractSHRT (const Matrix44 &mat, + Vec3 &s, + Vec3 &h, + Vec3 &r, + Vec3 &t, + bool exc /* = true */ , + typename Euler::Order rOrder /* = Euler::XYZ */ ) +{ + Matrix44 rot; + + rot = mat; + if (! extractAndRemoveScalingAndShear (rot, s, h, exc)) + return false; + + extractEulerXYZ (rot, r); + + t.x = mat[3][0]; + t.y = mat[3][1]; + t.z = mat[3][2]; + + if (rOrder != Euler::XYZ) + { + IMATH_INTERNAL_NAMESPACE::Euler eXYZ (r, IMATH_INTERNAL_NAMESPACE::Euler::XYZ); + IMATH_INTERNAL_NAMESPACE::Euler e (eXYZ, rOrder); + r = e.toXYZVector (); + } + + return true; +} + +template +bool +extractSHRT (const Matrix44 &mat, + Vec3 &s, + Vec3 &h, + Vec3 &r, + Vec3 &t, + bool exc) +{ + return extractSHRT(mat, s, h, r, t, exc, IMATH_INTERNAL_NAMESPACE::Euler::XYZ); +} + +template +bool +extractSHRT (const Matrix44 &mat, + Vec3 &s, + Vec3 &h, + Euler &r, + Vec3 &t, + bool exc /* = true */) +{ + return extractSHRT (mat, s, h, r, t, exc, r.order ()); +} + + +template +bool +checkForZeroScaleInRow (const T& scl, + const Vec3 &row, + bool exc /* = true */ ) +{ + for (int i = 0; i < 3; i++) + { + if ((abs (scl) < 1 && abs (row[i]) >= limits::max() * abs (scl))) + { + if (exc) + throw IMATH_INTERNAL_NAMESPACE::ZeroScaleExc ("Cannot remove zero scaling " + "from matrix."); + else + return false; + } + } + + return true; +} + +template +Matrix44 +outerProduct (const Vec4 &a, const Vec4 &b ) +{ + return Matrix44 (a.x*b.x, a.x*b.y, a.x*b.z, a.x*b.w, + a.y*b.x, a.y*b.y, a.y*b.z, a.x*b.w, + a.z*b.x, a.z*b.y, a.z*b.z, a.x*b.w, + a.w*b.x, a.w*b.y, a.w*b.z, a.w*b.w); +} + +template +Matrix44 +rotationMatrix (const Vec3 &from, const Vec3 &to) +{ + Quat q; + q.setRotation(from, to); + return q.toMatrix44(); +} + + +template +Matrix44 +rotationMatrixWithUpDir (const Vec3 &fromDir, + const Vec3 &toDir, + const Vec3 &upDir) +{ + // + // The goal is to obtain a rotation matrix that takes + // "fromDir" to "toDir". We do this in two steps and + // compose the resulting rotation matrices; + // (a) rotate "fromDir" into the z-axis + // (b) rotate the z-axis into "toDir" + // + + // The from direction must be non-zero; but we allow zero to and up dirs. + if (fromDir.length () == 0) + return Matrix44 (); + + else + { + Matrix44 zAxis2FromDir( IMATH_INTERNAL_NAMESPACE::UNINITIALIZED ); + alignZAxisWithTargetDir (zAxis2FromDir, fromDir, Vec3 (0, 1, 0)); + + Matrix44 fromDir2zAxis = zAxis2FromDir.transposed (); + + Matrix44 zAxis2ToDir( IMATH_INTERNAL_NAMESPACE::UNINITIALIZED ); + alignZAxisWithTargetDir (zAxis2ToDir, toDir, upDir); + + return fromDir2zAxis * zAxis2ToDir; + } +} + + +template +void +alignZAxisWithTargetDir (Matrix44 &result, Vec3 targetDir, Vec3 upDir) +{ + // + // Ensure that the target direction is non-zero. + // + + if ( targetDir.length () == 0 ) + targetDir = Vec3 (0, 0, 1); + + // + // Ensure that the up direction is non-zero. + // + + if ( upDir.length () == 0 ) + upDir = Vec3 (0, 1, 0); + + // + // Check for degeneracies. If the upDir and targetDir are parallel + // or opposite, then compute a new, arbitrary up direction that is + // not parallel or opposite to the targetDir. + // + + if (upDir.cross (targetDir).length () == 0) + { + upDir = targetDir.cross (Vec3 (1, 0, 0)); + if (upDir.length() == 0) + upDir = targetDir.cross(Vec3 (0, 0, 1)); + } + + // + // Compute the x-, y-, and z-axis vectors of the new coordinate system. + // + + Vec3 targetPerpDir = upDir.cross (targetDir); + Vec3 targetUpDir = targetDir.cross (targetPerpDir); + + // + // Rotate the x-axis into targetPerpDir (row 0), + // rotate the y-axis into targetUpDir (row 1), + // rotate the z-axis into targetDir (row 2). + // + + Vec3 row[3]; + row[0] = targetPerpDir.normalized (); + row[1] = targetUpDir .normalized (); + row[2] = targetDir .normalized (); + + result.x[0][0] = row[0][0]; + result.x[0][1] = row[0][1]; + result.x[0][2] = row[0][2]; + result.x[0][3] = (T)0; + + result.x[1][0] = row[1][0]; + result.x[1][1] = row[1][1]; + result.x[1][2] = row[1][2]; + result.x[1][3] = (T)0; + + result.x[2][0] = row[2][0]; + result.x[2][1] = row[2][1]; + result.x[2][2] = row[2][2]; + result.x[2][3] = (T)0; + + result.x[3][0] = (T)0; + result.x[3][1] = (T)0; + result.x[3][2] = (T)0; + result.x[3][3] = (T)1; +} + + +// Compute an orthonormal direct frame from : a position, an x axis direction and a normal to the y axis +// If the x axis and normal are perpendicular, then the normal will have the same direction as the z axis. +// Inputs are : +// -the position of the frame +// -the x axis direction of the frame +// -a normal to the y axis of the frame +// Return is the orthonormal frame +template +Matrix44 +computeLocalFrame( const Vec3& p, + const Vec3& xDir, + const Vec3& normal) +{ + Vec3 _xDir(xDir); + Vec3 x = _xDir.normalize(); + Vec3 y = (normal % x).normalize(); + Vec3 z = (x % y).normalize(); + + Matrix44 L; + L[0][0] = x[0]; + L[0][1] = x[1]; + L[0][2] = x[2]; + L[0][3] = 0.0; + + L[1][0] = y[0]; + L[1][1] = y[1]; + L[1][2] = y[2]; + L[1][3] = 0.0; + + L[2][0] = z[0]; + L[2][1] = z[1]; + L[2][2] = z[2]; + L[2][3] = 0.0; + + L[3][0] = p[0]; + L[3][1] = p[1]; + L[3][2] = p[2]; + L[3][3] = 1.0; + + return L; +} + +// Add a translate/rotate/scale offset to an input frame +// and put it in another frame of reference +// Inputs are : +// - input frame +// - translate offset +// - rotate offset in degrees +// - scale offset +// - frame of reference +// Output is the offsetted frame +template +Matrix44 +addOffset( const Matrix44& inMat, + const Vec3& tOffset, + const Vec3& rOffset, + const Vec3& sOffset, + const Matrix44& ref) +{ + Matrix44 O; + + Vec3 _rOffset(rOffset); + _rOffset *= M_PI / 180.0; + O.rotate (_rOffset); + + O[3][0] = tOffset[0]; + O[3][1] = tOffset[1]; + O[3][2] = tOffset[2]; + + Matrix44 S; + S.scale (sOffset); + + Matrix44 X = S * O * inMat * ref; + + return X; +} + +// Compute Translate/Rotate/Scale matrix from matrix A with the Rotate/Scale of Matrix B +// Inputs are : +// -keepRotateA : if true keep rotate from matrix A, use B otherwise +// -keepScaleA : if true keep scale from matrix A, use B otherwise +// -Matrix A +// -Matrix B +// Return Matrix A with tweaked rotation/scale +template +Matrix44 +computeRSMatrix( bool keepRotateA, + bool keepScaleA, + const Matrix44& A, + const Matrix44& B) +{ + Vec3 as, ah, ar, at; + extractSHRT (A, as, ah, ar, at); + + Vec3 bs, bh, br, bt; + extractSHRT (B, bs, bh, br, bt); + + if (!keepRotateA) + ar = br; + + if (!keepScaleA) + as = bs; + + Matrix44 mat; + mat.makeIdentity(); + mat.translate (at); + mat.rotate (ar); + mat.scale (as); + + return mat; +} + + + +//----------------------------------------------------------------------------- +// Implementation for 3x3 Matrix +//------------------------------ + + +template +bool +extractScaling (const Matrix33 &mat, Vec2 &scl, bool exc) +{ + T shr; + Matrix33 M (mat); + + if (! extractAndRemoveScalingAndShear (M, scl, shr, exc)) + return false; + + return true; +} + + +template +Matrix33 +sansScaling (const Matrix33 &mat, bool exc) +{ + Vec2 scl; + T shr; + T rot; + Vec2 tran; + + if (! extractSHRT (mat, scl, shr, rot, tran, exc)) + return mat; + + Matrix33 M; + + M.translate (tran); + M.rotate (rot); + M.shear (shr); + + return M; +} + + +template +bool +removeScaling (Matrix33 &mat, bool exc) +{ + Vec2 scl; + T shr; + T rot; + Vec2 tran; + + if (! extractSHRT (mat, scl, shr, rot, tran, exc)) + return false; + + mat.makeIdentity (); + mat.translate (tran); + mat.rotate (rot); + mat.shear (shr); + + return true; +} + + +template +bool +extractScalingAndShear (const Matrix33 &mat, Vec2 &scl, T &shr, bool exc) +{ + Matrix33 M (mat); + + if (! extractAndRemoveScalingAndShear (M, scl, shr, exc)) + return false; + + return true; +} + + +template +Matrix33 +sansScalingAndShear (const Matrix33 &mat, bool exc) +{ + Vec2 scl; + T shr; + Matrix33 M (mat); + + if (! extractAndRemoveScalingAndShear (M, scl, shr, exc)) + return mat; + + return M; +} + + +template +bool +removeScalingAndShear (Matrix33 &mat, bool exc) +{ + Vec2 scl; + T shr; + + if (! extractAndRemoveScalingAndShear (mat, scl, shr, exc)) + return false; + + return true; +} + +template +bool +extractAndRemoveScalingAndShear (Matrix33 &mat, + Vec2 &scl, T &shr, bool exc) +{ + Vec2 row[2]; + + row[0] = Vec2 (mat[0][0], mat[0][1]); + row[1] = Vec2 (mat[1][0], mat[1][1]); + + T maxVal = 0; + for (int i=0; i < 2; i++) + for (int j=0; j < 2; j++) + if (IMATH_INTERNAL_NAMESPACE::abs (row[i][j]) > maxVal) + maxVal = IMATH_INTERNAL_NAMESPACE::abs (row[i][j]); + + // + // We normalize the 2x2 matrix here. + // It was noticed that this can improve numerical stability significantly, + // especially when many of the upper 2x2 matrix's coefficients are very + // close to zero; we correct for this step at the end by multiplying the + // scaling factors by maxVal at the end (shear and rotation are not + // affected by the normalization). + + if (maxVal != 0) + { + for (int i=0; i < 2; i++) + if (! checkForZeroScaleInRow (maxVal, row[i], exc)) + return false; + else + row[i] /= maxVal; + } + + // Compute X scale factor. + scl.x = row[0].length (); + if (! checkForZeroScaleInRow (scl.x, row[0], exc)) + return false; + + // Normalize first row. + row[0] /= scl.x; + + // An XY shear factor will shear the X coord. as the Y coord. changes. + // There are 2 combinations (XY, YX), although we only extract the XY + // shear factor because we can effect the an YX shear factor by + // shearing in XY combined with rotations and scales. + // + // shear matrix < 1, YX, 0, + // XY, 1, 0, + // 0, 0, 1 > + + // Compute XY shear factor and make 2nd row orthogonal to 1st. + shr = row[0].dot (row[1]); + row[1] -= shr * row[0]; + + // Now, compute Y scale. + scl.y = row[1].length (); + if (! checkForZeroScaleInRow (scl.y, row[1], exc)) + return false; + + // Normalize 2nd row and correct the XY shear factor for Y scaling. + row[1] /= scl.y; + shr /= scl.y; + + // At this point, the upper 2x2 matrix in mat is orthonormal. + // Check for a coordinate system flip. If the determinant + // is -1, then flip the rotation matrix and adjust the scale(Y) + // and shear(XY) factors to compensate. + if (row[0][0] * row[1][1] - row[0][1] * row[1][0] < 0) + { + row[1][0] *= -1; + row[1][1] *= -1; + scl[1] *= -1; + shr *= -1; + } + + // Copy over the orthonormal rows into the returned matrix. + // The upper 2x2 matrix in mat is now a rotation matrix. + for (int i=0; i < 2; i++) + { + mat[i][0] = row[i][0]; + mat[i][1] = row[i][1]; + } + + scl *= maxVal; + + return true; +} + + +template +void +extractEuler (const Matrix33 &mat, T &rot) +{ + // + // Normalize the local x and y axes to remove scaling. + // + + Vec2 i (mat[0][0], mat[0][1]); + Vec2 j (mat[1][0], mat[1][1]); + + i.normalize(); + j.normalize(); + + // + // Extract the angle, rot. + // + + rot = - Math::atan2 (j[0], i[0]); +} + + +template +bool +extractSHRT (const Matrix33 &mat, + Vec2 &s, + T &h, + T &r, + Vec2 &t, + bool exc) +{ + Matrix33 rot; + + rot = mat; + if (! extractAndRemoveScalingAndShear (rot, s, h, exc)) + return false; + + extractEuler (rot, r); + + t.x = mat[2][0]; + t.y = mat[2][1]; + + return true; +} + + +template +bool +checkForZeroScaleInRow (const T& scl, + const Vec2 &row, + bool exc /* = true */ ) +{ + for (int i = 0; i < 2; i++) + { + if ((abs (scl) < 1 && abs (row[i]) >= limits::max() * abs (scl))) + { + if (exc) + throw IMATH_INTERNAL_NAMESPACE::ZeroScaleExc ( + "Cannot remove zero scaling from matrix."); + else + return false; + } + } + + return true; +} + + +template +Matrix33 +outerProduct (const Vec3 &a, const Vec3 &b ) +{ + return Matrix33 (a.x*b.x, a.x*b.y, a.x*b.z, + a.y*b.x, a.y*b.y, a.y*b.z, + a.z*b.x, a.z*b.y, a.z*b.z ); +} + + +// Computes the translation and rotation that brings the 'from' points +// as close as possible to the 'to' points under the Frobenius norm. +// To be more specific, let x be the matrix of 'from' points and y be +// the matrix of 'to' points, we want to find the matrix A of the form +// [ R t ] +// [ 0 1 ] +// that minimizes +// || (A*x - y)^T * W * (A*x - y) ||_F +// If doScaling is true, then a uniform scale is allowed also. +template +IMATH_INTERNAL_NAMESPACE::M44d +procrustesRotationAndTranslation (const IMATH_INTERNAL_NAMESPACE::Vec3* A, // From these + const IMATH_INTERNAL_NAMESPACE::Vec3* B, // To these + const T* weights, + const size_t numPoints, + const bool doScaling = false); + +// Unweighted: +template +IMATH_INTERNAL_NAMESPACE::M44d +procrustesRotationAndTranslation (const IMATH_INTERNAL_NAMESPACE::Vec3* A, + const IMATH_INTERNAL_NAMESPACE::Vec3* B, + const size_t numPoints, + const bool doScaling = false); + +// Compute the SVD of a 3x3 matrix using Jacobi transformations. This method +// should be quite accurate (competitive with LAPACK) even for poorly +// conditioned matrices, and because it has been written specifically for the +// 3x3/4x4 case it is much faster than calling out to LAPACK. +// +// The SVD of a 3x3/4x4 matrix A is defined as follows: +// A = U * S * V^T +// where S is the diagonal matrix of singular values and both U and V are +// orthonormal. By convention, the entries S are all positive and sorted from +// the largest to the smallest. However, some uses of this function may +// require that the matrix U*V^T have positive determinant; in this case, we +// may make the smallest singular value negative to ensure that this is +// satisfied. +// +// Currently only available for single- and double-precision matrices. +template +void +jacobiSVD (const IMATH_INTERNAL_NAMESPACE::Matrix33& A, + IMATH_INTERNAL_NAMESPACE::Matrix33& U, + IMATH_INTERNAL_NAMESPACE::Vec3& S, + IMATH_INTERNAL_NAMESPACE::Matrix33& V, + const T tol = IMATH_INTERNAL_NAMESPACE::limits::epsilon(), + const bool forcePositiveDeterminant = false); + +template +void +jacobiSVD (const IMATH_INTERNAL_NAMESPACE::Matrix44& A, + IMATH_INTERNAL_NAMESPACE::Matrix44& U, + IMATH_INTERNAL_NAMESPACE::Vec4& S, + IMATH_INTERNAL_NAMESPACE::Matrix44& V, + const T tol = IMATH_INTERNAL_NAMESPACE::limits::epsilon(), + const bool forcePositiveDeterminant = false); + +// Compute the eigenvalues (S) and the eigenvectors (V) of +// a real symmetric matrix using Jacobi transformation. +// +// Jacobi transformation of a 3x3/4x4 matrix A outputs S and V: +// A = V * S * V^T +// where V is orthonormal and S is the diagonal matrix of eigenvalues. +// Input matrix A must be symmetric. A is also modified during +// the computation so that upper diagonal entries of A become zero. +// +template +void +jacobiEigenSolver (Matrix33& A, + Vec3& S, + Matrix33& V, + const T tol); + +template +inline +void +jacobiEigenSolver (Matrix33& A, + Vec3& S, + Matrix33& V) +{ + jacobiEigenSolver(A,S,V,limits::epsilon()); +} + +template +void +jacobiEigenSolver (Matrix44& A, + Vec4& S, + Matrix44& V, + const T tol); + +template +inline +void +jacobiEigenSolver (Matrix44& A, + Vec4& S, + Matrix44& V) +{ + jacobiEigenSolver(A,S,V,limits::epsilon()); +} + +// Compute a eigenvector corresponding to the abs max/min eigenvalue +// of a real symmetric matrix using Jacobi transformation. +template +void +maxEigenVector (TM& A, TV& S); +template +void +minEigenVector (TM& A, TV& S); + +IMATH_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_IMATHMATRIXALGO_H diff --git a/OpenEXR/include/OpenEXR/ImathNamespace.h b/OpenEXR/include/OpenEXR/ImathNamespace.h new file mode 100644 index 0000000..c1fb993 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathNamespace.h @@ -0,0 +1,115 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDED_IMATHNAMESPACE_H +#define INCLUDED_IMATHNAMESPACE_H + +// +// The purpose of this file is to make it possible to specify an +// IMATH_INTERNAL_NAMESPACE as a preprocessor definition and have all of the +// Imath symbols defined within that namespace rather than the standard +// Imath namespace. Those symbols are made available to client code through +// the IMATH_NAMESPACE in addition to the IMATH_INTERNAL_NAMESPACE. +// +// To ensure source code compatibility, the IMATH_NAMESPACE defaults to Imath +// and then "using namespace IMATH_INTERNAL_NAMESPACE;" brings all of the +// declarations from the IMATH_INTERNAL_NAMESPACE into the IMATH_NAMESPACE. +// This means that client code can continue to use syntax like Imath::V3f, +// but at link time it will resolve to a mangled symbol based on the +// IMATH_INTERNAL_NAMESPACE. +// +// As an example, if one needed to build against a newer version of Imath and +// have it run alongside an older version in the same application, it is now +// possible to use an internal namespace to prevent collisions between the +// older versions of Imath symbols and the newer ones. To do this, the +// following could be defined at build time: +// +// IMATH_INTERNAL_NAMESPACE = Imath_v2 +// +// This means that declarations inside Imath headers look like this (after +// the preprocessor has done its work): +// +// namespace Imath_v2 { +// ... +// class declarations +// ... +// } +// +// namespace Imath { +// using namespace Imath_v2; +// } +// + +// +// Open Source version of this file pulls in the IlmBaseConfig.h file +// for the configure time options. +// +#include "IlmBaseConfig.h" + + +#ifndef IMATH_NAMESPACE +#define IMATH_NAMESPACE Imath +#endif + +#ifndef IMATH_INTERNAL_NAMESPACE +#define IMATH_INTERNAL_NAMESPACE IMATH_NAMESPACE +#endif + +// +// We need to be sure that we import the internal namespace into the public one. +// To do this, we use the small bit of code below which initially defines +// IMATH_INTERNAL_NAMESPACE (so it can be referenced) and then defines +// IMATH_NAMESPACE and pulls the internal symbols into the public +// namespace. +// + +namespace IMATH_INTERNAL_NAMESPACE {} +namespace IMATH_NAMESPACE { + using namespace IMATH_INTERNAL_NAMESPACE; +} + +// +// There are identical pairs of HEADER/SOURCE ENTER/EXIT macros so that +// future extension to the namespace mechanism is possible without changing +// project source code. +// + +#define IMATH_INTERNAL_NAMESPACE_HEADER_ENTER namespace IMATH_INTERNAL_NAMESPACE { +#define IMATH_INTERNAL_NAMESPACE_HEADER_EXIT } + +#define IMATH_INTERNAL_NAMESPACE_SOURCE_ENTER namespace IMATH_INTERNAL_NAMESPACE { +#define IMATH_INTERNAL_NAMESPACE_SOURCE_EXIT } + + +#endif /* INCLUDED_IMATHNAMESPACE_H */ diff --git a/OpenEXR/include/OpenEXR/ImathPlane.h b/OpenEXR/include/OpenEXR/ImathPlane.h new file mode 100644 index 0000000..7272d67 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathPlane.h @@ -0,0 +1,257 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMATHPLANE_H +#define INCLUDED_IMATHPLANE_H + +//---------------------------------------------------------------------- +// +// template class Plane3 +// +// The Imath::Plane3<> class represents a half space, so the +// normal may point either towards or away from origin. The +// plane P can be represented by Imath::Plane3 as either p or -p +// corresponding to the two half-spaces on either side of the +// plane. Any function which computes a distance will return +// either negative or positive values for the distance indicating +// which half-space the point is in. Note that reflection, and +// intersection functions will operate as expected. +// +//---------------------------------------------------------------------- + +#include "ImathVec.h" +#include "ImathLine.h" +#include "ImathNamespace.h" + +IMATH_INTERNAL_NAMESPACE_HEADER_ENTER + + +template +class Plane3 +{ + public: + + Vec3 normal; + T distance; + + Plane3() {} + Plane3(const Vec3 &normal, T distance); + Plane3(const Vec3 &point, const Vec3 &normal); + Plane3(const Vec3 &point1, + const Vec3 &point2, + const Vec3 &point3); + + //---------------------- + // Various set methods + //---------------------- + + void set(const Vec3 &normal, + T distance); + + void set(const Vec3 &point, + const Vec3 &normal); + + void set(const Vec3 &point1, + const Vec3 &point2, + const Vec3 &point3 ); + + //---------------------- + // Utilities + //---------------------- + + bool intersect(const Line3 &line, + Vec3 &intersection) const; + + bool intersectT(const Line3 &line, + T ¶meter) const; + + T distanceTo(const Vec3 &) const; + + Vec3 reflectPoint(const Vec3 &) const; + Vec3 reflectVector(const Vec3 &) const; +}; + + +//-------------------- +// Convenient typedefs +//-------------------- + +typedef Plane3 Plane3f; +typedef Plane3 Plane3d; + + +//--------------- +// Implementation +//--------------- + +template +inline Plane3::Plane3(const Vec3 &p0, + const Vec3 &p1, + const Vec3 &p2) +{ + set(p0,p1,p2); +} + +template +inline Plane3::Plane3(const Vec3 &n, T d) +{ + set(n, d); +} + +template +inline Plane3::Plane3(const Vec3 &p, const Vec3 &n) +{ + set(p, n); +} + +template +inline void Plane3::set(const Vec3& point1, + const Vec3& point2, + const Vec3& point3) +{ + normal = (point2 - point1) % (point3 - point1); + normal.normalize(); + distance = normal ^ point1; +} + +template +inline void Plane3::set(const Vec3& point, const Vec3& n) +{ + normal = n; + normal.normalize(); + distance = normal ^ point; +} + +template +inline void Plane3::set(const Vec3& n, T d) +{ + normal = n; + normal.normalize(); + distance = d; +} + +template +inline T Plane3::distanceTo(const Vec3 &point) const +{ + return (point ^ normal) - distance; +} + +template +inline Vec3 Plane3::reflectPoint(const Vec3 &point) const +{ + return normal * distanceTo(point) * -2.0 + point; +} + + +template +inline Vec3 Plane3::reflectVector(const Vec3 &v) const +{ + return normal * (normal ^ v) * 2.0 - v; +} + + +template +inline bool Plane3::intersect(const Line3& line, Vec3& point) const +{ + T d = normal ^ line.dir; + if ( d == 0.0 ) return false; + T t = - ((normal ^ line.pos) - distance) / d; + point = line(t); + return true; +} + +template +inline bool Plane3::intersectT(const Line3& line, T &t) const +{ + T d = normal ^ line.dir; + if ( d == 0.0 ) return false; + t = - ((normal ^ line.pos) - distance) / d; + return true; +} + +template +std::ostream &operator<< (std::ostream &o, const Plane3 &plane) +{ + return o << "(" << plane.normal << ", " << plane.distance + << ")"; +} + +template +Plane3 operator* (const Plane3 &plane, const Matrix44 &M) +{ + // T + // -1 + // Could also compute M but that would suck. + // + + Vec3 dir1 = Vec3 (1, 0, 0) % plane.normal; + T dir1Len = dir1 ^ dir1; + + Vec3 tmp = Vec3 (0, 1, 0) % plane.normal; + T tmpLen = tmp ^ tmp; + + if (tmpLen > dir1Len) + { + dir1 = tmp; + dir1Len = tmpLen; + } + + tmp = Vec3 (0, 0, 1) % plane.normal; + tmpLen = tmp ^ tmp; + + if (tmpLen > dir1Len) + { + dir1 = tmp; + } + + Vec3 dir2 = dir1 % plane.normal; + Vec3 point = plane.distance * plane.normal; + + return Plane3 ( point * M, + (point + dir2) * M, + (point + dir1) * M ); +} + +template +Plane3 operator- (const Plane3 &plane) +{ + return Plane3(-plane.normal,-plane.distance); +} + + +IMATH_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_IMATHPLANE_H diff --git a/OpenEXR/include/OpenEXR/ImathPlatform.h b/OpenEXR/include/OpenEXR/ImathPlatform.h new file mode 100644 index 0000000..91e82cc --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathPlatform.h @@ -0,0 +1,112 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002, 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. +// +/////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDED_IMATHPLATFORM_H +#define INCLUDED_IMATHPLATFORM_H + +//---------------------------------------------------------------------------- +// +// ImathPlatform.h +// +// This file contains functions and constants which aren't +// provided by the system libraries, compilers, or includes on +// certain platforms. +// +//---------------------------------------------------------------------------- + +#include + +#ifndef M_PI + #define M_PI 3.14159265358979323846 +#endif + +#ifndef M_PI_2 + #define M_PI_2 1.57079632679489661923 // pi/2 +#endif + + +//----------------------------------------------------------------------------- +// +// Some, but not all, C++ compilers support the C99 restrict +// keyword or some variant of it, for example, __restrict. +// +//----------------------------------------------------------------------------- + +#if defined __GNUC__ + + // + // supports __restrict + // + + #define IMATH_RESTRICT __restrict + +#elif defined (__INTEL_COMPILER) || \ + defined(__ICL) || \ + defined(__ICC) || \ + defined(__ECC) + + // + // supports restrict + // + + #define IMATH_RESTRICT restrict + +#elif defined __sgi + + // + // supports restrict + // + + #define IMATH_RESTRICT restrict + +#elif defined _MSC_VER + + // + // supports __restrict + // + +// #define IMATH_RESTRICT __restrict + #define IMATH_RESTRICT + +#else + + // + // restrict / __restrict not supported + // + + #define IMATH_RESTRICT + +#endif + +#endif // INCLUDED_IMATHPLATFORM_H diff --git a/OpenEXR/include/OpenEXR/ImathQuat.h b/OpenEXR/include/OpenEXR/ImathQuat.h new file mode 100644 index 0000000..e95e356 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathQuat.h @@ -0,0 +1,964 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMATHQUAT_H +#define INCLUDED_IMATHQUAT_H + +//---------------------------------------------------------------------- +// +// template class Quat +// +// "Quaternions came from Hamilton ... and have been an unmixed +// evil to those who have touched them in any way. Vector is a +// useless survival ... and has never been of the slightest use +// to any creature." +// +// - Lord Kelvin +// +// This class implements the quaternion numerical type -- you +// will probably want to use this class to represent orientations +// in R3 and to convert between various euler angle reps. You +// should probably use Imath::Euler<> for that. +// +//---------------------------------------------------------------------- + +#include "ImathExc.h" +#include "ImathMatrix.h" +#include "ImathNamespace.h" + +#include + +IMATH_INTERNAL_NAMESPACE_HEADER_ENTER + +#if (defined _WIN32 || defined _WIN64) && defined _MSC_VER +// Disable MS VC++ warnings about conversion from double to float +#pragma warning(disable:4244) +#endif + +template +class Quat +{ + public: + + T r; // real part + Vec3 v; // imaginary vector + + + //----------------------------------------------------- + // Constructors - default constructor is identity quat + //----------------------------------------------------- + + Quat (); + + template + Quat (const Quat &q); + + Quat (T s, T i, T j, T k); + + Quat (T s, Vec3 d); + + static Quat identity (); + + + //------------------------------------------------- + // Basic Algebra - Operators and Methods + // The operator return values are *NOT* normalized + // + // operator^ and euclideanInnnerProduct() both + // implement the 4D dot product + // + // operator/ uses the inverse() quaternion + // + // operator~ is conjugate -- if (S+V) is quat then + // the conjugate (S+V)* == (S-V) + // + // some operators (*,/,*=,/=) treat the quat as + // a 4D vector when one of the operands is scalar + //------------------------------------------------- + + const Quat & operator = (const Quat &q); + const Quat & operator *= (const Quat &q); + const Quat & operator *= (T t); + const Quat & operator /= (const Quat &q); + const Quat & operator /= (T t); + const Quat & operator += (const Quat &q); + const Quat & operator -= (const Quat &q); + T & operator [] (int index); // as 4D vector + T operator [] (int index) const; + + template bool operator == (const Quat &q) const; + template bool operator != (const Quat &q) const; + + Quat & invert (); // this -> 1 / this + Quat inverse () const; + Quat & normalize (); // returns this + Quat normalized () const; + T length () const; // in R4 + Vec3 rotateVector(const Vec3 &original) const; + T euclideanInnerProduct(const Quat &q) const; + + //----------------------- + // Rotation conversion + //----------------------- + + Quat & setAxisAngle (const Vec3 &axis, T radians); + + Quat & setRotation (const Vec3 &fromDirection, + const Vec3 &toDirection); + + T angle () const; + Vec3 axis () const; + + Matrix33 toMatrix33 () const; + Matrix44 toMatrix44 () const; + + Quat log () const; + Quat exp () const; + + + private: + + void setRotationInternal (const Vec3 &f0, + const Vec3 &t0, + Quat &q); +}; + + +template +Quat slerp (const Quat &q1, const Quat &q2, T t); + +template +Quat slerpShortestArc + (const Quat &q1, const Quat &q2, T t); + + +template +Quat squad (const Quat &q1, const Quat &q2, + const Quat &qa, const Quat &qb, T t); + +template +void intermediate (const Quat &q0, const Quat &q1, + const Quat &q2, const Quat &q3, + Quat &qa, Quat &qb); + +template +Matrix33 operator * (const Matrix33 &M, const Quat &q); + +template +Matrix33 operator * (const Quat &q, const Matrix33 &M); + +template +std::ostream & operator << (std::ostream &o, const Quat &q); + +template +Quat operator * (const Quat &q1, const Quat &q2); + +template +Quat operator / (const Quat &q1, const Quat &q2); + +template +Quat operator / (const Quat &q, T t); + +template +Quat operator * (const Quat &q, T t); + +template +Quat operator * (T t, const Quat &q); + +template +Quat operator + (const Quat &q1, const Quat &q2); + +template +Quat operator - (const Quat &q1, const Quat &q2); + +template +Quat operator ~ (const Quat &q); + +template +Quat operator - (const Quat &q); + +template +Vec3 operator * (const Vec3 &v, const Quat &q); + + +//-------------------- +// Convenient typedefs +//-------------------- + +typedef Quat Quatf; +typedef Quat Quatd; + + +//--------------- +// Implementation +//--------------- + +template +inline +Quat::Quat (): r (1), v (0, 0, 0) +{ + // empty +} + + +template +template +inline +Quat::Quat (const Quat &q): r (q.r), v (q.v) +{ + // empty +} + + +template +inline +Quat::Quat (T s, T i, T j, T k): r (s), v (i, j, k) +{ + // empty +} + + +template +inline +Quat::Quat (T s, Vec3 d): r (s), v (d) +{ + // empty +} + + +template +inline Quat +Quat::identity () +{ + return Quat(); +} + +template +inline const Quat & +Quat::operator = (const Quat &q) +{ + r = q.r; + v = q.v; + return *this; +} + + +template +inline const Quat & +Quat::operator *= (const Quat &q) +{ + T rtmp = r * q.r - (v ^ q.v); + v = r * q.v + v * q.r + v % q.v; + r = rtmp; + return *this; +} + + +template +inline const Quat & +Quat::operator *= (T t) +{ + r *= t; + v *= t; + return *this; +} + + +template +inline const Quat & +Quat::operator /= (const Quat &q) +{ + *this = *this * q.inverse(); + return *this; +} + + +template +inline const Quat & +Quat::operator /= (T t) +{ + r /= t; + v /= t; + return *this; +} + + +template +inline const Quat & +Quat::operator += (const Quat &q) +{ + r += q.r; + v += q.v; + return *this; +} + + +template +inline const Quat & +Quat::operator -= (const Quat &q) +{ + r -= q.r; + v -= q.v; + return *this; +} + + +template +inline T & +Quat::operator [] (int index) +{ + return index ? v[index - 1] : r; +} + + +template +inline T +Quat::operator [] (int index) const +{ + return index ? v[index - 1] : r; +} + + +template +template +inline bool +Quat::operator == (const Quat &q) const +{ + return r == q.r && v == q.v; +} + + +template +template +inline bool +Quat::operator != (const Quat &q) const +{ + return r != q.r || v != q.v; +} + + +template +inline T +operator ^ (const Quat& q1 ,const Quat& q2) +{ + return q1.r * q2.r + (q1.v ^ q2.v); +} + + +template +inline T +Quat::length () const +{ + return Math::sqrt (r * r + (v ^ v)); +} + + +template +inline Quat & +Quat::normalize () +{ + if (T l = length()) + { + r /= l; + v /= l; + } + else + { + r = 1; + v = Vec3 (0); + } + + return *this; +} + + +template +inline Quat +Quat::normalized () const +{ + if (T l = length()) + return Quat (r / l, v / l); + + return Quat(); +} + + +template +inline Quat +Quat::inverse () const +{ + // + // 1 Q* + // - = ---- where Q* is conjugate (operator~) + // Q Q* Q and (Q* Q) == Q ^ Q (4D dot) + // + + T qdot = *this ^ *this; + return Quat (r / qdot, -v / qdot); +} + + +template +inline Quat & +Quat::invert () +{ + T qdot = (*this) ^ (*this); + r /= qdot; + v = -v / qdot; + return *this; +} + + +template +inline Vec3 +Quat::rotateVector(const Vec3& original) const +{ + // + // Given a vector p and a quaternion q (aka this), + // calculate p' = qpq* + // + // Assumes unit quaternions (because non-unit + // quaternions cannot be used to rotate vectors + // anyway). + // + + Quat vec (0, original); // temporarily promote grade of original + Quat inv (*this); + inv.v *= -1; // unit multiplicative inverse + Quat result = *this * vec * inv; + return result.v; +} + + +template +inline T +Quat::euclideanInnerProduct (const Quat &q) const +{ + return r * q.r + v.x * q.v.x + v.y * q.v.y + v.z * q.v.z; +} + + +template +T +angle4D (const Quat &q1, const Quat &q2) +{ + // + // Compute the angle between two quaternions, + // interpreting the quaternions as 4D vectors. + // + + Quat d = q1 - q2; + T lengthD = Math::sqrt (d ^ d); + + Quat s = q1 + q2; + T lengthS = Math::sqrt (s ^ s); + + return 2 * Math::atan2 (lengthD, lengthS); +} + + +template +Quat +slerp (const Quat &q1, const Quat &q2, T t) +{ + // + // Spherical linear interpolation. + // Assumes q1 and q2 are normalized and that q1 != -q2. + // + // This method does *not* interpolate along the shortest + // arc between q1 and q2. If you desire interpolation + // along the shortest arc, and q1^q2 is negative, then + // consider calling slerpShortestArc(), below, or flipping + // the second quaternion explicitly. + // + // The implementation of squad() depends on a slerp() + // that interpolates as is, without the automatic + // flipping. + // + // Don Hatch explains the method we use here on his + // web page, The Right Way to Calculate Stuff, at + // http://www.plunk.org/~hatch/rightway.php + // + + T a = angle4D (q1, q2); + T s = 1 - t; + + Quat q = sinx_over_x (s * a) / sinx_over_x (a) * s * q1 + + sinx_over_x (t * a) / sinx_over_x (a) * t * q2; + + return q.normalized(); +} + + +template +Quat +slerpShortestArc (const Quat &q1, const Quat &q2, T t) +{ + // + // Spherical linear interpolation along the shortest + // arc from q1 to either q2 or -q2, whichever is closer. + // Assumes q1 and q2 are unit quaternions. + // + + if ((q1 ^ q2) >= 0) + return slerp (q1, q2, t); + else + return slerp (q1, -q2, t); +} + + +template +Quat +spline (const Quat &q0, const Quat &q1, + const Quat &q2, const Quat &q3, + T t) +{ + // + // Spherical Cubic Spline Interpolation - + // from Advanced Animation and Rendering + // Techniques by Watt and Watt, Page 366: + // A spherical curve is constructed using three + // spherical linear interpolations of a quadrangle + // of unit quaternions: q1, qa, qb, q2. + // Given a set of quaternion keys: q0, q1, q2, q3, + // this routine does the interpolation between + // q1 and q2 by constructing two intermediate + // quaternions: qa and qb. The qa and qb are + // computed by the intermediate function to + // guarantee the continuity of tangents across + // adjacent cubic segments. The qa represents in-tangent + // for q1 and the qb represents the out-tangent for q2. + // + // The q1 q2 is the cubic segment being interpolated. + // The q0 is from the previous adjacent segment and q3 is + // from the next adjacent segment. The q0 and q3 are used + // in computing qa and qb. + // + + Quat qa = intermediate (q0, q1, q2); + Quat qb = intermediate (q1, q2, q3); + Quat result = squad (q1, qa, qb, q2, t); + + return result; +} + + +template +Quat +squad (const Quat &q1, const Quat &qa, + const Quat &qb, const Quat &q2, + T t) +{ + // + // Spherical Quadrangle Interpolation - + // from Advanced Animation and Rendering + // Techniques by Watt and Watt, Page 366: + // It constructs a spherical cubic interpolation as + // a series of three spherical linear interpolations + // of a quadrangle of unit quaternions. + // + + Quat r1 = slerp (q1, q2, t); + Quat r2 = slerp (qa, qb, t); + Quat result = slerp (r1, r2, 2 * t * (1 - t)); + + return result; +} + + +template +Quat +intermediate (const Quat &q0, const Quat &q1, const Quat &q2) +{ + // + // From advanced Animation and Rendering + // Techniques by Watt and Watt, Page 366: + // computing the inner quadrangle + // points (qa and qb) to guarantee tangent + // continuity. + // + + Quat q1inv = q1.inverse(); + Quat c1 = q1inv * q2; + Quat c2 = q1inv * q0; + Quat c3 = (T) (-0.25) * (c2.log() + c1.log()); + Quat qa = q1 * c3.exp(); + qa.normalize(); + return qa; +} + + +template +inline Quat +Quat::log () const +{ + // + // For unit quaternion, from Advanced Animation and + // Rendering Techniques by Watt and Watt, Page 366: + // + + T theta = Math::acos (std::min (r, (T) 1.0)); + + if (theta == 0) + return Quat (0, v); + + T sintheta = Math::sin (theta); + + T k; + if (abs (sintheta) < 1 && abs (theta) >= limits::max() * abs (sintheta)) + k = 1; + else + k = theta / sintheta; + + return Quat ((T) 0, v.x * k, v.y * k, v.z * k); +} + + +template +inline Quat +Quat::exp () const +{ + // + // For pure quaternion (zero scalar part): + // from Advanced Animation and Rendering + // Techniques by Watt and Watt, Page 366: + // + + T theta = v.length(); + T sintheta = Math::sin (theta); + + T k; + if (abs (theta) < 1 && abs (sintheta) >= limits::max() * abs (theta)) + k = 1; + else + k = sintheta / theta; + + T costheta = Math::cos (theta); + + return Quat (costheta, v.x * k, v.y * k, v.z * k); +} + + +template +inline T +Quat::angle () const +{ + return 2 * Math::atan2 (v.length(), r); +} + + +template +inline Vec3 +Quat::axis () const +{ + return v.normalized(); +} + + +template +inline Quat & +Quat::setAxisAngle (const Vec3 &axis, T radians) +{ + r = Math::cos (radians / 2); + v = axis.normalized() * Math::sin (radians / 2); + return *this; +} + + +template +Quat & +Quat::setRotation (const Vec3 &from, const Vec3 &to) +{ + // + // Create a quaternion that rotates vector from into vector to, + // such that the rotation is around an axis that is the cross + // product of from and to. + // + // This function calls function setRotationInternal(), which is + // numerically accurate only for rotation angles that are not much + // greater than pi/2. In order to achieve good accuracy for angles + // greater than pi/2, we split large angles in half, and rotate in + // two steps. + // + + // + // Normalize from and to, yielding f0 and t0. + // + + Vec3 f0 = from.normalized(); + Vec3 t0 = to.normalized(); + + if ((f0 ^ t0) >= 0) + { + // + // The rotation angle is less than or equal to pi/2. + // + + setRotationInternal (f0, t0, *this); + } + else + { + // + // The angle is greater than pi/2. After computing h0, + // which is halfway between f0 and t0, we rotate first + // from f0 to h0, then from h0 to t0. + // + + Vec3 h0 = (f0 + t0).normalized(); + + if ((h0 ^ h0) != 0) + { + setRotationInternal (f0, h0, *this); + + Quat q; + setRotationInternal (h0, t0, q); + + *this *= q; + } + else + { + // + // f0 and t0 point in exactly opposite directions. + // Pick an arbitrary axis that is orthogonal to f0, + // and rotate by pi. + // + + r = T (0); + + Vec3 f02 = f0 * f0; + + if (f02.x <= f02.y && f02.x <= f02.z) + v = (f0 % Vec3 (1, 0, 0)).normalized(); + else if (f02.y <= f02.z) + v = (f0 % Vec3 (0, 1, 0)).normalized(); + else + v = (f0 % Vec3 (0, 0, 1)).normalized(); + } + } + + return *this; +} + + +template +void +Quat::setRotationInternal (const Vec3 &f0, const Vec3 &t0, Quat &q) +{ + // + // The following is equivalent to setAxisAngle(n,2*phi), + // where the rotation axis, n, is orthogonal to the f0 and + // t0 vectors, and 2*phi is the angle between f0 and t0. + // + // This function is called by setRotation(), above; it assumes + // that f0 and t0 are normalized and that the angle between + // them is not much greater than pi/2. This function becomes + // numerically inaccurate if f0 and t0 point into nearly + // opposite directions. + // + + // + // Find a normalized vector, h0, that is halfway between f0 and t0. + // The angle between f0 and h0 is phi. + // + + Vec3 h0 = (f0 + t0).normalized(); + + // + // Store the rotation axis and rotation angle. + // + + q.r = f0 ^ h0; // f0 ^ h0 == cos (phi) + q.v = f0 % h0; // (f0 % h0).length() == sin (phi) +} + + +template +Matrix33 +Quat::toMatrix33() const +{ + return Matrix33 (1 - 2 * (v.y * v.y + v.z * v.z), + 2 * (v.x * v.y + v.z * r), + 2 * (v.z * v.x - v.y * r), + + 2 * (v.x * v.y - v.z * r), + 1 - 2 * (v.z * v.z + v.x * v.x), + 2 * (v.y * v.z + v.x * r), + + 2 * (v.z * v.x + v.y * r), + 2 * (v.y * v.z - v.x * r), + 1 - 2 * (v.y * v.y + v.x * v.x)); +} + +template +Matrix44 +Quat::toMatrix44() const +{ + return Matrix44 (1 - 2 * (v.y * v.y + v.z * v.z), + 2 * (v.x * v.y + v.z * r), + 2 * (v.z * v.x - v.y * r), + 0, + 2 * (v.x * v.y - v.z * r), + 1 - 2 * (v.z * v.z + v.x * v.x), + 2 * (v.y * v.z + v.x * r), + 0, + 2 * (v.z * v.x + v.y * r), + 2 * (v.y * v.z - v.x * r), + 1 - 2 * (v.y * v.y + v.x * v.x), + 0, + 0, + 0, + 0, + 1); +} + + +template +inline Matrix33 +operator * (const Matrix33 &M, const Quat &q) +{ + return M * q.toMatrix33(); +} + + +template +inline Matrix33 +operator * (const Quat &q, const Matrix33 &M) +{ + return q.toMatrix33() * M; +} + + +template +std::ostream & +operator << (std::ostream &o, const Quat &q) +{ + return o << "(" << q.r + << " " << q.v.x + << " " << q.v.y + << " " << q.v.z + << ")"; +} + + +template +inline Quat +operator * (const Quat &q1, const Quat &q2) +{ + return Quat (q1.r * q2.r - (q1.v ^ q2.v), + q1.r * q2.v + q1.v * q2.r + q1.v % q2.v); +} + + +template +inline Quat +operator / (const Quat &q1, const Quat &q2) +{ + return q1 * q2.inverse(); +} + + +template +inline Quat +operator / (const Quat &q, T t) +{ + return Quat (q.r / t, q.v / t); +} + + +template +inline Quat +operator * (const Quat &q, T t) +{ + return Quat (q.r * t, q.v * t); +} + + +template +inline Quat +operator * (T t, const Quat &q) +{ + return Quat (q.r * t, q.v * t); +} + + +template +inline Quat +operator + (const Quat &q1, const Quat &q2) +{ + return Quat (q1.r + q2.r, q1.v + q2.v); +} + + +template +inline Quat +operator - (const Quat &q1, const Quat &q2) +{ + return Quat (q1.r - q2.r, q1.v - q2.v); +} + + +template +inline Quat +operator ~ (const Quat &q) +{ + return Quat (q.r, -q.v); +} + + +template +inline Quat +operator - (const Quat &q) +{ + return Quat (-q.r, -q.v); +} + + +template +inline Vec3 +operator * (const Vec3 &v, const Quat &q) +{ + Vec3 a = q.v % v; + Vec3 b = q.v % a; + return v + T (2) * (q.r * a + b); +} + +#if (defined _WIN32 || defined _WIN64) && defined _MSC_VER +#pragma warning(default:4244) +#endif + +IMATH_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_IMATHQUAT_H diff --git a/OpenEXR/include/OpenEXR/ImathRandom.h b/OpenEXR/include/OpenEXR/ImathRandom.h new file mode 100644 index 0000000..4f0db13 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathRandom.h @@ -0,0 +1,401 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMATHRANDOM_H +#define INCLUDED_IMATHRANDOM_H + +//----------------------------------------------------------------------------- +// +// Generators for uniformly distributed pseudo-random numbers and +// functions that use those generators to generate numbers with +// non-uniform distributions: +// +// class Rand32 +// class Rand48 +// solidSphereRand() +// hollowSphereRand() +// gaussRand() +// gaussSphereRand() +// +// Note: class Rand48() calls erand48() and nrand48(), which are not +// available on all operating systems. For compatibility we include +// our own versions of erand48() and nrand48(). Our functions have +// been reverse-engineered from the corresponding Unix/Linux man page. +// +//----------------------------------------------------------------------------- + +#include "ImathNamespace.h" +#include "ImathExport.h" + +#include +#include + +IMATH_INTERNAL_NAMESPACE_HEADER_ENTER + +//----------------------------------------------- +// Fast random-number generator that generates +// a uniformly distributed sequence with a period +// length of 2^32. +//----------------------------------------------- + +class IMATH_EXPORT Rand32 +{ + public: + + //------------ + // Constructor + //------------ + + Rand32 (unsigned long int seed = 0); + + + //-------------------------------- + // Re-initialize with a given seed + //-------------------------------- + + void init (unsigned long int seed); + + + //---------------------------------------------------------- + // Get the next value in the sequence (range: [false, true]) + //---------------------------------------------------------- + + bool nextb (); + + + //--------------------------------------------------------------- + // Get the next value in the sequence (range: [0 ... 0xffffffff]) + //--------------------------------------------------------------- + + unsigned long int nexti (); + + + //------------------------------------------------------ + // Get the next value in the sequence (range: [0 ... 1[) + //------------------------------------------------------ + + float nextf (); + + + //------------------------------------------------------------------- + // Get the next value in the sequence (range [rangeMin ... rangeMax[) + //------------------------------------------------------------------- + + float nextf (float rangeMin, float rangeMax); + + + private: + + void next (); + + unsigned long int _state; +}; + + +//-------------------------------------------------------- +// Random-number generator based on the C Standard Library +// functions erand48(), nrand48() & company; generates a +// uniformly distributed sequence. +//-------------------------------------------------------- + +class Rand48 +{ + public: + + //------------ + // Constructor + //------------ + + Rand48 (unsigned long int seed = 0); + + + //-------------------------------- + // Re-initialize with a given seed + //-------------------------------- + + void init (unsigned long int seed); + + + //---------------------------------------------------------- + // Get the next value in the sequence (range: [false, true]) + //---------------------------------------------------------- + + bool nextb (); + + + //--------------------------------------------------------------- + // Get the next value in the sequence (range: [0 ... 0x7fffffff]) + //--------------------------------------------------------------- + + long int nexti (); + + + //------------------------------------------------------ + // Get the next value in the sequence (range: [0 ... 1[) + //------------------------------------------------------ + + double nextf (); + + + //------------------------------------------------------------------- + // Get the next value in the sequence (range [rangeMin ... rangeMax[) + //------------------------------------------------------------------- + + double nextf (double rangeMin, double rangeMax); + + + private: + + unsigned short int _state[3]; +}; + + +//------------------------------------------------------------ +// Return random points uniformly distributed in a sphere with +// radius 1 around the origin (distance from origin <= 1). +//------------------------------------------------------------ + +template +Vec +solidSphereRand (Rand &rand); + + +//------------------------------------------------------------- +// Return random points uniformly distributed on the surface of +// a sphere with radius 1 around the origin. +//------------------------------------------------------------- + +template +Vec +hollowSphereRand (Rand &rand); + + +//----------------------------------------------- +// Return random numbers with a normal (Gaussian) +// distribution with zero mean and unit variance. +//----------------------------------------------- + +template +float +gaussRand (Rand &rand); + + +//---------------------------------------------------- +// Return random points whose distance from the origin +// has a normal (Gaussian) distribution with zero mean +// and unit variance. +//---------------------------------------------------- + +template +Vec +gaussSphereRand (Rand &rand); + + +//--------------------------------- +// erand48(), nrand48() and friends +//--------------------------------- + +IMATH_EXPORT double erand48 (unsigned short state[3]); +IMATH_EXPORT double drand48 (); +IMATH_EXPORT long int nrand48 (unsigned short state[3]); +IMATH_EXPORT long int lrand48 (); +IMATH_EXPORT void srand48 (long int seed); + + +//--------------- +// Implementation +//--------------- + + +inline void +Rand32::init (unsigned long int seed) +{ + _state = (seed * 0xa5a573a5L) ^ 0x5a5a5a5aL; +} + + +inline +Rand32::Rand32 (unsigned long int seed) +{ + init (seed); +} + + +inline void +Rand32::next () +{ + _state = 1664525L * _state + 1013904223L; +} + + +inline bool +Rand32::nextb () +{ + next (); + // Return the 31st (most significant) bit, by and-ing with 2 ^ 31. + return !!(_state & 2147483648UL); +} + + +inline unsigned long int +Rand32::nexti () +{ + next (); + return _state & 0xffffffff; +} + + +inline float +Rand32::nextf (float rangeMin, float rangeMax) +{ + float f = nextf(); + return rangeMin * (1 - f) + rangeMax * f; +} + + +inline void +Rand48::init (unsigned long int seed) +{ + seed = (seed * 0xa5a573a5L) ^ 0x5a5a5a5aL; + + _state[0] = (unsigned short int) (seed & 0xFFFF); + _state[1] = (unsigned short int) ((seed >> 16) & 0xFFFF); + _state[2] = (unsigned short int) (seed & 0xFFFF); +} + + +inline +Rand48::Rand48 (unsigned long int seed) +{ + init (seed); +} + + +inline bool +Rand48::nextb () +{ + return nrand48 (_state) & 1; +} + + +inline long int +Rand48::nexti () +{ + return nrand48 (_state); +} + + +inline double +Rand48::nextf () +{ + return erand48 (_state); +} + + +inline double +Rand48::nextf (double rangeMin, double rangeMax) +{ + double f = nextf(); + return rangeMin * (1 - f) + rangeMax * f; +} + + +template +Vec +solidSphereRand (Rand &rand) +{ + Vec v; + + do + { + for (unsigned int i = 0; i < Vec::dimensions(); i++) + v[i] = (typename Vec::BaseType) rand.nextf (-1, 1); + } + while (v.length2() > 1); + + return v; +} + + +template +Vec +hollowSphereRand (Rand &rand) +{ + Vec v; + typename Vec::BaseType length; + + do + { + for (unsigned int i = 0; i < Vec::dimensions(); i++) + v[i] = (typename Vec::BaseType) rand.nextf (-1, 1); + + length = v.length(); + } + while (length > 1 || length == 0); + + return v / length; +} + + +template +float +gaussRand (Rand &rand) +{ + float x; // Note: to avoid numerical problems with very small + float y; // numbers, we make these variables singe-precision + float length2; // floats, but later we call the double-precision log() + // and sqrt() functions instead of logf() and sqrtf(). + do + { + x = float (rand.nextf (-1, 1)); + y = float (rand.nextf (-1, 1)); + length2 = x * x + y * y; + } + while (length2 >= 1 || length2 == 0); + + return x * sqrt (-2 * log (double (length2)) / length2); +} + + +template +Vec +gaussSphereRand (Rand &rand) +{ + return hollowSphereRand (rand) * gaussRand (rand); +} + +IMATH_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_IMATHRANDOM_H diff --git a/OpenEXR/include/OpenEXR/ImathRoots.h b/OpenEXR/include/OpenEXR/ImathRoots.h new file mode 100644 index 0000000..036b7f7 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathRoots.h @@ -0,0 +1,219 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMATHROOTS_H +#define INCLUDED_IMATHROOTS_H + +//--------------------------------------------------------------------- +// +// Functions to solve linear, quadratic or cubic equations +// +//--------------------------------------------------------------------- + +#include "ImathMath.h" +#include "ImathNamespace.h" +#include + +IMATH_INTERNAL_NAMESPACE_HEADER_ENTER + +//-------------------------------------------------------------------------- +// Find the real solutions of a linear, quadratic or cubic equation: +// +// function equation solved +// +// solveLinear (a, b, x) a * x + b == 0 +// solveQuadratic (a, b, c, x) a * x*x + b * x + c == 0 +// solveNormalizedCubic (r, s, t, x) x*x*x + r * x*x + s * x + t == 0 +// solveCubic (a, b, c, d, x) a * x*x*x + b * x*x + c * x + d == 0 +// +// Return value: +// +// 3 three real solutions, stored in x[0], x[1] and x[2] +// 2 two real solutions, stored in x[0] and x[1] +// 1 one real solution, stored in x[1] +// 0 no real solutions +// -1 all real numbers are solutions +// +// Notes: +// +// * It is possible that an equation has real solutions, but that the +// solutions (or some intermediate result) are not representable. +// In this case, either some of the solutions returned are invalid +// (nan or infinity), or, if floating-point exceptions have been +// enabled with Iex::mathExcOn(), an Iex::MathExc exception is +// thrown. +// +// * Cubic equations are solved using Cardano's Formula; even though +// only real solutions are produced, some intermediate results are +// complex (std::complex). +// +//-------------------------------------------------------------------------- + +template int solveLinear (T a, T b, T &x); +template int solveQuadratic (T a, T b, T c, T x[2]); +template int solveNormalizedCubic (T r, T s, T t, T x[3]); +template int solveCubic (T a, T b, T c, T d, T x[3]); + + +//--------------- +// Implementation +//--------------- + +template +int +solveLinear (T a, T b, T &x) +{ + if (a != 0) + { + x = -b / a; + return 1; + } + else if (b != 0) + { + return 0; + } + else + { + return -1; + } +} + + +template +int +solveQuadratic (T a, T b, T c, T x[2]) +{ + if (a == 0) + { + return solveLinear (b, c, x[0]); + } + else + { + T D = b * b - 4 * a * c; + + if (D > 0) + { + T s = Math::sqrt (D); + T q = -(b + (b > 0 ? 1 : -1) * s) / T(2); + + x[0] = q / a; + x[1] = c / q; + return 2; + } + if (D == 0) + { + x[0] = -b / (2 * a); + return 1; + } + else + { + return 0; + } + } +} + + +template +int +solveNormalizedCubic (T r, T s, T t, T x[3]) +{ + T p = (3 * s - r * r) / 3; + T q = 2 * r * r * r / 27 - r * s / 3 + t; + T p3 = p / 3; + T q2 = q / 2; + T D = p3 * p3 * p3 + q2 * q2; + + if (D == 0 && p3 == 0) + { + x[0] = -r / 3; + x[1] = -r / 3; + x[2] = -r / 3; + return 1; + } + + std::complex u = std::pow (-q / 2 + std::sqrt (std::complex (D)), + T (1) / T (3)); + + std::complex v = -p / (T (3) * u); + + const T sqrt3 = T (1.73205080756887729352744634150587); // enough digits + // for long double + std::complex y0 (u + v); + + std::complex y1 (-(u + v) / T (2) + + (u - v) / T (2) * std::complex (0, sqrt3)); + + std::complex y2 (-(u + v) / T (2) - + (u - v) / T (2) * std::complex (0, sqrt3)); + + if (D > 0) + { + x[0] = y0.real() - r / 3; + return 1; + } + else if (D == 0) + { + x[0] = y0.real() - r / 3; + x[1] = y1.real() - r / 3; + return 2; + } + else + { + x[0] = y0.real() - r / 3; + x[1] = y1.real() - r / 3; + x[2] = y2.real() - r / 3; + return 3; + } +} + + +template +int +solveCubic (T a, T b, T c, T d, T x[3]) +{ + if (a == 0) + { + return solveQuadratic (b, c, d, x); + } + else + { + return solveNormalizedCubic (b / a, c / a, d / a, x); + } +} + +IMATH_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_IMATHROOTS_H diff --git a/OpenEXR/include/OpenEXR/ImathShear.h b/OpenEXR/include/OpenEXR/ImathShear.h new file mode 100644 index 0000000..b6f7b9a --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathShear.h @@ -0,0 +1,656 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2004-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMATHSHEAR_H +#define INCLUDED_IMATHSHEAR_H + +//---------------------------------------------------- +// +// Shear6 class template. +// +//---------------------------------------------------- + +#include "ImathExc.h" +#include "ImathLimits.h" +#include "ImathMath.h" +#include "ImathVec.h" +#include "ImathNamespace.h" +#include + + +IMATH_INTERNAL_NAMESPACE_HEADER_ENTER + +template class Shear6 +{ + public: + + //------------------- + // Access to elements + //------------------- + + T xy, xz, yz, yx, zx, zy; + + T & operator [] (int i); + const T & operator [] (int i) const; + + + //------------- + // Constructors + //------------- + + Shear6 (); // (0 0 0 0 0 0) + Shear6 (T XY, T XZ, T YZ); // (XY XZ YZ 0 0 0) + Shear6 (const Vec3 &v); // (v.x v.y v.z 0 0 0) + template // (v.x v.y v.z 0 0 0) + Shear6 (const Vec3 &v); + Shear6 (T XY, T XZ, T YZ, // (XY XZ YZ YX ZX ZY) + T YX, T ZX, T ZY); + + + //--------------------------------- + // Copy constructors and assignment + //--------------------------------- + + Shear6 (const Shear6 &h); + template Shear6 (const Shear6 &h); + + const Shear6 & operator = (const Shear6 &h); + template + const Shear6 & operator = (const Vec3 &v); + + + //---------------------- + // Compatibility with Sb + //---------------------- + + template + void setValue (S XY, S XZ, S YZ, S YX, S ZX, S ZY); + + template + void setValue (const Shear6 &h); + + template + void getValue (S &XY, S &XZ, S &YZ, + S &YX, S &ZX, S &ZY) const; + + template + void getValue (Shear6 &h) const; + + T * getValue(); + const T * getValue() const; + + + //--------- + // Equality + //--------- + + template + bool operator == (const Shear6 &h) const; + + template + bool operator != (const Shear6 &h) const; + + //----------------------------------------------------------------------- + // Compare two shears and test if they are "approximately equal": + // + // equalWithAbsError (h, e) + // + // Returns true if the coefficients of this and h are the same with + // an absolute error of no more than e, i.e., for all i + // + // abs (this[i] - h[i]) <= e + // + // equalWithRelError (h, e) + // + // Returns true if the coefficients of this and h are the same with + // a relative error of no more than e, i.e., for all i + // + // abs (this[i] - h[i]) <= e * abs (this[i]) + //----------------------------------------------------------------------- + + bool equalWithAbsError (const Shear6 &h, T e) const; + bool equalWithRelError (const Shear6 &h, T e) const; + + + //------------------------ + // Component-wise addition + //------------------------ + + const Shear6 & operator += (const Shear6 &h); + Shear6 operator + (const Shear6 &h) const; + + + //--------------------------- + // Component-wise subtraction + //--------------------------- + + const Shear6 & operator -= (const Shear6 &h); + Shear6 operator - (const Shear6 &h) const; + + + //------------------------------------ + // Component-wise multiplication by -1 + //------------------------------------ + + Shear6 operator - () const; + const Shear6 & negate (); + + + //------------------------------ + // Component-wise multiplication + //------------------------------ + + const Shear6 & operator *= (const Shear6 &h); + const Shear6 & operator *= (T a); + Shear6 operator * (const Shear6 &h) const; + Shear6 operator * (T a) const; + + + //------------------------ + // Component-wise division + //------------------------ + + const Shear6 & operator /= (const Shear6 &h); + const Shear6 & operator /= (T a); + Shear6 operator / (const Shear6 &h) const; + Shear6 operator / (T a) const; + + + //---------------------------------------------------------- + // Number of dimensions, i.e. number of elements in a Shear6 + //---------------------------------------------------------- + + static unsigned int dimensions() {return 6;} + + + //------------------------------------------------- + // Limitations of type T (see also class limits) + //------------------------------------------------- + + static T baseTypeMin() {return limits::min();} + static T baseTypeMax() {return limits::max();} + static T baseTypeSmallest() {return limits::smallest();} + static T baseTypeEpsilon() {return limits::epsilon();} + + + //-------------------------------------------------------------- + // Base type -- in templates, which accept a parameter, V, which + // could be either a Vec2 or a Shear6, you can refer to T as + // V::BaseType + //-------------------------------------------------------------- + + typedef T BaseType; +}; + + +//-------------- +// Stream output +//-------------- + +template +std::ostream & operator << (std::ostream &s, const Shear6 &h); + + +//---------------------------------------------------- +// Reverse multiplication: scalar * Shear6 +//---------------------------------------------------- + +template Shear6 operator * (S a, const Shear6 &h); + + +//------------------------- +// Typedefs for convenience +//------------------------- + +typedef Vec3 Shear3f; +typedef Vec3 Shear3d; +typedef Shear6 Shear6f; +typedef Shear6 Shear6d; + + + + +//----------------------- +// Implementation of Shear6 +//----------------------- + +template +inline T & +Shear6::operator [] (int i) +{ + return (&xy)[i]; +} + +template +inline const T & +Shear6::operator [] (int i) const +{ + return (&xy)[i]; +} + +template +inline +Shear6::Shear6 () +{ + xy = xz = yz = yx = zx = zy = 0; +} + +template +inline +Shear6::Shear6 (T XY, T XZ, T YZ) +{ + xy = XY; + xz = XZ; + yz = YZ; + yx = 0; + zx = 0; + zy = 0; +} + +template +inline +Shear6::Shear6 (const Vec3 &v) +{ + xy = v.x; + xz = v.y; + yz = v.z; + yx = 0; + zx = 0; + zy = 0; +} + +template +template +inline +Shear6::Shear6 (const Vec3 &v) +{ + xy = T (v.x); + xz = T (v.y); + yz = T (v.z); + yx = 0; + zx = 0; + zy = 0; +} + +template +inline +Shear6::Shear6 (T XY, T XZ, T YZ, T YX, T ZX, T ZY) +{ + xy = XY; + xz = XZ; + yz = YZ; + yx = YX; + zx = ZX; + zy = ZY; +} + +template +inline +Shear6::Shear6 (const Shear6 &h) +{ + xy = h.xy; + xz = h.xz; + yz = h.yz; + yx = h.yx; + zx = h.zx; + zy = h.zy; +} + +template +template +inline +Shear6::Shear6 (const Shear6 &h) +{ + xy = T (h.xy); + xz = T (h.xz); + yz = T (h.yz); + yx = T (h.yx); + zx = T (h.zx); + zy = T (h.zy); +} + +template +inline const Shear6 & +Shear6::operator = (const Shear6 &h) +{ + xy = h.xy; + xz = h.xz; + yz = h.yz; + yx = h.yx; + zx = h.zx; + zy = h.zy; + return *this; +} + +template +template +inline const Shear6 & +Shear6::operator = (const Vec3 &v) +{ + xy = T (v.x); + xz = T (v.y); + yz = T (v.z); + yx = 0; + zx = 0; + zy = 0; + return *this; +} + +template +template +inline void +Shear6::setValue (S XY, S XZ, S YZ, S YX, S ZX, S ZY) +{ + xy = T (XY); + xz = T (XZ); + yz = T (YZ); + yx = T (YX); + zx = T (ZX); + zy = T (ZY); +} + +template +template +inline void +Shear6::setValue (const Shear6 &h) +{ + xy = T (h.xy); + xz = T (h.xz); + yz = T (h.yz); + yx = T (h.yx); + zx = T (h.zx); + zy = T (h.zy); +} + +template +template +inline void +Shear6::getValue (S &XY, S &XZ, S &YZ, S &YX, S &ZX, S &ZY) const +{ + XY = S (xy); + XZ = S (xz); + YZ = S (yz); + YX = S (yx); + ZX = S (zx); + ZY = S (zy); +} + +template +template +inline void +Shear6::getValue (Shear6 &h) const +{ + h.xy = S (xy); + h.xz = S (xz); + h.yz = S (yz); + h.yx = S (yx); + h.zx = S (zx); + h.zy = S (zy); +} + +template +inline T * +Shear6::getValue() +{ + return (T *) &xy; +} + +template +inline const T * +Shear6::getValue() const +{ + return (const T *) &xy; +} + +template +template +inline bool +Shear6::operator == (const Shear6 &h) const +{ + return xy == h.xy && xz == h.xz && yz == h.yz && + yx == h.yx && zx == h.zx && zy == h.zy; +} + +template +template +inline bool +Shear6::operator != (const Shear6 &h) const +{ + return xy != h.xy || xz != h.xz || yz != h.yz || + yx != h.yx || zx != h.zx || zy != h.zy; +} + +template +bool +Shear6::equalWithAbsError (const Shear6 &h, T e) const +{ + for (int i = 0; i < 6; i++) + if (!IMATH_INTERNAL_NAMESPACE::equalWithAbsError ((*this)[i], h[i], e)) + return false; + + return true; +} + +template +bool +Shear6::equalWithRelError (const Shear6 &h, T e) const +{ + for (int i = 0; i < 6; i++) + if (!IMATH_INTERNAL_NAMESPACE::equalWithRelError ((*this)[i], h[i], e)) + return false; + + return true; +} + + +template +inline const Shear6 & +Shear6::operator += (const Shear6 &h) +{ + xy += h.xy; + xz += h.xz; + yz += h.yz; + yx += h.yx; + zx += h.zx; + zy += h.zy; + return *this; +} + +template +inline Shear6 +Shear6::operator + (const Shear6 &h) const +{ + return Shear6 (xy + h.xy, xz + h.xz, yz + h.yz, + yx + h.yx, zx + h.zx, zy + h.zy); +} + +template +inline const Shear6 & +Shear6::operator -= (const Shear6 &h) +{ + xy -= h.xy; + xz -= h.xz; + yz -= h.yz; + yx -= h.yx; + zx -= h.zx; + zy -= h.zy; + return *this; +} + +template +inline Shear6 +Shear6::operator - (const Shear6 &h) const +{ + return Shear6 (xy - h.xy, xz - h.xz, yz - h.yz, + yx - h.yx, zx - h.zx, zy - h.zy); +} + +template +inline Shear6 +Shear6::operator - () const +{ + return Shear6 (-xy, -xz, -yz, -yx, -zx, -zy); +} + +template +inline const Shear6 & +Shear6::negate () +{ + xy = -xy; + xz = -xz; + yz = -yz; + yx = -yx; + zx = -zx; + zy = -zy; + return *this; +} + +template +inline const Shear6 & +Shear6::operator *= (const Shear6 &h) +{ + xy *= h.xy; + xz *= h.xz; + yz *= h.yz; + yx *= h.yx; + zx *= h.zx; + zy *= h.zy; + return *this; +} + +template +inline const Shear6 & +Shear6::operator *= (T a) +{ + xy *= a; + xz *= a; + yz *= a; + yx *= a; + zx *= a; + zy *= a; + return *this; +} + +template +inline Shear6 +Shear6::operator * (const Shear6 &h) const +{ + return Shear6 (xy * h.xy, xz * h.xz, yz * h.yz, + yx * h.yx, zx * h.zx, zy * h.zy); +} + +template +inline Shear6 +Shear6::operator * (T a) const +{ + return Shear6 (xy * a, xz * a, yz * a, + yx * a, zx * a, zy * a); +} + +template +inline const Shear6 & +Shear6::operator /= (const Shear6 &h) +{ + xy /= h.xy; + xz /= h.xz; + yz /= h.yz; + yx /= h.yx; + zx /= h.zx; + zy /= h.zy; + return *this; +} + +template +inline const Shear6 & +Shear6::operator /= (T a) +{ + xy /= a; + xz /= a; + yz /= a; + yx /= a; + zx /= a; + zy /= a; + return *this; +} + +template +inline Shear6 +Shear6::operator / (const Shear6 &h) const +{ + return Shear6 (xy / h.xy, xz / h.xz, yz / h.yz, + yx / h.yx, zx / h.zx, zy / h.zy); +} + +template +inline Shear6 +Shear6::operator / (T a) const +{ + return Shear6 (xy / a, xz / a, yz / a, + yx / a, zx / a, zy / a); +} + + +//----------------------------- +// Stream output implementation +//----------------------------- + +template +std::ostream & +operator << (std::ostream &s, const Shear6 &h) +{ + return s << '(' + << h.xy << ' ' << h.xz << ' ' << h.yz + << h.yx << ' ' << h.zx << ' ' << h.zy + << ')'; +} + + +//----------------------------------------- +// Implementation of reverse multiplication +//----------------------------------------- + +template +inline Shear6 +operator * (S a, const Shear6 &h) +{ + return Shear6 (a * h.xy, a * h.xz, a * h.yz, + a * h.yx, a * h.zx, a * h.zy); +} + + +IMATH_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_IMATHSHEAR_H diff --git a/OpenEXR/include/OpenEXR/ImathSphere.h b/OpenEXR/include/OpenEXR/ImathSphere.h new file mode 100644 index 0000000..e8f36df --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathSphere.h @@ -0,0 +1,177 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMATHSPHERE_H +#define INCLUDED_IMATHSPHERE_H + +//------------------------------------- +// +// A 3D sphere class template +// +//------------------------------------- + +#include "ImathVec.h" +#include "ImathBox.h" +#include "ImathLine.h" +#include "ImathNamespace.h" + +IMATH_INTERNAL_NAMESPACE_HEADER_ENTER + +template +class Sphere3 +{ + public: + + Vec3 center; + T radius; + + //--------------- + // Constructors + //--------------- + + Sphere3() : center(0,0,0), radius(0) {} + Sphere3(const Vec3 &c, T r) : center(c), radius(r) {} + + //------------------------------------------------------------------- + // Utilities: + // + // s.circumscribe(b) sets center and radius of sphere s + // so that the s tightly encloses box b. + // + // s.intersectT (l, t) If sphere s and line l intersect, then + // intersectT() computes the smallest t, + // t >= 0, so that l(t) is a point on the + // sphere. intersectT() then returns true. + // + // If s and l do not intersect, intersectT() + // returns false. + // + // s.intersect (l, i) If sphere s and line l intersect, then + // intersect() calls s.intersectT(l,t) and + // computes i = l(t). + // + // If s and l do not intersect, intersect() + // returns false. + // + //------------------------------------------------------------------- + + void circumscribe(const Box > &box); + bool intersect(const Line3 &l, Vec3 &intersection) const; + bool intersectT(const Line3 &l, T &t) const; +}; + + +//-------------------- +// Convenient typedefs +//-------------------- + +typedef Sphere3 Sphere3f; +typedef Sphere3 Sphere3d; + + +//--------------- +// Implementation +//--------------- + +template +void Sphere3::circumscribe(const Box > &box) +{ + center = T(0.5) * (box.min + box.max); + radius = (box.max - center).length(); +} + + +template +bool Sphere3::intersectT(const Line3 &line, T &t) const +{ + bool doesIntersect = true; + + Vec3 v = line.pos - center; + T B = T(2.0) * (line.dir ^ v); + T C = (v ^ v) - (radius * radius); + + // compute discriminant + // if negative, there is no intersection + + T discr = B*B - T(4.0)*C; + + if (discr < 0.0) + { + // line and Sphere3 do not intersect + + doesIntersect = false; + } + else + { + // t0: (-B - sqrt(B^2 - 4AC)) / 2A (A = 1) + + T sqroot = Math::sqrt(discr); + t = (-B - sqroot) * T(0.5); + + if (t < 0.0) + { + // no intersection, try t1: (-B + sqrt(B^2 - 4AC)) / 2A (A = 1) + + t = (-B + sqroot) * T(0.5); + } + + if (t < 0.0) + doesIntersect = false; + } + + return doesIntersect; +} + + +template +bool Sphere3::intersect(const Line3 &line, Vec3 &intersection) const +{ + T t; + + if (intersectT (line, t)) + { + intersection = line(t); + return true; + } + else + { + return false; + } +} + +IMATH_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_IMATHSPHERE_H diff --git a/OpenEXR/include/OpenEXR/ImathVec.h b/OpenEXR/include/OpenEXR/ImathVec.h new file mode 100644 index 0000000..fb859eb --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathVec.h @@ -0,0 +1,2227 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2004-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMATHVEC_H +#define INCLUDED_IMATHVEC_H + +//---------------------------------------------------- +// +// 2D, 3D and 4D point/vector class templates +// +//---------------------------------------------------- + +#include "ImathExc.h" +#include "ImathLimits.h" +#include "ImathMath.h" +#include "ImathNamespace.h" + +#include + +#if (defined _WIN32 || defined _WIN64) && defined _MSC_VER +// suppress exception specification warnings +#pragma warning(push) +#pragma warning(disable:4290) +#endif + + +IMATH_INTERNAL_NAMESPACE_HEADER_ENTER + +template class Vec2; +template class Vec3; +template class Vec4; + +enum InfException {INF_EXCEPTION}; + + +template class Vec2 +{ + public: + + //------------------- + // Access to elements + //------------------- + + T x, y; + + T & operator [] (int i); + const T & operator [] (int i) const; + + + //------------- + // Constructors + //------------- + + Vec2 (); // no initialization + explicit Vec2 (T a); // (a a) + Vec2 (T a, T b); // (a b) + + + //--------------------------------- + // Copy constructors and assignment + //--------------------------------- + + Vec2 (const Vec2 &v); + template Vec2 (const Vec2 &v); + + const Vec2 & operator = (const Vec2 &v); + + + //---------------------- + // Compatibility with Sb + //---------------------- + + template + void setValue (S a, S b); + + template + void setValue (const Vec2 &v); + + template + void getValue (S &a, S &b) const; + + template + void getValue (Vec2 &v) const; + + T * getValue (); + const T * getValue () const; + + + //--------- + // Equality + //--------- + + template + bool operator == (const Vec2 &v) const; + + template + bool operator != (const Vec2 &v) const; + + + //----------------------------------------------------------------------- + // Compare two vectors and test if they are "approximately equal": + // + // equalWithAbsError (v, e) + // + // Returns true if the coefficients of this and v are the same with + // an absolute error of no more than e, i.e., for all i + // + // abs (this[i] - v[i]) <= e + // + // equalWithRelError (v, e) + // + // Returns true if the coefficients of this and v are the same with + // a relative error of no more than e, i.e., for all i + // + // abs (this[i] - v[i]) <= e * abs (this[i]) + //----------------------------------------------------------------------- + + bool equalWithAbsError (const Vec2 &v, T e) const; + bool equalWithRelError (const Vec2 &v, T e) const; + + //------------ + // Dot product + //------------ + + T dot (const Vec2 &v) const; + T operator ^ (const Vec2 &v) const; + + + //------------------------------------------------ + // Right-handed cross product, i.e. z component of + // Vec3 (this->x, this->y, 0) % Vec3 (v.x, v.y, 0) + //------------------------------------------------ + + T cross (const Vec2 &v) const; + T operator % (const Vec2 &v) const; + + + //------------------------ + // Component-wise addition + //------------------------ + + const Vec2 & operator += (const Vec2 &v); + Vec2 operator + (const Vec2 &v) const; + + + //--------------------------- + // Component-wise subtraction + //--------------------------- + + const Vec2 & operator -= (const Vec2 &v); + Vec2 operator - (const Vec2 &v) const; + + + //------------------------------------ + // Component-wise multiplication by -1 + //------------------------------------ + + Vec2 operator - () const; + const Vec2 & negate (); + + + //------------------------------ + // Component-wise multiplication + //------------------------------ + + const Vec2 & operator *= (const Vec2 &v); + const Vec2 & operator *= (T a); + Vec2 operator * (const Vec2 &v) const; + Vec2 operator * (T a) const; + + + //------------------------ + // Component-wise division + //------------------------ + + const Vec2 & operator /= (const Vec2 &v); + const Vec2 & operator /= (T a); + Vec2 operator / (const Vec2 &v) const; + Vec2 operator / (T a) const; + + + //---------------------------------------------------------------- + // Length and normalization: If v.length() is 0.0, v.normalize() + // and v.normalized() produce a null vector; v.normalizeExc() and + // v.normalizedExc() throw a NullVecExc. + // v.normalizeNonNull() and v.normalizedNonNull() are slightly + // faster than the other normalization routines, but if v.length() + // is 0.0, the result is undefined. + //---------------------------------------------------------------- + + T length () const; + T length2 () const; + + const Vec2 & normalize (); // modifies *this + const Vec2 & normalizeExc () throw (IEX_NAMESPACE::MathExc); + const Vec2 & normalizeNonNull (); + + Vec2 normalized () const; // does not modify *this + Vec2 normalizedExc () const throw (IEX_NAMESPACE::MathExc); + Vec2 normalizedNonNull () const; + + + //-------------------------------------------------------- + // Number of dimensions, i.e. number of elements in a Vec2 + //-------------------------------------------------------- + + static unsigned int dimensions() {return 2;} + + + //------------------------------------------------- + // Limitations of type T (see also class limits) + //------------------------------------------------- + + static T baseTypeMin() {return limits::min();} + static T baseTypeMax() {return limits::max();} + static T baseTypeSmallest() {return limits::smallest();} + static T baseTypeEpsilon() {return limits::epsilon();} + + + //-------------------------------------------------------------- + // Base type -- in templates, which accept a parameter, V, which + // could be either a Vec2, a Vec3, or a Vec4 you can + // refer to T as V::BaseType + //-------------------------------------------------------------- + + typedef T BaseType; + + private: + + T lengthTiny () const; +}; + + +template class Vec3 +{ + public: + + //------------------- + // Access to elements + //------------------- + + T x, y, z; + + T & operator [] (int i); + const T & operator [] (int i) const; + + + //------------- + // Constructors + //------------- + + Vec3 (); // no initialization + explicit Vec3 (T a); // (a a a) + Vec3 (T a, T b, T c); // (a b c) + + + //--------------------------------- + // Copy constructors and assignment + //--------------------------------- + + Vec3 (const Vec3 &v); + template Vec3 (const Vec3 &v); + + const Vec3 & operator = (const Vec3 &v); + + + //--------------------------------------------------------- + // Vec4 to Vec3 conversion, divides x, y and z by w: + // + // The one-argument conversion function divides by w even + // if w is zero. The result depends on how the environment + // handles floating-point exceptions. + // + // The two-argument version thows an InfPointExc exception + // if w is zero or if division by w would overflow. + //--------------------------------------------------------- + + template explicit Vec3 (const Vec4 &v); + template explicit Vec3 (const Vec4 &v, InfException); + + + //---------------------- + // Compatibility with Sb + //---------------------- + + template + void setValue (S a, S b, S c); + + template + void setValue (const Vec3 &v); + + template + void getValue (S &a, S &b, S &c) const; + + template + void getValue (Vec3 &v) const; + + T * getValue(); + const T * getValue() const; + + + //--------- + // Equality + //--------- + + template + bool operator == (const Vec3 &v) const; + + template + bool operator != (const Vec3 &v) const; + + //----------------------------------------------------------------------- + // Compare two vectors and test if they are "approximately equal": + // + // equalWithAbsError (v, e) + // + // Returns true if the coefficients of this and v are the same with + // an absolute error of no more than e, i.e., for all i + // + // abs (this[i] - v[i]) <= e + // + // equalWithRelError (v, e) + // + // Returns true if the coefficients of this and v are the same with + // a relative error of no more than e, i.e., for all i + // + // abs (this[i] - v[i]) <= e * abs (this[i]) + //----------------------------------------------------------------------- + + bool equalWithAbsError (const Vec3 &v, T e) const; + bool equalWithRelError (const Vec3 &v, T e) const; + + //------------ + // Dot product + //------------ + + T dot (const Vec3 &v) const; + T operator ^ (const Vec3 &v) const; + + + //--------------------------- + // Right-handed cross product + //--------------------------- + + Vec3 cross (const Vec3 &v) const; + const Vec3 & operator %= (const Vec3 &v); + Vec3 operator % (const Vec3 &v) const; + + + //------------------------ + // Component-wise addition + //------------------------ + + const Vec3 & operator += (const Vec3 &v); + Vec3 operator + (const Vec3 &v) const; + + + //--------------------------- + // Component-wise subtraction + //--------------------------- + + const Vec3 & operator -= (const Vec3 &v); + Vec3 operator - (const Vec3 &v) const; + + + //------------------------------------ + // Component-wise multiplication by -1 + //------------------------------------ + + Vec3 operator - () const; + const Vec3 & negate (); + + + //------------------------------ + // Component-wise multiplication + //------------------------------ + + const Vec3 & operator *= (const Vec3 &v); + const Vec3 & operator *= (T a); + Vec3 operator * (const Vec3 &v) const; + Vec3 operator * (T a) const; + + + //------------------------ + // Component-wise division + //------------------------ + + const Vec3 & operator /= (const Vec3 &v); + const Vec3 & operator /= (T a); + Vec3 operator / (const Vec3 &v) const; + Vec3 operator / (T a) const; + + + //---------------------------------------------------------------- + // Length and normalization: If v.length() is 0.0, v.normalize() + // and v.normalized() produce a null vector; v.normalizeExc() and + // v.normalizedExc() throw a NullVecExc. + // v.normalizeNonNull() and v.normalizedNonNull() are slightly + // faster than the other normalization routines, but if v.length() + // is 0.0, the result is undefined. + //---------------------------------------------------------------- + + T length () const; + T length2 () const; + + const Vec3 & normalize (); // modifies *this + const Vec3 & normalizeExc () throw (IEX_NAMESPACE::MathExc); + const Vec3 & normalizeNonNull (); + + Vec3 normalized () const; // does not modify *this + Vec3 normalizedExc () const throw (IEX_NAMESPACE::MathExc); + Vec3 normalizedNonNull () const; + + + //-------------------------------------------------------- + // Number of dimensions, i.e. number of elements in a Vec3 + //-------------------------------------------------------- + + static unsigned int dimensions() {return 3;} + + + //------------------------------------------------- + // Limitations of type T (see also class limits) + //------------------------------------------------- + + static T baseTypeMin() {return limits::min();} + static T baseTypeMax() {return limits::max();} + static T baseTypeSmallest() {return limits::smallest();} + static T baseTypeEpsilon() {return limits::epsilon();} + + + //-------------------------------------------------------------- + // Base type -- in templates, which accept a parameter, V, which + // could be either a Vec2, a Vec3, or a Vec4 you can + // refer to T as V::BaseType + //-------------------------------------------------------------- + + typedef T BaseType; + + private: + + T lengthTiny () const; +}; + + + +template class Vec4 +{ + public: + + //------------------- + // Access to elements + //------------------- + + T x, y, z, w; + + T & operator [] (int i); + const T & operator [] (int i) const; + + + //------------- + // Constructors + //------------- + + Vec4 (); // no initialization + explicit Vec4 (T a); // (a a a a) + Vec4 (T a, T b, T c, T d); // (a b c d) + + + //--------------------------------- + // Copy constructors and assignment + //--------------------------------- + + Vec4 (const Vec4 &v); + template Vec4 (const Vec4 &v); + + const Vec4 & operator = (const Vec4 &v); + + + //------------------------------------- + // Vec3 to Vec4 conversion, sets w to 1 + //------------------------------------- + + template explicit Vec4 (const Vec3 &v); + + + //--------- + // Equality + //--------- + + template + bool operator == (const Vec4 &v) const; + + template + bool operator != (const Vec4 &v) const; + + + //----------------------------------------------------------------------- + // Compare two vectors and test if they are "approximately equal": + // + // equalWithAbsError (v, e) + // + // Returns true if the coefficients of this and v are the same with + // an absolute error of no more than e, i.e., for all i + // + // abs (this[i] - v[i]) <= e + // + // equalWithRelError (v, e) + // + // Returns true if the coefficients of this and v are the same with + // a relative error of no more than e, i.e., for all i + // + // abs (this[i] - v[i]) <= e * abs (this[i]) + //----------------------------------------------------------------------- + + bool equalWithAbsError (const Vec4 &v, T e) const; + bool equalWithRelError (const Vec4 &v, T e) const; + + + //------------ + // Dot product + //------------ + + T dot (const Vec4 &v) const; + T operator ^ (const Vec4 &v) const; + + + //----------------------------------- + // Cross product is not defined in 4D + //----------------------------------- + + //------------------------ + // Component-wise addition + //------------------------ + + const Vec4 & operator += (const Vec4 &v); + Vec4 operator + (const Vec4 &v) const; + + + //--------------------------- + // Component-wise subtraction + //--------------------------- + + const Vec4 & operator -= (const Vec4 &v); + Vec4 operator - (const Vec4 &v) const; + + + //------------------------------------ + // Component-wise multiplication by -1 + //------------------------------------ + + Vec4 operator - () const; + const Vec4 & negate (); + + + //------------------------------ + // Component-wise multiplication + //------------------------------ + + const Vec4 & operator *= (const Vec4 &v); + const Vec4 & operator *= (T a); + Vec4 operator * (const Vec4 &v) const; + Vec4 operator * (T a) const; + + + //------------------------ + // Component-wise division + //------------------------ + + const Vec4 & operator /= (const Vec4 &v); + const Vec4 & operator /= (T a); + Vec4 operator / (const Vec4 &v) const; + Vec4 operator / (T a) const; + + + //---------------------------------------------------------------- + // Length and normalization: If v.length() is 0.0, v.normalize() + // and v.normalized() produce a null vector; v.normalizeExc() and + // v.normalizedExc() throw a NullVecExc. + // v.normalizeNonNull() and v.normalizedNonNull() are slightly + // faster than the other normalization routines, but if v.length() + // is 0.0, the result is undefined. + //---------------------------------------------------------------- + + T length () const; + T length2 () const; + + const Vec4 & normalize (); // modifies *this + const Vec4 & normalizeExc () throw (IEX_NAMESPACE::MathExc); + const Vec4 & normalizeNonNull (); + + Vec4 normalized () const; // does not modify *this + Vec4 normalizedExc () const throw (IEX_NAMESPACE::MathExc); + Vec4 normalizedNonNull () const; + + + //-------------------------------------------------------- + // Number of dimensions, i.e. number of elements in a Vec4 + //-------------------------------------------------------- + + static unsigned int dimensions() {return 4;} + + + //------------------------------------------------- + // Limitations of type T (see also class limits) + //------------------------------------------------- + + static T baseTypeMin() {return limits::min();} + static T baseTypeMax() {return limits::max();} + static T baseTypeSmallest() {return limits::smallest();} + static T baseTypeEpsilon() {return limits::epsilon();} + + + //-------------------------------------------------------------- + // Base type -- in templates, which accept a parameter, V, which + // could be either a Vec2, a Vec3, or a Vec4 you can + // refer to T as V::BaseType + //-------------------------------------------------------------- + + typedef T BaseType; + + private: + + T lengthTiny () const; +}; + + +//-------------- +// Stream output +//-------------- + +template +std::ostream & operator << (std::ostream &s, const Vec2 &v); + +template +std::ostream & operator << (std::ostream &s, const Vec3 &v); + +template +std::ostream & operator << (std::ostream &s, const Vec4 &v); + +//---------------------------------------------------- +// Reverse multiplication: S * Vec2 and S * Vec3 +//---------------------------------------------------- + +template Vec2 operator * (T a, const Vec2 &v); +template Vec3 operator * (T a, const Vec3 &v); +template Vec4 operator * (T a, const Vec4 &v); + + +//------------------------- +// Typedefs for convenience +//------------------------- + +typedef Vec2 V2s; +typedef Vec2 V2i; +typedef Vec2 V2f; +typedef Vec2 V2d; +typedef Vec3 V3s; +typedef Vec3 V3i; +typedef Vec3 V3f; +typedef Vec3 V3d; +typedef Vec4 V4s; +typedef Vec4 V4i; +typedef Vec4 V4f; +typedef Vec4 V4d; + + +//------------------------------------------- +// Specializations for VecN, VecN +//------------------------------------------- + +// Vec2 + +template <> short +Vec2::length () const; + +template <> const Vec2 & +Vec2::normalize (); + +template <> const Vec2 & +Vec2::normalizeExc () throw (IEX_NAMESPACE::MathExc); + +template <> const Vec2 & +Vec2::normalizeNonNull (); + +template <> Vec2 +Vec2::normalized () const; + +template <> Vec2 +Vec2::normalizedExc () const throw (IEX_NAMESPACE::MathExc); + +template <> Vec2 +Vec2::normalizedNonNull () const; + + +// Vec2 + +template <> int +Vec2::length () const; + +template <> const Vec2 & +Vec2::normalize (); + +template <> const Vec2 & +Vec2::normalizeExc () throw (IEX_NAMESPACE::MathExc); + +template <> const Vec2 & +Vec2::normalizeNonNull (); + +template <> Vec2 +Vec2::normalized () const; + +template <> Vec2 +Vec2::normalizedExc () const throw (IEX_NAMESPACE::MathExc); + +template <> Vec2 +Vec2::normalizedNonNull () const; + + +// Vec3 + +template <> short +Vec3::length () const; + +template <> const Vec3 & +Vec3::normalize (); + +template <> const Vec3 & +Vec3::normalizeExc () throw (IEX_NAMESPACE::MathExc); + +template <> const Vec3 & +Vec3::normalizeNonNull (); + +template <> Vec3 +Vec3::normalized () const; + +template <> Vec3 +Vec3::normalizedExc () const throw (IEX_NAMESPACE::MathExc); + +template <> Vec3 +Vec3::normalizedNonNull () const; + + +// Vec3 + +template <> int +Vec3::length () const; + +template <> const Vec3 & +Vec3::normalize (); + +template <> const Vec3 & +Vec3::normalizeExc () throw (IEX_NAMESPACE::MathExc); + +template <> const Vec3 & +Vec3::normalizeNonNull (); + +template <> Vec3 +Vec3::normalized () const; + +template <> Vec3 +Vec3::normalizedExc () const throw (IEX_NAMESPACE::MathExc); + +template <> Vec3 +Vec3::normalizedNonNull () const; + +// Vec4 + +template <> short +Vec4::length () const; + +template <> const Vec4 & +Vec4::normalize (); + +template <> const Vec4 & +Vec4::normalizeExc () throw (IEX_NAMESPACE::MathExc); + +template <> const Vec4 & +Vec4::normalizeNonNull (); + +template <> Vec4 +Vec4::normalized () const; + +template <> Vec4 +Vec4::normalizedExc () const throw (IEX_NAMESPACE::MathExc); + +template <> Vec4 +Vec4::normalizedNonNull () const; + + +// Vec4 + +template <> int +Vec4::length () const; + +template <> const Vec4 & +Vec4::normalize (); + +template <> const Vec4 & +Vec4::normalizeExc () throw (IEX_NAMESPACE::MathExc); + +template <> const Vec4 & +Vec4::normalizeNonNull (); + +template <> Vec4 +Vec4::normalized () const; + +template <> Vec4 +Vec4::normalizedExc () const throw (IEX_NAMESPACE::MathExc); + +template <> Vec4 +Vec4::normalizedNonNull () const; + + +//------------------------ +// Implementation of Vec2: +//------------------------ + +template +inline T & +Vec2::operator [] (int i) +{ + return (&x)[i]; +} + +template +inline const T & +Vec2::operator [] (int i) const +{ + return (&x)[i]; +} + +template +inline +Vec2::Vec2 () +{ + // empty +} + +template +inline +Vec2::Vec2 (T a) +{ + x = y = a; +} + +template +inline +Vec2::Vec2 (T a, T b) +{ + x = a; + y = b; +} + +template +inline +Vec2::Vec2 (const Vec2 &v) +{ + x = v.x; + y = v.y; +} + +template +template +inline +Vec2::Vec2 (const Vec2 &v) +{ + x = T (v.x); + y = T (v.y); +} + +template +inline const Vec2 & +Vec2::operator = (const Vec2 &v) +{ + x = v.x; + y = v.y; + return *this; +} + +template +template +inline void +Vec2::setValue (S a, S b) +{ + x = T (a); + y = T (b); +} + +template +template +inline void +Vec2::setValue (const Vec2 &v) +{ + x = T (v.x); + y = T (v.y); +} + +template +template +inline void +Vec2::getValue (S &a, S &b) const +{ + a = S (x); + b = S (y); +} + +template +template +inline void +Vec2::getValue (Vec2 &v) const +{ + v.x = S (x); + v.y = S (y); +} + +template +inline T * +Vec2::getValue() +{ + return (T *) &x; +} + +template +inline const T * +Vec2::getValue() const +{ + return (const T *) &x; +} + +template +template +inline bool +Vec2::operator == (const Vec2 &v) const +{ + return x == v.x && y == v.y; +} + +template +template +inline bool +Vec2::operator != (const Vec2 &v) const +{ + return x != v.x || y != v.y; +} + +template +bool +Vec2::equalWithAbsError (const Vec2 &v, T e) const +{ + for (int i = 0; i < 2; i++) + if (!IMATH_INTERNAL_NAMESPACE::equalWithAbsError ((*this)[i], v[i], e)) + return false; + + return true; +} + +template +bool +Vec2::equalWithRelError (const Vec2 &v, T e) const +{ + for (int i = 0; i < 2; i++) + if (!IMATH_INTERNAL_NAMESPACE::equalWithRelError ((*this)[i], v[i], e)) + return false; + + return true; +} + +template +inline T +Vec2::dot (const Vec2 &v) const +{ + return x * v.x + y * v.y; +} + +template +inline T +Vec2::operator ^ (const Vec2 &v) const +{ + return dot (v); +} + +template +inline T +Vec2::cross (const Vec2 &v) const +{ + return x * v.y - y * v.x; + +} + +template +inline T +Vec2::operator % (const Vec2 &v) const +{ + return x * v.y - y * v.x; +} + +template +inline const Vec2 & +Vec2::operator += (const Vec2 &v) +{ + x += v.x; + y += v.y; + return *this; +} + +template +inline Vec2 +Vec2::operator + (const Vec2 &v) const +{ + return Vec2 (x + v.x, y + v.y); +} + +template +inline const Vec2 & +Vec2::operator -= (const Vec2 &v) +{ + x -= v.x; + y -= v.y; + return *this; +} + +template +inline Vec2 +Vec2::operator - (const Vec2 &v) const +{ + return Vec2 (x - v.x, y - v.y); +} + +template +inline Vec2 +Vec2::operator - () const +{ + return Vec2 (-x, -y); +} + +template +inline const Vec2 & +Vec2::negate () +{ + x = -x; + y = -y; + return *this; +} + +template +inline const Vec2 & +Vec2::operator *= (const Vec2 &v) +{ + x *= v.x; + y *= v.y; + return *this; +} + +template +inline const Vec2 & +Vec2::operator *= (T a) +{ + x *= a; + y *= a; + return *this; +} + +template +inline Vec2 +Vec2::operator * (const Vec2 &v) const +{ + return Vec2 (x * v.x, y * v.y); +} + +template +inline Vec2 +Vec2::operator * (T a) const +{ + return Vec2 (x * a, y * a); +} + +template +inline const Vec2 & +Vec2::operator /= (const Vec2 &v) +{ + x /= v.x; + y /= v.y; + return *this; +} + +template +inline const Vec2 & +Vec2::operator /= (T a) +{ + x /= a; + y /= a; + return *this; +} + +template +inline Vec2 +Vec2::operator / (const Vec2 &v) const +{ + return Vec2 (x / v.x, y / v.y); +} + +template +inline Vec2 +Vec2::operator / (T a) const +{ + return Vec2 (x / a, y / a); +} + +template +T +Vec2::lengthTiny () const +{ + T absX = (x >= T (0))? x: -x; + T absY = (y >= T (0))? y: -y; + + T max = absX; + + if (max < absY) + max = absY; + + if (max == T (0)) + return T (0); + + // + // Do not replace the divisions by max with multiplications by 1/max. + // Computing 1/max can overflow but the divisions below will always + // produce results less than or equal to 1. + // + + absX /= max; + absY /= max; + + return max * Math::sqrt (absX * absX + absY * absY); +} + +template +inline T +Vec2::length () const +{ + T length2 = dot (*this); + + if (length2 < T (2) * limits::smallest()) + return lengthTiny(); + + return Math::sqrt (length2); +} + +template +inline T +Vec2::length2 () const +{ + return dot (*this); +} + +template +const Vec2 & +Vec2::normalize () +{ + T l = length(); + + if (l != T (0)) + { + // + // Do not replace the divisions by l with multiplications by 1/l. + // Computing 1/l can overflow but the divisions below will always + // produce results less than or equal to 1. + // + + x /= l; + y /= l; + } + + return *this; +} + +template +const Vec2 & +Vec2::normalizeExc () throw (IEX_NAMESPACE::MathExc) +{ + T l = length(); + + if (l == T (0)) + throw NullVecExc ("Cannot normalize null vector."); + + x /= l; + y /= l; + return *this; +} + +template +inline +const Vec2 & +Vec2::normalizeNonNull () +{ + T l = length(); + x /= l; + y /= l; + return *this; +} + +template +Vec2 +Vec2::normalized () const +{ + T l = length(); + + if (l == T (0)) + return Vec2 (T (0)); + + return Vec2 (x / l, y / l); +} + +template +Vec2 +Vec2::normalizedExc () const throw (IEX_NAMESPACE::MathExc) +{ + T l = length(); + + if (l == T (0)) + throw NullVecExc ("Cannot normalize null vector."); + + return Vec2 (x / l, y / l); +} + +template +inline +Vec2 +Vec2::normalizedNonNull () const +{ + T l = length(); + return Vec2 (x / l, y / l); +} + + +//----------------------- +// Implementation of Vec3 +//----------------------- + +template +inline T & +Vec3::operator [] (int i) +{ + return (&x)[i]; +} + +template +inline const T & +Vec3::operator [] (int i) const +{ + return (&x)[i]; +} + +template +inline +Vec3::Vec3 () +{ + // empty +} + +template +inline +Vec3::Vec3 (T a) +{ + x = y = z = a; +} + +template +inline +Vec3::Vec3 (T a, T b, T c) +{ + x = a; + y = b; + z = c; +} + +template +inline +Vec3::Vec3 (const Vec3 &v) +{ + x = v.x; + y = v.y; + z = v.z; +} + +template +template +inline +Vec3::Vec3 (const Vec3 &v) +{ + x = T (v.x); + y = T (v.y); + z = T (v.z); +} + +template +inline const Vec3 & +Vec3::operator = (const Vec3 &v) +{ + x = v.x; + y = v.y; + z = v.z; + return *this; +} + +template +template +inline +Vec3::Vec3 (const Vec4 &v) +{ + x = T (v.x / v.w); + y = T (v.y / v.w); + z = T (v.z / v.w); +} + +template +template +Vec3::Vec3 (const Vec4 &v, InfException) +{ + T vx = T (v.x); + T vy = T (v.y); + T vz = T (v.z); + T vw = T (v.w); + + T absW = (vw >= T (0))? vw: -vw; + + if (absW < 1) + { + T m = baseTypeMax() * absW; + + if (vx <= -m || vx >= m || vy <= -m || vy >= m || vz <= -m || vz >= m) + throw InfPointExc ("Cannot normalize point at infinity."); + } + + x = vx / vw; + y = vy / vw; + z = vz / vw; +} + +template +template +inline void +Vec3::setValue (S a, S b, S c) +{ + x = T (a); + y = T (b); + z = T (c); +} + +template +template +inline void +Vec3::setValue (const Vec3 &v) +{ + x = T (v.x); + y = T (v.y); + z = T (v.z); +} + +template +template +inline void +Vec3::getValue (S &a, S &b, S &c) const +{ + a = S (x); + b = S (y); + c = S (z); +} + +template +template +inline void +Vec3::getValue (Vec3 &v) const +{ + v.x = S (x); + v.y = S (y); + v.z = S (z); +} + +template +inline T * +Vec3::getValue() +{ + return (T *) &x; +} + +template +inline const T * +Vec3::getValue() const +{ + return (const T *) &x; +} + +template +template +inline bool +Vec3::operator == (const Vec3 &v) const +{ + return x == v.x && y == v.y && z == v.z; +} + +template +template +inline bool +Vec3::operator != (const Vec3 &v) const +{ + return x != v.x || y != v.y || z != v.z; +} + +template +bool +Vec3::equalWithAbsError (const Vec3 &v, T e) const +{ + for (int i = 0; i < 3; i++) + if (!IMATH_INTERNAL_NAMESPACE::equalWithAbsError ((*this)[i], v[i], e)) + return false; + + return true; +} + +template +bool +Vec3::equalWithRelError (const Vec3 &v, T e) const +{ + for (int i = 0; i < 3; i++) + if (!IMATH_INTERNAL_NAMESPACE::equalWithRelError ((*this)[i], v[i], e)) + return false; + + return true; +} + +template +inline T +Vec3::dot (const Vec3 &v) const +{ + return x * v.x + y * v.y + z * v.z; +} + +template +inline T +Vec3::operator ^ (const Vec3 &v) const +{ + return dot (v); +} + +template +inline Vec3 +Vec3::cross (const Vec3 &v) const +{ + return Vec3 (y * v.z - z * v.y, + z * v.x - x * v.z, + x * v.y - y * v.x); +} + +template +inline const Vec3 & +Vec3::operator %= (const Vec3 &v) +{ + T a = y * v.z - z * v.y; + T b = z * v.x - x * v.z; + T c = x * v.y - y * v.x; + x = a; + y = b; + z = c; + return *this; +} + +template +inline Vec3 +Vec3::operator % (const Vec3 &v) const +{ + return Vec3 (y * v.z - z * v.y, + z * v.x - x * v.z, + x * v.y - y * v.x); +} + +template +inline const Vec3 & +Vec3::operator += (const Vec3 &v) +{ + x += v.x; + y += v.y; + z += v.z; + return *this; +} + +template +inline Vec3 +Vec3::operator + (const Vec3 &v) const +{ + return Vec3 (x + v.x, y + v.y, z + v.z); +} + +template +inline const Vec3 & +Vec3::operator -= (const Vec3 &v) +{ + x -= v.x; + y -= v.y; + z -= v.z; + return *this; +} + +template +inline Vec3 +Vec3::operator - (const Vec3 &v) const +{ + return Vec3 (x - v.x, y - v.y, z - v.z); +} + +template +inline Vec3 +Vec3::operator - () const +{ + return Vec3 (-x, -y, -z); +} + +template +inline const Vec3 & +Vec3::negate () +{ + x = -x; + y = -y; + z = -z; + return *this; +} + +template +inline const Vec3 & +Vec3::operator *= (const Vec3 &v) +{ + x *= v.x; + y *= v.y; + z *= v.z; + return *this; +} + +template +inline const Vec3 & +Vec3::operator *= (T a) +{ + x *= a; + y *= a; + z *= a; + return *this; +} + +template +inline Vec3 +Vec3::operator * (const Vec3 &v) const +{ + return Vec3 (x * v.x, y * v.y, z * v.z); +} + +template +inline Vec3 +Vec3::operator * (T a) const +{ + return Vec3 (x * a, y * a, z * a); +} + +template +inline const Vec3 & +Vec3::operator /= (const Vec3 &v) +{ + x /= v.x; + y /= v.y; + z /= v.z; + return *this; +} + +template +inline const Vec3 & +Vec3::operator /= (T a) +{ + x /= a; + y /= a; + z /= a; + return *this; +} + +template +inline Vec3 +Vec3::operator / (const Vec3 &v) const +{ + return Vec3 (x / v.x, y / v.y, z / v.z); +} + +template +inline Vec3 +Vec3::operator / (T a) const +{ + return Vec3 (x / a, y / a, z / a); +} + +template +T +Vec3::lengthTiny () const +{ + T absX = (x >= T (0))? x: -x; + T absY = (y >= T (0))? y: -y; + T absZ = (z >= T (0))? z: -z; + + T max = absX; + + if (max < absY) + max = absY; + + if (max < absZ) + max = absZ; + + if (max == T (0)) + return T (0); + + // + // Do not replace the divisions by max with multiplications by 1/max. + // Computing 1/max can overflow but the divisions below will always + // produce results less than or equal to 1. + // + + absX /= max; + absY /= max; + absZ /= max; + + return max * Math::sqrt (absX * absX + absY * absY + absZ * absZ); +} + +template +inline T +Vec3::length () const +{ + T length2 = dot (*this); + + if (length2 < T (2) * limits::smallest()) + return lengthTiny(); + + return Math::sqrt (length2); +} + +template +inline T +Vec3::length2 () const +{ + return dot (*this); +} + +template +const Vec3 & +Vec3::normalize () +{ + T l = length(); + + if (l != T (0)) + { + // + // Do not replace the divisions by l with multiplications by 1/l. + // Computing 1/l can overflow but the divisions below will always + // produce results less than or equal to 1. + // + + x /= l; + y /= l; + z /= l; + } + + return *this; +} + +template +const Vec3 & +Vec3::normalizeExc () throw (IEX_NAMESPACE::MathExc) +{ + T l = length(); + + if (l == T (0)) + throw NullVecExc ("Cannot normalize null vector."); + + x /= l; + y /= l; + z /= l; + return *this; +} + +template +inline +const Vec3 & +Vec3::normalizeNonNull () +{ + T l = length(); + x /= l; + y /= l; + z /= l; + return *this; +} + +template +Vec3 +Vec3::normalized () const +{ + T l = length(); + + if (l == T (0)) + return Vec3 (T (0)); + + return Vec3 (x / l, y / l, z / l); +} + +template +Vec3 +Vec3::normalizedExc () const throw (IEX_NAMESPACE::MathExc) +{ + T l = length(); + + if (l == T (0)) + throw NullVecExc ("Cannot normalize null vector."); + + return Vec3 (x / l, y / l, z / l); +} + +template +inline +Vec3 +Vec3::normalizedNonNull () const +{ + T l = length(); + return Vec3 (x / l, y / l, z / l); +} + + +//----------------------- +// Implementation of Vec4 +//----------------------- + +template +inline T & +Vec4::operator [] (int i) +{ + return (&x)[i]; +} + +template +inline const T & +Vec4::operator [] (int i) const +{ + return (&x)[i]; +} + +template +inline +Vec4::Vec4 () +{ + // empty +} + +template +inline +Vec4::Vec4 (T a) +{ + x = y = z = w = a; +} + +template +inline +Vec4::Vec4 (T a, T b, T c, T d) +{ + x = a; + y = b; + z = c; + w = d; +} + +template +inline +Vec4::Vec4 (const Vec4 &v) +{ + x = v.x; + y = v.y; + z = v.z; + w = v.w; +} + +template +template +inline +Vec4::Vec4 (const Vec4 &v) +{ + x = T (v.x); + y = T (v.y); + z = T (v.z); + w = T (v.w); +} + +template +inline const Vec4 & +Vec4::operator = (const Vec4 &v) +{ + x = v.x; + y = v.y; + z = v.z; + w = v.w; + return *this; +} + +template +template +inline +Vec4::Vec4 (const Vec3 &v) +{ + x = T (v.x); + y = T (v.y); + z = T (v.z); + w = T (1); +} + +template +template +inline bool +Vec4::operator == (const Vec4 &v) const +{ + return x == v.x && y == v.y && z == v.z && w == v.w; +} + +template +template +inline bool +Vec4::operator != (const Vec4 &v) const +{ + return x != v.x || y != v.y || z != v.z || w != v.w; +} + +template +bool +Vec4::equalWithAbsError (const Vec4 &v, T e) const +{ + for (int i = 0; i < 4; i++) + if (!IMATH_INTERNAL_NAMESPACE::equalWithAbsError ((*this)[i], v[i], e)) + return false; + + return true; +} + +template +bool +Vec4::equalWithRelError (const Vec4 &v, T e) const +{ + for (int i = 0; i < 4; i++) + if (!IMATH_INTERNAL_NAMESPACE::equalWithRelError ((*this)[i], v[i], e)) + return false; + + return true; +} + +template +inline T +Vec4::dot (const Vec4 &v) const +{ + return x * v.x + y * v.y + z * v.z + w * v.w; +} + +template +inline T +Vec4::operator ^ (const Vec4 &v) const +{ + return dot (v); +} + + +template +inline const Vec4 & +Vec4::operator += (const Vec4 &v) +{ + x += v.x; + y += v.y; + z += v.z; + w += v.w; + return *this; +} + +template +inline Vec4 +Vec4::operator + (const Vec4 &v) const +{ + return Vec4 (x + v.x, y + v.y, z + v.z, w + v.w); +} + +template +inline const Vec4 & +Vec4::operator -= (const Vec4 &v) +{ + x -= v.x; + y -= v.y; + z -= v.z; + w -= v.w; + return *this; +} + +template +inline Vec4 +Vec4::operator - (const Vec4 &v) const +{ + return Vec4 (x - v.x, y - v.y, z - v.z, w - v.w); +} + +template +inline Vec4 +Vec4::operator - () const +{ + return Vec4 (-x, -y, -z, -w); +} + +template +inline const Vec4 & +Vec4::negate () +{ + x = -x; + y = -y; + z = -z; + w = -w; + return *this; +} + +template +inline const Vec4 & +Vec4::operator *= (const Vec4 &v) +{ + x *= v.x; + y *= v.y; + z *= v.z; + w *= v.w; + return *this; +} + +template +inline const Vec4 & +Vec4::operator *= (T a) +{ + x *= a; + y *= a; + z *= a; + w *= a; + return *this; +} + +template +inline Vec4 +Vec4::operator * (const Vec4 &v) const +{ + return Vec4 (x * v.x, y * v.y, z * v.z, w * v.w); +} + +template +inline Vec4 +Vec4::operator * (T a) const +{ + return Vec4 (x * a, y * a, z * a, w * a); +} + +template +inline const Vec4 & +Vec4::operator /= (const Vec4 &v) +{ + x /= v.x; + y /= v.y; + z /= v.z; + w /= v.w; + return *this; +} + +template +inline const Vec4 & +Vec4::operator /= (T a) +{ + x /= a; + y /= a; + z /= a; + w /= a; + return *this; +} + +template +inline Vec4 +Vec4::operator / (const Vec4 &v) const +{ + return Vec4 (x / v.x, y / v.y, z / v.z, w / v.w); +} + +template +inline Vec4 +Vec4::operator / (T a) const +{ + return Vec4 (x / a, y / a, z / a, w / a); +} + +template +T +Vec4::lengthTiny () const +{ + T absX = (x >= T (0))? x: -x; + T absY = (y >= T (0))? y: -y; + T absZ = (z >= T (0))? z: -z; + T absW = (w >= T (0))? w: -w; + + T max = absX; + + if (max < absY) + max = absY; + + if (max < absZ) + max = absZ; + + if (max < absW) + max = absW; + + if (max == T (0)) + return T (0); + + // + // Do not replace the divisions by max with multiplications by 1/max. + // Computing 1/max can overflow but the divisions below will always + // produce results less than or equal to 1. + // + + absX /= max; + absY /= max; + absZ /= max; + absW /= max; + + return max * + Math::sqrt (absX * absX + absY * absY + absZ * absZ + absW * absW); +} + +template +inline T +Vec4::length () const +{ + T length2 = dot (*this); + + if (length2 < T (2) * limits::smallest()) + return lengthTiny(); + + return Math::sqrt (length2); +} + +template +inline T +Vec4::length2 () const +{ + return dot (*this); +} + +template +const Vec4 & +Vec4::normalize () +{ + T l = length(); + + if (l != T (0)) + { + // + // Do not replace the divisions by l with multiplications by 1/l. + // Computing 1/l can overflow but the divisions below will always + // produce results less than or equal to 1. + // + + x /= l; + y /= l; + z /= l; + w /= l; + } + + return *this; +} + +template +const Vec4 & +Vec4::normalizeExc () throw (IEX_NAMESPACE::MathExc) +{ + T l = length(); + + if (l == T (0)) + throw NullVecExc ("Cannot normalize null vector."); + + x /= l; + y /= l; + z /= l; + w /= l; + return *this; +} + +template +inline +const Vec4 & +Vec4::normalizeNonNull () +{ + T l = length(); + x /= l; + y /= l; + z /= l; + w /= l; + return *this; +} + +template +Vec4 +Vec4::normalized () const +{ + T l = length(); + + if (l == T (0)) + return Vec4 (T (0)); + + return Vec4 (x / l, y / l, z / l, w / l); +} + +template +Vec4 +Vec4::normalizedExc () const throw (IEX_NAMESPACE::MathExc) +{ + T l = length(); + + if (l == T (0)) + throw NullVecExc ("Cannot normalize null vector."); + + return Vec4 (x / l, y / l, z / l, w / l); +} + +template +inline +Vec4 +Vec4::normalizedNonNull () const +{ + T l = length(); + return Vec4 (x / l, y / l, z / l, w / l); +} + +//----------------------------- +// Stream output implementation +//----------------------------- + +template +std::ostream & +operator << (std::ostream &s, const Vec2 &v) +{ + return s << '(' << v.x << ' ' << v.y << ')'; +} + +template +std::ostream & +operator << (std::ostream &s, const Vec3 &v) +{ + return s << '(' << v.x << ' ' << v.y << ' ' << v.z << ')'; +} + +template +std::ostream & +operator << (std::ostream &s, const Vec4 &v) +{ + return s << '(' << v.x << ' ' << v.y << ' ' << v.z << ' ' << v.w << ')'; +} + + +//----------------------------------------- +// Implementation of reverse multiplication +//----------------------------------------- + +template +inline Vec2 +operator * (T a, const Vec2 &v) +{ + return Vec2 (a * v.x, a * v.y); +} + +template +inline Vec3 +operator * (T a, const Vec3 &v) +{ + return Vec3 (a * v.x, a * v.y, a * v.z); +} + +template +inline Vec4 +operator * (T a, const Vec4 &v) +{ + return Vec4 (a * v.x, a * v.y, a * v.z, a * v.w); +} + + +#if (defined _WIN32 || defined _WIN64) && defined _MSC_VER +#pragma warning(pop) +#endif + +IMATH_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_IMATHVEC_H diff --git a/OpenEXR/include/OpenEXR/ImathVecAlgo.h b/OpenEXR/include/OpenEXR/ImathVecAlgo.h new file mode 100644 index 0000000..28bab6b --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImathVecAlgo.h @@ -0,0 +1,147 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002-2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMATHVECALGO_H +#define INCLUDED_IMATHVECALGO_H + +//------------------------------------------------------------------------- +// +// This file contains algorithms applied to or in conjunction +// with points (Imath::Vec2 and Imath::Vec3). +// The assumption made is that these functions are called much +// less often than the basic point functions or these functions +// require more support classes. +// +//------------------------------------------------------------------------- + +#include "ImathVec.h" +#include "ImathLimits.h" +#include "ImathNamespace.h" + +IMATH_INTERNAL_NAMESPACE_HEADER_ENTER + + +//----------------------------------------------------------------- +// Find the projection of vector t onto vector s (Vec2, Vec3, Vec4) +//----------------------------------------------------------------- + +template Vec project (const Vec &s, const Vec &t); + + +//------------------------------------------------ +// Find a vector that is perpendicular to s and +// in the same plane as s and t (Vec2, Vec3, Vec4) +//------------------------------------------------ + +template Vec orthogonal (const Vec &s, const Vec &t); + + +//----------------------------------------------- +// Find the direction of a ray s after reflection +// off a plane with normal t (Vec2, Vec3, Vec4) +//----------------------------------------------- + +template Vec reflect (const Vec &s, const Vec &t); + + +//-------------------------------------------------------------------- +// Find the vertex of triangle (v0, v1, v2) that is closest to point p +// (Vec2, Vec3, Vec4) +//-------------------------------------------------------------------- + +template Vec closestVertex (const Vec &v0, + const Vec &v1, + const Vec &v2, + const Vec &p); + +//--------------- +// Implementation +//--------------- + +template +Vec +project (const Vec &s, const Vec &t) +{ + Vec sNormalized = s.normalized(); + return sNormalized * (sNormalized ^ t); +} + +template +Vec +orthogonal (const Vec &s, const Vec &t) +{ + return t - project (s, t); +} + +template +Vec +reflect (const Vec &s, const Vec &t) +{ + return s - typename Vec::BaseType(2) * (s - project(t, s)); +} + +template +Vec +closestVertex(const Vec &v0, + const Vec &v1, + const Vec &v2, + const Vec &p) +{ + Vec nearest = v0; + typename Vec::BaseType neardot = (v0 - p).length2(); + typename Vec::BaseType tmp = (v1 - p).length2(); + + if (tmp < neardot) + { + neardot = tmp; + nearest = v1; + } + + tmp = (v2 - p).length2(); + + if (tmp < neardot) + { + neardot = tmp; + nearest = v2; + } + + return nearest; +} + + +IMATH_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif // INCLUDED_IMATHVECALGO_H diff --git a/OpenEXR/include/OpenEXR/ImfAcesFile.h b/OpenEXR/include/OpenEXR/ImfAcesFile.h new file mode 100644 index 0000000..b801a86 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfAcesFile.h @@ -0,0 +1,324 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2007, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMF_ACES_FILE_H +#define INCLUDED_IMF_ACES_FILE_H + + +//----------------------------------------------------------------------------- +// +// ACES image file I/O. +// +// This header file declares two classes that directly support +// image file input and output according to the Academy Image +// Interchange Framework. +// +// The Academy Image Interchange file format is a subset of OpenEXR: +// +// - Images are stored as scanlines. Tiles are not allowed. +// +// - Images contain three color channels, either +// R, G, B (red, green, blue) or +// Y, RY, BY (luminance, sub-sampled chroma) +// +// - Images may optionally contain an alpha channel. +// +// - Only three compression types are allowed: +// - NO_COMPRESSION (file is not compressed) +// - PIZ_COMPRESSION (lossless) +// - B44A_COMPRESSION (lossy) +// +// - The "chromaticities" header attribute must specify +// the ACES RGB primaries and white point. +// +// class AcesOutputFile writes an OpenEXR file, enforcing the +// restrictions listed above. Pixel data supplied by application +// software must already be in the ACES RGB space. +// +// class AcesInputFile reads an OpenEXR file. Pixel data delivered +// to application software is guaranteed to be in the ACES RGB space. +// If the RGB space of the file is not the same as the ACES space, +// then the pixels are automatically converted: the pixels are +// converted to CIE XYZ, a color adaptation transform shifts the +// white point, and the result is converted to ACES RGB. +// +//----------------------------------------------------------------------------- + +#include "ImfHeader.h" +#include "ImfRgba.h" +#include "ImathVec.h" +#include "ImathBox.h" +#include "ImfThreading.h" +#include "ImfNamespace.h" +#include "ImfExport.h" +#include "ImfForward.h" + +#include + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +// +// ACES red, green, blue and white-point chromaticities. +// + +const Chromaticities & acesChromaticities (); + + +// +// ACES output file. +// + +class IMF_EXPORT AcesOutputFile +{ + public: + + //--------------------------------------------------- + // Constructor -- header is constructed by the caller + //--------------------------------------------------- + + AcesOutputFile (const std::string &name, + const Header &header, + RgbaChannels rgbaChannels = WRITE_RGBA, + int numThreads = globalThreadCount()); + + + //---------------------------------------------------- + // Constructor -- header is constructed by the caller, + // file is opened by the caller, destructor will not + // automatically close the file. + //---------------------------------------------------- + + AcesOutputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &os, + const Header &header, + RgbaChannels rgbaChannels = WRITE_RGBA, + int numThreads = globalThreadCount()); + + + //---------------------------------------------------------------- + // Constructor -- header data are explicitly specified as function + // call arguments (empty dataWindow means "same as displayWindow") + //---------------------------------------------------------------- + + AcesOutputFile (const std::string &name, + const IMATH_NAMESPACE::Box2i &displayWindow, + const IMATH_NAMESPACE::Box2i &dataWindow = IMATH_NAMESPACE::Box2i(), + RgbaChannels rgbaChannels = WRITE_RGBA, + float pixelAspectRatio = 1, + const IMATH_NAMESPACE::V2f screenWindowCenter = IMATH_NAMESPACE::V2f (0, 0), + float screenWindowWidth = 1, + LineOrder lineOrder = INCREASING_Y, + Compression compression = PIZ_COMPRESSION, + int numThreads = globalThreadCount()); + + + //----------------------------------------------- + // Constructor -- like the previous one, but both + // the display window and the data window are + // Box2i (V2i (0, 0), V2i (width - 1, height -1)) + //----------------------------------------------- + + AcesOutputFile (const std::string &name, + int width, + int height, + RgbaChannels rgbaChannels = WRITE_RGBA, + float pixelAspectRatio = 1, + const IMATH_NAMESPACE::V2f screenWindowCenter = IMATH_NAMESPACE::V2f (0, 0), + float screenWindowWidth = 1, + LineOrder lineOrder = INCREASING_Y, + Compression compression = PIZ_COMPRESSION, + int numThreads = globalThreadCount()); + + + //----------- + // Destructor + //----------- + + virtual ~AcesOutputFile (); + + + //------------------------------------------------ + // Define a frame buffer as the pixel data source: + // Pixel (x, y) is at address + // + // base + x * xStride + y * yStride + // + //------------------------------------------------ + + void setFrameBuffer (const Rgba *base, + size_t xStride, + size_t yStride); + + + //------------------------------------------------- + // Write pixel data (see class Imf::OutputFile) + // The pixels are assumed to contain ACES RGB data. + //------------------------------------------------- + + void writePixels (int numScanLines = 1); + int currentScanLine () const; + + + //-------------------------- + // Access to the file header + //-------------------------- + + const Header & header () const; + const IMATH_NAMESPACE::Box2i & displayWindow () const; + const IMATH_NAMESPACE::Box2i & dataWindow () const; + float pixelAspectRatio () const; + const IMATH_NAMESPACE::V2f screenWindowCenter () const; + float screenWindowWidth () const; + LineOrder lineOrder () const; + Compression compression () const; + RgbaChannels channels () const; + + + // -------------------------------------------------------------------- + // Update the preview image (see Imf::OutputFile::updatePreviewImage()) + // -------------------------------------------------------------------- + + void updatePreviewImage (const PreviewRgba[]); + + + private: + + AcesOutputFile (const AcesOutputFile &); // not implemented + AcesOutputFile & operator = (const AcesOutputFile &); // not implemented + + class Data; + + Data * _data; +}; + + +// +// ACES input file +// + +class IMF_EXPORT AcesInputFile +{ + public: + + //------------------------------------------------------- + // Constructor -- opens the file with the specified name, + // destructor will automatically close the file. + //------------------------------------------------------- + + AcesInputFile (const std::string &name, + int numThreads = globalThreadCount()); + + + //----------------------------------------------------------- + // Constructor -- attaches the new AcesInputFile object to a + // file that has already been opened by the caller. + // Destroying the AcesInputFile object will not automatically + // close the file. + //----------------------------------------------------------- + + AcesInputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is, + int numThreads = globalThreadCount()); + + + //----------- + // Destructor + //----------- + + virtual ~AcesInputFile (); + + + //----------------------------------------------------- + // Define a frame buffer as the pixel data destination: + // Pixel (x, y) is at address + // + // base + x * xStride + y * yStride + // + //----------------------------------------------------- + + void setFrameBuffer (Rgba *base, + size_t xStride, + size_t yStride); + + + //-------------------------------------------- + // Read pixel data (see class Imf::InputFile) + // Pixels returned will contain ACES RGB data. + //-------------------------------------------- + + void readPixels (int scanLine1, int scanLine2); + void readPixels (int scanLine); + + + //-------------------------- + // Access to the file header + //-------------------------- + + const Header & header () const; + const IMATH_NAMESPACE::Box2i & displayWindow () const; + const IMATH_NAMESPACE::Box2i & dataWindow () const; + float pixelAspectRatio () const; + const IMATH_NAMESPACE::V2f screenWindowCenter () const; + float screenWindowWidth () const; + LineOrder lineOrder () const; + Compression compression () const; + RgbaChannels channels () const; + const char * fileName () const; + bool isComplete () const; + + + //---------------------------------- + // Access to the file format version + //---------------------------------- + + int version () const; + + private: + + AcesInputFile (const AcesInputFile &); // not implemented + AcesInputFile & operator = (const AcesInputFile &); // not implemented + + class Data; + + Data * _data; +}; + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + + + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfArray.h b/OpenEXR/include/OpenEXR/ImfArray.h new file mode 100644 index 0000000..6a80d8f --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfArray.h @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMF_ARRAY_H +#define INCLUDED_IMF_ARRAY_H + +#include "ImfForward.h" + +//------------------------------------------------------------------------- +// +// class Array +// class Array2D +// +// "Arrays of T" whose sizes are not known at compile time. +// When an array goes out of scope, its elements are automatically +// deleted. +// +// Usage example: +// +// struct C +// { +// C () {std::cout << "C::C (" << this << ")\n";}; +// virtual ~C () {std::cout << "C::~C (" << this << ")\n";}; +// }; +// +// int +// main () +// { +// Array a(3); +// +// C &b = a[1]; +// const C &c = a[1]; +// C *d = a + 2; +// const C *e = a; +// +// return 0; +// } +// +//------------------------------------------------------------------------- + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + +template +class Array +{ + public: + + //----------------------------- + // Constructors and destructors + //----------------------------- + + Array () {_data = 0; _size = 0;} + Array (long size) {_data = new T[size]; _size = size;} + ~Array () {delete [] _data;} + + + //----------------------------- + // Access to the array elements + //----------------------------- + + operator T * () {return _data;} + operator const T * () const {return _data;} + + + //------------------------------------------------------ + // Resize and clear the array (the contents of the array + // are not preserved across the resize operation). + // + // resizeEraseUnsafe() is more memory efficient than + // resizeErase() because it deletes the old memory block + // before allocating a new one, but if allocating the + // new block throws an exception, resizeEraseUnsafe() + // leaves the array in an unusable state. + // + //------------------------------------------------------ + + void resizeErase (long size); + void resizeEraseUnsafe (long size); + + + //------------------------------- + // Return the size of this array. + //------------------------------- + + long size() const {return _size;} + + + private: + + Array (const Array &); // Copying and assignment + Array & operator = (const Array &); // are not implemented + + long _size; + T * _data; +}; + + +template +class Array2D +{ + public: + + //----------------------------- + // Constructors and destructors + //----------------------------- + + Array2D (); // empty array, 0 by 0 elements + Array2D (long sizeX, long sizeY); // sizeX by sizeY elements + ~Array2D (); + + + //----------------------------- + // Access to the array elements + //----------------------------- + + T * operator [] (long x); + const T * operator [] (long x) const; + + + //------------------------------------------------------ + // Resize and clear the array (the contents of the array + // are not preserved across the resize operation). + // + // resizeEraseUnsafe() is more memory efficient than + // resizeErase() because it deletes the old memory block + // before allocating a new one, but if allocating the + // new block throws an exception, resizeEraseUnsafe() + // leaves the array in an unusable state. + // + //------------------------------------------------------ + + void resizeErase (long sizeX, long sizeY); + void resizeEraseUnsafe (long sizeX, long sizeY); + + + //------------------------------- + // Return the size of this array. + //------------------------------- + + long height() const {return _sizeX;} + long width() const {return _sizeY;} + + + private: + + Array2D (const Array2D &); // Copying and assignment + Array2D & operator = (const Array2D &); // are not implemented + + long _sizeX; + long _sizeY; + T * _data; +}; + + +//--------------- +// Implementation +//--------------- + +template +inline void +Array::resizeErase (long size) +{ + T *tmp = new T[size]; + delete [] _data; + _size = size; + _data = tmp; +} + + +template +inline void +Array::resizeEraseUnsafe (long size) +{ + delete [] _data; + _data = 0; + _size = 0; + _data = new T[size]; + _size = size; +} + + +template +inline +Array2D::Array2D (): + _sizeX(0), _sizeY (0), _data (0) +{ + // emtpy +} + + +template +inline +Array2D::Array2D (long sizeX, long sizeY): + _sizeX (sizeX), _sizeY (sizeY), _data (new T[sizeX * sizeY]) +{ + // emtpy +} + + +template +inline +Array2D::~Array2D () +{ + delete [] _data; +} + + +template +inline T * +Array2D::operator [] (long x) +{ + return _data + x * _sizeY; +} + + +template +inline const T * +Array2D::operator [] (long x) const +{ + return _data + x * _sizeY; +} + + +template +inline void +Array2D::resizeErase (long sizeX, long sizeY) +{ + T *tmp = new T[sizeX * sizeY]; + delete [] _data; + _sizeX = sizeX; + _sizeY = sizeY; + _data = tmp; +} + + +template +inline void +Array2D::resizeEraseUnsafe (long sizeX, long sizeY) +{ + delete [] _data; + _data = 0; + _sizeX = 0; + _sizeY = 0; + _data = new T[sizeX * sizeY]; + _sizeX = sizeX; + _sizeY = sizeY; +} + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfAttribute.h b/OpenEXR/include/OpenEXR/ImfAttribute.h new file mode 100644 index 0000000..86762ad --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfAttribute.h @@ -0,0 +1,407 @@ +/////////////////////////////////////////////////////////////////////////// +// +// 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMF_ATTRIBUTE_H +#define INCLUDED_IMF_ATTRIBUTE_H + +//----------------------------------------------------------------------------- +// +// class Attribute +// +//----------------------------------------------------------------------------- + +#include "IexBaseExc.h" +#include "ImfIO.h" +#include "ImfXdr.h" +#include "ImfForward.h" +#include "ImfExport.h" +#include "ImfNamespace.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +class IMF_EXPORT Attribute +{ + public: + + //--------------------------- + // Constructor and destructor + //--------------------------- + + Attribute (); + virtual ~Attribute (); + + + //------------------------------- + // Get this attribute's type name + //------------------------------- + + virtual const char * typeName () const = 0; + + + //------------------------------ + // Make a copy of this attribute + //------------------------------ + + virtual Attribute * copy () const = 0; + + + //---------------------------------------- + // Type-specific attribute I/O and copying + //---------------------------------------- + + virtual void writeValueTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &os, + int version) const = 0; + + virtual void readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is, + int size, + int version) = 0; + + virtual void copyValueFrom (const Attribute &other) = 0; + + + //------------------ + // Attribute factory + //------------------ + + static Attribute * newAttribute (const char typeName[]); + + + //----------------------------------------------------------- + // Test if a given attribute type has already been registered + //----------------------------------------------------------- + + static bool knownType (const char typeName[]); + + + protected: + + //-------------------------------------------------- + // Register an attribute type so that newAttribute() + // knows how to make objects of this type. + //-------------------------------------------------- + + static void registerAttributeType (const char typeName[], + Attribute *(*newAttribute)()); + + //------------------------------------------------------ + // Un-register an attribute type so that newAttribute() + // no longer knows how to make objects of this type (for + // debugging only). + //------------------------------------------------------ + + static void unRegisterAttributeType (const char typeName[]); +}; + + +//------------------------------------------------- +// Class template for attributes of a specific type +//------------------------------------------------- + +template +class TypedAttribute: public Attribute +{ + public: + + //---------------------------- + // Constructors and destructor + //------------_--------------- + + TypedAttribute (); + TypedAttribute (const T &value); + TypedAttribute (const TypedAttribute &other); + virtual ~TypedAttribute (); + + + //-------------------------------- + // Access to the attribute's value + //-------------------------------- + + T & value (); + const T & value () const; + + + //-------------------------------- + // Get this attribute's type name. + //-------------------------------- + + virtual const char * typeName () const; + + + //--------------------------------------------------------- + // Static version of typeName() + // This function must be specialized for each value type T. + //--------------------------------------------------------- + + static const char * staticTypeName (); + + + //--------------------- + // Make a new attribute + //--------------------- + + static Attribute * makeNewAttribute (); + + + //------------------------------ + // Make a copy of this attribute + //------------------------------ + + virtual Attribute * copy () const; + + + //----------------------------------------------------------------- + // Type-specific attribute I/O and copying. + // Depending on type T, these functions may have to be specialized. + //----------------------------------------------------------------- + + virtual void writeValueTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &os, + int version) const; + + virtual void readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is, + int size, + int version); + + virtual void copyValueFrom (const Attribute &other); + + + //------------------------------------------------------------ + // Dynamic casts that throw exceptions instead of returning 0. + //------------------------------------------------------------ + + static TypedAttribute * cast (Attribute *attribute); + static const TypedAttribute * cast (const Attribute *attribute); + static TypedAttribute & cast (Attribute &attribute); + static const TypedAttribute & cast (const Attribute &attribute); + + + //--------------------------------------------------------------- + // Register this attribute type so that Attribute::newAttribute() + // knows how to make objects of this type. + // + // Note that this function is not thread-safe because it modifies + // a global variable in the IlmIlm library. A thread in a multi- + // threaded program may call registerAttributeType() only when no + // other thread is accessing any functions or classes in the + // IlmImf library. + // + //--------------------------------------------------------------- + + static void registerAttributeType (); + + + //----------------------------------------------------- + // Un-register this attribute type (for debugging only) + //----------------------------------------------------- + + static void unRegisterAttributeType (); + + + private: + + T _value; +}; + +//------------------------------------ +// Implementation of TypedAttribute +//------------------------------------ +template +TypedAttribute::TypedAttribute (): + Attribute (), + _value (T()) +{ + // empty +} + + +template +TypedAttribute::TypedAttribute (const T & value): + Attribute (), + _value (value) +{ + // empty +} + + +template +TypedAttribute::TypedAttribute (const TypedAttribute &other): + Attribute (other), + _value () +{ + copyValueFrom (other); +} + + +template +TypedAttribute::~TypedAttribute () +{ + // empty +} + + +template +inline T & +TypedAttribute::value () +{ + return _value; +} + + +template +inline const T & +TypedAttribute::value () const +{ + return _value; +} + + +template +const char * +TypedAttribute::typeName () const +{ + return staticTypeName(); +} + + +template +Attribute * +TypedAttribute::makeNewAttribute () +{ + return new TypedAttribute(); +} + + +template +Attribute * +TypedAttribute::copy () const +{ + Attribute * attribute = new TypedAttribute(); + attribute->copyValueFrom (*this); + return attribute; +} + + +template +void +TypedAttribute::writeValueTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &os, + int version) const +{ + OPENEXR_IMF_INTERNAL_NAMESPACE::Xdr::write (os, _value); +} + + +template +void +TypedAttribute::readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is, + int size, + int version) +{ + OPENEXR_IMF_INTERNAL_NAMESPACE::Xdr::read (is, _value); +} + + +template +void +TypedAttribute::copyValueFrom (const Attribute &other) +{ + _value = cast(other)._value; +} + + +template +TypedAttribute * +TypedAttribute::cast (Attribute *attribute) +{ + TypedAttribute *t = + dynamic_cast *> (attribute); + + if (t == 0) + throw IEX_NAMESPACE::TypeExc ("Unexpected attribute type."); + + return t; +} + + +template +const TypedAttribute * +TypedAttribute::cast (const Attribute *attribute) +{ + const TypedAttribute *t = + dynamic_cast *> (attribute); + + if (t == 0) + throw IEX_NAMESPACE::TypeExc ("Unexpected attribute type."); + + return t; +} + + +template +inline TypedAttribute & +TypedAttribute::cast (Attribute &attribute) +{ + return *cast (&attribute); +} + + +template +inline const TypedAttribute & +TypedAttribute::cast (const Attribute &attribute) +{ + return *cast (&attribute); +} + + +template +inline void +TypedAttribute::registerAttributeType () +{ + Attribute::registerAttributeType (staticTypeName(), makeNewAttribute); +} + + +template +inline void +TypedAttribute::unRegisterAttributeType () +{ + Attribute::unRegisterAttributeType (staticTypeName()); +} + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfB44Compressor.h b/OpenEXR/include/OpenEXR/ImfB44Compressor.h new file mode 100644 index 0000000..5c381c1 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfB44Compressor.h @@ -0,0 +1,118 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2006, 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_B44_COMPRESSOR_H +#define INCLUDED_IMF_B44_COMPRESSOR_H + +//----------------------------------------------------------------------------- +// +// class B44Compressor -- lossy compression of 4x4 pixel blocks +// +//----------------------------------------------------------------------------- + +#include "ImfCompressor.h" +#include "ImfNamespace.h" +#include "ImfExport.h" +#include "ImfForward.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +class IMF_EXPORT B44Compressor: public Compressor +{ + public: + + B44Compressor (const Header &hdr, + size_t maxScanLineSize, + size_t numScanLines, + bool optFlatFields); + + virtual ~B44Compressor (); + + virtual int numScanLines () const; + + virtual Format format () const; + + virtual int compress (const char *inPtr, + int inSize, + int minY, + const char *&outPtr); + + virtual int compressTile (const char *inPtr, + int inSize, + IMATH_NAMESPACE::Box2i range, + const char *&outPtr); + + virtual int uncompress (const char *inPtr, + int inSize, + int minY, + const char *&outPtr); + + virtual int uncompressTile (const char *inPtr, + int inSize, + IMATH_NAMESPACE::Box2i range, + const char *&outPtr); + private: + + struct ChannelData; + + int compress (const char *inPtr, + int inSize, + IMATH_NAMESPACE::Box2i range, + const char *&outPtr); + + int uncompress (const char *inPtr, + int inSize, + IMATH_NAMESPACE::Box2i range, + const char *&outPtr); + + int _maxScanLineSize; + bool _optFlatFields; + Format _format; + int _numScanLines; + unsigned short * _tmpBuffer; + char * _outBuffer; + int _numChans; + const ChannelList & _channels; + ChannelData * _channelData; + int _minX; + int _maxX; + int _maxY; +}; + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfBoxAttribute.h b/OpenEXR/include/OpenEXR/ImfBoxAttribute.h new file mode 100644 index 0000000..7bf2585 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfBoxAttribute.h @@ -0,0 +1,87 @@ +/////////////////////////////////////////////////////////////////////////// +// +// 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMF_BOX_ATTRIBUTE_H +#define INCLUDED_IMF_BOX_ATTRIBUTE_H + +//----------------------------------------------------------------------------- +// +// class Box2iAttribute +// class Box2fAttribute +// +//----------------------------------------------------------------------------- + +#include "ImfForward.h" +#include "ImfExport.h" +#include "ImfAttribute.h" +#include "ImathBox.h" +#include "ImfNamespace.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +typedef TypedAttribute Box2iAttribute; + +template <> +IMF_EXPORT +const char *Box2iAttribute::staticTypeName (); +template <> +IMF_EXPORT +void Box2iAttribute::writeValueTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &, + int) const; +template <> +IMF_EXPORT +void Box2iAttribute::readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &, + int, int); + + +typedef TypedAttribute Box2fAttribute; +template <> +IMF_EXPORT +const char *Box2fAttribute::staticTypeName (); +template <> +IMF_EXPORT +void Box2fAttribute::writeValueTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &, + int) const; +template <> +IMF_EXPORT +void Box2fAttribute::readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &, + int, int); + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfCRgbaFile.h b/OpenEXR/include/OpenEXR/ImfCRgbaFile.h new file mode 100644 index 0000000..5ac2bf8 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfCRgbaFile.h @@ -0,0 +1,555 @@ +/* + +Copyright (c) 2002, 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. + +*/ + +#ifndef INCLUDED_IMF_C_RGBA_FILE_H +#define INCLUDED_IMF_C_RGBA_FILE_H + +#include "ImfExport.h" + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* +** Interpreting unsigned shorts as 16-bit floating point numbers +*/ + +typedef unsigned short ImfHalf; + +IMF_EXPORT +void ImfFloatToHalf (float f, + ImfHalf *h); + +IMF_EXPORT +void ImfFloatToHalfArray (int n, + const float f[/*n*/], + ImfHalf h[/*n*/]); + +IMF_EXPORT +float ImfHalfToFloat (ImfHalf h); + +IMF_EXPORT +void ImfHalfToFloatArray (int n, + const ImfHalf h[/*n*/], + float f[/*n*/]); + +/* +** RGBA pixel; memory layout must be the same as struct Imf::Rgba. +*/ + +struct ImfRgba +{ + ImfHalf r; + ImfHalf g; + ImfHalf b; + ImfHalf a; +}; + +typedef struct ImfRgba ImfRgba; + +/* +** Magic number; this must be the same as Imf::MAGIC +*/ + +#define IMF_MAGIC 20000630 + +/* +** Version number; this must be the same as Imf::EXR_VERSION +*/ + +#define IMF_VERSION_NUMBER 2 + +/* +** Line order; values must the the same as in Imf::LineOrder. +*/ + +#define IMF_INCREASING_Y 0 +#define IMF_DECREASING_Y 1 +#define IMF_RAMDOM_Y 2 + + +/* +** Compression types; values must be the same as in Imf::Compression. +*/ + +#define IMF_NO_COMPRESSION 0 +#define IMF_RLE_COMPRESSION 1 +#define IMF_ZIPS_COMPRESSION 2 +#define IMF_ZIP_COMPRESSION 3 +#define IMF_PIZ_COMPRESSION 4 +#define IMF_PXR24_COMPRESSION 5 +#define IMF_B44_COMPRESSION 6 +#define IMF_B44A_COMPRESSION 7 + + +/* +** Channels; values must be the same as in Imf::RgbaChannels. +*/ + +#define IMF_WRITE_R 0x01 +#define IMF_WRITE_G 0x02 +#define IMF_WRITE_B 0x04 +#define IMF_WRITE_A 0x08 +#define IMF_WRITE_Y 0x10 +#define IMF_WRITE_C 0x20 +#define IMF_WRITE_RGB 0x07 +#define IMF_WRITE_RGBA 0x0f +#define IMF_WRITE_YC 0x30 +#define IMF_WRITE_YA 0x18 +#define IMF_WRITE_YCA 0x38 + + +/* +** Level modes; values must be the same as in Imf::LevelMode +*/ + +#define IMF_ONE_LEVEL 0 +#define IMF_MIPMAP_LEVELS 1 +#define IMF_RIPMAP_LEVELS 2 + + +/* +** Level rounding modes; values must be the same as in Imf::LevelRoundingMode +*/ + +#define IMF_ROUND_DOWN 0 +#define IMF_ROUND_UP 1 + + +/* +** RGBA file header +*/ + +struct ImfHeader; +typedef struct ImfHeader ImfHeader; + +IMF_EXPORT +ImfHeader * ImfNewHeader (void); + +IMF_EXPORT +void ImfDeleteHeader (ImfHeader *hdr); + +IMF_EXPORT +ImfHeader * ImfCopyHeader (const ImfHeader *hdr); + +IMF_EXPORT +void ImfHeaderSetDisplayWindow (ImfHeader *hdr, + int xMin, int yMin, + int xMax, int yMax); + +IMF_EXPORT +void ImfHeaderDisplayWindow (const ImfHeader *hdr, + int *xMin, int *yMin, + int *xMax, int *yMax); + +IMF_EXPORT +void ImfHeaderSetDataWindow (ImfHeader *hdr, + int xMin, int yMin, + int xMax, int yMax); + +IMF_EXPORT +void ImfHeaderDataWindow (const ImfHeader *hdr, + int *xMin, int *yMin, + int *xMax, int *yMax); + +IMF_EXPORT +void ImfHeaderSetPixelAspectRatio (ImfHeader *hdr, + float pixelAspectRatio); + +IMF_EXPORT +float ImfHeaderPixelAspectRatio (const ImfHeader *hdr); + +IMF_EXPORT +void ImfHeaderSetScreenWindowCenter (ImfHeader *hdr, + float x, float y); + +IMF_EXPORT +void ImfHeaderScreenWindowCenter (const ImfHeader *hdr, + float *x, float *y); + +IMF_EXPORT +void ImfHeaderSetScreenWindowWidth (ImfHeader *hdr, + float width); + +IMF_EXPORT +float ImfHeaderScreenWindowWidth (const ImfHeader *hdr); + +IMF_EXPORT +void ImfHeaderSetLineOrder (ImfHeader *hdr, + int lineOrder); + +IMF_EXPORT +int ImfHeaderLineOrder (const ImfHeader *hdr); + +IMF_EXPORT +void ImfHeaderSetCompression (ImfHeader *hdr, + int compression); + +IMF_EXPORT +int ImfHeaderCompression (const ImfHeader *hdr); + +IMF_EXPORT +int ImfHeaderSetIntAttribute (ImfHeader *hdr, + const char name[], + int value); + +IMF_EXPORT +int ImfHeaderIntAttribute (const ImfHeader *hdr, + const char name[], + int *value); + +IMF_EXPORT +int ImfHeaderSetFloatAttribute (ImfHeader *hdr, + const char name[], + float value); + +IMF_EXPORT +int ImfHeaderSetDoubleAttribute (ImfHeader *hdr, + const char name[], + double value); + +IMF_EXPORT +int ImfHeaderFloatAttribute (const ImfHeader *hdr, + const char name[], + float *value); + +IMF_EXPORT +int ImfHeaderDoubleAttribute (const ImfHeader *hdr, + const char name[], + double *value); + +IMF_EXPORT +int ImfHeaderSetStringAttribute (ImfHeader *hdr, + const char name[], + const char value[]); + +IMF_EXPORT +int ImfHeaderStringAttribute (const ImfHeader *hdr, + const char name[], + const char **value); + +IMF_EXPORT +int ImfHeaderSetBox2iAttribute (ImfHeader *hdr, + const char name[], + int xMin, int yMin, + int xMax, int yMax); + +IMF_EXPORT +int ImfHeaderBox2iAttribute (const ImfHeader *hdr, + const char name[], + int *xMin, int *yMin, + int *xMax, int *yMax); + +IMF_EXPORT +int ImfHeaderSetBox2fAttribute (ImfHeader *hdr, + const char name[], + float xMin, float yMin, + float xMax, float yMax); + +IMF_EXPORT +int ImfHeaderBox2fAttribute (const ImfHeader *hdr, + const char name[], + float *xMin, float *yMin, + float *xMax, float *yMax); + +IMF_EXPORT +int ImfHeaderSetV2iAttribute (ImfHeader *hdr, + const char name[], + int x, int y); + +IMF_EXPORT +int ImfHeaderV2iAttribute (const ImfHeader *hdr, + const char name[], + int *x, int *y); + +IMF_EXPORT +int ImfHeaderSetV2fAttribute (ImfHeader *hdr, + const char name[], + float x, float y); + +IMF_EXPORT +int ImfHeaderV2fAttribute (const ImfHeader *hdr, + const char name[], + float *x, float *y); + +IMF_EXPORT +int ImfHeaderSetV3iAttribute (ImfHeader *hdr, + const char name[], + int x, int y, int z); + +IMF_EXPORT +int ImfHeaderV3iAttribute (const ImfHeader *hdr, + const char name[], + int *x, int *y, int *z); + +IMF_EXPORT +int ImfHeaderSetV3fAttribute (ImfHeader *hdr, + const char name[], + float x, float y, float z); + +IMF_EXPORT +int ImfHeaderV3fAttribute (const ImfHeader *hdr, + const char name[], + float *x, float *y, float *z); + +IMF_EXPORT +int ImfHeaderSetM33fAttribute (ImfHeader *hdr, + const char name[], + const float m[3][3]); + +IMF_EXPORT +int ImfHeaderM33fAttribute (const ImfHeader *hdr, + const char name[], + float m[3][3]); + +IMF_EXPORT +int ImfHeaderSetM44fAttribute (ImfHeader *hdr, + const char name[], + const float m[4][4]); + +IMF_EXPORT +int ImfHeaderM44fAttribute (const ImfHeader *hdr, + const char name[], + float m[4][4]); + +/* +** RGBA output file +*/ + +struct ImfOutputFile; +typedef struct ImfOutputFile ImfOutputFile; + +IMF_EXPORT +ImfOutputFile * ImfOpenOutputFile (const char name[], + const ImfHeader *hdr, + int channels); + +IMF_EXPORT +int ImfCloseOutputFile (ImfOutputFile *out); + +IMF_EXPORT +int ImfOutputSetFrameBuffer (ImfOutputFile *out, + const ImfRgba *base, + size_t xStride, + size_t yStride); + +IMF_EXPORT +int ImfOutputWritePixels (ImfOutputFile *out, + int numScanLines); + +IMF_EXPORT +int ImfOutputCurrentScanLine (const ImfOutputFile *out); + +IMF_EXPORT +const ImfHeader * ImfOutputHeader (const ImfOutputFile *out); + +IMF_EXPORT +int ImfOutputChannels (const ImfOutputFile *out); + + +/* +** Tiled RGBA output file +*/ + +struct ImfTiledOutputFile; +typedef struct ImfTiledOutputFile ImfTiledOutputFile; + +IMF_EXPORT +ImfTiledOutputFile * ImfOpenTiledOutputFile (const char name[], + const ImfHeader *hdr, + int channels, + int xSize, int ySize, + int mode, int rmode); + +IMF_EXPORT +int ImfCloseTiledOutputFile (ImfTiledOutputFile *out); + +IMF_EXPORT +int ImfTiledOutputSetFrameBuffer (ImfTiledOutputFile *out, + const ImfRgba *base, + size_t xStride, + size_t yStride); + +IMF_EXPORT +int ImfTiledOutputWriteTile (ImfTiledOutputFile *out, + int dx, int dy, + int lx, int ly); + +IMF_EXPORT +int ImfTiledOutputWriteTiles (ImfTiledOutputFile *out, + int dxMin, int dxMax, + int dyMin, int dyMax, + int lx, int ly); + +IMF_EXPORT +const ImfHeader * ImfTiledOutputHeader (const ImfTiledOutputFile *out); + +IMF_EXPORT +int ImfTiledOutputChannels (const ImfTiledOutputFile *out); + +IMF_EXPORT +int ImfTiledOutputTileXSize (const ImfTiledOutputFile *out); + +IMF_EXPORT +int ImfTiledOutputTileYSize (const ImfTiledOutputFile *out); + +IMF_EXPORT +int ImfTiledOutputLevelMode (const ImfTiledOutputFile *out); + +IMF_EXPORT +int ImfTiledOutputLevelRoundingMode + (const ImfTiledOutputFile *out); + + +/* +** RGBA input file +*/ + +struct ImfInputFile; +typedef struct ImfInputFile ImfInputFile; + +ImfInputFile * ImfOpenInputFile (const char name[]); + +IMF_EXPORT +int ImfCloseInputFile (ImfInputFile *in); + +IMF_EXPORT +int ImfInputSetFrameBuffer (ImfInputFile *in, + ImfRgba *base, + size_t xStride, + size_t yStride); + +IMF_EXPORT +int ImfInputReadPixels (ImfInputFile *in, + int scanLine1, + int scanLine2); + +IMF_EXPORT +const ImfHeader * ImfInputHeader (const ImfInputFile *in); + +IMF_EXPORT +int ImfInputChannels (const ImfInputFile *in); + +IMF_EXPORT +const char * ImfInputFileName (const ImfInputFile *in); + + +/* +** Tiled RGBA input file +*/ + +struct ImfTiledInputFile; +typedef struct ImfTiledInputFile ImfTiledInputFile; + +IMF_EXPORT +ImfTiledInputFile * ImfOpenTiledInputFile (const char name[]); + +IMF_EXPORT +int ImfCloseTiledInputFile (ImfTiledInputFile *in); + +IMF_EXPORT +int ImfTiledInputSetFrameBuffer (ImfTiledInputFile *in, + ImfRgba *base, + size_t xStride, + size_t yStride); + +IMF_EXPORT +int ImfTiledInputReadTile (ImfTiledInputFile *in, + int dx, int dy, + int lx, int ly); + +IMF_EXPORT +int ImfTiledInputReadTiles (ImfTiledInputFile *in, + int dxMin, int dxMax, + int dyMin, int dyMax, + int lx, int ly); + +IMF_EXPORT +const ImfHeader * ImfTiledInputHeader (const ImfTiledInputFile *in); + +IMF_EXPORT +int ImfTiledInputChannels (const ImfTiledInputFile *in); + +IMF_EXPORT +const char * ImfTiledInputFileName (const ImfTiledInputFile *in); + +IMF_EXPORT +int ImfTiledInputTileXSize (const ImfTiledInputFile *in); + +IMF_EXPORT +int ImfTiledInputTileYSize (const ImfTiledInputFile *in); + +IMF_EXPORT +int ImfTiledInputLevelMode (const ImfTiledInputFile *in); + +IMF_EXPORT +int ImfTiledInputLevelRoundingMode + (const ImfTiledInputFile *in); + +/* +** Lookup tables +*/ + +struct ImfLut; +typedef struct ImfLut ImfLut; + +IMF_EXPORT +ImfLut * ImfNewRound12logLut (int channels); + +IMF_EXPORT +ImfLut * ImfNewRoundNBitLut (unsigned int n, int channels); + +IMF_EXPORT +void ImfDeleteLut (ImfLut *lut); + +IMF_EXPORT +void ImfApplyLut (ImfLut *lut, + ImfRgba *data, + int nData, + int stride); +/* +** Most recent error message +*/ + +IMF_EXPORT +const char * ImfErrorMessage (void); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfChannelList.h b/OpenEXR/include/OpenEXR/ImfChannelList.h new file mode 100644 index 0000000..fc31a15 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfChannelList.h @@ -0,0 +1,436 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMF_CHANNEL_LIST_H +#define INCLUDED_IMF_CHANNEL_LIST_H + +//----------------------------------------------------------------------------- +// +// class Channel +// class ChannelList +// +//----------------------------------------------------------------------------- + +#include "ImfName.h" +#include "ImfPixelType.h" + +#include "ImfNamespace.h" +#include "ImfExport.h" + +#include +#include +#include + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +struct IMF_EXPORT Channel +{ + //------------------------------ + // Data type; see ImfPixelType.h + //------------------------------ + + PixelType type; + + + //-------------------------------------------- + // Subsampling: pixel (x, y) is present in the + // channel only if + // + // x % xSampling == 0 && y % ySampling == 0 + // + //-------------------------------------------- + + int xSampling; + int ySampling; + + + //-------------------------------------------------------------- + // Hint to lossy compression methods that indicates whether + // human perception of the quantity represented by this channel + // is closer to linear or closer to logarithmic. Compression + // methods may optimize image quality by adjusting pixel data + // quantization acording to this hint. + // For example, perception of red, green, blue and luminance is + // approximately logarithmic; the difference between 0.1 and 0.2 + // is perceived to be roughly the same as the difference between + // 1.0 and 2.0. Perception of chroma coordinates tends to be + // closer to linear than logarithmic; the difference between 0.1 + // and 0.2 is perceived to be roughly the same as the difference + // between 1.0 and 1.1. + //-------------------------------------------------------------- + + bool pLinear; + + + //------------ + // Constructor + //------------ + + Channel (PixelType type = HALF, + int xSampling = 1, + int ySampling = 1, + bool pLinear = false); + + + //------------ + // Operator == + //------------ + + bool operator == (const Channel &other) const; +}; + + +class IMF_EXPORT ChannelList +{ + public: + + //-------------- + // Add a channel + //-------------- + + void insert (const char name[], + const Channel &channel); + + void insert (const std::string &name, + const Channel &channel); + + //------------------------------------------------------------------ + // Access to existing channels: + // + // [n] Returns a reference to the channel with name n. + // If no channel with name n exists, an IEX_NAMESPACE::ArgExc + // is thrown. + // + // findChannel(n) Returns a pointer to the channel with name n, + // or 0 if no channel with name n exists. + // + //------------------------------------------------------------------ + + Channel & operator [] (const char name[]); + const Channel & operator [] (const char name[]) const; + + Channel & operator [] (const std::string &name); + const Channel & operator [] (const std::string &name) const; + + Channel * findChannel (const char name[]); + const Channel * findChannel (const char name[]) const; + + Channel * findChannel (const std::string &name); + const Channel * findChannel (const std::string &name) const; + + + //------------------------------------------- + // Iterator-style access to existing channels + //------------------------------------------- + + typedef std::map ChannelMap; + + class Iterator; + class ConstIterator; + + Iterator begin (); + ConstIterator begin () const; + + Iterator end (); + ConstIterator end () const; + + Iterator find (const char name[]); + ConstIterator find (const char name[]) const; + + Iterator find (const std::string &name); + ConstIterator find (const std::string &name) const; + + + //----------------------------------------------------------------- + // Support for image layers: + // + // In an image file with many channels it is sometimes useful to + // group the channels into "layers", that is, into sets of channels + // that logically belong together. Grouping channels into layers + // is done using a naming convention: channel C in layer L is + // called "L.C". + // + // For example, a computer graphic image may contain separate + // R, G and B channels for light that originated at each of + // several different virtual light sources. The channels in + // this image might be called "light1.R", "light1.G", "light1.B", + // "light2.R", "light2.G", "light2.B", etc. + // + // Note that this naming convention allows layers to be nested; + // for example, "light1.specular.R" identifies the "R" channel + // in the "specular" sub-layer of layer "light1". + // + // Channel names that don't contain a "." or that contain a + // "." only at the beginning or at the end are not considered + // to be part of any layer. + // + // layers(lns) sorts the channels in this ChannelList + // into layers and stores the names of + // all layers, sorted alphabetically, + // into string set lns. + // + // channelsInLayer(ln,f,l) stores a pair of iterators in f and l + // such that the loop + // + // for (ConstIterator i = f; i != l; ++i) + // ... + // + // iterates over all channels in layer ln. + // channelsInLayer (ln, l, p) calls + // channelsWithPrefix (ln + ".", l, p). + // + //----------------------------------------------------------------- + + void layers (std::set &layerNames) const; + + void channelsInLayer (const std::string &layerName, + Iterator &first, + Iterator &last); + + void channelsInLayer (const std::string &layerName, + ConstIterator &first, + ConstIterator &last) const; + + + //------------------------------------------------------------------- + // Find all channels whose name begins with a given prefix: + // + // channelsWithPrefix(p,f,l) stores a pair of iterators in f and l + // such that the following loop iterates over all channels whose name + // begins with string p: + // + // for (ConstIterator i = f; i != l; ++i) + // ... + // + //------------------------------------------------------------------- + + void channelsWithPrefix (const char prefix[], + Iterator &first, + Iterator &last); + + void channelsWithPrefix (const char prefix[], + ConstIterator &first, + ConstIterator &last) const; + + void channelsWithPrefix (const std::string &prefix, + Iterator &first, + Iterator &last); + + void channelsWithPrefix (const std::string &prefix, + ConstIterator &first, + ConstIterator &last) const; + + //------------ + // Operator == + //------------ + + bool operator == (const ChannelList &other) const; + + private: + + ChannelMap _map; +}; + + +//---------- +// Iterators +//---------- + +class ChannelList::Iterator +{ + public: + + Iterator (); + Iterator (const ChannelList::ChannelMap::iterator &i); + + Iterator & operator ++ (); + Iterator operator ++ (int); + + const char * name () const; + Channel & channel () const; + + private: + + friend class ChannelList::ConstIterator; + + ChannelList::ChannelMap::iterator _i; +}; + + +class ChannelList::ConstIterator +{ + public: + + ConstIterator (); + ConstIterator (const ChannelList::ChannelMap::const_iterator &i); + ConstIterator (const ChannelList::Iterator &other); + + ConstIterator & operator ++ (); + ConstIterator operator ++ (int); + + const char * name () const; + const Channel & channel () const; + + private: + + friend bool operator == (const ConstIterator &, const ConstIterator &); + friend bool operator != (const ConstIterator &, const ConstIterator &); + + ChannelList::ChannelMap::const_iterator _i; +}; + + +//----------------- +// Inline Functions +//----------------- + +inline +ChannelList::Iterator::Iterator (): _i() +{ + // empty +} + + +inline +ChannelList::Iterator::Iterator (const ChannelList::ChannelMap::iterator &i): + _i (i) +{ + // empty +} + + +inline ChannelList::Iterator & +ChannelList::Iterator::operator ++ () +{ + ++_i; + return *this; +} + + +inline ChannelList::Iterator +ChannelList::Iterator::operator ++ (int) +{ + Iterator tmp = *this; + ++_i; + return tmp; +} + + +inline const char * +ChannelList::Iterator::name () const +{ + return *_i->first; +} + + +inline Channel & +ChannelList::Iterator::channel () const +{ + return _i->second; +} + + +inline +ChannelList::ConstIterator::ConstIterator (): _i() +{ + // empty +} + +inline +ChannelList::ConstIterator::ConstIterator + (const ChannelList::ChannelMap::const_iterator &i): _i (i) +{ + // empty +} + + +inline +ChannelList::ConstIterator::ConstIterator (const ChannelList::Iterator &other): + _i (other._i) +{ + // empty +} + +inline ChannelList::ConstIterator & +ChannelList::ConstIterator::operator ++ () +{ + ++_i; + return *this; +} + + +inline ChannelList::ConstIterator +ChannelList::ConstIterator::operator ++ (int) +{ + ConstIterator tmp = *this; + ++_i; + return tmp; +} + + +inline const char * +ChannelList::ConstIterator::name () const +{ + return *_i->first; +} + +inline const Channel & +ChannelList::ConstIterator::channel () const +{ + return _i->second; +} + + +inline bool +operator == (const ChannelList::ConstIterator &x, + const ChannelList::ConstIterator &y) +{ + return x._i == y._i; +} + + +inline bool +operator != (const ChannelList::ConstIterator &x, + const ChannelList::ConstIterator &y) +{ + return !(x == y); +} + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfChannelListAttribute.h b/OpenEXR/include/OpenEXR/ImfChannelListAttribute.h new file mode 100644 index 0000000..60d8907 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfChannelListAttribute.h @@ -0,0 +1,74 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMF_CHANNEL_LIST_ATTRIBUTE_H +#define INCLUDED_IMF_CHANNEL_LIST_ATTRIBUTE_H + +//----------------------------------------------------------------------------- +// +// class ChannelListAttribute +// +//----------------------------------------------------------------------------- + +#include "ImfAttribute.h" +#include "ImfChannelList.h" +#include "ImfExport.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +typedef TypedAttribute ChannelListAttribute; + +template <> +IMF_EXPORT +const char *ChannelListAttribute::staticTypeName (); + +template <> +IMF_EXPORT +void ChannelListAttribute::writeValueTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &, + int) const; + +template <> +IMF_EXPORT +void ChannelListAttribute::readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &, + int, int); + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + +#endif + diff --git a/OpenEXR/include/OpenEXR/ImfChromaticities.h b/OpenEXR/include/OpenEXR/ImfChromaticities.h new file mode 100644 index 0000000..9af4769 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfChromaticities.h @@ -0,0 +1,131 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2003, 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_CHROMATICITIES_H +#define INCLUDED_IMF_CHROMATICITIES_H + +//----------------------------------------------------------------------------- +// +// CIE (x,y) chromaticities, and conversions between +// RGB tiples and CIE XYZ tristimulus values. +// +//----------------------------------------------------------------------------- + +#include "ImathVec.h" +#include "ImathMatrix.h" +#include "ImfNamespace.h" +#include "ImfExport.h" + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +struct IMF_EXPORT Chromaticities +{ + //----------------------------------------------- + // The CIE x and y coordinates of the RGB triples + // (1,0,0), (0,1,0), (0,0,1) and (1,1,1). + //----------------------------------------------- + + IMATH_NAMESPACE::V2f red; + IMATH_NAMESPACE::V2f green; + IMATH_NAMESPACE::V2f blue; + IMATH_NAMESPACE::V2f white; + + //-------------------------------------------- + // Default constructor produces chromaticities + // according to Rec. ITU-R BT.709-3 + //-------------------------------------------- + + Chromaticities (const IMATH_NAMESPACE::V2f &red = IMATH_NAMESPACE::V2f (0.6400f, 0.3300f), + const IMATH_NAMESPACE::V2f &green = IMATH_NAMESPACE::V2f (0.3000f, 0.6000f), + const IMATH_NAMESPACE::V2f &blue = IMATH_NAMESPACE::V2f (0.1500f, 0.0600f), + const IMATH_NAMESPACE::V2f &white = IMATH_NAMESPACE::V2f (0.3127f, 0.3290f)); + + + //--------- + // Equality + //--------- + + bool operator == (const Chromaticities &v) const; + bool operator != (const Chromaticities &v) const; +}; + + +// +// Conversions between RGB and CIE XYZ +// +// RGB to XYZ: +// +// Given a set of chromaticities, c, and the luminance, Y, of the RGB +// triple (1,1,1), or "white", RGBtoXYZ(c,Y) computes a matrix, M, so +// that multiplying an RGB value, v, with M produces an equivalent +// XYZ value, w. (w == v * M) +// +// If we define that +// +// (Xr, Yr, Zr) == (1, 0, 0) * M +// (Xg, Yg, Zg) == (0, 1, 0) * M +// (Xb, Yb, Zb) == (0, 0, 1) * M +// (Xw, Yw, Zw) == (1, 1, 1) * M, +// +// then the following statements are true: +// +// Xr / (Xr + Yr + Zr) == c.red.x +// Yr / (Xr + Yr + Zr) == c.red.y +// +// Xg / (Xg + Yg + Zg) == c.red.x +// Yg / (Xg + Yg + Zg) == c.red.y +// +// Xb / (Xb + Yb + Zb) == c.red.x +// Yb / (Xb + Yb + Zb) == c.red.y +// +// Xw / (Xw + Yw + Zw) == c.red.x +// Yw / (Xw + Yw + Zw) == c.red.y +// +// Yw == Y. +// +// XYZ to RGB: +// +// YYZtoRGB(c,Y) returns RGBtoXYZ(c,Y).inverse(). +// + +IMF_EXPORT IMATH_NAMESPACE::M44f RGBtoXYZ (const Chromaticities chroma, float Y); +IMF_EXPORT IMATH_NAMESPACE::M44f XYZtoRGB (const Chromaticities chroma, float Y); + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfChromaticitiesAttribute.h b/OpenEXR/include/OpenEXR/ImfChromaticitiesAttribute.h new file mode 100644 index 0000000..6c0c35a --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfChromaticitiesAttribute.h @@ -0,0 +1,73 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2003, 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_CHROMATICITIES_ATTRIBUTE_H +#define INCLUDED_IMF_CHROMATICITIES_ATTRIBUTE_H + + +//----------------------------------------------------------------------------- +// +// class ChromaticitiesAttribute +// +//----------------------------------------------------------------------------- + +#include "ImfAttribute.h" +#include "ImfChromaticities.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +typedef TypedAttribute ChromaticitiesAttribute; + +template <> +IMF_EXPORT +const char *ChromaticitiesAttribute::staticTypeName (); + +template <> +IMF_EXPORT +void ChromaticitiesAttribute::writeValueTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &, + int) const; + +template <> +IMF_EXPORT +void ChromaticitiesAttribute::readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &, + int, + int); + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfCompositeDeepScanLine.h b/OpenEXR/include/OpenEXR/ImfCompositeDeepScanLine.h new file mode 100644 index 0000000..2dc23e5 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfCompositeDeepScanLine.h @@ -0,0 +1,142 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2012, Weta Digital Ltd +// +// 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 Weta Digital 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_COMPOSITEDEEPSCANLINE_H +#define INCLUDED_IMF_COMPOSITEDEEPSCANLINE_H + +//----------------------------------------------------------------------------- +// +// Class to composite deep samples into a frame buffer +// Initialise with a deep input part or deep inputfile +// (also supports multiple files and parts, and will +// composite them together, as long as their sizes and channelmaps agree) +// +// Then call setFrameBuffer, and readPixels, exactly as for reading +// regular scanline images. +// +// Restrictions - source file(s) must contain at least Z and alpha channels +// - if multiple files/parts are provided, sizes must match +// - all requested channels will be composited as premultiplied +// - only half and float channels can be requested +// +// This object should not be considered threadsafe +// +// The default compositing engine will give spurious results with overlapping +// volumetric samples - you may derive from DeepCompositing class, override the +// sort_pixel() and composite_pixel() functions, and pass an instance to +// setCompositing(). +// +//----------------------------------------------------------------------------- + +#include "ImfForward.h" +#include "ImfNamespace.h" +#include "ImfExport.h" +#include + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + +class IMF_EXPORT CompositeDeepScanLine +{ + public: + CompositeDeepScanLine(); + virtual ~CompositeDeepScanLine(); + + /// set the source data as a part + ///@note all parts must remain valid until after last interaction with DeepComp + void addSource(DeepScanLineInputPart * part); + + /// set the source data as a file + ///@note all file must remain valid until after last interaction with DeepComp + void addSource(DeepScanLineInputFile * file); + + + ///////////////////////////////////////// + // + // set the frame buffer for output values + // the buffers specified must be large enough + // to handle the dataWindow() + // + ///////////////////////////////////////// + void setFrameBuffer(const FrameBuffer & fr); + + + + ///////////////////////////////////////// + // + // retrieve frameBuffer + // + //////////////////////////////////////// + const FrameBuffer & frameBuffer() const; + + + ////////////////////////////////////////////////// + // + // read scanlines start to end from the source(s) + // storing the result in the frame buffer provided + // + ////////////////////////////////////////////////// + + void readPixels(int start,int end); + + int sources() const; // return number of sources + + ///////////////////////////////////////////////// + // + // retrieve the datawindow + // If multiple parts are specified, this will + // be the union of the dataWindow of all parts + // + //////////////////////////////////////////////// + + const IMATH_NAMESPACE::Box2i & dataWindow() const; + + + // + // override default sorting/compositing operation + // (otherwise an instance of the base class will be used) + // + + void setCompositing(DeepCompositing *); + + struct Data; + private : + struct Data *_Data; + + CompositeDeepScanLine(const CompositeDeepScanLine &); // not implemented + const CompositeDeepScanLine & operator=(const CompositeDeepScanLine &); // not implemented +}; + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfCompression.h b/OpenEXR/include/OpenEXR/ImfCompression.h new file mode 100644 index 0000000..c066d34 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfCompression.h @@ -0,0 +1,84 @@ +/////////////////////////////////////////////////////////////////////////// +// +// 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMF_COMPRESSION_H +#define INCLUDED_IMF_COMPRESSION_H + +//----------------------------------------------------------------------------- +// +// enum Compression +// +//----------------------------------------------------------------------------- +#include "ImfNamespace.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + +enum Compression +{ + NO_COMPRESSION = 0, // no compression + + RLE_COMPRESSION = 1, // run length encoding + + ZIPS_COMPRESSION = 2, // zlib compression, one scan line at a time + + ZIP_COMPRESSION = 3, // zlib compression, in blocks of 16 scan lines + + PIZ_COMPRESSION = 4, // piz-based wavelet compression + + PXR24_COMPRESSION = 5, // lossy 24-bit float compression + + B44_COMPRESSION = 6, // lossy 4-by-4 pixel block compression, + // fixed compression rate + + B44A_COMPRESSION = 7, // lossy 4-by-4 pixel block compression, + // flat fields are compressed more + + DWAA_COMPRESSION = 8, // lossy DCT based compression, in blocks + // of 32 scanlines. More efficient for partial + // buffer access. + + DWAB_COMPRESSION = 9, // lossy DCT based compression, in blocks + // of 256 scanlines. More efficient space + // wise and faster to decode full frames + // than DWAA_COMPRESSION. + + NUM_COMPRESSION_METHODS // number of different compression methods +}; + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfCompressionAttribute.h b/OpenEXR/include/OpenEXR/ImfCompressionAttribute.h new file mode 100644 index 0000000..bfc72de --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfCompressionAttribute.h @@ -0,0 +1,64 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMF_COMPRESSION_ATTRIBUTE_H +#define INCLUDED_IMF_COMPRESSION_ATTRIBUTE_H + +//----------------------------------------------------------------------------- +// +// class CompressionAttribute +// +//----------------------------------------------------------------------------- + +#include "ImfAttribute.h" +#include "ImfCompression.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +typedef TypedAttribute CompressionAttribute; +template <> const char *CompressionAttribute::staticTypeName (); +template <> void CompressionAttribute::writeValueTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &, + int) const; +template <> void CompressionAttribute::readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &, + int, + int); + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfConvert.h b/OpenEXR/include/OpenEXR/ImfConvert.h new file mode 100644 index 0000000..b0a7f47 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfConvert.h @@ -0,0 +1,107 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002, 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_CONVERT_H +#define INCLUDED_IMF_CONVERT_H + +//----------------------------------------------------------------------------- +// +// Routines for converting between pixel data types, +// with well-defined behavior for exceptional cases, +// without depending on how hardware and operating +// system handle integer overflows and floating-point +// exceptions. +// +//----------------------------------------------------------------------------- + +#include "half.h" +#include "ImfExport.h" +#include "ImfNamespace.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +//--------------------------------------------------------- +// Conversion from half or float to unsigned int: +// +// input result +// --------------------------------------------------- +// +// finite, >= 0 input, cast to unsigned int +// (rounds towards zero) +// +// finite, < 0 0 +// +// NaN 0 +// +// +infinity UINT_MAX +// +// -infinity 0 +// +//--------------------------------------------------------- + +IMF_EXPORT unsigned int halfToUint (half h); +IMF_EXPORT unsigned int floatToUint (float f); + + +//--------------------------------------------------------- +// Conversion from unsigned int or float to half: +// +// input result +// --------------------------------------------------- +// +// finite, closest possible half +// magnitude <= HALF_MAX +// +// finite, > HALF_MAX +infinity +// +// finite, < -HALF_MAX -infinity +// +// NaN NaN +// +// +infinity +infinity +// +// -infinity -infinity +// +//--------------------------------------------------------- + +IMF_EXPORT half uintToHalf (unsigned int ui); +IMF_EXPORT half floatToHalf (float f); + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfDeepCompositing.h b/OpenEXR/include/OpenEXR/ImfDeepCompositing.h new file mode 100644 index 0000000..b400efc --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfDeepCompositing.h @@ -0,0 +1,132 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2012, Weta Digital Ltd +// +// 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 Weta Digital 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_DEEPCOMPOSITING_H +#define INCLUDED_IMF_DEEPCOMPOSITING_H + +//----------------------------------------------------------------------------- +// +// Class to sort and composite deep samples into a frame buffer +// You may derive from this class to change the way that CompositeDeepScanLine +// and CompositeDeepTile combine samples together - pass an instance of your derived +// class to the compositing engine +// +//----------------------------------------------------------------------------- + +#include "ImfForward.h" +#include "ImfNamespace.h" +#include "ImfExport.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + +class IMF_EXPORT DeepCompositing +{ + public: + DeepCompositing(); + virtual ~DeepCompositing(); + + + ////////////////////////////////////////////// + /// + /// composite together the given channels + /// + /// @param outputs - return array of pixel values - + /// @param inputs - arrays of input sample + /// @param channel_names - array of channel names for corresponding channels + /// @param num_channels - number of active channels (3 or greater) + /// @param num_samples - number of values in all input arrays + /// @param sources - number of different sources + /// + /// each array input has num_channels entries: outputs[n] should be the composited + /// values in array inputs[n], whose name will be given by channel_names[n] + /// + /// The channel ordering shall be as follows: + /// Position Channel + /// 0 Z + /// 1 ZBack (if no ZBack, then inputs[1]==inputs[0] and channel_names[1]==channel_names[0]) + /// 2 A (alpha channel) + /// 3-n other channels - only channels in the frame buffer will appear here + /// + /// since a Z and Alpha channel is required, and channel[1] is ZBack or another copy of Z + /// there will always be 3 or more channels. + /// + /// The default implementation calls sort() if and only if more than one source is active, + /// composites all samples together using the Over operator from front to back, + /// stopping as soon as a sample with alpha=1 is found + /// It also blanks all outputs if num_samples==0 + /// + /// note - multiple threads may call composite_pixel simultaneously for different pixels + /// + /// + ////////////////////////////////////////////// + virtual void composite_pixel(float outputs[], + const float * inputs[], + const char * channel_names[], + int num_channels, + int num_samples, + int sources + ); + + + + //////////////////////////////////////////////////////////////// + /// + /// find the depth order for samples with given channel values + /// does not sort the values in-place. Instead it populates + /// array 'order' with the desired sorting order + /// + /// the default operation sorts samples from front to back according to their Z channel + /// + /// @param order - required output order. order[n] shall be the nth closest sample + /// @param inputs - arrays of input samples, one array per channel_name + /// @param channel_names - array of channel names for corresponding channels + /// @param num_channels - number of channels (3 or greater) + /// @param num_samples - number of samples in each array + /// @param sources - number of different sources the data arises from + /// + /// the channel layout is identical to composite_pixel() + /// + /////////////////////////////////////////////////////////////// + + virtual void sort(int order[], + const float * inputs[], + const char * channel_names[], + int num_channels, + int num_samples, + int sources); +}; + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfDeepFrameBuffer.h b/OpenEXR/include/OpenEXR/ImfDeepFrameBuffer.h new file mode 100644 index 0000000..8eec6ff --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfDeepFrameBuffer.h @@ -0,0 +1,339 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2011, 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. +// +/////////////////////////////////////////////////////////////////////////// + +#ifndef IMFDEEPFRAMEBUFFER_H_ +#define IMFDEEPFRAMEBUFFER_H_ + +#include "ImfFrameBuffer.h" +#include "ImfNamespace.h" +#include "ImfExport.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + +//-------------------------------------------------------- +// Description of a single deep slice of the frame buffer: +//-------------------------------------------------------- + +struct IMF_EXPORT DeepSlice : public Slice +{ + //--------------------------------------------------------------------- + // The stride for each sample in this slice. + // + // Memory layout: The address of sample i in pixel (x, y) is + // + // base + (xp / xSampling) * xStride + (yp / ySampling) * yStride + // + i * sampleStride + // + // where xp and yp are computed as follows: + // + // * If we are reading or writing a scanline-based file: + // + // xp = x + // yp = y + // + // * If we are reading a tile whose upper left coorner is at (xt, yt): + // + // if xTileCoords is true then xp = x - xt, else xp = x + // if yTileCoords is true then yp = y - yt, else yp = y + // + //--------------------------------------------------------------------- + + int sampleStride; + + //------------ + // Constructor + //------------ + DeepSlice (PixelType type = HALF, + char * base = 0, + size_t xStride = 0, + size_t yStride = 0, + size_t sampleStride = 0, + int xSampling = 1, + int ySampling = 1, + double fillValue = 0.0, + bool xTileCoords = false, + bool yTileCoords = false); +}; + +//----------------- +// DeepFrameBuffer. +//----------------- + +class IMF_EXPORT DeepFrameBuffer +{ + public: + + + //------------ + // Add a slice + //------------ + + void insert (const char name[], + const DeepSlice &slice); + + void insert (const std::string &name, + const DeepSlice &slice); + + //---------------------------------------------------------------- + // Access to existing slices: + // + // [n] Returns a reference to the slice with name n. + // If no slice with name n exists, an IEX_NAMESPACE::ArgExc + // is thrown. + // + // findSlice(n) Returns a pointer to the slice with name n, + // or 0 if no slice with name n exists. + // + //---------------------------------------------------------------- + + DeepSlice & operator [] (const char name[]); + const DeepSlice & operator [] (const char name[]) const; + + DeepSlice & operator [] (const std::string &name); + const DeepSlice & operator [] (const std::string &name) const; + + DeepSlice * findSlice (const char name[]); + const DeepSlice * findSlice (const char name[]) const; + + DeepSlice * findSlice (const std::string &name); + const DeepSlice * findSlice (const std::string &name) const; + + + //----------------------------------------- + // Iterator-style access to existing slices + //----------------------------------------- + + typedef std::map SliceMap; + + class Iterator; + class ConstIterator; + + Iterator begin (); + ConstIterator begin () const; + + Iterator end (); + ConstIterator end () const; + + Iterator find (const char name[]); + ConstIterator find (const char name[]) const; + + Iterator find (const std::string &name); + ConstIterator find (const std::string &name) const; + + //---------------------------------------------------- + // Public function for accessing a sample count slice. + //---------------------------------------------------- + + void insertSampleCountSlice(const Slice & slice); + const Slice & getSampleCountSlice() const; + + private: + + SliceMap _map; + Slice _sampleCounts; +}; + +//---------- +// Iterators +//---------- + +class DeepFrameBuffer::Iterator +{ + public: + + Iterator (); + Iterator (const DeepFrameBuffer::SliceMap::iterator &i); + + Iterator & operator ++ (); + Iterator operator ++ (int); + + const char * name () const; + DeepSlice & slice () const; + + private: + + friend class DeepFrameBuffer::ConstIterator; + + DeepFrameBuffer::SliceMap::iterator _i; +}; + + +class DeepFrameBuffer::ConstIterator +{ + public: + + ConstIterator (); + ConstIterator (const DeepFrameBuffer::SliceMap::const_iterator &i); + ConstIterator (const DeepFrameBuffer::Iterator &other); + + ConstIterator & operator ++ (); + ConstIterator operator ++ (int); + + const char * name () const; + const DeepSlice & slice () const; + + private: + + friend bool operator == (const ConstIterator &, const ConstIterator &); + friend bool operator != (const ConstIterator &, const ConstIterator &); + + DeepFrameBuffer::SliceMap::const_iterator _i; +}; + + +//----------------- +// Inline Functions +//----------------- + +inline +DeepFrameBuffer::Iterator::Iterator (): _i() +{ + // empty +} + + +inline +DeepFrameBuffer::Iterator::Iterator (const DeepFrameBuffer::SliceMap::iterator &i): + _i (i) +{ + // empty +} + + +inline DeepFrameBuffer::Iterator & +DeepFrameBuffer::Iterator::operator ++ () +{ + ++_i; + return *this; +} + + +inline DeepFrameBuffer::Iterator +DeepFrameBuffer::Iterator::operator ++ (int) +{ + Iterator tmp = *this; + ++_i; + return tmp; +} + + +inline const char * +DeepFrameBuffer::Iterator::name () const +{ + return *_i->first; +} + + +inline DeepSlice & +DeepFrameBuffer::Iterator::slice () const +{ + return _i->second; +} + + +inline +DeepFrameBuffer::ConstIterator::ConstIterator (): _i() +{ + // empty +} + +inline +DeepFrameBuffer::ConstIterator::ConstIterator + (const DeepFrameBuffer::SliceMap::const_iterator &i): _i (i) +{ + // empty +} + + +inline +DeepFrameBuffer::ConstIterator::ConstIterator (const DeepFrameBuffer::Iterator &other): + _i (other._i) +{ + // empty +} + +inline DeepFrameBuffer::ConstIterator & +DeepFrameBuffer::ConstIterator::operator ++ () +{ + ++_i; + return *this; +} + + +inline DeepFrameBuffer::ConstIterator +DeepFrameBuffer::ConstIterator::operator ++ (int) +{ + ConstIterator tmp = *this; + ++_i; + return tmp; +} + + +inline const char * +DeepFrameBuffer::ConstIterator::name () const +{ + return *_i->first; +} + +inline const DeepSlice & +DeepFrameBuffer::ConstIterator::slice () const +{ + return _i->second; +} + + +inline bool +operator == (const DeepFrameBuffer::ConstIterator &x, + const DeepFrameBuffer::ConstIterator &y) +{ + return x._i == y._i; +} + + +inline bool +operator != (const DeepFrameBuffer::ConstIterator &x, + const DeepFrameBuffer::ConstIterator &y) +{ + return !(x == y); +} + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + + + + + +#endif /* IMFDEEPFRAMEBUFFER_H_ */ diff --git a/OpenEXR/include/OpenEXR/ImfDeepImageState.h b/OpenEXR/include/OpenEXR/ImfDeepImageState.h new file mode 100644 index 0000000..a3941c4 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfDeepImageState.h @@ -0,0 +1,96 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2013, 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_DEEPIMAGESTATE_H +#define INCLUDED_IMF_DEEPIMAGESTATE_H + +//----------------------------------------------------------------------------- +// +// enum DeepImageState -- describes how orderly the pixel data +// in a deep image are +// +// The samples in a deep image pixel may be sorted according to +// depth, and the sample depths or depth ranges may or may not +// overlap each other. A pixel is +// +// - SORTED if for every i and j with i < j +// +// (Z[i] < Z[j]) || (Z[i] == Z[j] && ZBack[i] < ZBack[j]), +// +// - NON_OVERLAPPING if for every i and j with i != j +// +// (Z[i] < Z[j] && ZBack[i] <= Z[j]) || +// (Z[j] < Z[i] && ZBack[j] <= Z[i]) || +// (Z[i] == Z[j] && ZBack[i] <= Z[i] & ZBack[j] > Z[j]) || +// (Z[i] == Z[j] && ZBack[j] <= Z[j] & ZBack[i] > Z[i]), +// +// - TIDY if it is SORTED and NON_OVERLAPPING, +// +// - MESSY if it is neither SORTED nor NON_OVERLAPPING. +// +// A deep image is +// +// - MESSY if at least one of its pixels is MESSY, +// - SORTED if all of its pixels are SORTED, +// - NON_OVERLAPPING if all of its pixels are NON_OVERLAPPING, +// - TIDY if all of its pixels are TIDY. +// +// Note: the rather complicated definition of NON_OVERLAPPING prohibits +// overlapping volume samples, coincident point samples and point samples +// in the middle of a volume sample, but it does allow point samples at +// the front or back of a volume sample. +// +//----------------------------------------------------------------------------- + +#include "ImfNamespace.h" +#include "ImfExport.h" + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + +enum DeepImageState +{ + DIS_MESSY = 0, + DIS_SORTED = 1, + DIS_NON_OVERLAPPING = 2, + DIS_TIDY = 3, + + DIS_NUMSTATES // Number of different image states +}; + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfDeepImageStateAttribute.h b/OpenEXR/include/OpenEXR/ImfDeepImageStateAttribute.h new file mode 100644 index 0000000..6174e94 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfDeepImageStateAttribute.h @@ -0,0 +1,68 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2013, 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. +// +/////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDED_IMF_DEEPIMAGESTATE_ATTRIBUTE_H +#define INCLUDED_IMF_DEEPIMAGESTATE_ATTRIBUTE_H + + +//----------------------------------------------------------------------------- +// +// class DeepImageStateAttribute +// +//----------------------------------------------------------------------------- + +#include "ImfAttribute.h" +#include "ImfDeepImageState.h" +#include "ImfExport.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +typedef TypedAttribute + DeepImageStateAttribute; + +template <> IMF_EXPORT const char *DeepImageStateAttribute::staticTypeName (); + +template <> IMF_EXPORT +void DeepImageStateAttribute::writeValueTo + (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &, int) const; + +template <> IMF_EXPORT +void DeepImageStateAttribute::readValueFrom + (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &, int, int); + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfDeepScanLineInputFile.h b/OpenEXR/include/OpenEXR/ImfDeepScanLineInputFile.h new file mode 100644 index 0000000..87a4065 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfDeepScanLineInputFile.h @@ -0,0 +1,276 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2011, 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_DEEP_SCAN_LINE_INPUT_FILE_H +#define INCLUDED_IMF_DEEP_SCAN_LINE_INPUT_FILE_H + +//----------------------------------------------------------------------------- +// +// class DeepScanLineInputFile +// +//----------------------------------------------------------------------------- + +#include "ImfThreading.h" +#include "ImfGenericInputFile.h" +#include "ImfNamespace.h" +#include "ImfForward.h" +#include "ImfExport.h" +#include "ImfDeepScanLineOutputFile.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +class IMF_EXPORT DeepScanLineInputFile : public GenericInputFile +{ + public: + + //------------ + // Constructor + //------------ + + DeepScanLineInputFile (const char fileName[], + int numThreads = globalThreadCount()); + + DeepScanLineInputFile (const Header &header, OPENEXR_IMF_INTERNAL_NAMESPACE::IStream *is, + int version, /*version field from file*/ + int numThreads = globalThreadCount()); + + + //----------------------------------------- + // Destructor -- deallocates internal data + // structures, but does not close the file. + //----------------------------------------- + + virtual ~DeepScanLineInputFile (); + + + //------------------------ + // Access to the file name + //------------------------ + + const char * fileName () const; + + + //-------------------------- + // Access to the file header + //-------------------------- + + const Header & header () const; + + + //---------------------------------- + // Access to the file format version + //---------------------------------- + + int version () const; + + + //----------------------------------------------------------- + // Set the current frame buffer -- copies the FrameBuffer + // object into the InputFile object. + // + // The current frame buffer is the destination for the pixel + // data read from the file. The current frame buffer must be + // set at least once before readPixels() is called. + // The current frame buffer can be changed after each call + // to readPixels(). + //----------------------------------------------------------- + + void setFrameBuffer (const DeepFrameBuffer &frameBuffer); + + + //----------------------------------- + // Access to the current frame buffer + //----------------------------------- + + const DeepFrameBuffer & frameBuffer () const; + + + //--------------------------------------------------------------- + // Check if the file is complete: + // + // isComplete() returns true if all pixels in the data window are + // present in the input file, or false if any pixels are missing. + // (Another program may still be busy writing the file, or file + // writing may have been aborted prematurely.) + //--------------------------------------------------------------- + + bool isComplete () const; + + + //--------------------------------------------------------------- + // Read pixel data: + // + // readPixels(s1,s2) reads all scan lines with y coordinates + // in the interval [min (s1, s2), max (s1, s2)] from the file, + // and stores them in the current frame buffer. + // + // Both s1 and s2 must be within the interval + // [header().dataWindow().min.y, header.dataWindow().max.y] + // + // The scan lines can be read from the file in random order, and + // individual scan lines may be skipped or read multiple times. + // For maximum efficiency, the scan lines should be read in the + // order in which they were written to the file. + // + // readPixels(s) calls readPixels(s,s). + // + // If threading is enabled, readPixels (s1, s2) tries to perform + // decopmression of multiple scanlines in parallel. + // + //--------------------------------------------------------------- + + void readPixels (int scanLine1, int scanLine2); + void readPixels (int scanLine); + + + + //--------------------------------------------------------------- + // Extract pixel data from pre-read block + // + // readPixels(rawPixelData,frameBuffer,s1,s2) reads all scan lines with y coordinates + // in the interval [min (s1, s2), max (s1, s2)] from the data provided and + // stores them in the provided frameBuffer. + // the data can be obtained from a call to rawPixelData() + // + // + // Both s1 and s2 must be within the data specified + // + // you must provide a frameBuffer with a samplecountslice, which must have been read + // and the data valid - readPixels uses your sample count buffer to compute + // offsets to the data it needs + // + // This call does not block, and is thread safe for clients with an existing + // threading model. The InputFile's frameBuffer is not used in this call. + // + // This call is only provided for clients which have an existing threading model in place + // and unpredictable access patterns to the data. + // The fastest way to read an entire image is to enable threading,use setFrameBuffer then + // readPixels(header().dataWindow().min.y, header.dataWindow().max.y) + // + //--------------------------------------------------------------- + + void readPixels (const char * rawPixelData, + const DeepFrameBuffer & frameBuffer, + int scanLine1, + int scanLine2) const; + + //---------------------------------------------- + // Read a block of raw pixel data from the file, + // without uncompressing it (this function is + // used to implement OutputFile::copyPixels()). + // note: returns the entire payload of the relevant chunk of data, not including part number + // including compressed and uncompressed sizes + // on entry, if pixelDataSize is insufficiently large, no bytes are read (pixelData can safely be NULL) + // on exit, pixelDataSize is the number of bytes required to read the chunk + // + //---------------------------------------------- + + void rawPixelData (int firstScanLine, + char * pixelData, + Int64 &pixelDataSize); + + + //------------------------------------------------- + // firstScanLineInChunk() returns the row number of the first row that's stored in the + // same chunk as scanline y. Depending on the compression mode, this may not be the same as y + // + // lastScanLineInChunk() returns the row number of the last row that's stored in the same + // chunk as scanline y. Depending on the compression mode, this may not be the same as y. + // The last chunk in the file may be smaller than all the others + // + //------------------------------------------------ + int firstScanLineInChunk(int y) const; + int lastScanLineInChunk (int y) const; + + //----------------------------------------------------------- + // Read pixel sample counts into a slice in the frame buffer. + // + // readPixelSampleCounts(s1, s2) reads all the counts of + // pixel samples with y coordinates in the interval + // [min (s1, s2), max (s1, s2)] from the file, and stores + // them in the slice naming "sample count". + // + // Both s1 and s2 must be within the interval + // [header().dataWindow().min.y, header.dataWindow().max.y] + // + // readPixelSampleCounts(s) calls readPixelSampleCounts(s,s). + // + //----------------------------------------------------------- + + void readPixelSampleCounts (int scanline1, + int scanline2); + void readPixelSampleCounts (int scanline); + + + //---------------------------------------------------------- + // Read pixel sample counts into the provided frameBuffer + // using a block read of data read by rawPixelData + // for multi-scanline compression schemes, you must decode the entire block + // so scanline1=firstScanLineInChunk(y) and scanline2=lastScanLineInChunk(y) + // + // This call does not block, and is thread safe for clients with an existing + // threading model. The InputFile's frameBuffer is not used in this call. + // + // The fastest way to read an entire image is to enable threading in OpenEXR, use setFrameBuffer then + // readPixelSampleCounts(header().dataWindow().min.y, header.dataWindow().max.y) + // + //---------------------------------------------------------- + void readPixelSampleCounts (const char * rawdata , + const DeepFrameBuffer & frameBuffer, + int scanLine1 , + int scanLine2) const; + + struct Data; + + private: + + Data * _data; + + DeepScanLineInputFile (InputPartData* part); + + void initialize(const Header& header); + void compatibilityInitialize(OPENEXR_IMF_INTERNAL_NAMESPACE::IStream & is); + void multiPartInitialize(InputPartData* part); + + friend class InputFile; + friend class MultiPartInputFile; + friend void DeepScanLineOutputFile::copyPixels(DeepScanLineInputFile &); +}; + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfDeepScanLineInputPart.h b/OpenEXR/include/OpenEXR/ImfDeepScanLineInputPart.h new file mode 100644 index 0000000..c21786b --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfDeepScanLineInputPart.h @@ -0,0 +1,181 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2011, 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef IMFDEEPSCANLINEINPUTPART_H_ +#define IMFDEEPSCANLINEINPUTPART_H_ + +#include "ImfMultiPartInputFile.h" +#include "ImfDeepScanLineInputFile.h" +#include "ImfDeepScanLineOutputFile.h" +#include "ImfNamespace.h" +#include "ImfExport.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + +class IMF_EXPORT DeepScanLineInputPart +{ + public: + + DeepScanLineInputPart(MultiPartInputFile& file, int partNumber); + + //------------------------ + // Access to the file name + //------------------------ + + const char * fileName () const; + + + //-------------------------- + // Access to the file header + //-------------------------- + + const Header & header () const; + + + //---------------------------------- + // Access to the file format version + //---------------------------------- + + int version () const; + + + //----------------------------------------------------------- + // Set the current frame buffer -- copies the FrameBuffer + // object into the InputFile object. + // + // The current frame buffer is the destination for the pixel + // data read from the file. The current frame buffer must be + // set at least once before readPixels() is called. + // The current frame buffer can be changed after each call + // to readPixels(). + //----------------------------------------------------------- + + void setFrameBuffer (const DeepFrameBuffer &frameBuffer); + + + //----------------------------------- + // Access to the current frame buffer + //----------------------------------- + + const DeepFrameBuffer & frameBuffer () const; + + + //--------------------------------------------------------------- + // Check if the file is complete: + // + // isComplete() returns true if all pixels in the data window are + // present in the input file, or false if any pixels are missing. + // (Another program may still be busy writing the file, or file + // writing may have been aborted prematurely.) + //--------------------------------------------------------------- + + bool isComplete () const; + + + //--------------------------------------------------------------- + // Read pixel data: + // + // readPixels(s1,s2) reads all scan lines with y coordinates + // in the interval [min (s1, s2), max (s1, s2)] from the file, + // and stores them in the current frame buffer. + // + // Both s1 and s2 must be within the interval + // [header().dataWindow().min.y, header.dataWindow().max.y] + // + // The scan lines can be read from the file in random order, and + // individual scan lines may be skipped or read multiple times. + // For maximum efficiency, the scan lines should be read in the + // order in which they were written to the file. + // + // readPixels(s) calls readPixels(s,s). + // + // If threading is enabled, readPixels (s1, s2) tries to perform + // decopmression of multiple scanlines in parallel. + // + //--------------------------------------------------------------- + + void readPixels (int scanLine1, int scanLine2); + void readPixels (int scanLine); + void readPixels (const char * rawPixelData,const DeepFrameBuffer & frameBuffer, + int scanLine1,int scanLine2) const; + + //---------------------------------------------- + // Read a block of raw pixel data from the file, + // without uncompressing it (this function is + // used to implement OutputFile::copyPixels()). + //---------------------------------------------- + + void rawPixelData (int firstScanLine, + char * pixelData, + Int64 &pixelDataSize); + + + //----------------------------------------------------------- + // Read pixel sample counts into a slice in the frame buffer. + // + // readPixelSampleCounts(s1, s2) reads all the counts of + // pixel samples with y coordinates in the interval + // [min (s1, s2), max (s1, s2)] from the file, and stores + // them in the slice naming "sample count". + // + // Both s1 and s2 must be within the interval + // [header().dataWindow().min.y, header.dataWindow().max.y] + // + // readPixelSampleCounts(s) calls readPixelSampleCounts(s,s). + //----------------------------------------------------------- + + void readPixelSampleCounts(int scanline1, + int scanline2); + void readPixelSampleCounts(int scanline); + + void readPixelSampleCounts( const char * rawdata , const DeepFrameBuffer & frameBuffer, + int scanLine1 , int scanLine2) const; + + int firstScanLineInChunk(int y) const; + int lastScanLineInChunk (int y) const; + private: + DeepScanLineInputFile *file; + + // needed for copyPixels + friend void DeepScanLineOutputFile::copyPixels(DeepScanLineInputPart &); +}; + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + + + + +#endif /* IMFDEEPSCANLINEINPUTPART_H_ */ diff --git a/OpenEXR/include/OpenEXR/ImfDeepScanLineOutputFile.h b/OpenEXR/include/OpenEXR/ImfDeepScanLineOutputFile.h new file mode 100644 index 0000000..c823d7f --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfDeepScanLineOutputFile.h @@ -0,0 +1,244 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2011, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMF_DEEP_SCAN_LINE_OUTPUT_FILE_H +#define INCLUDED_IMF_DEEP_SCAN_LINE_OUTPUT_FILE_H + +//----------------------------------------------------------------------------- +// +// class DeepScanLineOutputFile +// +//----------------------------------------------------------------------------- + +#include "ImfHeader.h" +#include "ImfFrameBuffer.h" +#include "ImfThreading.h" +#include "ImfGenericOutputFile.h" +#include "ImfNamespace.h" +#include "ImfForward.h" +#include "ImfExport.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +struct PreviewRgba; + +class IMF_EXPORT DeepScanLineOutputFile : public GenericOutputFile +{ + public: + + //----------------------------------------------------------- + // Constructor -- opens the file and writes the file header. + // The file header is also copied into the DeepScanLineOutputFile + // object, and can later be accessed via the header() method. + // Destroying this DeepScanLineOutputFile object automatically closes + // the file. + // + // numThreads determines the number of threads that will be + // used to write the file (see ImfThreading.h). + //----------------------------------------------------------- + + DeepScanLineOutputFile (const char fileName[], const Header &header, + int numThreads = globalThreadCount()); + + + //------------------------------------------------------------ + // Constructor -- attaches the new DeepScanLineOutputFile object + // to a file that has already been opened, and writes the file header. + // The file header is also copied into the DeepScanLineOutputFile + // object, and can later be accessed via the header() method. + // Destroying this DeepScanLineOutputFile object does not automatically + // close the file. + // + // numThreads determines the number of threads that will be + // used to write the file (see ImfThreading.h). + //------------------------------------------------------------ + + DeepScanLineOutputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &os, const Header &header, + int numThreads = globalThreadCount()); + + + //------------------------------------------------- + // Destructor + // + // Destroying the DeepScanLineOutputFile object + // before writing all scan lines within the data + // window results in an incomplete file. + //------------------------------------------------- + + virtual ~DeepScanLineOutputFile (); + + + //------------------------ + // Access to the file name + //------------------------ + + const char * fileName () const; + + + //-------------------------- + // Access to the file header + //-------------------------- + + const Header & header () const; + + + //------------------------------------------------------- + // Set the current frame buffer -- copies the FrameBuffer + // object into the OutputFile object. + // + // The current frame buffer is the source of the pixel + // data written to the file. The current frame buffer + // must be set at least once before writePixels() is + // called. The current frame buffer can be changed + // after each call to writePixels. + //------------------------------------------------------- + + void setFrameBuffer (const DeepFrameBuffer &frameBuffer); + + + //----------------------------------- + // Access to the current frame buffer + //----------------------------------- + + const DeepFrameBuffer & frameBuffer () const; + + + //------------------------------------------------------------------- + // Write pixel data: + // + // writePixels(n) retrieves the next n scan lines worth of data from + // the current frame buffer, starting with the scan line indicated by + // currentScanLine(), and stores the data in the output file, and + // progressing in the direction indicated by header.lineOrder(). + // + // To produce a complete and correct file, exactly m scan lines must + // be written, where m is equal to + // header().dataWindow().max.y - header().dataWindow().min.y + 1. + //------------------------------------------------------------------- + + void writePixels (int numScanLines = 1); + + + //------------------------------------------------------------------ + // Access to the current scan line: + // + // currentScanLine() returns the y coordinate of the first scan line + // that will be read from the current frame buffer during the next + // call to writePixels(). + // + // If header.lineOrder() == INCREASING_Y: + // + // The current scan line before the first call to writePixels() + // is header().dataWindow().min.y. After writing each scan line, + // the current scan line is incremented by 1. + // + // If header.lineOrder() == DECREASING_Y: + // + // The current scan line before the first call to writePixels() + // is header().dataWindow().max.y. After writing each scan line, + // the current scan line is decremented by 1. + // + //------------------------------------------------------------------ + + int currentScanLine () const; + + + //-------------------------------------------------------------- + // Shortcut to copy all pixels from an InputFile into this file, + // without uncompressing and then recompressing the pixel data. + // This file's header must be compatible with the InputFile's + // header: The two header's "dataWindow", "compression", + // "lineOrder" and "channels" attributes must be the same. + //-------------------------------------------------------------- + + void copyPixels (DeepScanLineInputFile &in); + + // -------------------------------------------------------------- + // Shortcut to copy pixels from a given part of a multipart file + // -------------------------------------------------------------- + void copyPixels (DeepScanLineInputPart &in); + + + //-------------------------------------------------------------- + // Updating the preview image: + // + // updatePreviewImage() supplies a new set of pixels for the + // preview image attribute in the file's header. If the header + // does not contain a preview image, updatePreviewImage() throws + // an IEX_NAMESPACE::LogicExc. + // + // Note: updatePreviewImage() is necessary because images are + // often stored in a file incrementally, a few scan lines at a + // time, while the image is being generated. Since the preview + // image is an attribute in the file's header, it gets stored in + // the file as soon as the file is opened, but we may not know + // what the preview image should look like until we have written + // the last scan line of the main image. + // + //-------------------------------------------------------------- + + void updatePreviewImage (const PreviewRgba newPixels[]); + + + struct Data; + + private: + + //------------------------------------------------------------ + // Constructor -- attaches the OutputStreamMutex to the + // given one from MultiPartOutputFile. Set the previewPosition + // and lineOffsetsPosition which have been acquired from + // the constructor of MultiPartOutputFile as well. + //------------------------------------------------------------ + DeepScanLineOutputFile (const OutputPartData* part); + + DeepScanLineOutputFile (const DeepScanLineOutputFile &); // not implemented + DeepScanLineOutputFile & operator = (const DeepScanLineOutputFile &); // not implemented + + void initialize (const Header &header); + void initializeLineBuffer(); + + Data * _data; + + + + friend class MultiPartOutputFile; +}; + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfDeepScanLineOutputPart.h b/OpenEXR/include/OpenEXR/ImfDeepScanLineOutputPart.h new file mode 100644 index 0000000..05410f3 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfDeepScanLineOutputPart.h @@ -0,0 +1,168 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2011, 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. +// +/////////////////////////////////////////////////////////////////////////// + +#ifndef IMFDEEPSCANLINEOUTPUTPART_H_ +#define IMFDEEPSCANLINEOUTPUTPART_H_ + +#include "ImfDeepScanLineOutputFile.h" +#include "ImfMultiPartOutputFile.h" +#include "ImfNamespace.h" +#include "ImfExport.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + +class IMF_EXPORT DeepScanLineOutputPart +{ + public: + + DeepScanLineOutputPart(MultiPartOutputFile& multiPartFile, int partNumber); + + //------------------------ + // Access to the file name + //------------------------ + + const char * fileName () const; + + + //-------------------------- + // Access to the file header + //-------------------------- + + const Header & header () const; + + + //------------------------------------------------------- + // Set the current frame buffer -- copies the FrameBuffer + // object into the OutputFile object. + // + // The current frame buffer is the source of the pixel + // data written to the file. The current frame buffer + // must be set at least once before writePixels() is + // called. The current frame buffer can be changed + // after each call to writePixels. + //------------------------------------------------------- + + void setFrameBuffer (const DeepFrameBuffer &frameBuffer); + + + //----------------------------------- + // Access to the current frame buffer + //----------------------------------- + + const DeepFrameBuffer & frameBuffer () const; + + + //------------------------------------------------------------------- + // Write pixel data: + // + // writePixels(n) retrieves the next n scan lines worth of data from + // the current frame buffer, starting with the scan line indicated by + // currentScanLine(), and stores the data in the output file, and + // progressing in the direction indicated by header.lineOrder(). + // + // To produce a complete and correct file, exactly m scan lines must + // be written, where m is equal to + // header().dataWindow().max.y - header().dataWindow().min.y + 1. + //------------------------------------------------------------------- + + void writePixels (int numScanLines = 1); + + + //------------------------------------------------------------------ + // Access to the current scan line: + // + // currentScanLine() returns the y coordinate of the first scan line + // that will be read from the current frame buffer during the next + // call to writePixels(). + // + // If header.lineOrder() == INCREASING_Y: + // + // The current scan line before the first call to writePixels() + // is header().dataWindow().min.y. After writing each scan line, + // the current scan line is incremented by 1. + // + // If header.lineOrder() == DECREASING_Y: + // + // The current scan line before the first call to writePixels() + // is header().dataWindow().max.y. After writing each scan line, + // the current scan line is decremented by 1. + // + //------------------------------------------------------------------ + + int currentScanLine () const; + + + //-------------------------------------------------------------- + // Shortcut to copy all pixels from an InputFile into this file, + // without uncompressing and then recompressing the pixel data. + // This file's header must be compatible with the InputFile's + // header: The two header's "dataWindow", "compression", + // "lineOrder" and "channels" attributes must be the same. + //-------------------------------------------------------------- + + void copyPixels (DeepScanLineInputFile &in); + void copyPixels (DeepScanLineInputPart &in); + + + //-------------------------------------------------------------- + // Updating the preview image: + // + // updatePreviewImage() supplies a new set of pixels for the + // preview image attribute in the file's header. If the header + // does not contain a preview image, updatePreviewImage() throws + // an IEX_NAMESPACE::LogicExc. + // + // Note: updatePreviewImage() is necessary because images are + // often stored in a file incrementally, a few scan lines at a + // time, while the image is being generated. Since the preview + // image is an attribute in the file's header, it gets stored in + // the file as soon as the file is opened, but we may not know + // what the preview image should look like until we have written + // the last scan line of the main image. + // + //-------------------------------------------------------------- + + void updatePreviewImage (const PreviewRgba newPixels[]); + + private: + DeepScanLineOutputFile* file; +}; + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + + + + +#endif /* IMFDEEPSCANLINEOUTPUTPART_H_ */ diff --git a/OpenEXR/include/OpenEXR/ImfDeepTiledInputFile.h b/OpenEXR/include/OpenEXR/ImfDeepTiledInputFile.h new file mode 100644 index 0000000..87294b5 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfDeepTiledInputFile.h @@ -0,0 +1,437 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2011, 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_DEEP_TILED_INPUT_FILE_H +#define INCLUDED_IMF_DEEP_TILED_INPUT_FILE_H + +//----------------------------------------------------------------------------- +// +// class DeepTiledInputFile +// +//----------------------------------------------------------------------------- + +#include "ImfHeader.h" +#include "ImfFrameBuffer.h" +#include "ImathBox.h" +#include "ImfTileDescription.h" +#include "ImfThreading.h" +#include "ImfGenericInputFile.h" +#include "ImfDeepFrameBuffer.h" +#include "ImfDeepTiledOutputFile.h" +#include "ImfForward.h" +#include "ImfNamespace.h" +#include "ImfExport.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + +class IMF_EXPORT DeepTiledInputFile : public GenericInputFile +{ + public: + + //-------------------------------------------------------------------- + // A constructor that opens the file with the specified name, and + // reads the file header. The constructor throws an IEX_NAMESPACE::ArgExc + // exception if the file is not tiled. + // The numThreads parameter specifies how many worker threads this + // file will try to keep busy when decompressing individual tiles. + // Destroying TiledInputFile objects constructed with this constructor + // automatically closes the corresponding files. + //-------------------------------------------------------------------- + + DeepTiledInputFile (const char fileName[], + int numThreads = globalThreadCount ()); + + + // ---------------------------------------------------------- + // A constructor that attaches the new TiledInputFile object + // to a file that has already been opened. + // Destroying TiledInputFile objects constructed with this + // constructor does not automatically close the corresponding + // files. + // ---------------------------------------------------------- + + DeepTiledInputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is, int numThreads = globalThreadCount ()); + + + //----------- + // Destructor + //----------- + + virtual ~DeepTiledInputFile (); + + + //------------------------ + // Access to the file name + //------------------------ + + const char * fileName () const; + + + //-------------------------- + // Access to the file header + //-------------------------- + + const Header & header () const; + + + //---------------------------------- + // Access to the file format version + //---------------------------------- + + int version () const; + + + //----------------------------------------------------------- + // Set the current frame buffer -- copies the FrameBuffer + // object into the TiledInputFile object. + // + // The current frame buffer is the destination for the pixel + // data read from the file. The current frame buffer must be + // set at least once before readTile() is called. + // The current frame buffer can be changed after each call + // to readTile(). + //----------------------------------------------------------- + + void setFrameBuffer (const DeepFrameBuffer &frameBuffer); + + + //----------------------------------- + // Access to the current frame buffer + //----------------------------------- + + const DeepFrameBuffer & frameBuffer () const; + + + //------------------------------------------------------------ + // Check if the file is complete: + // + // isComplete() returns true if all pixels in the data window + // (in all levels) are present in the input file, or false if + // any pixels are missing. (Another program may still be busy + // writing the file, or file writing may have been aborted + // prematurely.) + //------------------------------------------------------------ + + bool isComplete () const; + + + //-------------------------------------------------- + // Utility functions: + //-------------------------------------------------- + + //--------------------------------------------------------- + // Multiresolution mode and tile size: + // The following functions return the xSize, ySize and mode + // fields of the file header's TileDescriptionAttribute. + //--------------------------------------------------------- + + unsigned int tileXSize () const; + unsigned int tileYSize () const; + LevelMode levelMode () const; + LevelRoundingMode levelRoundingMode () const; + + + //-------------------------------------------------------------------- + // Number of levels: + // + // numXLevels() returns the file's number of levels in x direction. + // + // if levelMode() == ONE_LEVEL: + // return value is: 1 + // + // if levelMode() == MIPMAP_LEVELS: + // return value is: rfunc (log (max (w, h)) / log (2)) + 1 + // + // if levelMode() == RIPMAP_LEVELS: + // return value is: rfunc (log (w) / log (2)) + 1 + // + // where + // w is the width of the image's data window, max.x - min.x + 1, + // y is the height of the image's data window, max.y - min.y + 1, + // and rfunc(x) is either floor(x), or ceil(x), depending on + // whether levelRoundingMode() returns ROUND_DOWN or ROUND_UP. + // + // numYLevels() returns the file's number of levels in y direction. + // + // if levelMode() == ONE_LEVEL or levelMode() == MIPMAP_LEVELS: + // return value is the same as for numXLevels() + // + // if levelMode() == RIPMAP_LEVELS: + // return value is: rfunc (log (h) / log (2)) + 1 + // + // + // numLevels() is a convenience function for use with + // MIPMAP_LEVELS files. + // + // if levelMode() == ONE_LEVEL or levelMode() == MIPMAP_LEVELS: + // return value is the same as for numXLevels() + // + // if levelMode() == RIPMAP_LEVELS: + // an IEX_NAMESPACE::LogicExc exception is thrown + // + // isValidLevel(lx, ly) returns true if the file contains + // a level with level number (lx, ly), false if not. + // + // totalTiles() returns the total number of tiles in the image + // + //-------------------------------------------------------------------- + + int numLevels () const; + int numXLevels () const; + int numYLevels () const; + bool isValidLevel (int lx, int ly) const; + size_t totalTiles() const; + + //---------------------------------------------------------- + // Dimensions of a level: + // + // levelWidth(lx) returns the width of a level with level + // number (lx, *), where * is any number. + // + // return value is: + // max (1, rfunc (w / pow (2, lx))) + // + // + // levelHeight(ly) returns the height of a level with level + // number (*, ly), where * is any number. + // + // return value is: + // max (1, rfunc (h / pow (2, ly))) + // + //---------------------------------------------------------- + + int levelWidth (int lx) const; + int levelHeight (int ly) const; + + + //-------------------------------------------------------------- + // Number of tiles: + // + // numXTiles(lx) returns the number of tiles in x direction + // that cover a level with level number (lx, *), where * is + // any number. + // + // return value is: + // (levelWidth(lx) + tileXSize() - 1) / tileXSize() + // + // + // numYTiles(ly) returns the number of tiles in y direction + // that cover a level with level number (*, ly), where * is + // any number. + // + // return value is: + // (levelHeight(ly) + tileXSize() - 1) / tileXSize() + // + //-------------------------------------------------------------- + + int numXTiles (int lx = 0) const; + int numYTiles (int ly = 0) const; + + + //--------------------------------------------------------------- + // Level pixel ranges: + // + // dataWindowForLevel(lx, ly) returns a 2-dimensional region of + // valid pixel coordinates for a level with level number (lx, ly) + // + // return value is a Box2i with min value: + // (dataWindow.min.x, dataWindow.min.y) + // + // and max value: + // (dataWindow.min.x + levelWidth(lx) - 1, + // dataWindow.min.y + levelHeight(ly) - 1) + // + // dataWindowForLevel(level) is a convenience function used + // for ONE_LEVEL and MIPMAP_LEVELS files. It returns + // dataWindowForLevel(level, level). + // + //--------------------------------------------------------------- + + IMATH_NAMESPACE::Box2i dataWindowForLevel (int l = 0) const; + IMATH_NAMESPACE::Box2i dataWindowForLevel (int lx, int ly) const; + + + //------------------------------------------------------------------- + // Tile pixel ranges: + // + // dataWindowForTile(dx, dy, lx, ly) returns a 2-dimensional + // region of valid pixel coordinates for a tile with tile coordinates + // (dx,dy) and level number (lx, ly). + // + // return value is a Box2i with min value: + // (dataWindow.min.x + dx * tileXSize(), + // dataWindow.min.y + dy * tileYSize()) + // + // and max value: + // (dataWindow.min.x + (dx + 1) * tileXSize() - 1, + // dataWindow.min.y + (dy + 1) * tileYSize() - 1) + // + // dataWindowForTile(dx, dy, level) is a convenience function + // used for ONE_LEVEL and MIPMAP_LEVELS files. It returns + // dataWindowForTile(dx, dy, level, level). + // + //------------------------------------------------------------------- + + IMATH_NAMESPACE::Box2i dataWindowForTile (int dx, int dy, int l = 0) const; + + IMATH_NAMESPACE::Box2i dataWindowForTile (int dx, int dy, + int lx, int ly) const; + + //------------------------------------------------------------ + // Read pixel data: + // + // readTile(dx, dy, lx, ly) reads the tile with tile + // coordinates (dx, dy), and level number (lx, ly), + // and stores it in the current frame buffer. + // + // dx must lie in the interval [0, numXTiles(lx)-1] + // dy must lie in the interval [0, numYTiles(ly)-1] + // + // lx must lie in the interval [0, numXLevels()-1] + // ly must lie in the inverval [0, numYLevels()-1] + // + // readTile(dx, dy, level) is a convenience function used + // for ONE_LEVEL and MIPMAP_LEVELS files. It calls + // readTile(dx, dy, level, level). + // + // The two readTiles(dx1, dx2, dy1, dy2, ...) functions allow + // reading multiple tiles at once. If multi-threading is used + // the multiple tiles are read concurrently. + // + // Pixels that are outside the pixel coordinate range for the + // tile's level, are never accessed by readTile(). + // + // Attempting to access a tile that is not present in the file + // throws an InputExc exception. + // + //------------------------------------------------------------ + + void readTile (int dx, int dy, int l = 0); + void readTile (int dx, int dy, int lx, int ly); + + void readTiles (int dx1, int dx2, int dy1, int dy2, + int lx, int ly); + + void readTiles (int dx1, int dx2, int dy1, int dy2, + int l = 0); + + + //-------------------------------------------------- + // Read a tile of raw pixel data from the file, + // without uncompressing it (this function is + // used to implement TiledOutputFile::copyPixels()). + //-------------------------------------------------- + + void rawTileData (int &dx, int &dy, + int &lx, int &ly, + char *pixelData, + Int64 &dataSize) const; + + //------------------------------------------------------------------ + // Read pixel sample counts into a slice in the frame buffer. + // + // readPixelSampleCount(dx, dy, lx, ly) reads the sample counts + // for tile (dx, dy) in level (lx, ly). + // + // readPixelSampleCount(dx, dy, l) calls + // readPixelSampleCount(dx, dy, lx = l, ly = l) + // + // dx must lie in the interval [0, numXTiles(lx)-1] + // dy must lie in the interval [0, numYTiles(ly)-1] + // + // lx must lie in the interval [0, numXLevels()-1] + // ly must lie in the inverval [0, numYLevels()-1] + // + // readPixelSampleCounts(dx1, dx2, dy1, dy2, lx, ly) reads all + // the sample counts for tiles within range + // [(min(dx1, dx2), min(dy1, dy2))...(max(dx1, dx2), max(dy1, dy2)], + // and on level (lx, ly) + // + // readPixelSampleCounts(dx1, dx2, dy1, dy2, l) calls + // readPixelSampleCounts(dx1, dx2, dy1, dy2, lx = l, ly = l). + //------------------------------------------------------------------ + + void readPixelSampleCount (int dx, int dy, int l = 0); + void readPixelSampleCount (int dx, int dy, int lx, int ly); + + void readPixelSampleCounts (int dx1, int dx2, + int dy1, int dy2, + int lx, int ly); + + void readPixelSampleCounts (int dx1, int dx2, + int dy1, int dy2, + int l = 0); + + struct Data; + + + + private: + + friend class InputFile; + friend class MultiPartInputFile; + + DeepTiledInputFile (InputPartData* part); + + DeepTiledInputFile (const DeepTiledInputFile &); // not implemented + DeepTiledInputFile & operator = (const DeepTiledInputFile &); // not implemented + + DeepTiledInputFile (const Header &header, OPENEXR_IMF_INTERNAL_NAMESPACE::IStream *is, int version, + int numThreads); + + void initialize (); + void multiPartInitialize(InputPartData* part); + void compatibilityInitialize(OPENEXR_IMF_INTERNAL_NAMESPACE::IStream& is); + + bool isValidTile (int dx, int dy, + int lx, int ly) const; + + size_t bytesPerLineForTile (int dx, int dy, + int lx, int ly) const; + + + void getTileOrder(int dx[],int dy[],int lx[],int ly[]) const; + + + Data * _data; + + + // needed for copyPixels + friend void DeepTiledOutputFile::copyPixels(DeepTiledInputFile &); +}; + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfDeepTiledInputPart.h b/OpenEXR/include/OpenEXR/ImfDeepTiledInputPart.h new file mode 100644 index 0000000..8663639 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfDeepTiledInputPart.h @@ -0,0 +1,362 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2011, 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef IMFDEEPTILEDINPUTPART_H_ +#define IMFDEEPTILEDINPUTPART_H_ + +#include "ImfDeepTiledInputFile.h" +#include "ImfNamespace.h" +#include "ImfForward.h" +#include "ImfExport.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + +class IMF_EXPORT DeepTiledInputPart +{ + public: + + DeepTiledInputPart(MultiPartInputFile& multiPartFile, int partNumber); + + //------------------------ + // Access to the file name + //------------------------ + + const char * fileName () const; + + + //-------------------------- + // Access to the file header + //-------------------------- + + const Header & header () const; + + + //---------------------------------- + // Access to the file format version + //---------------------------------- + + int version () const; + + + //----------------------------------------------------------- + // Set the current frame buffer -- copies the FrameBuffer + // object into the TiledInputFile object. + // + // The current frame buffer is the destination for the pixel + // data read from the file. The current frame buffer must be + // set at least once before readTile() is called. + // The current frame buffer can be changed after each call + // to readTile(). + //----------------------------------------------------------- + + void setFrameBuffer (const DeepFrameBuffer &frameBuffer); + + + //----------------------------------- + // Access to the current frame buffer + //----------------------------------- + + const DeepFrameBuffer & frameBuffer () const; + + + //------------------------------------------------------------ + // Check if the file is complete: + // + // isComplete() returns true if all pixels in the data window + // (in all levels) are present in the input file, or false if + // any pixels are missing. (Another program may still be busy + // writing the file, or file writing may have been aborted + // prematurely.) + //------------------------------------------------------------ + + bool isComplete () const; + + + //-------------------------------------------------- + // Utility functions: + //-------------------------------------------------- + + //--------------------------------------------------------- + // Multiresolution mode and tile size: + // The following functions return the xSize, ySize and mode + // fields of the file header's TileDescriptionAttribute. + //--------------------------------------------------------- + + unsigned int tileXSize () const; + unsigned int tileYSize () const; + LevelMode levelMode () const; + LevelRoundingMode levelRoundingMode () const; + + + //-------------------------------------------------------------------- + // Number of levels: + // + // numXLevels() returns the file's number of levels in x direction. + // + // if levelMode() == ONE_LEVEL: + // return value is: 1 + // + // if levelMode() == MIPMAP_LEVELS: + // return value is: rfunc (log (max (w, h)) / log (2)) + 1 + // + // if levelMode() == RIPMAP_LEVELS: + // return value is: rfunc (log (w) / log (2)) + 1 + // + // where + // w is the width of the image's data window, max.x - min.x + 1, + // y is the height of the image's data window, max.y - min.y + 1, + // and rfunc(x) is either floor(x), or ceil(x), depending on + // whether levelRoundingMode() returns ROUND_DOWN or ROUND_UP. + // + // numYLevels() returns the file's number of levels in y direction. + // + // if levelMode() == ONE_LEVEL or levelMode() == MIPMAP_LEVELS: + // return value is the same as for numXLevels() + // + // if levelMode() == RIPMAP_LEVELS: + // return value is: rfunc (log (h) / log (2)) + 1 + // + // + // numLevels() is a convenience function for use with + // MIPMAP_LEVELS files. + // + // if levelMode() == ONE_LEVEL or levelMode() == MIPMAP_LEVELS: + // return value is the same as for numXLevels() + // + // if levelMode() == RIPMAP_LEVELS: + // an IEX_NAMESPACE::LogicExc exception is thrown + // + // isValidLevel(lx, ly) returns true if the file contains + // a level with level number (lx, ly), false if not. + // + //-------------------------------------------------------------------- + + int numLevels () const; + int numXLevels () const; + int numYLevels () const; + bool isValidLevel (int lx, int ly) const; + + + //---------------------------------------------------------- + // Dimensions of a level: + // + // levelWidth(lx) returns the width of a level with level + // number (lx, *), where * is any number. + // + // return value is: + // max (1, rfunc (w / pow (2, lx))) + // + // + // levelHeight(ly) returns the height of a level with level + // number (*, ly), where * is any number. + // + // return value is: + // max (1, rfunc (h / pow (2, ly))) + // + //---------------------------------------------------------- + + int levelWidth (int lx) const; + int levelHeight (int ly) const; + + + //-------------------------------------------------------------- + // Number of tiles: + // + // numXTiles(lx) returns the number of tiles in x direction + // that cover a level with level number (lx, *), where * is + // any number. + // + // return value is: + // (levelWidth(lx) + tileXSize() - 1) / tileXSize() + // + // + // numYTiles(ly) returns the number of tiles in y direction + // that cover a level with level number (*, ly), where * is + // any number. + // + // return value is: + // (levelHeight(ly) + tileXSize() - 1) / tileXSize() + // + //-------------------------------------------------------------- + + int numXTiles (int lx = 0) const; + int numYTiles (int ly = 0) const; + + + //--------------------------------------------------------------- + // Level pixel ranges: + // + // dataWindowForLevel(lx, ly) returns a 2-dimensional region of + // valid pixel coordinates for a level with level number (lx, ly) + // + // return value is a Box2i with min value: + // (dataWindow.min.x, dataWindow.min.y) + // + // and max value: + // (dataWindow.min.x + levelWidth(lx) - 1, + // dataWindow.min.y + levelHeight(ly) - 1) + // + // dataWindowForLevel(level) is a convenience function used + // for ONE_LEVEL and MIPMAP_LEVELS files. It returns + // dataWindowForLevel(level, level). + // + //--------------------------------------------------------------- + + IMATH_NAMESPACE::Box2i dataWindowForLevel (int l = 0) const; + IMATH_NAMESPACE::Box2i dataWindowForLevel (int lx, int ly) const; + + + //------------------------------------------------------------------- + // Tile pixel ranges: + // + // dataWindowForTile(dx, dy, lx, ly) returns a 2-dimensional + // region of valid pixel coordinates for a tile with tile coordinates + // (dx,dy) and level number (lx, ly). + // + // return value is a Box2i with min value: + // (dataWindow.min.x + dx * tileXSize(), + // dataWindow.min.y + dy * tileYSize()) + // + // and max value: + // (dataWindow.min.x + (dx + 1) * tileXSize() - 1, + // dataWindow.min.y + (dy + 1) * tileYSize() - 1) + // + // dataWindowForTile(dx, dy, level) is a convenience function + // used for ONE_LEVEL and MIPMAP_LEVELS files. It returns + // dataWindowForTile(dx, dy, level, level). + // + //------------------------------------------------------------------- + + IMATH_NAMESPACE::Box2i dataWindowForTile (int dx, int dy, int l = 0) const; + + IMATH_NAMESPACE::Box2i dataWindowForTile (int dx, int dy, + int lx, int ly) const; + + //------------------------------------------------------------ + // Read pixel data: + // + // readTile(dx, dy, lx, ly) reads the tile with tile + // coordinates (dx, dy), and level number (lx, ly), + // and stores it in the current frame buffer. + // + // dx must lie in the interval [0, numXTiles(lx)-1] + // dy must lie in the interval [0, numYTiles(ly)-1] + // + // lx must lie in the interval [0, numXLevels()-1] + // ly must lie in the inverval [0, numYLevels()-1] + // + // readTile(dx, dy, level) is a convenience function used + // for ONE_LEVEL and MIPMAP_LEVELS files. It calls + // readTile(dx, dy, level, level). + // + // The two readTiles(dx1, dx2, dy1, dy2, ...) functions allow + // reading multiple tiles at once. If multi-threading is used + // the multiple tiles are read concurrently. + // + // Pixels that are outside the pixel coordinate range for the + // tile's level, are never accessed by readTile(). + // + // Attempting to access a tile that is not present in the file + // throws an InputExc exception. + // + //------------------------------------------------------------ + + void readTile (int dx, int dy, int l = 0); + void readTile (int dx, int dy, int lx, int ly); + + void readTiles (int dx1, int dx2, int dy1, int dy2, + int lx, int ly); + + void readTiles (int dx1, int dx2, int dy1, int dy2, + int l = 0); + + + //-------------------------------------------------- + // Read a tile of raw pixel data from the file, + // without uncompressing it (this function is + // used to implement TiledOutputFile::copyPixels()). + //-------------------------------------------------- + + void rawTileData (int &dx, int &dy, + int &lx, int &ly, + char *data, + Int64 &dataSize + ) const; + + //------------------------------------------------------------------ + // Read pixel sample counts into a slice in the frame buffer. + // + // readPixelSampleCount(dx, dy, lx, ly) reads the sample counts + // for tile (dx, dy) in level (lx, ly). + // + // readPixelSampleCount(dx, dy, l) calls + // readPixelSampleCount(dx, dy, lx = l, ly = l) + // + // dx must lie in the interval [0, numXTiles(lx)-1] + // dy must lie in the interval [0, numYTiles(ly)-1] + // + // lx must lie in the interval [0, numXLevels()-1] + // ly must lie in the inverval [0, numYLevels()-1] + // + // readPixelSampleCounts(dx1, dx2, dy1, dy2, lx, ly) reads all + // the sample counts for tiles within range + // [(min(dx1, dx2), min(dy1, dy2))...(max(dx1, dx2), max(dy1, dy2)], + // and on level (lx, ly) + // + // readPixelSampleCounts(dx1, dx2, dy1, dy2, l) calls + // readPixelSampleCounts(dx1, dx2, dy1, dy2, lx = l, ly = l). + //------------------------------------------------------------------ + + void readPixelSampleCount (int dx, int dy, int l = 0); + void readPixelSampleCount (int dx, int dy, int lx, int ly); + + void readPixelSampleCounts (int dx1, int dx2, + int dy1, int dy2, + int lx, int ly); + + void readPixelSampleCounts (int dx1, int dx2, + int dy1, int dy2, + int l = 0); + + private: + DeepTiledInputFile* file; + + friend void DeepTiledOutputFile::copyPixels(DeepTiledInputPart &); +}; + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + +#endif /* IMFDEEPTILEDINPUTPART_H_ */ diff --git a/OpenEXR/include/OpenEXR/ImfDeepTiledOutputFile.h b/OpenEXR/include/OpenEXR/ImfDeepTiledOutputFile.h new file mode 100644 index 0000000..e12dda1 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfDeepTiledOutputFile.h @@ -0,0 +1,475 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2011, 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_DEEP_TILED_OUTPUT_FILE_H +#define INCLUDED_IMF_DEEP_TILED_OUTPUT_FILE_H + +//----------------------------------------------------------------------------- +// +// class DeepTiledOutputFile +// +//----------------------------------------------------------------------------- + +#include "ImfHeader.h" +#include "ImfFrameBuffer.h" +#include "ImathBox.h" +#include "ImfThreading.h" +#include "ImfGenericOutputFile.h" +#include "ImfNamespace.h" +#include "ImfForward.h" +#include "ImfExport.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +class IMF_EXPORT DeepTiledOutputFile : public GenericOutputFile +{ + public: + + //------------------------------------------------------------------- + // A constructor that opens the file with the specified name, and + // writes the file header. The file header is also copied into the + // TiledOutputFile object, and can later be accessed via the header() + // method. + // + // Destroying TiledOutputFile constructed with this constructor + // automatically closes the corresponding files. + // + // The header must contain a TileDescriptionAttribute called "tiles". + // + // The x and y subsampling factors for all image channels must be 1; + // subsampling is not supported. + // + // Tiles can be written to the file in arbitrary order. The line + // order attribute can be used to cause the tiles to be sorted in + // the file. When the file is read later, reading the tiles in the + // same order as they are in the file tends to be significantly + // faster than reading the tiles in random order (see writeTile, + // below). + //------------------------------------------------------------------- + + DeepTiledOutputFile (const char fileName[], + const Header &header, + int numThreads = globalThreadCount ()); + + + // ---------------------------------------------------------------- + // A constructor that attaches the new TiledOutputFile object to + // a file that has already been opened. Destroying TiledOutputFile + // objects constructed with this constructor does not automatically + // close the corresponding files. + // ---------------------------------------------------------------- + + DeepTiledOutputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &os, + const Header &header, + int numThreads = globalThreadCount ()); + + + //----------------------------------------------------- + // Destructor + // + // Destroying a TiledOutputFile object before all tiles + // have been written results in an incomplete file. + //----------------------------------------------------- + + virtual ~DeepTiledOutputFile (); + + + //------------------------ + // Access to the file name + //------------------------ + + const char * fileName () const; + + + //-------------------------- + // Access to the file header + //-------------------------- + + const Header & header () const; + + + //------------------------------------------------------- + // Set the current frame buffer -- copies the FrameBuffer + // object into the TiledOutputFile object. + // + // The current frame buffer is the source of the pixel + // data written to the file. The current frame buffer + // must be set at least once before writeTile() is + // called. The current frame buffer can be changed + // after each call to writeTile(). + //------------------------------------------------------- + + void setFrameBuffer (const DeepFrameBuffer &frameBuffer); + + + //----------------------------------- + // Access to the current frame buffer + //----------------------------------- + + const DeepFrameBuffer & frameBuffer () const; + + + //------------------- + // Utility functions: + //------------------- + + //--------------------------------------------------------- + // Multiresolution mode and tile size: + // The following functions return the xSize, ySize and mode + // fields of the file header's TileDescriptionAttribute. + //--------------------------------------------------------- + + unsigned int tileXSize () const; + unsigned int tileYSize () const; + LevelMode levelMode () const; + LevelRoundingMode levelRoundingMode () const; + + + //-------------------------------------------------------------------- + // Number of levels: + // + // numXLevels() returns the file's number of levels in x direction. + // + // if levelMode() == ONE_LEVEL: + // return value is: 1 + // + // if levelMode() == MIPMAP_LEVELS: + // return value is: rfunc (log (max (w, h)) / log (2)) + 1 + // + // if levelMode() == RIPMAP_LEVELS: + // return value is: rfunc (log (w) / log (2)) + 1 + // + // where + // w is the width of the image's data window, max.x - min.x + 1, + // y is the height of the image's data window, max.y - min.y + 1, + // and rfunc(x) is either floor(x), or ceil(x), depending on + // whether levelRoundingMode() returns ROUND_DOWN or ROUND_UP. + // + // numYLevels() returns the file's number of levels in y direction. + // + // if levelMode() == ONE_LEVEL or levelMode() == MIPMAP_LEVELS: + // return value is the same as for numXLevels() + // + // if levelMode() == RIPMAP_LEVELS: + // return value is: rfunc (log (h) / log (2)) + 1 + // + // + // numLevels() is a convenience function for use with MIPMAP_LEVELS + // files. + // + // if levelMode() == ONE_LEVEL or levelMode() == MIPMAP_LEVELS: + // return value is the same as for numXLevels() + // + // if levelMode() == RIPMAP_LEVELS: + // an IEX_NAMESPACE::LogicExc exception is thrown + // + // isValidLevel(lx, ly) returns true if the file contains + // a level with level number (lx, ly), false if not. + // + //-------------------------------------------------------------------- + + int numLevels () const; + int numXLevels () const; + int numYLevels () const; + bool isValidLevel (int lx, int ly) const; + + + //--------------------------------------------------------- + // Dimensions of a level: + // + // levelWidth(lx) returns the width of a level with level + // number (lx, *), where * is any number. + // + // return value is: + // max (1, rfunc (w / pow (2, lx))) + // + // + // levelHeight(ly) returns the height of a level with level + // number (*, ly), where * is any number. + // + // return value is: + // max (1, rfunc (h / pow (2, ly))) + // + //--------------------------------------------------------- + + int levelWidth (int lx) const; + int levelHeight (int ly) const; + + + //---------------------------------------------------------- + // Number of tiles: + // + // numXTiles(lx) returns the number of tiles in x direction + // that cover a level with level number (lx, *), where * is + // any number. + // + // return value is: + // (levelWidth(lx) + tileXSize() - 1) / tileXSize() + // + // + // numYTiles(ly) returns the number of tiles in y direction + // that cover a level with level number (*, ly), where * is + // any number. + // + // return value is: + // (levelHeight(ly) + tileXSize() - 1) / tileXSize() + // + //---------------------------------------------------------- + + int numXTiles (int lx = 0) const; + int numYTiles (int ly = 0) const; + + + //--------------------------------------------------------- + // Level pixel ranges: + // + // dataWindowForLevel(lx, ly) returns a 2-dimensional + // region of valid pixel coordinates for a level with + // level number (lx, ly) + // + // return value is a Box2i with min value: + // (dataWindow.min.x, dataWindow.min.y) + // + // and max value: + // (dataWindow.min.x + levelWidth(lx) - 1, + // dataWindow.min.y + levelHeight(ly) - 1) + // + // dataWindowForLevel(level) is a convenience function used + // for ONE_LEVEL and MIPMAP_LEVELS files. It returns + // dataWindowForLevel(level, level). + // + //--------------------------------------------------------- + + IMATH_NAMESPACE::Box2i dataWindowForLevel (int l = 0) const; + IMATH_NAMESPACE::Box2i dataWindowForLevel (int lx, int ly) const; + + + //------------------------------------------------------------------- + // Tile pixel ranges: + // + // dataWindowForTile(dx, dy, lx, ly) returns a 2-dimensional + // region of valid pixel coordinates for a tile with tile coordinates + // (dx,dy) and level number (lx, ly). + // + // return value is a Box2i with min value: + // (dataWindow.min.x + dx * tileXSize(), + // dataWindow.min.y + dy * tileYSize()) + // + // and max value: + // (dataWindow.min.x + (dx + 1) * tileXSize() - 1, + // dataWindow.min.y + (dy + 1) * tileYSize() - 1) + // + // dataWindowForTile(dx, dy, level) is a convenience function + // used for ONE_LEVEL and MIPMAP_LEVELS files. It returns + // dataWindowForTile(dx, dy, level, level). + // + //------------------------------------------------------------------- + + IMATH_NAMESPACE::Box2i dataWindowForTile (int dx, int dy, + int l = 0) const; + + IMATH_NAMESPACE::Box2i dataWindowForTile (int dx, int dy, + int lx, int ly) const; + + //------------------------------------------------------------------ + // Write pixel data: + // + // writeTile(dx, dy, lx, ly) writes the tile with tile + // coordinates (dx, dy), and level number (lx, ly) to + // the file. + // + // dx must lie in the interval [0, numXTiles(lx) - 1] + // dy must lie in the interval [0, numYTiles(ly) - 1] + // + // lx must lie in the interval [0, numXLevels() - 1] + // ly must lie in the inverval [0, numYLevels() - 1] + // + // writeTile(dx, dy, level) is a convenience function + // used for ONE_LEVEL and MIPMAP_LEVEL files. It calls + // writeTile(dx, dy, level, level). + // + // The two writeTiles(dx1, dx2, dy1, dy2, ...) functions allow + // writing multiple tiles at once. If multi-threading is used + // multiple tiles are written concurrently. The tile coordinates, + // dx1, dx2 and dy1, dy2, specify inclusive ranges of tile + // coordinates. It is valid for dx1 < dx2 or dy1 < dy2; the + // tiles are always written in the order specified by the line + // order attribute. Hence, it is not possible to specify an + // "invalid" or empty tile range. + // + // Pixels that are outside the pixel coordinate range for the tile's + // level, are never accessed by writeTile(). + // + // Each tile in the file must be written exactly once. + // + // The file's line order attribute determines the order of the tiles + // in the file: + // + // INCREASING_Y In the file, the tiles for each level are stored + // in a contiguous block. The levels are ordered + // like this: + // + // (0, 0) (1, 0) ... (nx-1, 0) + // (0, 1) (1, 1) ... (nx-1, 1) + // ... + // (0,ny-1) (1,ny-1) ... (nx-1,ny-1) + // + // where nx = numXLevels(), and ny = numYLevels(). + // In an individual level, (lx, ly), the tiles + // are stored in the following order: + // + // (0, 0) (1, 0) ... (tx-1, 0) + // (0, 1) (1, 1) ... (tx-1, 1) + // ... + // (0,ty-1) (1,ty-1) ... (tx-1,ty-1) + // + // where tx = numXTiles(lx), + // and ty = numYTiles(ly). + // + // DECREASING_Y As for INCREASING_Y, the tiles for each level + // are stored in a contiguous block. The levels + // are ordered the same way as for INCREASING_Y, + // but within an individual level, the tiles + // are stored in this order: + // + // (0,ty-1) (1,ty-1) ... (tx-1,ty-1) + // ... + // (0, 1) (1, 1) ... (tx-1, 1) + // (0, 0) (1, 0) ... (tx-1, 0) + // + // + // RANDOM_Y The order of the calls to writeTile() determines + // the order of the tiles in the file. + // + //------------------------------------------------------------------ + + void writeTile (int dx, int dy, int l = 0); + void writeTile (int dx, int dy, int lx, int ly); + + void writeTiles (int dx1, int dx2, int dy1, int dy2, + int lx, int ly); + + void writeTiles (int dx1, int dx2, int dy1, int dy2, + int l = 0); + + + //------------------------------------------------------------------ + // Shortcut to copy all pixels from a TiledInputFile into this file, + // without uncompressing and then recompressing the pixel data. + // This file's header must be compatible with the TiledInputFile's + // header: The two header's "dataWindow", "compression", + // "lineOrder", "channels", and "tiles" attributes must be the same. + //------------------------------------------------------------------ + + void copyPixels (DeepTiledInputFile &in); + void copyPixels (DeepTiledInputPart &in); + + + + //-------------------------------------------------------------- + // Updating the preview image: + // + // updatePreviewImage() supplies a new set of pixels for the + // preview image attribute in the file's header. If the header + // does not contain a preview image, updatePreviewImage() throws + // an IEX_NAMESPACE::LogicExc. + // + // Note: updatePreviewImage() is necessary because images are + // often stored in a file incrementally, a few tiles at a time, + // while the image is being generated. Since the preview image + // is an attribute in the file's header, it gets stored in the + // file as soon as the file is opened, but we may not know what + // the preview image should look like until we have written the + // last tile of the main image. + // + //-------------------------------------------------------------- + + void updatePreviewImage (const PreviewRgba newPixels[]); + + + //------------------------------------------------------------- + // Break a tile -- for testing and debugging only: + // + // breakTile(dx,dy,lx,ly,p,n,c) introduces an error into the + // output file by writing n copies of character c, starting + // p bytes from the beginning of the tile with tile coordinates + // (dx, dy) and level number (lx, ly). + // + // Warning: Calling this function usually results in a broken + // image file. The file or parts of it may not be readable, + // or the file may contain bad data. + // + //------------------------------------------------------------- + + void breakTile (int dx, int dy, + int lx, int ly, + int offset, + int length, + char c); + struct Data; + + private: + + // ---------------------------------------------------------------- + // A constructor attaches the OutputStreamMutex to the + // given one from MultiPartOutputFile. Set the previewPosition + // and lineOffsetsPosition which have been acquired from + // the constructor of MultiPartOutputFile as well. + // ---------------------------------------------------------------- + DeepTiledOutputFile (const OutputPartData* part); + + DeepTiledOutputFile (const DeepTiledOutputFile &); // not implemented + DeepTiledOutputFile & operator = (const DeepTiledOutputFile &); // not implemented + + void initialize (const Header &header); + + bool isValidTile (int dx, int dy, + int lx, int ly) const; + + size_t bytesPerLineForTile (int dx, int dy, + int lx, int ly) const; + + Data * _data; + + + friend class MultiPartOutputFile; + +}; + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfDeepTiledOutputPart.h b/OpenEXR/include/OpenEXR/ImfDeepTiledOutputPart.h new file mode 100644 index 0000000..c88da12 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfDeepTiledOutputPart.h @@ -0,0 +1,394 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2011, 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. +// +/////////////////////////////////////////////////////////////////////////// + +#ifndef IMFDEEPTILEDOUTPUTPART_H_ +#define IMFDEEPTILEDOUTPUTPART_H_ + +#include "ImfForward.h" +#include "ImfDeepTiledInputFile.h" +#include "ImfNamespace.h" +#include "ImfExport.h" + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +class IMF_EXPORT DeepTiledOutputPart +{ + public: + + DeepTiledOutputPart(MultiPartOutputFile& multiPartFile, int partNumber); + + //------------------------ + // Access to the file name + //------------------------ + + const char * fileName () const; + + + //-------------------------- + // Access to the file header + //-------------------------- + + const Header & header () const; + + + //------------------------------------------------------- + // Set the current frame buffer -- copies the FrameBuffer + // object into the TiledOutputFile object. + // + // The current frame buffer is the source of the pixel + // data written to the file. The current frame buffer + // must be set at least once before writeTile() is + // called. The current frame buffer can be changed + // after each call to writeTile(). + //------------------------------------------------------- + + void setFrameBuffer (const DeepFrameBuffer &frameBuffer); + + + //----------------------------------- + // Access to the current frame buffer + //----------------------------------- + + const DeepFrameBuffer & frameBuffer () const; + + + //------------------- + // Utility functions: + //------------------- + + //--------------------------------------------------------- + // Multiresolution mode and tile size: + // The following functions return the xSize, ySize and mode + // fields of the file header's TileDescriptionAttribute. + //--------------------------------------------------------- + + unsigned int tileXSize () const; + unsigned int tileYSize () const; + LevelMode levelMode () const; + LevelRoundingMode levelRoundingMode () const; + + + //-------------------------------------------------------------------- + // Number of levels: + // + // numXLevels() returns the file's number of levels in x direction. + // + // if levelMode() == ONE_LEVEL: + // return value is: 1 + // + // if levelMode() == MIPMAP_LEVELS: + // return value is: rfunc (log (max (w, h)) / log (2)) + 1 + // + // if levelMode() == RIPMAP_LEVELS: + // return value is: rfunc (log (w) / log (2)) + 1 + // + // where + // w is the width of the image's data window, max.x - min.x + 1, + // y is the height of the image's data window, max.y - min.y + 1, + // and rfunc(x) is either floor(x), or ceil(x), depending on + // whether levelRoundingMode() returns ROUND_DOWN or ROUND_UP. + // + // numYLevels() returns the file's number of levels in y direction. + // + // if levelMode() == ONE_LEVEL or levelMode() == MIPMAP_LEVELS: + // return value is the same as for numXLevels() + // + // if levelMode() == RIPMAP_LEVELS: + // return value is: rfunc (log (h) / log (2)) + 1 + // + // + // numLevels() is a convenience function for use with MIPMAP_LEVELS + // files. + // + // if levelMode() == ONE_LEVEL or levelMode() == MIPMAP_LEVELS: + // return value is the same as for numXLevels() + // + // if levelMode() == RIPMAP_LEVELS: + // an IEX_NAMESPACE::LogicExc exception is thrown + // + // isValidLevel(lx, ly) returns true if the file contains + // a level with level number (lx, ly), false if not. + // + //-------------------------------------------------------------------- + + int numLevels () const; + int numXLevels () const; + int numYLevels () const; + bool isValidLevel (int lx, int ly) const; + + + //--------------------------------------------------------- + // Dimensions of a level: + // + // levelWidth(lx) returns the width of a level with level + // number (lx, *), where * is any number. + // + // return value is: + // max (1, rfunc (w / pow (2, lx))) + // + // + // levelHeight(ly) returns the height of a level with level + // number (*, ly), where * is any number. + // + // return value is: + // max (1, rfunc (h / pow (2, ly))) + // + //--------------------------------------------------------- + + int levelWidth (int lx) const; + int levelHeight (int ly) const; + + + //---------------------------------------------------------- + // Number of tiles: + // + // numXTiles(lx) returns the number of tiles in x direction + // that cover a level with level number (lx, *), where * is + // any number. + // + // return value is: + // (levelWidth(lx) + tileXSize() - 1) / tileXSize() + // + // + // numYTiles(ly) returns the number of tiles in y direction + // that cover a level with level number (*, ly), where * is + // any number. + // + // return value is: + // (levelHeight(ly) + tileXSize() - 1) / tileXSize() + // + //---------------------------------------------------------- + + int numXTiles (int lx = 0) const; + int numYTiles (int ly = 0) const; + + + //--------------------------------------------------------- + // Level pixel ranges: + // + // dataWindowForLevel(lx, ly) returns a 2-dimensional + // region of valid pixel coordinates for a level with + // level number (lx, ly) + // + // return value is a Box2i with min value: + // (dataWindow.min.x, dataWindow.min.y) + // + // and max value: + // (dataWindow.min.x + levelWidth(lx) - 1, + // dataWindow.min.y + levelHeight(ly) - 1) + // + // dataWindowForLevel(level) is a convenience function used + // for ONE_LEVEL and MIPMAP_LEVELS files. It returns + // dataWindowForLevel(level, level). + // + //--------------------------------------------------------- + + IMATH_NAMESPACE::Box2i dataWindowForLevel (int l = 0) const; + IMATH_NAMESPACE::Box2i dataWindowForLevel (int lx, int ly) const; + + + //------------------------------------------------------------------- + // Tile pixel ranges: + // + // dataWindowForTile(dx, dy, lx, ly) returns a 2-dimensional + // region of valid pixel coordinates for a tile with tile coordinates + // (dx,dy) and level number (lx, ly). + // + // return value is a Box2i with min value: + // (dataWindow.min.x + dx * tileXSize(), + // dataWindow.min.y + dy * tileYSize()) + // + // and max value: + // (dataWindow.min.x + (dx + 1) * tileXSize() - 1, + // dataWindow.min.y + (dy + 1) * tileYSize() - 1) + // + // dataWindowForTile(dx, dy, level) is a convenience function + // used for ONE_LEVEL and MIPMAP_LEVELS files. It returns + // dataWindowForTile(dx, dy, level, level). + // + //------------------------------------------------------------------- + + IMATH_NAMESPACE::Box2i dataWindowForTile (int dx, int dy, + int l = 0) const; + + IMATH_NAMESPACE::Box2i dataWindowForTile (int dx, int dy, + int lx, int ly) const; + + //------------------------------------------------------------------ + // Write pixel data: + // + // writeTile(dx, dy, lx, ly) writes the tile with tile + // coordinates (dx, dy), and level number (lx, ly) to + // the file. + // + // dx must lie in the interval [0, numXTiles(lx) - 1] + // dy must lie in the interval [0, numYTiles(ly) - 1] + // + // lx must lie in the interval [0, numXLevels() - 1] + // ly must lie in the inverval [0, numYLevels() - 1] + // + // writeTile(dx, dy, level) is a convenience function + // used for ONE_LEVEL and MIPMAP_LEVEL files. It calls + // writeTile(dx, dy, level, level). + // + // The two writeTiles(dx1, dx2, dy1, dy2, ...) functions allow + // writing multiple tiles at once. If multi-threading is used + // multiple tiles are written concurrently. The tile coordinates, + // dx1, dx2 and dy1, dy2, specify inclusive ranges of tile + // coordinates. It is valid for dx1 < dx2 or dy1 < dy2; the + // tiles are always written in the order specified by the line + // order attribute. Hence, it is not possible to specify an + // "invalid" or empty tile range. + // + // Pixels that are outside the pixel coordinate range for the tile's + // level, are never accessed by writeTile(). + // + // Each tile in the file must be written exactly once. + // + // The file's line order attribute determines the order of the tiles + // in the file: + // + // INCREASING_Y In the file, the tiles for each level are stored + // in a contiguous block. The levels are ordered + // like this: + // + // (0, 0) (1, 0) ... (nx-1, 0) + // (0, 1) (1, 1) ... (nx-1, 1) + // ... + // (0,ny-1) (1,ny-1) ... (nx-1,ny-1) + // + // where nx = numXLevels(), and ny = numYLevels(). + // In an individual level, (lx, ly), the tiles + // are stored in the following order: + // + // (0, 0) (1, 0) ... (tx-1, 0) + // (0, 1) (1, 1) ... (tx-1, 1) + // ... + // (0,ty-1) (1,ty-1) ... (tx-1,ty-1) + // + // where tx = numXTiles(lx), + // and ty = numYTiles(ly). + // + // DECREASING_Y As for INCREASING_Y, the tiles for each level + // are stored in a contiguous block. The levels + // are ordered the same way as for INCREASING_Y, + // but within an individual level, the tiles + // are stored in this order: + // + // (0,ty-1) (1,ty-1) ... (tx-1,ty-1) + // ... + // (0, 1) (1, 1) ... (tx-1, 1) + // (0, 0) (1, 0) ... (tx-1, 0) + // + // + // RANDOM_Y The order of the calls to writeTile() determines + // the order of the tiles in the file. + // + //------------------------------------------------------------------ + + void writeTile (int dx, int dy, int l = 0); + void writeTile (int dx, int dy, int lx, int ly); + + void writeTiles (int dx1, int dx2, int dy1, int dy2, + int lx, int ly); + + void writeTiles (int dx1, int dx2, int dy1, int dy2, + int l = 0); + + + //------------------------------------------------------------------ + // Shortcut to copy all pixels from a TiledInputFile into this file, + // without uncompressing and then recompressing the pixel data. + // This file's header must be compatible with the TiledInputFile's + // header: The two header's "dataWindow", "compression", + // "lineOrder", "channels", and "tiles" attributes must be the same. + //------------------------------------------------------------------ + + void copyPixels (DeepTiledInputFile &in); + void copyPixels (DeepTiledInputPart &in); + + + + + //-------------------------------------------------------------- + // Updating the preview image: + // + // updatePreviewImage() supplies a new set of pixels for the + // preview image attribute in the file's header. If the header + // does not contain a preview image, updatePreviewImage() throws + // an IEX_NAMESPACE::LogicExc. + // + // Note: updatePreviewImage() is necessary because images are + // often stored in a file incrementally, a few tiles at a time, + // while the image is being generated. Since the preview image + // is an attribute in the file's header, it gets stored in the + // file as soon as the file is opened, but we may not know what + // the preview image should look like until we have written the + // last tile of the main image. + // + //-------------------------------------------------------------- + + void updatePreviewImage (const PreviewRgba newPixels[]); + + + //------------------------------------------------------------- + // Break a tile -- for testing and debugging only: + // + // breakTile(dx,dy,lx,ly,p,n,c) introduces an error into the + // output file by writing n copies of character c, starting + // p bytes from the beginning of the tile with tile coordinates + // (dx, dy) and level number (lx, ly). + // + // Warning: Calling this function usually results in a broken + // image file. The file or parts of it may not be readable, + // or the file may contain bad data. + // + //------------------------------------------------------------- + + void breakTile (int dx, int dy, + int lx, int ly, + int offset, + int length, + char c); + + private: + DeepTiledOutputFile* file; + +}; + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif /* IMFDEEPTILEDOUTPUTPART_H_ */ diff --git a/OpenEXR/include/OpenEXR/ImfDoubleAttribute.h b/OpenEXR/include/OpenEXR/ImfDoubleAttribute.h new file mode 100644 index 0000000..d9a88a8 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfDoubleAttribute.h @@ -0,0 +1,59 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMF_DOUBLE_ATTRIBUTE_H +#define INCLUDED_IMF_DOUBLE_ATTRIBUTE_H + +//----------------------------------------------------------------------------- +// +// class DoubleAttribute +// +//----------------------------------------------------------------------------- + +#include "ImfAttribute.h" +#include "ImfExport.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +typedef TypedAttribute DoubleAttribute; +template <> IMF_EXPORT const char *DoubleAttribute::staticTypeName (); + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfEnvmap.h b/OpenEXR/include/OpenEXR/ImfEnvmap.h new file mode 100644 index 0000000..16e4ee3 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfEnvmap.h @@ -0,0 +1,336 @@ +/////////////////////////////////////////////////////////////////////////// +// +// 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_ENVMAP_H +#define INCLUDED_IMF_ENVMAP_H + +//----------------------------------------------------------------------------- +// +// Environment maps +// +// Environment maps define a mapping from 3D directions to 2D +// pixel space locations. Environment maps are typically used +// in 3D rendering, for effects such as quickly approximating +// how shiny surfaces reflect their environment. +// +// Environment maps can be stored in scanline-based or in tiled +// OpenEXR files. The fact that an image is an environment map +// is indicated by the presence of an EnvmapAttribute whose name +// is "envmap". (Convenience functions to access this attribute +// are defined in header file ImfStandardAttributes.h.) +// The attribute's value defines the mapping from 3D directions +// to 2D pixel space locations. +// +// This header file defines the set of possible EnvmapAttribute +// values. +// +// For each possible EnvmapAttribute value, this header file also +// defines a set of convienience functions to convert between 3D +// directions and 2D pixel locations. +// +// Most of the convenience functions defined below require a +// dataWindow parameter. For scanline-based images, and for +// tiled images with level mode ONE_LEVEL, the dataWindow +// parameter should be set to the image's data window, as +// defined in the image header. For tiled images with level +// mode MIPMAP_LEVELS or RIPMAP_LEVELS, the data window of the +// image level that is being accessed should be used instead. +// (See the dataWindowForLevel() methods in ImfTiledInputFile.h +// and ImfTiledOutputFile.h.) +// +//----------------------------------------------------------------------------- + +#include "ImathBox.h" +#include "ImfNamespace.h" +#include "ImfExport.h" + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + +//-------------------------------- +// Supported environment map types +//-------------------------------- + +enum Envmap +{ + ENVMAP_LATLONG = 0, // Latitude-longitude environment map + ENVMAP_CUBE = 1, // Cube map + + NUM_ENVMAPTYPES // Number of different environment map types +}; + + +//------------------------------------------------------------------------- +// Latitude-Longitude Map: +// +// The environment is projected onto the image using polar coordinates +// (latitude and longitude). A pixel's x coordinate corresponds to +// its longitude, and the y coordinate corresponds to its latitude. +// Pixel (dataWindow.min.x, dataWindow.min.y) has latitude +pi/2 and +// longitude +pi; pixel (dataWindow.max.x, dataWindow.max.y) has +// latitude -pi/2 and longitude -pi. +// +// In 3D space, latitudes -pi/2 and +pi/2 correspond to the negative and +// positive y direction. Latitude 0, longitude 0 points into positive +// z direction; and latitude 0, longitude pi/2 points into positive x +// direction. +// +// The size of the data window should be 2*N by N pixels (width by height), +// where N can be any integer greater than 0. +//------------------------------------------------------------------------- + +namespace LatLongMap +{ + //---------------------------------------------------- + // Convert a 3D direction to a 2D vector whose x and y + // components represent the corresponding latitude + // and longitude. + //---------------------------------------------------- + + IMF_EXPORT + IMATH_NAMESPACE::V2f latLong (const IMATH_NAMESPACE::V3f &direction); + + + //-------------------------------------------------------- + // Convert the position of a pixel to a 2D vector whose + // x and y components represent the corresponding latitude + // and longitude. + //-------------------------------------------------------- + + IMF_EXPORT + IMATH_NAMESPACE::V2f latLong (const IMATH_NAMESPACE::Box2i &dataWindow, + const IMATH_NAMESPACE::V2f &pixelPosition); + + + //------------------------------------------------------------- + // Convert a 2D vector, whose x and y components represent + // longitude and latitude, into a corresponding pixel position. + //------------------------------------------------------------- + + IMF_EXPORT + IMATH_NAMESPACE::V2f pixelPosition (const IMATH_NAMESPACE::Box2i &dataWindow, + const IMATH_NAMESPACE::V2f &latLong); + + + //----------------------------------------------------- + // Convert a 3D direction vector into a corresponding + // pixel position. pixelPosition(dw,dir) is equivalent + // to pixelPosition(dw,latLong(dw,dir)). + //----------------------------------------------------- + + IMF_EXPORT + IMATH_NAMESPACE::V2f pixelPosition (const IMATH_NAMESPACE::Box2i &dataWindow, + const IMATH_NAMESPACE::V3f &direction); + + + //-------------------------------------------------------- + // Convert the position of a pixel in a latitude-longitude + // map into a corresponding 3D direction. + //-------------------------------------------------------- + + IMF_EXPORT + IMATH_NAMESPACE::V3f direction (const IMATH_NAMESPACE::Box2i &dataWindow, + const IMATH_NAMESPACE::V2f &pixelPosition); +} + + +//-------------------------------------------------------------- +// Cube Map: +// +// The environment is projected onto the six faces of an +// axis-aligned cube. The cube's faces are then arranged +// in a 2D image as shown below. +// +// 2-----------3 +// / /| +// / / | Y +// / / | | +// 6-----------7 | | +// | | | | +// | | | | +// | 0 | 1 *------- X +// | | / / +// | | / / +// | |/ / +// 4-----------5 Z +// +// dataWindow.min +// / +// / +// +-----------+ +// |3 Y 7| +// | | | +// | | | +// | ---+---Z | +X face +// | | | +// | | | +// |1 5| +// +-----------+ +// |6 Y 2| +// | | | +// | | | +// | Z---+--- | -X face +// | | | +// | | | +// |4 0| +// +-----------+ +// |6 Z 7| +// | | | +// | | | +// | ---+---X | +Y face +// | | | +// | | | +// |2 3| +// +-----------+ +// |0 1| +// | | | +// | | | +// | ---+---X | -Y face +// | | | +// | | | +// |4 Z 5| +// +-----------+ +// |7 Y 6| +// | | | +// | | | +// | X---+--- | +Z face +// | | | +// | | | +// |5 4| +// +-----------+ +// |2 Y 3| +// | | | +// | | | +// | ---+---X | -Z face +// | | | +// | | | +// |0 1| +// +-----------+ +// / +// / +// dataWindow.max +// +// The size of the data window should be N by 6*N pixels +// (width by height), where N can be any integer greater +// than 0. +// +//-------------------------------------------------------------- + +//------------------------------------ +// Names for the six faces of the cube +//------------------------------------ + +enum CubeMapFace +{ + CUBEFACE_POS_X, // +X face + CUBEFACE_NEG_X, // -X face + CUBEFACE_POS_Y, // +Y face + CUBEFACE_NEG_Y, // -Y face + CUBEFACE_POS_Z, // +Z face + CUBEFACE_NEG_Z // -Z face +}; + +namespace CubeMap +{ + //--------------------------------------------- + // Width and height of a cube's face, in pixels + //--------------------------------------------- + + IMF_EXPORT + int sizeOfFace (const IMATH_NAMESPACE::Box2i &dataWindow); + + + //------------------------------------------ + // Compute the region in the environment map + // that is covered by the specified face. + //------------------------------------------ + + IMF_EXPORT + IMATH_NAMESPACE::Box2i dataWindowForFace (CubeMapFace face, + const IMATH_NAMESPACE::Box2i &dataWindow); + + + //---------------------------------------------------- + // Convert the coordinates of a pixel within a face + // [in the range from (0,0) to (s-1,s-1), where + // s == sizeOfFace(dataWindow)] to pixel coordinates + // in the environment map. + //---------------------------------------------------- + + IMF_EXPORT + IMATH_NAMESPACE::V2f pixelPosition (CubeMapFace face, + const IMATH_NAMESPACE::Box2i &dataWindow, + IMATH_NAMESPACE::V2f positionInFace); + + + //-------------------------------------------------------------- + // Convert a 3D direction into a cube face, and a pixel position + // within that face. + // + // If you have a 3D direction, dir, the following code fragment + // finds the position, pos, of the corresponding pixel in an + // environment map with data window dw: + // + // CubeMapFace f; + // V2f pif, pos; + // + // faceAndPixelPosition (dir, dw, f, pif); + // pos = pixelPosition (f, dw, pif); + // + //-------------------------------------------------------------- + + IMF_EXPORT + void faceAndPixelPosition (const IMATH_NAMESPACE::V3f &direction, + const IMATH_NAMESPACE::Box2i &dataWindow, + CubeMapFace &face, + IMATH_NAMESPACE::V2f &positionInFace); + + + // -------------------------------------------------------- + // Given a cube face and a pixel position within that face, + // compute the corresponding 3D direction. + // -------------------------------------------------------- + + IMF_EXPORT + IMATH_NAMESPACE::V3f direction (CubeMapFace face, + const IMATH_NAMESPACE::Box2i &dataWindow, + const IMATH_NAMESPACE::V2f &positionInFace); +} + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfEnvmapAttribute.h b/OpenEXR/include/OpenEXR/ImfEnvmapAttribute.h new file mode 100644 index 0000000..0d0129b --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfEnvmapAttribute.h @@ -0,0 +1,68 @@ +/////////////////////////////////////////////////////////////////////////// +// +// 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. +// +/////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDED_IMF_ENVMAP_ATTRIBUTE_H +#define INCLUDED_IMF_ENVMAP_ATTRIBUTE_H + + +//----------------------------------------------------------------------------- +// +// class EnvmapAttribute +// +//----------------------------------------------------------------------------- + +#include "ImfAttribute.h" +#include "ImfEnvmap.h" +#include "ImfExport.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +typedef TypedAttribute EnvmapAttribute; + +template <> IMF_EXPORT const char *EnvmapAttribute::staticTypeName (); + +template <> IMF_EXPORT +void EnvmapAttribute::writeValueTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &, + int) const; + +template <> IMF_EXPORT +void EnvmapAttribute::readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &, + int, + int); + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfExport.h b/OpenEXR/include/OpenEXR/ImfExport.h new file mode 100644 index 0000000..6563fd5 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfExport.h @@ -0,0 +1,46 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + +#if defined(OPENEXR_DLL) + #if defined(ILMIMF_EXPORTS) + #define IMF_EXPORT __declspec(dllexport) + #define IMF_EXPORT_CONST extern __declspec(dllexport) + #else + #define IMF_EXPORT __declspec(dllimport) + #define IMF_EXPORT_CONST extern __declspec(dllimport) + #endif +#else + #define IMF_EXPORT + #define IMF_EXPORT_CONST extern const +#endif diff --git a/OpenEXR/include/OpenEXR/ImfFloatAttribute.h b/OpenEXR/include/OpenEXR/ImfFloatAttribute.h new file mode 100644 index 0000000..7370721 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfFloatAttribute.h @@ -0,0 +1,58 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMF_FLOAT_ATTRIBUTE_H +#define INCLUDED_IMF_FLOAT_ATTRIBUTE_H + +//----------------------------------------------------------------------------- +// +// class FloatAttribute +// +//----------------------------------------------------------------------------- + +#include "ImfAttribute.h" + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +typedef TypedAttribute FloatAttribute; +template <> IMF_EXPORT const char *FloatAttribute::staticTypeName (); + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfForward.h b/OpenEXR/include/OpenEXR/ImfForward.h new file mode 100644 index 0000000..ea51c24 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfForward.h @@ -0,0 +1,127 @@ + + +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2011, Industrial Light & Magic, a division of Lucas +// Digital Ltd. LLC +// +// Portions (c) 2012 Weta Digital Ltd +// +// 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. +// +/////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDED_IMF_FORWARD_H +#define INCLUDED_IMF_FORWARD_H + +//////////////////////////////////////////////////////////////////// +// +// Forward declarations for OpenEXR - correctly declares namespace +// +//////////////////////////////////////////////////////////////////// + +#include "ImfNamespace.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +// classes for basic types; +template class Array; +template class Array2D; +struct Channel; +class ChannelList; +struct Chromaticities; + +// attributes used in headers are TypedAttributes +class Attribute; + +class Header; + +// file handling classes +class OutputFile; +class TiledInputFile; +class ScanLineInputFile; +class InputFile; +class TiledOutputFile; +class DeepScanLineInputFile; +class DeepScanLineOutputFile; +class DeepTiledInputFile; +class DeepTiledOutputFile; +class AcesInputFile; +class AcesOutputFile; +class TiledInputPart; +class TiledInputFile; +class TileOffsets; + +// multipart file handling +class GenericInputFile; +class GenericOutputFile; +class MultiPartInputFile; +class MultiPartOutputFile; + +class InputPart; +class TiledInputPart; +class DeepScanLineInputPart; +class DeepTiledInputPart; + +class OutputPart; +class ScanLineOutputPart; +class TiledOutputPart; +class DeepScanLineOutputPart; +class DeepTiledOutputPart; + + +// internal use only +struct InputPartData; +struct OutputStreamMutex; +struct OutputPartData; +struct InputStreamMutex; + +// frame buffers + +class FrameBuffer; +class DeepFrameBuffer; +struct DeepSlice; + +// compositing +class DeepCompositing; +class CompositeDeepScanLine; + +// preview image +class PreviewImage; +struct PreviewRgba; + +// streams +class OStream; +class IStream; + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + +#endif // include guard diff --git a/OpenEXR/include/OpenEXR/ImfFrameBuffer.h b/OpenEXR/include/OpenEXR/ImfFrameBuffer.h new file mode 100644 index 0000000..a810cfa --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfFrameBuffer.h @@ -0,0 +1,386 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMF_FRAME_BUFFER_H +#define INCLUDED_IMF_FRAME_BUFFER_H + +//----------------------------------------------------------------------------- +// +// class Slice +// class FrameBuffer +// +//----------------------------------------------------------------------------- + +#include "ImfName.h" +#include "ImfPixelType.h" +#include "ImfExport.h" +#include "ImfNamespace.h" + +#include +#include + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +//------------------------------------------------------- +// Description of a single slice of the frame buffer: +// +// Note -- terminology: as part of a file, a component of +// an image (e.g. red, green, blue, depth etc.) is called +// a "channel". As part of a frame buffer, an image +// component is called a "slice". +//------------------------------------------------------- + +struct IMF_EXPORT Slice +{ + //------------------------------ + // Data type; see ImfPixelType.h + //------------------------------ + + PixelType type; + + + //--------------------------------------------------------------------- + // Memory layout: The address of pixel (x, y) is + // + // base + (xp / xSampling) * xStride + (yp / ySampling) * yStride + // + // where xp and yp are computed as follows: + // + // * If we are reading or writing a scanline-based file: + // + // xp = x + // yp = y + // + // * If we are reading a tile whose upper left coorner is at (xt, yt): + // + // if xTileCoords is true then xp = x - xt, else xp = x + // if yTileCoords is true then yp = y - yt, else yp = y + // + //--------------------------------------------------------------------- + + char * base; + size_t xStride; + size_t yStride; + + + //-------------------------------------------- + // Subsampling: pixel (x, y) is present in the + // slice only if + // + // x % xSampling == 0 && y % ySampling == 0 + // + //-------------------------------------------- + + int xSampling; + int ySampling; + + + //---------------------------------------------------------- + // Default value, used to fill the slice when a file without + // a channel that corresponds to this slice is read. + //---------------------------------------------------------- + + double fillValue; + + + //------------------------------------------------------- + // For tiled files, the xTileCoords and yTileCoords flags + // determine whether pixel addressing is performed using + // absolute coordinates or coordinates relative to a + // tile's upper left corner. (See the comment on base, + // xStride and yStride, above.) + // + // For scanline-based files these flags have no effect; + // pixel addressing is always done using absolute + // coordinates. + //------------------------------------------------------- + + bool xTileCoords; + bool yTileCoords; + + + //------------ + // Constructor + //------------ + + Slice (PixelType type = HALF, + char * base = 0, + size_t xStride = 0, + size_t yStride = 0, + int xSampling = 1, + int ySampling = 1, + double fillValue = 0.0, + bool xTileCoords = false, + bool yTileCoords = false); +}; + + +class IMF_EXPORT FrameBuffer +{ + public: + + //------------ + // Add a slice + //------------ + + void insert (const char name[], + const Slice &slice); + + void insert (const std::string &name, + const Slice &slice); + + //---------------------------------------------------------------- + // Access to existing slices: + // + // [n] Returns a reference to the slice with name n. + // If no slice with name n exists, an IEX_NAMESPACE::ArgExc + // is thrown. + // + // findSlice(n) Returns a pointer to the slice with name n, + // or 0 if no slice with name n exists. + // + //---------------------------------------------------------------- + + Slice & operator [] (const char name[]); + const Slice & operator [] (const char name[]) const; + + Slice & operator [] (const std::string &name); + const Slice & operator [] (const std::string &name) const; + + Slice * findSlice (const char name[]); + const Slice * findSlice (const char name[]) const; + + Slice * findSlice (const std::string &name); + const Slice * findSlice (const std::string &name) const; + + + //----------------------------------------- + // Iterator-style access to existing slices + //----------------------------------------- + + typedef std::map SliceMap; + + class Iterator; + class ConstIterator; + + Iterator begin (); + ConstIterator begin () const; + + Iterator end (); + ConstIterator end () const; + + Iterator find (const char name[]); + ConstIterator find (const char name[]) const; + + Iterator find (const std::string &name); + ConstIterator find (const std::string &name) const; + + private: + + SliceMap _map; +}; + + +//---------- +// Iterators +//---------- + +class FrameBuffer::Iterator +{ + public: + + Iterator (); + Iterator (const FrameBuffer::SliceMap::iterator &i); + + Iterator & operator ++ (); + Iterator operator ++ (int); + + const char * name () const; + Slice & slice () const; + + private: + + friend class FrameBuffer::ConstIterator; + + FrameBuffer::SliceMap::iterator _i; +}; + + +class FrameBuffer::ConstIterator +{ + public: + + ConstIterator (); + ConstIterator (const FrameBuffer::SliceMap::const_iterator &i); + ConstIterator (const FrameBuffer::Iterator &other); + + ConstIterator & operator ++ (); + ConstIterator operator ++ (int); + + const char * name () const; + const Slice & slice () const; + + private: + + friend bool operator == (const ConstIterator &, const ConstIterator &); + friend bool operator != (const ConstIterator &, const ConstIterator &); + + FrameBuffer::SliceMap::const_iterator _i; +}; + + +//----------------- +// Inline Functions +//----------------- + +inline +FrameBuffer::Iterator::Iterator (): _i() +{ + // empty +} + + +inline +FrameBuffer::Iterator::Iterator (const FrameBuffer::SliceMap::iterator &i): + _i (i) +{ + // empty +} + + +inline FrameBuffer::Iterator & +FrameBuffer::Iterator::operator ++ () +{ + ++_i; + return *this; +} + + +inline FrameBuffer::Iterator +FrameBuffer::Iterator::operator ++ (int) +{ + Iterator tmp = *this; + ++_i; + return tmp; +} + + +inline const char * +FrameBuffer::Iterator::name () const +{ + return *_i->first; +} + + +inline Slice & +FrameBuffer::Iterator::slice () const +{ + return _i->second; +} + + +inline +FrameBuffer::ConstIterator::ConstIterator (): _i() +{ + // empty +} + +inline +FrameBuffer::ConstIterator::ConstIterator + (const FrameBuffer::SliceMap::const_iterator &i): _i (i) +{ + // empty +} + + +inline +FrameBuffer::ConstIterator::ConstIterator (const FrameBuffer::Iterator &other): + _i (other._i) +{ + // empty +} + +inline FrameBuffer::ConstIterator & +FrameBuffer::ConstIterator::operator ++ () +{ + ++_i; + return *this; +} + + +inline FrameBuffer::ConstIterator +FrameBuffer::ConstIterator::operator ++ (int) +{ + ConstIterator tmp = *this; + ++_i; + return tmp; +} + + +inline const char * +FrameBuffer::ConstIterator::name () const +{ + return *_i->first; +} + +inline const Slice & +FrameBuffer::ConstIterator::slice () const +{ + return _i->second; +} + + +inline bool +operator == (const FrameBuffer::ConstIterator &x, + const FrameBuffer::ConstIterator &y) +{ + return x._i == y._i; +} + + +inline bool +operator != (const FrameBuffer::ConstIterator &x, + const FrameBuffer::ConstIterator &y) +{ + return !(x == y); +} + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfFramesPerSecond.h b/OpenEXR/include/OpenEXR/ImfFramesPerSecond.h new file mode 100644 index 0000000..59ab4cb --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfFramesPerSecond.h @@ -0,0 +1,94 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2006, 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_FRAMES_PER_SECOND_H +#define INCLUDED_IMF_FRAMES_PER_SECOND_H + +//----------------------------------------------------------------------------- +// +// Convenience functions related to the framesPerSecond attribute +// +// Functions that return the exact values for commonly used frame rates: +// +// name frames per second +// +// fps_23_976() 23.976023... +// fps_24() 24.0 35mm film frames +// fps_25() 25.0 PAL video frames +// fps_29_97() 29.970029... NTSC video frames +// fps_30() 30.0 60Hz HDTV frames +// fps_47_952() 47.952047... +// fps_48() 48.0 +// fps_50() 50.0 PAL video fields +// fps_59_94() 59.940059... NTSC video fields +// fps_60() 60.0 60Hz HDTV fields +// +// Functions that try to convert inexact frame rates into exact ones: +// +// Given a frame rate, fps, that is close to one of the pre-defined +// frame rates fps_23_976(), fps_29_97(), fps_47_952() or fps_59_94(), +// guessExactFps(fps) returns the corresponding pre-defined frame +// rate. If fps is not close to one of the pre-defined frame rates, +// then guessExactFps(fps) returns Rational(fps). +// +//----------------------------------------------------------------------------- + +#include "ImfRational.h" +#include "ImfNamespace.h" +#include "ImfExport.h" + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +inline Rational fps_23_976 () {return Rational (24000, 1001);} +inline Rational fps_24 () {return Rational (24, 1);} +inline Rational fps_25 () {return Rational (25, 1);} +inline Rational fps_29_97 () {return Rational (30000, 1001);} +inline Rational fps_30 () {return Rational (30, 1);} +inline Rational fps_47_952 () {return Rational (48000, 1001);} +inline Rational fps_48 () {return Rational (48, 1);} +inline Rational fps_50 () {return Rational (50, 1);} +inline Rational fps_59_94 () {return Rational (60000, 1001);} +inline Rational fps_60 () {return Rational (60, 1);} + +IMF_EXPORT Rational guessExactFps (double fps); +IMF_EXPORT Rational guessExactFps (const Rational &fps); + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfGenericInputFile.h b/OpenEXR/include/OpenEXR/ImfGenericInputFile.h new file mode 100644 index 0000000..78b32ba --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfGenericInputFile.h @@ -0,0 +1,58 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2011, 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. +// +/////////////////////////////////////////////////////////////////////////// + +#ifndef IMFGENERICINPUTFILE_H_ +#define IMFGENERICINPUTFILE_H_ + +#include "ImfIO.h" +#include "ImfHeader.h" +#include "ImfNamespace.h" +#include "ImfExport.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + +class IMF_EXPORT GenericInputFile +{ + public: + virtual ~GenericInputFile() {} + + protected: + GenericInputFile() {} + void readMagicNumberAndVersionField(OPENEXR_IMF_INTERNAL_NAMESPACE::IStream& is, int& version); +}; + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + +#endif /* IMFGENERICINPUTFILE_H_ */ diff --git a/OpenEXR/include/OpenEXR/ImfGenericOutputFile.h b/OpenEXR/include/OpenEXR/ImfGenericOutputFile.h new file mode 100644 index 0000000..6b37f2a --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfGenericOutputFile.h @@ -0,0 +1,62 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2011, 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. +// +/////////////////////////////////////////////////////////////////////////// + +#ifndef IMFGENERICOUTPUTFILE_H_ +#define IMFGENERICOUTPUTFILE_H_ + +#include "ImfVersion.h" +#include "ImfIO.h" +#include "ImfXdr.h" +#include "ImfHeader.h" +#include "ImfNamespace.h" +#include "ImfExport.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +class IMF_EXPORT GenericOutputFile +{ + public: + virtual ~GenericOutputFile() {} + + protected: + GenericOutputFile() {} + void writeMagicNumberAndVersionField (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream& os, const Header& header); + void writeMagicNumberAndVersionField (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream& os, const Header * headers, int parts); + +}; + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif /* GENERICOUTPUTFILE_H_ */ diff --git a/OpenEXR/include/OpenEXR/ImfHeader.h b/OpenEXR/include/OpenEXR/ImfHeader.h new file mode 100644 index 0000000..756a62e --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfHeader.h @@ -0,0 +1,699 @@ +/////////////////////////////////////////////////////////////////////////// +// +// 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMF_HEADER_H +#define INCLUDED_IMF_HEADER_H + +//----------------------------------------------------------------------------- +// +// class Header +// +//----------------------------------------------------------------------------- + +#include "ImfLineOrder.h" +#include "ImfCompression.h" +#include "ImfName.h" +#include "ImfTileDescription.h" +#include "ImfInt64.h" +#include "ImathVec.h" +#include "ImathBox.h" +#include "IexBaseExc.h" + +#include "ImfForward.h" +#include "ImfNamespace.h" +#include "ImfExport.h" + +#include +#include +#include + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + +using std::string; + + +class IMF_EXPORT Header +{ + public: + + //---------------------------------------------------------------- + // Default constructor -- the display window and the data window + // are both set to Box2i (V2i (0, 0), V2i (width-1, height-1). + //---------------------------------------------------------------- + + Header (int width = 64, + int height = 64, + float pixelAspectRatio = 1, + const IMATH_NAMESPACE::V2f &screenWindowCenter = IMATH_NAMESPACE::V2f (0, 0), + float screenWindowWidth = 1, + LineOrder lineOrder = INCREASING_Y, + Compression = ZIP_COMPRESSION); + + + //-------------------------------------------------------------------- + // Constructor -- the data window is specified explicitly; the display + // window is set to Box2i (V2i (0, 0), V2i (width-1, height-1). + //-------------------------------------------------------------------- + + Header (int width, + int height, + const IMATH_NAMESPACE::Box2i &dataWindow, + float pixelAspectRatio = 1, + const IMATH_NAMESPACE::V2f &screenWindowCenter = IMATH_NAMESPACE::V2f (0, 0), + float screenWindowWidth = 1, + LineOrder lineOrder = INCREASING_Y, + Compression = ZIP_COMPRESSION); + + + //---------------------------------------------------------- + // Constructor -- the display window and the data window are + // both specified explicitly. + //---------------------------------------------------------- + + Header (const IMATH_NAMESPACE::Box2i &displayWindow, + const IMATH_NAMESPACE::Box2i &dataWindow, + float pixelAspectRatio = 1, + const IMATH_NAMESPACE::V2f &screenWindowCenter = IMATH_NAMESPACE::V2f (0, 0), + float screenWindowWidth = 1, + LineOrder lineOrder = INCREASING_Y, + Compression = ZIP_COMPRESSION); + + + //----------------- + // Copy constructor + //----------------- + + Header (const Header &other); + + + //----------- + // Destructor + //----------- + + ~Header (); + + + //----------- + // Assignment + //----------- + + Header & operator = (const Header &other); + + + //--------------------------------------------------------------- + // Add an attribute: + // + // insert(n,attr) If no attribute with name n exists, a new + // attribute with name n, and the same type as + // attr, is added, and the value of attr is + // copied into the new attribute. + // + // If an attribute with name n exists, and its + // type is the same as attr, the value of attr + // is copied into this attribute. + // + // If an attribute with name n exists, and its + // type is different from attr, an IEX_NAMESPACE::TypeExc + // is thrown. + // + //--------------------------------------------------------------- + + void insert (const char name[], + const Attribute &attribute); + + void insert (const std::string &name, + const Attribute &attribute); + + //--------------------------------------------------------------- + // Remove an attribute: + // + // remove(n) If an attribute with name n exists, then it + // is removed from the map of present attributes. + // + // If no attribute with name n exists, then this + // functions becomes a 'no-op' + // + //--------------------------------------------------------------- + void erase (const char name[]); + void erase (const std::string &name); + + + + //------------------------------------------------------------------ + // Access to existing attributes: + // + // [n] Returns a reference to the attribute + // with name n. If no attribute with + // name n exists, an IEX_NAMESPACE::ArgExc is thrown. + // + // typedAttribute(n) Returns a reference to the attribute + // with name n and type T. If no attribute + // with name n exists, an IEX_NAMESPACE::ArgExc is + // thrown. If an attribute with name n + // exists, but its type is not T, an + // IEX_NAMESPACE::TypeExc is thrown. + // + // findTypedAttribute(n) Returns a pointer to the attribute with + // name n and type T, or 0 if no attribute + // with name n and type T exists. + // + //------------------------------------------------------------------ + + Attribute & operator [] (const char name[]); + const Attribute & operator [] (const char name[]) const; + + Attribute & operator [] (const std::string &name); + const Attribute & operator [] (const std::string &name) const; + + template T& typedAttribute (const char name[]); + template const T& typedAttribute (const char name[]) const; + + template T& typedAttribute (const std::string &name); + template const T& typedAttribute (const std::string &name) const; + + template T* findTypedAttribute (const char name[]); + template const T* findTypedAttribute (const char name[]) const; + + template T* findTypedAttribute (const std::string &name); + template const T* findTypedAttribute (const std::string &name) + const; + + //--------------------------------------------- + // Iterator-style access to existing attributes + //--------------------------------------------- + + typedef std::map AttributeMap; + + class Iterator; + class ConstIterator; + + Iterator begin (); + ConstIterator begin () const; + + Iterator end (); + ConstIterator end () const; + + Iterator find (const char name[]); + ConstIterator find (const char name[]) const; + + Iterator find (const std::string &name); + ConstIterator find (const std::string &name) const; + + + //-------------------------------- + // Access to predefined attributes + //-------------------------------- + + IMATH_NAMESPACE::Box2i & displayWindow (); + const IMATH_NAMESPACE::Box2i & displayWindow () const; + + IMATH_NAMESPACE::Box2i & dataWindow (); + const IMATH_NAMESPACE::Box2i & dataWindow () const; + + float & pixelAspectRatio (); + const float & pixelAspectRatio () const; + + IMATH_NAMESPACE::V2f & screenWindowCenter (); + const IMATH_NAMESPACE::V2f & screenWindowCenter () const; + + float & screenWindowWidth (); + const float & screenWindowWidth () const; + + ChannelList & channels (); + const ChannelList & channels () const; + + LineOrder & lineOrder (); + const LineOrder & lineOrder () const; + + Compression & compression (); + const Compression & compression () const; + + + //----------------------------------------------------- + // Access to required attributes for multipart files + // They are optional to non-multipart files and mandatory + // for multipart files. + //----------------------------------------------------- + void setName (const string& name); + + string& name(); + const string& name() const; + + bool hasName() const; + + void setType (const string& Type); + + string& type(); + const string& type() const; + + bool hasType() const; + + void setVersion (const int version); + + int& version(); + const int& version() const; + + bool hasVersion() const; + + // + // the chunkCount attribute is set automatically when a file is written. + // There is no need to set it manually + // + void setChunkCount(int chunks); + bool hasChunkCount() const; + const int & chunkCount() const; + int & chunkCount(); + + + // + // for multipart files, return whether the file has a view string attribute + // (for the deprecated single part multiview format EXR, see ImfMultiView.h) + // + void setView(const string & view); + bool hasView() const; + string & view(); + const string & view() const; + + + //---------------------------------------------------------------------- + // Tile Description: + // + // The tile description is a TileDescriptionAttribute whose name + // is "tiles". The "tiles" attribute must be present in any tiled + // image file. When present, it describes various properties of the + // tiles that make up the file. + // + // Convenience functions: + // + // setTileDescription(td) + // calls insert ("tiles", TileDescriptionAttribute (td)) + // + // tileDescription() + // returns typedAttribute("tiles").value() + // + // hasTileDescription() + // return findTypedAttribute("tiles") != 0 + // + //---------------------------------------------------------------------- + + void setTileDescription (const TileDescription & td); + + TileDescription & tileDescription (); + const TileDescription & tileDescription () const; + + bool hasTileDescription() const; + + + //---------------------------------------------------------------------- + // Preview image: + // + // The preview image is a PreviewImageAttribute whose name is "preview". + // This attribute is special -- while an image file is being written, + // the pixels of the preview image can be changed repeatedly by calling + // OutputFile::updatePreviewImage(). + // + // Convenience functions: + // + // setPreviewImage(p) + // calls insert ("preview", PreviewImageAttribute (p)) + // + // previewImage() + // returns typedAttribute("preview").value() + // + // hasPreviewImage() + // return findTypedAttribute("preview") != 0 + // + //---------------------------------------------------------------------- + + void setPreviewImage (const PreviewImage &p); + + PreviewImage & previewImage (); + const PreviewImage & previewImage () const; + + bool hasPreviewImage () const; + + + //------------------------------------------------------------- + // Sanity check -- examines the header, and throws an exception + // if it finds something wrong (empty display window, negative + // pixel aspect ratio, unknown compression sceme etc.) + // + // set isTiled to true if you are checking a tiled/multi-res + // header + //------------------------------------------------------------- + + void sanityCheck (bool isTiled = false, + bool isMultipartFile = false) const; + + + //---------------------------------------------------------------- + // Maximum image size and maximim tile size: + // + // sanityCheck() will throw an exception if the width or height of + // the data window exceeds the maximum image width or height, or + // if the size of a tile exceeds the maximum tile width or height. + // + // At program startup the maximum image and tile width and height + // are set to zero, meaning that width and height are unlimited. + // + // Limiting image and tile width and height limits how much memory + // will be allocated when a file is opened. This can help protect + // applications from running out of memory while trying to read + // a damaged image file. + //---------------------------------------------------------------- + + static void setMaxImageSize (int maxWidth, int maxHeight); + static void setMaxTileSize (int maxWidth, int maxHeight); + + // + // Check if the header reads nothing. + // + bool readsNothing(); + + + //------------------------------------------------------------------ + // Input and output: + // + // If the header contains a preview image attribute, then writeTo() + // returns the position of that attribute in the output stream; this + // information is used by OutputFile::updatePreviewImage(). + // If the header contains no preview image attribute, then writeTo() + // returns 0. + //------------------------------------------------------------------ + + + Int64 writeTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &os, + bool isTiled = false) const; + + void readFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is, + int &version); + + + private: + + AttributeMap _map; + + bool _readsNothing; +}; + + +//---------- +// Iterators +//---------- + +class Header::Iterator +{ + public: + + Iterator (); + Iterator (const Header::AttributeMap::iterator &i); + + Iterator & operator ++ (); + Iterator operator ++ (int); + + const char * name () const; + Attribute & attribute () const; + + private: + + friend class Header::ConstIterator; + + Header::AttributeMap::iterator _i; +}; + + +class Header::ConstIterator +{ + public: + + ConstIterator (); + ConstIterator (const Header::AttributeMap::const_iterator &i); + ConstIterator (const Header::Iterator &other); + + ConstIterator & operator ++ (); + ConstIterator operator ++ (int); + + const char * name () const; + const Attribute & attribute () const; + + private: + + friend bool operator == (const ConstIterator &, const ConstIterator &); + friend bool operator != (const ConstIterator &, const ConstIterator &); + + Header::AttributeMap::const_iterator _i; +}; + + +//------------------------------------------------------------------------ +// Library initialization: +// +// In a multithreaded program, staticInitialize() must be called once +// during startup, before the program accesses any other functions or +// classes in the IlmImf library. Calling staticInitialize() in this +// way avoids races during initialization of the library's global +// variables. +// +// Single-threaded programs are not required to call staticInitialize(); +// initialization of the library's global variables happens automatically. +// +//------------------------------------------------------------------------ + +void staticInitialize (); + + +//----------------- +// Inline Functions +//----------------- + + +inline +Header::Iterator::Iterator (): _i() +{ + // empty +} + + +inline +Header::Iterator::Iterator (const Header::AttributeMap::iterator &i): _i (i) +{ + // empty +} + + +inline Header::Iterator & +Header::Iterator::operator ++ () +{ + ++_i; + return *this; +} + + +inline Header::Iterator +Header::Iterator::operator ++ (int) +{ + Iterator tmp = *this; + ++_i; + return tmp; +} + + +inline const char * +Header::Iterator::name () const +{ + return *_i->first; +} + + +inline Attribute & +Header::Iterator::attribute () const +{ + return *_i->second; +} + + +inline +Header::ConstIterator::ConstIterator (): _i() +{ + // empty +} + +inline +Header::ConstIterator::ConstIterator + (const Header::AttributeMap::const_iterator &i): _i (i) +{ + // empty +} + + +inline +Header::ConstIterator::ConstIterator (const Header::Iterator &other): + _i (other._i) +{ + // empty +} + +inline Header::ConstIterator & +Header::ConstIterator::operator ++ () +{ + ++_i; + return *this; +} + + +inline Header::ConstIterator +Header::ConstIterator::operator ++ (int) +{ + ConstIterator tmp = *this; + ++_i; + return tmp; +} + + +inline const char * +Header::ConstIterator::name () const +{ + return *_i->first; +} + + +inline const Attribute & +Header::ConstIterator::attribute () const +{ + return *_i->second; +} + + +inline bool +operator == (const Header::ConstIterator &x, const Header::ConstIterator &y) +{ + return x._i == y._i; +} + + +inline bool +operator != (const Header::ConstIterator &x, const Header::ConstIterator &y) +{ + return !(x == y); +} + + +//--------------------- +// Template definitions +//--------------------- + +template +T & +Header::typedAttribute (const char name[]) +{ + Attribute *attr = &(*this)[name]; + T *tattr = dynamic_cast (attr); + + if (tattr == 0) + throw IEX_NAMESPACE::TypeExc ("Unexpected attribute type."); + + return *tattr; +} + + +template +const T & +Header::typedAttribute (const char name[]) const +{ + const Attribute *attr = &(*this)[name]; + const T *tattr = dynamic_cast (attr); + + if (tattr == 0) + throw IEX_NAMESPACE::TypeExc ("Unexpected attribute type."); + + return *tattr; +} + + +template +T & +Header::typedAttribute (const std::string &name) +{ + return typedAttribute (name.c_str()); +} + + +template +const T & +Header::typedAttribute (const std::string &name) const +{ + return typedAttribute (name.c_str()); +} + + +template +T * +Header::findTypedAttribute (const char name[]) +{ + AttributeMap::iterator i = _map.find (name); + return (i == _map.end())? 0: dynamic_cast (i->second); +} + + +template +const T * +Header::findTypedAttribute (const char name[]) const +{ + AttributeMap::const_iterator i = _map.find (name); + return (i == _map.end())? 0: dynamic_cast (i->second); +} + + +template +T * +Header::findTypedAttribute (const std::string &name) +{ + return findTypedAttribute (name.c_str()); +} + + +template +const T * +Header::findTypedAttribute (const std::string &name) const +{ + return findTypedAttribute (name.c_str()); +} + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfHuf.h b/OpenEXR/include/OpenEXR/ImfHuf.h new file mode 100644 index 0000000..fa89604 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfHuf.h @@ -0,0 +1,82 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMF_HUF_H +#define INCLUDED_IMF_HUF_H + +#include "ImfExport.h" +#include "ImfNamespace.h" + +//----------------------------------------------------------------------------- +// +// 16-bit Huffman compression and decompression: +// +// hufCompress (r, nr, c) +// +// Compresses the contents of array r (of length nr), +// stores the compressed data in array c, and returns +// the size of the compressed data (in bytes). +// +// To avoid buffer overflows, the size of array c should +// be at least 2 * nr + 65536. +// +// hufUncompress (c, nc, r, nr) +// +// Uncompresses the data in array c (with length nc), +// and stores the results in array r (with length nr). +// +//----------------------------------------------------------------------------- + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +IMF_EXPORT +int +hufCompress (const unsigned short raw[/*nRaw*/], + int nRaw, + char compressed[/*2 * nRaw + 65536*/]); + +IMF_EXPORT +void +hufUncompress (const char compressed[/*nCompressed*/], + int nCompressed, + unsigned short raw[/*nRaw*/], + int nRaw); + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfIO.h b/OpenEXR/include/OpenEXR/ImfIO.h new file mode 100644 index 0000000..4416d17 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfIO.h @@ -0,0 +1,255 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002, 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_IO_H +#define INCLUDED_IMF_IO_H + +//----------------------------------------------------------------------------- +// +// Low-level file input and output for OpenEXR. +// +//----------------------------------------------------------------------------- + +#include "ImfInt64.h" +#include "ImfNamespace.h" +#include "ImfExport.h" + +#include + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + +//----------------------------------------------------------- +// class IStream -- an abstract base class for input streams. +//----------------------------------------------------------- + +class IMF_EXPORT IStream +{ + public: + + //----------- + // Destructor + //----------- + + virtual ~IStream (); + + + //------------------------------------------------- + // Does this input stream support memory-mapped IO? + // + // Memory-mapped streams can avoid an extra copy; + // memory-mapped read operations return a pointer + // to an internal buffer instead of copying data + // into a buffer supplied by the caller. + //------------------------------------------------- + + virtual bool isMemoryMapped () const; + + + //------------------------------------------------------ + // Read from the stream: + // + // read(c,n) reads n bytes from the stream, and stores + // them in array c. If the stream contains less than n + // bytes, or if an I/O error occurs, read(c,n) throws + // an exception. If read(c,n) reads the last byte from + // the file it returns false, otherwise it returns true. + //------------------------------------------------------ + + virtual bool read (char c[/*n*/], int n) = 0; + + + //--------------------------------------------------- + // Read from a memory-mapped stream: + // + // readMemoryMapped(n) reads n bytes from the stream + // and returns a pointer to the first byte. The + // returned pointer remains valid until the stream + // is closed. If there are less than n byte left to + // read in the stream or if the stream is not memory- + // mapped, readMemoryMapped(n) throws an exception. + //--------------------------------------------------- + + virtual char * readMemoryMapped (int n); + + + //-------------------------------------------------------- + // Get the current reading position, in bytes from the + // beginning of the file. If the next call to read() will + // read the first byte in the file, tellg() returns 0. + //-------------------------------------------------------- + + virtual Int64 tellg () = 0; + + + //------------------------------------------- + // Set the current reading position. + // After calling seekg(i), tellg() returns i. + //------------------------------------------- + + virtual void seekg (Int64 pos) = 0; + + + //------------------------------------------------------ + // Clear error conditions after an operation has failed. + //------------------------------------------------------ + + virtual void clear (); + + + //------------------------------------------------------ + // Get the name of the file associated with this stream. + //------------------------------------------------------ + + const char * fileName () const; + + protected: + + IStream (const char fileName[]); + + private: + + IStream (const IStream &); // not implemented + IStream & operator = (const IStream &); // not implemented + + std::string _fileName; +}; + + +//----------------------------------------------------------- +// class OStream -- an abstract base class for output streams +//----------------------------------------------------------- + +class IMF_EXPORT OStream +{ + public: + + //----------- + // Destructor + //----------- + + virtual ~OStream (); + + + //---------------------------------------------------------- + // Write to the stream: + // + // write(c,n) takes n bytes from array c, and stores them + // in the stream. If an I/O error occurs, write(c,n) throws + // an exception. + //---------------------------------------------------------- + + virtual void write (const char c[/*n*/], int n) = 0; + + + //--------------------------------------------------------- + // Get the current writing position, in bytes from the + // beginning of the file. If the next call to write() will + // start writing at the beginning of the file, tellp() + // returns 0. + //--------------------------------------------------------- + + virtual Int64 tellp () = 0; + + + //------------------------------------------- + // Set the current writing position. + // After calling seekp(i), tellp() returns i. + //------------------------------------------- + + virtual void seekp (Int64 pos) = 0; + + + //------------------------------------------------------ + // Get the name of the file associated with this stream. + //------------------------------------------------------ + + const char * fileName () const; + + protected: + + OStream (const char fileName[]); + + private: + + OStream (const OStream &); // not implemented + OStream & operator = (const OStream &); // not implemented + + std::string _fileName; +}; + + +//----------------------- +// Helper classes for Xdr +//----------------------- + +struct StreamIO +{ + static void + writeChars (OStream &os, const char c[/*n*/], int n) + { + os.write (c, n); + } + + static bool + readChars (IStream &is, char c[/*n*/], int n) + { + return is.read (c, n); + } +}; + + +struct CharPtrIO +{ + static void + writeChars (char *&op, const char c[/*n*/], int n) + { + while (n--) + *op++ = *c++; + } + + static bool + readChars (const char *&ip, char c[/*n*/], int n) + { + while (n--) + *c++ = *ip++; + + return true; + } +}; + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfInputFile.h b/OpenEXR/include/OpenEXR/ImfInputFile.h new file mode 100644 index 0000000..42c6352 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfInputFile.h @@ -0,0 +1,240 @@ +/////////////////////////////////////////////////////////////////////////// +// +// 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_INPUT_FILE_H +#define INCLUDED_IMF_INPUT_FILE_H + +//----------------------------------------------------------------------------- +// +// class InputFile -- a scanline-based interface that can be used +// to read both scanline-based and tiled OpenEXR image files. +// +//----------------------------------------------------------------------------- + +#include "ImfHeader.h" +#include "ImfFrameBuffer.h" +#include "ImfTiledOutputFile.h" +#include "ImfThreading.h" +#include "ImfGenericInputFile.h" +#include "ImfNamespace.h" +#include "ImfForward.h" +#include "ImfExport.h" + +#include + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +class IMF_EXPORT InputFile : public GenericInputFile +{ + public: + + //----------------------------------------------------------- + // A constructor that opens the file with the specified name. + // Destroying the InputFile object will close the file. + // + // numThreads determines the number of threads that will be + // used to read the file (see ImfThreading.h). + //----------------------------------------------------------- + + InputFile (const char fileName[], int numThreads = globalThreadCount()); + + + //------------------------------------------------------------- + // A constructor that attaches the new InputFile object to a + // file that has already been opened. Destroying the InputFile + // object will not close the file. + // + // numThreads determines the number of threads that will be + // used to read the file (see ImfThreading.h). + //------------------------------------------------------------- + + InputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is, int numThreads = globalThreadCount()); + + + //----------- + // Destructor + //----------- + + virtual ~InputFile (); + + + //------------------------ + // Access to the file name + //------------------------ + + const char * fileName () const; + + + //-------------------------- + // Access to the file header + //-------------------------- + + const Header & header () const; + + + //---------------------------------- + // Access to the file format version + //---------------------------------- + + int version () const; + + + //----------------------------------------------------------- + // Set the current frame buffer -- copies the FrameBuffer + // object into the InputFile object. + // + // The current frame buffer is the destination for the pixel + // data read from the file. The current frame buffer must be + // set at least once before readPixels() is called. + // The current frame buffer can be changed after each call + // to readPixels(). + //----------------------------------------------------------- + + void setFrameBuffer (const FrameBuffer &frameBuffer); + + + //----------------------------------- + // Access to the current frame buffer + //----------------------------------- + + const FrameBuffer & frameBuffer () const; + + + //--------------------------------------------------------------- + // Check if the file is complete: + // + // isComplete() returns true if all pixels in the data window are + // present in the input file, or false if any pixels are missing. + // (Another program may still be busy writing the file, or file + // writing may have been aborted prematurely.) + //--------------------------------------------------------------- + + bool isComplete () const; + + + //--------------------------------------------------------------- + // Check if SSE optimization is enabled + // + // Call after setFrameBuffer() to query whether optimized file decoding + // is available - decode times will be faster if returns true + // + // Optimization depends on: + // the file type (only scanline data is supported), + // the framebuffer channels (RGB/RGBA mono or stereo) + // the framebuffer channel types (all channels half-float format only) + // the file channels (RGB/RGBA mono or stereo) + // the file channel types (all channel half-float format only) + // whether SSE2 instruction support was detected at compile time + // + // Calling isOptimizationEnabled before setFrameBuffer will throw an exception + // + //--------------------------------------------------------------- + + bool isOptimizationEnabled () const; + + + + + //--------------------------------------------------------------- + // Read pixel data: + // + // readPixels(s1,s2) reads all scan lines with y coordinates + // in the interval [min (s1, s2), max (s1, s2)] from the file, + // and stores them in the current frame buffer. + // + // Both s1 and s2 must be within the interval + // [header().dataWindow().min.y, header().dataWindow().max.y] + // + // The scan lines can be read from the file in random order, and + // individual scan lines may be skipped or read multiple times. + // For maximum efficiency, the scan lines should be read in the + // order in which they were written to the file. + // + // readPixels(s) calls readPixels(s,s). + // + //--------------------------------------------------------------- + + void readPixels (int scanLine1, int scanLine2); + void readPixels (int scanLine); + + + //---------------------------------------------- + // Read a block of raw pixel data from the file, + // without uncompressing it (this function is + // used to implement OutputFile::copyPixels()). + //---------------------------------------------- + + void rawPixelData (int firstScanLine, + const char *&pixelData, + int &pixelDataSize); + + //-------------------------------------------------- + // Read a tile of raw pixel data from the file, + // without uncompressing it (this function is + // used to implement TiledOutputFile::copyPixels()). + //-------------------------------------------------- + + void rawTileData (int &dx, int &dy, + int &lx, int &ly, + const char *&pixelData, + int &pixelDataSize); + + struct Data; + + private: + + InputFile (InputPartData* part); + InputFile (const InputFile &); // not implemented + InputFile & operator = (const InputFile &); // not implemented + + void initialize (); + void multiPartInitialize(InputPartData* part); + void compatibilityInitialize(OPENEXR_IMF_INTERNAL_NAMESPACE::IStream& is); + TiledInputFile * tFile (); + + friend void TiledOutputFile::copyPixels (InputFile &); + + Data * _data; + + + friend class MultiPartInputFile; +}; + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfInputPart.h b/OpenEXR/include/OpenEXR/ImfInputPart.h new file mode 100644 index 0000000..bfc30e3 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfInputPart.h @@ -0,0 +1,84 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2011, 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. +// +/////////////////////////////////////////////////////////////////////////// + +#ifndef IMFINPUTPART_H_ +#define IMFINPUTPART_H_ + +#include "ImfInputFile.h" +#include "ImfOutputPart.h" +#include "ImfForward.h" +#include "ImfNamespace.h" +#include "ImfExport.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + +//------------------------------------------------------------------- +// class InputPart: +// +// Same interface as InputFile. Please refer to InputFile. +//------------------------------------------------------------------- + +class IMF_EXPORT InputPart +{ + public: + InputPart(MultiPartInputFile& multiPartFile, int partNumber); + + const char * fileName () const; + const Header & header () const; + int version () const; + void setFrameBuffer (const FrameBuffer &frameBuffer); + const FrameBuffer & frameBuffer () const; + bool isComplete () const; + bool isOptimizationEnabled () const; + void readPixels (int scanLine1, int scanLine2); + void readPixels (int scanLine); + void rawPixelData (int firstScanLine, + const char *&pixelData, + int &pixelDataSize); + void rawTileData (int &dx, int &dy, + int &lx, int &ly, + const char *&pixelData, + int &pixelDataSize); + + private: + InputFile* file; + // for internal use - give OutputFile and TiledOutputFile access to file for copyPixels + friend void OutputFile::copyPixels(InputPart&); + friend void TiledOutputFile::copyPixels(InputPart&); + +}; + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif /* IMFINPUTPART_H_ */ diff --git a/OpenEXR/include/OpenEXR/ImfInt64.h b/OpenEXR/include/OpenEXR/ImfInt64.h new file mode 100644 index 0000000..761557d --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfInt64.h @@ -0,0 +1,56 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2006, 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. +// +/////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDED_IMF_INT64_H +#define INCLUDED_IMF_INT64_H + +//---------------------------------------------------------------------------- +// +// Int64 -- unsigned 64-bit integers, imported from namespace Imath +// +//---------------------------------------------------------------------------- + +#include "ImathInt64.h" +#include "ImfNamespace.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + +using IMATH_NAMESPACE::Int64; + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + + + +#endif // INCLUDED_IMF_INT64_H diff --git a/OpenEXR/include/OpenEXR/ImfIntAttribute.h b/OpenEXR/include/OpenEXR/ImfIntAttribute.h new file mode 100644 index 0000000..3d271ca --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfIntAttribute.h @@ -0,0 +1,58 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMF_INT_ATTRIBUTE_H +#define INCLUDED_IMF_INT_ATTRIBUTE_H + +//----------------------------------------------------------------------------- +// +// class IntAttribute +// +//----------------------------------------------------------------------------- + +#include "ImfAttribute.h" +#include "ImfNamespace.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +typedef TypedAttribute IntAttribute; +template <> IMF_EXPORT const char *IntAttribute::staticTypeName (); + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfKeyCode.h b/OpenEXR/include/OpenEXR/ImfKeyCode.h new file mode 100644 index 0000000..2146101 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfKeyCode.h @@ -0,0 +1,167 @@ +/////////////////////////////////////////////////////////////////////////// +// +// 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_KEY_CODE_H +#define INCLUDED_IMF_KEY_CODE_H + +//----------------------------------------------------------------------------- +// +// class KeyCode +// +// A KeyCode object uniquely identifies a motion picture film frame. +// The following fields specifiy film manufacturer, film type, film +// roll and the frame's position within the roll: +// +// filmMfcCode film manufacturer code +// range: 0 - 99 +// +// filmType film type code +// range: 0 - 99 +// +// prefix prefix to identify film roll +// range: 0 - 999999 +// +// count count, increments once every perfsPerCount +// perforations (see below) +// range: 0 - 9999 +// +// perfOffset offset of frame, in perforations from +// zero-frame reference mark +// range: 0 - 119 +// +// perfsPerFrame number of perforations per frame +// range: 1 - 15 +// +// typical values: +// +// 1 for 16mm film +// 3, 4, or 8 for 35mm film +// 5, 8 or 15 for 65mm film +// +// perfsPerCount number of perforations per count +// range: 20 - 120 +// +// typical values: +// +// 20 for 16mm film +// 64 for 35mm film +// 80 or 120 for 65mm film +// +// For more information about the interpretation of those fields see +// the following standards and recommended practice publications: +// +// SMPTE 254 Motion-Picture Film (35-mm) - Manufacturer-Printed +// Latent Image Identification Information +// +// SMPTE 268M File Format for Digital Moving-Picture Exchange (DPX) +// (section 6.1) +// +// SMPTE 270 Motion-Picture Film (65-mm) - Manufacturer- Printed +// Latent Image Identification Information +// +// SMPTE 271 Motion-Picture Film (16-mm) - Manufacturer- Printed +// Latent Image Identification Information +// +//----------------------------------------------------------------------------- +#include "ImfNamespace.h" +#include "ImfExport.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +class IMF_EXPORT KeyCode +{ + public: + + //------------------------------------- + // Constructors and assignment operator + //------------------------------------- + + KeyCode (int filmMfcCode = 0, + int filmType = 0, + int prefix = 0, + int count = 0, + int perfOffset = 0, + int perfsPerFrame = 4, + int perfsPerCount = 64); + + KeyCode (const KeyCode &other); + KeyCode & operator = (const KeyCode &other); + + + //---------------------------- + // Access to individual fields + //---------------------------- + + int filmMfcCode () const; + void setFilmMfcCode (int filmMfcCode); + + int filmType () const; + void setFilmType (int filmType); + + int prefix () const; + void setPrefix (int prefix); + + int count () const; + void setCount (int count); + + int perfOffset () const; + void setPerfOffset (int perfOffset); + + int perfsPerFrame () const; + void setPerfsPerFrame (int perfsPerFrame); + + int perfsPerCount () const; + void setPerfsPerCount (int perfsPerCount); + + private: + + int _filmMfcCode; + int _filmType; + int _prefix; + int _count; + int _perfOffset; + int _perfsPerFrame; + int _perfsPerCount; +}; + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + + + + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfKeyCodeAttribute.h b/OpenEXR/include/OpenEXR/ImfKeyCodeAttribute.h new file mode 100644 index 0000000..00d4ece --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfKeyCodeAttribute.h @@ -0,0 +1,73 @@ +/////////////////////////////////////////////////////////////////////////// +// +// 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_KEY_CODE_ATTRIBUTE_H +#define INCLUDED_IMF_KEY_CODE_ATTRIBUTE_H + + +//----------------------------------------------------------------------------- +// +// class KeyCodeAttribute +// +//----------------------------------------------------------------------------- + +#include "ImfAttribute.h" +#include "ImfKeyCode.h" +#include "ImfExport.h" + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +typedef TypedAttribute KeyCodeAttribute; + +template <> +IMF_EXPORT +const char *KeyCodeAttribute::staticTypeName (); + +template <> +IMF_EXPORT +void KeyCodeAttribute::writeValueTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &, + int) const; + +template <> +IMF_EXPORT +void KeyCodeAttribute::readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &, + int, int); + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfLineOrder.h b/OpenEXR/include/OpenEXR/ImfLineOrder.h new file mode 100644 index 0000000..8f30bed --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfLineOrder.h @@ -0,0 +1,69 @@ +/////////////////////////////////////////////////////////////////////////// +// +// 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMF_LINE_ORDER_H +#define INCLUDED_IMF_LINE_ORDER_H + +//----------------------------------------------------------------------------- +// +// enum LineOrder +// +//----------------------------------------------------------------------------- +#include "ImfNamespace.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +enum LineOrder +{ + INCREASING_Y = 0, // first scan line has lowest y coordinate + + DECREASING_Y = 1, // first scan line has highest y coordinate + + RANDOM_Y = 2, // only for tiled files; tiles are written + // in random order + + NUM_LINEORDERS // number of different line orders +}; + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + + + + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfLineOrderAttribute.h b/OpenEXR/include/OpenEXR/ImfLineOrderAttribute.h new file mode 100644 index 0000000..342c3d0 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfLineOrderAttribute.h @@ -0,0 +1,72 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMF_LINE_ORDER_ATTRIBUTE_H +#define INCLUDED_IMF_LINE_ORDER_ATTRIBUTE_H + +//----------------------------------------------------------------------------- +// +// class LineOrderAttribute +// +//----------------------------------------------------------------------------- + +#include "ImfAttribute.h" +#include "ImfLineOrder.h" +#include "ImfExport.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +typedef TypedAttribute LineOrderAttribute; + +template <> +IMF_EXPORT +const char *LineOrderAttribute::staticTypeName (); + +template <> +IMF_EXPORT +void LineOrderAttribute::writeValueTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &, + int) const; + +template <> +IMF_EXPORT +void LineOrderAttribute::readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &, + int, int); + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfLut.h b/OpenEXR/include/OpenEXR/ImfLut.h new file mode 100644 index 0000000..b9ccc4c --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfLut.h @@ -0,0 +1,188 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMF_LUT_H +#define INCLUDED_IMF_LUT_H + +//----------------------------------------------------------------------------- +// +// Lookup tables for efficient application +// of half --> half functions to pixel data, +// and some commonly applied functions. +// +//----------------------------------------------------------------------------- + +#include "ImfRgbaFile.h" +#include "ImfFrameBuffer.h" +#include "ImathBox.h" +#include "halfFunction.h" +#include "ImfNamespace.h" +#include "ImfExport.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + +// +// Lookup table for individual half channels. +// + +class IMF_EXPORT HalfLut +{ + public: + + //------------ + // Constructor + //------------ + + template + HalfLut (Function f); + + + //---------------------------------------------------------------------- + // Apply the table to data[0], data[stride] ... data[(nData-1) * stride] + //---------------------------------------------------------------------- + + void apply (half *data, + int nData, + int stride = 1) const; + + + //--------------------------------------------------------------- + // Apply the table to a frame buffer slice (see ImfFrameBuffer.h) + //--------------------------------------------------------------- + + void apply (const Slice &data, + const IMATH_NAMESPACE::Box2i &dataWindow) const; + + private: + + halfFunction _lut; +}; + + +// +// Lookup table for combined RGBA data. +// + +class IMF_EXPORT RgbaLut +{ + public: + + //------------ + // Constructor + //------------ + + template + RgbaLut (Function f, RgbaChannels chn = WRITE_RGB); + + + //---------------------------------------------------------------------- + // Apply the table to data[0], data[stride] ... data[(nData-1) * stride] + //---------------------------------------------------------------------- + + void apply (Rgba *data, + int nData, + int stride = 1) const; + + + //----------------------------------------------------------------------- + // Apply the table to a frame buffer (see RgbaOutpuFile.setFrameBuffer()) + //----------------------------------------------------------------------- + + void apply (Rgba *base, + int xStride, + int yStride, + const IMATH_NAMESPACE::Box2i &dataWindow) const; + + private: + + halfFunction _lut; + RgbaChannels _chn; +}; + + +// +// 12bit log rounding reduces data to 20 stops with 200 steps per stop. +// That makes 4000 numbers. An extra 96 just come along for the ride. +// Zero explicitly remains zero. The first non-zero half will map to 1 +// in the 0-4095 12log space. A nice power of two number is placed at +// the center [2000] and that number is near 0.18. +// + +IMF_EXPORT +half round12log (half x); + + +// +// Round to n-bit precision (n should be between 0 and 10). +// After rounding, the significand's 10-n least significant +// bits will be zero. +// + +struct roundNBit +{ + roundNBit (int n): n(n) {} + half operator () (half x) {return x.round(n);} + int n; +}; + + +// +// Template definitions +// + + +template +HalfLut::HalfLut (Function f): + _lut(f, -HALF_MAX, HALF_MAX, half (0), + half::posInf(), half::negInf(), half::qNan()) +{ + // empty +} + + +template +RgbaLut::RgbaLut (Function f, RgbaChannels chn): + _lut(f, -HALF_MAX, HALF_MAX, half (0), + half::posInf(), half::negInf(), half::qNan()), + _chn(chn) +{ + // empty +} + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfMatrixAttribute.h b/OpenEXR/include/OpenEXR/ImfMatrixAttribute.h new file mode 100644 index 0000000..31f1466 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfMatrixAttribute.h @@ -0,0 +1,83 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMF_MATRIX_ATTRIBUTE_H +#define INCLUDED_IMF_MATRIX_ATTRIBUTE_H + +//----------------------------------------------------------------------------- +// +// class M33fAttribute +// class M33dAttribute +// class M44fAttribute +// class M44dAttribute +// +//----------------------------------------------------------------------------- + +#include "ImfAttribute.h" +#include "ImathMatrix.h" +#include "ImfExport.h" + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +typedef TypedAttribute M33fAttribute; +template <> IMF_EXPORT const char *M33fAttribute::staticTypeName (); +template <> IMF_EXPORT void M33fAttribute::writeValueTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &, int) const; +template <> IMF_EXPORT void M33fAttribute::readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &, int, int); + + +typedef TypedAttribute M33dAttribute; +template <> IMF_EXPORT const char *M33dAttribute::staticTypeName (); +template <> IMF_EXPORT void M33dAttribute::writeValueTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &, int) const; +template <> IMF_EXPORT void M33dAttribute::readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &, int, int); + + +typedef TypedAttribute M44fAttribute; +template <> IMF_EXPORT const char *M44fAttribute::staticTypeName (); +template <> IMF_EXPORT void M44fAttribute::writeValueTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &, int) const; +template <> IMF_EXPORT void M44fAttribute::readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &, int, int); + + +typedef TypedAttribute M44dAttribute; +template <> IMF_EXPORT const char *M44dAttribute::staticTypeName (); +template <> IMF_EXPORT void M44dAttribute::writeValueTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &, int) const; +template <> IMF_EXPORT void M44dAttribute::readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &, int, int); + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfMisc.h b/OpenEXR/include/OpenEXR/ImfMisc.h new file mode 100644 index 0000000..cc697e2 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfMisc.h @@ -0,0 +1,466 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMF_MISC_H +#define INCLUDED_IMF_MISC_H + +//----------------------------------------------------------------------------- +// +// Miscellaneous helper functions for OpenEXR image file I/O +// +//----------------------------------------------------------------------------- + +#include "ImfPixelType.h" +#include "ImfCompressor.h" +#include "ImfArray.h" +#include "ImfNamespace.h" +#include "ImfExport.h" +#include "ImfForward.h" + +#include +#include + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +// +// Return the size of a single value of the indicated type, +// in the machine's native format. +// + +IMF_EXPORT +int pixelTypeSize (PixelType type); + + +// +// Return the number of samples a channel with subsampling rate +// s has in the interval [a, b]. For example, a channel with +// subsampling rate 2 (and samples at 0, 2, 4, 6, 8, etc.) has +// 2 samples in the interval [1, 5] and three samples in the +// interval [2, 6]. +// + +IMF_EXPORT +int numSamples (int s, int a, int b); + + +// +// Build a table that lists, for each scanline in a file's +// data window, how many bytes are required to store all +// pixels in all channels in that scanline (assuming that +// the pixel data are tightly packed). +// + +IMF_EXPORT +size_t bytesPerLineTable (const Header &header, + std::vector &bytesPerLine); + + +// +// Get the sample count for pixel (x, y) using the array base +// pointer, xStride and yStride. +// + +IMF_EXPORT +int& +sampleCount(char* base, int xStride, int yStride, int x, int y); + + +IMF_EXPORT +const int& +sampleCount(const char* base, int xStride, int yStride, int x, int y); + +// +// Build a table that lists, for each scanline in a DEEP file's +// data window, how many bytes are required to store all +// pixels in all channels in scanlines ranged in [minY, maxY] +// (assuming that the pixel data are tightly packed). +// + +IMF_EXPORT +size_t bytesPerDeepLineTable (const Header &header, + int minY, int maxY, + const char* base, + int xStride, + int yStride, + std::vector &bytesPerLine); + + +// +// Build a table that lists, for each scanline in a DEEP file's +// data window, how many bytes are required to store all +// pixels in all channels in every scanline (assuming that +// the pixel data are tightly packed). +// + +IMF_EXPORT +size_t bytesPerDeepLineTable (const Header &header, + char* base, + int xStride, + int yStride, + std::vector &bytesPerLine); + + +// +// For scanline-based files, pixels are read or written in +// in multi-scanline blocks. Internally, class OutputFile +// and class ScanLineInputFile store a block of scan lines +// in a "line buffer". Function offsetInLineBufferTable() +// builds a table that lists, scanlines within range +// [scanline1, scanline2], the location of the pixel data +// for the scanline relative to the beginning of the line buffer, +// where scanline1 = 0 represents the first line in the DATA WINDOW. +// The one without specifying the range will make scanline1 = 0 +// and scanline2 = bytesPerLine.size(). +// + +IMF_EXPORT +void offsetInLineBufferTable (const std::vector &bytesPerLine, + int scanline1, int scanline2, + int linesInLineBuffer, + std::vector &offsetInLineBuffer); + +IMF_EXPORT +void offsetInLineBufferTable (const std::vector &bytesPerLine, + int linesInLineBuffer, + std::vector &offsetInLineBuffer); + +// +// For a scanline-based file, compute the range of scanlines +// that occupy the same line buffer as a given scanline, y. +// (minY is the minimum y coordinate of the file's data window.) +// + +IMF_EXPORT int lineBufferMinY (int y, int minY, int linesInLineBuffer); +IMF_EXPORT int lineBufferMaxY (int y, int minY, int linesInLineBuffer); + + +// +// Return a compressor's data format (Compressor::NATIVE or Compressor::XDR). +// If compressor is 0, return Compressor::XDR. +// + +IMF_EXPORT +Compressor::Format defaultFormat (Compressor *compressor); + + +// +// Return the number of scan lines a compressor wants to compress +// or uncompress at once. If compressor is 0, return 1. +// + +IMF_EXPORT +int numLinesInBuffer (Compressor *compressor); + + +// +// Copy a single channel of a horizontal row of pixels from an +// input file's internal line buffer or tile buffer into a +// frame buffer slice. If necessary, perform on-the-fly data +// type conversion. +// +// readPtr initially points to the beginning of the +// data in the line or tile buffer. readPtr +// is advanced as the pixel data are copied; +// when copyIntoFrameBuffer() returns, +// readPtr points just past the end of the +// copied data. +// +// writePtr, endPtr point to the lefmost and rightmost pixels +// in the frame buffer slice +// +// xStride the xStride for the frame buffer slice +// +// format indicates if the line or tile buffer is +// in NATIVE or XDR format. +// +// typeInFrameBuffer the pixel data type of the frame buffer slice +// +// typeInFile the pixel data type in the input file's channel +// + +IMF_EXPORT +void copyIntoFrameBuffer (const char *&readPtr, + char *writePtr, + char *endPtr, + size_t xStride, + bool fill, + double fillValue, + Compressor::Format format, + PixelType typeInFrameBuffer, + PixelType typeInFile); + + +// +// Copy a single channel of a horizontal row of pixels from an +// input file's internal line buffer or tile buffer into a +// frame buffer slice. If necessary, perform on-the-fly data +// type conversion. +// +// readPtr initially points to the beginning of the +// data in the line or tile buffer. readPtr +// is advanced as the pixel data are copied; +// when copyIntoFrameBuffer() returns, +// readPtr points just past the end of the +// copied data. +// +// base point to each pixel in the framebuffer +// +// sampleCountBase, provide the number of samples in each pixel +// sampleCountXStride, +// sampleCountYStride +// +// y the scanline to copy. The coordinate is +// relative to the datawindow.min.y. +// +// minX, maxX used to indicate which pixels in the scanline +// will be copied. +// +// xOffsetForSampleCount, used to offset the sample count array +// yOffsetForSampleCount, and the base array. +// xOffsetForData, +// yOffsetForData +// +// xStride the xStride for the frame buffer slice +// +// format indicates if the line or tile buffer is +// in NATIVE or XDR format. +// +// typeInFrameBuffer the pixel data type of the frame buffer slice +// +// typeInFile the pixel data type in the input file's channel +// + +IMF_EXPORT +void copyIntoDeepFrameBuffer (const char *& readPtr, + char * base, + const char* sampleCountBase, + ptrdiff_t sampleCountXStride, + ptrdiff_t sampleCountYStride, + int y, int minX, int maxX, + int xOffsetForSampleCount, + int yOffsetForSampleCount, + int xOffsetForData, + int yOffsetForData, + ptrdiff_t xStride, + ptrdiff_t xPointerStride, + ptrdiff_t yPointerStride, + bool fill, + double fillValue, + Compressor::Format format, + PixelType typeInFrameBuffer, + PixelType typeInFile); + + +// +// Given a pointer into a an input file's line buffer or tile buffer, +// skip over the data for xSize pixels of type typeInFile. +// readPtr initially points to the beginning of the data to be skipped; +// when skipChannel() returns, readPtr points just past the end of the +// skipped data. +// + +IMF_EXPORT +void skipChannel (const char *&readPtr, + PixelType typeInFile, + size_t xSize); + +// +// Convert an array of pixel data from the machine's native +// representation to XDR format. +// +// toPtr, fromPtr initially point to the beginning of the input +// and output pixel data arrays; when convertInPlace() +// returns, toPtr and fromPtr point just past the +// end of the input and output arrays. +// If the native representation of the data has the +// same size as the XDR data, then the conversion +// can take in place, without an intermediate +// temporary buffer (toPtr and fromPtr can point +// to the same location). +// +// type the pixel data type +// +// numPixels number of pixels in the input and output arrays +// + +IMF_EXPORT +void convertInPlace (char *&toPtr, + const char *&fromPtr, + PixelType type, + size_t numPixels); + +// +// Copy a single channel of a horizontal row of pixels from a +// a frame buffer into an output file's internal line buffer or +// tile buffer. +// +// writePtr initially points to the beginning of the +// data in the line or tile buffer. writePtr +// is advanced as the pixel data are copied; +// when copyFromFrameBuffer() returns, +// writePtr points just past the end of the +// copied data. +// +// readPtr, endPtr point to the lefmost and rightmost pixels +// in the frame buffer slice +// +// xStride the xStride for the frame buffer slice +// +// format indicates if the line or tile buffer is +// in NATIVE or XDR format. +// +// type the pixel data type in the frame buffer +// and in the output file's channel (function +// copyFromFrameBuffer() doesn't do on-the-fly +// data type conversion) +// + +IMF_EXPORT +void copyFromFrameBuffer (char *&writePtr, + const char *&readPtr, + const char *endPtr, + size_t xStride, + Compressor::Format format, + PixelType type); + +// +// Copy a single channel of a horizontal row of pixels from a +// a frame buffer in a deep data file into an output file's +// internal line buffer or tile buffer. +// +// writePtr initially points to the beginning of the +// data in the line or tile buffer. writePtr +// is advanced as the pixel data are copied; +// when copyFromDeepFrameBuffer() returns, +// writePtr points just past the end of the +// copied data. +// +// base the start pointer of each pixel in this channel. +// It points to the real data in FrameBuffer. +// It is different for different channels. +// dataWindowMinX and dataWindowMinY are involved in +// locating for base. +// +// sampleCountBase, used to locate the position to get +// sampleCountXStride, the number of samples for each pixel. +// sampleCountYStride Used to determine how far we should +// read based on the pointer provided by base. +// +// y the scanline to copy. If we are dealing +// with a tiled deep file, then probably a portion +// of the scanline is copied. +// +// xMin, xMax used to indicate which pixels in the scanline +// will be copied. +// +// xOffsetForSampleCount, used to offset the sample count array +// yOffsetForSampleCount, and the base array. +// xOffsetForData, +// yOffsetForData +// +// xStride the xStride for the frame buffer slice +// +// format indicates if the line or tile buffer is +// in NATIVE or XDR format. +// +// type the pixel data type in the frame buffer +// and in the output file's channel (function +// copyFromFrameBuffer() doesn't do on-the-fly +// data type conversion) +// + +IMF_EXPORT +void copyFromDeepFrameBuffer (char *& writePtr, + const char * base, + char* sampleCountBase, + ptrdiff_t sampleCountXStride, + ptrdiff_t sampleCountYStride, + int y, int xMin, int xMax, + int xOffsetForSampleCount, + int yOffsetForSampleCount, + int xOffsetForData, + int yOffsetForData, + ptrdiff_t sampleStride, + ptrdiff_t xStrideForData, + ptrdiff_t yStrideForData, + Compressor::Format format, + PixelType type); + +// +// Fill part of an output file's line buffer or tile buffer with +// zeroes. This routine is called when an output file contains +// a channel for which the frame buffer contains no corresponding +// slice. +// +// writePtr initially points to the beginning of the +// data in the line or tile buffer. When +// fillChannelWithZeroes() returns, writePtr +// points just past the end of the zeroed +// data. +// +// format indicates if the line or tile buffer is +// in NATIVE or XDR format. +// +// type the pixel data type in the line or frame buffer. +// +// xSize number of pixels to be filled with zeroes. +// + +IMF_EXPORT +void fillChannelWithZeroes (char *&writePtr, + Compressor::Format format, + PixelType type, + size_t xSize); + +IMF_EXPORT +bool usesLongNames (const Header &header); + + +// +// compute size of chunk offset table - if ignore_attribute set to true +// will compute from the image size and layout, rather than the attribute +// The default behaviour is to read the attribute +// + +IMF_EXPORT +int getChunkOffsetTableSize(const Header& header,bool ignore_attribute=false); + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfMultiPartInputFile.h b/OpenEXR/include/OpenEXR/ImfMultiPartInputFile.h new file mode 100644 index 0000000..51ef9d3 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfMultiPartInputFile.h @@ -0,0 +1,128 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2011, 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. +// +/////////////////////////////////////////////////////////////////////////// + +#ifndef IMFMULTIPARTINPUTFILE_H_ +#define IMFMULTIPARTINPUTFILE_H_ + +#include "ImfGenericInputFile.h" +#include "ImfNamespace.h" +#include "ImfForward.h" +#include "ImfThreading.h" +#include "ImfExport.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +class IMF_EXPORT MultiPartInputFile : public GenericInputFile +{ + public: + MultiPartInputFile(const char fileName[], + int numThreads = globalThreadCount(), + bool reconstructChunkOffsetTable = true); + + MultiPartInputFile(IStream& is, + int numThreads = globalThreadCount(), + bool reconstructChunkOffsetTable = true); + + virtual ~MultiPartInputFile(); + + // ---------------------- + // Count of number of parts in file + // --------------------- + int parts() const; + + + //---------------------- + // Access to the headers + //---------------------- + + const Header & header(int n) const; + + + //---------------------------------- + // Access to the file format version + //---------------------------------- + + int version () const; + + + // =---------------------------------------- + // Check whether the entire chunk offset + // table for the part is written correctly + // ----------------------------------------- + bool partComplete(int part) const; + + + + struct Data; + + + private: + Data* _data; + + MultiPartInputFile(const MultiPartInputFile &); // not implemented + + + // + // used internally by 'Part' types to access individual parts of the multipart file + // + template T* getInputPart(int partNumber); + InputPartData* getPart(int); + + void initialize(); + + + + + friend class InputPart; + friend class ScanLineInputPart; + friend class TiledInputPart; + friend class DeepScanLineInputPart; + friend class DeepTiledInputPart; + + // + // For backward compatibility. + // + + friend class InputFile; + friend class TiledInputFile; + friend class ScanLineInputFile; + friend class DeepScanLineInputFile; + friend class DeepTiledInputFile; +}; + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif /* IMFMULTIPARTINPUTFILE_H_ */ diff --git a/OpenEXR/include/OpenEXR/ImfMultiPartOutputFile.h b/OpenEXR/include/OpenEXR/ImfMultiPartOutputFile.h new file mode 100644 index 0000000..d5d6bfc --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfMultiPartOutputFile.h @@ -0,0 +1,118 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2011, Industrial Light & Magic, a division of Lucas +// Digital Ltd. LLC +// +// Portions (c) 2012 Weta Digital Ltd +// +// 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. +// +/////////////////////////////////////////////////////////////////////////// + +#ifndef MULTIPARTOUTPUTFILE_H_ +#define MULTIPARTOUTPUTFILE_H_ + +#include "ImfHeader.h" +#include "ImfGenericOutputFile.h" +#include "ImfForward.h" +#include "ImfThreading.h" +#include "ImfNamespace.h" +#include "ImfExport.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +// +// Class responsible for handling the writing of multipart images. +// +// Note: Certain attributes are 'common' to all parts. Notably: +// * Display Window +// * Pixel Aspect Ratio +// * Time Code +// * Chromaticities +// The first header forms the basis for the set of attributes that are shared +// across the constituent parts. +// +// Parameters +// headers - pointer to array of headers; one for each part of the image file +// parts - count of number of parts +// overrideSharedAttributes - toggle for the handling of shared attributes. +// set false to check for inconsistencies, true +// to copy the values over from the first header. +// numThreads - number of threads that should be used in encoding the data. +// + +class IMF_EXPORT MultiPartOutputFile : public GenericOutputFile +{ + public: + MultiPartOutputFile(const char fileName[], + const Header * headers, + int parts, + bool overrideSharedAttributes = false, + int numThreads = globalThreadCount()); + + MultiPartOutputFile(OStream & os, + const Header * headers, + int parts, + bool overrideSharedAttributes = false, + int numThreads = globalThreadCount()); + + // + // return number of parts in file + // + int parts() const ; + + + // + // return header for part n + // (note: may have additional attributes compared to that passed to constructor) + // + const Header & header(int n) const; + + ~MultiPartOutputFile(); + + struct Data; + + private: + Data* _data; + + MultiPartOutputFile(const MultiPartOutputFile &); // not implemented + + template T* getOutputPart(int partNumber); + + + friend class OutputPart; + friend class TiledOutputPart; + friend class DeepScanLineOutputPart; + friend class DeepTiledOutputPart; +}; + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif /* MULTIPARTOUTPUTFILE_H_ */ diff --git a/OpenEXR/include/OpenEXR/ImfMultiView.h b/OpenEXR/include/OpenEXR/ImfMultiView.h new file mode 100644 index 0000000..127f97d --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfMultiView.h @@ -0,0 +1,187 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2007, Weta Digital Ltd +// +// 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 Weta Digital 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_MULTIVIEW_H +#define INCLUDED_IMF_MULTIVIEW_H + +#include "ImfChannelList.h" +#include "ImfStringVectorAttribute.h" +#include "ImfExport.h" +#include "ImfNamespace.h" + +//----------------------------------------------------------------------------- +// +// Functions related to accessing channels and views in multi-view +// OpenEXR files. +// +// A multi-view image file contains two or more views of the same +// scene, as seen from different viewpoints, for example, a left-eye +// and a right-eye view for stereo displays. Each view has its own +// set of image channels. A naming convention identifies the channels +// that belong to a given view. +// +// A "multiView" attribute in the file header lists the names of the +// views in an image (see ImfStandardAttributes.h), and channel names +// of the form +// +// layer.view.channel +// +// allow channels to be matched with views. +// +// For compatibility with singe-view images, the first view listed in +// the multiView attribute is the "default view", and channels that +// have no periods in their names are considered part of the default +// view. +// +// For example, if a file's multiView attribute lists the views +// "left" and "right", in that order, then "left" is the default +// view. Channels +// +// "R", "left.Z", "diffuse.left.R" +// +// are part of the "left" view; channels +// +// "right.R", "right.Z", "diffuse.right.R" +// +// are part of the "right" view; and channels +// +// "tmp.R", "right.diffuse.R", "diffuse.tmp.R" +// +// belong to no view at all. +// +//----------------------------------------------------------------------------- + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + +// +// Return the name of the default view given a multi-view string vector, +// that is, return the first element of the string vector. If the string +// vector is empty, return "". +// + +IMF_EXPORT +std::string defaultViewName (const StringVector &multiView); + + +// +// Given the name of a channel, return the name of the view to +// which it belongs. Returns the empty string ("") if the channel +// is not a member of any named view. +// + +IMF_EXPORT +std::string viewFromChannelName (const std::string &channel, + const StringVector &multiView); + + +// +// Return whether channel1 and channel2 are the same channel but +// viewed in different views. (Return false if either channel +// belongs to no view or if both channels belong to the same view.) +// + +IMF_EXPORT +bool areCounterparts (const std::string &channel1, + const std::string &channel2, + const StringVector &multiView); + +// +// Return a list of all channels belonging to view viewName. +// + +IMF_EXPORT +ChannelList channelsInView (const std::string &viewName, + const ChannelList &channelList, + const StringVector &multiView); + +// +// Return a list of channels not associated with any view. +// + +IMF_EXPORT +ChannelList channelsInNoView (const ChannelList &channelList, + const StringVector &multiView); + +// +// Given the name of a channel, return a list of the same channel +// in all views (for example, given X.left.Y return X.left.Y, +// X.right.Y, X.centre.Y, etc.). +// + +IMF_EXPORT +ChannelList channelInAllViews (const std::string &channame, + const ChannelList &channelList, + const StringVector &multiView); + +// +// Given the name of a channel in one view, return the corresponding +// channel name for view otherViewName. Return "" if no corresponding +// channel exists in view otherViewName, or if view otherViewName doesn't +// exist. +// + +IMF_EXPORT +std::string channelInOtherView (const std::string &channel, + const ChannelList &channelList, + const StringVector &multiView, + const std::string &otherViewName); + +// +// Given a channel name that does not include a view name, insert +// multiView[i] into the channel name at the appropriate location. +// If i is zero and the channel name contains no periods, then do +// not insert the view name. +// + +IMF_EXPORT +std::string insertViewName (const std::string &channel, + const StringVector &multiView, + int i); + +// +// Given a channel name that does may include a view name, return +// string without the view name. If the string does not contain +// the view name, return the string unaltered. +// (Will only remove the viewname if it is in the correct position +// in the string) +// + +IMF_EXPORT +std::string removeViewName (const std::string &channel, + const std::string &view); + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfName.h b/OpenEXR/include/OpenEXR/ImfName.h new file mode 100644 index 0000000..4d4f25a --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfName.h @@ -0,0 +1,150 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMF_NAME_H +#define INCLUDED_IMF_NAME_H + +//----------------------------------------------------------------------------- +// +// class ImfName -- a zero-terminated string +// with a fixed, small maximum length +// +//----------------------------------------------------------------------------- + +#include +#include "ImfNamespace.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +class Name +{ + public: + + //------------- + // Constructors + //------------- + + Name (); + Name (const char text[]); + + + //-------------------- + // Assignment operator + //-------------------- + + Name & operator = (const char text[]); + + + //--------------------- + // Access to the string + //--------------------- + + const char * text () const {return _text;} + const char * operator * () const {return _text;} + + //--------------- + // Maximum length + //--------------- + + static const int SIZE = 256; + static const int MAX_LENGTH = SIZE - 1; + + private: + + char _text[SIZE]; +}; + + +bool operator == (const Name &x, const Name &y); +bool operator != (const Name &x, const Name &y); +bool operator < (const Name &x, const Name &y); + + +//----------------- +// Inline functions +//----------------- + +inline Name & +Name::operator = (const char text[]) +{ + strncpy (_text, text, MAX_LENGTH); + return *this; +} + + +inline +Name::Name () +{ + _text[0] = 0; +} + + +inline +Name::Name (const char text[]) +{ + *this = text; + _text [MAX_LENGTH] = 0; +} + + +inline bool +operator == (const Name &x, const Name &y) +{ + return strcmp (*x, *y) == 0; +} + + +inline bool +operator != (const Name &x, const Name &y) +{ + return !(x == y); +} + + +inline bool +operator < (const Name &x, const Name &y) +{ + return strcmp (*x, *y) < 0; +} + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + + + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfNamespace.h b/OpenEXR/include/OpenEXR/ImfNamespace.h new file mode 100644 index 0000000..c36a31e --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfNamespace.h @@ -0,0 +1,115 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2012, 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. +// +/////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDED_IMFNAMESPACE_H +#define INCLUDED_IMFNAMESPACE_H + +// +// The purpose of this file is to have all of the Imath symbols defined within +// the OPENEXR_IMF_INTERNAL_NAMESPACE namespace rather than the standard Imath +// namespace. Those symbols are made available to client code through the +// OPENEXR_IMF_NAMESPACE in addition to the OPENEXR_IMF_INTERNAL_NAMESPACE. +// +// To ensure source code compatibility, the OPENEXR_IMF_NAMESPACE defaults to +// Imath and then "using namespace OPENEXR_IMF_INTERNAL_NAMESPACE;" brings all +// of the declarations from the OPENEXR_IMF_INTERNAL_NAMESPACE into the +// OPENEXR_IMF_NAMESPACE. +// This means that client code can continue to use syntax like +// Imf::Header, but at link time it will resolve to a +// mangled symbol based on the OPENEXR_IMF_INTERNAL_NAMESPACE. +// +// As an example, if one needed to build against a newer version of Imath and +// have it run alongside an older version in the same application, it is now +// possible to use an internal namespace to prevent collisions between the +// older versions of Imath symbols and the newer ones. To do this, the +// following could be defined at build time: +// +// OPENEXR_IMF_INTERNAL_NAMESPACE = Imf_v2 +// +// This means that declarations inside Imath headers look like this (after +// the preprocessor has done its work): +// +// namespace Imf_v2 { +// ... +// class declarations +// ... +// } +// +// namespace Imf { +// using namespace IMF_NAMESPACE_v2; +// } +// + +// +// Open Source version of this file pulls in the OpenEXRConfig.h file +// for the configure time options. +// +#include "OpenEXRConfig.h" + + +#ifndef OPENEXR_IMF_NAMESPACE +#define OPENEXR_IMF_NAMESPACE Imf +#endif + +#ifndef OPENEXR_IMF_INTERNAL_NAMESPACE +#define OPENEXR_IMF_INTERNAL_NAMESPACE OPENEXR_IMF_NAMESPACE +#endif + +// +// We need to be sure that we import the internal namespace into the public one. +// To do this, we use the small bit of code below which initially defines +// OPENEXR_IMF_INTERNAL_NAMESPACE (so it can be referenced) and then defines +// OPENEXR_IMF_NAMESPACE and pulls the internal symbols into the public +// namespace. +// + +namespace OPENEXR_IMF_INTERNAL_NAMESPACE {} +namespace OPENEXR_IMF_NAMESPACE { + using namespace OPENEXR_IMF_INTERNAL_NAMESPACE; +} + +// +// There are identical pairs of HEADER/SOURCE ENTER/EXIT macros so that +// future extension to the namespace mechanism is possible without changing +// project source code. +// + +#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER namespace OPENEXR_IMF_INTERNAL_NAMESPACE { +#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT } + +#define OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER namespace OPENEXR_IMF_INTERNAL_NAMESPACE { +#define OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT } + + +#endif /* INCLUDED_IMFNAMESPACE_H */ diff --git a/OpenEXR/include/OpenEXR/ImfOpaqueAttribute.h b/OpenEXR/include/OpenEXR/ImfOpaqueAttribute.h new file mode 100644 index 0000000..1682bfd --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfOpaqueAttribute.h @@ -0,0 +1,110 @@ +/////////////////////////////////////////////////////////////////////////// +// +// 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMF_OPAQUE_ATTRIBUTE_H +#define INCLUDED_IMF_OPAQUE_ATTRIBUTE_H + +//----------------------------------------------------------------------------- +// +// class OpaqueAttribute +// +// When an image file is read, OpqaqueAttribute objects are used +// to hold the values of attributes whose types are not recognized +// by the reading program. OpaqueAttribute objects can be read +// from an image file, copied, and written back to to another image +// file, but their values are inaccessible. +// +//----------------------------------------------------------------------------- + +#include "ImfAttribute.h" +#include "ImfArray.h" +#include "ImfNamespace.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +class IMF_EXPORT OpaqueAttribute: public Attribute +{ + public: + + //---------------------------- + // Constructors and destructor + //---------------------------- + + OpaqueAttribute (const char typeName[]); + OpaqueAttribute (const OpaqueAttribute &other); + virtual ~OpaqueAttribute (); + + + //------------------------------- + // Get this attribute's type name + //------------------------------- + + virtual const char * typeName () const; + + + //------------------------------ + // Make a copy of this attribute + //------------------------------ + + virtual Attribute * copy () const; + + + //---------------- + // I/O and copying + //---------------- + + virtual void writeValueTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &os, + int version) const; + + virtual void readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is, + int size, + int version); + + virtual void copyValueFrom (const Attribute &other); + + + private: + + Array _typeName; + long _dataSize; + Array _data; +}; + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfOutputFile.h b/OpenEXR/include/OpenEXR/ImfOutputFile.h new file mode 100644 index 0000000..00f9f80 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfOutputFile.h @@ -0,0 +1,263 @@ +/////////////////////////////////////////////////////////////////////////// +// +// 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMF_OUTPUT_FILE_H +#define INCLUDED_IMF_OUTPUT_FILE_H + +//----------------------------------------------------------------------------- +// +// class OutputFile +// +//----------------------------------------------------------------------------- + +#include "ImfHeader.h" +#include "ImfFrameBuffer.h" +#include "ImfThreading.h" +#include "ImfGenericOutputFile.h" +#include "ImfNamespace.h" +#include "ImfForward.h" +#include "ImfExport.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +class IMF_EXPORT OutputFile : public GenericOutputFile +{ + public: + + //----------------------------------------------------------- + // Constructor -- opens the file and writes the file header. + // The file header is also copied into the OutputFile object, + // and can later be accessed via the header() method. + // Destroying this OutputFile object automatically closes + // the file. + // + // numThreads determines the number of threads that will be + // used to write the file (see ImfThreading.h). + //----------------------------------------------------------- + + OutputFile (const char fileName[], const Header &header, + int numThreads = globalThreadCount()); + + + //------------------------------------------------------------ + // Constructor -- attaches the new OutputFile object to a file + // that has already been opened, and writes the file header. + // The file header is also copied into the OutputFile object, + // and can later be accessed via the header() method. + // Destroying this OutputFile object does not automatically + // close the file. + // + // numThreads determines the number of threads that will be + // used to write the file (see ImfThreading.h). + //------------------------------------------------------------ + + OutputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &os, const Header &header, + int numThreads = globalThreadCount()); + + + //------------------------------------------------- + // Destructor + // + // Destroying the OutputFile object before writing + // all scan lines within the data window results in + // an incomplete file. + //------------------------------------------------- + + virtual ~OutputFile (); + + + //------------------------ + // Access to the file name + //------------------------ + + const char * fileName () const; + + + //-------------------------- + // Access to the file header + //-------------------------- + + const Header & header () const; + + + //------------------------------------------------------- + // Set the current frame buffer -- copies the FrameBuffer + // object into the OutputFile object. + // + // The current frame buffer is the source of the pixel + // data written to the file. The current frame buffer + // must be set at least once before writePixels() is + // called. The current frame buffer can be changed + // after each call to writePixels. + //------------------------------------------------------- + + void setFrameBuffer (const FrameBuffer &frameBuffer); + + + //----------------------------------- + // Access to the current frame buffer + //----------------------------------- + + const FrameBuffer & frameBuffer () const; + + + //------------------------------------------------------------------- + // Write pixel data: + // + // writePixels(n) retrieves the next n scan lines worth of data from + // the current frame buffer, starting with the scan line indicated by + // currentScanLine(), and stores the data in the output file, and + // progressing in the direction indicated by header.lineOrder(). + // + // To produce a complete and correct file, exactly m scan lines must + // be written, where m is equal to + // header().dataWindow().max.y - header().dataWindow().min.y + 1. + //------------------------------------------------------------------- + + void writePixels (int numScanLines = 1); + + + //------------------------------------------------------------------ + // Access to the current scan line: + // + // currentScanLine() returns the y coordinate of the first scan line + // that will be read from the current frame buffer during the next + // call to writePixels(). + // + // If header.lineOrder() == INCREASING_Y: + // + // The current scan line before the first call to writePixels() + // is header().dataWindow().min.y. After writing each scan line, + // the current scan line is incremented by 1. + // + // If header.lineOrder() == DECREASING_Y: + // + // The current scan line before the first call to writePixels() + // is header().dataWindow().max.y. After writing each scan line, + // the current scan line is decremented by 1. + // + //------------------------------------------------------------------ + + int currentScanLine () const; + + + //-------------------------------------------------------------- + // Shortcut to copy all pixels from an InputFile into this file, + // without uncompressing and then recompressing the pixel data. + // This file's header must be compatible with the InputFile's + // header: The two header's "dataWindow", "compression", + // "lineOrder" and "channels" attributes must be the same. + //-------------------------------------------------------------- + + void copyPixels (InputFile &in); + + //------------------------------------------------------------- + // Shortcut to copy all pixels from an InputPart into this file + // - equivalent to copyPixel(InputFile &in) but for multipart files + //--------------------------------------------------------------- + + void copyPixels (InputPart &in); + + + + //-------------------------------------------------------------- + // Updating the preview image: + // + // updatePreviewImage() supplies a new set of pixels for the + // preview image attribute in the file's header. If the header + // does not contain a preview image, updatePreviewImage() throws + // an IEX_NAMESPACE::LogicExc. + // + // Note: updatePreviewImage() is necessary because images are + // often stored in a file incrementally, a few scan lines at a + // time, while the image is being generated. Since the preview + // image is an attribute in the file's header, it gets stored in + // the file as soon as the file is opened, but we may not know + // what the preview image should look like until we have written + // the last scan line of the main image. + // + //-------------------------------------------------------------- + + void updatePreviewImage (const PreviewRgba newPixels[]); + + + //--------------------------------------------------------- + // Break a scan line -- for testing and debugging only: + // + // breakScanLine(y,p,n,c) introduces an error into the + // output file by writing n copies of character c, starting + // p bytes from the beginning of the pixel data block that + // contains scan line y. + // + // Warning: Calling this function usually results in a + // broken image file. The file or parts of it may not + // be readable, or the file may contain bad data. + // + //--------------------------------------------------------- + + void breakScanLine (int y, int offset, int length, char c); + + + struct Data; + + private: + + //------------------------------------------------------------ + // Constructor -- attaches the OutputStreamMutex to the + // given one from MultiPartOutputFile. Set the previewPosition + // and lineOffsetsPosition which have been acquired from + // the constructor of MultiPartOutputFile as well. + //------------------------------------------------------------ + OutputFile (const OutputPartData* part); + + OutputFile (const OutputFile &); // not implemented + OutputFile & operator = (const OutputFile &); // not implemented + + void initialize (const Header &header); + + Data * _data; + + + friend class MultiPartOutputFile; + +}; + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfOutputPart.h b/OpenEXR/include/OpenEXR/ImfOutputPart.h new file mode 100644 index 0000000..41f3cf3 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfOutputPart.h @@ -0,0 +1,77 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2011, 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. +// +/////////////////////////////////////////////////////////////////////////// + +#ifndef IMFOUTPUTPART_H_ +#define IMFOUTPUTPART_H_ + +#include "ImfMultiPartOutputFile.h" +#include "ImfOutputFile.h" +#include "ImfForward.h" +#include "ImfNamespace.h" +#include "ImfExport.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +//--------------------------------------------------------------------- +// class OutputPart: +// +// Same interface as OutputFile. Please refer to OutputFile. +//--------------------------------------------------------------------- + +class IMF_EXPORT OutputPart +{ + public: + OutputPart(MultiPartOutputFile& multiPartFile, int partNumber); + + const char * fileName () const; + const Header & header () const; + void setFrameBuffer (const FrameBuffer &frameBuffer); + const FrameBuffer & frameBuffer () const; + void writePixels (int numScanLines = 1); + int currentScanLine () const; + void copyPixels (InputFile &in); + void copyPixels (InputPart &in); + + void updatePreviewImage (const PreviewRgba newPixels[]); + void breakScanLine (int y, int offset, int length, char c); + + private: + OutputFile* file; +}; + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif /* IMFOUTPUTPART_H_ */ diff --git a/OpenEXR/include/OpenEXR/ImfPartHelper.h b/OpenEXR/include/OpenEXR/ImfPartHelper.h new file mode 100644 index 0000000..d55cc7b --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfPartHelper.h @@ -0,0 +1,262 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2012, Weta Digital Ltd +// +// 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 Weta Digital 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_PARTHELPER_H +#define INCLUDED_IMF_PARTHELPER_H + +//----------------------------------------------------------------------------- +// +// Functions to help split channels into separate parts: provide a list of +// channels, with desired views. call SplitChannels to assign a part to each +// layer, or correct the name of the channel. +// Also can enumerate the parts in a file and list which parts channels are in +// +// This is a good way to offer a 'create Multipart file' checkbox to the user in a +// write dialog box: Populate a list of MultiViewChannelName objects, +// call SplitChannels with whether single or multipart files are required. +// Then write the number of parts it specifies, using internal_name for the channel +// names in the ChannelList and FrameBuffer objects. There should be no need +// for different codepaths for single part and multipart files +// +// Similarly, on reading a file as a MultiPartInputFile, use GetChannelsInMultiPartFile to +// enumerate all channels in the file, using internal_name in FrameBuffer objects +// to read the channel +// +// +//----------------------------------------------------------------------------- + +#include "ImfForward.h" +#include "ImfNamespace.h" +#include "ImfExport.h" +#include "ImfMultiPartInputFile.h" +#include "ImfChannelList.h" +#include "ImfStringVectorAttribute.h" +#include "ImfStandardAttributes.h" +#include "ImfMultiView.h" + +#include +#include +#include + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + +struct MultiViewChannelName{ + +public: + std::string name; ///< name of channel + std::string view; ///< view for channel + + int part_number; ///< part number: updated by SplitChannels + std::string internal_name;///< name used in headers: in singlepart mode, may contain viewname + + virtual ~MultiViewChannelName() {} + + //return layer for this channel, or "" if no layer + std::string getLayer() const + { + std::size_t q=name.rfind('.'); + if( q==name.npos ) + { + return ""; + } + return name.substr(0,q); + + } + + std::string getSuffix() const + { + std::size_t q=name.rfind('.'); + if( q==name.npos ) + { + return name; + } + return name.substr(q+1); + + } + +}; + + + +// +///\brief assigns individual channels to different parts based on their layer and view name +/// input is an array, list, vector etc of MultiViewChannelName objects +/// on entry, each MultiViewChannelName name/view must be set (view can be empty if not multiview) +/// +/// if singlepart set, then on exit part_number will be zero, and internal_name will have view name inserted +/// otherwise, each channel will be assigned to a different part based on its layer name and view name +/// +/// @param begin pointer to first MultiViewChannelName item +/// @param end pointer to end of MultiViewChannelName item array +/// @return total number of parts required +// + +template int +SplitChannels(const T & begin,const T & end,bool multipart=true,const std::string & heroView="") +{ + if(!multipart) + { + for(T i=begin;i!=end;i++) + { + i->part_number=0; + + //does this have a view name set? + if(i->view=="") + { + i->internal_name=i->name; + }else{ + + std::string lname = i->getLayer(); + + // no layer, only non-hero views get view name in layer name + + + if(lname=="") + { + if(i->view==heroView) + { + i->internal_name = i->name; + }else{ + i->internal_name = i->view+"."+i->name; + } + }else{ + i->internal_name = lname+"."+i->view+"."+i->getSuffix(); + } + } + } + // single part created + return 1; + }else{ + // step 1: extract individual layers and parts + // for each layer, enumerate which views are active + + std::map< std::string , std::set< std::string > > viewsInLayers; + for(T i=begin;i!=end;i++) + { + viewsInLayers[i->getLayer()].insert(i->view); + } + + // step 2: assign a part number to each layer/view + + std::map< std::pair , int > layerToPart; + + int partCount=0; + + for(std::map< std::string , std::set< std::string > >::const_iterator layer=viewsInLayers.begin(); + layer!=viewsInLayers.end();layer++) + { + // if this layer has a heroView, insert that first + bool layer_has_hero = layer->second.find(heroView)!=layer->second.end(); + if( layer_has_hero ) + { + layerToPart[ std::make_pair(layer->first,heroView) ] = partCount++; + } + + + // insert other layers which aren't the hero view + for(std::set< std::string >::const_iterator view=layer->second.begin(); + view!=layer->second.end();view++) + { + if(*view!=heroView) + { + layerToPart[ std::make_pair(layer->first,*view) ] = partCount++; + } + } + + } + + // step 3: update part number of each provided channel + + for( T i=begin;i!=end;i++) + { + i->internal_name=i->name; + i->part_number = layerToPart[ std::make_pair(i->getLayer(),i->view) ]; + } + + + // return number of parts created + return partCount; + } +} + +// +// populate the chans vector with a list of channels in the file +// and their corresponding part number +// +template void +GetChannelsInMultiPartFile(const MultiPartInputFile & file,T & chans) +{ + bool has_multiview=false; + StringVector mview; + if(file.parts()==1) + { + if(hasMultiView(file.header(0))) + { + mview=multiView(file.header(0)); + has_multiview=true; + } + } + + for(int p=0;p +#include "ImfNamespace.h" +#include "ImfExport.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +const std::string SCANLINEIMAGE = "scanlineimage"; +const std::string TILEDIMAGE = "tiledimage"; +const std::string DEEPSCANLINE = "deepscanline"; +const std::string DEEPTILE = "deeptile"; + +IMF_EXPORT bool isImage(const std::string& name); + +IMF_EXPORT bool isTiled(const std::string& name); + +IMF_EXPORT bool isDeepData(const std::string& name); + +IMF_EXPORT bool isSupportedType(const std::string& name); + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + +#endif /* IMFPARTTYPE_H_ */ diff --git a/OpenEXR/include/OpenEXR/ImfPixelType.h b/OpenEXR/include/OpenEXR/ImfPixelType.h new file mode 100644 index 0000000..4b8005e --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfPixelType.h @@ -0,0 +1,67 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMF_PIXEL_TYPE_H +#define INCLUDED_IMF_PIXEL_TYPE_H + +//----------------------------------------------------------------------------- +// +// enum PixelType +// +//----------------------------------------------------------------------------- + +#include "ImfNamespace.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +enum PixelType +{ + UINT = 0, // unsigned int (32 bit) + HALF = 1, // half (16 bit floating point) + FLOAT = 2, // float (32 bit floating point) + + NUM_PIXELTYPES // number of different pixel types +}; + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + + + + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfPreviewImage.h b/OpenEXR/include/OpenEXR/ImfPreviewImage.h new file mode 100644 index 0000000..dcd2ebe --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfPreviewImage.h @@ -0,0 +1,135 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2003, 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_PREVIEW_IMAGE_H +#define INCLUDED_IMF_PREVIEW_IMAGE_H + +#include "ImfNamespace.h" +#include "ImfExport.h" + +//----------------------------------------------------------------------------- +// +// class PreviewImage -- a usually small, low-dynamic range image, +// that is intended to be stored in an image file's header. +// +// struct PreviewRgba -- holds the value of a PreviewImage pixel. +// +//----------------------------------------------------------------------------- + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +struct IMF_EXPORT PreviewRgba +{ + unsigned char r; // Red, green and blue components of + unsigned char g; // the pixel's color; intensity is + unsigned char b; // proportional to pow (x/255, 2.2), + // where x is r, g, or b. + + unsigned char a; // The pixel's alpha; 0 == transparent, + // 255 == opaque. + + PreviewRgba (unsigned char r = 0, + unsigned char g = 0, + unsigned char b = 0, + unsigned char a = 255) + : r(r), g(g), b(b), a(a) {} +}; + + +class IMF_EXPORT PreviewImage +{ + public: + + //-------------------------------------------------------------------- + // Constructor: + // + // PreviewImage(w,h,p) constructs a preview image with w by h pixels + // whose initial values are specified in pixel array p. The x and y + // coordinates of the pixels in p go from 0 to w-1, and from 0 to h-1. + // The pixel with coordinates (x, y) is at address p + y*w + x. + // Pixel (0, 0) is in the upper left corner of the preview image. + // If p is zero, the pixels in the preview image are initialized with + // (r = 0, b = 0, g = 0, a = 255). + // + //-------------------------------------------------------------------- + + PreviewImage (unsigned int width = 0, + unsigned int height = 0, + const PreviewRgba pixels[] = 0); + + //----------------------------------------------------- + // Copy constructor, destructor and assignment operator + //----------------------------------------------------- + + PreviewImage (const PreviewImage &other); + ~PreviewImage (); + + PreviewImage & operator = (const PreviewImage &other); + + + //----------------------------------------------- + // Access to width, height and to the pixel array + //----------------------------------------------- + + unsigned int width () const {return _width;} + unsigned int height () const {return _height;} + + PreviewRgba * pixels () {return _pixels;} + const PreviewRgba * pixels () const {return _pixels;} + + + //---------------------------- + // Access to individual pixels + //---------------------------- + + PreviewRgba & pixel (unsigned int x, unsigned int y) + {return _pixels[y * _width + x];} + + const PreviewRgba & pixel (unsigned int x, unsigned int y) const + {return _pixels[y * _width + x];} + + private: + + unsigned int _width; + unsigned int _height; + PreviewRgba * _pixels; +}; + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfPreviewImageAttribute.h b/OpenEXR/include/OpenEXR/ImfPreviewImageAttribute.h new file mode 100644 index 0000000..160e409 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfPreviewImageAttribute.h @@ -0,0 +1,70 @@ +/////////////////////////////////////////////////////////////////////////// +// +// 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_PREVIEW_IMAGE_ATTRIBUTE_H +#define INCLUDED_IMF_PREVIEW_IMAGE_ATTRIBUTE_H + +//----------------------------------------------------------------------------- +// +// class PreviewImageAttribute +// +//----------------------------------------------------------------------------- + +#include "ImfAttribute.h" +#include "ImfPreviewImage.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +typedef TypedAttribute PreviewImageAttribute; + +template <> +IMF_EXPORT +const char *PreviewImageAttribute::staticTypeName (); + +template <> +IMF_EXPORT +void PreviewImageAttribute::writeValueTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &, + int) const; + +template <> +IMF_EXPORT +void PreviewImageAttribute::readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &, + int, int); + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfRational.h b/OpenEXR/include/OpenEXR/ImfRational.h new file mode 100644 index 0000000..ba62b6b --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfRational.h @@ -0,0 +1,98 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2006, 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_RATIONAL_H +#define INCLUDED_IMF_RATIONAL_H + +#include "ImfExport.h" +#include "ImfNamespace.h" + +//----------------------------------------------------------------------------- +// +// Rational numbers +// +// A rational number is represented as pair of integers, n and d. +// The value of of the rational number is +// +// n/d for d > 0 +// positive infinity for n > 0, d == 0 +// negative infinity for n < 0, d == 0 +// not a number (NaN) for n == 0, d == 0 +// +//----------------------------------------------------------------------------- + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +class IMF_EXPORT Rational +{ + public: + + int n; // numerator + unsigned int d; // denominator + + + //---------------------------------------- + // Default constructor, sets value to zero + //---------------------------------------- + + Rational (): n (0), d (1) {} + + + //------------------------------------- + // Constructor, explicitly sets n and d + //------------------------------------- + + Rational (int n, int d): n (n), d (d) {} + + + //---------------------------- + // Constructor, approximates x + //---------------------------- + + explicit Rational (double x); + + + //--------------------------------- + // Approximate conversion to double + //--------------------------------- + + operator double () const {return double (n) / double (d);} +}; + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfRationalAttribute.h b/OpenEXR/include/OpenEXR/ImfRationalAttribute.h new file mode 100644 index 0000000..988fe01 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfRationalAttribute.h @@ -0,0 +1,69 @@ +/////////////////////////////////////////////////////////////////////////// +// +// 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. +// +/////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDED_IMF_RATIONAL_ATTRIBUTE_H +#define INCLUDED_IMF_RATIONAL_ATTRIBUTE_H + +//----------------------------------------------------------------------------- +// +// class RationalAttribute +// +//----------------------------------------------------------------------------- + +#include "ImfAttribute.h" +#include "ImfRational.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +typedef TypedAttribute RationalAttribute; + +template <> +IMF_EXPORT +const char *RationalAttribute::staticTypeName (); + +template <> +IMF_EXPORT +void RationalAttribute::writeValueTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &, + int) const; + +template <> +IMF_EXPORT +void RationalAttribute::readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &, + int, int); + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfRgba.h b/OpenEXR/include/OpenEXR/ImfRgba.h new file mode 100644 index 0000000..dccba9f --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfRgba.h @@ -0,0 +1,109 @@ +/////////////////////////////////////////////////////////////////////////// +// +// 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_RGBA_H +#define INCLUDED_IMF_RGBA_H + +//----------------------------------------------------------------------------- +// +// class Rgba +// +//----------------------------------------------------------------------------- + +#include "half.h" +#include "ImfNamespace.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +// +// RGBA pixel +// + +struct Rgba +{ + half r; + half g; + half b; + half a; + + Rgba () {} + Rgba (half r, half g, half b, half a = 1.f): r (r), g (g), b (b), a (a) {} + + Rgba & operator = (const Rgba &other) + { + r = other.r; + g = other.g; + b = other.b; + a = other.a; + + return *this; + } +}; + + +// +// Channels in an RGBA file +// + +enum RgbaChannels +{ + WRITE_R = 0x01, // Red + WRITE_G = 0x02, // Green + WRITE_B = 0x04, // Blue + WRITE_A = 0x08, // Alpha + + WRITE_Y = 0x10, // Luminance, for black-and-white images, + // or in combination with chroma + + WRITE_C = 0x20, // Chroma (two subsampled channels, RY and BY, + // supported only for scanline-based files) + + WRITE_RGB = 0x07, // Red, green, blue + WRITE_RGBA = 0x0f, // Red, green, blue, alpha + + WRITE_YC = 0x30, // Luminance, chroma + WRITE_YA = 0x18, // Luminance, alpha + WRITE_YCA = 0x38 // Luminance, chroma, alpha +}; + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + + + + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfRgbaFile.h b/OpenEXR/include/OpenEXR/ImfRgbaFile.h new file mode 100644 index 0000000..10a74a0 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfRgbaFile.h @@ -0,0 +1,346 @@ +/////////////////////////////////////////////////////////////////////////// +// +// 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMF_RGBA_FILE_H +#define INCLUDED_IMF_RGBA_FILE_H + + +//----------------------------------------------------------------------------- +// +// Simplified RGBA image I/O +// +// class RgbaOutputFile +// class RgbaInputFile +// +//----------------------------------------------------------------------------- + +#include "ImfHeader.h" +#include "ImfFrameBuffer.h" +#include "ImfRgba.h" +#include "ImathVec.h" +#include "ImathBox.h" +#include "half.h" +#include "ImfThreading.h" +#include +#include "ImfNamespace.h" +#include "ImfForward.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +// +// RGBA output file. +// + +class IMF_EXPORT RgbaOutputFile +{ + public: + + //--------------------------------------------------- + // Constructor -- header is constructed by the caller + //--------------------------------------------------- + + RgbaOutputFile (const char name[], + const Header &header, + RgbaChannels rgbaChannels = WRITE_RGBA, + int numThreads = globalThreadCount()); + + + //---------------------------------------------------- + // Constructor -- header is constructed by the caller, + // file is opened by the caller, destructor will not + // automatically close the file. + //---------------------------------------------------- + + RgbaOutputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &os, + const Header &header, + RgbaChannels rgbaChannels = WRITE_RGBA, + int numThreads = globalThreadCount()); + + + //---------------------------------------------------------------- + // Constructor -- header data are explicitly specified as function + // call arguments (empty dataWindow means "same as displayWindow") + //---------------------------------------------------------------- + + RgbaOutputFile (const char name[], + const IMATH_NAMESPACE::Box2i &displayWindow, + const IMATH_NAMESPACE::Box2i &dataWindow = IMATH_NAMESPACE::Box2i(), + RgbaChannels rgbaChannels = WRITE_RGBA, + float pixelAspectRatio = 1, + const IMATH_NAMESPACE::V2f screenWindowCenter = IMATH_NAMESPACE::V2f (0, 0), + float screenWindowWidth = 1, + LineOrder lineOrder = INCREASING_Y, + Compression compression = PIZ_COMPRESSION, + int numThreads = globalThreadCount()); + + + //----------------------------------------------- + // Constructor -- like the previous one, but both + // the display window and the data window are + // Box2i (V2i (0, 0), V2i (width - 1, height -1)) + //----------------------------------------------- + + RgbaOutputFile (const char name[], + int width, + int height, + RgbaChannels rgbaChannels = WRITE_RGBA, + float pixelAspectRatio = 1, + const IMATH_NAMESPACE::V2f screenWindowCenter = IMATH_NAMESPACE::V2f (0, 0), + float screenWindowWidth = 1, + LineOrder lineOrder = INCREASING_Y, + Compression compression = PIZ_COMPRESSION, + int numThreads = globalThreadCount()); + + + //----------- + // Destructor + //----------- + + virtual ~RgbaOutputFile (); + + + //------------------------------------------------ + // Define a frame buffer as the pixel data source: + // Pixel (x, y) is at address + // + // base + x * xStride + y * yStride + // + //------------------------------------------------ + + void setFrameBuffer (const Rgba *base, + size_t xStride, + size_t yStride); + + + //--------------------------------------------- + // Write pixel data (see class Imf::OutputFile) + //--------------------------------------------- + + void writePixels (int numScanLines = 1); + int currentScanLine () const; + + + //-------------------------- + // Access to the file header + //-------------------------- + + const Header & header () const; + const FrameBuffer & frameBuffer () const; + const IMATH_NAMESPACE::Box2i & displayWindow () const; + const IMATH_NAMESPACE::Box2i & dataWindow () const; + float pixelAspectRatio () const; + const IMATH_NAMESPACE::V2f screenWindowCenter () const; + float screenWindowWidth () const; + LineOrder lineOrder () const; + Compression compression () const; + RgbaChannels channels () const; + + + // -------------------------------------------------------------------- + // Update the preview image (see Imf::OutputFile::updatePreviewImage()) + // -------------------------------------------------------------------- + + void updatePreviewImage (const PreviewRgba[]); + + + //----------------------------------------------------------------------- + // Rounding control for luminance/chroma images: + // + // If the output file contains luminance and chroma channels (WRITE_YC + // or WRITE_YCA), then the the significands of the luminance and + // chroma values are rounded to roundY and roundC bits respectively (see + // function half::round()). Rounding improves compression with minimal + // image degradation, usually much less than the degradation caused by + // chroma subsampling. By default, roundY is 7, and roundC is 5. + // + // If the output file contains RGB channels or a luminance channel, + // without chroma, then no rounding is performed. + //----------------------------------------------------------------------- + + void setYCRounding (unsigned int roundY, + unsigned int roundC); + + + //---------------------------------------------------- + // Break a scan line -- for testing and debugging only + // (see Imf::OutputFile::updatePreviewImage() + // + // Warning: Calling this function usually results in a + // broken image file. The file or parts of it may not + // be readable, or the file may contain bad data. + // + //---------------------------------------------------- + + void breakScanLine (int y, + int offset, + int length, + char c); + private: + + RgbaOutputFile (const RgbaOutputFile &); // not implemented + RgbaOutputFile & operator = (const RgbaOutputFile &); // not implemented + + class ToYca; + + OutputFile * _outputFile; + ToYca * _toYca; +}; + + +// +// RGBA input file +// + +class IMF_EXPORT RgbaInputFile +{ + public: + + //------------------------------------------------------- + // Constructor -- opens the file with the specified name, + // destructor will automatically close the file. + //------------------------------------------------------- + + RgbaInputFile (const char name[], int numThreads = globalThreadCount()); + + + //----------------------------------------------------------- + // Constructor -- attaches the new RgbaInputFile object to a + // file that has already been opened by the caller. + // Destroying the RgbaInputFile object will not automatically + // close the file. + //----------------------------------------------------------- + + RgbaInputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is, int numThreads = globalThreadCount()); + + + //-------------------------------------------------------------- + // Constructors -- the same as the previous two, but the names + // of the red, green, blue, alpha, luminance and chroma channels + // are expected to be layerName.R, layerName.G, etc. + //-------------------------------------------------------------- + + RgbaInputFile (const char name[], + const std::string &layerName, + int numThreads = globalThreadCount()); + + RgbaInputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is, + const std::string &layerName, + int numThreads = globalThreadCount()); + + + //----------- + // Destructor + //----------- + + virtual ~RgbaInputFile (); + + + //----------------------------------------------------- + // Define a frame buffer as the pixel data destination: + // Pixel (x, y) is at address + // + // base + x * xStride + y * yStride + // + //----------------------------------------------------- + + void setFrameBuffer (Rgba *base, + size_t xStride, + size_t yStride); + + + //---------------------------------------------------------------- + // Switch to a different layer -- subsequent calls to readPixels() + // will read channels layerName.R, layerName.G, etc. + // After each call to setLayerName(), setFrameBuffer() must be + // called at least once before the next call to readPixels(). + //---------------------------------------------------------------- + + void setLayerName (const std::string &layerName); + + + //------------------------------------------- + // Read pixel data (see class Imf::InputFile) + //------------------------------------------- + + void readPixels (int scanLine1, int scanLine2); + void readPixels (int scanLine); + + + //-------------------------- + // Access to the file header + //-------------------------- + + const Header & header () const; + const FrameBuffer & frameBuffer () const; + const IMATH_NAMESPACE::Box2i & displayWindow () const; + const IMATH_NAMESPACE::Box2i & dataWindow () const; + float pixelAspectRatio () const; + const IMATH_NAMESPACE::V2f screenWindowCenter () const; + float screenWindowWidth () const; + LineOrder lineOrder () const; + Compression compression () const; + RgbaChannels channels () const; + const char * fileName () const; + bool isComplete () const; + + + //---------------------------------- + // Access to the file format version + //---------------------------------- + + int version () const; + + private: + + RgbaInputFile (const RgbaInputFile &); // not implemented + RgbaInputFile & operator = (const RgbaInputFile &); // not implemented + + class FromYca; + + InputFile * _inputFile; + FromYca * _fromYca; + std::string _channelNamePrefix; +}; + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + + + + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfRgbaYca.h b/OpenEXR/include/OpenEXR/ImfRgbaYca.h new file mode 100644 index 0000000..c4c6775 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfRgbaYca.h @@ -0,0 +1,259 @@ +#ifndef INCLUDED_IMF_RGBA_YCA_H +#define INCLUDED_IMF_RGBA_YCA_H + +////////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2004, Industrial Light & Magic, a division of Lucasfilm +// Entertainment Company Ltd. Portions contributed and copyright held by +// others as indicated. 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 +// any other contributors to this software 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. +// +////////////////////////////////////////////////////////////////////////////// + +//----------------------------------------------------------------------------- +// +// Conversion between RGBA (red, green, blue alpha) +// and YCA (luminance, subsampled chroma, alpha) data: +// +// Luminance, Y, is computed as a weighted sum of R, G, and B: +// +// Y = yw.x * R + yw.y * G + yw.z * B +// +// Function computeYw() computes a set of RGB-to-Y weights, yw, +// from a set of primary and white point chromaticities. +// +// Chroma, C, consists of two components, RY and BY: +// +// RY = (R - Y) / Y +// BY = (B - Y) / Y +// +// For efficiency, the x and y subsampling rates for chroma are +// hardwired to 2, and the chroma subsampling and reconstruction +// filters are fixed 27-pixel wide windowed sinc functions. +// +// Starting with an image that has RGBA data for all pixels, +// +// RGBA RGBA RGBA RGBA ... RGBA RGBA +// RGBA RGBA RGBA RGBA ... RGBA RGBA +// RGBA RGBA RGBA RGBA ... RGBA RGBA +// RGBA RGBA RGBA RGBA ... RGBA RGBA +// ... +// RGBA RGBA RGBA RGBA ... RGBA RGBA +// RGBA RGBA RGBA RGBA ... RGBA RGBA +// +// function RGBAtoYCA() converts the pixels to YCA format: +// +// YCA YCA YCA YCA ... YCA YCA +// YCA YCA YCA YCA ... YCA YCA +// YCA YCA YCA YCA ... YCA YCA +// YCA YCA YCA YCA ... YCA YCA +// ... +// YCA YCA YCA YCA ... YCA YCA +// YCA YCA YCA YCA ... YCA YCA +// +// Next, decimateChomaHoriz() eliminates the chroma values from +// the odd-numbered pixels in every scan line: +// +// YCA YA YCA YA ... YCA YA +// YCA YA YCA YA ... YCA YA +// YCA YA YCA YA ... YCA YA +// YCA YA YCA YA ... YCA YA +// ... +// YCA YA YCA YA ... YCA YA +// YCA YA YCA YA ... YCA YA +// +// decimateChromaVert() eliminates all chroma values from the +// odd-numbered scan lines: +// +// YCA YA YCA YA ... YCA YA +// YA YA YA YA ... YA YA +// YCA YA YCA YA ... YCA YA +// YA YA YA YA ... YA YA +// ... +// YCA YA YCA YA ... YCA YA +// YA YA YA YA ... YA YA +// +// Finally, roundYCA() reduces the precision of the luminance +// and chroma values so that the pixel data shrink more when +// they are saved in a compressed file. +// +// The output of roundYCA() can be converted back to a set +// of RGBA pixel data that is visually very similar to the +// original RGBA image, by calling reconstructChromaHoriz(), +// reconstructChromaVert(), YCAtoRGBA(), and finally +// fixSaturation(). +// +//----------------------------------------------------------------------------- + +#include "ImfRgba.h" +#include "ImfChromaticities.h" +#include "ImfNamespace.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + +namespace RgbaYca { + + +// +// Width of the chroma subsampling and reconstruction filters +// + +static const int N = 27; +static const int N2 = N / 2; + + +// +// Convert a set of primary chromaticities into a set of weighting +// factors for computing a pixels's luminance, Y, from R, G and B +// + +IMF_EXPORT +IMATH_NAMESPACE::V3f computeYw (const Chromaticities &cr); + + +// +// Convert an array of n RGBA pixels, rgbaIn, to YCA (luminance/chroma/alpha): +// +// ycaOut[i].g = Y (rgbaIn[i]); +// ycaOut[i].r = RY (rgbaIn[i]); +// ycaOut[i].b = BY (rgbaIn[i]); +// ycaOut[i].a = aIsValid? rgbaIn[i].a: 1 +// +// yw is a set of RGB-to-Y weighting factors, as computed by computeYw(). +// + +IMF_EXPORT +void RGBAtoYCA (const IMATH_NAMESPACE::V3f &yw, + int n, + bool aIsValid, + const Rgba rgbaIn[/*n*/], + Rgba ycaOut[/*n*/]); + +// +// Perform horizontal low-pass filtering and subsampling of +// the chroma channels of an array of n pixels. In order +// to avoid indexing off the ends of the input array during +// low-pass filtering, ycaIn must have N2 extra pixels at +// both ends. Before calling decimateChromaHoriz(), the extra +// pixels should be filled with copies of the first and last +// "real" input pixel. +// + +IMF_EXPORT +void decimateChromaHoriz (int n, + const Rgba ycaIn[/*n+N-1*/], + Rgba ycaOut[/*n*/]); + +// +// Perform vertical chroma channel low-pass filtering and subsampling. +// N scan lines of input pixels are combined into a single scan line +// of output pixels. +// + +IMF_EXPORT +void decimateChromaVert (int n, + const Rgba * const ycaIn[N], + Rgba ycaOut[/*n*/]); + +// +// Round the luminance and chroma channels of an array of YCA +// pixels that has already been filtered and subsampled. +// The signifcands of the pixels' luminance and chroma values +// are rounded to roundY and roundC bits respectively. +// + +IMF_EXPORT +void roundYCA (int n, + unsigned int roundY, + unsigned int roundC, + const Rgba ycaIn[/*n*/], + Rgba ycaOut[/*n*/]); + +// +// For a scan line that has valid chroma data only for every other pixel, +// reconstruct the missing chroma values. +// + +IMF_EXPORT +void reconstructChromaHoriz (int n, + const Rgba ycaIn[/*n+N-1*/], + Rgba ycaOut[/*n*/]); + +// +// For a scan line that has only luminance and no valid chroma data, +// reconstruct chroma from the surronding N scan lines. +// + +IMF_EXPORT +void reconstructChromaVert (int n, + const Rgba * const ycaIn[N], + Rgba ycaOut[/*n*/]); + +// +// Convert an array of n YCA (luminance/chroma/alpha) pixels to RGBA. +// This function is the inverse of RGBAtoYCA(). +// yw is a set of RGB-to-Y weighting factors, as computed by computeYw(). +// + +IMF_EXPORT +void YCAtoRGBA (const IMATH_NAMESPACE::V3f &yw, + int n, + const Rgba ycaIn[/*n*/], + Rgba rgbaOut[/*n*/]); + +// +// Eliminate super-saturated pixels: +// +// Converting an image from RGBA to YCA, low-pass filtering chroma, +// and converting the result back to RGBA can produce pixels with +// super-saturated colors, where one or two of the RGB components +// become zero or negative. (The low-pass and reconstruction filters +// introduce some amount of ringing into the chroma components. +// This can lead to negative RGB values near high-contrast edges.) +// +// The fixSaturation() function finds super-saturated pixels and +// corrects them by desaturating their colors while maintaining +// their luminance. fixSaturation() takes three adjacent input +// scan lines, rgbaIn[0], rgbaIn[1], rgbaIn[2], adjusts the +// saturation of rgbaIn[1], and stores the result in rgbaOut. +// + +IMF_EXPORT +void fixSaturation (const IMATH_NAMESPACE::V3f &yw, + int n, + const Rgba * const rgbaIn[3], + Rgba rgbaOut[/*n*/]); + +} // namespace RgbaYca +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfStandardAttributes.h b/OpenEXR/include/OpenEXR/ImfStandardAttributes.h new file mode 100644 index 0000000..4280ac4 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfStandardAttributes.h @@ -0,0 +1,382 @@ +/////////////////////////////////////////////////////////////////////////// +// +// 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_STANDARD_ATTRIBUTES_H +#define INCLUDED_IMF_STANDARD_ATTRIBUTES_H + +//----------------------------------------------------------------------------- +// +// Optional Standard Attributes -- these attributes are "optional" +// because not every image file header has them, but they define a +// "standard" way to represent commonly used data in the file header. +// +// For each attribute, with name "foo", and type "T", the following +// functions are automatically generated via macros: +// +// void addFoo (Header &header, const T &value); +// bool hasFoo (const Header &header); +// const TypedAttribute & fooAttribute (const Header &header); +// TypedAttribute & fooAttribute (Header &header); +// const T & foo (const Header &Header); +// T & foo (Header &Header); +// +//----------------------------------------------------------------------------- + +#include "ImfHeader.h" +#include "ImfBoxAttribute.h" +#include "ImfChromaticitiesAttribute.h" +#include "ImfEnvmapAttribute.h" +#include "ImfDeepImageStateAttribute.h" +#include "ImfFloatAttribute.h" +#include "ImfKeyCodeAttribute.h" +#include "ImfMatrixAttribute.h" +#include "ImfRationalAttribute.h" +#include "ImfStringAttribute.h" +#include "ImfStringVectorAttribute.h" +#include "ImfTimeCodeAttribute.h" +#include "ImfVecAttribute.h" +#include "ImfNamespace.h" +#include "ImfExport.h" + +#define IMF_STD_ATTRIBUTE_DEF(name,suffix,object) \ + \ + OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER \ + IMF_EXPORT void add##suffix (Header &header, const object &v); \ + IMF_EXPORT bool has##suffix (const Header &header); \ + IMF_EXPORT const TypedAttribute & \ + name##Attribute (const Header &header); \ + IMF_EXPORT TypedAttribute & \ + name##Attribute (Header &header); \ + IMF_EXPORT const object & \ + name (const Header &header); \ + IMF_EXPORT object & name (Header &header); \ + OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT \ + +// +// chromaticities -- for RGB images, specifies the CIE (x,y) +// chromaticities of the primaries and the white point +// + +IMF_STD_ATTRIBUTE_DEF (chromaticities, Chromaticities, Chromaticities) + + +// +// whiteLuminance -- for RGB images, defines the luminance, in Nits +// (candelas per square meter) of the RGB value (1.0, 1.0, 1.0). +// +// If the chromaticities and the whiteLuminance of an RGB image are +// known, then it is possible to convert the image's pixels from RGB +// to CIE XYZ tristimulus values (see function RGBtoXYZ() in header +// file ImfChromaticities.h). +// +// + +IMF_STD_ATTRIBUTE_DEF (whiteLuminance, WhiteLuminance, float) + + +// +// adoptedNeutral -- specifies the CIE (x,y) coordinates that should +// be considered neutral during color rendering. Pixels in the image +// file whose (x,y) coordinates match the adoptedNeutral value should +// be mapped to neutral values on the display. +// + +IMF_STD_ATTRIBUTE_DEF (adoptedNeutral, AdoptedNeutral, IMATH_NAMESPACE::V2f) + + +// +// renderingTransform, lookModTransform -- specify the names of the +// CTL functions that implements the intended color rendering and look +// modification transforms for this image. +// + +IMF_STD_ATTRIBUTE_DEF (renderingTransform, RenderingTransform, std::string) +IMF_STD_ATTRIBUTE_DEF (lookModTransform, LookModTransform, std::string) + + +// +// xDensity -- horizontal output density, in pixels per inch. +// The image's vertical output density is xDensity * pixelAspectRatio. +// + +IMF_STD_ATTRIBUTE_DEF (xDensity, XDensity, float) + + +// +// owner -- name of the owner of the image +// + +IMF_STD_ATTRIBUTE_DEF (owner, Owner, std::string) + + +// +// comments -- additional image information in human-readable +// form, for example a verbal description of the image +// + +IMF_STD_ATTRIBUTE_DEF (comments, Comments, std::string) + + +// +// capDate -- the date when the image was created or captured, +// in local time, and formatted as +// +// YYYY:MM:DD hh:mm:ss +// +// where YYYY is the year (4 digits, e.g. 2003), MM is the month +// (2 digits, 01, 02, ... 12), DD is the day of the month (2 digits, +// 01, 02, ... 31), hh is the hour (2 digits, 00, 01, ... 23), mm +// is the minute, and ss is the second (2 digits, 00, 01, ... 59). +// +// + +IMF_STD_ATTRIBUTE_DEF (capDate, CapDate, std::string) + + +// +// utcOffset -- offset of local time at capDate from +// Universal Coordinated Time (UTC), in seconds: +// +// UTC == local time + utcOffset +// + +IMF_STD_ATTRIBUTE_DEF (utcOffset, UtcOffset, float) + + +// +// longitude, latitude, altitude -- for images of real objects, the +// location where the image was recorded. Longitude and latitude are +// in degrees east of Greenwich and north of the equator. Altitude +// is in meters above sea level. For example, Kathmandu, Nepal is +// at longitude 85.317, latitude 27.717, altitude 1305. +// + +IMF_STD_ATTRIBUTE_DEF (longitude, Longitude, float) +IMF_STD_ATTRIBUTE_DEF (latitude, Latitude, float) +IMF_STD_ATTRIBUTE_DEF (altitude, Altitude, float) + + +// +// focus -- the camera's focus distance, in meters +// + +IMF_STD_ATTRIBUTE_DEF (focus, Focus, float) + + +// +// exposure -- exposure time, in seconds +// + +IMF_STD_ATTRIBUTE_DEF (expTime, ExpTime, float) + + +// +// aperture -- the camera's lens aperture, in f-stops (focal length +// of the lens divided by the diameter of the iris opening) +// + +IMF_STD_ATTRIBUTE_DEF (aperture, Aperture, float) + + +// +// isoSpeed -- the ISO speed of the film or image sensor +// that was used to record the image +// + +IMF_STD_ATTRIBUTE_DEF (isoSpeed, IsoSpeed, float) + + +// +// envmap -- if this attribute is present, the image represents +// an environment map. The attribute's value defines how 3D +// directions are mapped to 2D pixel locations. For details +// see header file ImfEnvmap.h +// + +IMF_STD_ATTRIBUTE_DEF (envmap, Envmap, Envmap) + + +// +// keyCode -- for motion picture film frames. Identifies film +// manufacturer, film type, film roll and frame position within +// the roll. +// + +IMF_STD_ATTRIBUTE_DEF (keyCode, KeyCode, KeyCode) + + +// +// timeCode -- time and control code +// + +IMF_STD_ATTRIBUTE_DEF (timeCode, TimeCode, TimeCode) + + +// +// wrapmodes -- determines how texture map images are extrapolated. +// If an OpenEXR file is used as a texture map for 3D rendering, +// texture coordinates (0.0, 0.0) and (1.0, 1.0) correspond to +// the upper left and lower right corners of the data window. +// If the image is mapped onto a surface with texture coordinates +// outside the zero-to-one range, then the image must be extrapolated. +// This attribute tells the renderer how to do this extrapolation. +// The attribute contains either a pair of comma-separated keywords, +// to specify separate extrapolation modes for the horizontal and +// vertical directions; or a single keyword, to specify extrapolation +// in both directions (e.g. "clamp,periodic" or "clamp"). Extra white +// space surrounding the keywords is allowed, but should be ignored +// by the renderer ("clamp, black " is equivalent to "clamp,black"). +// The keywords listed below are predefined; some renderers may support +// additional extrapolation modes: +// +// black pixels outside the zero-to-one range are black +// +// clamp texture coordinates less than 0.0 and greater +// than 1.0 are clamped to 0.0 and 1.0 respectively +// +// periodic the texture image repeats periodically +// +// mirror the texture image repeats periodically, but +// every other instance is mirrored +// + +IMF_STD_ATTRIBUTE_DEF (wrapmodes, Wrapmodes, std::string) + + +// +// framesPerSecond -- defines the nominal playback frame rate for image +// sequences, in frames per second. Every image in a sequence should +// have a framesPerSecond attribute, and the attribute value should be +// the same for all images in the sequence. If an image sequence has +// no framesPerSecond attribute, playback software should assume that +// the frame rate for the sequence is 24 frames per second. +// +// In order to allow exact representation of NTSC frame and field rates, +// framesPerSecond is stored as a rational number. A rational number is +// a pair of integers, n and d, that represents the value n/d. +// +// For the exact values of commonly used frame rates, please see header +// file ImfFramesPerSecond.h. +// + +IMF_STD_ATTRIBUTE_DEF (framesPerSecond, FramesPerSecond, Rational) + + +// +// multiView -- defines the view names for multi-view image files. +// A multi-view image contains two or more views of the same scene, +// as seen from different viewpoints, for example a left-eye and +// a right-eye view for stereo displays. The multiView attribute +// lists the names of the views in an image, and a naming convention +// identifies the channels that belong to each view. +// +// For details, please see header file ImfMultiView.h +// + +IMF_STD_ATTRIBUTE_DEF (multiView , MultiView, StringVector) + + +// +// worldToCamera -- for images generated by 3D computer graphics rendering, +// a matrix that transforms 3D points from the world to the camera coordinate +// space of the renderer. +// +// The camera coordinate space is left-handed. Its origin indicates the +// location of the camera. The positive x and y axes correspond to the +// "right" and "up" directions in the rendered image. The positive z +// axis indicates the camera's viewing direction. (Objects in front of +// the camera have positive z coordinates.) +// +// Camera coordinate space in OpenEXR is the same as in Pixar's Renderman. +// + +IMF_STD_ATTRIBUTE_DEF (worldToCamera, WorldToCamera, IMATH_NAMESPACE::M44f) + + +// +// worldToNDC -- for images generated by 3D computer graphics rendering, a +// matrix that transforms 3D points from the world to the Normalized Device +// Coordinate (NDC) space of the renderer. +// +// NDC is a 2D coordinate space that corresponds to the image plane, with +// positive x and pointing to the right and y positive pointing down. The +// coordinates (0, 0) and (1, 1) correspond to the upper left and lower right +// corners of the OpenEXR display window. +// +// To transform a 3D point in word space into a 2D point in NDC space, +// multiply the 3D point by the worldToNDC matrix and discard the z +// coordinate. +// +// NDC space in OpenEXR is the same as in Pixar's Renderman. +// + +IMF_STD_ATTRIBUTE_DEF (worldToNDC, WorldToNDC, IMATH_NAMESPACE::M44f) + + +// +// deepImageState -- specifies whether the pixels in a deep image are +// sorted and non-overlapping. +// +// Note: this attribute can be set by application code that writes a file +// in order to tell applications that read the file whether the pixel data +// must be cleaned up prior to image processing operations such as flattening. +// The IlmImf library does not verify that the attribute is consistent with +// the actual state of the pixels. Application software may assume that the +// attribute is valid, as long as the software will not crash or lock up if +// any pixels are inconsistent with the deepImageState attribute. +// + +IMF_STD_ATTRIBUTE_DEF (deepImageState, DeepImageState, DeepImageState) + + +// +// originalDataWindow -- if application software crops an image, then it +// should save the data window of the original, un-cropped image in the +// originalDataWindow attribute. +// + +IMF_STD_ATTRIBUTE_DEF + (originalDataWindow, OriginalDataWindow, IMATH_NAMESPACE::Box2i) + + +// +// dwaCompressionLevel -- sets the quality level for images compressed +// with the DWAA or DWAB method. +// + +IMF_STD_ATTRIBUTE_DEF (dwaCompressionLevel, DwaCompressionLevel, float) + + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfStringAttribute.h b/OpenEXR/include/OpenEXR/ImfStringAttribute.h new file mode 100644 index 0000000..f5d62d7 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfStringAttribute.h @@ -0,0 +1,71 @@ +/////////////////////////////////////////////////////////////////////////// +// +// 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMF_STRING_ATTRIBUTE_H +#define INCLUDED_IMF_STRING_ATTRIBUTE_H + +//----------------------------------------------------------------------------- +// +// class StringAttribute +// +//----------------------------------------------------------------------------- + +#include "ImfAttribute.h" +#include + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +typedef TypedAttribute StringAttribute; + +template <> +IMF_EXPORT +const char *StringAttribute::staticTypeName (); + +template <> +IMF_EXPORT +void StringAttribute::writeValueTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &, + int) const; + +template <> +IMF_EXPORT +void StringAttribute::readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &, + int, int); + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfStringVectorAttribute.h b/OpenEXR/include/OpenEXR/ImfStringVectorAttribute.h new file mode 100644 index 0000000..d13ef96 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfStringVectorAttribute.h @@ -0,0 +1,74 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2007, Weta Digital Ltd +// +// 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 Weta Digital 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMF_STRINGVECTOR_ATTRIBUTE_H +#define INCLUDED_IMF_STRINGVECTOR_ATTRIBUTE_H + +//----------------------------------------------------------------------------- +// +// class StringVectorAttribute +// +//----------------------------------------------------------------------------- + +#include "ImfAttribute.h" +#include "ImfNamespace.h" + +#include +#include + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + +typedef std::vector StringVector; +typedef TypedAttribute StringVectorAttribute; + +template <> +IMF_EXPORT +const char *StringVectorAttribute::staticTypeName (); + +template <> +IMF_EXPORT +void StringVectorAttribute::writeValueTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &, + int) const; + +template <> +IMF_EXPORT +void StringVectorAttribute::readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &, + int, int); + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfTestFile.h b/OpenEXR/include/OpenEXR/ImfTestFile.h new file mode 100644 index 0000000..d02d3bc --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfTestFile.h @@ -0,0 +1,97 @@ +/////////////////////////////////////////////////////////////////////////// +// +// 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_TEST_FILE_H +#define INCLUDED_IMF_TEST_FILE_H + +//----------------------------------------------------------------------------- +// +// Utility routines to test quickly if a given +// file is an OpenEXR file, and whether the +// file is scanline-based or tiled. +// +//----------------------------------------------------------------------------- + +#include "ImfForward.h" +#include "ImfExport.h" +#include "ImfNamespace.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +IMF_EXPORT bool isOpenExrFile (const char fileName[]); + +IMF_EXPORT bool isOpenExrFile (const char fileName[], + bool &isTiled); + +IMF_EXPORT bool isOpenExrFile (const char fileName[], + bool &isTiled, + bool &isDeep); + +IMF_EXPORT bool isOpenExrFile (const char fileName[], + bool &isTiled, + bool &isDeep, + bool &isMultiPart); + +IMF_EXPORT bool isTiledOpenExrFile (const char fileName[]); + +IMF_EXPORT bool isDeepOpenExrFile (const char fileName[]); + +IMF_EXPORT bool isMultiPartOpenExrFile (const char fileName[]); + +IMF_EXPORT bool isOpenExrFile (IStream &is); + +IMF_EXPORT bool isOpenExrFile (IStream &is, + bool &isTiled); + +IMF_EXPORT bool isOpenExrFile (IStream &is, + bool &isTiled, + bool &isDeep); + +IMF_EXPORT bool isOpenExrFile (IStream &is, + bool &isTiled, + bool &isDeep, + bool &isMultiPart); + +IMF_EXPORT bool isTiledOpenExrFile (IStream &is); + +IMF_EXPORT bool isDeepOpenExrFile (IStream &is); + +IMF_EXPORT bool isMultiPartOpenExrFile (IStream &is); + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfThreading.h b/OpenEXR/include/OpenEXR/ImfThreading.h new file mode 100644 index 0000000..4d1db04 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfThreading.h @@ -0,0 +1,95 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2005, 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. +// +/////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDED_IMF_THREADING_H +#define INCLUDED_IMF_THREADING_H + +#include "ImfExport.h" +#include "ImfNamespace.h" + +//----------------------------------------------------------------------------- +// +// Threading support for the IlmImf library +// +// The IlmImf library uses threads to perform reading and writing +// of OpenEXR files in parallel. The thread that calls the library +// always performs the actual file IO (this is usually the main +// application thread) whereas a several worker threads perform +// data compression and decompression. The number of worker +// threads can be any non-negative value (a value of zero reverts +// to single-threaded operation). As long as there is at least +// one worker thread, file IO and compression can potentially be +// done concurrently through pinelining. If there are two or more +// worker threads, then pipelining as well as concurrent compression +// of multiple blocks can be performed. +// +// Threading in the Imf library is controllable at two granularities: +// +// * The functions in this file query and control the total number +// of worker threads, which will be created globally for the whole +// library. Regardless of how many input or output files are +// opened simultaneously, the library will use at most this number +// of worker threads to perform all work. The default number of +// global worker threads is zero (i.e. single-threaded operation; +// everything happens in the thread that calls the library). +// +// * Furthermore, it is possible to set the number of threads that +// each input or output file should keep busy. This number can +// be explicitly set for each file. The default behavior is for +// each file to try to occupy all worker threads in the library's +// thread pool. +// +//----------------------------------------------------------------------------- + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +//----------------------------------------------------------------------------- +// Return the number of Imf-global worker threads used for parallel +// compression and decompression of OpenEXR files. +//----------------------------------------------------------------------------- + +IMF_EXPORT int globalThreadCount (); + + +//----------------------------------------------------------------------------- +// Change the number of Imf-global worker threads +//----------------------------------------------------------------------------- + +IMF_EXPORT void setGlobalThreadCount (int count); + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfTileDescription.h b/OpenEXR/include/OpenEXR/ImfTileDescription.h new file mode 100644 index 0000000..7b219c8 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfTileDescription.h @@ -0,0 +1,107 @@ +/////////////////////////////////////////////////////////////////////////// +// +// 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_TILE_DESCRIPTION_H +#define INCLUDED_IMF_TILE_DESCRIPTION_H + +//----------------------------------------------------------------------------- +// +// class TileDescription and enum LevelMode +// +//----------------------------------------------------------------------------- +#include "ImfNamespace.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +enum LevelMode +{ + ONE_LEVEL = 0, + MIPMAP_LEVELS = 1, + RIPMAP_LEVELS = 2, + + NUM_LEVELMODES // number of different level modes +}; + + +enum LevelRoundingMode +{ + ROUND_DOWN = 0, + ROUND_UP = 1, + + NUM_ROUNDINGMODES // number of different rounding modes +}; + + +class TileDescription +{ + public: + + unsigned int xSize; // size of a tile in the x dimension + unsigned int ySize; // size of a tile in the y dimension + LevelMode mode; + LevelRoundingMode roundingMode; + + TileDescription (unsigned int xs = 32, + unsigned int ys = 32, + LevelMode m = ONE_LEVEL, + LevelRoundingMode r = ROUND_DOWN) + : + xSize (xs), + ySize (ys), + mode (m), + roundingMode (r) + { + // empty + } + + bool + operator == (const TileDescription &other) const + { + return xSize == other.xSize && + ySize == other.ySize && + mode == other.mode && + roundingMode == other.roundingMode; + } +}; + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + + + + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfTileDescriptionAttribute.h b/OpenEXR/include/OpenEXR/ImfTileDescriptionAttribute.h new file mode 100644 index 0000000..a8b69b9 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfTileDescriptionAttribute.h @@ -0,0 +1,72 @@ +/////////////////////////////////////////////////////////////////////////// +// +// 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_TILE_DESCRIPTION_ATTRIBUTE_H +#define INCLUDED_IMF_TILE_DESCRIPTION_ATTRIBUTE_H + +//----------------------------------------------------------------------------- +// +// class TileDescriptionAttribute +// +//----------------------------------------------------------------------------- + +#include "ImfAttribute.h" +#include "ImfTileDescription.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + +typedef TypedAttribute TileDescriptionAttribute; + +template <> +IMF_EXPORT +const char * +TileDescriptionAttribute::staticTypeName (); + +template <> +IMF_EXPORT +void +TileDescriptionAttribute::writeValueTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &, + int) const; + +template <> +IMF_EXPORT +void +TileDescriptionAttribute::readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &, + int, int); + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfTiledInputFile.h b/OpenEXR/include/OpenEXR/ImfTiledInputFile.h new file mode 100644 index 0000000..108ec7a --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfTiledInputFile.h @@ -0,0 +1,401 @@ +/////////////////////////////////////////////////////////////////////////// +// +// 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_TILED_INPUT_FILE_H +#define INCLUDED_IMF_TILED_INPUT_FILE_H + +//----------------------------------------------------------------------------- +// +// class TiledInputFile +// +//----------------------------------------------------------------------------- + +#include "ImfHeader.h" +#include "ImfFrameBuffer.h" +#include "ImathBox.h" +#include "ImfTileDescription.h" +#include "ImfThreading.h" +#include "ImfGenericInputFile.h" +#include "ImfTiledOutputFile.h" +#include "ImfNamespace.h" +#include "ImfExport.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +class IMF_EXPORT TiledInputFile : public GenericInputFile +{ + public: + + //-------------------------------------------------------------------- + // A constructor that opens the file with the specified name, and + // reads the file header. The constructor throws an IEX_NAMESPACE::ArgExc + // exception if the file is not tiled. + // The numThreads parameter specifies how many worker threads this + // file will try to keep busy when decompressing individual tiles. + // Destroying TiledInputFile objects constructed with this constructor + // automatically closes the corresponding files. + //-------------------------------------------------------------------- + + TiledInputFile (const char fileName[], + int numThreads = globalThreadCount ()); + + + // ---------------------------------------------------------- + // A constructor that attaches the new TiledInputFile object + // to a file that has already been opened. + // Destroying TiledInputFile objects constructed with this + // constructor does not automatically close the corresponding + // files. + // ---------------------------------------------------------- + + TiledInputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is, int numThreads = globalThreadCount ()); + + + //----------- + // Destructor + //----------- + + virtual ~TiledInputFile (); + + + //------------------------ + // Access to the file name + //------------------------ + + const char * fileName () const; + + + //-------------------------- + // Access to the file header + //-------------------------- + + const Header & header () const; + + + //---------------------------------- + // Access to the file format version + //---------------------------------- + + int version () const; + + + //----------------------------------------------------------- + // Set the current frame buffer -- copies the FrameBuffer + // object into the TiledInputFile object. + // + // The current frame buffer is the destination for the pixel + // data read from the file. The current frame buffer must be + // set at least once before readTile() is called. + // The current frame buffer can be changed after each call + // to readTile(). + //----------------------------------------------------------- + + void setFrameBuffer (const FrameBuffer &frameBuffer); + + + //----------------------------------- + // Access to the current frame buffer + //----------------------------------- + + const FrameBuffer & frameBuffer () const; + + + //------------------------------------------------------------ + // Check if the file is complete: + // + // isComplete() returns true if all pixels in the data window + // (in all levels) are present in the input file, or false if + // any pixels are missing. (Another program may still be busy + // writing the file, or file writing may have been aborted + // prematurely.) + //------------------------------------------------------------ + + bool isComplete () const; + + + //-------------------------------------------------- + // Utility functions: + //-------------------------------------------------- + + //--------------------------------------------------------- + // Multiresolution mode and tile size: + // The following functions return the xSize, ySize and mode + // fields of the file header's TileDescriptionAttribute. + //--------------------------------------------------------- + + unsigned int tileXSize () const; + unsigned int tileYSize () const; + LevelMode levelMode () const; + LevelRoundingMode levelRoundingMode () const; + + + //-------------------------------------------------------------------- + // Number of levels: + // + // numXLevels() returns the file's number of levels in x direction. + // + // if levelMode() == ONE_LEVEL: + // return value is: 1 + // + // if levelMode() == MIPMAP_LEVELS: + // return value is: rfunc (log (max (w, h)) / log (2)) + 1 + // + // if levelMode() == RIPMAP_LEVELS: + // return value is: rfunc (log (w) / log (2)) + 1 + // + // where + // w is the width of the image's data window, max.x - min.x + 1, + // y is the height of the image's data window, max.y - min.y + 1, + // and rfunc(x) is either floor(x), or ceil(x), depending on + // whether levelRoundingMode() returns ROUND_DOWN or ROUND_UP. + // + // numYLevels() returns the file's number of levels in y direction. + // + // if levelMode() == ONE_LEVEL or levelMode() == MIPMAP_LEVELS: + // return value is the same as for numXLevels() + // + // if levelMode() == RIPMAP_LEVELS: + // return value is: rfunc (log (h) / log (2)) + 1 + // + // + // numLevels() is a convenience function for use with + // MIPMAP_LEVELS files. + // + // if levelMode() == ONE_LEVEL or levelMode() == MIPMAP_LEVELS: + // return value is the same as for numXLevels() + // + // if levelMode() == RIPMAP_LEVELS: + // an IEX_NAMESPACE::LogicExc exception is thrown + // + // isValidLevel(lx, ly) returns true if the file contains + // a level with level number (lx, ly), false if not. + // + //-------------------------------------------------------------------- + + int numLevels () const; + int numXLevels () const; + int numYLevels () const; + bool isValidLevel (int lx, int ly) const; + + + //---------------------------------------------------------- + // Dimensions of a level: + // + // levelWidth(lx) returns the width of a level with level + // number (lx, *), where * is any number. + // + // return value is: + // max (1, rfunc (w / pow (2, lx))) + // + // + // levelHeight(ly) returns the height of a level with level + // number (*, ly), where * is any number. + // + // return value is: + // max (1, rfunc (h / pow (2, ly))) + // + //---------------------------------------------------------- + + int levelWidth (int lx) const; + int levelHeight (int ly) const; + + + //-------------------------------------------------------------- + // Number of tiles: + // + // numXTiles(lx) returns the number of tiles in x direction + // that cover a level with level number (lx, *), where * is + // any number. + // + // return value is: + // (levelWidth(lx) + tileXSize() - 1) / tileXSize() + // + // + // numYTiles(ly) returns the number of tiles in y direction + // that cover a level with level number (*, ly), where * is + // any number. + // + // return value is: + // (levelHeight(ly) + tileXSize() - 1) / tileXSize() + // + //-------------------------------------------------------------- + + int numXTiles (int lx = 0) const; + int numYTiles (int ly = 0) const; + + + //--------------------------------------------------------------- + // Level pixel ranges: + // + // dataWindowForLevel(lx, ly) returns a 2-dimensional region of + // valid pixel coordinates for a level with level number (lx, ly) + // + // return value is a Box2i with min value: + // (dataWindow.min.x, dataWindow.min.y) + // + // and max value: + // (dataWindow.min.x + levelWidth(lx) - 1, + // dataWindow.min.y + levelHeight(ly) - 1) + // + // dataWindowForLevel(level) is a convenience function used + // for ONE_LEVEL and MIPMAP_LEVELS files. It returns + // dataWindowForLevel(level, level). + // + //--------------------------------------------------------------- + + IMATH_NAMESPACE::Box2i dataWindowForLevel (int l = 0) const; + IMATH_NAMESPACE::Box2i dataWindowForLevel (int lx, int ly) const; + + + //------------------------------------------------------------------- + // Tile pixel ranges: + // + // dataWindowForTile(dx, dy, lx, ly) returns a 2-dimensional + // region of valid pixel coordinates for a tile with tile coordinates + // (dx,dy) and level number (lx, ly). + // + // return value is a Box2i with min value: + // (dataWindow.min.x + dx * tileXSize(), + // dataWindow.min.y + dy * tileYSize()) + // + // and max value: + // (dataWindow.min.x + (dx + 1) * tileXSize() - 1, + // dataWindow.min.y + (dy + 1) * tileYSize() - 1) + // + // dataWindowForTile(dx, dy, level) is a convenience function + // used for ONE_LEVEL and MIPMAP_LEVELS files. It returns + // dataWindowForTile(dx, dy, level, level). + // + //------------------------------------------------------------------- + + IMATH_NAMESPACE::Box2i dataWindowForTile (int dx, int dy, int l = 0) const; + + IMATH_NAMESPACE::Box2i dataWindowForTile (int dx, int dy, + int lx, int ly) const; + + //------------------------------------------------------------ + // Read pixel data: + // + // readTile(dx, dy, lx, ly) reads the tile with tile + // coordinates (dx, dy), and level number (lx, ly), + // and stores it in the current frame buffer. + // + // dx must lie in the interval [0, numXTiles(lx)-1] + // dy must lie in the interval [0, numYTiles(ly)-1] + // + // lx must lie in the interval [0, numXLevels()-1] + // ly must lie in the inverval [0, numYLevels()-1] + // + // readTile(dx, dy, level) is a convenience function used + // for ONE_LEVEL and MIPMAP_LEVELS files. It calls + // readTile(dx, dy, level, level). + // + // The two readTiles(dx1, dx2, dy1, dy2, ...) functions allow + // reading multiple tiles at once. If multi-threading is used + // the multiple tiles are read concurrently. + // + // Pixels that are outside the pixel coordinate range for the + // tile's level, are never accessed by readTile(). + // + // Attempting to access a tile that is not present in the file + // throws an InputExc exception. + // + //------------------------------------------------------------ + + void readTile (int dx, int dy, int l = 0); + void readTile (int dx, int dy, int lx, int ly); + + void readTiles (int dx1, int dx2, int dy1, int dy2, + int lx, int ly); + + void readTiles (int dx1, int dx2, int dy1, int dy2, + int l = 0); + + + //-------------------------------------------------- + // Read a tile of raw pixel data from the file, + // without uncompressing it (this function is + // used to implement TiledOutputFile::copyPixels()). + // + // for single part files, reads the next tile in the file + // for multipart files, reads the tile specified by dx,dy,lx,ly + // + //-------------------------------------------------- + + void rawTileData (int &dx, int &dy, + int &lx, int &ly, + const char *&pixelData, + int &pixelDataSize); + + struct Data; + + private: + + friend class InputFile; + friend class MultiPartInputFile; + + TiledInputFile (InputPartData* part); + + TiledInputFile (const TiledInputFile &); // not implemented + TiledInputFile & operator = (const TiledInputFile &); // not implemented + + TiledInputFile (const Header &header, OPENEXR_IMF_INTERNAL_NAMESPACE::IStream *is, int version, + int numThreads); + + void initialize (); + void multiPartInitialize(InputPartData* part); + void compatibilityInitialize(OPENEXR_IMF_INTERNAL_NAMESPACE::IStream& is); + + bool isValidTile (int dx, int dy, + int lx, int ly) const; + + size_t bytesPerLineForTile (int dx, int dy, + int lx, int ly) const; + + void tileOrder(int dx[],int dy[],int lx[],int ly[]) const; + Data * _data; + + friend void TiledOutputFile::copyPixels(TiledInputFile &); +}; + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + + + + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfTiledInputPart.h b/OpenEXR/include/OpenEXR/ImfTiledInputPart.h new file mode 100644 index 0000000..ea44c02 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfTiledInputPart.h @@ -0,0 +1,100 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2011, 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. +// +/////////////////////////////////////////////////////////////////////////// + +#ifndef IMFTILEDINPUTPART_H_ +#define IMFTILEDINPUTPART_H_ + +#include "ImfMultiPartInputFile.h" +#include "ImfTiledInputFile.h" +#include "ImfNamespace.h" +#include "ImfForward.h" +#include "ImfExport.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + +//----------------------------------------------------------------------------- +// class TiledInputPart: +// +// Same interface as TiledInputFile. Please have a reference to TiledInputFile. +//----------------------------------------------------------------------------- + +class IMF_EXPORT TiledInputPart +{ + public: + TiledInputPart(MultiPartInputFile& multiPartFile, int partNumber); + + const char * fileName () const; + const Header & header () const; + int version () const; + void setFrameBuffer (const FrameBuffer &frameBuffer); + const FrameBuffer & frameBuffer () const; + bool isComplete () const; + unsigned int tileXSize () const; + unsigned int tileYSize () const; + LevelMode levelMode () const; + LevelRoundingMode levelRoundingMode () const; + int numLevels () const; + int numXLevels () const; + int numYLevels () const; + bool isValidLevel (int lx, int ly) const; + int levelWidth (int lx) const; + int levelHeight (int ly) const; + int numXTiles (int lx = 0) const; + int numYTiles (int ly = 0) const; + IMATH_NAMESPACE::Box2i dataWindowForLevel (int l = 0) const; + IMATH_NAMESPACE::Box2i dataWindowForLevel (int lx, int ly) const; + IMATH_NAMESPACE::Box2i dataWindowForTile (int dx, int dy, int l = 0) const; + IMATH_NAMESPACE::Box2i dataWindowForTile (int dx, int dy, + int lx, int ly) const; + void readTile (int dx, int dy, int l = 0); + void readTile (int dx, int dy, int lx, int ly); + void readTiles (int dx1, int dx2, int dy1, int dy2, + int lx, int ly); + void readTiles (int dx1, int dx2, int dy1, int dy2, + int l = 0); + void rawTileData (int &dx, int &dy, + int &lx, int &ly, + const char *&pixelData, + int &pixelDataSize); + + private: + TiledInputFile* file; + // for internal use - allow TiledOutputFile access to file for copyPixels + friend class TiledOutputFile; + +}; + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif /* IMFTILEDINPUTPART_H_ */ diff --git a/OpenEXR/include/OpenEXR/ImfTiledOutputFile.h b/OpenEXR/include/OpenEXR/ImfTiledOutputFile.h new file mode 100644 index 0000000..bfd6bea --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfTiledOutputFile.h @@ -0,0 +1,495 @@ +/////////////////////////////////////////////////////////////////////////// +// +// 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_TILED_OUTPUT_FILE_H +#define INCLUDED_IMF_TILED_OUTPUT_FILE_H + +//----------------------------------------------------------------------------- +// +// class TiledOutputFile +// +//----------------------------------------------------------------------------- + +#include "ImfHeader.h" +#include "ImfFrameBuffer.h" +#include "ImathBox.h" +#include "ImfTileDescription.h" +#include "ImfThreading.h" +#include "ImfGenericOutputFile.h" +#include "ImfForward.h" +#include "ImfNamespace.h" +#include "ImfExport.h" + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +struct PreviewRgba; + + +class IMF_EXPORT TiledOutputFile : public GenericOutputFile +{ + public: + + //------------------------------------------------------------------- + // A constructor that opens the file with the specified name, and + // writes the file header. The file header is also copied into the + // TiledOutputFile object, and can later be accessed via the header() + // method. + // + // Destroying TiledOutputFile constructed with this constructor + // automatically closes the corresponding files. + // + // The header must contain a TileDescriptionAttribute called "tiles". + // + // The x and y subsampling factors for all image channels must be 1; + // subsampling is not supported. + // + // Tiles can be written to the file in arbitrary order. The line + // order attribute can be used to cause the tiles to be sorted in + // the file. When the file is read later, reading the tiles in the + // same order as they are in the file tends to be significantly + // faster than reading the tiles in random order (see writeTile, + // below). + //------------------------------------------------------------------- + + TiledOutputFile (const char fileName[], + const Header &header, + int numThreads = globalThreadCount ()); + + + // ---------------------------------------------------------------- + // A constructor that attaches the new TiledOutputFile object to + // a file that has already been opened. Destroying TiledOutputFile + // objects constructed with this constructor does not automatically + // close the corresponding files. + // ---------------------------------------------------------------- + + TiledOutputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &os, + const Header &header, + int numThreads = globalThreadCount ()); + + + //----------------------------------------------------- + // Destructor + // + // Destroying a TiledOutputFile object before all tiles + // have been written results in an incomplete file. + //----------------------------------------------------- + + virtual ~TiledOutputFile (); + + + //------------------------ + // Access to the file name + //------------------------ + + const char * fileName () const; + + + //-------------------------- + // Access to the file header + //-------------------------- + + const Header & header () const; + + + //------------------------------------------------------- + // Set the current frame buffer -- copies the FrameBuffer + // object into the TiledOutputFile object. + // + // The current frame buffer is the source of the pixel + // data written to the file. The current frame buffer + // must be set at least once before writeTile() is + // called. The current frame buffer can be changed + // after each call to writeTile(). + //------------------------------------------------------- + + void setFrameBuffer (const FrameBuffer &frameBuffer); + + + //----------------------------------- + // Access to the current frame buffer + //----------------------------------- + + const FrameBuffer & frameBuffer () const; + + + //------------------- + // Utility functions: + //------------------- + + //--------------------------------------------------------- + // Multiresolution mode and tile size: + // The following functions return the xSize, ySize and mode + // fields of the file header's TileDescriptionAttribute. + //--------------------------------------------------------- + + unsigned int tileXSize () const; + unsigned int tileYSize () const; + LevelMode levelMode () const; + LevelRoundingMode levelRoundingMode () const; + + + //-------------------------------------------------------------------- + // Number of levels: + // + // numXLevels() returns the file's number of levels in x direction. + // + // if levelMode() == ONE_LEVEL: + // return value is: 1 + // + // if levelMode() == MIPMAP_LEVELS: + // return value is: rfunc (log (max (w, h)) / log (2)) + 1 + // + // if levelMode() == RIPMAP_LEVELS: + // return value is: rfunc (log (w) / log (2)) + 1 + // + // where + // w is the width of the image's data window, max.x - min.x + 1, + // y is the height of the image's data window, max.y - min.y + 1, + // and rfunc(x) is either floor(x), or ceil(x), depending on + // whether levelRoundingMode() returns ROUND_DOWN or ROUND_UP. + // + // numYLevels() returns the file's number of levels in y direction. + // + // if levelMode() == ONE_LEVEL or levelMode() == MIPMAP_LEVELS: + // return value is the same as for numXLevels() + // + // if levelMode() == RIPMAP_LEVELS: + // return value is: rfunc (log (h) / log (2)) + 1 + // + // + // numLevels() is a convenience function for use with MIPMAP_LEVELS + // files. + // + // if levelMode() == ONE_LEVEL or levelMode() == MIPMAP_LEVELS: + // return value is the same as for numXLevels() + // + // if levelMode() == RIPMAP_LEVELS: + // an IEX_NAMESPACE::LogicExc exception is thrown + // + // isValidLevel(lx, ly) returns true if the file contains + // a level with level number (lx, ly), false if not. + // + //-------------------------------------------------------------------- + + int numLevels () const; + int numXLevels () const; + int numYLevels () const; + bool isValidLevel (int lx, int ly) const; + + + //--------------------------------------------------------- + // Dimensions of a level: + // + // levelWidth(lx) returns the width of a level with level + // number (lx, *), where * is any number. + // + // return value is: + // max (1, rfunc (w / pow (2, lx))) + // + // + // levelHeight(ly) returns the height of a level with level + // number (*, ly), where * is any number. + // + // return value is: + // max (1, rfunc (h / pow (2, ly))) + // + //--------------------------------------------------------- + + int levelWidth (int lx) const; + int levelHeight (int ly) const; + + + //---------------------------------------------------------- + // Number of tiles: + // + // numXTiles(lx) returns the number of tiles in x direction + // that cover a level with level number (lx, *), where * is + // any number. + // + // return value is: + // (levelWidth(lx) + tileXSize() - 1) / tileXSize() + // + // + // numYTiles(ly) returns the number of tiles in y direction + // that cover a level with level number (*, ly), where * is + // any number. + // + // return value is: + // (levelHeight(ly) + tileXSize() - 1) / tileXSize() + // + //---------------------------------------------------------- + + int numXTiles (int lx = 0) const; + int numYTiles (int ly = 0) const; + + + //--------------------------------------------------------- + // Level pixel ranges: + // + // dataWindowForLevel(lx, ly) returns a 2-dimensional + // region of valid pixel coordinates for a level with + // level number (lx, ly) + // + // return value is a Box2i with min value: + // (dataWindow.min.x, dataWindow.min.y) + // + // and max value: + // (dataWindow.min.x + levelWidth(lx) - 1, + // dataWindow.min.y + levelHeight(ly) - 1) + // + // dataWindowForLevel(level) is a convenience function used + // for ONE_LEVEL and MIPMAP_LEVELS files. It returns + // dataWindowForLevel(level, level). + // + //--------------------------------------------------------- + + IMATH_NAMESPACE::Box2i dataWindowForLevel (int l = 0) const; + IMATH_NAMESPACE::Box2i dataWindowForLevel (int lx, int ly) const; + + + //------------------------------------------------------------------- + // Tile pixel ranges: + // + // dataWindowForTile(dx, dy, lx, ly) returns a 2-dimensional + // region of valid pixel coordinates for a tile with tile coordinates + // (dx,dy) and level number (lx, ly). + // + // return value is a Box2i with min value: + // (dataWindow.min.x + dx * tileXSize(), + // dataWindow.min.y + dy * tileYSize()) + // + // and max value: + // (dataWindow.min.x + (dx + 1) * tileXSize() - 1, + // dataWindow.min.y + (dy + 1) * tileYSize() - 1) + // + // dataWindowForTile(dx, dy, level) is a convenience function + // used for ONE_LEVEL and MIPMAP_LEVELS files. It returns + // dataWindowForTile(dx, dy, level, level). + // + //------------------------------------------------------------------- + + IMATH_NAMESPACE::Box2i dataWindowForTile (int dx, int dy, + int l = 0) const; + + IMATH_NAMESPACE::Box2i dataWindowForTile (int dx, int dy, + int lx, int ly) const; + + //------------------------------------------------------------------ + // Write pixel data: + // + // writeTile(dx, dy, lx, ly) writes the tile with tile + // coordinates (dx, dy), and level number (lx, ly) to + // the file. + // + // dx must lie in the interval [0, numXTiles(lx) - 1] + // dy must lie in the interval [0, numYTiles(ly) - 1] + // + // lx must lie in the interval [0, numXLevels() - 1] + // ly must lie in the inverval [0, numYLevels() - 1] + // + // writeTile(dx, dy, level) is a convenience function + // used for ONE_LEVEL and MIPMAP_LEVEL files. It calls + // writeTile(dx, dy, level, level). + // + // The two writeTiles(dx1, dx2, dy1, dy2, ...) functions allow + // writing multiple tiles at once. If multi-threading is used + // multiple tiles are written concurrently. The tile coordinates, + // dx1, dx2 and dy1, dy2, specify inclusive ranges of tile + // coordinates. It is valid for dx1 < dx2 or dy1 < dy2; the + // tiles are always written in the order specified by the line + // order attribute. Hence, it is not possible to specify an + // "invalid" or empty tile range. + // + // Pixels that are outside the pixel coordinate range for the tile's + // level, are never accessed by writeTile(). + // + // Each tile in the file must be written exactly once. + // + // The file's line order attribute determines the order of the tiles + // in the file: + // + // INCREASING_Y In the file, the tiles for each level are stored + // in a contiguous block. The levels are ordered + // like this: + // + // (0, 0) (1, 0) ... (nx-1, 0) + // (0, 1) (1, 1) ... (nx-1, 1) + // ... + // (0,ny-1) (1,ny-1) ... (nx-1,ny-1) + // + // where nx = numXLevels(), and ny = numYLevels(). + // In an individual level, (lx, ly), the tiles + // are stored in the following order: + // + // (0, 0) (1, 0) ... (tx-1, 0) + // (0, 1) (1, 1) ... (tx-1, 1) + // ... + // (0,ty-1) (1,ty-1) ... (tx-1,ty-1) + // + // where tx = numXTiles(lx), + // and ty = numYTiles(ly). + // + // DECREASING_Y As for INCREASING_Y, the tiles for each level + // are stored in a contiguous block. The levels + // are ordered the same way as for INCREASING_Y, + // but within an individual level, the tiles + // are stored in this order: + // + // (0,ty-1) (1,ty-1) ... (tx-1,ty-1) + // ... + // (0, 1) (1, 1) ... (tx-1, 1) + // (0, 0) (1, 0) ... (tx-1, 0) + // + // + // RANDOM_Y The order of the calls to writeTile() determines + // the order of the tiles in the file. + // + //------------------------------------------------------------------ + + void writeTile (int dx, int dy, int l = 0); + void writeTile (int dx, int dy, int lx, int ly); + + void writeTiles (int dx1, int dx2, int dy1, int dy2, + int lx, int ly); + + void writeTiles (int dx1, int dx2, int dy1, int dy2, + int l = 0); + + + //------------------------------------------------------------------ + // Shortcut to copy all pixels from a TiledInputFile into this file, + // without uncompressing and then recompressing the pixel data. + // This file's header must be compatible with the TiledInputFile's + // header: The two header's "dataWindow", "compression", + // "lineOrder", "channels", and "tiles" attributes must be the same. + //------------------------------------------------------------------ + + void copyPixels (TiledInputFile &in); + void copyPixels (TiledInputPart &in); + + + //------------------------------------------------------------------ + // Shortcut to copy all pixels from an InputFile into this file, + // without uncompressing and then recompressing the pixel data. + // This file's header must be compatible with the InputFile's + // header: The two header's "dataWindow", "compression", + // "lineOrder", "channels", and "tiles" attributes must be the same. + // + // To use this function, the InputFile must be tiled. + //------------------------------------------------------------------ + + void copyPixels (InputFile &in); + void copyPixels (InputPart &in); + + + + //-------------------------------------------------------------- + // Updating the preview image: + // + // updatePreviewImage() supplies a new set of pixels for the + // preview image attribute in the file's header. If the header + // does not contain a preview image, updatePreviewImage() throws + // an IEX_NAMESPACE::LogicExc. + // + // Note: updatePreviewImage() is necessary because images are + // often stored in a file incrementally, a few tiles at a time, + // while the image is being generated. Since the preview image + // is an attribute in the file's header, it gets stored in the + // file as soon as the file is opened, but we may not know what + // the preview image should look like until we have written the + // last tile of the main image. + // + //-------------------------------------------------------------- + + void updatePreviewImage (const PreviewRgba newPixels[]); + + + //------------------------------------------------------------- + // Break a tile -- for testing and debugging only: + // + // breakTile(dx,dy,lx,ly,p,n,c) introduces an error into the + // output file by writing n copies of character c, starting + // p bytes from the beginning of the tile with tile coordinates + // (dx, dy) and level number (lx, ly). + // + // Warning: Calling this function usually results in a broken + // image file. The file or parts of it may not be readable, + // or the file may contain bad data. + // + //------------------------------------------------------------- + + void breakTile (int dx, int dy, + int lx, int ly, + int offset, + int length, + char c); + struct Data; + + private: + + // ---------------------------------------------------------------- + // A constructor attaches the OutputStreamMutex to the + // given one from MultiPartOutputFile. Set the previewPosition + // and lineOffsetsPosition which have been acquired from + // the constructor of MultiPartOutputFile as well. + // ---------------------------------------------------------------- + TiledOutputFile (const OutputPartData* part); + + TiledOutputFile (const TiledOutputFile &); // not implemented + TiledOutputFile & operator = (const TiledOutputFile &); // not implemented + + void initialize (const Header &header); + + bool isValidTile (int dx, int dy, + int lx, int ly) const; + + size_t bytesPerLineForTile (int dx, int dy, + int lx, int ly) const; + + Data * _data; + + OutputStreamMutex* _streamData; + bool _deleteStream; + + friend class MultiPartOutputFile; +}; + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfTiledOutputPart.h b/OpenEXR/include/OpenEXR/ImfTiledOutputPart.h new file mode 100644 index 0000000..1af84be --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfTiledOutputPart.h @@ -0,0 +1,105 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2011, 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. +// +/////////////////////////////////////////////////////////////////////////// + +#ifndef IMFTILEDOUTPUTPART_H_ +#define IMFTILEDOUTPUTPART_H_ + +#include "ImfMultiPartOutputFile.h" +#include "ImfTiledOutputFile.h" +#include "ImfForward.h" +#include "ImfExport.h" +#include "ImfNamespace.h" + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + +//------------------------------------------------------------------------------- +// class TiledOutputPart: +// +// Same interface as TiledOutputFile. Please have a reference to TiledOutputFile. +//------------------------------------------------------------------------------- + +class IMF_EXPORT TiledOutputPart +{ + public: + TiledOutputPart(MultiPartOutputFile& multiPartFile, int partNumber); + + const char * fileName () const; + const Header & header () const; + void setFrameBuffer (const FrameBuffer &frameBuffer); + const FrameBuffer & frameBuffer () const; + unsigned int tileXSize () const; + unsigned int tileYSize () const; + LevelMode levelMode () const; + LevelRoundingMode levelRoundingMode () const; + int numLevels () const; + int numXLevels () const; + int numYLevels () const; + bool isValidLevel (int lx, int ly) const; + int levelWidth (int lx) const; + int levelHeight (int ly) const; + int numXTiles (int lx = 0) const; + int numYTiles (int ly = 0) const; + IMATH_NAMESPACE::Box2i dataWindowForLevel (int l = 0) const; + IMATH_NAMESPACE::Box2i dataWindowForLevel (int lx, int ly) const; + IMATH_NAMESPACE::Box2i dataWindowForTile (int dx, int dy, + int l = 0) const; + IMATH_NAMESPACE::Box2i dataWindowForTile (int dx, int dy, + int lx, int ly) const; + void writeTile (int dx, int dy, int l = 0); + void writeTile (int dx, int dy, int lx, int ly); + void writeTiles (int dx1, int dx2, int dy1, int dy2, + int lx, int ly); + void writeTiles (int dx1, int dx2, int dy1, int dy2, + int l = 0); + void copyPixels (TiledInputFile &in); + void copyPixels (InputFile &in); + void copyPixels (TiledInputPart &in); + void copyPixels (InputPart &in); + + + void updatePreviewImage (const PreviewRgba newPixels[]); + void breakTile (int dx, int dy, + int lx, int ly, + int offset, + int length, + char c); + + private: + TiledOutputFile* file; +}; + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + +#endif /* IMFTILEDOUTPUTPART_H_ */ diff --git a/OpenEXR/include/OpenEXR/ImfTiledRgbaFile.h b/OpenEXR/include/OpenEXR/ImfTiledRgbaFile.h new file mode 100644 index 0000000..978ba36 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfTiledRgbaFile.h @@ -0,0 +1,482 @@ +/////////////////////////////////////////////////////////////////////////// +// +// 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_TILED_RGBA_FILE_H +#define INCLUDED_IMF_TILED_RGBA_FILE_H + +//----------------------------------------------------------------------------- +// +// Simplified RGBA image I/O for tiled files +// +// class TiledRgbaOutputFile +// class TiledRgbaInputFile +// +//----------------------------------------------------------------------------- + +#include "ImfHeader.h" +#include "ImfFrameBuffer.h" +#include "ImathVec.h" +#include "ImathBox.h" +#include "half.h" +#include "ImfTileDescription.h" +#include "ImfRgba.h" +#include "ImfThreading.h" +#include +#include "ImfNamespace.h" +#include "ImfForward.h" + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +// +// Tiled RGBA output file. +// + +class IMF_EXPORT TiledRgbaOutputFile +{ + public: + + //--------------------------------------------------- + // Constructor -- rgbaChannels, tileXSize, tileYSize, + // levelMode, and levelRoundingMode overwrite the + // channel list and tile description attribute in the + // header that is passed as an argument to the + // constructor. + //--------------------------------------------------- + + TiledRgbaOutputFile (const char name[], + const Header &header, + RgbaChannels rgbaChannels, + int tileXSize, + int tileYSize, + LevelMode mode, + LevelRoundingMode rmode = ROUND_DOWN, + int numThreads = globalThreadCount ()); + + + //--------------------------------------------------- + // Constructor -- like the previous one, but the new + // TiledRgbaOutputFile is attached to a file that has + // already been opened by the caller. Destroying + // TiledRgbaOutputFileObjects constructed with this + // constructor does not automatically close the + // corresponding files. + //--------------------------------------------------- + + TiledRgbaOutputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &os, + const Header &header, + RgbaChannels rgbaChannels, + int tileXSize, + int tileYSize, + LevelMode mode, + LevelRoundingMode rmode = ROUND_DOWN, + int numThreads = globalThreadCount ()); + + + //------------------------------------------------------ + // Constructor -- header data are explicitly specified + // as function call arguments (an empty dataWindow means + // "same as displayWindow") + //------------------------------------------------------ + + TiledRgbaOutputFile (const char name[], + int tileXSize, + int tileYSize, + LevelMode mode, + LevelRoundingMode rmode, + const IMATH_NAMESPACE::Box2i &displayWindow, + const IMATH_NAMESPACE::Box2i &dataWindow = IMATH_NAMESPACE::Box2i(), + RgbaChannels rgbaChannels = WRITE_RGBA, + float pixelAspectRatio = 1, + const IMATH_NAMESPACE::V2f screenWindowCenter = + IMATH_NAMESPACE::V2f (0, 0), + float screenWindowWidth = 1, + LineOrder lineOrder = INCREASING_Y, + Compression compression = ZIP_COMPRESSION, + int numThreads = globalThreadCount ()); + + + //----------------------------------------------- + // Constructor -- like the previous one, but both + // the display window and the data window are + // Box2i (V2i (0, 0), V2i (width - 1, height -1)) + //----------------------------------------------- + + TiledRgbaOutputFile (const char name[], + int width, + int height, + int tileXSize, + int tileYSize, + LevelMode mode, + LevelRoundingMode rmode = ROUND_DOWN, + RgbaChannels rgbaChannels = WRITE_RGBA, + float pixelAspectRatio = 1, + const IMATH_NAMESPACE::V2f screenWindowCenter = + IMATH_NAMESPACE::V2f (0, 0), + float screenWindowWidth = 1, + LineOrder lineOrder = INCREASING_Y, + Compression compression = ZIP_COMPRESSION, + int numThreads = globalThreadCount ()); + + + virtual ~TiledRgbaOutputFile (); + + + //------------------------------------------------ + // Define a frame buffer as the pixel data source: + // Pixel (x, y) is at address + // + // base + x * xStride + y * yStride + // + //------------------------------------------------ + + void setFrameBuffer (const Rgba *base, + size_t xStride, + size_t yStride); + + //-------------------------- + // Access to the file header + //-------------------------- + + const Header & header () const; + const FrameBuffer & frameBuffer () const; + const IMATH_NAMESPACE::Box2i & displayWindow () const; + const IMATH_NAMESPACE::Box2i & dataWindow () const; + float pixelAspectRatio () const; + const IMATH_NAMESPACE::V2f screenWindowCenter () const; + float screenWindowWidth () const; + LineOrder lineOrder () const; + Compression compression () const; + RgbaChannels channels () const; + + + //---------------------------------------------------- + // Utility functions (same as in Imf::TiledOutputFile) + //---------------------------------------------------- + + unsigned int tileXSize () const; + unsigned int tileYSize () const; + LevelMode levelMode () const; + LevelRoundingMode levelRoundingMode () const; + + int numLevels () const; + int numXLevels () const; + int numYLevels () const; + bool isValidLevel (int lx, int ly) const; + + int levelWidth (int lx) const; + int levelHeight (int ly) const; + + int numXTiles (int lx = 0) const; + int numYTiles (int ly = 0) const; + + IMATH_NAMESPACE::Box2i dataWindowForLevel (int l = 0) const; + IMATH_NAMESPACE::Box2i dataWindowForLevel (int lx, int ly) const; + + IMATH_NAMESPACE::Box2i dataWindowForTile (int dx, int dy, + int l = 0) const; + + IMATH_NAMESPACE::Box2i dataWindowForTile (int dx, int dy, + int lx, int ly) const; + + //------------------------------------------------------------------ + // Write pixel data: + // + // writeTile(dx, dy, lx, ly) writes the tile with tile + // coordinates (dx, dy), and level number (lx, ly) to + // the file. + // + // dx must lie in the interval [0, numXTiles(lx)-1] + // dy must lie in the interval [0, numYTiles(ly)-1] + // + // lx must lie in the interval [0, numXLevels()-1] + // ly must lie in the inverval [0, numYLevels()-1] + // + // writeTile(dx, dy, level) is a convenience function + // used for ONE_LEVEL and MIPMAP_LEVEL files. It calls + // writeTile(dx, dy, level, level). + // + // The two writeTiles(dx1, dx2, dy1, dy2, ...) functions allow + // writing multiple tiles at once. If multi-threading is used + // multiple tiles are written concurrently. + // + // Pixels that are outside the pixel coordinate range for the tile's + // level, are never accessed by writeTile(). + // + // Each tile in the file must be written exactly once. + // + //------------------------------------------------------------------ + + void writeTile (int dx, int dy, int l = 0); + void writeTile (int dx, int dy, int lx, int ly); + + void writeTiles (int dxMin, int dxMax, int dyMin, int dyMax, + int lx, int ly); + + void writeTiles (int dxMin, int dxMax, int dyMin, int dyMax, + int l = 0); + + + // ------------------------------------------------------------------------- + // Update the preview image (see Imf::TiledOutputFile::updatePreviewImage()) + // ------------------------------------------------------------------------- + + void updatePreviewImage (const PreviewRgba[]); + + + //------------------------------------------------ + // Break a tile -- for testing and debugging only + // (see Imf::TiledOutputFile::breakTile()) + // + // Warning: Calling this function usually results + // in a broken image file. The file or parts of + // it may not be readable, or the file may contain + // bad data. + // + //------------------------------------------------ + + void breakTile (int dx, int dy, + int lx, int ly, + int offset, + int length, + char c); + private: + + // + // Copy constructor and assignment are not implemented + // + + TiledRgbaOutputFile (const TiledRgbaOutputFile &); + TiledRgbaOutputFile & operator = (const TiledRgbaOutputFile &); + + class ToYa; + + TiledOutputFile * _outputFile; + ToYa * _toYa; +}; + + + +// +// Tiled RGBA input file +// + +class IMF_EXPORT TiledRgbaInputFile +{ + public: + + //-------------------------------------------------------- + // Constructor -- opens the file with the specified name. + // Destroying TiledRgbaInputFile objects constructed with + // this constructor automatically closes the corresponding + // files. + //-------------------------------------------------------- + + TiledRgbaInputFile (const char name[], + int numThreads = globalThreadCount ()); + + + //------------------------------------------------------- + // Constructor -- attaches the new TiledRgbaInputFile + // object to a file that has already been opened by the + // caller. + // Destroying TiledRgbaInputFile objects constructed with + // this constructor does not automatically close the + // corresponding files. + //------------------------------------------------------- + + TiledRgbaInputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is, int numThreads = globalThreadCount ()); + + + //------------------------------------------------------------ + // Constructors -- the same as the previous two, but the names + // of the red, green, blue, alpha, and luminance channels are + // expected to be layerName.R, layerName.G, etc. + //------------------------------------------------------------ + + TiledRgbaInputFile (const char name[], + const std::string &layerName, + int numThreads = globalThreadCount()); + + TiledRgbaInputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is, + const std::string &layerName, + int numThreads = globalThreadCount()); + + //----------- + // Destructor + //----------- + + virtual ~TiledRgbaInputFile (); + + + //----------------------------------------------------- + // Define a frame buffer as the pixel data destination: + // Pixel (x, y) is at address + // + // base + x * xStride + y * yStride + // + //----------------------------------------------------- + + void setFrameBuffer (Rgba *base, + size_t xStride, + size_t yStride); + + //------------------------------------------------------------------- + // Switch to a different layer -- subsequent calls to readTile() + // and readTiles() will read channels layerName.R, layerName.G, etc. + // After each call to setLayerName(), setFrameBuffer() must be called + // at least once before the next call to readTile() or readTiles(). + //------------------------------------------------------------------- + + void setLayerName (const std::string &layerName); + + + //-------------------------- + // Access to the file header + //-------------------------- + + const Header & header () const; + const FrameBuffer & frameBuffer () const; + const IMATH_NAMESPACE::Box2i & displayWindow () const; + const IMATH_NAMESPACE::Box2i & dataWindow () const; + float pixelAspectRatio () const; + const IMATH_NAMESPACE::V2f screenWindowCenter () const; + float screenWindowWidth () const; + LineOrder lineOrder () const; + Compression compression () const; + RgbaChannels channels () const; + const char * fileName () const; + bool isComplete () const; + + //---------------------------------- + // Access to the file format version + //---------------------------------- + + int version () const; + + + //--------------------------------------------------- + // Utility functions (same as in Imf::TiledInputFile) + //--------------------------------------------------- + + unsigned int tileXSize () const; + unsigned int tileYSize () const; + LevelMode levelMode () const; + LevelRoundingMode levelRoundingMode () const; + + int numLevels () const; + int numXLevels () const; + int numYLevels () const; + bool isValidLevel (int lx, int ly) const; + + int levelWidth (int lx) const; + int levelHeight (int ly) const; + + int numXTiles (int lx = 0) const; + int numYTiles (int ly = 0) const; + + IMATH_NAMESPACE::Box2i dataWindowForLevel (int l = 0) const; + IMATH_NAMESPACE::Box2i dataWindowForLevel (int lx, int ly) const; + + IMATH_NAMESPACE::Box2i dataWindowForTile (int dx, int dy, + int l = 0) const; + + IMATH_NAMESPACE::Box2i dataWindowForTile (int dx, int dy, + int lx, int ly) const; + + + //---------------------------------------------------------------- + // Read pixel data: + // + // readTile(dx, dy, lx, ly) reads the tile with tile + // coordinates (dx, dy), and level number (lx, ly), + // and stores it in the current frame buffer. + // + // dx must lie in the interval [0, numXTiles(lx)-1] + // dy must lie in the interval [0, numYTiles(ly)-1] + // + // lx must lie in the interval [0, numXLevels()-1] + // ly must lie in the inverval [0, numYLevels()-1] + // + // readTile(dx, dy, level) is a convenience function used + // for ONE_LEVEL and MIPMAP_LEVELS files. It calls + // readTile(dx, dy, level, level). + // + // The two readTiles(dx1, dx2, dy1, dy2, ...) functions allow + // reading multiple tiles at once. If multi-threading is used + // multiple tiles are read concurrently. + // + // Pixels that are outside the pixel coordinate range for the + // tile's level, are never accessed by readTile(). + // + // Attempting to access a tile that is not present in the file + // throws an InputExc exception. + // + //---------------------------------------------------------------- + + void readTile (int dx, int dy, int l = 0); + void readTile (int dx, int dy, int lx, int ly); + + void readTiles (int dxMin, int dxMax, + int dyMin, int dyMax, int lx, int ly); + + void readTiles (int dxMin, int dxMax, + int dyMin, int dyMax, int l = 0); + + private: + + // + // Copy constructor and assignment are not implemented + // + + TiledRgbaInputFile (const TiledRgbaInputFile &); + TiledRgbaInputFile & operator = (const TiledRgbaInputFile &); + + class FromYa; + + TiledInputFile * _inputFile; + FromYa * _fromYa; + std::string _channelNamePrefix; +}; + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + + + + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfTimeCode.h b/OpenEXR/include/OpenEXR/ImfTimeCode.h new file mode 100644 index 0000000..751c416 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfTimeCode.h @@ -0,0 +1,242 @@ +/////////////////////////////////////////////////////////////////////////// +// +// 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_TIME_CODE_H +#define INCLUDED_IMF_TIME_CODE_H + +#include "ImfExport.h" +#include "ImfNamespace.h" + +//----------------------------------------------------------------------------- +// +// class TimeCode +// +// A TimeCode object stores time and control codes as described +// in SMPTE standard 12M-1999. A TimeCode object contains the +// following fields: +// +// Time Address: +// +// hours integer, range 0 - 23 +// minutes integer, range 0 - 59 +// seconds integer, range 0 - 59 +// frame integer, range 0 - 29 +// +// Flags: +// +// drop frame flag boolean +// color frame flag boolean +// field/phase flag boolean +// bgf0 boolean +// bgf1 boolean +// bgf2 boolean +// +// Binary groups for user-defined data and control codes: +// +// binary group 1 integer, range 0 - 15 +// binary group 2 integer, range 0 - 15 +// ... +// binary group 8 integer, range 0 - 15 +// +// Class TimeCode contains methods to convert between the fields +// listed above and a more compact representation where the fields +// are packed into two unsigned 32-bit integers. In the packed +// integer representations, bit 0 is the least significant bit, +// and bit 31 is the most significant bit of the integer value. +// +// The time address and flags fields can be packed in three +// different ways: +// +// bits packing for packing for packing for +// 24-frame 60-field 50-field +// film television television +// +// 0 - 3 frame units frame units frame units +// 4 - 5 frame tens frame tens frame tens +// 6 unused, set to 0 drop frame flag unused, set to 0 +// 7 unused, set to 0 color frame flag color frame flag +// 8 - 11 seconds units seconds units seconds units +// 12 - 14 seconds tens seconds tens seconds tens +// 15 phase flag field/phase flag bgf0 +// 16 - 19 minutes units minutes units minutes units +// 20 - 22 minutes tens minutes tens minutes tens +// 23 bgf0 bgf0 bgf2 +// 24 - 27 hours units hours units hours units +// 28 - 29 hours tens hours tens hours tens +// 30 bgf1 bgf1 bgf1 +// 31 bgf2 bgf2 field/phase flag +// +// User-defined data and control codes are packed as follows: +// +// bits field +// +// 0 - 3 binary group 1 +// 4 - 7 binary group 2 +// 8 - 11 binary group 3 +// 12 - 15 binary group 4 +// 16 - 19 binary group 5 +// 20 - 23 binary group 6 +// 24 - 27 binary group 7 +// 28 - 31 binary group 8 +// +//----------------------------------------------------------------------------- + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +class IMF_EXPORT TimeCode +{ + public: + + //--------------------- + // Bit packing variants + //--------------------- + + enum Packing + { + TV60_PACKING, // packing for 60-field television + TV50_PACKING, // packing for 50-field television + FILM24_PACKING // packing for 24-frame film + }; + + + //------------------------------------- + // Constructors and assignment operator + //------------------------------------- + + TimeCode (); // all fields set to 0 or false + + TimeCode (int hours, + int minutes, + int seconds, + int frame, + bool dropFrame = false, + bool colorFrame = false, + bool fieldPhase = false, + bool bgf0 = false, + bool bgf1 = false, + bool bgf2 = false, + int binaryGroup1 = 0, + int binaryGroup2 = 0, + int binaryGroup3 = 0, + int binaryGroup4 = 0, + int binaryGroup5 = 0, + int binaryGroup6 = 0, + int binaryGroup7 = 0, + int binaryGroup8 = 0); + + TimeCode (unsigned int timeAndFlags, + unsigned int userData = 0, + Packing packing = TV60_PACKING); + + TimeCode (const TimeCode &other); + + TimeCode & operator = (const TimeCode &other); + + + //---------------------------- + // Access to individual fields + //---------------------------- + + int hours () const; + void setHours (int value); + + int minutes () const; + void setMinutes (int value); + + int seconds () const; + void setSeconds (int value); + + int frame () const; + void setFrame (int value); + + bool dropFrame () const; + void setDropFrame (bool value); + + bool colorFrame () const; + void setColorFrame (bool value); + + bool fieldPhase () const; + void setFieldPhase (bool value); + + bool bgf0 () const; + void setBgf0 (bool value); + + bool bgf1 () const; + void setBgf1 (bool value); + + bool bgf2 () const; + void setBgf2 (bool value); + + int binaryGroup (int group) const; // group must be between 1 and 8 + void setBinaryGroup (int group, int value); + + + //--------------------------------- + // Access to packed representations + //--------------------------------- + + unsigned int timeAndFlags (Packing packing = TV60_PACKING) const; + + void setTimeAndFlags (unsigned int value, + Packing packing = TV60_PACKING); + + unsigned int userData () const; + + void setUserData (unsigned int value); + + + //--------- + // Equality + //--------- + + bool operator == (const TimeCode &v) const; + bool operator != (const TimeCode &v) const; + + private: + + unsigned int _time; + unsigned int _user; +}; + + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + + + + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfTimeCodeAttribute.h b/OpenEXR/include/OpenEXR/ImfTimeCodeAttribute.h new file mode 100644 index 0000000..ccd893a --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfTimeCodeAttribute.h @@ -0,0 +1,74 @@ +/////////////////////////////////////////////////////////////////////////// +// +// 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_TIME_CODE_ATTRIBUTE_H +#define INCLUDED_IMF_TIME_CODE_ATTRIBUTE_H + + +//----------------------------------------------------------------------------- +// +// class TimeCodeAttribute +// +//----------------------------------------------------------------------------- + +#include "ImfAttribute.h" +#include "ImfTimeCode.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +typedef TypedAttribute TimeCodeAttribute; + +template <> +IMF_EXPORT +const char *TimeCodeAttribute::staticTypeName (); + +template <> +IMF_EXPORT +void TimeCodeAttribute::writeValueTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &, + int) const; + +template <> +IMF_EXPORT +void TimeCodeAttribute::readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &, + int, int); + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + + + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfVecAttribute.h b/OpenEXR/include/OpenEXR/ImfVecAttribute.h new file mode 100644 index 0000000..8480fe6 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfVecAttribute.h @@ -0,0 +1,100 @@ +/////////////////////////////////////////////////////////////////////////// +// +// 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMF_VEC_ATTRIBUTE_H +#define INCLUDED_IMF_VEC_ATTRIBUTE_H + +//----------------------------------------------------------------------------- +// +// class V2iAttribute +// class V2fAttribute +// class V2dAttribute +// class V3iAttribute +// class V3fAttribute +// class V3dAttribute +// +//----------------------------------------------------------------------------- + +#include "ImfAttribute.h" +#include "ImathVec.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + +typedef TypedAttribute V2iAttribute; +template <> IMF_EXPORT const char *V2iAttribute::staticTypeName (); +template <> IMF_EXPORT void V2iAttribute::writeValueTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &, int) const; +template <> IMF_EXPORT void V2iAttribute::readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &, int, int); + + +typedef TypedAttribute V2fAttribute; +template <> IMF_EXPORT const char *V2fAttribute::staticTypeName (); +template <> IMF_EXPORT void V2fAttribute::writeValueTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &, int) const; +template <> IMF_EXPORT void V2fAttribute::readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &, int, int); + + +typedef TypedAttribute V2dAttribute; +template <> IMF_EXPORT const char *V2dAttribute::staticTypeName (); +template <> IMF_EXPORT void V2dAttribute::writeValueTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &, int) const; +template <> IMF_EXPORT void V2dAttribute::readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &, int, int); + + +typedef TypedAttribute V3iAttribute; +template <> IMF_EXPORT const char *V3iAttribute::staticTypeName (); +template <> IMF_EXPORT void V3iAttribute::writeValueTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &, int) const; +template <> IMF_EXPORT void V3iAttribute::readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &, int, int); + + +typedef TypedAttribute V3fAttribute; +template <> IMF_EXPORT const char *V3fAttribute::staticTypeName (); +template <> IMF_EXPORT void V3fAttribute::writeValueTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &, int) const; +template <> IMF_EXPORT void V3fAttribute::readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &, int, int); + + +typedef TypedAttribute V3dAttribute; +template <> IMF_EXPORT const char *V3dAttribute::staticTypeName (); +template <> IMF_EXPORT void V3dAttribute::writeValueTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &, int) const; +template <> IMF_EXPORT void V3dAttribute::readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &, int, int); + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + +#if defined (OPENEXR_IMF_INTERNAL_NAMESPACE_AUTO_EXPOSE) +namespace Imf { using namespace OPENEXR_IMF_INTERNAL_NAMESPACE; } + +#endif + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfVersion.h b/OpenEXR/include/OpenEXR/ImfVersion.h new file mode 100644 index 0000000..de2577f --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfVersion.h @@ -0,0 +1,136 @@ +/////////////////////////////////////////////////////////////////////////// +// +// 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_VERSION_H +#define INCLUDED_IMF_VERSION_H + +//----------------------------------------------------------------------------- +// +// Magic and version number. +// +//----------------------------------------------------------------------------- + +#include "ImfExport.h" +#include "ImfNamespace.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + +// +// The MAGIC number is stored in the first four bytes of every +// OpenEXR image file. This can be used to quickly test whether +// a given file is an OpenEXR image file (see isImfMagic(), below). +// + +const int MAGIC = 20000630; + + +// +// The second item in each OpenEXR image file, right after the +// magic number, is a four-byte file version identifier. Depending +// on a file's version identifier, a file reader can enable various +// backwards-compatibility switches, or it can quickly reject files +// that it cannot read. +// +// The version identifier is split into an 8-bit version number, +// and a 24-bit flags field. +// + +const int VERSION_NUMBER_FIELD = 0x000000ff; +const int VERSION_FLAGS_FIELD = 0xffffff00; + + +// +// Value that goes into VERSION_NUMBER_FIELD. +// + +const int EXR_VERSION = 2; + + +// +// Flags that can go into VERSION_FLAGS_FIELD. +// Flags can only occupy the 1 bits in VERSION_FLAGS_FIELD. +// + +const int TILED_FLAG = 0x00000200; // File is tiled + +const int LONG_NAMES_FLAG = 0x00000400; // File contains long + // attribute or channel + // names + +const int NON_IMAGE_FLAG = 0x00000800; // File has at least one part + // which is not a regular + // scanline image or regular tiled image + // (that is, it is a deep format) + +const int MULTI_PART_FILE_FLAG = 0x00001000; // File has multiple parts + +// +// Bitwise OR of all known flags. +// + +const int ALL_FLAGS = TILED_FLAG | LONG_NAMES_FLAG | + NON_IMAGE_FLAG | MULTI_PART_FILE_FLAG; + + +// +// Utility functions +// + +inline bool isTiled (int version) {return !!(version & TILED_FLAG);} +inline bool isMultiPart (int version) {return version & MULTI_PART_FILE_FLAG; } +inline bool isNonImage(int version) {return version & NON_IMAGE_FLAG; } +inline int makeTiled (int version) {return version | TILED_FLAG;} +inline int makeNotTiled (int version) {return version & ~TILED_FLAG;} +inline int getVersion (int version) {return version & VERSION_NUMBER_FIELD;} +inline int getFlags (int version) {return version & VERSION_FLAGS_FIELD;} +inline bool supportsFlags (int flags) {return !(flags & ~ALL_FLAGS);} + + +// +// Given the first four bytes of a file, returns true if the +// file is probably an OpenEXR image file, false if not. +// + +IMF_EXPORT +bool isImfMagic (const char bytes[4]); + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + + + + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfWav.h b/OpenEXR/include/OpenEXR/ImfWav.h new file mode 100644 index 0000000..9751433 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfWav.h @@ -0,0 +1,78 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002, 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. +// +/////////////////////////////////////////////////////////////////////////// + + + +#ifndef INCLUDED_IMF_WAV_H +#define INCLUDED_IMF_WAV_H + +//----------------------------------------------------------------------------- +// +// 16-bit Haar Wavelet encoding and decoding +// +//----------------------------------------------------------------------------- +#include "ImfNamespace.h" +#include "ImfExport.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + + +IMF_EXPORT +void +wav2Encode + (unsigned short *in, // io: values in[y][x] are transformed in place + int nx, // i : x size + int ox, // i : x offset + int ny, // i : y size + int oy, // i : y offset + unsigned short mx); // i : maximum in[x][y] value + +IMF_EXPORT +void +wav2Decode + (unsigned short *in, // io: values in[y][x] are transformed in place + int nx, // i : x size + int ox, // i : x offset + int ny, // i : y size + int oy, // i : y offset + unsigned short mx); // i : maximum in[x][y] value + + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + + + + +#endif diff --git a/OpenEXR/include/OpenEXR/ImfXdr.h b/OpenEXR/include/OpenEXR/ImfXdr.h new file mode 100644 index 0000000..0af6f67 --- /dev/null +++ b/OpenEXR/include/OpenEXR/ImfXdr.h @@ -0,0 +1,927 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002, 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. +// +/////////////////////////////////////////////////////////////////////////// + + +#ifndef INCLUDED_IMF_XDR_H +#define INCLUDED_IMF_XDR_H + + +//---------------------------------------------------------------------------- +// +// Xdr -- routines to convert data between the machine's native +// format and a machine-independent external data representation: +// +// write (T &o, S v); converts a value, v, of type S +// into a machine-independent +// representation and stores the +// result in an output buffer, o. +// +// read (T &i, S &v); reads the machine-independent +// representation of a value of type +// S from input buffer i, converts +// the value into the machine's native +// representation, and stores the result +// in v. +// +// size(); returns the size, in bytes, of the +// machine-independent representation +// of an object of type S. +// +// The write() and read() routines are templates; data can be written +// to and read from any output or input buffer type T for which a helper +// class, R, exits. Class R must define a method to store a char array +// in a T, and a method to read a char array from a T: +// +// struct R +// { +// static void +// writeChars (T &o, const char c[/*n*/], int n) +// { +// ... // Write c[0], c[1] ... c[n-1] to output buffer o. +// } +// +// static void +// readChars (T &i, char c[/*n*/], int n) +// { +// ... // Read n characters from input buffer i +// // and copy them to c[0], c[1] ... c[n-1]. +// } +// }; +// +// Example - writing to and reading from iostreams: +// +// struct CharStreamIO +// { +// static void +// writeChars (ostream &os, const char c[], int n) +// { +// os.write (c, n); +// } +// +// static void +// readChars (istream &is, char c[], int n) +// { +// is.read (c, n); +// } +// }; +// +// ... +// +// Xdr::write (os, 3); +// Xdr::write (os, 5.0); +// +//---------------------------------------------------------------------------- + +#include "ImfInt64.h" +#include "IexMathExc.h" +#include "half.h" +#include + +#include "ImfNamespace.h" + +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER + +namespace Xdr { + + +//------------------------------- +// Write data to an output stream +//------------------------------- + +template +void +write (T &out, bool v); + +template +void +write (T &out, char v); + +template +void +write (T &out, signed char v); + +template +void +write (T &out, unsigned char v); + +template +void +write (T &out, signed short v); + +template +void +write (T &out, unsigned short v); + +template +void +write (T &out, signed int v); + +template +void +write (T &out, unsigned int v); + +template +void +write (T &out, signed long v); + +template +void +write (T &out, unsigned long v); + +#if ULONG_MAX != 18446744073709551615LU + + template + void + write (T &out, Int64 v); + +#endif + +template +void +write (T &out, float v); + +template +void +write (T &out, double v); + +template +void +write (T &out, half v); + +template +void +write (T &out, const char v[/*n*/], int n); // fixed-size char array + +template +void +write (T &out, const char v[]); // zero-terminated string + + +//----------------------------------------- +// Append padding bytes to an output stream +//----------------------------------------- + +template +void +pad (T &out, int n); // write n padding bytes + + + +//------------------------------- +// Read data from an input stream +//------------------------------- + +template +void +read (T &in, bool &v); + +template +void +read (T &in, char &v); + +template +void +read (T &in, signed char &v); + +template +void +read (T &in, unsigned char &v); + +template +void +read (T &in, signed short &v); + +template +void +read (T &in, unsigned short &v); + +template +void +read (T &in, signed int &v); + +template +void +read (T &in, unsigned int &v); + +template +void +read (T &in, signed long &v); + +template +void +read (T &in, unsigned long &v); + +#if ULONG_MAX != 18446744073709551615LU + + template + void + read (T &in, Int64 &v); + +#endif + +template +void +read (T &in, float &v); + +template +void +read (T &in, double &v); + +template +void +read (T &in, half &v); + +template +void +read (T &in, char v[/*n*/], int n); // fixed-size char array + +template +void +read (T &in, int n, char v[/*n*/]); // zero-terminated string + + +//------------------------------------------- +// Skip over padding bytes in an input stream +//------------------------------------------- + +template +void +skip (T &in, int n); // skip n padding bytes + + + +//-------------------------------------- +// Size of the machine-independent +// representation of an object of type S +//-------------------------------------- + +template +int +size (); + + +//--------------- +// Implementation +//--------------- + +template +inline void +writeSignedChars (T &out, const signed char c[], int n) +{ + S::writeChars (out, (const char *) c, n); +} + + +template +inline void +writeUnsignedChars (T &out, const unsigned char c[], int n) +{ + S::writeChars (out, (const char *) c, n); +} + + +template +inline void +readSignedChars (T &in, signed char c[], int n) +{ + S::readChars (in, (char *) c, n); +} + + +template +inline void +readUnsignedChars (T &in, unsigned char c[], int n) +{ + S::readChars (in, (char *) c, n); +} + + +template +inline void +write (T &out, bool v) +{ + char c = !!v; + S::writeChars (out, &c, 1); +} + + +template +inline void +write (T &out, char v) +{ + S::writeChars (out, &v, 1); +} + + +template +inline void +write (T &out, signed char v) +{ + writeSignedChars (out, &v, 1); +} + + +template +inline void +write (T &out, unsigned char v) +{ + writeUnsignedChars (out, &v, 1); +} + + +template +void +write (T &out, signed short v) +{ + signed char b[2]; + + b[0] = (signed char) (v); + b[1] = (signed char) (v >> 8); + + writeSignedChars (out, b, 2); +} + + +template +void +write (T &out, unsigned short v) +{ + unsigned char b[2]; + + b[0] = (unsigned char) (v); + b[1] = (unsigned char) (v >> 8); + + writeUnsignedChars (out, b, 2); +} + + +template +void +write (T &out, signed int v) +{ + signed char b[4]; + + b[0] = (signed char) (v); + b[1] = (signed char) (v >> 8); + b[2] = (signed char) (v >> 16); + b[3] = (signed char) (v >> 24); + + writeSignedChars (out, b, 4); +} + + +template +void +write (T &out, unsigned int v) +{ + unsigned char b[4]; + + b[0] = (unsigned char) (v); + b[1] = (unsigned char) (v >> 8); + b[2] = (unsigned char) (v >> 16); + b[3] = (unsigned char) (v >> 24); + + writeUnsignedChars (out, b, 4); +} + + +template +void +write (T &out, signed long v) +{ + signed char b[8]; + + b[0] = (signed char) (v); + b[1] = (signed char) (v >> 8); + b[2] = (signed char) (v >> 16); + b[3] = (signed char) (v >> 24); + + #if LONG_MAX == 2147483647 + + if (v >= 0) + { + b[4] = 0; + b[5] = 0; + b[6] = 0; + b[7] = 0; + } + else + { + b[4] = ~0; + b[5] = ~0; + b[6] = ~0; + b[7] = ~0; + } + + #elif LONG_MAX == 9223372036854775807L + + b[4] = (signed char) (v >> 32); + b[5] = (signed char) (v >> 40); + b[6] = (signed char) (v >> 48); + b[7] = (signed char) (v >> 56); + + #else + + #error write (T &out, signed long v) not implemented + + #endif + + writeSignedChars (out, b, 8); +} + + +template +void +write (T &out, unsigned long v) +{ + unsigned char b[8]; + + b[0] = (unsigned char) (v); + b[1] = (unsigned char) (v >> 8); + b[2] = (unsigned char) (v >> 16); + b[3] = (unsigned char) (v >> 24); + + #if ULONG_MAX == 4294967295U + + b[4] = 0; + b[5] = 0; + b[6] = 0; + b[7] = 0; + + #elif ULONG_MAX == 18446744073709551615LU + + b[4] = (unsigned char) (v >> 32); + b[5] = (unsigned char) (v >> 40); + b[6] = (unsigned char) (v >> 48); + b[7] = (unsigned char) (v >> 56); + + #else + + #error write (T &out, unsigned long v) not implemented + + #endif + + writeUnsignedChars (out, b, 8); +} + + +#if ULONG_MAX != 18446744073709551615LU + + template + void + write (T &out, Int64 v) + { + unsigned char b[8]; + + b[0] = (unsigned char) (v); + b[1] = (unsigned char) (v >> 8); + b[2] = (unsigned char) (v >> 16); + b[3] = (unsigned char) (v >> 24); + b[4] = (unsigned char) (v >> 32); + b[5] = (unsigned char) (v >> 40); + b[6] = (unsigned char) (v >> 48); + b[7] = (unsigned char) (v >> 56); + + writeUnsignedChars (out, b, 8); + } + +#endif + + +template +void +write (T &out, float v) +{ + union {unsigned int i; float f;} u; + u.f = v; + + unsigned char b[4]; + + b[0] = (unsigned char) (u.i); + b[1] = (unsigned char) (u.i >> 8); + b[2] = (unsigned char) (u.i >> 16); + b[3] = (unsigned char) (u.i >> 24); + + writeUnsignedChars (out, b, 4); +} + + +template +void +write (T &out, double v) +{ + union {Int64 i; double d;} u; + u.d = v; + + unsigned char b[8]; + + b[0] = (unsigned char) (u.i); + b[1] = (unsigned char) (u.i >> 8); + b[2] = (unsigned char) (u.i >> 16); + b[3] = (unsigned char) (u.i >> 24); + b[4] = (unsigned char) (u.i >> 32); + b[5] = (unsigned char) (u.i >> 40); + b[6] = (unsigned char) (u.i >> 48); + b[7] = (unsigned char) (u.i >> 56); + + writeUnsignedChars (out, b, 8); +} + + +template +inline void +write (T &out, half v) +{ + unsigned char b[2]; + + b[0] = (unsigned char) (v.bits()); + b[1] = (unsigned char) (v.bits() >> 8); + + writeUnsignedChars (out, b, 2); +} + + +template +inline void +write (T &out, const char v[], int n) // fixed-size char array +{ + S::writeChars (out, v, n); +} + + +template +void +write (T &out, const char v[]) // zero-terminated string +{ + while (*v) + { + S::writeChars (out, v, 1); + ++v; + } + + S::writeChars (out, v, 1); +} + + +template +void +pad (T &out, int n) // add n padding bytes +{ + for (int i = 0; i < n; i++) + { + const char c = 0; + S::writeChars (out, &c, 1); + } +} + + +template +inline void +read (T &in, bool &v) +{ + char c; + + S::readChars (in, &c, 1); + v = !!c; +} + + +template +inline void +read (T &in, char &v) +{ + S::readChars (in, &v, 1); +} + + +template +inline void +read (T &in, signed char &v) +{ + readSignedChars (in, &v, 1); +} + + +template +inline void +read (T &in, unsigned char &v) +{ + readUnsignedChars (in, &v, 1); +} + + +template +void +read (T &in, signed short &v) +{ + signed char b[2]; + + readSignedChars (in, b, 2); + + v = (b[0] & 0x00ff) | + (b[1] << 8); +} + + +template +void +read (T &in, unsigned short &v) +{ + unsigned char b[2]; + + readUnsignedChars (in, b, 2); + + v = (b[0] & 0x00ff) | + (b[1] << 8); +} + + +template +void +read (T &in, signed int &v) +{ + signed char b[4]; + + readSignedChars (in, b, 4); + + v = (b[0] & 0x000000ff) | + ((b[1] << 8) & 0x0000ff00) | + ((b[2] << 16) & 0x00ff0000) | + (b[3] << 24); +} + + +template +void +read (T &in, unsigned int &v) +{ + unsigned char b[4]; + + readUnsignedChars (in, b, 4); + + v = (b[0] & 0x000000ff) | + ((b[1] << 8) & 0x0000ff00) | + ((b[2] << 16) & 0x00ff0000) | + (b[3] << 24); +} + + +template +void +read (T &in, signed long &v) +{ + signed char b[8]; + + readSignedChars (in, b, 8); + + #if LONG_MAX == 2147483647 + + v = (b[0] & 0x000000ff) | + ((b[1] << 8) & 0x0000ff00) | + ((b[2] << 16) & 0x00ff0000) | + (b[3] << 24); + + if (( b[4] || b[5] || b[6] || b[7]) && + (~b[4] || ~b[5] || ~b[6] || ~b[7])) + { + throw IEX_NAMESPACE::OverflowExc ("Long int overflow - read a large " + "64-bit integer in a 32-bit process."); + } + + #elif LONG_MAX == 9223372036854775807L + + v = ((long) b[0] & 0x00000000000000ff) | + (((long) b[1] << 8) & 0x000000000000ff00) | + (((long) b[2] << 16) & 0x0000000000ff0000) | + (((long) b[3] << 24) & 0x00000000ff000000) | + (((long) b[4] << 32) & 0x000000ff00000000) | + (((long) b[5] << 40) & 0x0000ff0000000000) | + (((long) b[6] << 48) & 0x00ff000000000000) | + ((long) b[7] << 56); + + #else + + #error read (T &in, signed long &v) not implemented + + #endif +} + + +template +void +read (T &in, unsigned long &v) +{ + unsigned char b[8]; + + readUnsignedChars (in, b, 8); + + #if ULONG_MAX == 4294967295U + + v = (b[0] & 0x000000ff) | + ((b[1] << 8) & 0x0000ff00) | + ((b[2] << 16) & 0x00ff0000) | + (b[3] << 24); + + if (b[4] || b[5] || b[6] || b[7]) + { + throw IEX_NAMESPACE::OverflowExc ("Long int overflow - read a large " + "64-bit integer in a 32-bit process."); + } + + #elif ULONG_MAX == 18446744073709551615LU + + v = ((unsigned long) b[0] & 0x00000000000000ff) | + (((unsigned long) b[1] << 8) & 0x000000000000ff00) | + (((unsigned long) b[2] << 16) & 0x0000000000ff0000) | + (((unsigned long) b[3] << 24) & 0x00000000ff000000) | + (((unsigned long) b[4] << 32) & 0x000000ff00000000) | + (((unsigned long) b[5] << 40) & 0x0000ff0000000000) | + (((unsigned long) b[6] << 48) & 0x00ff000000000000) | + ((unsigned long) b[7] << 56); + + #else + + #error read (T &in, unsigned long &v) not implemented + + #endif +} + + +#if ULONG_MAX != 18446744073709551615LU + + template + void + read (T &in, Int64 &v) + { + unsigned char b[8]; + + readUnsignedChars (in, b, 8); + + v = ((Int64) b[0] & 0x00000000000000ffLL) | + (((Int64) b[1] << 8) & 0x000000000000ff00LL) | + (((Int64) b[2] << 16) & 0x0000000000ff0000LL) | + (((Int64) b[3] << 24) & 0x00000000ff000000LL) | + (((Int64) b[4] << 32) & 0x000000ff00000000LL) | + (((Int64) b[5] << 40) & 0x0000ff0000000000LL) | + (((Int64) b[6] << 48) & 0x00ff000000000000LL) | + ((Int64) b[7] << 56); + } + +#endif + + +template +void +read (T &in, float &v) +{ + unsigned char b[4]; + + readUnsignedChars (in, b, 4); + + union {unsigned int i; float f;} u; + + u.i = (b[0] & 0x000000ff) | + ((b[1] << 8) & 0x0000ff00) | + ((b[2] << 16) & 0x00ff0000) | + (b[3] << 24); + + v = u.f; +} + + +template +void +read (T &in, double &v) +{ + unsigned char b[8]; + + readUnsignedChars (in, b, 8); + + union {Int64 i; double d;} u; + + u.i = ((Int64) b[0] & 0x00000000000000ffULL) | + (((Int64) b[1] << 8) & 0x000000000000ff00ULL) | + (((Int64) b[2] << 16) & 0x0000000000ff0000ULL) | + (((Int64) b[3] << 24) & 0x00000000ff000000ULL) | + (((Int64) b[4] << 32) & 0x000000ff00000000ULL) | + (((Int64) b[5] << 40) & 0x0000ff0000000000ULL) | + (((Int64) b[6] << 48) & 0x00ff000000000000ULL) | + ((Int64) b[7] << 56); + + v = u.d; +} + + +template +inline void +read (T &in, half &v) +{ + unsigned char b[2]; + + readUnsignedChars (in, b, 2); + + v.setBits ((b[0] & 0x00ff) | (b[1] << 8)); +} + + +template +inline void +read (T &in, char v[], int n) // fixed-size char array +{ + S::readChars (in, v, n); +} + + +template +void +read (T &in, int n, char v[]) // zero-terminated string +{ + while (n >= 0) + { + S::readChars (in, v, 1); + + if (*v == 0) + break; + + --n; + ++v; + } +} + + +template +void +skip (T &in, int n) // skip n padding bytes +{ + char c[1024]; + + while (n >= (int) sizeof (c)) + { + if (!S::readChars (in, c, sizeof (c))) + return; + + n -= sizeof (c); + } + + if (n >= 1) + S::readChars (in, c, n); +} + + +template <> inline int size () {return 1;} +template <> inline int size () {return 1;} +template <> inline int size () {return 1;} +template <> inline int size () {return 1;} +template <> inline int size () {return 2;} +template <> inline int size () {return 2;} +template <> inline int size () {return 4;} +template <> inline int size () {return 4;} +template <> inline int size () {return 8;} +template <> inline int size () {return 8;} +template <> inline int size () {return 8;} +template <> inline int size () {return 4;} +template <> inline int size () {return 8;} +template <> inline int size () {return 2;} + + +} // namespace Xdr +OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT + + +#if defined (OPENEXR_IMF_INTERNAL_NAMESPACE_AUTO_EXPOSE) +namespace Imf{using namespace OPENEXR_IMF_INTERNAL_NAMESPACE;} +#endif + + +#endif diff --git a/OpenEXR/include/OpenEXR/OpenEXRConfig.h b/OpenEXR/include/OpenEXR/OpenEXRConfig.h new file mode 100644 index 0000000..a92067d --- /dev/null +++ b/OpenEXR/include/OpenEXR/OpenEXRConfig.h @@ -0,0 +1,73 @@ +/* config/OpenEXRConfig.h. Generated from OpenEXRConfig.h.in by configure. */ +// +// Define and set to 1 if the target system supports a proc filesystem +// compatible with the Linux kernel's proc filesystem. Note that this +// is only used by a program in the IlmImfTest test suite, it's not +// used by any OpenEXR library or application code. +// + +#define OPENEXR_IMF_HAVE_LINUX_PROCFS 1 + +// +// Define and set to 1 if the target system is a Darwin-based system +// (e.g., OS X). +// + +/* #undef OPENEXR_IMF_HAVE_DARWIN */ + +// +// Define and set to 1 if the target system has a complete +// implementation, specifically if it supports the std::right +// formatter. +// + +#define OPENEXR_IMF_HAVE_COMPLETE_IOMANIP 1 + +// +// Define and set to 1 if the target system has support for large +// stack sizes. +// + +#define OPENEXR_IMF_HAVE_LARGE_STACK 1 + +// +// Define if we can support GCC style inline asm with AVX instructions +// + +#define OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX 1 + +// +// Define if we can use sysconf(_SC_NPROCESSORS_ONLN) to get CPU count +// + +#define OPENEXR_IMF_HAVE_SYSCONF_NPROCESSORS_ONLN 1 + +// +// Current internal library namepace name +// +#define OPENEXR_IMF_INTERNAL_NAMESPACE_CUSTOM 1 +#define OPENEXR_IMF_INTERNAL_NAMESPACE Imf_2_2 + +// +// Current public user namepace name +// + +/* #undef OPENEXR_IMF_NAMESPACE_CUSTOM */ +#define OPENEXR_IMF_NAMESPACE Imf + +// +// Version string for runtime access +// + +#define OPENEXR_VERSION_STRING "2.2.0" +#define OPENEXR_PACKAGE_STRING "OpenEXR 2.2.0" + +#define OPENEXR_VERSION_MAJOR 2 +#define OPENEXR_VERSION_MINOR 2 +#define OPENEXR_VERSION_PATCH 0 + +// Version as a single hex number, e.g. 0x01000300 == 1.0.3 +#define OPENEXR_VERSION_HEX ((OPENEXR_VERSION_MAJOR << 24) | \ + (OPENEXR_VERSION_MINOR << 16) | \ + (OPENEXR_VERSION_PATCH << 8)) + diff --git a/OpenEXR/include/OpenEXR/half.h b/OpenEXR/include/OpenEXR/half.h new file mode 100644 index 0000000..f78e4f6 --- /dev/null +++ b/OpenEXR/include/OpenEXR/half.h @@ -0,0 +1,757 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002, 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. +// +/////////////////////////////////////////////////////////////////////////// + +// Primary authors: +// Florian Kainz +// Rod Bogart + +//--------------------------------------------------------------------------- +// +// half -- a 16-bit floating point number class: +// +// Type half can represent positive and negative numbers whose +// magnitude is between roughly 6.1e-5 and 6.5e+4 with a relative +// error of 9.8e-4; numbers smaller than 6.1e-5 can be represented +// with an absolute error of 6.0e-8. All integers from -2048 to +// +2048 can be represented exactly. +// +// Type half behaves (almost) like the built-in C++ floating point +// types. In arithmetic expressions, half, float and double can be +// mixed freely. Here are a few examples: +// +// half a (3.5); +// float b (a + sqrt (a)); +// a += b; +// b += a; +// b = a + 7; +// +// Conversions from half to float are lossless; all half numbers +// are exactly representable as floats. +// +// Conversions from float to half may not preserve a float's value +// exactly. If a float is not representable as a half, then the +// float value is rounded to the nearest representable half. If a +// float value is exactly in the middle between the two closest +// representable half values, then the float value is rounded to +// the closest half whose least significant bit is zero. +// +// Overflows during float-to-half conversions cause arithmetic +// exceptions. An overflow occurs when the float value to be +// converted is too large to be represented as a half, or if the +// float value is an infinity or a NAN. +// +// The implementation of type half makes the following assumptions +// about the implementation of the built-in C++ types: +// +// float is an IEEE 754 single-precision number +// sizeof (float) == 4 +// sizeof (unsigned int) == sizeof (float) +// alignof (unsigned int) == alignof (float) +// sizeof (unsigned short) == 2 +// +//--------------------------------------------------------------------------- + +#ifndef _HALF_H_ +#define _HALF_H_ + +#include "halfExport.h" // for definition of HALF_EXPORT +#include + +class half +{ + public: + + //------------- + // Constructors + //------------- + + half (); // no initialization + half (float f); + + + //-------------------- + // Conversion to float + //-------------------- + + operator float () const; + + + //------------ + // Unary minus + //------------ + + half operator - () const; + + + //----------- + // Assignment + //----------- + + half & operator = (half h); + half & operator = (float f); + + half & operator += (half h); + half & operator += (float f); + + half & operator -= (half h); + half & operator -= (float f); + + half & operator *= (half h); + half & operator *= (float f); + + half & operator /= (half h); + half & operator /= (float f); + + + //--------------------------------------------------------- + // Round to n-bit precision (n should be between 0 and 10). + // After rounding, the significand's 10-n least significant + // bits will be zero. + //--------------------------------------------------------- + + half round (unsigned int n) const; + + + //-------------------------------------------------------------------- + // Classification: + // + // h.isFinite() returns true if h is a normalized number, + // a denormalized number or zero + // + // h.isNormalized() returns true if h is a normalized number + // + // h.isDenormalized() returns true if h is a denormalized number + // + // h.isZero() returns true if h is zero + // + // h.isNan() returns true if h is a NAN + // + // h.isInfinity() returns true if h is a positive + // or a negative infinity + // + // h.isNegative() returns true if the sign bit of h + // is set (negative) + //-------------------------------------------------------------------- + + bool isFinite () const; + bool isNormalized () const; + bool isDenormalized () const; + bool isZero () const; + bool isNan () const; + bool isInfinity () const; + bool isNegative () const; + + + //-------------------------------------------- + // Special values + // + // posInf() returns +infinity + // + // negInf() returns -infinity + // + // qNan() returns a NAN with the bit + // pattern 0111111111111111 + // + // sNan() returns a NAN with the bit + // pattern 0111110111111111 + //-------------------------------------------- + + static half posInf (); + static half negInf (); + static half qNan (); + static half sNan (); + + + //-------------------------------------- + // Access to the internal representation + //-------------------------------------- + + HALF_EXPORT unsigned short bits () const; + HALF_EXPORT void setBits (unsigned short bits); + + + public: + + union uif + { + unsigned int i; + float f; + }; + + private: + + HALF_EXPORT static short convert (int i); + HALF_EXPORT static float overflow (); + + unsigned short _h; + + HALF_EXPORT static const uif _toFloat[1 << 16]; + HALF_EXPORT static const unsigned short _eLut[1 << 9]; +}; + + + +//----------- +// Stream I/O +//----------- + +HALF_EXPORT std::ostream & operator << (std::ostream &os, half h); +HALF_EXPORT std::istream & operator >> (std::istream &is, half &h); + + +//---------- +// Debugging +//---------- + +HALF_EXPORT void printBits (std::ostream &os, half h); +HALF_EXPORT void printBits (std::ostream &os, float f); +HALF_EXPORT void printBits (char c[19], half h); +HALF_EXPORT void printBits (char c[35], float f); + + +//------------------------------------------------------------------------- +// Limits +// +// Visual C++ will complain if HALF_MIN, HALF_NRM_MIN etc. are not float +// constants, but at least one other compiler (gcc 2.96) produces incorrect +// results if they are. +//------------------------------------------------------------------------- + +#if (defined _WIN32 || defined _WIN64) && defined _MSC_VER + + #define HALF_MIN 5.96046448e-08f // Smallest positive half + + #define HALF_NRM_MIN 6.10351562e-05f // Smallest positive normalized half + + #define HALF_MAX 65504.0f // Largest positive half + + #define HALF_EPSILON 0.00097656f // Smallest positive e for which + // half (1.0 + e) != half (1.0) +#else + + #define HALF_MIN 5.96046448e-08 // Smallest positive half + + #define HALF_NRM_MIN 6.10351562e-05 // Smallest positive normalized half + + #define HALF_MAX 65504.0 // Largest positive half + + #define HALF_EPSILON 0.00097656 // Smallest positive e for which + // half (1.0 + e) != half (1.0) +#endif + + +#define HALF_MANT_DIG 11 // Number of digits in mantissa + // (significand + hidden leading 1) + +#define HALF_DIG 2 // Number of base 10 digits that + // can be represented without change + +#define HALF_RADIX 2 // Base of the exponent + +#define HALF_MIN_EXP -13 // Minimum negative integer such that + // HALF_RADIX raised to the power of + // one less than that integer is a + // normalized half + +#define HALF_MAX_EXP 16 // Maximum positive integer such that + // HALF_RADIX raised to the power of + // one less than that integer is a + // normalized half + +#define HALF_MIN_10_EXP -4 // Minimum positive integer such + // that 10 raised to that power is + // a normalized half + +#define HALF_MAX_10_EXP 4 // Maximum positive integer such + // that 10 raised to that power is + // a normalized half + + +//--------------------------------------------------------------------------- +// +// Implementation -- +// +// Representation of a float: +// +// We assume that a float, f, is an IEEE 754 single-precision +// floating point number, whose bits are arranged as follows: +// +// 31 (msb) +// | +// | 30 23 +// | | | +// | | | 22 0 (lsb) +// | | | | | +// X XXXXXXXX XXXXXXXXXXXXXXXXXXXXXXX +// +// s e m +// +// S is the sign-bit, e is the exponent and m is the significand. +// +// If e is between 1 and 254, f is a normalized number: +// +// s e-127 +// f = (-1) * 2 * 1.m +// +// If e is 0, and m is not zero, f is a denormalized number: +// +// s -126 +// f = (-1) * 2 * 0.m +// +// If e and m are both zero, f is zero: +// +// f = 0.0 +// +// If e is 255, f is an "infinity" or "not a number" (NAN), +// depending on whether m is zero or not. +// +// Examples: +// +// 0 00000000 00000000000000000000000 = 0.0 +// 0 01111110 00000000000000000000000 = 0.5 +// 0 01111111 00000000000000000000000 = 1.0 +// 0 10000000 00000000000000000000000 = 2.0 +// 0 10000000 10000000000000000000000 = 3.0 +// 1 10000101 11110000010000000000000 = -124.0625 +// 0 11111111 00000000000000000000000 = +infinity +// 1 11111111 00000000000000000000000 = -infinity +// 0 11111111 10000000000000000000000 = NAN +// 1 11111111 11111111111111111111111 = NAN +// +// Representation of a half: +// +// Here is the bit-layout for a half number, h: +// +// 15 (msb) +// | +// | 14 10 +// | | | +// | | | 9 0 (lsb) +// | | | | | +// X XXXXX XXXXXXXXXX +// +// s e m +// +// S is the sign-bit, e is the exponent and m is the significand. +// +// If e is between 1 and 30, h is a normalized number: +// +// s e-15 +// h = (-1) * 2 * 1.m +// +// If e is 0, and m is not zero, h is a denormalized number: +// +// S -14 +// h = (-1) * 2 * 0.m +// +// If e and m are both zero, h is zero: +// +// h = 0.0 +// +// If e is 31, h is an "infinity" or "not a number" (NAN), +// depending on whether m is zero or not. +// +// Examples: +// +// 0 00000 0000000000 = 0.0 +// 0 01110 0000000000 = 0.5 +// 0 01111 0000000000 = 1.0 +// 0 10000 0000000000 = 2.0 +// 0 10000 1000000000 = 3.0 +// 1 10101 1111000001 = -124.0625 +// 0 11111 0000000000 = +infinity +// 1 11111 0000000000 = -infinity +// 0 11111 1000000000 = NAN +// 1 11111 1111111111 = NAN +// +// Conversion: +// +// Converting from a float to a half requires some non-trivial bit +// manipulations. In some cases, this makes conversion relatively +// slow, but the most common case is accelerated via table lookups. +// +// Converting back from a half to a float is easier because we don't +// have to do any rounding. In addition, there are only 65536 +// different half numbers; we can convert each of those numbers once +// and store the results in a table. Later, all conversions can be +// done using only simple table lookups. +// +//--------------------------------------------------------------------------- + + +//-------------------- +// Simple constructors +//-------------------- + +inline +half::half () +{ + // no initialization +} + + +//---------------------------- +// Half-from-float constructor +//---------------------------- + +inline +half::half (float f) +{ + uif x; + + x.f = f; + + if (f == 0) + { + // + // Common special case - zero. + // Preserve the zero's sign bit. + // + + _h = (x.i >> 16); + } + else + { + // + // We extract the combined sign and exponent, e, from our + // floating-point number, f. Then we convert e to the sign + // and exponent of the half number via a table lookup. + // + // For the most common case, where a normalized half is produced, + // the table lookup returns a non-zero value; in this case, all + // we have to do is round f's significand to 10 bits and combine + // the result with e. + // + // For all other cases (overflow, zeroes, denormalized numbers + // resulting from underflow, infinities and NANs), the table + // lookup returns zero, and we call a longer, non-inline function + // to do the float-to-half conversion. + // + + register int e = (x.i >> 23) & 0x000001ff; + + e = _eLut[e]; + + if (e) + { + // + // Simple case - round the significand, m, to 10 + // bits and combine it with the sign and exponent. + // + + register int m = x.i & 0x007fffff; + _h = e + ((m + 0x00000fff + ((m >> 13) & 1)) >> 13); + } + else + { + // + // Difficult case - call a function. + // + + _h = convert (x.i); + } + } +} + + +//------------------------------------------ +// Half-to-float conversion via table lookup +//------------------------------------------ + +inline +half::operator float () const +{ + return _toFloat[_h].f; +} + + +//------------------------- +// Round to n-bit precision +//------------------------- + +inline half +half::round (unsigned int n) const +{ + // + // Parameter check. + // + + if (n >= 10) + return *this; + + // + // Disassemble h into the sign, s, + // and the combined exponent and significand, e. + // + + unsigned short s = _h & 0x8000; + unsigned short e = _h & 0x7fff; + + // + // Round the exponent and significand to the nearest value + // where ones occur only in the (10-n) most significant bits. + // Note that the exponent adjusts automatically if rounding + // up causes the significand to overflow. + // + + e >>= 9 - n; + e += e & 1; + e <<= 9 - n; + + // + // Check for exponent overflow. + // + + if (e >= 0x7c00) + { + // + // Overflow occurred -- truncate instead of rounding. + // + + e = _h; + e >>= 10 - n; + e <<= 10 - n; + } + + // + // Put the original sign bit back. + // + + half h; + h._h = s | e; + + return h; +} + + +//----------------------- +// Other inline functions +//----------------------- + +inline half +half::operator - () const +{ + half h; + h._h = _h ^ 0x8000; + return h; +} + + +inline half & +half::operator = (half h) +{ + _h = h._h; + return *this; +} + + +inline half & +half::operator = (float f) +{ + *this = half (f); + return *this; +} + + +inline half & +half::operator += (half h) +{ + *this = half (float (*this) + float (h)); + return *this; +} + + +inline half & +half::operator += (float f) +{ + *this = half (float (*this) + f); + return *this; +} + + +inline half & +half::operator -= (half h) +{ + *this = half (float (*this) - float (h)); + return *this; +} + + +inline half & +half::operator -= (float f) +{ + *this = half (float (*this) - f); + return *this; +} + + +inline half & +half::operator *= (half h) +{ + *this = half (float (*this) * float (h)); + return *this; +} + + +inline half & +half::operator *= (float f) +{ + *this = half (float (*this) * f); + return *this; +} + + +inline half & +half::operator /= (half h) +{ + *this = half (float (*this) / float (h)); + return *this; +} + + +inline half & +half::operator /= (float f) +{ + *this = half (float (*this) / f); + return *this; +} + + +inline bool +half::isFinite () const +{ + unsigned short e = (_h >> 10) & 0x001f; + return e < 31; +} + + +inline bool +half::isNormalized () const +{ + unsigned short e = (_h >> 10) & 0x001f; + return e > 0 && e < 31; +} + + +inline bool +half::isDenormalized () const +{ + unsigned short e = (_h >> 10) & 0x001f; + unsigned short m = _h & 0x3ff; + return e == 0 && m != 0; +} + + +inline bool +half::isZero () const +{ + return (_h & 0x7fff) == 0; +} + + +inline bool +half::isNan () const +{ + unsigned short e = (_h >> 10) & 0x001f; + unsigned short m = _h & 0x3ff; + return e == 31 && m != 0; +} + + +inline bool +half::isInfinity () const +{ + unsigned short e = (_h >> 10) & 0x001f; + unsigned short m = _h & 0x3ff; + return e == 31 && m == 0; +} + + +inline bool +half::isNegative () const +{ + return (_h & 0x8000) != 0; +} + + +inline half +half::posInf () +{ + half h; + h._h = 0x7c00; + return h; +} + + +inline half +half::negInf () +{ + half h; + h._h = 0xfc00; + return h; +} + + +inline half +half::qNan () +{ + half h; + h._h = 0x7fff; + return h; +} + + +inline half +half::sNan () +{ + half h; + h._h = 0x7dff; + return h; +} + + +inline unsigned short +half::bits () const +{ + return _h; +} + + +inline void +half::setBits (unsigned short bits) +{ + _h = bits; +} + +#endif diff --git a/OpenEXR/include/OpenEXR/halfExport.h b/OpenEXR/include/OpenEXR/halfExport.h new file mode 100644 index 0000000..3a0c86a --- /dev/null +++ b/OpenEXR/include/OpenEXR/halfExport.h @@ -0,0 +1,27 @@ +#ifndef HALFEXPORT_H +#define HALFEXPORT_H + +// +// Copyright (c) 2008 Lucasfilm Entertainment Company Ltd. +// All rights reserved. Used under authorization. +// This material contains the confidential and proprietary +// information of Lucasfilm Entertainment Company and +// may not be copied in whole or in part without the express +// written permission of Lucasfilm Entertainment Company. +// This copyright notice does not imply publication. +// + +#if defined(OPENEXR_DLL) + #if defined(HALF_EXPORTS) + #define HALF_EXPORT __declspec(dllexport) + #else + #define HALF_EXPORT __declspec(dllimport) + #endif + #define HALF_EXPORT_CONST +#else + #define HALF_EXPORT + #define HALF_EXPORT_CONST const +#endif + +#endif // #ifndef HALFEXPORT_H + diff --git a/OpenEXR/include/OpenEXR/halfFunction.h b/OpenEXR/include/OpenEXR/halfFunction.h new file mode 100644 index 0000000..98c1d17 --- /dev/null +++ b/OpenEXR/include/OpenEXR/halfFunction.h @@ -0,0 +1,179 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002, 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. +// +/////////////////////////////////////////////////////////////////////////// + +// Primary authors: +// Florian Kainz +// Rod Bogart + + +//--------------------------------------------------------------------------- +// +// halfFunction -- a class for fast evaluation +// of half --> T functions +// +// The constructor for a halfFunction object, +// +// halfFunction (function, +// domainMin, domainMax, +// defaultValue, +// posInfValue, negInfValue, +// nanValue); +// +// evaluates the function for all finite half values in the interval +// [domainMin, domainMax], and stores the results in a lookup table. +// For finite half values that are not in [domainMin, domainMax], the +// constructor stores defaultValue in the table. For positive infinity, +// negative infinity and NANs, posInfValue, negInfValue and nanValue +// are stored in the table. +// +// The tabulated function can then be evaluated quickly for arbitrary +// half values by calling the the halfFunction object's operator() +// method. +// +// Example: +// +// #include +// #include +// +// halfFunction hsin (sin); +// +// halfFunction hsqrt (sqrt, // function +// 0, HALF_MAX, // domain +// half::qNan(), // sqrt(x) for x < 0 +// half::posInf(), // sqrt(+inf) +// half::qNan(), // sqrt(-inf) +// half::qNan()); // sqrt(nan) +// +// half x = hsin (1); +// half y = hsqrt (3.5); +// +//--------------------------------------------------------------------------- + +#ifndef _HALF_FUNCTION_H_ +#define _HALF_FUNCTION_H_ + +#include "half.h" + +#include "IlmBaseConfig.h" +#ifndef ILMBASE_HAVE_LARGE_STACK +#include // need this for memset +#else +#endif + +#include + + +template +class halfFunction +{ + public: + + //------------ + // Constructor + //------------ + + template + halfFunction (Function f, + half domainMin = -HALF_MAX, + half domainMax = HALF_MAX, + T defaultValue = 0, + T posInfValue = 0, + T negInfValue = 0, + T nanValue = 0); + +#ifndef ILMBASE_HAVE_LARGE_STACK + ~halfFunction () { delete [] _lut; } +#endif + + //----------- + // Evaluation + //----------- + + T operator () (half x) const; + + private: + +#ifdef ILMBASE_HAVE_LARGE_STACK + T _lut[1 << 16]; +#else + T * _lut; +#endif +}; + + +//--------------- +// Implementation +//--------------- + +template +template +halfFunction::halfFunction (Function f, + half domainMin, + half domainMax, + T defaultValue, + T posInfValue, + T negInfValue, + T nanValue) +{ +#ifndef ILMBASE_HAVE_LARGE_STACK + _lut = new T[1<<16]; + memset (_lut, 0 , (1<<16) * sizeof(T)); +#endif + + for (int i = 0; i < (1 << 16); i++) + { + half x; + x.setBits (i); + + if (x.isNan()) + _lut[i] = nanValue; + else if (x.isInfinity()) + _lut[i] = x.isNegative()? negInfValue: posInfValue; + else if (x < domainMin || x > domainMax) + _lut[i] = defaultValue; + else + _lut[i] = f (x); + } +} + + +template +inline T +halfFunction::operator () (half x) const +{ + return _lut[x.bits()]; +} + + +#endif diff --git a/OpenEXR/include/OpenEXR/halfLimits.h b/OpenEXR/include/OpenEXR/halfLimits.h new file mode 100644 index 0000000..404f589 --- /dev/null +++ b/OpenEXR/include/OpenEXR/halfLimits.h @@ -0,0 +1,102 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2002, 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. +// +/////////////////////////////////////////////////////////////////////////// + + +// Primary authors: +// Florian Kainz +// Rod Bogart + + +#ifndef INCLUDED_HALF_LIMITS_H +#define INCLUDED_HALF_LIMITS_H + + +//------------------------------------------------------------------------ +// +// C++ standard library-style numeric_limits for class half +// +//------------------------------------------------------------------------ + +#include +#include "half.h" + +namespace std { + +template <> +class numeric_limits +{ + public: + + static const bool is_specialized = true; + + static half min () throw () {return HALF_NRM_MIN;} + static half max () throw () {return HALF_MAX;} + + static const int digits = HALF_MANT_DIG; + static const int digits10 = HALF_DIG; + static const bool is_signed = true; + static const bool is_integer = false; + static const bool is_exact = false; + static const int radix = HALF_RADIX; + static half epsilon () throw () {return HALF_EPSILON;} + static half round_error () throw () {return HALF_EPSILON / 2;} + + static const int min_exponent = HALF_MIN_EXP; + static const int min_exponent10 = HALF_MIN_10_EXP; + static const int max_exponent = HALF_MAX_EXP; + static const int max_exponent10 = HALF_MAX_10_EXP; + + static const bool has_infinity = true; + static const bool has_quiet_NaN = true; + static const bool has_signaling_NaN = true; + static const float_denorm_style has_denorm = denorm_present; + static const bool has_denorm_loss = false; + static half infinity () throw () {return half::posInf();} + static half quiet_NaN () throw () {return half::qNan();} + static half signaling_NaN () throw () {return half::sNan();} + static half denorm_min () throw () {return HALF_MIN;} + + static const bool is_iec559 = false; + static const bool is_bounded = false; + static const bool is_modulo = false; + + static const bool traps = true; + static const bool tinyness_before = false; + static const float_round_style round_style = round_to_nearest; +}; + + +} // namespace std + +#endif diff --git a/OpenEXR/lib/Half.lib b/OpenEXR/lib/Half.lib new file mode 100644 index 0000000..9972429 Binary files /dev/null and b/OpenEXR/lib/Half.lib differ diff --git a/OpenEXR/lib/Iex-2_2.lib b/OpenEXR/lib/Iex-2_2.lib new file mode 100644 index 0000000..2d86cdd Binary files /dev/null and b/OpenEXR/lib/Iex-2_2.lib differ diff --git a/OpenEXR/lib/IexMath-2_2.lib b/OpenEXR/lib/IexMath-2_2.lib new file mode 100644 index 0000000..a10429d Binary files /dev/null and b/OpenEXR/lib/IexMath-2_2.lib differ diff --git a/OpenEXR/lib/IlmImf-2_2.lib b/OpenEXR/lib/IlmImf-2_2.lib new file mode 100644 index 0000000..1e5211c Binary files /dev/null and b/OpenEXR/lib/IlmImf-2_2.lib differ diff --git a/OpenEXR/lib/IlmImfUtil-2_2.lib b/OpenEXR/lib/IlmImfUtil-2_2.lib new file mode 100644 index 0000000..08ddc7b Binary files /dev/null and b/OpenEXR/lib/IlmImfUtil-2_2.lib differ diff --git a/OpenEXR/lib/IlmThread-2_2.lib b/OpenEXR/lib/IlmThread-2_2.lib new file mode 100644 index 0000000..e78e265 Binary files /dev/null and b/OpenEXR/lib/IlmThread-2_2.lib differ diff --git a/OpenEXR/lib/Imath-2_2.lib b/OpenEXR/lib/Imath-2_2.lib new file mode 100644 index 0000000..f1ce85d Binary files /dev/null and b/OpenEXR/lib/Imath-2_2.lib differ diff --git a/README.md b/README.md new file mode 100644 index 0000000..5eb0129 --- /dev/null +++ b/README.md @@ -0,0 +1,83 @@ +This is an experiment to: + +- Allow applying color changes to single objects in a deep EXR render with clean +edge antialiasing, to avoid the artifacts caused by masks. +- Allow it to be done using simple tools like Photoshop, instead of heavy compositing +packages like Nuke. + +This works with image editing software without additional plugins, and requires no +extra renderer support beyond standard deep EXR rendering and object IDs. This +idea is based on . + +This tool separates objects in a deep EXR file by object ID, and generates a layer +for each file that can be edited separately and blended together. The only trick +is that the layers are blended together with additive blending rather than normal +blending. + +Instructions +------------ + +- Render a deep EXR file with object ID samples. This is tested with Arnold renders +out of Maya. The EXR channel names should be "R", "G", "B", "A", "Z", "ZBack" and +"id". +- Run the tool: + +``` +exrflatten input.exr "output .exr" +``` + +``""`` in the output will be substituted with the object ID, giving filenames like +"output #1.exr". Be sure to include quotes around the output file. + +- In Photoshop, add all output EXRs to a document. Be sure they're aligned identically. +(The easiest way to do this is to zoom out so the whole document is visible, and then +drag each EXR into the document. For some reason, zooming out first convinces Photoshop +to align the image correctly.) Set all layer blending modes to "Linear dodge (add)". +- Add a layer to the bottom, and fill with black. This is needed for the layers to +combine correctly. + +The image should now look like the original render, and you can make color adjustments +to individual object layers. + +Limitations +----------- + +This is an experiment, and hasn't been used on very complex scenes. + +This doesn't currently perform "tidying" of images, which means it will probably give +incorrect results if the EXR file contains volumes (samples with nonzero depth). + +The names of input channels are fixed. The basic names are standardized, but they +can be different if EXR layers are used. + +Transparency in the input file won't work if it shows through to the background and not +onto another object. To apply the original contribution of a sample in a way that will +give the same input in additive blending, the final contribution is used as the alpha +channel. For this to work, the background needs to be solid black. This can be worked +around by using the original image's alpha channel as a mask on the final output. + +Algorithm +--------- + +By reorganizing samples from over blending to additive blending, layer compositing +becomes independent of order: you can add layers together in any order you want and +get the same result. From this we can combine all samples for each object ID and +output a layer for each. + +Layers (or samples for deep EXR images) are normally composited with "over" blending: + +bottom = (top\*alpha) + (bottom\*(1-alpha)) + +Each layer's contribution is added based on its alpha, and the contribution of all +layers underneath it is reduced proportionally. + +Instead of destructively reducing the contribution of lower layers by accumulating +them into a single output buffer, we track the contribution fo each layer individually. +When we add a layer, we reduce the contribution of each layer underneath it, but +remember each layer separately. + +This gives us a list of the (top\*alpha) terms in the above formula, with their future +(\*(1-alpha)) adjustments already applied into their alpha value. (Adding all of these +together would be the same as the original compositing.) We can then combine samples +with the same object ID and save them separately. + diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000..5570e4a --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1 @@ +exrflatten.* diff --git a/bin/Half.dll b/bin/Half.dll new file mode 100644 index 0000000..df9eff1 Binary files /dev/null and b/bin/Half.dll differ diff --git a/bin/Iex-2_2.dll b/bin/Iex-2_2.dll new file mode 100644 index 0000000..07ab165 Binary files /dev/null and b/bin/Iex-2_2.dll differ diff --git a/bin/IexMath-2_2.dll b/bin/IexMath-2_2.dll new file mode 100644 index 0000000..bf33e7a Binary files /dev/null and b/bin/IexMath-2_2.dll differ diff --git a/bin/IlmImf-2_2.dll b/bin/IlmImf-2_2.dll new file mode 100644 index 0000000..4489c43 Binary files /dev/null and b/bin/IlmImf-2_2.dll differ diff --git a/bin/IlmImfUtil-2_2.dll b/bin/IlmImfUtil-2_2.dll new file mode 100644 index 0000000..6fdc89e Binary files /dev/null and b/bin/IlmImfUtil-2_2.dll differ diff --git a/bin/IlmThread-2_2.dll b/bin/IlmThread-2_2.dll new file mode 100644 index 0000000..7ccc537 Binary files /dev/null and b/bin/IlmThread-2_2.dll differ diff --git a/bin/Imath-2_2.dll b/bin/Imath-2_2.dll new file mode 100644 index 0000000..65514a8 Binary files /dev/null and b/bin/Imath-2_2.dll differ diff --git a/empty b/empty deleted file mode 100644 index e69de29..0000000 diff --git a/exrflatten.cpp b/exrflatten.cpp new file mode 100644 index 0000000..bdfce8c --- /dev/null +++ b/exrflatten.cpp @@ -0,0 +1,699 @@ +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; +using namespace Imf; +using namespace Imath; + +const int NO_OBJECT_ID = 0; + +// This currently processes all object IDs at once, which means we need enough memory to hold all +// output buffers at once. We could make a separate pass for each object ID to reduce memory usage, +// so we only need to hold one at a time. +// +// Not currently supported/tested: +// - data window is untested +// - tiled images +// - volumes (samples with non-zero depth) +// - arbitrary channel mappings, including layers (we assume "R", "G", "B", "A", "Z", "ZBack", "id") +// - separate per-color alpha (RA, GA, BA) +// - (and lots of other stuff, EXR is "too general") + +string vssprintf(const char *fmt, va_list va) +{ + // Work around a gcc bug: passing a va_list to vsnprintf alters it. va_list is supposed + // to be by value. + va_list vc; + va_copy(vc, va); + + int iBytes = vsnprintf(NULL, 0, fmt, vc); + char *pBuf = (char*) alloca(iBytes + 1); + vsnprintf(pBuf, iBytes + 1, fmt, va); + return string(pBuf, iBytes); +} + +string ssprintf(const char *fmt, ...) +{ + va_list va; + va_start(va, fmt); + return vssprintf(fmt, va); +} + +string subst(string s, string from, string to) +{ + int start = 0; + while(1) + { + auto pos = s.find(from, start); + if(pos == string::npos) + break; + + string before = s.substr(0, pos); + string after = s.substr(pos + from.size()); + s = before + to + after; + start = pos + to.size(); + } + + return s; +} + +/* + * Return the last named component of dir: + * a/b/c -> c + * a/b/c/ -> c + */ +string basename(const string &dir) +{ + size_t end = dir.find_last_not_of("/\\"); + if( end == dir.npos ) + return ""; + + size_t start = dir.find_last_of("/\\", end); + if(start == dir.npos) + start = 0; + else + ++start; + + return dir.substr(start, end-start+1); +} + +string setExtension(string path, const string &ext) +{ + auto pos = path.rfind('.'); + if(pos != string::npos) + path = path.substr(0, pos); + + return path + ext; +} + +// Given a filename like "abcdef.1234.exr", return "1234". +string getFrameNumberFromFilename(string s) +{ + // abcdef.1234.exr -> abcdef.1234 + s = setExtension(s, ""); + + auto pos = s.rfind("."); + if(pos == string::npos) + return ""; + + string frameString = s.substr(pos+1); + return frameString; +} + +// http://www.openexr.com/TechnicalIntroduction.pdf: +void splitVolumeSample( + float a, float c, // Opacity and color of original sample + float zf, float zb, // Front and back of original sample + float z, // Position of split + float& af, float& cf, // Opacity and color of part closer than z + float& ab, float& cb) // Opacity and color of part further away than z +{ + // Given a volume sample whose front and back are at depths zf and zb respectively, split the + // sample at depth z. Return the opacities and colors of the two parts that result from the split. + // + // The code below is written to avoid excessive rounding errors when the opacity of the original + // sample is very small: + // + // The straightforward computation of the opacity of either part requires evaluating an expression + // of the form + // + // 1 - pow (1-a, x). + // + // However, if a is very small, then 1-a evaluates to 1.0 exactly, and the entire expression + // evaluates to 0.0. + // + // We can avoid this by rewriting the expression as + // + // 1 - exp (x * log (1-a)), + // + // and replacing the call to log() with a call to the function log1p(), which computes the logarithm + // of 1+x without attempting to evaluate the expression 1+x when x is very small. + // + // Now we have + // + // 1 - exp (x * log1p (-a)). + // + // However, if a is very small then the call to exp() returns 1.0, and the overall expression still + // evaluates to 0.0. We can avoid that by replacing the call to exp() with a call to expm1(): + // + // -expm1 (x * log1p (-a)) + // + // expm1(x) computes exp(x) - 1 in such a way that the result is accurate even if x is very small. + + assert (zb > zf && z >= zf && z <= zb); + a = max (0.0f, min (a, 1.0f)); + if (a == 1) + { + af = ab = 1; + cf = cb = c; + } + else + { + float xf = (z - zf) / (zb - zf); + float xb = (zb - z) / (zb - zf); + if (a > numeric_limits::min()) + { + af = -expm1 (xf * log1p (-a)); + cf = (af / a) * c; + ab = -expm1 (xb * log1p (-a)); + cb = (ab / a) * c; + } + else + { + af = a * xf; + cf = c * xf; + ab = a * xb; + cb = c * xb; + } + } +} + +void mergeOverlappingSamples( + float a1, float c1, // Opacity and color of first sample + float a2, float c2, // Opacity and color of second sample + float &am, float &cm) // Opacity and color of merged sample +{ + // This function merges two perfectly overlapping volume or point samples. Given the color and + // opacity of two samples, it returns the color and opacity of the merged sample. + // + // The code below is written to avoid very large rounding errors when the opacity of one or both + // samples is very small: + // + // * The merged opacity must not be computed as 1 - (1-a1) * (1-a2)./ If a1 and a2 are less than + // about half a floating-point epsilon, the expressions (1-a1) and (1-a2) evaluate to 1.0 exactly, + // and the merged opacity becomes 0.0. The error is amplified later in the calculation of the + // merged color. + // + // Changing the calculation of the merged opacity to a1 + a2 - a1*a2 avoids the excessive rounding + // error. + // + // * For small x, the logarithm of 1+x is approximately equal to x, but log(1+x) returns 0 because + // 1+x evaluates to 1.0 exactly. This can lead to large errors in the calculation of the merged + // color if a1 or a2 is very small. + // + // The math library function log1p(x) returns the logarithm of 1+x, but without attempting to + // evaluate the expression 1+x when x is very small. + + a1 = max (0.0f, min (a1, 1.0f)); + a2 = max (0.0f, min (a2, 1.0f)); + am = a1 + a2 - a1 * a2; + if (a1 == 1 && a2 == 1) + cm = (c1 + c2) / 2; + else if (a1 == 1) + cm = c1; + else if (a2 == 1) + cm = c2; + else + { + static const float MAX = numeric_limits::max(); + float u1 = -log1p (-a1); + float v1 = (u1 < a1 * MAX)? u1 / a1: 1; + float u2 = -log1p (-a2); + float v2 = (u2 < a2 * MAX)? u2 / a2: 1; + float u = u1 + u2; + float w = (u > 1 || am < u * MAX)? am / u: 1; + cm = (c1 * v1 + c2 * v2) * w; + } +} + +template +class FBArray { +public: + Array2D data; + + FBArray() + { + } + + ~FBArray() + { + for(int y = 0; y < data.height(); y++) + { + for(int x = 0; x < data.width(); x++) + delete[] data[y][x]; + } + } + + void alloc(const Array2D &sampleCount) + { + for(int y = 0; y < data.height(); y++) + { + for(int x = 0; x < data.width(); x++) + data[y][x] = new T[sampleCount[y][x]]; + } + } + + void AddArrayToFramebuffer(string name, PixelType pt, const Header &header, DeepFrameBuffer &frameBuffer) + { + Box2i dataWindow = header.dataWindow(); + int width = dataWindow.max.x - dataWindow.min.x + 1; + int height = dataWindow.max.y - dataWindow.min.y + 1; + data.resizeErase(height, width); + + DeepSlice slice(pt, + (char *) (&data[0][0] - dataWindow.min.x - dataWindow.min.y * data.width()), + sizeof(T *), sizeof(T *) * data.width(), sizeof(T)); + frameBuffer.insert(name, slice); + } +}; + +// A simple container for an output EXR containing only RGBA data. +class SimpleImage +{ +public: + struct pixel { + float rgba[4]; + }; + vector data; + int width, height; + Header header; + + SimpleImage(int width_, int height_): + header(width_, height_) + { + width = width_; + height = height_; + data.resize(width*height); + } + + void setColor(float r, float g, float b, float a) + { + for(int y = 0; y < height; y++) + { + for(int x = 0; x < width; x++) + { + const int pixelIdx = x + y*width; + data[pixelIdx].rgba[0] = r; + data[pixelIdx].rgba[1] = g; + data[pixelIdx].rgba[2] = b; + data[pixelIdx].rgba[3] = a; + } + } + } + + void write(string filename) const + { + Header headerCopy(header); + headerCopy.channels().insert("R", Channel(FLOAT)); + headerCopy.channels().insert("G", Channel(FLOAT)); + headerCopy.channels().insert("B", Channel(FLOAT)); + headerCopy.channels().insert("A", Channel(FLOAT)); + + FrameBuffer frameBuffer; + frameBuffer.insert("R", Slice(FLOAT, (char *) &data.data()->rgba[0], sizeof(pixel), sizeof(pixel) * width)); + frameBuffer.insert("G", Slice(FLOAT, (char *) &data.data()->rgba[1], sizeof(pixel), sizeof(pixel) * width)); + frameBuffer.insert("B", Slice(FLOAT, (char *) &data.data()->rgba[2], sizeof(pixel), sizeof(pixel) * width)); + frameBuffer.insert("A", Slice(FLOAT, (char *) &data.data()->rgba[3], sizeof(pixel), sizeof(pixel) * width)); + + OutputFile file(filename.c_str(), headerCopy); + file.setFrameBuffer(frameBuffer); + file.writePixels(height); + } +}; + +struct DeepSample +{ + float rgba[4]; + float zNear, zFar; + uint32_t objectId; +}; + +void ReadEXR(DeepScanLineInputFile &file, Array2D> &samples) +{ + const Header &header = file.header(); + Box2i dataWindow = header.dataWindow(); + const int width = dataWindow.max.x - dataWindow.min.x + 1; + const int height = dataWindow.max.y - dataWindow.min.y + 1; + + DeepFrameBuffer frameBuffer; + + Array2D sampleCount; + sampleCount.resizeErase(height, width); + frameBuffer.insertSampleCountSlice(Slice(UINT, + (char *) (&sampleCount[0][0] - dataWindow.min.x - dataWindow.min.y * width), + sizeof(unsigned int), sizeof(unsigned int) * width)); + + // Set up the channels that we need. This would be a lot cleaner if we could use a single data + // structure for all data, but the EXR library doesn't seem to support interleaved data for deep + // samples. + FBArray dataR; + dataR.AddArrayToFramebuffer("R", FLOAT, header, frameBuffer); + + FBArray dataG; + dataG.AddArrayToFramebuffer("G", FLOAT, header, frameBuffer); + + FBArray dataB; + dataB.AddArrayToFramebuffer("B", FLOAT, header, frameBuffer); + + FBArray dataA; + dataA.AddArrayToFramebuffer("A", FLOAT, header, frameBuffer); + + FBArray dataId; + dataId.AddArrayToFramebuffer("id", UINT, header, frameBuffer); + + FBArray dataZ; + dataZ.AddArrayToFramebuffer("Z", FLOAT, header, frameBuffer); + + FBArray dataZB; + dataZB.AddArrayToFramebuffer("ZBack", FLOAT, header, frameBuffer); + + file.setFrameBuffer(frameBuffer); + file.readPixelSampleCounts(dataWindow.min.y, dataWindow.max.y); + + // Allocate the channels now that we know the number of samples per pixel. + dataR.alloc(sampleCount); + dataG.alloc(sampleCount); + dataB.alloc(sampleCount); + dataA.alloc(sampleCount); + dataId.alloc(sampleCount); + dataZ.alloc(sampleCount); + dataZB.alloc(sampleCount); + + // Read the main image data. + file.readPixels(dataWindow.min.y, dataWindow.max.y); + + samples.resizeErase(height, width); + + for(int y = 0; y < height; y++) + { + for(int x = 0; x < width; x++) + { + vector &out = samples[y][x]; + samples[y][x].resize(sampleCount[y][x]); + for(int s = 0; s < sampleCount[y][x]; ++s) + { + out[s].rgba[0] = dataR.data[y][x][s]; + out[s].rgba[1] = dataG.data[y][x][s]; + out[s].rgba[2] = dataB.data[y][x][s]; + out[s].rgba[3] = dataA.data[y][x][s]; + out[s].zNear = dataZ.data[y][x][s]; + out[s].zFar = dataZB.data[y][x][s]; + out[s].objectId = dataId.data[y][x][s]; + + // Try to work around bad Arnold default IDs. If you don't explicitly specify an object ID, + // Arnold seems to write uninitialized memory or some other random-looking data to it. + if(out[s].objectId > 1000000) + out[s].objectId = NO_OBJECT_ID; + } + } + } +} + +// Given a list of samples on a pixel, return a list of sample indices sorted by depth, furthest +// from the camera first. +void sortSamplesByDepth(vector &samples) +{ + // Sort samples by depth. + sort(samples.begin(), samples.end(), [](const auto &lhs, const auto &rhs) { + return lhs.zNear > rhs.zNear; + }); +} + +struct Layer +{ + string name; + int objectId; + shared_ptr image; + + Layer(string name_, int width, int height) + { + name = name_; + image = make_shared(width, height); + } +}; + +/* + * Create a set of images, one per object ID in the input image, which can be combined with + * additive blending to get the original image. This is useful because the layers can be + * edited simply on a per-object basis and composited in a simpler application like Photoshop. + * + * Normally, samples are composited with "over" compositing. The order of samples is important: + * + * r = 0 // current color + * r = r0*a0 + r*(1-a0); // overlay r0/a0, and reduce everything under it + * r = r1*a1 + r*(1-a1); // overlay r1/a1, and reduce everything under it + * r = r2*a2 + r*(1-a2); // overlay r2/a2, and reduce everything under it + * ... + * + * which iteratively adds each sample on top to the output, and reduces the contribution + * of everything underneath it in the process. This is repeated for each RGBA channel. + * + * We want to know the final contribution of each sample at the end, so instead we do: + * + * r[0] = r0*a0 // r*(1-a0) is zero since this is the first layer + * + * r[1]= r1*a1 // overlay r1/a1 + * r[0] *= (1-a1) // and reduce everything under it + * + * r[2] = r2*a2 // overlay r2/a2 + * r[1] *= (1-a2) // and reduce everything under it + * r[0] *= (1-a2) // and reduce everything under it + * + * This tracks each term separately: instead of applying the r*(1-a0) term accumulatively, + * we track its effect on each individual sample underneath it. Adding r[0]+r[1]+r[2] + * would be equivalent to the normal compositing formula. + * + * Since this is simple addition, the order of samples no longer matters. We can then + * combine samples by object ID, and the resulting images can be added together with simple + * additive blending. + */ +void SeparateIntoAdditiveLayers(vector &layers, const Array2D> &samples) +{ +/* layers.push_back(Layer("test", samples.width(), samples.height())); + layers.back().objectId = 0; + auto image = layers.back().image;*/ + + map> imagesPerObjectId; + + for(int y = 0; y < samples.height(); y++) + { + for(int x = 0; x < samples.width(); x++) + { + const vector &samplesForPixel = samples[y][x]; + + struct AccumulatedSample { + AccumulatedSample() + { + for(int i = 0; i < 4; ++i) + rgba[i] = 0; + } + float rgba[4]; + int objectId; + float zNear; + }; + + vector sampleLayers; + for(const DeepSample &sample: samplesForPixel) + { + AccumulatedSample new_sample; + new_sample.objectId = sample.objectId; + new_sample.zNear = sample.zNear; + for(int i = 0; i < 4; ++i) + new_sample.rgba[i] = sample.rgba[i]; + + // Apply the alpha term to each sample underneath this one. + float a = sample.rgba[3]; + for(AccumulatedSample &sample: sampleLayers) + { + for(int i = 0; i < 4; ++i) + sample.rgba[i] *= 1-a; + } + + // Add the new sample. + sampleLayers.push_back(new_sample); + } + + // Combine samples by object ID, creating a layer for each. + // + // We could do this in one pass instead of two, but debugging is easier in two passes. + const int pixelIdx = x + y*samples.width(); +/* for(const AccumulatedSample &sample: sampleLayers) + { + for(int i = 0; i < 4; ++i) + image->data[pixelIdx].rgba[i] += sample.rgba[i]; + } */ + + for(const AccumulatedSample &sample: sampleLayers) + { + int objectId = sample.objectId; + if(imagesPerObjectId.find(objectId) == imagesPerObjectId.end()) + { + layers.push_back(Layer("color", samples.width(), samples.height())); + Layer &layer = layers.back(); + layer.objectId = objectId; + imagesPerObjectId[objectId] = layer.image; + } + + auto image = imagesPerObjectId.at(objectId); + for(int i = 0; i < 4; ++i) + image->data[pixelIdx].rgba[i] += sample.rgba[i]; + } + } + } +} + +void readObjectIdNames(const Header &header, map &objectIdNames) +{ + for(auto it = header.begin(); it != header.end(); ++it) + { + auto &attr = it.attribute(); + if(strcmp(attr.typeName(), "string")) + continue; + + string headerName = it.name(); + if(headerName.substr(0, 9) != "ObjectId/") + continue; + + string idString = headerName.substr(9); + int id = atoi(idString.c_str()); + const StringAttribute &value = dynamic_cast(attr); + objectIdNames[id] = value.value(); + } +} + +void readDeepScanlineFile(string filename, string output) +{ + DeepScanLineInputFile file(filename.c_str()); + const Header &header = file.header(); + +/* + const ChannelList &channels = file.header().channels(); + for(auto i = channels.begin(); i != channels.end(); ++i) + { + const Channel &channel = i.channel(); + printf("... %s: %i\n", i.name(), channel.type); + } + + set layerNames; + channels.layers(layerNames); + for(const string &layerName: layerNames) + { + printf("layer: %s", layerName.c_str()); + ChannelList::ConstIterator layerBegin, layerEnd; + channels.channelsInLayer(layerName, layerBegin, layerEnd); + for(auto j = layerBegin; j != layerEnd; ++j) + { + cout << "\tchannel " << j.name() << endl; + } + } +*/ + Array2D> samples; + ReadEXR(file, samples); + + // Sort all samples by depth. If we want to support volumes, this is where we'd do the rest + // of "tidying", splitting samples where they overlap using splitVolumeSample. + for(int y = 0; y < samples.height(); y++) + { + for(int x = 0; x < samples.width(); x++) + { + vector &samplesForPixel = samples[y][x]; + sortSamplesByDepth(samplesForPixel); + } + } + + // Separate the image into layers. + vector layers; + + SeparateIntoAdditiveLayers(layers, samples); + + // If this file has names for object IDs, read them. + map objectIdNames; + readObjectIdNames(header, objectIdNames); + + if(!objectIdNames.empty()) + { + printf("Object ID names:\n"); + for(auto it: objectIdNames) + printf("Id %i: %s\n", it.first, it.second.c_str()); + printf("\n"); + } + + // Set the layer with the object ID 0 to "default", unless a name for that ID + // was specified explicitly. + if(objectIdNames.find(NO_OBJECT_ID) == objectIdNames.end()) + objectIdNames[NO_OBJECT_ID] = "default"; + + // Write the results. + for(int i = 0; i < layers.size(); ++i) + { + auto &layer = layers[i]; + + // Copy all image attributes, except for built-in EXR headers that we shouldn't set. + for(auto it = header.begin(); it != header.end(); ++it) + { + auto &attr = it.attribute(); + string headerName = it.name(); + if(headerName == "channels" || + headerName == "chunkCount" || + headerName == "compression" || + headerName == "lineOrder" || + headerName == "type" || + headerName == "version") + continue; + + if(headerName.substr(0, 9) == "ObjectId/") + continue; + + layer.image->header.insert(headerName, attr); + } + + // Do simple substitutions on the output filename. + string outputName = output; + string objectIdName; + if(objectIdNames.find(layer.objectId) != objectIdNames.end()) + objectIdName = objectIdNames.at(layer.objectId); + else + objectIdName = ssprintf("#%i", layer.objectId); + + // : the name of the object ID that we got from the EXR file, or "#100" if we + // only have a number. + outputName = subst(outputName, "", objectIdName); + + // : the output layer that we generated. This is currently always "color". + outputName = subst(outputName, "", layer.name); + + // : the input filename, with the directory and ".exr" removed. + string inputName = filename; + inputName = basename(inputName); + inputName = setExtension(inputName, ""); + outputName = subst(outputName, "", inputName); + + // : the input filename's frame number, given a "abcdef.1234.exr" filename. + // It would be nice if there was an EXR attribute contained the frame number. + outputName = subst(outputName, "", getFrameNumberFromFilename(filename)); + + printf("Writing: %s\n", outputName.c_str()); + layer.image->write(outputName); + } +} + +int main(int argc, char **argv) +{ + if(argc < 3) { + fprintf( stderr, "Usage: exrflatten input.exr output\n" ); + return 1; + } + + readDeepScanlineFile(argv[1], argv[2]); + return 0; +} + diff --git a/exrflatten.sln b/exrflatten.sln new file mode 100644 index 0000000..ee36b01 --- /dev/null +++ b/exrflatten.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25029.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "exrflatten", "exrflatten.vcxproj", "{9C9F1D42-292A-4DA0-A2AD-C46618E0ABED}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9C9F1D42-292A-4DA0-A2AD-C46618E0ABED}.Debug|x64.ActiveCfg = Debug|x64 + {9C9F1D42-292A-4DA0-A2AD-C46618E0ABED}.Debug|x64.Build.0 = Debug|x64 + {9C9F1D42-292A-4DA0-A2AD-C46618E0ABED}.Release|x64.ActiveCfg = Release|x64 + {9C9F1D42-292A-4DA0-A2AD-C46618E0ABED}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/exrflatten.vcxproj b/exrflatten.vcxproj new file mode 100644 index 0000000..e585e7e --- /dev/null +++ b/exrflatten.vcxproj @@ -0,0 +1,101 @@ + + + + + Debug + x64 + + + Release + x64 + + + + {9C9F1D42-292A-4DA0-A2AD-C46618E0ABED} + Win32Proj + exrflatten + 8.1 + + + + Application + true + v140 + Unicode + + + Application + false + v140 + false + Unicode + + + + + + + + + + + + + + + true + $(VC_IncludePath);$(WindowsSDK_IncludePath);OpenEXR\include + $(SolutionDir)\build\$(Configuration)\ + bin\ + + + false + $(VC_IncludePath);$(WindowsSDK_IncludePath);OpenEXR\include + $(SolutionDir)\build\$(Configuration)\ + bin\ + + + + + + Level3 + Disabled + _DEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + /wd4018 /wd4800 /wd4267 %(AdditionalOptions) + + + Console + true + OpenEXR\lib;%(AdditionalLibraryDirectories) + IlmImf-2_2.lib;%(AdditionalDependencies) + bin\$(TargetName)$(TargetExt) + + + + + Level3 + + + MaxSpeed + true + true + NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + /wd4018 /wd4800 /wd4267 %(AdditionalOptions) + + + Console + true + true + true + OpenEXR\lib;%(AdditionalLibraryDirectories) + IlmImf-2_2.lib;%(AdditionalDependencies) + bin\$(TargetName)$(TargetExt) + + + + + + + + + \ No newline at end of file diff --git a/exrflatten.vcxproj.filters b/exrflatten.vcxproj.filters new file mode 100644 index 0000000..bd7abc7 --- /dev/null +++ b/exrflatten.vcxproj.filters @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file