2019-07-23 12:38:58 +00:00
|
|
|
// Copyright 2019, Collabora, Ltd.
|
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
|
|
/*!
|
|
|
|
* @file
|
2019-08-20 11:17:24 +00:00
|
|
|
* @brief @ref xrt_frame_sink converters and other helpers.
|
2019-07-23 12:38:58 +00:00
|
|
|
* @author Jakob Bornecrantz <jakob@collabora.com>
|
|
|
|
* @ingroup aux_util
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "util/u_misc.h"
|
|
|
|
#include "util/u_sink.h"
|
2019-08-22 13:15:41 +00:00
|
|
|
#include "util/u_frame.h"
|
2019-07-23 12:38:58 +00:00
|
|
|
#include "util/u_format.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#ifdef XRT_HAVE_JPEG
|
|
|
|
#include "jpeglib.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Structs
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct u_sink_converter
|
|
|
|
{
|
2019-08-20 11:17:24 +00:00
|
|
|
struct xrt_frame_sink base;
|
2019-08-22 13:15:41 +00:00
|
|
|
struct xrt_frame_node node;
|
2019-07-23 12:38:58 +00:00
|
|
|
|
2019-08-20 11:17:24 +00:00
|
|
|
struct xrt_frame_sink *downstream;
|
2019-07-23 12:38:58 +00:00
|
|
|
|
2019-08-22 13:15:41 +00:00
|
|
|
struct xrt_frame *frame;
|
2019-07-23 12:38:58 +00:00
|
|
|
|
|
|
|
enum xrt_format format;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* YUV functions.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
clamp_to_byte(int v)
|
|
|
|
{
|
|
|
|
if (v < 0) {
|
|
|
|
return 0;
|
2019-08-16 21:56:47 +00:00
|
|
|
}
|
|
|
|
if (v >= 255) {
|
2019-07-23 12:38:58 +00:00
|
|
|
return 255;
|
|
|
|
}
|
2019-08-16 21:56:47 +00:00
|
|
|
return v;
|
2019-07-23 12:38:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t
|
|
|
|
YUV444_to_RGBX8888(int y, int u, int v)
|
|
|
|
{
|
|
|
|
int C = y - 16;
|
|
|
|
int D = u - 128;
|
|
|
|
int E = v - 128;
|
|
|
|
|
|
|
|
int R = clamp_to_byte((298 * C + 409 * E + 128) >> 8);
|
|
|
|
int G = clamp_to_byte((298 * C - 100 * D - 209 * E + 128) >> 8);
|
|
|
|
int B = clamp_to_byte((298 * C + 516 * D + 128) >> 8);
|
|
|
|
|
|
|
|
return B << 16 | G << 8 | R;
|
|
|
|
}
|
|
|
|
|
2019-08-17 09:34:40 +00:00
|
|
|
#undef USE_TABLE
|
|
|
|
#ifdef USE_TABLE
|
|
|
|
static uint32_t lookup_YUV_to_RGBX[256][256][256] = {0};
|
2019-07-23 12:38:58 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
generate_lookup_YUV_to_RGBX()
|
|
|
|
{
|
|
|
|
if (lookup_YUV_to_RGBX[255][255][255] != 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int y;
|
|
|
|
int u;
|
|
|
|
int v;
|
|
|
|
|
|
|
|
for (y = 0; y < 256; y++) {
|
|
|
|
for (u = 0; u < 256; u++) {
|
|
|
|
for (v = 0; v < 256; v++) {
|
|
|
|
lookup_YUV_to_RGBX[y][u][v] =
|
|
|
|
YUV444_to_RGBX8888(y, u, v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-17 09:34:40 +00:00
|
|
|
#endif
|
2019-07-23 12:38:58 +00:00
|
|
|
|
|
|
|
inline static void
|
|
|
|
YUV422_to_R8G8B8X8(const uint8_t *input, uint32_t *rgb1, uint32_t *rgb2)
|
|
|
|
{
|
|
|
|
uint8_t y0 = input[0];
|
|
|
|
uint8_t u = input[1];
|
|
|
|
uint8_t y1 = input[2];
|
|
|
|
uint8_t v = input[3];
|
|
|
|
|
2019-08-17 09:34:40 +00:00
|
|
|
#ifdef USE_TABLE
|
2019-07-23 12:38:58 +00:00
|
|
|
*rgb1 = lookup_YUV_to_RGBX[y0][u][v];
|
|
|
|
*rgb2 = lookup_YUV_to_RGBX[y1][u][v];
|
2019-08-17 09:34:40 +00:00
|
|
|
#else
|
|
|
|
*rgb1 = YUV444_to_RGBX8888(y0, u, v);
|
|
|
|
*rgb2 = YUV444_to_RGBX8888(y1, u, v);
|
|
|
|
#endif
|
2019-07-23 12:38:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline static void
|
|
|
|
YUV422_to_R8G8B8(const uint8_t *input, uint8_t *dst)
|
|
|
|
{
|
|
|
|
uint8_t y0 = input[0];
|
|
|
|
uint8_t u = input[1];
|
|
|
|
uint8_t y1 = input[2];
|
|
|
|
uint8_t v = input[3];
|
|
|
|
|
2019-08-17 09:34:40 +00:00
|
|
|
#ifdef USE_TABLE
|
2019-07-23 12:38:58 +00:00
|
|
|
uint8_t *rgb1 = (uint8_t *)&lookup_YUV_to_RGBX[y0][u][v];
|
|
|
|
uint8_t *rgb2 = (uint8_t *)&lookup_YUV_to_RGBX[y1][u][v];
|
2019-08-17 09:34:40 +00:00
|
|
|
#else
|
|
|
|
uint32_t rgb1v = YUV444_to_RGBX8888(y0, u, v);
|
|
|
|
uint32_t rgb2v = YUV444_to_RGBX8888(y1, u, v);
|
|
|
|
uint8_t *rgb1 = (uint8_t *)&rgb1v;
|
|
|
|
uint8_t *rgb2 = (uint8_t *)&rgb2v;
|
|
|
|
#endif
|
2019-07-23 12:38:58 +00:00
|
|
|
|
|
|
|
dst[0] = rgb1[0];
|
|
|
|
dst[1] = rgb1[1];
|
|
|
|
dst[2] = rgb1[2];
|
|
|
|
dst[3] = rgb2[0];
|
|
|
|
dst[4] = rgb2[1];
|
|
|
|
dst[5] = rgb2[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
from_YUV422_to_R8G8B8(struct u_sink_converter *s,
|
2019-08-22 13:15:41 +00:00
|
|
|
uint32_t w,
|
|
|
|
uint32_t h,
|
2019-07-23 12:38:58 +00:00
|
|
|
size_t stride,
|
|
|
|
const uint8_t *data)
|
|
|
|
{
|
2019-08-22 13:15:41 +00:00
|
|
|
for (uint32_t y = 0; y < h; y++) {
|
|
|
|
for (uint32_t x = 0; x < w; x += 2) {
|
2019-07-23 12:38:58 +00:00
|
|
|
const uint8_t *src = data;
|
2019-08-22 13:15:41 +00:00
|
|
|
uint8_t *dst = s->frame->data;
|
2019-07-23 12:38:58 +00:00
|
|
|
|
|
|
|
src = src + (y * stride) + (x * 2);
|
2019-08-22 13:15:41 +00:00
|
|
|
dst = dst + (y * s->frame->stride) + (x * 3);
|
2019-07-23 12:38:58 +00:00
|
|
|
YUV422_to_R8G8B8(src, dst);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* MJPEG
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef XRT_HAVE_JPEG
|
2019-11-23 00:01:05 +00:00
|
|
|
static bool
|
|
|
|
check_header(size_t size, const uint8_t *data)
|
|
|
|
{
|
|
|
|
if (size < 16) {
|
|
|
|
fprintf(stderr, "error: Invalid JPEG file size! %u\n",
|
|
|
|
(uint32_t)size);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data[0] != 0xFF || data[1] != 0xD8) {
|
|
|
|
fprintf(stderr, "error: Invalid file header! 0x%02X 0x%02X\n",
|
|
|
|
data[0], data[1]);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2019-07-23 12:38:58 +00:00
|
|
|
from_MJPEG_to_R8G8B8(struct u_sink_converter *s,
|
|
|
|
size_t size,
|
|
|
|
const uint8_t *data)
|
|
|
|
{
|
2019-11-23 00:01:05 +00:00
|
|
|
if (!check_header(size, data)) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-07-23 12:38:58 +00:00
|
|
|
|
|
|
|
struct jpeg_decompress_struct cinfo = {0};
|
|
|
|
struct jpeg_error_mgr jerr = {0};
|
|
|
|
|
|
|
|
cinfo.err = jpeg_std_error(&jerr);
|
|
|
|
jerr.trace_level = 0;
|
|
|
|
|
|
|
|
jpeg_create_decompress(&cinfo);
|
|
|
|
jpeg_mem_src(&cinfo, data, size);
|
2019-11-23 00:01:05 +00:00
|
|
|
|
|
|
|
int ret = jpeg_read_header(&cinfo, TRUE);
|
|
|
|
if (ret != JPEG_HEADER_OK) {
|
|
|
|
jpeg_destroy_decompress(&cinfo);
|
|
|
|
return false;
|
|
|
|
}
|
2019-07-23 12:38:58 +00:00
|
|
|
|
|
|
|
cinfo.out_color_space = JCS_RGB;
|
|
|
|
jpeg_start_decompress(&cinfo);
|
|
|
|
|
2019-08-22 13:15:41 +00:00
|
|
|
uint8_t *moving_ptr = s->frame->data;
|
2019-07-23 12:38:58 +00:00
|
|
|
|
|
|
|
uint32_t scanlines_read = 0;
|
|
|
|
while (scanlines_read < cinfo.image_height) {
|
|
|
|
int read_count = jpeg_read_scanlines(&cinfo, &moving_ptr, 16);
|
2019-08-22 13:15:41 +00:00
|
|
|
moving_ptr += read_count * s->frame->stride;
|
2019-07-23 12:38:58 +00:00
|
|
|
scanlines_read += read_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
jpeg_finish_decompress(&cinfo);
|
|
|
|
jpeg_destroy_decompress(&cinfo);
|
2019-11-23 00:01:05 +00:00
|
|
|
|
|
|
|
return true;
|
2019-07-23 12:38:58 +00:00
|
|
|
}
|
2019-08-05 18:20:53 +00:00
|
|
|
|
2019-11-23 00:01:05 +00:00
|
|
|
static bool
|
2019-08-05 18:20:53 +00:00
|
|
|
from_MJPEG_to_YUV888(struct u_sink_converter *s,
|
|
|
|
size_t size,
|
|
|
|
const uint8_t *data)
|
|
|
|
{
|
2019-11-23 00:01:05 +00:00
|
|
|
if (!check_header(size, data)) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-08-05 18:20:53 +00:00
|
|
|
|
|
|
|
struct jpeg_decompress_struct cinfo = {0};
|
|
|
|
struct jpeg_error_mgr jerr = {0};
|
|
|
|
|
|
|
|
cinfo.err = jpeg_std_error(&jerr);
|
|
|
|
jerr.trace_level = 0;
|
|
|
|
|
|
|
|
jpeg_create_decompress(&cinfo);
|
|
|
|
jpeg_mem_src(&cinfo, data, size);
|
2019-11-23 00:01:05 +00:00
|
|
|
|
|
|
|
int ret = jpeg_read_header(&cinfo, TRUE);
|
|
|
|
if (ret != JPEG_HEADER_OK) {
|
|
|
|
jpeg_destroy_decompress(&cinfo);
|
|
|
|
return false;
|
|
|
|
}
|
2019-08-05 18:20:53 +00:00
|
|
|
|
|
|
|
cinfo.out_color_space = JCS_YCbCr;
|
|
|
|
jpeg_start_decompress(&cinfo);
|
|
|
|
|
2019-08-22 13:15:41 +00:00
|
|
|
uint8_t *moving_ptr = s->frame->data;
|
2019-08-05 18:20:53 +00:00
|
|
|
|
|
|
|
uint32_t scanlines_read = 0;
|
|
|
|
while (scanlines_read < cinfo.image_height) {
|
|
|
|
int read_count = jpeg_read_scanlines(&cinfo, &moving_ptr, 16);
|
2019-08-22 13:15:41 +00:00
|
|
|
moving_ptr += read_count * s->frame->stride;
|
2019-08-05 18:20:53 +00:00
|
|
|
scanlines_read += read_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
jpeg_finish_decompress(&cinfo);
|
|
|
|
jpeg_destroy_decompress(&cinfo);
|
2019-11-23 00:01:05 +00:00
|
|
|
|
|
|
|
return true;
|
2019-08-05 18:20:53 +00:00
|
|
|
}
|
2019-07-23 12:38:58 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Misc functions.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2019-08-05 18:20:53 +00:00
|
|
|
ensure_data(struct u_sink_converter *s,
|
|
|
|
enum xrt_format format,
|
|
|
|
uint32_t w,
|
|
|
|
uint32_t h)
|
2019-07-23 12:38:58 +00:00
|
|
|
{
|
2019-08-22 13:15:41 +00:00
|
|
|
u_frame_create_one_off(format, w, h, &s->frame);
|
2019-07-23 12:38:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-08-05 18:20:53 +00:00
|
|
|
push_data_downstream(struct u_sink_converter *s, struct xrt_frame *xf)
|
2019-07-23 12:38:58 +00:00
|
|
|
{
|
2019-08-22 13:15:41 +00:00
|
|
|
// The frame has a single reference on it when it's on the converter
|
|
|
|
// struct, we move it so no need to change the ref count.
|
|
|
|
struct xrt_frame *frame = s->frame;
|
|
|
|
s->frame = NULL;
|
2019-07-23 12:38:58 +00:00
|
|
|
|
2019-08-05 18:20:53 +00:00
|
|
|
// Copy directly from original frame.
|
2019-08-22 13:15:41 +00:00
|
|
|
frame->timestamp = xf->timestamp;
|
|
|
|
frame->source_timestamp = xf->source_timestamp;
|
|
|
|
frame->source_sequence = xf->source_sequence;
|
|
|
|
frame->source_id = xf->source_id;
|
2019-07-23 12:38:58 +00:00
|
|
|
|
2019-08-22 13:15:41 +00:00
|
|
|
s->downstream->push_frame(s->downstream, frame);
|
|
|
|
|
|
|
|
// Refcount in case it's being held downstream.
|
|
|
|
xrt_frame_reference(&frame, NULL);
|
2019-08-05 18:20:53 +00:00
|
|
|
}
|
|
|
|
|
2019-10-19 22:14:19 +00:00
|
|
|
static void
|
|
|
|
receive_frame_r8g8b8_or_l8(struct xrt_frame_sink *xs, struct xrt_frame *xf)
|
|
|
|
{
|
|
|
|
struct u_sink_converter *s = (struct u_sink_converter *)xs;
|
|
|
|
|
|
|
|
switch (xf->format) {
|
|
|
|
case XRT_FORMAT_L8:
|
|
|
|
case XRT_FORMAT_R8G8B8:
|
|
|
|
s->downstream->push_frame(s->downstream, xf);
|
|
|
|
return;
|
|
|
|
case XRT_FORMAT_YUV422:
|
|
|
|
ensure_data(s, XRT_FORMAT_R8G8B8, xf->width, xf->height);
|
|
|
|
from_YUV422_to_R8G8B8(s, xf->width, xf->height, xf->stride,
|
|
|
|
xf->data);
|
|
|
|
break;
|
|
|
|
#ifdef XRT_HAVE_JPEG
|
|
|
|
case XRT_FORMAT_MJPEG:
|
|
|
|
ensure_data(s, XRT_FORMAT_R8G8B8, xf->width, xf->height);
|
2019-11-23 00:01:05 +00:00
|
|
|
if (!from_MJPEG_to_R8G8B8(s, xf->size, xf->data)) {
|
|
|
|
return;
|
|
|
|
}
|
2019-10-19 22:14:19 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "error: Can not convert from '%s'\n",
|
|
|
|
u_format_str(xf->format));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
push_data_downstream(s, xf);
|
|
|
|
}
|
|
|
|
|
2019-08-05 18:20:53 +00:00
|
|
|
static void
|
|
|
|
receive_frame_r8g8b8(struct xrt_frame_sink *xs, struct xrt_frame *xf)
|
|
|
|
{
|
|
|
|
struct u_sink_converter *s = (struct u_sink_converter *)xs;
|
2019-07-23 12:38:58 +00:00
|
|
|
|
|
|
|
switch (xf->format) {
|
2019-08-05 18:20:53 +00:00
|
|
|
case XRT_FORMAT_R8G8B8:
|
|
|
|
s->downstream->push_frame(s->downstream, xf);
|
|
|
|
return;
|
2019-07-23 12:38:58 +00:00
|
|
|
case XRT_FORMAT_YUV422:
|
2019-08-05 18:20:53 +00:00
|
|
|
ensure_data(s, XRT_FORMAT_R8G8B8, xf->width, xf->height);
|
2019-08-22 13:15:41 +00:00
|
|
|
from_YUV422_to_R8G8B8(s, xf->width, xf->height, xf->stride,
|
|
|
|
xf->data);
|
2019-07-23 12:38:58 +00:00
|
|
|
break;
|
|
|
|
#ifdef XRT_HAVE_JPEG
|
|
|
|
case XRT_FORMAT_MJPEG:
|
2019-08-05 18:20:53 +00:00
|
|
|
ensure_data(s, XRT_FORMAT_R8G8B8, xf->width, xf->height);
|
2019-11-23 00:01:05 +00:00
|
|
|
if (!from_MJPEG_to_R8G8B8(s, xf->size, xf->data)) {
|
|
|
|
return;
|
|
|
|
}
|
2019-07-23 12:38:58 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "error: Can not convert from '%s'\n",
|
|
|
|
u_format_str(xf->format));
|
2019-08-05 18:20:53 +00:00
|
|
|
return;
|
2019-07-23 12:38:58 +00:00
|
|
|
}
|
|
|
|
|
2019-08-05 18:20:53 +00:00
|
|
|
push_data_downstream(s, xf);
|
|
|
|
}
|
2019-07-23 12:38:58 +00:00
|
|
|
|
2019-08-05 18:20:53 +00:00
|
|
|
static void
|
|
|
|
receive_frame_yuv_or_yuyv(struct xrt_frame_sink *xs, struct xrt_frame *xf)
|
|
|
|
{
|
|
|
|
struct u_sink_converter *s = (struct u_sink_converter *)xs;
|
2019-07-23 12:38:58 +00:00
|
|
|
|
2019-08-05 18:20:53 +00:00
|
|
|
|
|
|
|
switch (xf->format) {
|
|
|
|
case XRT_FORMAT_YUV422:
|
|
|
|
case XRT_FORMAT_YUV888:
|
|
|
|
s->downstream->push_frame(s->downstream, xf);
|
|
|
|
return;
|
|
|
|
#ifdef XRT_HAVE_JPEG
|
|
|
|
case XRT_FORMAT_MJPEG:
|
|
|
|
ensure_data(s, XRT_FORMAT_YUV888, xf->width, xf->height);
|
2019-11-23 00:01:05 +00:00
|
|
|
if (!from_MJPEG_to_YUV888(s, xf->size, xf->data)) {
|
|
|
|
return;
|
|
|
|
}
|
2019-08-05 18:20:53 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
fprintf(
|
|
|
|
stderr,
|
|
|
|
"error: Can not convert from '%s' to either YUV or YUYV\n",
|
|
|
|
u_format_str(xf->format));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
push_data_downstream(s, xf);
|
2019-07-23 12:38:58 +00:00
|
|
|
}
|
|
|
|
|
2019-08-22 13:15:41 +00:00
|
|
|
static void
|
|
|
|
break_apart(struct xrt_frame_node *node)
|
|
|
|
{}
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroy(struct xrt_frame_node *node)
|
|
|
|
{
|
|
|
|
struct u_sink_converter *s =
|
|
|
|
container_of(node, struct u_sink_converter, node);
|
|
|
|
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
|
2019-07-23 12:38:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* "Exported" functions.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2019-08-22 13:15:41 +00:00
|
|
|
u_sink_create_format_converter(struct xrt_frame_context *xfctx,
|
|
|
|
enum xrt_format f,
|
2019-08-20 11:17:24 +00:00
|
|
|
struct xrt_frame_sink *downstream,
|
|
|
|
struct xrt_frame_sink **out_xfs)
|
2019-07-23 12:38:58 +00:00
|
|
|
{
|
|
|
|
if (f != XRT_FORMAT_R8G8B8) {
|
|
|
|
fprintf(stderr, "error: Format '%s' not supported\n",
|
|
|
|
u_format_str(f));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-17 09:34:40 +00:00
|
|
|
#ifdef USE_TABLE
|
2019-07-23 12:38:58 +00:00
|
|
|
generate_lookup_YUV_to_RGBX();
|
2019-08-17 09:34:40 +00:00
|
|
|
#endif
|
2019-07-23 12:38:58 +00:00
|
|
|
|
|
|
|
struct u_sink_converter *s = U_TYPED_CALLOC(struct u_sink_converter);
|
2019-08-05 18:20:53 +00:00
|
|
|
s->base.push_frame = receive_frame_r8g8b8;
|
2019-08-22 13:15:41 +00:00
|
|
|
s->node.break_apart = break_apart;
|
|
|
|
s->node.destroy = destroy;
|
2019-07-23 12:38:58 +00:00
|
|
|
s->downstream = downstream;
|
2019-08-05 18:20:53 +00:00
|
|
|
|
2019-08-22 13:15:41 +00:00
|
|
|
xrt_frame_context_add(xfctx, &s->node);
|
|
|
|
|
2019-08-05 18:20:53 +00:00
|
|
|
*out_xfs = &s->base;
|
|
|
|
}
|
|
|
|
|
2019-10-19 22:14:19 +00:00
|
|
|
void
|
|
|
|
u_sink_create_to_r8g8b8_or_l8(struct xrt_frame_context *xfctx,
|
|
|
|
struct xrt_frame_sink *downstream,
|
|
|
|
struct xrt_frame_sink **out_xfs)
|
|
|
|
{
|
|
|
|
struct u_sink_converter *s = U_TYPED_CALLOC(struct u_sink_converter);
|
|
|
|
s->base.push_frame = receive_frame_r8g8b8_or_l8;
|
|
|
|
s->node.break_apart = break_apart;
|
|
|
|
s->node.destroy = destroy;
|
|
|
|
s->downstream = downstream;
|
|
|
|
|
|
|
|
#ifdef USE_TABLE
|
|
|
|
generate_lookup_YUV_to_RGBX();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
xrt_frame_context_add(xfctx, &s->node);
|
|
|
|
|
|
|
|
*out_xfs = &s->base;
|
|
|
|
}
|
|
|
|
|
2019-08-05 18:20:53 +00:00
|
|
|
void
|
2019-08-22 13:15:41 +00:00
|
|
|
u_sink_create_to_yuv_or_yuyv(struct xrt_frame_context *xfctx,
|
|
|
|
struct xrt_frame_sink *downstream,
|
2019-08-05 18:20:53 +00:00
|
|
|
struct xrt_frame_sink **out_xfs)
|
|
|
|
{
|
|
|
|
struct u_sink_converter *s = U_TYPED_CALLOC(struct u_sink_converter);
|
|
|
|
s->base.push_frame = receive_frame_yuv_or_yuyv;
|
2019-08-22 13:15:41 +00:00
|
|
|
s->node.break_apart = break_apart;
|
|
|
|
s->node.destroy = destroy;
|
2019-08-05 18:20:53 +00:00
|
|
|
s->downstream = downstream;
|
|
|
|
|
2019-08-22 13:15:41 +00:00
|
|
|
xrt_frame_context_add(xfctx, &s->node);
|
|
|
|
|
2019-07-23 12:38:58 +00:00
|
|
|
*out_xfs = &s->base;
|
|
|
|
}
|