Skip to content

More changes to hide Imath: new half.h, improve vecparam.h #3406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ endif ()
configure_file (${PROJECT_NAME}/${versionfile}.in "${CMAKE_BINARY_DIR}/include/${PROJECT_NAME}/${versionfile}" @ONLY)
list (APPEND public_headers "${CMAKE_BINARY_DIR}/include/${PROJECT_NAME}/${versionfile}")

# Generate half.h
if (VERBOSE)
message(STATUS "Create half.h from half.h.in")
endif ()
configure_file (${PROJECT_NAME}/half.h.in "${CMAKE_BINARY_DIR}/include/${PROJECT_NAME}/half.h" @ONLY)
list (APPEND public_headers "${CMAKE_BINARY_DIR}/include/${PROJECT_NAME}/half.h")


# Generate Imath.h
if (VERBOSE)
message(STATUS "Create Imath.h from Imath.h.in")
Expand Down
3 changes: 1 addition & 2 deletions src/include/OpenImageIO/Imath.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#pragma once

#include <OpenImageIO/half.h>
#include <OpenImageIO/detail/fmt.h>

#ifndef OIIO_IMATH_H_INCLUDED
Expand All @@ -20,12 +21,10 @@
# include <Imath/ImathColor.h>
# include <Imath/ImathMatrix.h>
# include <Imath/ImathVec.h>
# include <Imath/half.h>
#else
# include <OpenEXR/ImathColor.h>
# include <OpenEXR/ImathMatrix.h>
# include <OpenEXR/ImathVec.h>
# include <OpenEXR/half.h>
#endif


Expand Down
4 changes: 1 addition & 3 deletions src/include/OpenImageIO/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,8 @@ class OIIO_API ColorConfig {
///
/// Created ColorProcessors are cached, so asking for the same color
/// space transformation multiple times shouldn't be very expensive.
#ifdef INCLUDED_IMATHMATRIX_H
ColorProcessorHandle createMatrixTransform(const Imath::M44f& M,
ColorProcessorHandle createMatrixTransform(M44fParam M,
bool inverse = false) const;
#endif

/// Given a filepath, ask OCIO what color space it thinks the file
/// should be, based on how the name matches file naming rules in the
Expand Down
2 changes: 1 addition & 1 deletion src/include/OpenImageIO/fmath.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
OIIO_NAMESPACE_BEGIN

/// If the caller defines OIIO_FMATH_HEADER_ONLY to nonzero, then 100% of the
/// implementation of fmath functions will be defined direcly in this header
/// implementation of fmath functions will be defined directly in this header
/// file. If it is not defined, or set to 0, then there are a few functions
/// for which this header will only provide the definition.
#ifndef OIIO_FMATH_HEADER_ONLY
Expand Down
17 changes: 17 additions & 0 deletions src/include/OpenImageIO/half.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2008-present Contributors to the OpenImageIO project.
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/OpenImageIO/oiio/


#pragma once

// Determine which Imath we're dealing with and include the appropriate path
// to half.h.

#if defined(__has_include) && __has_include(<Imath/half.h>)
# include <Imath/half.h>
#elif @OIIO_USING_IMATH@ >= 3
# include <Imath/half.h>
#else
# include <OpenEXR/half.h>
#endif
2 changes: 1 addition & 1 deletion src/include/OpenImageIO/imagebufalgo_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <functional>

#include <OpenImageIO/Imath.h>
#include <OpenImageIO/half.h>
#include <OpenImageIO/parallel.h>
#include <OpenImageIO/imagebufalgo.h>

Expand Down
145 changes: 57 additions & 88 deletions src/include/OpenImageIO/simd.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include <cstring>

#ifdef OIIO_INTERNAL
# include <OpenImageIO/Imath.h>
# include <OpenImageIO/half.h>
#endif

#include <OpenImageIO/dassert.h>
Expand Down Expand Up @@ -1860,6 +1860,18 @@ class vfloat4 {
/// Construct from the underlying SIMD type
vfloat4 (const simd_t& m) : m_simd(m) { }

/// Construct from a generic subscripted 3-vector, including Imath::V3f.
template<typename V, OIIO_ENABLE_IF(has_subscript_N<V, value_t, 3>::value
&& !std::is_same<V, vfloat3>::value)>
explicit vfloat4 (const V& v) { load (v[0], v[1], v[2]); }

/// Construct from a generic subscripted or xyzw 4-vector, including
/// Imath::V4f.
template<typename V, OIIO_ENABLE_IF((has_subscript_N<V, value_t, 4>::value
|| has_xyzw<V, value_t>::value))
&& !std::is_same<V, vfloat4>::value>
explicit vfloat4(const V& v) { load ((const value_t *)&v); }

/// Return the raw SIMD type
operator simd_t () const { return m_simd; }
simd_t simd () const { return m_simd; }
Expand All @@ -1870,15 +1882,9 @@ class vfloat4 {
value_t* data () { return (value_t*)this; }

#ifdef INCLUDED_IMATHVEC_H
/// Construct from a Imath::V3f
explicit vfloat4 (const Imath::V3f &v) { load (v[0], v[1], v[2]); }

/// Cast to a Imath::V3f
const Imath::V3f& V3f () const { return *(const Imath::V3f*)this; }

/// Construct from a Imath::V4f
explicit vfloat4 (const Imath::V4f &v) { load ((const float *)&v); }

/// Cast to a Imath::V4f
const Imath::V4f& V4f () const { return *(const Imath::V4f*)this; }
#endif
Expand Down Expand Up @@ -1922,13 +1928,24 @@ class vfloat4 {
/// Set all components to 0.0
void clear ();

#ifdef INCLUDED_IMATHVEC_H
/// Assign from a Imath::V4f
const vfloat4 & operator= (const Imath::V4f &v);
/// Assign from a generic subscripted or xyzw 4-vector, including an
/// Imath::V4f.
template<typename V, OIIO_ENABLE_IF((has_subscript_N<V, value_t, 4>::value
|| has_xyzw<V, value_t>::value)
&& !std::is_same<V, vfloat4>::value)>
const vfloat4 & operator= (const V& v) {
load ((const float *)&v);
return *this;
}

/// Assign from a Imath::V3f
const vfloat4 & operator= (const Imath::V3f &v);
#endif
/// Assign from a generic subscripted 3-vector, including an
/// Imath::V3f.
template<typename V, OIIO_ENABLE_IF(has_subscript_N<V, value_t, 3>::value
&& !std::is_same<V, vfloat3>::value)>
const vfloat4 & operator= (const V& v) {
load (v[0], v[1], v[2], 0.0f);
return *this;
}

/// Component access (get)
float operator[] (int i) const;
Expand Down Expand Up @@ -2233,9 +2250,6 @@ class vfloat3 : public vfloat4 {
#endif

#ifdef INCLUDED_IMATHVEC_H
/// Construct from a Imath::V3f
// vfloat3 (const Imath::V3f &v) : vfloat4(v) { }

/// Cast to a Imath::V3f
const Imath::V3f& V3f () const { return *(const Imath::V3f*)this; }
#endif
Expand Down Expand Up @@ -2304,10 +2318,13 @@ class vfloat3 : public vfloat4 {
void store (half *values) const;
#endif

#ifdef INCLUDED_IMATHVEC_H
/// Store into an Imath::V3f reference.
void store (Imath::V3f &vec) const;
#endif
/// Store into a generic subscripted or xyz 3-vector, including Imath::V3f.
template<typename V, OIIO_ENABLE_IF((has_subscript_N<V, value_t, 3>::value
|| has_xyzw<V, value_t>::value)
&& !std::is_same<V, vfloat3>::value)>
void store(V& vec) const {
store((value_t *)&vec);
}

// Math operators -- define in terms of vfloat3.
friend vfloat3 operator+ (const vfloat3& a, const vfloat3& b);
Expand Down Expand Up @@ -2371,16 +2388,6 @@ class matrix44 {
m_row[3] = M[3];
}

#ifdef INCLUDED_IMATHMATRIX_H
/// Construct from a reference to an Imath::M44f
OIIO_FORCEINLINE explicit matrix44 (const Imath::M44f &M) {
m_row[0].load (M[0]);
m_row[1].load (M[1]);
m_row[2].load (M[2]);
m_row[3].load (M[3]);
}
#endif

/// Construct from a float array
OIIO_FORCEINLINE explicit matrix44 (const float *f) {
m_row[0].load (f+0);
Expand Down Expand Up @@ -2451,12 +2458,10 @@ class matrix44 {

bool operator!= (const matrix44& m) const;

#ifdef INCLUDED_IMATHMATRIX_H
bool operator== (const Imath::M44f& m) const ;
friend bool operator== (const Imath::M44f& a, const matrix44 &b);
bool operator!= (const Imath::M44f& m) const;
friend bool operator!= (const Imath::M44f& a, const matrix44 &b);
#endif
bool operator== (M44fParam m) const ;
friend bool operator== (M44fParam a, const matrix44 &b);
bool operator!= (M44fParam m) const;
friend bool operator!= (M44fParam a, const matrix44 &b);

/// Return the inverse of the matrix.
matrix44 inverse() const;
Expand All @@ -2480,11 +2485,9 @@ vfloat3 transformv (const matrix44 &M, const vfloat3 &V);
// Transform 3-vector by the transpose of 4x4 matrix M.
vfloat3 transformvT (const matrix44 &M, const vfloat3 &V);

#ifdef INCLUDED_IMATHMATRIX_H
vfloat3 transformp (const Imath::M44f &M, const vfloat3 &V);
vfloat3 transformv (const Imath::M44f &M, const vfloat3 &V);
vfloat3 transformvT (const Imath::M44f &M, const vfloat3 &V);
#endif
vfloat3 transformp (M44fParam M, const vfloat3 &V);
vfloat3 transformv (M44fParam M, const vfloat3 &V);
vfloat3 transformvT (M44fParam M, const vfloat3 &V);



Expand Down Expand Up @@ -6617,17 +6620,6 @@ OIIO_FORCEINLINE void vfloat4::clear () {
#endif
}

#ifdef INCLUDED_IMATHVECTOR_H
OIIO_FORCEINLINE const vfloat4 & vfloat4::operator= (const Imath::V4f &v) {
load ((const float *)&v);
return *this;
}

OIIO_FORCEINLINE const vfloat4 & vfloat4::operator= (const Imath::V3f &v) {
load (v[0], v[1], v[2], 0.0f);
return *this;
}
#endif

OIIO_FORCEINLINE float& vfloat4::operator[] (int i) {
OIIO_DASSERT(i<elements);
Expand Down Expand Up @@ -7991,11 +7983,6 @@ OIIO_FORCEINLINE void vfloat3::store (half *values) const {
}
#endif

#ifdef INCLUDED_IMATHVECTOR_H
OIIO_FORCEINLINE void vfloat3::store (Imath::V3f &vec) const {
store ((float *)&vec);
}
#endif

OIIO_FORCEINLINE vfloat3 operator+ (const vfloat3& a, const vfloat3& b) {
return vfloat3 (vfloat4(a) + vfloat4(b));
Expand Down Expand Up @@ -8329,23 +8316,23 @@ OIIO_FORCEINLINE bool matrix44::operator!= (const matrix44& m) const {
#endif
}

#ifdef INCLUDED_IMATHMATRIX_H
OIIO_FORCEINLINE bool matrix44::operator== (const Imath::M44f& m) const {
return memcmp(this, &m, 16*sizeof(float)) == 0;

OIIO_FORCEINLINE bool matrix44::operator== (M44fParam m) const {
return memcmp(this, m.data(), 16*sizeof(float)) == 0;
}

OIIO_FORCEINLINE bool operator== (const Imath::M44f& a, const matrix44 &b) {
OIIO_FORCEINLINE bool operator== (M44fParam a, const matrix44 &b) {
return (b == a);
}

OIIO_FORCEINLINE bool matrix44::operator!= (const Imath::M44f& m) const {
return memcmp(this, &m, 16*sizeof(float)) != 0;
OIIO_FORCEINLINE bool matrix44::operator!= (M44fParam m) const {
return memcmp(this, m.data(), 16*sizeof(float)) != 0;
}

OIIO_FORCEINLINE bool operator!= (const Imath::M44f& a, const matrix44 &b) {
OIIO_FORCEINLINE bool operator!= (M44fParam a, const matrix44 &b) {
return (b != a);
}
#endif


#if OIIO_SIMD_SSE
OIIO_FORCEINLINE matrix44 matrix44::inverse() const {
Expand Down Expand Up @@ -8456,38 +8443,20 @@ OIIO_FORCEINLINE vfloat3 transformvT (const matrix44 &M, const vfloat3 &V)
}


#ifdef INCLUDED_IMATHMATRIX_H
OIIO_FORCEINLINE vfloat3 transformp (const Imath::M44f &M, const vfloat3 &V)
OIIO_FORCEINLINE vfloat3 transformp (M44fParam M, const vfloat3 &V)
{
#if OIIO_SIMD
return matrix44(M).transformp (V);
#else
Imath::V3f R;
M.multVecMatrix (*(const Imath::V3f *)&V, R);
return vfloat3(R);
#endif
return matrix44(M).transformp(V);
}

OIIO_FORCEINLINE vfloat3 transformv (const Imath::M44f &M, const vfloat3 &V)
OIIO_FORCEINLINE vfloat3 transformv (M44fParam M, const vfloat3 &V)
{
#if OIIO_SIMD
return matrix44(M).transformv (V);
#else
Imath::V3f R;
M.multDirMatrix (*(const Imath::V3f *)&V, R);
return vfloat3(R);
#endif
return matrix44(M).transformv(V);
}

OIIO_FORCEINLINE vfloat3 transformvT (const Imath::M44f &M, const vfloat3 &V)
OIIO_FORCEINLINE vfloat3 transformvT (M44fParam M, const vfloat3 &V)
{
#if OIIO_SIMD
return matrix44(M).transformvT(V);
#else
return transformv (M.transposed(), V);
#endif
}
#endif



Expand Down
22 changes: 19 additions & 3 deletions src/include/OpenImageIO/vecparam.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ OIIO_NAMESPACE_BEGIN
/// stating that `mytype` should be considered a subscriptable 3-vector:
///
/// template<>
/// struct OIIO::has_subscript<mytype, float, 3> : public std::true_type { };
/// struct OIIO::has_subscript_N<mytype, float, 3> : public std::true_type { };
///
/// And similarly, user code may correct a potential false positive (that
/// is, a `mytype` looks like it should be a 3-vector, but we don't want any
/// implicit conversions to happen):
///
/// template<typename B, int N>
/// struct OIIO::has_subscript<mytype, B, N> : public std::false_type { };
/// struct OIIO::has_subscript_N<mytype, B, N> : public std::false_type { };
///


Expand Down Expand Up @@ -274,7 +274,23 @@ template<typename T> class Vec3Param {
}
#endif

private:
// Return a reference to the contiguous values comprising the matrix.
template<typename V, OIIO_ENABLE_IF(sizeof(V) == 3 * sizeof(T))>
constexpr const V& cast() const noexcept
{
const char* p = (const char*)this;
return *(const V*)p;
}

/// Implicitly convert a `Vec3Param<T>` to a `const V&` for a V that looks
/// like a 3-vector.
template<typename V, OIIO_ENABLE_IF(has_subscript_N<V, T, 3>::value
|| has_xyz<V, T>::value)>
OIIO_HOSTDEVICE constexpr operator const V&() const noexcept
{
return cast<V>();
}

// The internal representation is just the 3 values.
T x, y, z;
};
Expand Down
5 changes: 3 additions & 2 deletions src/libOpenImageIO/color_ocio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1393,9 +1393,10 @@ ColorConfig::createFileTransform(ustring name, bool inverse) const


ColorProcessorHandle
ColorConfig::createMatrixTransform(const Imath::M44f& M, bool inverse) const
ColorConfig::createMatrixTransform(M44fParam M, bool inverse) const
{
return ColorProcessorHandle(new ColorProcessor_Matrix(M, inverse));
return ColorProcessorHandle(
new ColorProcessor_Matrix(*(const Imath::M44f*)M.data(), inverse));
}


Expand Down
Loading