Skip to content
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
33 changes: 12 additions & 21 deletions include/fused_kernel/algorithms/image_processing/color_conversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ namespace fk {
DECLARE_UNARY_PARENT
FK_HOST_DEVICE_FUSE OutputType exec(const InputType input) {
constexpr auto alpha = maxDepthValue<CD>;
return AddLast<InputType, OutputType>::exec(input, { alpha });
return AddLast<InputType, OutputType>::exec(input, { static_cast<VBase<I>>(alpha) });
}
};

Expand Down Expand Up @@ -147,37 +147,28 @@ namespace fk {
}
};

template <ColorDepth CD, ColorRange CR, ColorPrimitives CP, bool ALPHA>
template <ColorDepth CD, ColorRange CR, ColorPrimitives CP>
struct ConvertYUVToRGB {
private:
using SelfType = ConvertYUVToRGB<CD, CR, CP, ALPHA>;
using Parent = UnaryOperation<ColorDepthPixelType<CD, ALPHA>, ColorDepthPixelType<CD, ALPHA>, ConvertYUVToRGB<CD, CR, CP, ALPHA>>;
using SelfType = ConvertYUVToRGB<CD, CR, CP>;
using Parent = UnaryOperation<ColorDepthPixelType<CD>, float3, SelfType >;
Comment thread
morousg marked this conversation as resolved.
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<CR, CP, ColorConversionDir::YCbCr2RGB, CD>;
constexpr float CSub = subCoefficients<CD>.chroma;
if constexpr (CR == ColorRange::Limited) {
constexpr float YSub = subCoefficients<CD>.luma;
return MxVFloat3<UnaryType>::exec({ make_<float3>(pixel.x - YSub, pixel.y - CSub, pixel.z - CSub), coefficients });
} else {
return MxVFloat3<UnaryType>::exec({ make_<float3>(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<UnaryType>::exec(
{make_<float3>(input.x - YSub, input.y - CSub, input.z - CSub), coefficients});
} else {
return pixelRGBFloat;
return MxVFloat3<UnaryType>::exec(
{make_<float3>(input.x, input.y - CSub, input.z - CSub), coefficients});
}
}
};
Expand All @@ -195,7 +186,7 @@ namespace fk {
using PixelBaseType = ColorDepthPixelBaseType<PixelFormatTraits<PF>::depth>;
using Parent = ReadOperation<PixelBaseType,
RawImage<PF>,
ColorDepthPixelType<(ColorDepth)PixelFormatTraits<PF>::depth, false>,
ColorDepthPixelType<(ColorDepth)PixelFormatTraits<PF>::depth>,
TF::DISABLED,
ReadYUV<PF>>;
DECLARE_READ_PARENT
Expand Down Expand Up @@ -283,7 +274,7 @@ namespace fk {
public:
FK_STATIC_STRUCT(WriteYUV, SelfType)
using PixelBaseType = ColorDepthPixelBaseType<PixelFormatTraits<PF>::depth>;
using Parent = WriteOperation<ColorDepthPixelType<(ColorDepth)PixelFormatTraits<PF>::depth, false>,
using Parent = WriteOperation<ColorDepthPixelType<(ColorDepth)PixelFormatTraits<PF>::depth>,
RawImage<PF>,
PixelBaseType,
TF::DISABLED,
Expand Down
3 changes: 2 additions & 1 deletion include/fused_kernel/algorithms/image_processing/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define FK_IMAGE_H

#include <fused_kernel/algorithms/image_processing/raw_image.h>
#include <fused_kernel/algorithms/image_processing/color_conversion.h>
#include <fused_kernel/core/data/ptr_nd.h>

namespace fk {
Expand All @@ -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<PF>::rf.width_f;
const uint dataHeight = height * PixelFormatTraits<PF>::rf.height_f;
Expand Down
7 changes: 2 additions & 5 deletions include/fused_kernel/algorithms/image_processing/itu_color.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,10 @@ namespace fk {
CD_t<ColorDepth::fn8bit>, CD_t<ColorDepth::fn10bit>, CD_t<ColorDepth::fn12bit>>;
using ColorDepthPixelBaseTypes = TypeList<uchar, ushort, ushort, float, float, float>;
using ColorDepthPixelTypes = TypeList<uchar3, ushort3, ushort3, float3, float3, float3>;
using ColorDepthPixelTypesAlpha = TypeList<uchar4, ushort4, ushort4, float4, float4, float4>;
template <ColorDepth CD>
using ColorDepthPixelBaseType = EquivalentType_t<CD_t<CD>, ColorDepthTypes, ColorDepthPixelBaseTypes>;
template <ColorDepth CD, bool ALPHA>
using ColorDepthPixelType = std::conditional_t<ALPHA,
EquivalentType_t<CD_t<CD>, ColorDepthTypes, ColorDepthPixelTypesAlpha>,
EquivalentType_t<CD_t<CD>, ColorDepthTypes, ColorDepthPixelTypes>>;
template <ColorDepth CD>
using ColorDepthPixelType = EquivalentType_t<CD_t<CD>, ColorDepthTypes, ColorDepthPixelTypes>;
Comment thread
morousg marked this conversation as resolved.

// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename ST>
FK_HOST_DEVICE_FUSE auto exec(const ST& s)
-> std::enable_if_t<!fk::validCUDAVec<ST>, ST> {
return s;
}
template <fk::vector_type VT>
FK_HOST_DEVICE_FUSE auto exec(const VT& v)
-> decltype(Op::exec(std::declval<fk::VBase<VT>>(), std::declval<fk::VBase<VT>>())) {
Expand Down
2 changes: 1 addition & 1 deletion tests/buildAPI/batch_build_compilation_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void testCompareReferenceVSValueVSInstantiableDPP() {

// Create the operation instances once, and use them multiple times
const auto readIOp = ReadYUV<PixelFormat::NV12>::build(inputImage);
const auto yuvToRGB = ConvertYUVToRGB<ColorDepth::p8bit, ColorRange::Full, ColorPrimitives::bt2020, false>::build();
const auto yuvToRGB = ConvertYUVToRGB<ColorDepth::p8bit, ColorRange::Full, ColorPrimitives::bt2020>::build();
const auto borderReader = BorderReader<BorderType::REPLICATE>::build();
const auto cropIOp = Crop<>::build(crops);
const auto resizeIOp =
Expand Down
2 changes: 1 addition & 1 deletion tests/operation/test_fused_operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ constexpr bool test_fuseDFResultingTypes() {
static_assert(std::is_same_v<std::decay_t<decltype(readOp2)>, Read<PerThreadRead<ND::_2D, uchar3>>>, "Unexpected type after fuseIOps");

constexpr auto readYUV = ReadYUV<PixelFormat::NV12>::build({ {RawPtr<ND::_2D, uchar>{nullptr, PtrDims<ND::_2D>(128, 128 + 64)}, 128, 128} });
constexpr auto readRGB = readYUV.then(ConvertYUVToRGB<ColorDepth::p8bit, ColorRange::Full, ColorPrimitives::bt2020, false>::build());
constexpr auto readRGB = readYUV.then(ConvertYUVToRGB<ColorDepth::p8bit, ColorRange::Full, ColorPrimitives::bt2020>::build());

constexpr auto resizeRead = Resize<InterpolationType::INTER_LINEAR>::build(readRGB, Size(64, 64));
constexpr auto resizeReadWithMul = resizeRead.then(Mul<float>::build(3.f));
Expand Down
Loading