Debian Codegraph @

cvd_src/NEON/convert_rgb_to_y.cc

raw symbols SCIP
1 #include <arm_neon.h>
2 #include <cvd/convert_image.h>
3
4 namespace CVD
5 {
6
7 namespace Internal
8 {
9 void convert_rgb_to_grey_NEON(const BasicImage<Rgb<byte>>& from, BasicImage<byte>& to, const unsigned r, const unsigned g, const unsigned b)
10 {
11 const uint8x8_t red = vdup_n_u8(r);
12 const uint8x8_t green = vdup_n_u8(g);
13 const uint8x8_t blue = vdup_n_u8(b);
14
15 for(int y = 0; y < from.size().y; ++y)
16 {
17 const Rgb<byte>* in = from[y];
18 byte* out = to[y];
19 for(int x = 0; x < from.size().x; x += 8, in += 8, out += 8)
20 {
21 uint8x8x3_t in_data = vld3_u8((const uint8_t*)in);
22
23 uint16x8_t sum = vmull_u8(in_data.val[0], red);
24 sum = vmlal_u8(sum, in_data.val[1], green);
25 sum = vmlal_u8(sum, in_data.val[2], blue);
26
27 uint8x8_t final_sum = vshrn_n_u16(sum, 8); // divide by 256
28 vst1_u8(out, final_sum);
29 }
30 }
31 }
32 }
33
34 void ConvertImage<Rgb<byte>, byte, Pixel::CIE<Rgb<byte>, byte>, 1>::convert(const BasicImage<Rgb<byte>>& from, BasicImage<byte>& to)
35 {
36
37 if((from.size().x % 8) == 0)
38 {
39 // red (77) + green (150) + blue (29) = 256
40 Internal::convert_rgb_to_grey_NEON(from, to, 77, 150, 29);
41 }
42 else
43 {
44 const int multiple_of_8_width = (from.size().x / 8) * 8;
45 const ImageRef end_fast(multiple_of_8_width, from.size().y);
46
47 // red (77) + green (150) + blue (29) = 256
48 Internal::convert_rgb_to_grey_NEON(from.sub_image(ImageRef_zero, end_fast), to.sub_image(ImageRef_zero, end_fast).ref(), 77, 150, 29);
49
50 for(int y = 0; y < from.size().y; ++y)
51 {
52 const Rgb<byte>* in = from[y] + multiple_of_8_width;
53 byte* out = to[y] + multiple_of_8_width;
54 for(int x = multiple_of_8_width; x < from.size().x; ++x, ++in, ++out)
55 {
56 Pixel::CIE<Rgb<byte>, byte>::convert(*in, *out);
57 }
58 }
59 }
60 }
61 }