opencv/3rdparty/openexr/IlmImf/ImfCRgbaFile.cpp

1435 lines
25 KiB
C++
Raw Normal View History

2012-08-25 04:31:49 +08:00
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2004, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
2012-10-17 15:12:04 +08:00
//
2012-08-25 04:31:49 +08:00
// All rights reserved.
2012-10-17 15:12:04 +08:00
//
2012-08-25 04:31:49 +08:00
// 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
2012-10-17 15:12:04 +08:00
// from this software without specific prior written permission.
//
2012-08-25 04:31:49 +08:00
// 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.
//
///////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
//
// C interface to C++ classes Imf::RgbaOutputFile and Imf::RgbaInputFile
//
//-----------------------------------------------------------------------------
#include <ImfCRgbaFile.h>
#include <ImfRgbaFile.h>
#include <ImfTiledRgbaFile.h>
#include <ImfIntAttribute.h>
#include <ImfFloatAttribute.h>
#include <ImfDoubleAttribute.h>
#include <ImfStringAttribute.h>
#include <ImfBoxAttribute.h>
#include <ImfVecAttribute.h>
#include <ImfMatrixAttribute.h>
#include <ImfChannelList.h>
#include <ImfLut.h>
#include "half.h"
#include <string.h>
using Imath::Box2i;
using Imath::Box2f;
using Imath::V2i;
using Imath::V2f;
using Imath::V3i;
using Imath::V3f;
using Imath::M33f;
using Imath::M44f;
namespace {
const int MAX_ERR_LENGTH = 1024;
char errorMessage[MAX_ERR_LENGTH];
void
setErrorMessage (const std::exception &e)
{
strncpy (errorMessage, e.what(), MAX_ERR_LENGTH - 1);
errorMessage[MAX_ERR_LENGTH - 1] = 0;
}
inline Imf::Header *
header (ImfHeader *hdr)
{
return (Imf::Header *)(hdr);
}
inline const Imf::Header *
header (const ImfHeader *hdr)
{
return (const Imf::Header *)(hdr);
}
inline Imf::RgbaOutputFile *
outfile (ImfOutputFile *out)
{
return (Imf::RgbaOutputFile *) out;
}
inline const Imf::RgbaOutputFile *
outfile (const ImfOutputFile *out)
{
return (const Imf::RgbaOutputFile *) out;
}
inline Imf::TiledRgbaOutputFile *
outfile (ImfTiledOutputFile *out)
{
return (Imf::TiledRgbaOutputFile *) out;
}
inline const Imf::TiledRgbaOutputFile *
outfile (const ImfTiledOutputFile *out)
{
return (const Imf::TiledRgbaOutputFile *) out;
}
inline Imf::RgbaInputFile *
infile (ImfInputFile *in)
{
return (Imf::RgbaInputFile *) in;
}
inline const Imf::RgbaInputFile *
infile (const ImfInputFile *in)
{
return (const Imf::RgbaInputFile *) in;
}
inline Imf::TiledRgbaInputFile *
infile (ImfTiledInputFile *in)
{
return (Imf::TiledRgbaInputFile *) in;
}
inline const Imf::TiledRgbaInputFile *
infile (const ImfTiledInputFile *in)
{
return (const Imf::TiledRgbaInputFile *) in;
}
} // namespace
2012-10-17 15:12:04 +08:00
void
2012-08-25 04:31:49 +08:00
ImfFloatToHalf (float f, ImfHalf *h)
{
*h = half(f).bits();
}
2012-10-17 15:12:04 +08:00
void
2012-08-25 04:31:49 +08:00
ImfFloatToHalfArray (int n, const float f[/*n*/], ImfHalf h[/*n*/])
{
for (int i = 0; i < n; ++i)
2012-10-17 15:12:04 +08:00
h[i] = half(f[i]).bits();
2012-08-25 04:31:49 +08:00
}
2012-10-17 15:12:04 +08:00
float
2012-08-25 04:31:49 +08:00
ImfHalfToFloat (ImfHalf h)
{
return float (*((half *)&h));
}
void
ImfHalfToFloatArray (int n, const ImfHalf h[/*n*/], float f[/*n*/])
{
for (int i = 0; i < n; ++i)
2012-10-17 15:12:04 +08:00
f[i] = float (*((half *)(h + i)));
2012-08-25 04:31:49 +08:00
}
ImfHeader *
ImfNewHeader (void)
{
try
{
2012-10-17 15:12:04 +08:00
return (ImfHeader *) new Imf::Header;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
2012-10-17 15:12:04 +08:00
void
2012-08-25 04:31:49 +08:00
ImfDeleteHeader (ImfHeader *hdr)
{
delete header (hdr);
}
ImfHeader *
ImfCopyHeader (const ImfHeader *hdr)
{
try
{
2012-10-17 15:12:04 +08:00
return (ImfHeader *) new Imf::Header (*header (hdr));
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
2012-10-17 15:12:04 +08:00
void
2012-08-25 04:31:49 +08:00
ImfHeaderSetDisplayWindow (ImfHeader *hdr,
2012-10-17 15:12:04 +08:00
int xMin, int yMin,
int xMax, int yMax)
2012-08-25 04:31:49 +08:00
{
header(hdr)->displayWindow() = Box2i (V2i (xMin, yMin), V2i (xMax, yMax));
}
2012-10-17 15:12:04 +08:00
void
2012-08-25 04:31:49 +08:00
ImfHeaderDisplayWindow (const ImfHeader *hdr,
2012-10-17 15:12:04 +08:00
int *xMin, int *yMin,
int *xMax, int *yMax)
2012-08-25 04:31:49 +08:00
{
const Box2i dw = header(hdr)->displayWindow();
*xMin = dw.min.x;
*yMin = dw.min.y;
*xMax = dw.max.x;
*yMax = dw.max.y;
}
void
ImfHeaderSetDataWindow (ImfHeader *hdr,
2012-10-17 15:12:04 +08:00
int xMin, int yMin,
int xMax, int yMax)
2012-08-25 04:31:49 +08:00
{
header(hdr)->dataWindow() = Box2i (V2i (xMin, yMin), V2i (xMax, yMax));
}
2012-10-17 15:12:04 +08:00
void
2012-08-25 04:31:49 +08:00
ImfHeaderDataWindow (const ImfHeader *hdr,
2012-10-17 15:12:04 +08:00
int *xMin, int *yMin,
int *xMax, int *yMax)
2012-08-25 04:31:49 +08:00
{
const Box2i dw = header(hdr)->dataWindow();
*xMin = dw.min.x;
*yMin = dw.min.y;
*xMax = dw.max.x;
*yMax = dw.max.y;
}
2012-10-17 15:12:04 +08:00
void
2012-08-25 04:31:49 +08:00
ImfHeaderSetPixelAspectRatio (ImfHeader *hdr, float pixelAspectRatio)
{
header(hdr)->pixelAspectRatio() = pixelAspectRatio;
}
2012-10-17 15:12:04 +08:00
float
2012-08-25 04:31:49 +08:00
ImfHeaderPixelAspectRatio (const ImfHeader *hdr)
{
return header(hdr)->pixelAspectRatio();
}
2012-10-17 15:12:04 +08:00
void
2012-08-25 04:31:49 +08:00
ImfHeaderSetScreenWindowCenter (ImfHeader *hdr, float x, float y)
{
header(hdr)->screenWindowCenter() = V2f (x, y);
}
2012-10-17 15:12:04 +08:00
void
2012-08-25 04:31:49 +08:00
ImfHeaderScreenWindowCenter (const ImfHeader *hdr, float *x, float *y)
{
const V2i &swc = header(hdr)->screenWindowCenter();
*x = swc.x;
*y = swc.y;
}
2012-10-17 15:12:04 +08:00
void
2012-08-25 04:31:49 +08:00
ImfHeaderSetScreenWindowWidth (ImfHeader *hdr, float width)
{
header(hdr)->screenWindowWidth() = width;
}
2012-10-17 15:12:04 +08:00
float
2012-08-25 04:31:49 +08:00
ImfHeaderScreenWindowWidth (const ImfHeader *hdr)
{
return header(hdr)->screenWindowWidth();
}
2012-10-17 15:12:04 +08:00
void
2012-08-25 04:31:49 +08:00
ImfHeaderSetLineOrder (ImfHeader *hdr, int lineOrder)
{
header(hdr)->lineOrder() = Imf::LineOrder (lineOrder);
}
2012-10-17 15:12:04 +08:00
int
2012-08-25 04:31:49 +08:00
ImfHeaderLineOrder (const ImfHeader *hdr)
{
return header(hdr)->lineOrder();
}
2012-10-17 15:12:04 +08:00
void
2012-08-25 04:31:49 +08:00
ImfHeaderSetCompression (ImfHeader *hdr, int compression)
{
header(hdr)->compression() = Imf::Compression (compression);
}
2012-10-17 15:12:04 +08:00
int
2012-08-25 04:31:49 +08:00
ImfHeaderCompression (const ImfHeader *hdr)
{
return header(hdr)->compression();
}
2012-10-17 15:12:04 +08:00
int
2012-08-25 04:31:49 +08:00
ImfHeaderSetIntAttribute (ImfHeader *hdr, const char name[], int value)
{
try
{
2012-10-17 15:12:04 +08:00
if (header(hdr)->find(name) == header(hdr)->end())
{
header(hdr)->insert (name, Imf::IntAttribute (value));
}
else
{
header(hdr)->typedAttribute<Imf::IntAttribute>(name).value() =
value;
}
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
2012-10-17 15:12:04 +08:00
int
2012-08-25 04:31:49 +08:00
ImfHeaderIntAttribute (const ImfHeader *hdr, const char name[], int *value)
{
try
{
2012-10-17 15:12:04 +08:00
*value = header(hdr)->typedAttribute<Imf::IntAttribute>(name).value();
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
2012-10-17 15:12:04 +08:00
int
2012-08-25 04:31:49 +08:00
ImfHeaderSetFloatAttribute (ImfHeader *hdr, const char name[], float value)
{
try
{
2012-10-17 15:12:04 +08:00
if (header(hdr)->find(name) == header(hdr)->end())
{
header(hdr)->insert (name, Imf::FloatAttribute (value));
}
else
{
header(hdr)->typedAttribute<Imf::FloatAttribute>(name).value() =
value;
}
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
2012-10-17 15:12:04 +08:00
int
2012-08-25 04:31:49 +08:00
ImfHeaderSetDoubleAttribute (ImfHeader *hdr, const char name[], double value)
{
try
{
2012-10-17 15:12:04 +08:00
if (header(hdr)->find(name) == header(hdr)->end())
{
header(hdr)->insert (name, Imf::DoubleAttribute (value));
}
else
{
header(hdr)->typedAttribute<Imf::DoubleAttribute>(name).value() =
value;
}
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
int
ImfHeaderFloatAttribute (const ImfHeader *hdr, const char name[], float *value)
{
try
{
2012-10-17 15:12:04 +08:00
*value = header(hdr)->typedAttribute<Imf::FloatAttribute>(name).value();
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
int
ImfHeaderDoubleAttribute (const ImfHeader *hdr,
2012-10-17 15:12:04 +08:00
const char name[],
double *value)
2012-08-25 04:31:49 +08:00
{
try
{
2012-10-17 15:12:04 +08:00
*value = header(hdr)->
typedAttribute<Imf::DoubleAttribute>(name).value();
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
int
ImfHeaderSetStringAttribute (ImfHeader *hdr,
2012-10-17 15:12:04 +08:00
const char name[],
const char value[])
2012-08-25 04:31:49 +08:00
{
try
{
2012-10-17 15:12:04 +08:00
if (header(hdr)->find(name) == header(hdr)->end())
{
header(hdr)->insert (name, Imf::StringAttribute (value));
}
else
{
header(hdr)->typedAttribute<Imf::StringAttribute>(name).value() =
value;
}
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
int
ImfHeaderStringAttribute (const ImfHeader *hdr,
2012-10-17 15:12:04 +08:00
const char name[],
const char **value)
2012-08-25 04:31:49 +08:00
{
try
{
2012-10-17 15:12:04 +08:00
*value = header(hdr)->
typedAttribute<Imf::StringAttribute>(name).value().c_str();
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
int
ImfHeaderSetBox2iAttribute (ImfHeader *hdr,
2012-10-17 15:12:04 +08:00
const char name[],
int xMin, int yMin,
int xMax, int yMax)
2012-08-25 04:31:49 +08:00
{
try
{
2012-10-17 15:12:04 +08:00
Box2i box (V2i (xMin, yMin), V2i (xMax, yMax));
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
if (header(hdr)->find(name) == header(hdr)->end())
{
header(hdr)->insert (name, Imf::Box2iAttribute (box));
}
else
{
header(hdr)->typedAttribute<Imf::Box2iAttribute>(name).value() =
box;
}
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
int
ImfHeaderBox2iAttribute (const ImfHeader *hdr,
2012-10-17 15:12:04 +08:00
const char name[],
int *xMin, int *yMin,
int *xMax, int *yMax)
2012-08-25 04:31:49 +08:00
{
try
{
2012-10-17 15:12:04 +08:00
const Box2i &box =
header(hdr)->typedAttribute<Imf::Box2iAttribute>(name).value();
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
*xMin = box.min.x;
*yMin = box.min.y;
*xMax = box.max.x;
*yMax = box.max.y;
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
int
ImfHeaderSetBox2fAttribute (ImfHeader *hdr,
2012-10-17 15:12:04 +08:00
const char name[],
float xMin, float yMin,
float xMax, float yMax)
2012-08-25 04:31:49 +08:00
{
try
{
2012-10-17 15:12:04 +08:00
Box2f box (V2f (xMin, yMin), V2f (xMax, yMax));
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
if (header(hdr)->find(name) == header(hdr)->end())
{
header(hdr)->insert (name, Imf::Box2fAttribute (box));
}
else
{
header(hdr)->typedAttribute<Imf::Box2fAttribute>(name).value() =
box;
}
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
int
ImfHeaderBox2fAttribute (const ImfHeader *hdr,
2012-10-17 15:12:04 +08:00
const char name[],
float *xMin, float *yMin,
float *xMax, float *yMax)
2012-08-25 04:31:49 +08:00
{
try
{
2012-10-17 15:12:04 +08:00
const Box2f &box =
header(hdr)->typedAttribute<Imf::Box2fAttribute>(name).value();
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
*xMin = box.min.x;
*yMin = box.min.y;
*xMax = box.max.x;
*yMax = box.max.y;
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
int
ImfHeaderSetV2iAttribute (ImfHeader *hdr,
2012-10-17 15:12:04 +08:00
const char name[],
int x, int y)
2012-08-25 04:31:49 +08:00
{
try
{
2012-10-17 15:12:04 +08:00
V2i v (x, y);
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
if (header(hdr)->find(name) == header(hdr)->end())
header(hdr)->insert (name, Imf::V2iAttribute (v));
else
header(hdr)->typedAttribute<Imf::V2iAttribute>(name).value() = v;
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
int
ImfHeaderV2iAttribute (const ImfHeader *hdr,
2012-10-17 15:12:04 +08:00
const char name[],
int *x, int *y)
2012-08-25 04:31:49 +08:00
{
try
{
2012-10-17 15:12:04 +08:00
const V2i &v =
header(hdr)->typedAttribute<Imf::V2iAttribute>(name).value();
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
*x = v.x;
*y = v.y;
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
2012-10-17 15:12:04 +08:00
int
2012-08-25 04:31:49 +08:00
ImfHeaderSetV2fAttribute (ImfHeader *hdr,
2012-10-17 15:12:04 +08:00
const char name[],
float x, float y)
2012-08-25 04:31:49 +08:00
{
try
{
2012-10-17 15:12:04 +08:00
V2f v (x, y);
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
if (header(hdr)->find(name) == header(hdr)->end())
header(hdr)->insert (name, Imf::V2fAttribute (v));
else
header(hdr)->typedAttribute<Imf::V2fAttribute>(name).value() = v;
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
int
ImfHeaderV2fAttribute (const ImfHeader *hdr,
2012-10-17 15:12:04 +08:00
const char name[],
float *x, float *y)
2012-08-25 04:31:49 +08:00
{
try
{
2012-10-17 15:12:04 +08:00
const V2f &v =
header(hdr)->typedAttribute<Imf::V2fAttribute>(name).value();
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
*x = v.x;
*y = v.y;
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
int
ImfHeaderSetV3iAttribute (ImfHeader *hdr,
2012-10-17 15:12:04 +08:00
const char name[],
int x, int y, int z)
2012-08-25 04:31:49 +08:00
{
try
{
2012-10-17 15:12:04 +08:00
V3i v (x, y, z);
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
if (header(hdr)->find(name) == header(hdr)->end())
header(hdr)->insert (name, Imf::V3iAttribute (v));
else
header(hdr)->typedAttribute<Imf::V3iAttribute>(name).value() = v;
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
int
ImfHeaderV3iAttribute (const ImfHeader *hdr,
2012-10-17 15:12:04 +08:00
const char name[],
int *x, int *y, int *z)
2012-08-25 04:31:49 +08:00
{
try
{
2012-10-17 15:12:04 +08:00
const V3i &v =
header(hdr)->typedAttribute<Imf::V3iAttribute>(name).value();
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
*x = v.x;
*y = v.y;
*z = v.z;
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
int
ImfHeaderSetV3fAttribute (ImfHeader *hdr,
2012-10-17 15:12:04 +08:00
const char name[],
float x, float y, float z)
2012-08-25 04:31:49 +08:00
{
try
{
2012-10-17 15:12:04 +08:00
V3f v (x, y, z);
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
if (header(hdr)->find(name) == header(hdr)->end())
header(hdr)->insert (name, Imf::V3fAttribute (v));
else
header(hdr)->typedAttribute<Imf::V3fAttribute>(name).value() = v;
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
int
ImfHeaderV3fAttribute (const ImfHeader *hdr,
2012-10-17 15:12:04 +08:00
const char name[],
float *x, float *y, float *z)
2012-08-25 04:31:49 +08:00
{
try
{
2012-10-17 15:12:04 +08:00
const V3f &v =
header(hdr)->typedAttribute<Imf::V3fAttribute>(name).value();
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
*x = v.x;
*y = v.y;
*z = v.z;
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
int
ImfHeaderSetM33fAttribute (ImfHeader *hdr,
2012-10-17 15:12:04 +08:00
const char name[],
const float m[3][3])
2012-08-25 04:31:49 +08:00
{
try
{
2012-10-17 15:12:04 +08:00
M33f m3 (m);
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
if (header(hdr)->find(name) == header(hdr)->end())
header(hdr)->insert (name, Imf::M33fAttribute (m3));
else
header(hdr)->typedAttribute<Imf::M33fAttribute>(name).value() = m3;
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
int
ImfHeaderM33fAttribute (const ImfHeader *hdr,
2012-10-17 15:12:04 +08:00
const char name[],
float m[3][3])
2012-08-25 04:31:49 +08:00
{
try
{
2012-10-17 15:12:04 +08:00
const M33f &m3 =
header(hdr)->typedAttribute<Imf::M33fAttribute>(name).value();
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
m[0][0] = m3[0][0];
m[0][1] = m3[0][1];
m[0][2] = m3[0][2];
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
m[1][0] = m3[1][0];
m[1][1] = m3[1][1];
m[1][2] = m3[1][2];
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
m[2][0] = m3[2][0];
m[2][1] = m3[2][1];
m[2][2] = m3[2][2];
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
int
ImfHeaderSetM44fAttribute (ImfHeader *hdr,
2012-10-17 15:12:04 +08:00
const char name[],
const float m[4][4])
2012-08-25 04:31:49 +08:00
{
try
{
2012-10-17 15:12:04 +08:00
M44f m4 (m);
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
if (header(hdr)->find(name) == header(hdr)->end())
header(hdr)->insert (name, Imf::M44fAttribute (m4));
else
header(hdr)->typedAttribute<Imf::M44fAttribute>(name).value() = m4;
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
int
ImfHeaderM44fAttribute (const ImfHeader *hdr,
2012-10-17 15:12:04 +08:00
const char name[],
float m[4][4])
2012-08-25 04:31:49 +08:00
{
try
{
2012-10-17 15:12:04 +08:00
const M44f &m4 =
header(hdr)->typedAttribute<Imf::M44fAttribute>(name).value();
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
m[0][0] = m4[0][0];
m[0][1] = m4[0][1];
m[0][2] = m4[0][2];
m[0][3] = m4[0][3];
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
m[1][0] = m4[1][0];
m[1][1] = m4[1][1];
m[1][2] = m4[1][2];
m[1][3] = m4[1][3];
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
m[2][0] = m4[2][0];
m[2][1] = m4[2][1];
m[2][2] = m4[2][2];
m[2][3] = m4[2][3];
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
m[3][0] = m4[3][0];
m[3][1] = m4[3][1];
m[3][2] = m4[3][2];
m[3][3] = m4[3][3];
2012-08-25 04:31:49 +08:00
2012-10-17 15:12:04 +08:00
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
2012-10-17 15:12:04 +08:00
ImfOutputFile *
2012-08-25 04:31:49 +08:00
ImfOpenOutputFile (const char name[], const ImfHeader *hdr, int channels)
{
try
{
2012-10-17 15:12:04 +08:00
return (ImfOutputFile *) new Imf::RgbaOutputFile
(name, *header(hdr), Imf::RgbaChannels (channels));
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
2012-10-17 15:12:04 +08:00
int
2012-08-25 04:31:49 +08:00
ImfCloseOutputFile (ImfOutputFile *out)
{
try
{
2012-10-17 15:12:04 +08:00
delete outfile (out);
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
2012-10-17 15:12:04 +08:00
int
2012-08-25 04:31:49 +08:00
ImfOutputSetFrameBuffer (ImfOutputFile *out,
2012-10-17 15:12:04 +08:00
const ImfRgba *base,
size_t xStride,
size_t yStride)
2012-08-25 04:31:49 +08:00
{
try
{
2012-10-17 15:12:04 +08:00
outfile(out)->setFrameBuffer ((Imf::Rgba *)base, xStride, yStride);
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
2012-10-17 15:12:04 +08:00
int
2012-08-25 04:31:49 +08:00
ImfOutputWritePixels (ImfOutputFile *out, int numScanLines)
{
try
{
2012-10-17 15:12:04 +08:00
outfile(out)->writePixels (numScanLines);
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
int
ImfOutputCurrentScanLine (const ImfOutputFile *out)
{
return outfile(out)->currentScanLine();
}
const ImfHeader *
ImfOutputHeader (const ImfOutputFile *out)
{
return (const ImfHeader *) &outfile(out)->header();
}
int
ImfOutputChannels (const ImfOutputFile *out)
{
return outfile(out)->channels();
}
2012-10-17 15:12:04 +08:00
ImfTiledOutputFile *
2012-08-25 04:31:49 +08:00
ImfOpenTiledOutputFile (const char name[],
2012-10-17 15:12:04 +08:00
const ImfHeader *hdr,
int channels,
int xSize, int ySize,
int mode, int rmode)
2012-08-25 04:31:49 +08:00
{
try
{
2012-10-17 15:12:04 +08:00
return (ImfTiledOutputFile *) new Imf::TiledRgbaOutputFile
(name, *header(hdr),
Imf::RgbaChannels (channels),
xSize, ySize,
Imf::LevelMode (mode),
Imf::LevelRoundingMode (rmode));
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
2012-10-17 15:12:04 +08:00
int
2012-08-25 04:31:49 +08:00
ImfCloseTiledOutputFile (ImfTiledOutputFile *out)
{
try
{
2012-10-17 15:12:04 +08:00
delete outfile (out);
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
2012-10-17 15:12:04 +08:00
int
2012-08-25 04:31:49 +08:00
ImfTiledOutputSetFrameBuffer (ImfTiledOutputFile *out,
2012-10-17 15:12:04 +08:00
const ImfRgba *base,
size_t xStride,
size_t yStride)
2012-08-25 04:31:49 +08:00
{
try
{
2012-10-17 15:12:04 +08:00
outfile(out)->setFrameBuffer ((Imf::Rgba *)base, xStride, yStride);
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
2012-10-17 15:12:04 +08:00
int
2012-08-25 04:31:49 +08:00
ImfTiledOutputWriteTile (ImfTiledOutputFile *out,
2012-10-17 15:12:04 +08:00
int dx, int dy,
int lx, int ly)
2012-08-25 04:31:49 +08:00
{
try
{
2012-10-17 15:12:04 +08:00
outfile(out)->writeTile (dx, dy, lx, ly);
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
2012-10-17 15:12:04 +08:00
int
2012-08-25 04:31:49 +08:00
ImfTiledOutputWriteTiles (ImfTiledOutputFile *out,
2012-10-17 15:12:04 +08:00
int dxMin, int dxMax,
2012-08-25 04:31:49 +08:00
int dyMin, int dyMax,
2012-10-17 15:12:04 +08:00
int lx, int ly)
2012-08-25 04:31:49 +08:00
{
try
{
2012-10-17 15:12:04 +08:00
outfile(out)->writeTiles (dxMin, dxMax, dyMin, dyMax, lx, ly);
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
const ImfHeader *
ImfTiledOutputHeader (const ImfTiledOutputFile *out)
{
return (const ImfHeader *) &outfile(out)->header();
}
int
ImfTiledOutputChannels (const ImfTiledOutputFile *out)
{
return outfile(out)->channels();
}
int
ImfTiledOutputTileXSize (const ImfTiledOutputFile *out)
{
return outfile(out)->tileXSize();
}
int
ImfTiledOutputTileYSize (const ImfTiledOutputFile *out)
{
return outfile(out)->tileYSize();
}
int
ImfTiledOutputLevelMode (const ImfTiledOutputFile *out)
{
return outfile(out)->levelMode();
}
int
ImfTiledOutputLevelRoundingMode (const ImfTiledOutputFile *out)
{
return outfile(out)->levelRoundingMode();
}
2012-10-17 15:12:04 +08:00
ImfInputFile *
2012-08-25 04:31:49 +08:00
ImfOpenInputFile (const char name[])
{
try
{
2012-10-17 15:12:04 +08:00
return (ImfInputFile *) new Imf::RgbaInputFile (name);
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
int
ImfCloseInputFile (ImfInputFile *in)
{
try
{
2012-10-17 15:12:04 +08:00
delete infile (in);
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
2012-10-17 15:12:04 +08:00
int
2012-08-25 04:31:49 +08:00
ImfInputSetFrameBuffer (ImfInputFile *in,
2012-10-17 15:12:04 +08:00
ImfRgba *base,
size_t xStride,
size_t yStride)
2012-08-25 04:31:49 +08:00
{
try
{
2012-10-17 15:12:04 +08:00
infile(in)->setFrameBuffer ((Imf::Rgba *) base, xStride, yStride);
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
int
ImfInputReadPixels (ImfInputFile *in, int scanLine1, int scanLine2)
{
try
{
2012-10-17 15:12:04 +08:00
infile(in)->readPixels (scanLine1, scanLine2);
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
const ImfHeader *
ImfInputHeader (const ImfInputFile *in)
{
return (const ImfHeader *) &infile(in)->header();
}
int
ImfInputChannels (const ImfInputFile *in)
{
return infile(in)->channels();
}
const char *
ImfInputFileName (const ImfInputFile *in)
{
return infile(in)->fileName();
}
2012-10-17 15:12:04 +08:00
ImfTiledInputFile *
2012-08-25 04:31:49 +08:00
ImfOpenTiledInputFile (const char name[])
{
try
{
2012-10-17 15:12:04 +08:00
return (ImfTiledInputFile *) new Imf::TiledRgbaInputFile (name);
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
int
ImfCloseTiledInputFile (ImfTiledInputFile *in)
{
try
{
2012-10-17 15:12:04 +08:00
delete infile (in);
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
2012-10-17 15:12:04 +08:00
int
2012-08-25 04:31:49 +08:00
ImfTiledInputSetFrameBuffer (ImfTiledInputFile *in,
2012-10-17 15:12:04 +08:00
ImfRgba *base,
size_t xStride,
size_t yStride)
2012-08-25 04:31:49 +08:00
{
try
{
2012-10-17 15:12:04 +08:00
infile(in)->setFrameBuffer ((Imf::Rgba *) base, xStride, yStride);
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
int
ImfTiledInputReadTile (ImfTiledInputFile *in,
2012-10-17 15:12:04 +08:00
int dx, int dy,
int lx, int ly)
2012-08-25 04:31:49 +08:00
{
try
{
2012-10-17 15:12:04 +08:00
infile(in)->readTile (dx, dy, lx, ly);
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
int
ImfTiledInputReadTiles (ImfTiledInputFile *in,
2012-10-17 15:12:04 +08:00
int dxMin, int dxMax,
2012-08-25 04:31:49 +08:00
int dyMin, int dyMax,
2012-10-17 15:12:04 +08:00
int lx, int ly)
2012-08-25 04:31:49 +08:00
{
try
{
2012-10-17 15:12:04 +08:00
infile(in)->readTiles (dxMin, dxMax, dyMin, dyMax, lx, ly);
return 1;
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
const ImfHeader *
ImfTiledInputHeader (const ImfTiledInputFile *in)
{
return (const ImfHeader *) &infile(in)->header();
}
int
ImfTiledInputChannels (const ImfTiledInputFile *in)
{
return infile(in)->channels();
}
const char *
ImfTiledInputFileName (const ImfTiledInputFile *in)
{
return infile(in)->fileName();
}
int
ImfTiledInputTileXSize (const ImfTiledInputFile *in)
{
return infile(in)->tileXSize();
}
int
ImfTiledInputTileYSize (const ImfTiledInputFile *in)
{
return infile(in)->tileYSize();
}
int
ImfTiledInputLevelMode (const ImfTiledInputFile *in)
{
return infile(in)->levelMode();
}
int
ImfTiledInputLevelRoundingMode (const ImfTiledInputFile *in)
{
return infile(in)->levelRoundingMode();
}
ImfLut *
ImfNewRound12logLut (int channels)
{
try
{
2012-10-17 15:12:04 +08:00
return (ImfLut *) new Imf::RgbaLut
(Imf::round12log, Imf::RgbaChannels (channels));
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
ImfLut *
ImfNewRoundNBitLut (unsigned int n, int channels)
{
try
{
2012-10-17 15:12:04 +08:00
return (ImfLut *) new Imf::RgbaLut
(Imf::roundNBit (n), Imf::RgbaChannels (channels));
2012-08-25 04:31:49 +08:00
}
catch (const std::exception &e)
{
2012-10-17 15:12:04 +08:00
setErrorMessage (e);
return 0;
2012-08-25 04:31:49 +08:00
}
}
void
ImfDeleteLut (ImfLut *lut)
{
delete (Imf::RgbaLut *) lut;
}
void
ImfApplyLut (ImfLut *lut, ImfRgba *data, int nData, int stride)
{
((Imf::RgbaLut *)lut)->apply ((Imf::Rgba *)data, nData, stride);
}
2012-10-17 15:12:04 +08:00
const char *
2012-08-25 04:31:49 +08:00
ImfErrorMessage ()
{
return errorMessage;
}