The open source OpenXR runtime
at prediction-2 86 lines 2.0 kB view raw
1// Copyright 2019, Collabora, Ltd. 2// SPDX-License-Identifier: BSL-1.0 3/*! 4 * @file 5 * @brief Code to build conversion tables and convert images. 6 * @author Jakob Bornecrantz <jakob@collabora.com> 7 * @ingroup aux_tracking 8 */ 9 10#include "tracking/t_tracking.h" 11 12#include <opencv2/opencv.hpp> 13 14 15/* 16 * 17 * 'Exported' functions. 18 * 19 */ 20 21extern "C" void 22t_convert_fill_table(struct t_convert_table *t) 23{ 24 for (int y = 0; y < 256; y++) { 25 for (int u = 0; u < 256; u++) { 26 uint8_t *dst = &t->v[y][u][0][0]; 27 28 for (int v = 0; v < 256; v++) { 29 dst[0] = y; 30 dst[1] = u; 31 dst[2] = v; 32 dst += 3; 33 } 34 } 35 } 36} 37 38extern "C" void 39t_convert_make_y8u8v8_to_r8g8b8(struct t_convert_table *t) 40{ 41 size_t size = 256 * 256 * 256; 42 43 t_convert_fill_table(t); 44 t_convert_in_place_y8u8v8_to_r8g8b8(size, 1, 0, t); 45} 46 47extern "C" void 48t_convert_make_y8u8v8_to_h8s8v8(struct t_convert_table *t) 49{ 50 size_t size = 256 * 256 * 256; 51 52 t_convert_fill_table(t); 53 t_convert_in_place_y8u8v8_to_h8s8v8(size, 1, 0, &t->v); 54} 55 56extern "C" void 57t_convert_make_h8s8v8_to_r8g8b8(struct t_convert_table *t) 58{ 59 size_t size = 256 * 256 * 256; 60 61 t_convert_fill_table(t); 62 t_convert_in_place_h8s8v8_to_r8g8b8(size, 1, 0, &t->v); 63} 64 65extern "C" void 66t_convert_in_place_y8u8v8_to_r8g8b8(uint32_t width, uint32_t height, size_t stride, void *data_ptr) 67{ 68 cv::Mat data(height, width, CV_8UC3, data_ptr, stride); 69 cv::cvtColor(data, data, cv::COLOR_YUV2RGB); 70} 71 72extern "C" void 73t_convert_in_place_y8u8v8_to_h8s8v8(uint32_t width, uint32_t height, size_t stride, void *data_ptr) 74{ 75 cv::Mat data(height, width, CV_8UC3, data_ptr, stride); 76 cv::Mat temp(height, width, CV_32FC3); 77 cv::cvtColor(data, temp, cv::COLOR_YUV2RGB); 78 cv::cvtColor(temp, data, cv::COLOR_RGB2HSV); 79} 80 81extern "C" void 82t_convert_in_place_h8s8v8_to_r8g8b8(uint32_t width, uint32_t height, size_t stride, void *data_ptr) 83{ 84 cv::Mat data(height, width, CV_8UC3, data_ptr, stride); 85 cv::cvtColor(data, data, cv::COLOR_YUV2RGB); 86}