UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
testcard_common.c File Reference
#include "pixfmt_conv.h"
#include "utils/color_out.h"
#include "video.h"
#include "video_capture/testcard_common.h"
Include dependency graph for testcard_common.c:

Go to the source code of this file.

Functions

static bool testcard_conv_handled_internally (codec_t c)
 
void testcard_convert_buffer (codec_t in_c, codec_t out_c, unsigned char *out, unsigned const char *in, int width, int height)
 
void testcard_fillRect (struct testcard_pixmap *s, struct testcard_rect *r, uint32_t color)
 
bool testcard_has_conversion (codec_t c)
 
void testcard_show_codec_help (const char *name, bool src_8b_only)
 
static void toI420 (unsigned char *out, const unsigned char *input, int width, int height)
 

Variables

const uint32_t rect_colors []
 

Detailed Description

Author
Martin Pulec pulec.nosp@m.@ces.nosp@m.net.c.nosp@m.z

Definition in file testcard_common.c.

Function Documentation

◆ testcard_conv_handled_internally()

static bool testcard_conv_handled_internally ( codec_t c)
static

Definition at line 144 of file testcard_common.c.

145{
146 return c == I420 || c == YUYV || c == v210;
147}
@ YUYV
YCbCr 422 8-bit - Y0 Cb Y1 Cr.
Definition types.h:72
@ I420
planar YCbCr 4:2:0
Definition types.h:97
@ v210
YCbCr 422 10-bit - xVY0U|xY2UY1|xUY3V|xY5VY4, little-endian (2 bit padding /'x'/),...
Definition types.h:75

References I420, v210, and YUYV.

Referenced by testcard_has_conversion(), and testcard_show_codec_help().

◆ testcard_convert_buffer()

void testcard_convert_buffer ( codec_t in_c,
codec_t out_c,
unsigned char * out,
unsigned const char * in,
int width,
int height )

Definition at line 115 of file testcard_common.c.

116{
117 unsigned char *tmp_buffer = NULL;
118 if (out_c == I420 || out_c == YUYV || (in_c == RGBA && out_c == v210)) {
119 decoder_t decoder = get_decoder_from_to(in_c, UYVY);
120 tmp_buffer = malloc(2L * ((width + 1U) ^ 1U) * height);
121 long in_linesize = vc_get_size(width, in_c);
122 long out_linesize = vc_get_size(width, UYVY);
123 for (int i = 0; i < height; ++i) {
124 decoder(tmp_buffer + i * out_linesize, in + i * in_linesize, vc_get_size(width, UYVY), DEFAULT_R_SHIFT, DEFAULT_G_SHIFT, DEFAULT_B_SHIFT);
125 }
126 in = tmp_buffer;
127 in_c = UYVY;
128 }
129 if (out_c == I420) {
130 toI420(out, in, width, height);
131 free(tmp_buffer);
132 return;
133 }
134 decoder_t decoder = get_decoder_from_to(in_c, out_c);
135 assert(decoder != NULL);
136 long out_linesize = vc_get_linesize(width, out_c);
137 long in_linesize = vc_get_linesize(width, in_c);
138 for (int i = 0; i < height; ++i) {
139 decoder(out + i * out_linesize, in + i * in_linesize, vc_get_size(width, out_c), DEFAULT_R_SHIFT, DEFAULT_G_SHIFT, DEFAULT_B_SHIFT);
140 }
141 free(tmp_buffer);
142}
int vc_get_linesize(unsigned int width, codec_t codec)
decoder_t get_decoder_from_to(codec_t in, codec_t out)
#define DEFAULT_B_SHIFT
Definition pixfmt_conv.h:72
#define DEFAULT_R_SHIFT
Definition pixfmt_conv.h:70
decoder_func_t * decoder_t
Definition pixfmt_conv.h:96
#define DEFAULT_G_SHIFT
Definition pixfmt_conv.h:71
static void toI420(unsigned char *out, const unsigned char *input, int width, int height)
@ UYVY
YCbCr 422 8-bit - Cb Y0 Cr Y1.
Definition types.h:71
@ RGBA
RGBA 8-bit, big-endian.
Definition types.h:70
int vc_get_size(unsigned int width, codec_t codec)

References DEFAULT_B_SHIFT, DEFAULT_G_SHIFT, DEFAULT_R_SHIFT, get_decoder_from_to(), I420, RGBA, toI420(), UYVY, v210, vc_get_linesize(), vc_get_size(), and YUYV.

Referenced by interlaced_video_pattern_generator::interlaced_video_pattern_generator(), still_image_video_pattern_generator::still_image_video_pattern_generator(), codec_conversion_test_testcard_uyvy_to_i420(), vidcap_testcard2_init(), and vidcap_testcard2_thread().

Here is the call graph for this function:

◆ testcard_fillRect()

void testcard_fillRect ( struct testcard_pixmap * s,
struct testcard_rect * r,
uint32_t color )

Definition at line 58 of file testcard_common.c.

59{
60 uint32_t *data = s->data;
61
62 for (int cur_x = r->x; cur_x < r->x + r->w; ++cur_x) {
63 for (int cur_y = r->y; cur_y < r->y + r->h; ++cur_y) {
64 if (cur_x < s->w) {
65 *(data + (long) s->w * cur_y + cur_x) = color;
66 }
67 }
68 }
69}

References testcard_pixmap::data, testcard_rect::h, testcard_pixmap::w, testcard_rect::w, testcard_rect::x, and testcard_rect::y.

Referenced by image_pattern_bars::fill(), image_pattern_ebu_smpte_bars< f, columns >::fill(), image_pattern_smpte_bars::fill(), and vidcap_testcard2_init().

◆ testcard_has_conversion()

bool testcard_has_conversion ( codec_t c)

Definition at line 179 of file testcard_common.c.

180{
181 return get_decoder_from_to(RG48, c) != NULL ||
182 get_decoder_from_to(RGBA, c) != NULL ||
184}
static bool testcard_conv_handled_internally(codec_t c)
@ RG48
16-bit RGB little-endian (RlRhGl...)
Definition types.h:95

References get_decoder_from_to(), RG48, RGBA, and testcard_conv_handled_internally().

Referenced by parse_format().

Here is the call graph for this function:

◆ testcard_show_codec_help()

void testcard_show_codec_help ( const char * name,
bool src_8b_only )

Definition at line 149 of file testcard_common.c.

150{
151 bool print_i420 = !src_8b_only; // testcard2 cannot handle planar format, anyway
152 printf("Supported codecs (%s):\n", name);
153
154 color_printf(TERM_FG_RED "\t8 bits\n" TERM_RESET);
155 for (codec_t c = VIDEO_CODEC_FIRST; c != VIDEO_CODEC_COUNT; c = (int) c + 1) {
158 continue;
159 }
160 if (c == I420 && !print_i420) {
161 continue;
162 }
164 }
165
166 color_printf(TERM_FG_RED "\t10+ bits\n" TERM_RESET);
167 for (codec_t c = VIDEO_CODEC_FIRST; c != VIDEO_CODEC_COUNT; c = (int) c + 1) {
168 if (is_codec_opaque(c) || get_bits_per_component(c) == 8) {
169 continue;
170 }
172 ((src_8b_only && c != v210) || get_decoder_from_to(RG48, c) == VIDEO_CODEC_NONE)) {
173 continue;
174 }
176 }
177}
const char * get_codec_name(codec_t codec)
int color_printf(const char *format,...)
#define TERM_BOLD
Definition color_out.h:48
#define TERM_FG_RED
Definition color_out.h:50
#define TERM_RESET
Definition color_out.h:47
const char * name
Definition settings.cpp:193
codec_t
Definition types.h:65
@ VIDEO_CODEC_NONE
dummy color spec
Definition types.h:66
@ VIDEO_CODEC_FIRST
Definition types.h:68
@ VIDEO_CODEC_COUNT
count of known video codecs (including VIDEO_CODEC_NONE)
Definition types.h:108
bool is_codec_opaque(codec_t codec)
const char * get_codec_name_long(codec_t codec)
int get_bits_per_component(codec_t codec)

References color_printf(), get_bits_per_component(), get_codec_name(), get_codec_name_long(), get_decoder_from_to(), I420, is_codec_opaque(), name, RG48, RGBA, TERM_BOLD, TERM_FG_RED, TERM_RESET, testcard_conv_handled_internally(), v210, VIDEO_CODEC_COUNT, VIDEO_CODEC_FIRST, and VIDEO_CODEC_NONE.

Referenced by show_help(), and vidcap_testcard2_init().

Here is the call graph for this function:

◆ toI420()

static void toI420 ( unsigned char * out,
const unsigned char * input,
int width,
int height )
static
Parameters
[in]inbuffer in UYVY
Return values
bufferin I420 (must be deallocated by the caller)
Note
Caller must deallocate returned buffer

Definition at line 77 of file testcard_common.c.

78{
79 const unsigned char *in = (const unsigned char *) input;
80 int w_ch = (width + 1) / 2;
81 int h_ch = (height + 1) / 2;
82 unsigned char *y = out;
83 unsigned char *u0 = out + width * height;
84 unsigned char *v0 = out + width * height + w_ch * h_ch;
85 unsigned char *u1 = u0, *v1 = v0;
86
87 for (int i = 0; i < height; i += 1) {
88 for (int j = 0; j < ((width + 1) & ~1); j += 2) {
89 // U
90 if (i % 2 == 0) {
91 *u0++ = *in++;
92 } else { // average with every 2nd row
93 *u1 = (*u1 + *in++) / 2;
94 u1++;
95 }
96 // Y
97 *y++ = *in++;
98 // V
99 if (i % 2 == 0) {
100 *v0++ = *in++;
101 } else { // average with every 2nd row
102 *v1 = (*v1 + *in++) / 2;
103 v1++;
104 }
105 // Y
106 if (j + 1 == width) {
107 in++;
108 } else {
109 *y++ = *in++;
110 }
111 }
112 }
113}

Referenced by testcard_convert_buffer().

Variable Documentation

◆ rect_colors

const uint32_t rect_colors[]
Initial value:
= {
0xff0000ffLU,
0xff00ff00LU,
0xffff0000LU,
0xff00ffffLU,
0xffffff00LU,
0xffff00ffLU
}

Definition at line 49 of file testcard_common.c.

49 {
50 0xff0000ffLU,
51 0xff00ff00LU,
52 0xffff0000LU,
53 0xff00ffffLU,
54 0xffffff00LU,
55 0xffff00ffLU
56};

Referenced by image_pattern_strips::image_pattern_strips(), image_pattern_bars::fill(), and vidcap_testcard2_init().