diff options
Diffstat (limited to 'tests/validation/reference')
-rw-r--r-- | tests/validation/reference/ColorConvert.cpp | 4 | ||||
-rw-r--r-- | tests/validation/reference/ColorConvertHelper.h | 27 |
2 files changed, 31 insertions, 0 deletions
diff --git a/tests/validation/reference/ColorConvert.cpp b/tests/validation/reference/ColorConvert.cpp index 8047b34688..9090319a86 100644 --- a/tests/validation/reference/ColorConvert.cpp +++ b/tests/validation/reference/ColorConvert.cpp @@ -46,6 +46,7 @@ inline std::vector<SimpleTensor<T>> create_image_planes(const TensorShape &shape switch(format) { + case Format::U8: case Format::RGB888: case Format::RGBA8888: case Format::YUYV422: @@ -102,6 +103,9 @@ std::vector<SimpleTensor<T>> color_convert(const TensorShape &shape, const std:: case Format::RGBA8888: colorconvert_helper::detail::colorconvert_rgb_to_rgbx(tensor_planes[0], dst[0]); break; + case Format::U8: + colorconvert_helper::detail::colorconvert_rgb_to_u8(tensor_planes[0], dst[0]); + break; case Format::NV12: colorconvert_helper::detail::colorconvert_rgb_to_nv12(tensor_planes[0], dst); break; diff --git a/tests/validation/reference/ColorConvertHelper.h b/tests/validation/reference/ColorConvertHelper.h index 7a8b547486..b2ae6f2f80 100644 --- a/tests/validation/reference/ColorConvertHelper.h +++ b/tests/validation/reference/ColorConvertHelper.h @@ -48,6 +48,10 @@ constexpr float rgb2yuv_bt709_cu = 0.5389f; // C_v = 1 / (2 * (1 - K_r)) constexpr float rgb2yuv_bt709_cv = 0.6350f; +constexpr float rgb2u8_red_coef = 0.2126f; +constexpr float rgb2u8_green_coef = 0.7152f; +constexpr float rgb2u8_blue_coef = 0.0722f; + template <typename T> inline void store_rgb_from_src(const SimpleTensor<T> src, SimpleTensor<T> &rvec, SimpleTensor<T> &gvec, SimpleTensor<T> &bvec) { @@ -219,6 +223,29 @@ inline void colorconvert_rgb_to_rgbx(const SimpleTensor<T> src, SimpleTensor<T> } template <typename T> +inline void colorconvert_rgb_to_u8(const SimpleTensor<T> src, SimpleTensor<T> &dst) +{ + const int width = dst.shape().x(); + const int height = dst.shape().y(); + + for(int y = 0; y < height; ++y) + { + for(int x = 0; x < width; ++x) + { + const Coordinates src_coord{ x, y }; + const Coordinates dst_coord{ x, y }; + + const auto *src_pixel = reinterpret_cast<const T *>(src(src_coord)); + auto *dst_pixel = reinterpret_cast<T *>(dst(dst_coord)); + + const float result = rgb2u8_red_coef * src_pixel[0] + rgb2u8_green_coef * src_pixel[1] + rgb2u8_blue_coef * src_pixel[2]; + + dst_pixel[0] = utility::clamp<float>(result, 0, 255); + } + } +} + +template <typename T> inline void colorconvert_rgbx_to_rgb(const SimpleTensor<T> src, SimpleTensor<T> &dst) { for(int channel_idx = 0; channel_idx < dst.num_channels(); ++channel_idx) |