From fda461824f18f0c7429abc899caea39937af88bc Mon Sep 17 00:00:00 2001 From: Giorgio Arena Date: Fri, 16 Jun 2017 13:57:33 +0100 Subject: COMPMID-378 IntegralImage testing completed. Change-Id: I848713c8aa4382b01111af714a207f92eefcdb44 Reviewed-on: http://mpd-gerrit.cambridge.arm.com/77878 Tested-by: Kaizen Reviewed-by: Steven Niu --- tests/TensorLibrary.cpp | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-) (limited to 'tests/TensorLibrary.cpp') diff --git a/tests/TensorLibrary.cpp b/tests/TensorLibrary.cpp index 0c85136a38..21bb4ecd73 100644 --- a/tests/TensorLibrary.cpp +++ b/tests/TensorLibrary.cpp @@ -46,33 +46,14 @@ namespace test { namespace { -void convert_rgb_to_u8(const RawTensor &src, RawTensor &dst) +template ::value, int>::type = 0> +void rgb_to_luminance(const RawTensor &src, RawTensor &dst) { const size_t min_size = std::min(src.size(), dst.size()); for(size_t i = 0, j = 0; i < min_size; i += 3, ++j) { - dst.data()[j] = 0.2126f * src.data()[i + 0] + 0.7152f * src.data()[i + 1] + 0.0722f * src.data()[i + 2]; - } -} - -void convert_rgb_to_u16(const RawTensor &src, RawTensor &dst) -{ - const size_t min_size = std::min(src.size(), dst.size()); - - for(size_t i = 0, j = 0; i < min_size; i += 3, ++j) - { - reinterpret_cast(dst.data())[j] = 0.2126f * src.data()[i + 0] + 0.7152f * src.data()[i + 1] + 0.0722f * src.data()[i + 2]; - } -} - -void convert_rgb_to_s16(const RawTensor &src, RawTensor &dst) -{ - const size_t min_size = std::min(src.size(), dst.size()); - - for(size_t i = 0, j = 0; i < min_size; i += 3, ++j) - { - reinterpret_cast(dst.data())[j] = 0.2126f * src.data()[i + 0] + 0.7152f * src.data()[i + 1] + 0.0722f * src.data()[i + 2]; + reinterpret_cast(dst.data())[j] = 0.2126f * src.data()[i + 0] + 0.7152f * src.data()[i + 1] + 0.0722f * src.data()[i + 2]; } } @@ -261,9 +242,10 @@ const TensorLibrary::Converter &TensorLibrary::get_converter(Format src, Format { static std::map, Converter> converters = { - { std::make_pair(Format::RGB888, Format::U8), convert_rgb_to_u8 }, - { std::make_pair(Format::RGB888, Format::U16), convert_rgb_to_u16 }, - { std::make_pair(Format::RGB888, Format::S16), convert_rgb_to_s16 } + { std::make_pair(Format::RGB888, Format::U8), rgb_to_luminance }, + { std::make_pair(Format::RGB888, Format::U16), rgb_to_luminance }, + { std::make_pair(Format::RGB888, Format::S16), rgb_to_luminance }, + { std::make_pair(Format::RGB888, Format::U32), rgb_to_luminance } }; const auto it = converters.find(std::make_pair(src, dst)); @@ -413,6 +395,11 @@ const RawTensor &TensorLibrary::find_or_create_raw_tensor(const std::string &nam return _cache.add(std::make_tuple(name, format, channel), std::move(dst)); } +TensorShape TensorLibrary::get_image_shape(const std::string &name) +{ + return load_image(name).shape(); +} + RawTensor TensorLibrary::get(const TensorShape &shape, DataType data_type, int num_channels, int fixed_point_position) { return RawTensor(shape, data_type, num_channels, fixed_point_position); -- cgit v1.2.1