From 4284bfab4594d4babb23123001ef63db7bebeccb Mon Sep 17 00:00:00 2001 From: Manuel Bottini Date: Wed, 26 Sep 2018 15:33:15 +0100 Subject: COMPMID-287: NEON colour convert to U8 Change-Id: I47033fa70881fd32b13266adb6ccbf10c202aabc Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/150344 Tested-by: bsgcomp Reviewed-by: Pablo Tello --- tests/validation/reference/ColorConvertHelper.h | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests/validation/reference/ColorConvertHelper.h') 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 inline void store_rgb_from_src(const SimpleTensor src, SimpleTensor &rvec, SimpleTensor &gvec, SimpleTensor &bvec) { @@ -218,6 +222,29 @@ inline void colorconvert_rgb_to_rgbx(const SimpleTensor src, SimpleTensor } } +template +inline void colorconvert_rgb_to_u8(const SimpleTensor src, SimpleTensor &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(src(src_coord)); + auto *dst_pixel = reinterpret_cast(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(result, 0, 255); + } + } +} + template inline void colorconvert_rgbx_to_rgb(const SimpleTensor src, SimpleTensor &dst) { -- cgit v1.2.1