The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

a/util: Add half scale frame sink

Useful for when you're dealing with a camera that's too high res you're trying to calibrate

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2457>

authored by

Beyley Cardellio and committed by
Marge Bot
4b38d313 aadd2eb8

+54
+5
src/xrt/auxiliary/util/u_sink.h
··· 84 84 struct xrt_frame_sink *downstream, 85 85 struct xrt_frame_sink **out_xfs); 86 86 87 + void 88 + u_sink_create_half_scale(struct xrt_frame_context *xfctx, 89 + struct xrt_frame_sink *downstream, 90 + struct xrt_frame_sink **out_xfs); 91 + 87 92 /*! 88 93 * @public @memberof xrt_frame_sink 89 94 * @see xrt_frame_context
+49
src/xrt/auxiliary/util/u_sink_converter.c
··· 1023 1023 1024 1024 *out_xfs = &s->base; 1025 1025 } 1026 + 1027 + static void 1028 + convert_half_scale(struct xrt_frame_sink *xs, struct xrt_frame *xf) 1029 + { 1030 + struct u_sink_converter *s = (struct u_sink_converter *)xs; 1031 + 1032 + uint32_t w = xf->width / 2; 1033 + uint32_t h = xf->height / 2; 1034 + struct xrt_frame *converted = NULL; 1035 + 1036 + if (!create_frame_with_format_of_size(xf, w, h, XRT_FORMAT_L8, &converted)) { 1037 + return; 1038 + } 1039 + 1040 + for (uint32_t x = 0; x < w; x++) { 1041 + for (uint32_t y = 0; y < h; y++) { 1042 + uint16_t sum = 0; 1043 + sum += xf->data[((y * 2) * xf->stride) + (x * 2)]; 1044 + sum += xf->data[((y * 2) * xf->stride) + (x * 2) + 1]; 1045 + sum += xf->data[(((y * 2) + 1) * xf->stride) + (x * 2)]; 1046 + sum += xf->data[(((y * 2) + 1) * xf->stride) + (x * 2) + 1]; 1047 + 1048 + converted->data[(y * converted->stride) + x] = sum / 4; 1049 + } 1050 + } 1051 + 1052 + s->downstream->push_frame(s->downstream, converted); 1053 + 1054 + // Refcount in case it's being held downstream. 1055 + xrt_frame_reference(&converted, NULL); 1056 + } 1057 + 1058 + void 1059 + u_sink_create_half_scale(struct xrt_frame_context *xfctx, 1060 + struct xrt_frame_sink *downstream, 1061 + struct xrt_frame_sink **out_xfs) 1062 + { 1063 + assert(downstream != NULL); 1064 + 1065 + struct u_sink_converter *s = U_TYPED_CALLOC(struct u_sink_converter); 1066 + s->base.push_frame = convert_half_scale; 1067 + s->node.break_apart = break_apart; 1068 + s->node.destroy = destroy; 1069 + s->downstream = downstream; 1070 + 1071 + xrt_frame_context_add(xfctx, &s->node); 1072 + 1073 + *out_xfs = &s->base; 1074 + }