Skip to content

Commit

Permalink
Fix flat image to use same mechanism for extern template instantiatio…
Browse files Browse the repository at this point in the history
…n as Deep

Signed-off-by: Kimball Thurston <kdt3rd@gmail.com>
  • Loading branch information
kdt3rd committed Mar 14, 2021
1 parent 879513f commit 6cf6719
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 88 deletions.
104 changes: 104 additions & 0 deletions src/lib/OpenEXRUtil/ImfFlatImageChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
// class FlatImageChannel
//
//----------------------------------------------------------------------------
#include "ImfUtilExport.h"
#include <ImathExport.h>
#include <ImathNamespace.h>

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"
Expand Down Expand Up @@ -58,4 +67,99 @@ FlatImageChannel::resize ()
}


//-----------------------------------------------------------------------------


template <class T>
TypedFlatImageChannel<T>::TypedFlatImageChannel
(FlatImageLevel &level,
int xSampling,
int ySampling,
bool pLinear)
:
FlatImageChannel (level, xSampling, ySampling, pLinear),
_pixels (0),
_base (0)
{
resize();
}


template <class T>
TypedFlatImageChannel<T>::~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 <class T>
Slice
TypedFlatImageChannel<T>::slice () const
{
return Slice (pixelType(), // type
(char *) _base, // base
sizeof (T), // xStride
pixelsPerRow() * sizeof (T), // yStride
xSampling(),
ySampling());
}


template <class T>
void
TypedFlatImageChannel<T>::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 <class T>
void
TypedFlatImageChannel<T>::resetBasePointer ()
{
_base = _pixels -
(level().dataWindow().min.y / ySampling()) * pixelsPerRow() -
(level().dataWindow().min.x / xSampling());
}


template class IMFUTIL_EXPORT_TEMPLATE_INSTANCE TypedFlatImageChannel<half>;
template class IMFUTIL_EXPORT_TEMPLATE_INSTANCE TypedFlatImageChannel<float>;
template class IMFUTIL_EXPORT_TEMPLATE_INSTANCE TypedFlatImageChannel<unsigned int>;


OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT
97 changes: 9 additions & 88 deletions src/lib/OpenEXRUtil/ImfFlatImageChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,24 +139,24 @@ 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;
TypedFlatImageChannel& operator = (const TypedFlatImageChannel& other) = delete;
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
Expand All @@ -178,63 +178,6 @@ typedef TypedFlatImageChannel<unsigned int> FlatUIntChannel;
//-----------------------------------------------------------------------------


template <class T>
TypedFlatImageChannel<T>::TypedFlatImageChannel
(FlatImageLevel &level,
int xSampling,
int ySampling,
bool pLinear)
:
FlatImageChannel (level, xSampling, ySampling, pLinear),
_pixels (0),
_base (0)
{
resize();
}


template <class T>
TypedFlatImageChannel<T>::~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 <class T>
Slice
TypedFlatImageChannel<T>::slice () const
{
return Slice (pixelType(), // type
(char *) _base, // base
sizeof (T), // xStride
pixelsPerRow() * sizeof (T), // yStride
xSampling(),
ySampling());
}


template <class T>
Expand Down Expand Up @@ -286,33 +229,11 @@ TypedFlatImageChannel<T>::row (int n) const
return _base + n * pixelsPerRow();
}


template <class T>
void
TypedFlatImageChannel<T>::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 <class T>
void
TypedFlatImageChannel<T>::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<half>;
extern template class IMFUTIL_EXPORT_EXTERN_TEMPLATE TypedFlatImageChannel<float>;
extern template class IMFUTIL_EXPORT_EXTERN_TEMPLATE TypedFlatImageChannel<unsigned int>;
#endif

OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT

Expand Down

0 comments on commit 6cf6719

Please sign in to comment.