Skip to content

Hide Imath headers and types from most of the public API #3301

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
Jan 28, 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
5 changes: 4 additions & 1 deletion src/doc/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -2173,7 +2173,10 @@ PREDEFINED = DOXYGEN_SHOULD_SKIP_THIS \
OIIO_NODISCARD=[[nodiscard]] \
OIIO_DEPRECATED:=[[deprecated]] \
OIIO_FORMAT_DEPRECATED:= \
OIIO_FORCEINLINE=inline
OIIO_FORCEINLINE=inline \
IMATH_HALF_H_=1 \
INCLUDED_IMATHVEC_H=1 \
INCLUDED_IMATHMATRIX_H=1 \


# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
Expand Down
2 changes: 2 additions & 0 deletions src/include/OpenImageIO/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,10 @@ 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,
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
76 changes: 46 additions & 30 deletions src/include/OpenImageIO/fmath.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include <typeinfo>
#include <type_traits>

#include <OpenImageIO/Imath.h>
#include <OpenImageIO/span.h>
#include <OpenImageIO/dassert.h>
#include <OpenImageIO/oiioversion.h>
Expand All @@ -47,6 +46,15 @@

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
/// 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
# define OIIO_FMATH_HEADER_ONLY 0
#endif


/// Occasionally there may be a tradeoff where the best/fastest
/// implementation of a math function in an ordinary scalar context does
/// things that prevent autovectorization (or OMP pragma vectorization) of a
Expand Down Expand Up @@ -1042,32 +1050,6 @@ inline void convert_type<uint16_t,float> (const uint16_t *src,
}


#if defined(_HALF_H_) || defined(IMATH_HALF_H_)
template<>
inline void convert_type<half,float> (const half *src,
float *dst, size_t n,
float /*_min*/, float /*_max*/)
{
#if OIIO_SIMD >= 8 && OIIO_F16C_ENABLED
// If f16c ops are enabled, it's worth doing this by 8's
for ( ; n >= 8; n -= 8, src += 8, dst += 8) {
simd::vfloat8 s_simd (src);
s_simd.store (dst);
}
#endif
#if OIIO_SIMD >= 4
for ( ; n >= 4; n -= 4, src += 4, dst += 4) {
simd::vfloat4 s_simd (src);
s_simd.store (dst);
}
#endif
while (n--)
*dst++ = (*src++);
}
#endif



template<>
inline void
convert_type<float,uint16_t> (const float *src, uint16_t *dst, size_t n,
Expand Down Expand Up @@ -1112,7 +1094,39 @@ convert_type<float,uint8_t> (const float *src, uint8_t *dst, size_t n,

#if defined(_HALF_H_) || defined(IMATH_HALF_H_)
template<>
inline void
OIIO_UTIL_API
void convert_type<half,float> (const half *src, float *dst, size_t n,
float /*_min*/, float /*_max*/);
template<>
OIIO_UTIL_API
void convert_type<float,half> (const float *src, half *dst, size_t n,
half /*_min*/, half /*_max*/);

#if OIIO_FMATH_HEADER_ONLY
// Not just the declarations, give the definitions here.
template<>
void convert_type<half,float> (const half *src, float *dst, size_t n,
float /*_min*/, float /*_max*/)
{
#if OIIO_SIMD >= 8 && OIIO_F16C_ENABLED
// If f16c ops are enabled, it's worth doing this by 8's
for ( ; n >= 8; n -= 8, src += 8, dst += 8) {
simd::vfloat8 s_simd (src);
s_simd.store (dst);
}
#endif
#if OIIO_SIMD >= 4
for ( ; n >= 4; n -= 4, src += 4, dst += 4) {
simd::vfloat4 s_simd (src);
s_simd.store (dst);
}
#endif
while (n--)
*dst++ = (*src++);
}

template<>
void
convert_type<float,half> (const float *src, half *dst, size_t n,
half /*_min*/, half /*_max*/)
{
Expand All @@ -1132,8 +1146,10 @@ convert_type<float,half> (const float *src, half *dst, size_t n,
while (n--)
*dst++ = *src++;
}
#endif
#endif
#endif /* if OIIO_FMATH_HEADER_ONLY */
#endif /* if defined(IMATH_HALF_H_) */

#endif /* ifndef __CUDA_ARCH__ */



Expand Down
2 changes: 1 addition & 1 deletion src/include/OpenImageIO/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <utility>
#include <vector>

#include <OpenImageIO/span.h>
#include <OpenImageIO/export.h>
#include <OpenImageIO/oiioversion.h>
#include <OpenImageIO/string_view.h>
Expand All @@ -31,6 +30,7 @@
# include <OpenImageIO/fmath.h>
#endif

#include <OpenImageIO/span.h>


OIIO_NAMESPACE_BEGIN
Expand Down
14 changes: 14 additions & 0 deletions src/include/OpenImageIO/imagebufalgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,12 @@ bool OIIO_API fit (ImageBuf &dst, const ImageBuf &src, Filter2D *filter,
/// filter is used to weight the `src` pixels falling underneath it for each
/// `dst` pixel; the filter's size is expressed in pixel units of the `dst`
/// image.
///
/// Note: C++ users must include `ImathMatrix.h` (or `OpenImageIO/Imath.h`)
/// prior to including `imagebufalgo.h` to see define the Imath::M33f class,
/// or else the `warp()` function declaration will not be visible.

#ifdef INCLUDED_IMATHMATRIX_H
ImageBuf OIIO_API warp (const ImageBuf &src, const Imath::M33f &M,
string_view filtername = string_view(),
float filterwidth = 0.0f, bool recompute_roi = false,
Expand All @@ -786,6 +791,7 @@ bool OIIO_API warp (ImageBuf &dst, const ImageBuf &src, const Imath::M33f &M,
const Filter2D *filter, bool recompute_roi = false,
ImageBuf::WrapMode wrap = ImageBuf::WrapDefault,
ROI roi = {}, int nthreads=0);
#endif
/// @}


Expand Down Expand Up @@ -1796,13 +1802,21 @@ inline bool colorconvert (float *color, int nchannels,
/// "not pre-multiplied colors").
///
/// @version 2.1+
///
/// Note: C++ users must include `ImathMatrix.h` (or `OpenImageIO/Imath.h`)
/// prior to including `imagebufalgo.h` to see define the Imath::M44f class,
/// or else the `colormatrixtransform()` function declaration will not be
/// visible.

#ifdef INCLUDED_IMATHMATRIX_H
ImageBuf OIIO_API colormatrixtransform (const ImageBuf &src,
const Imath::M44f& M, bool unpremult=true,
ROI roi={}, int nthreads=0);
/// Write to an existing image `dst` (allocating if it is uninitialized).
bool OIIO_API colormatrixtransform (ImageBuf &dst, const ImageBuf &src,
const Imath::M44f& M, bool unpremult=true,
ROI roi={}, int nthreads=0);
#endif


/// Return a copy of the pixels of `src` within the ROI, applying an
Expand Down
1 change: 1 addition & 0 deletions src/include/OpenImageIO/imagebufalgo_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <functional>

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

Expand Down
Loading