24 #ifndef ARM_COMPUTE_TEST_VALIDATION_COLOR_CONVERT_H
25 #define ARM_COMPUTE_TEST_VALIDATION_COLOR_CONVERT_H
33 namespace colorconvert_helper
58 int width =
src.shape().x();
59 int height =
src.shape().y();
61 for(
int y = 0; y < height; ++y)
63 for(
int x = 0; x < width; ++x)
68 const auto *src_pixel =
reinterpret_cast<const T *
>(
src(src_coord));
69 auto *rvec_pixel =
reinterpret_cast<T *
>(rvec(vec_coord));
70 auto *gvec_pixel =
reinterpret_cast<T *
>(gvec(vec_coord));
71 auto *bvec_pixel =
reinterpret_cast<T *
>(bvec(vec_coord));
73 rvec_pixel[0] = src_pixel[0];
74 gvec_pixel[0] = src_pixel[1];
75 bvec_pixel[0] = src_pixel[2];
84 int width = rvec.
shape().x();
85 int height = rvec.
shape().y();
89 Coordinates uvec_coord{ uvec_coord_x, uvec_coord_y };
91 for(
int y = 0; y < height; ++y)
93 for(
int x = 0; x < width; x += 2)
96 auto *yvec_pixel =
reinterpret_cast<T *
>(yvec(coord));
97 auto *uvec_top_pixel =
reinterpret_cast<T *
>(uvec_top(uvec_coord));
98 auto *uvec_bottom_pixel =
reinterpret_cast<T *
>(uvec_bottom(uvec_coord));
99 auto *vvec_top_pixel =
reinterpret_cast<T *
>(vvec_top(uvec_coord));
100 auto *vvec_bottom_pixel =
reinterpret_cast<T *
>(vvec_bottom(uvec_coord));
108 yvec_pixel[0] = result;
118 yvec_pixel[1] = result;
122 uvec_coord.set(0, ++uvec_coord_x);
134 result = y_value + red;
140 result = y_value + green;
146 result = y_value + blue;
155 return std::min(std::max(0.f, result), 255.f);
158 template <
typename T>
161 const int dst_width =
dst.shape().x();
162 const int dst_height =
dst.shape().y();
163 for(
int y = 0; y < dst_height; ++y)
166 for(
int x = 0; x < dst_width; x += 2, ++x_coord)
169 auto *dst_pixel =
reinterpret_cast<T *
>(
dst(dst_coord));
170 const T border_value(0);
186 dst_pixel =
reinterpret_cast<T *
>(
dst(dst_coord2));
196 template <
typename T>
201 const int width =
dst.shape().x();
202 const int height =
dst.shape().y();
204 for(
int y = 0; y < height; ++y)
206 for(
int x = 0; x < width; ++x)
211 const auto *src_pixel =
reinterpret_cast<const T *
>(
src(src_coord));
212 auto *dst_pixel =
reinterpret_cast<T *
>(
dst(dst_coord));
225 template <
typename T>
228 const int width =
dst.shape().x();
229 const int height =
dst.shape().y();
231 for(
int y = 0; y < height; ++y)
233 for(
int x = 0; x < width; ++x)
238 const auto *src_pixel =
reinterpret_cast<const T *
>(
src(src_coord));
239 auto *dst_pixel =
reinterpret_cast<T *
>(
dst(dst_coord));
243 dst_pixel[0] = utility::clamp<float>(result, 0, 255);
248 template <
typename T>
253 const int width =
dst.shape().x();
254 const int height =
dst.shape().y();
256 for(
int y = 0; y < height; ++y)
258 for(
int x = 0; x < width; ++x)
263 const auto *src_pixel =
reinterpret_cast<const T *
>(
src(src_coord));
264 auto *dst_pixel =
reinterpret_cast<T *
>(
dst(dst_coord));
272 template <
typename T>
284 const int width = yvec.shape().
x();
285 const int height = yvec.shape().y();
287 for(
int y = 0; y < height; ++y)
289 for(
int x = 0; x < width; ++x)
292 const auto *src_pixel =
reinterpret_cast<const T *
>(
src(src_coord));
293 auto *yvec_pixel =
reinterpret_cast<T *
>(yvec(elem_coord));
294 auto *uvec_pixel =
reinterpret_cast<T *
>(uvec(elem_coord));
295 auto *yyvec_pixel =
reinterpret_cast<T *
>(yyvec(elem_coord));
296 auto *vvec_pixel =
reinterpret_cast<T *
>(vvec(elem_coord));
297 yvec_pixel[x] = src_pixel[0 +
offset];
298 uvec_pixel[x] = src_pixel[1 -
offset];
299 yyvec_pixel[x] = src_pixel[2 +
offset];
300 vvec_pixel[x] = src_pixel[3 -
offset];
302 elem_coord.set(1, y + 1);
308 template <
typename T>
317 const int yvec_width = yvec.shape().
x();
318 const int yvec_height = yvec.shape().y();
320 for(
int y = 0; y < yvec_height; ++y)
322 for(
int x = 0; x < yvec_width; ++x)
325 const auto *src_pixel =
reinterpret_cast<const T *
>(tensor_planes[0](src_coord));
326 auto *yvec_pixel =
reinterpret_cast<T *
>(yvec(elem_coord));
327 auto *yyvec_pixel =
reinterpret_cast<T *
>(yyvec(elem_coord));
328 yvec_pixel[x] = src_pixel[x];
329 yyvec_pixel[x] = src_pixel[x + 1];
331 elem_coord.
set(1, y + 1);
334 const int uvec_width = uvec.shape().x();
335 const int uvec_height = uvec.shape().y();
339 for(
int y = 0; y < uvec_height; y += 2)
341 for(
int x = 0; x < uvec_width; ++x)
344 const auto *u_pixel =
reinterpret_cast<const T *
>(tensor_planes[1](src_coord));
345 const auto *v_pixel =
reinterpret_cast<const T *
>(tensor_planes[2](src_coord));
346 auto *uvec_pixel_top =
reinterpret_cast<T *
>(uvec(top_elem_coord));
347 auto *vvec_pixel_top =
reinterpret_cast<T *
>(vvec(top_elem_coord));
349 auto *uvec_pixel_bottom =
reinterpret_cast<T *
>(uvec(bottom_elem_coord));
350 auto *vvec_pixel_bottom =
reinterpret_cast<T *
>(vvec(bottom_elem_coord));
351 uvec_pixel_top[x] = u_pixel[0];
352 vvec_pixel_top[x] = v_pixel[0];
353 uvec_pixel_bottom[x] = u_pixel[0];
354 vvec_pixel_bottom[x] = v_pixel[0];
356 top_elem_coord.
set(1, y + 2);
357 bottom_elem_coord.set(1, top_elem_coord.y() + 1);
363 template <
typename T>
374 const int yvec_width = yvec.shape().
x();
375 const int yvec_height = yvec.shape().y();
377 for(
int y = 0; y < yvec_height; ++y)
379 for(
int x = 0; x < yvec_width; ++x)
382 const auto *src_pixel =
reinterpret_cast<const T *
>(tensor_planes[0](src_coord));
383 auto *yvec_pixel =
reinterpret_cast<T *
>(yvec(elem_coord));
384 auto *yyvec_pixel =
reinterpret_cast<T *
>(yyvec(elem_coord));
385 yvec_pixel[x] = src_pixel[x];
386 yyvec_pixel[x] = src_pixel[x + 1];
388 elem_coord.
set(1, y + 1);
391 const int uvec_width = uvec.shape().x();
392 const int uvec_height = uvec.shape().y();
396 for(
int y = 0; y < uvec_height; y += 2)
398 for(
int x = 0; x < uvec_width; ++x)
401 const auto *src_pixel =
reinterpret_cast<const T *
>(tensor_planes[1](src_coord));
402 auto *uvec_pixel_top =
reinterpret_cast<T *
>(uvec(top_elem_coord));
403 auto *vvec_pixel_top =
reinterpret_cast<T *
>(vvec(top_elem_coord));
405 auto *uvec_pixel_bottom =
reinterpret_cast<T *
>(uvec(bottom_elem_coord));
406 auto *vvec_pixel_bottom =
reinterpret_cast<T *
>(vvec(bottom_elem_coord));
407 uvec_pixel_top[x] = src_pixel[0 +
offset];
408 vvec_pixel_top[x] = src_pixel[1 -
offset];
409 uvec_pixel_bottom[x] = src_pixel[0 +
offset];
410 vvec_pixel_bottom[x] = src_pixel[1 -
offset];
412 top_elem_coord.
set(1, y + 2);
413 bottom_elem_coord.set(1, top_elem_coord.y() + 1);
419 template <
typename T>
427 int vec_shape_x =
src.shape().x() *
src.shape().y();
440 uint32_t utmp_width = utmp.
shape().
x();
441 uint32_t utmp_height = utmp.shape().y();
443 uint32_t uvec_coord_x = 0;
444 uint32_t uvec_coord_y = 0;
445 Coordinates uvec_coord{ uvec_coord_x, uvec_coord_y };
446 for(uint32_t y = 0; y < utmp_height; y++)
448 for(uint32_t x = 0; x < utmp_width; x++)
451 auto *utmp_pixel =
reinterpret_cast<T *
>(utmp(coord));
452 auto *vtmp_pixel =
reinterpret_cast<T *
>(vtmp(coord));
460 utmp_pixel[0] = std::ceil(
float(uvec_top_val + uvec_bottom_val) / 2);
461 vtmp_pixel[0] = std::ceil(
float(vvec_top_val + vvec_bottom_val) / 2);
463 uvec_coord.set(0, ++uvec_coord_x);
467 uint32_t second_plane_x =
dst[1].shape().x();
468 uint32_t second_plane_y =
dst[1].shape().y();
470 uint32_t utmp_coord_x = 0;
471 uint32_t utmp_coord_y = 0;
473 for(uint32_t y = 0; y < second_plane_y; y++)
475 for(uint32_t x = 0; x < second_plane_x; x++)
478 Coordinates utmp_top_coord{ utmp_coord_x, utmp_coord_y };
479 Coordinates utmp_bottom_coord{ utmp_coord_x, utmp_coord_y + 1 };
481 auto *dst_pixel =
reinterpret_cast<T *
>(
dst[1](coord));
487 int result = (utmp_top_val + utmp_bottom_val) / 2;
488 dst_pixel[0] = result;
493 result = (vtmp_top_val + vtmp_bottom_val) / 2;
494 dst_pixel[1] = result;
498 if(utmp_coord_x >= utmp_width)
507 template <
typename T>
515 int vec_shape_x =
src.shape().x() *
src.shape().y();
527 uint32_t utmp_width = utmp.
shape().
x();
528 uint32_t utmp_height = utmp.shape().y();
530 uint32_t uvec_coord_x = 0;
531 uint32_t uvec_coord_y = 0;
532 Coordinates uvec_coord{ uvec_coord_x, uvec_coord_y };
533 for(uint32_t y = 0; y < utmp_height; y++)
535 for(uint32_t x = 0; x < utmp_width; x++)
538 auto *utmp_pixel =
reinterpret_cast<T *
>(utmp(coord));
539 auto *vtmp_pixel =
reinterpret_cast<T *
>(vtmp(coord));
547 utmp_pixel[0] = std::ceil(
float(uvec_top_val + uvec_bottom_val) / 2);
548 vtmp_pixel[0] = std::ceil(
float(vvec_top_val + vvec_bottom_val) / 2);
550 uvec_coord.set(0, ++uvec_coord_x);
554 uint32_t second_plane_x =
dst[1].shape().x();
555 uint32_t second_plane_y =
dst[1].shape().y();
557 uint32_t utmp_coord_x = 0;
558 uint32_t utmp_coord_y = 0;
560 for(uint32_t y = 0; y < second_plane_y; y++)
562 for(uint32_t x = 0; x < second_plane_x; x++)
565 Coordinates utmp_top_coord{ utmp_coord_x, utmp_coord_y };
566 Coordinates utmp_bottom_coord{ utmp_coord_x, utmp_coord_y + 1 };
568 auto *u_pixel =
reinterpret_cast<T *
>(
dst[1](coord));
569 auto *v_pixel =
reinterpret_cast<T *
>(
dst[2](coord));
575 int result = (utmp_top_val + utmp_bottom_val) / 2;
581 result = (vtmp_top_val + vtmp_bottom_val) / 2;
586 if(utmp_coord_x >= utmp_width)
595 template <
typename T>
603 int vec_shape_x =
src.shape().x() *
src.shape().y();
610 int width =
src.shape().x();
611 int height =
src.shape().y();
618 for(
int y = 0; y < height; y++)
620 for(
int x = 0; x < width; x += 2)
623 auto *plane_1_pixel =
reinterpret_cast<T *
>(
dst[1](coord));
624 auto *plane_2_pixel =
reinterpret_cast<T *
>(
dst[2](coord));
630 plane_1_pixel[0] = uvec_top_val;
631 plane_1_pixel[1] = uvec_bottom_val;
636 plane_2_pixel[0] = vvec_top_val;
637 plane_2_pixel[1] = vvec_bottom_val;
639 uvec_coord.increment(0);
644 template <
typename T>
652 int width =
dst[0].shape().x();
653 int height =
dst[0].shape().y();
655 for(
int y = 0; y < height; ++y)
657 for(
int x = 0; x < width; x++)
662 const auto *src_pixel =
reinterpret_cast<const T *
>(
src(dst_coord));
663 auto *y_pixel =
reinterpret_cast<T *
>(
dst[0](dst_coord));
664 auto *uvvec_top_pixel =
reinterpret_cast<T *
>(uvvec_top(uv_coord));
665 auto *uvvec_bottom_pixel =
reinterpret_cast<T *
>(uvvec_bottom(uv_coord));
667 y_pixel[0] = src_pixel[0 +
offset];
671 uvvec_top_pixel[0] = src_pixel[1 -
offset];
675 uvvec_bottom_pixel[0] = src_pixel[1 -
offset];
680 width =
dst[1].shape().x();
681 height =
dst[1].shape().y();
686 for(
int y = 0; y < height; ++y)
688 for(
int x = 0; x < width; x++)
691 const Coordinates uv_coord{ uv_coord_x, uv_coord_y };
693 auto *uv_pixel =
reinterpret_cast<T *
>(
dst[1](dst_coord));
694 const auto *uvvec_top_pixel =
reinterpret_cast<T *
>(uvvec_top(uv_coord));
695 const auto *uvvec_bottom_pixel =
reinterpret_cast<T *
>(uvvec_bottom(uv_coord));
697 uv_pixel[0] = (uvvec_top_pixel[0] + uvvec_bottom_pixel[0]) / 2;
698 uv_pixel[1] = (uvvec_top_pixel[1] + uvvec_bottom_pixel[1]) / 2;
706 template <
typename T>
714 int width =
dst[0].shape().x();
715 int height =
dst[0].shape().y();
717 for(
int y = 0; y < height; ++y)
719 for(
int x = 0; x < width; x++)
724 const auto *src_pixel =
reinterpret_cast<const T *
>(
src(dst_coord));
725 auto *y_pixel =
reinterpret_cast<T *
>(
dst[0](dst_coord));
726 auto *uvvec_top_pixel =
reinterpret_cast<T *
>(uvvec_top(uv_coord));
727 auto *uvvec_bottom_pixel =
reinterpret_cast<T *
>(uvvec_bottom(uv_coord));
729 y_pixel[0] = src_pixel[0 +
offset];
733 uvvec_top_pixel[0] = src_pixel[1 -
offset];
737 uvvec_bottom_pixel[0] = src_pixel[1 -
offset];
742 width =
dst[1].shape().x();
743 height =
dst[1].shape().y();
748 for(
int y = 0; y < height; ++y)
750 for(
int x = 0; x < width; x++)
753 const Coordinates uv_coord{ uv_coord_x, uv_coord_y };
755 auto *u_pixel =
reinterpret_cast<T *
>(
dst[1](dst_coord));
756 auto *v_pixel =
reinterpret_cast<T *
>(
dst[2](dst_coord));
757 const auto *uvvec_top_pixel =
reinterpret_cast<T *
>(uvvec_top(uv_coord));
758 const auto *uvvec_bottom_pixel =
reinterpret_cast<T *
>(uvvec_bottom(uv_coord));
760 u_pixel[0] = (uvvec_top_pixel[0] + uvvec_bottom_pixel[0]) / 2;
761 v_pixel[0] = (uvvec_top_pixel[1] + uvvec_bottom_pixel[1]) / 2;
769 template <
typename T>
772 int width =
src.shape().x();
773 int height =
src.shape().y();
777 for(
int y = 0; y < height; ++y)
779 for(
int x = 0; x < width; x++)
782 const auto *src_pixel =
reinterpret_cast<const T *
>(
src(src_coord));
783 auto *u_pixel =
reinterpret_cast<T *
>(nv1(src_coord));
784 auto *v_pixel =
reinterpret_cast<T *
>(nv2(src_coord));
786 u_pixel[0] = src_pixel[1 -
offset];
787 v_pixel[0] = src_pixel[0 +
offset];
792 template <
typename T>
795 int width =
src.shape().x();
796 int height =
src.shape().y();
800 for(
int y = 0; y < height; ++y)
802 for(
int x = 0; x < width; x++)
806 const auto *src_pixel =
reinterpret_cast<const T *
>(
src(src_coord));
807 auto *u_pixel =
reinterpret_cast<T *
>(nv1(dst_coord));
808 auto *v_pixel =
reinterpret_cast<T *
>(nv2(dst_coord));
810 u_pixel[0] = src_pixel[1 -
offset];
811 u_pixel[1] = src_pixel[1 -
offset];
813 v_pixel[0] = src_pixel[0 +
offset];
814 v_pixel[1] = src_pixel[0 +
offset];
816 dst_coord.
set(1, y * 2 + 1);
817 u_pixel =
reinterpret_cast<T *
>(nv1(dst_coord));
818 v_pixel =
reinterpret_cast<T *
>(nv2(dst_coord));
819 u_pixel[0] = src_pixel[1 -
offset];
820 u_pixel[1] = src_pixel[1 -
offset];
822 v_pixel[0] = src_pixel[0 +
offset];
823 v_pixel[1] = src_pixel[0 +
offset];
828 template <
typename T>
831 int width =
dst[0].shape().x();
832 int height =
dst[0].shape().y();
834 for(
int y = 0; y < height; ++y)
836 for(
int x = 0; x < width; ++x)
840 const auto *src_pixel =
reinterpret_cast<const T *
>(
src[0](dst_coord));
841 auto *y_pixel =
reinterpret_cast<T *
>(
dst[0](dst_coord));
843 y_pixel[0] = src_pixel[0];
850 template <
typename T>
853 int width =
dst[0].shape().x();
854 int height =
dst[0].shape().y();
856 for(
int y = 0; y < height; ++y)
858 for(
int x = 0; x < width; ++x)
862 const auto *src_pixel =
reinterpret_cast<const T *
>(
src[0](dst_coord));
863 auto *y_pixel =
reinterpret_cast<T *
>(
dst[0](dst_coord));
865 y_pixel[0] = src_pixel[0];