Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Larry Gritz <lg@larrygritz.com>
  • Loading branch information
lgritz committed Oct 2, 2024
1 parent 4007409 commit 7acf4b1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 14 deletions.
57 changes: 45 additions & 12 deletions src/include/OpenImageIO/imagebufalgo_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,51 @@ inline bool is_common_pixel_type(TypeDesc t)
break; \
}

// Macro to call a type-specialized version func<Rtype,Atype>(R,A,...) for
// the most common types. It will auto-convert remaining rare cases to float.
#define OIIO_DISPATCH_COMMON_TYPES2_FULL(ret, name, func, Rtype_, Atype_, R, A, ...)\
{ \
OIIO_ASSERT((R).initialized()); \
ret = false; \
auto Rptr = &R; \
auto Aptr = &A; \
ImageBuf Rtmp, Atmp; \
TypeDesc Rtype = Rtype_, Atype = Atype_; \
if (!ImageBufAlgo::is_common_pixel_type(Atype)) { \
Atype = TypeDesc::FLOAT; \
Atmp.copy(A, Atype); \
Aptr = &Atmp; \
} \
if (!ImageBufAlgo::is_common_pixel_type(Rtype)) { \
Rtype = TypeDesc::FLOAT; \
Rtmp.copy(R, Rtype); \
Rptr = &Rtmp; \
} \
if (Rtype == TypeFloat) { \
OIIO_DISPATCH_COMMON_TYPES2_HELP(ret, name, func, float, Atype, \
*Rptr, *Aptr, __VA_ARGS__); \
} else if (Rtype == TypeUInt8) { \
OIIO_DISPATCH_COMMON_TYPES2_HELP(ret, name, func, uint8_t, Atype, \
*Rptr, *Aptr, __VA_ARGS__); \
} else if (Rtype == TypeHalf) { \
OIIO_DISPATCH_COMMON_TYPES2_HELP(ret, name, func, half, Atype, \
*Rptr, *Aptr, __VA_ARGS__); \
} else if (Rtype == TypeUInt16) { \
OIIO_DISPATCH_COMMON_TYPES2_HELP(ret, name, func, uint16_t, Atype, \
*Rptr, *Aptr, __VA_ARGS__); \
} else { \
OIIO_DASSERT(0 && "bad type"); \
} \
if (Rptr != &(R)) { \
/* If we used Rtmp, copy pixels or errors to the real R */ \
if (ret) \
(R).copy(*Rptr); \
else \
(R).errorfmt("{}", Rptr->geterror()); \
} \
}


// Macro to call a type-specialized version func<Rtype,Atype>(R,A,...) for
// the most common types. It will auto-convert remaining rare cases to float.
#define OIIO_DISPATCH_COMMON_TYPES2(ret, name, func, Rtype_, Atype_, R, A, ...)\
Expand All @@ -438,8 +483,6 @@ inline bool is_common_pixel_type(TypeDesc t)
} \
OIIO_ASSERT(Rtype == TypeFloat || Rtype == Atype); \
if (Rtype == TypeFloat) { \
/*OIIO_DISPATCH_COMMON_TYPES2_HELP(ret, name, func, float, Atype,*/ \
/* *Rptr, *Aptr, __VA_ARGS__);*/ \
switch (Atype.basetype) { \
case TypeDesc::FLOAT : \
ret = func<float,float> (*Rptr, *Aptr, __VA_ARGS__); break; \
Expand All @@ -455,8 +498,6 @@ inline bool is_common_pixel_type(TypeDesc t)
break; \
} \
} else if (Rtype == TypeUInt8) { \
/*OIIO_DISPATCH_COMMON_TYPES2_HELP(ret, name, func, uint8_t, Atype,*/ \
/* *Rptr, *Aptr, __VA_ARGS__);*/ \
switch (Atype.basetype) { \
case TypeDesc::FLOAT : \
ret = func<uint8_t,float> (*Rptr, *Aptr, __VA_ARGS__); break; \
Expand All @@ -472,8 +513,6 @@ inline bool is_common_pixel_type(TypeDesc t)
break; \
} \
} else if (Rtype == TypeHalf) { \
/*OIIO_DISPATCH_COMMON_TYPES2_HELP(ret, name, func, half, Atype,*/ \
/* *Rptr, *Aptr, __VA_ARGS__);*/ \
switch (Atype.basetype) { \
case TypeDesc::FLOAT : \
ret = func<half,float> (*Rptr, *Aptr, __VA_ARGS__); break; \
Expand All @@ -489,8 +528,6 @@ inline bool is_common_pixel_type(TypeDesc t)
break; \
} \
} else if (Rtype == TypeUInt16) { \
/*OIIO_DISPATCH_COMMON_TYPES2_HELP(ret, name, func, uint16_t, Atype,*/ \
/* *Rptr, *Aptr, __VA_ARGS__);*/ \
switch (Atype.basetype) { \
case TypeDesc::FLOAT : \
ret = func<uint16_t,float> (*Rptr, *Aptr, __VA_ARGS__); break; \
Expand Down Expand Up @@ -613,7 +650,6 @@ inline bool is_common_pixel_type(TypeDesc t)
OIIO_ASSERT(Rtype == Atype || Rtype == TypeFloat); \
switch (Atype.basetype) { \
case TypeDesc::FLOAT : \
/*OIIO_DISPATCH_COMMON_TYPES3_HELP(ret,name,func,Rtype,float,float,*Rptr,*Aptr,*Bptr,__VA_ARGS__);*/ \
switch (Rtype.basetype) { \
case TypeDesc::FLOAT : \
ret = func<float,float,float>(*Rptr,*Aptr,*Bptr,__VA_ARGS__); break; \
Expand All @@ -629,7 +665,6 @@ inline bool is_common_pixel_type(TypeDesc t)
} \
break; \
case TypeDesc::UINT8 : \
/* OIIO_DISPATCH_COMMON_TYPES3_HELP(ret,name,func,Rtype,uint8_t,uint8_t,*Rptr,*Aptr,*Bptr,__VA_ARGS__);*/ \
switch (Rtype.basetype) { \
case TypeDesc::FLOAT : \
ret = func<float,uint8_t,uint8_t>(*Rptr,*Aptr,*Bptr,__VA_ARGS__); break; \
Expand All @@ -645,7 +680,6 @@ inline bool is_common_pixel_type(TypeDesc t)
} \
break; \
case TypeDesc::HALF : \
/* OIIO_DISPATCH_COMMON_TYPES3_HELP(ret,name,func,Rtype,half,half,*Rptr,*Aptr,*Bptr,__VA_ARGS__);*/ \
switch (Rtype.basetype) { \
case TypeDesc::FLOAT : \
ret = func<float,half,half>(*Rptr,*Aptr,*Bptr,__VA_ARGS__); break; \
Expand All @@ -661,7 +695,6 @@ inline bool is_common_pixel_type(TypeDesc t)
} \
break; \
case TypeDesc::UINT16: \
/* OIIO_DISPATCH_COMMON_TYPES3_HELP(ret,name,func,Rtype,uint16_t,uint16_t,*Rptr,*Aptr,*Bptr,__VA_ARGS__);*/ \
switch (Rtype.basetype) { \
case TypeDesc::FLOAT : \
ret = func<float,uint16_t,uint16_t>(*Rptr,*Aptr,*Bptr,__VA_ARGS__); break; \
Expand Down
4 changes: 2 additions & 2 deletions testsuite/docs-examples-cpp/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ crop.exr : 200 x 100, 4 channel, half openexr
SHA-1: 4DA3918566D087A9D2D9E93B2A7BABE971FE6BBD
cut.exr : 200 x 100, 4 channel, half openexr
SHA-1: 4DA3918566D087A9D2D9E93B2A7BABE971FE6BBD
paste.exr : 256 x 256, 4 channel, half openexr
SHA-1: 67A4C36DEAED98A5A8ABA5F0E0EDE697345DC22A
paste.exr : 256 x 256, 4 channel, float openexr
SHA-1: ABE3206D533C8C643DD6033E672C6A51BEDB73D5
rotate-90.exr : 256 x 256, 4 channel, half openexr
SHA-1: AFFAEA876E8E7760226B017B0A89A3549B7A5895
rotate-180.exr : 256 x 256, 4 channel, half openexr
Expand Down

0 comments on commit 7acf4b1

Please sign in to comment.