diff --git a/include/fused_kernel/algorithms/image_processing/color_conversion.h b/include/fused_kernel/algorithms/image_processing/color_conversion.h index 691969a9..bee1a556 100644 --- a/include/fused_kernel/algorithms/image_processing/color_conversion.h +++ b/include/fused_kernel/algorithms/image_processing/color_conversion.h @@ -88,7 +88,7 @@ namespace fk { DECLARE_UNARY_PARENT FK_HOST_DEVICE_FUSE OutputType exec(const InputType input) { constexpr auto alpha = maxDepthValue; - return AddLast::exec(input, { alpha }); + return AddLast::exec(input, { static_cast>(alpha) }); } }; @@ -147,37 +147,28 @@ namespace fk { } }; - template + template struct ConvertYUVToRGB { private: - using SelfType = ConvertYUVToRGB; - using Parent = UnaryOperation, ColorDepthPixelType, ConvertYUVToRGB>; + using SelfType = ConvertYUVToRGB; + using Parent = UnaryOperation, float3, SelfType >; public: FK_STATIC_STRUCT(ConvertYUVToRGB, SelfType) DECLARE_UNARY_PARENT - - private: // Y -> input.x // Cb(U) -> input.y // Cr(V) -> input.z - FK_HOST_DEVICE_FUSE float3 computeRGB(const InputType pixel) { + public: + FK_HOST_DEVICE_FUSE OutputType exec(const InputType input) { constexpr M3x3Float coefficients = ccMatrix; constexpr float CSub = subCoefficients.chroma; if constexpr (CR == ColorRange::Limited) { constexpr float YSub = subCoefficients.luma; - return MxVFloat3::exec({ make_(pixel.x - YSub, pixel.y - CSub, pixel.z - CSub), coefficients }); - } else { - return MxVFloat3::exec({ make_(pixel.x, pixel.y - CSub, pixel.z - CSub), coefficients }); - } - } - - public: - FK_HOST_DEVICE_FUSE OutputType exec(const InputType input) { - const float3 pixelRGBFloat = computeRGB(input); - if constexpr (ALPHA) { - return float4{pixelRGBFloat.x, pixelRGBFloat.y, pixelRGBFloat.z, input.w}; + return MxVFloat3::exec( + {make_(input.x - YSub, input.y - CSub, input.z - CSub), coefficients}); } else { - return pixelRGBFloat; + return MxVFloat3::exec( + {make_(input.x, input.y - CSub, input.z - CSub), coefficients}); } } }; @@ -195,7 +186,7 @@ namespace fk { using PixelBaseType = ColorDepthPixelBaseType::depth>; using Parent = ReadOperation, - ColorDepthPixelType<(ColorDepth)PixelFormatTraits::depth, false>, + ColorDepthPixelType<(ColorDepth)PixelFormatTraits::depth>, TF::DISABLED, ReadYUV>; DECLARE_READ_PARENT @@ -283,7 +274,7 @@ namespace fk { public: FK_STATIC_STRUCT(WriteYUV, SelfType) using PixelBaseType = ColorDepthPixelBaseType::depth>; - using Parent = WriteOperation::depth, false>, + using Parent = WriteOperation::depth>, RawImage, PixelBaseType, TF::DISABLED, diff --git a/include/fused_kernel/algorithms/image_processing/image.h b/include/fused_kernel/algorithms/image_processing/image.h index e9e352d2..0f3fe0df 100644 --- a/include/fused_kernel/algorithms/image_processing/image.h +++ b/include/fused_kernel/algorithms/image_processing/image.h @@ -17,6 +17,7 @@ #define FK_IMAGE_H #include +#include #include namespace fk { @@ -39,7 +40,7 @@ namespace fk { : data(data), width(width), height(height) {} FK_HOST_CNST Image(const uint width, const uint height, - const MemType& memType = defaultMemType, const uint deviceID = 0) + const MemType memType = defaultMemType, const uint deviceID = 0) : width(width), height(height) { const uint dataWidth = width * PixelFormatTraits::rf.width_f; const uint dataHeight = height * PixelFormatTraits::rf.height_f; diff --git a/include/fused_kernel/algorithms/image_processing/itu_color.h b/include/fused_kernel/algorithms/image_processing/itu_color.h index 810be0f1..34daf433 100644 --- a/include/fused_kernel/algorithms/image_processing/itu_color.h +++ b/include/fused_kernel/algorithms/image_processing/itu_color.h @@ -38,13 +38,10 @@ namespace fk { CD_t, CD_t, CD_t>; using ColorDepthPixelBaseTypes = TypeList; using ColorDepthPixelTypes = TypeList; - using ColorDepthPixelTypesAlpha = TypeList; template using ColorDepthPixelBaseType = EquivalentType_t, ColorDepthTypes, ColorDepthPixelBaseTypes>; - template - using ColorDepthPixelType = std::conditional_t, ColorDepthTypes, ColorDepthPixelTypesAlpha>, - EquivalentType_t, ColorDepthTypes, ColorDepthPixelTypes>>; + template + using ColorDepthPixelType = EquivalentType_t, ColorDepthTypes, ColorDepthPixelTypes>; // Taking into account the color depth, the pixel base type is uchar, ushort or float // ResolutionFactors therefore are used to compute the number of pixel base type elements on width and height diff --git a/include/fused_kernel/core/constexpr_libs/constexpr_vector_exec.h b/include/fused_kernel/core/constexpr_libs/constexpr_vector_exec.h index 2baf7bc3..09721aaa 100644 --- a/include/fused_kernel/core/constexpr_libs/constexpr_vector_exec.h +++ b/include/fused_kernel/core/constexpr_libs/constexpr_vector_exec.h @@ -55,6 +55,14 @@ namespace cxp { FK_HOST_DEVICE_FUSE auto exec(const ST1& s1, const ST2& s2, const STs&... scals) { return exec(Op::exec(s1, s2), scals...); } + // Single scalar operand: a binary reduction over a single value is that value. + // This allows variadic folds (cxp::sum::f, cxp::max::f, cxp::min::f, ...) to be + // instantiated with parameter packs of size 1. + template + FK_HOST_DEVICE_FUSE auto exec(const ST& s) + -> std::enable_if_t, ST> { + return s; + } template FK_HOST_DEVICE_FUSE auto exec(const VT& v) -> decltype(Op::exec(std::declval>(), std::declval>())) { diff --git a/tests/buildAPI/batch_build_compilation_time.h b/tests/buildAPI/batch_build_compilation_time.h index 0eea5b0f..afd0e32c 100644 --- a/tests/buildAPI/batch_build_compilation_time.h +++ b/tests/buildAPI/batch_build_compilation_time.h @@ -63,7 +63,7 @@ void testCompareReferenceVSValueVSInstantiableDPP() { // Create the operation instances once, and use them multiple times const auto readIOp = ReadYUV::build(inputImage); - const auto yuvToRGB = ConvertYUVToRGB::build(); + const auto yuvToRGB = ConvertYUVToRGB::build(); const auto borderReader = BorderReader::build(); const auto cropIOp = Crop<>::build(crops); const auto resizeIOp = diff --git a/tests/operation/test_fused_operation.h b/tests/operation/test_fused_operation.h index 6b540066..5203dc34 100644 --- a/tests/operation/test_fused_operation.h +++ b/tests/operation/test_fused_operation.h @@ -41,7 +41,7 @@ constexpr bool test_fuseDFResultingTypes() { static_assert(std::is_same_v, Read>>, "Unexpected type after fuseIOps"); constexpr auto readYUV = ReadYUV::build({ {RawPtr{nullptr, PtrDims(128, 128 + 64)}, 128, 128} }); - constexpr auto readRGB = readYUV.then(ConvertYUVToRGB::build()); + constexpr auto readRGB = readYUV.then(ConvertYUVToRGB::build()); constexpr auto resizeRead = Resize::build(readRGB, Size(64, 64)); constexpr auto resizeReadWithMul = resizeRead.then(Mul::build(3.f));