From 6cf6719ba03003b4a9c609690a07b1dcc85ed6a5 Mon Sep 17 00:00:00 2001 From: Kimball Thurston Date: Sun, 14 Mar 2021 17:16:14 +1300 Subject: [PATCH] Fix flat image to use same mechanism for extern template instantiation as Deep Signed-off-by: Kimball Thurston --- src/lib/OpenEXRUtil/ImfFlatImageChannel.cpp | 104 ++++++++++++++++++++ src/lib/OpenEXRUtil/ImfFlatImageChannel.h | 97 ++---------------- 2 files changed, 113 insertions(+), 88 deletions(-) diff --git a/src/lib/OpenEXRUtil/ImfFlatImageChannel.cpp b/src/lib/OpenEXRUtil/ImfFlatImageChannel.cpp index 34bb202b63..c5d3f09579 100644 --- a/src/lib/OpenEXRUtil/ImfFlatImageChannel.cpp +++ b/src/lib/OpenEXRUtil/ImfFlatImageChannel.cpp @@ -8,6 +8,15 @@ // class FlatImageChannel // //---------------------------------------------------------------------------- +#include "ImfUtilExport.h" +#include +#include + +IMATH_INTERNAL_NAMESPACE_HEADER_ENTER +class IMFUTIL_EXPORT_TYPE half; +IMATH_INTERNAL_NAMESPACE_HEADER_EXIT + +#define COMPILING_IMF_FLAT_IMAGE_CHANNEL #include "ImfFlatImageChannel.h" #include "ImfFlatImageLevel.h" @@ -58,4 +67,99 @@ FlatImageChannel::resize () } +//----------------------------------------------------------------------------- + + +template +TypedFlatImageChannel::TypedFlatImageChannel + (FlatImageLevel &level, + int xSampling, + int ySampling, + bool pLinear) +: + FlatImageChannel (level, xSampling, ySampling, pLinear), + _pixels (0), + _base (0) +{ + resize(); +} + + +template +TypedFlatImageChannel::~TypedFlatImageChannel () +{ + delete [] _pixels; +} + + +template <> +inline PixelType +FlatHalfChannel::pixelType () const +{ + return HALF; +} + + +template <> +inline PixelType +FlatFloatChannel::pixelType () const +{ + return FLOAT; +} + + +template <> +inline PixelType +FlatUIntChannel::pixelType () const +{ + return UINT; +} + + +template +Slice +TypedFlatImageChannel::slice () const +{ + return Slice (pixelType(), // type + (char *) _base, // base + sizeof (T), // xStride + pixelsPerRow() * sizeof (T), // yStride + xSampling(), + ySampling()); +} + + +template +void +TypedFlatImageChannel::resize () +{ + delete [] _pixels; + _pixels = 0; + + FlatImageChannel::resize(); // may throw an exception + + _pixels = new T [numPixels()]; + + for (size_t i = 0; i < numPixels(); ++i) + _pixels[i] = T (0); + + resetBasePointer (); +} + + +template +void +TypedFlatImageChannel::resetBasePointer () +{ + _base = _pixels - + (level().dataWindow().min.y / ySampling()) * pixelsPerRow() - + (level().dataWindow().min.x / xSampling()); +} + + +template class IMFUTIL_EXPORT_TEMPLATE_INSTANCE TypedFlatImageChannel; +template class IMFUTIL_EXPORT_TEMPLATE_INSTANCE TypedFlatImageChannel; +template class IMFUTIL_EXPORT_TEMPLATE_INSTANCE TypedFlatImageChannel; + + OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT diff --git a/src/lib/OpenEXRUtil/ImfFlatImageChannel.h b/src/lib/OpenEXRUtil/ImfFlatImageChannel.h index e300a394a6..aa0064ab69 100644 --- a/src/lib/OpenEXRUtil/ImfFlatImageChannel.h +++ b/src/lib/OpenEXRUtil/ImfFlatImageChannel.h @@ -139,13 +139,13 @@ class IMFUTIL_EXPORT_TEMPLATE_TYPE TypedFlatImageChannel: public FlatImageChanne // image channels exist only as parts of a flat image level. // - IMF_HIDDEN + IMFUTIL_HIDDEN TypedFlatImageChannel (FlatImageLevel &level, int xSampling, int ySampling, bool pLinear); - IMF_HIDDEN + IMFUTIL_HIDDEN virtual ~TypedFlatImageChannel (); TypedFlatImageChannel (const TypedFlatImageChannel& other) = delete; @@ -153,10 +153,10 @@ class IMFUTIL_EXPORT_TEMPLATE_TYPE TypedFlatImageChannel: public FlatImageChanne TypedFlatImageChannel (TypedFlatImageChannel&& other) = delete; TypedFlatImageChannel& operator = (TypedFlatImageChannel&& other) = delete; - IMF_HIDDEN + IMFUTIL_HIDDEN virtual void resize (); - IMF_HIDDEN + IMFUTIL_HIDDEN virtual void resetBasePointer (); T * _pixels; // Pointer to allocated storage @@ -178,63 +178,6 @@ typedef TypedFlatImageChannel FlatUIntChannel; //----------------------------------------------------------------------------- -template -TypedFlatImageChannel::TypedFlatImageChannel - (FlatImageLevel &level, - int xSampling, - int ySampling, - bool pLinear) -: - FlatImageChannel (level, xSampling, ySampling, pLinear), - _pixels (0), - _base (0) -{ - resize(); -} - - -template -TypedFlatImageChannel::~TypedFlatImageChannel () -{ - delete [] _pixels; -} - - -template <> -inline PixelType -FlatHalfChannel::pixelType () const -{ - return HALF; -} - - -template <> -inline PixelType -FlatFloatChannel::pixelType () const -{ - return FLOAT; -} - - -template <> -inline PixelType -FlatUIntChannel::pixelType () const -{ - return UINT; -} - - -template -Slice -TypedFlatImageChannel::slice () const -{ - return Slice (pixelType(), // type - (char *) _base, // base - sizeof (T), // xStride - pixelsPerRow() * sizeof (T), // yStride - xSampling(), - ySampling()); -} template @@ -286,33 +229,11 @@ TypedFlatImageChannel::row (int n) const return _base + n * pixelsPerRow(); } - -template -void -TypedFlatImageChannel::resize () -{ - delete [] _pixels; - _pixels = 0; - - FlatImageChannel::resize(); // may throw an exception - - _pixels = new T [numPixels()]; - - for (size_t i = 0; i < numPixels(); ++i) - _pixels[i] = T (0); - - resetBasePointer (); -} - - -template -void -TypedFlatImageChannel::resetBasePointer () -{ - _base = _pixels - - (level().dataWindow().min.y / ySampling()) * pixelsPerRow() - - (level().dataWindow().min.x / xSampling()); -} +#ifndef COMPILING_IMF_FLAT_IMAGE_CHANNEL +extern template class IMFUTIL_EXPORT_EXTERN_TEMPLATE TypedFlatImageChannel; +extern template class IMFUTIL_EXPORT_EXTERN_TEMPLATE TypedFlatImageChannel; +extern template class IMFUTIL_EXPORT_EXTERN_TEMPLATE TypedFlatImageChannel; +#endif OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT