UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
codec_conversions_test.cpp File Reference
#include <iostream>
#include <list>
#include <sstream>
#include <string>
#include <utility>
#include "unit_common.h"
#include "video_codec.h"
#include "video_capture/testcard_common.h"
Include dependency graph for codec_conversions_test.cpp:

Go to the source code of this file.

Functions

int codec_conversion_test_testcard_uyvy_to_i420 (void)
 

Function Documentation

◆ codec_conversion_test_testcard_uyvy_to_i420()

int codec_conversion_test_testcard_uyvy_to_i420 ( void )
Todo
Check also if chroma is horizontally interpolated in UV planes

Definition at line 26 of file codec_conversions_test.cpp.

27{
28 list<pair<size_t,size_t>> sizes = { {1, 2}, {2, 1}, { 16, 1}, {16, 16}, {127, 255} };
29 for (auto &i : sizes) {
30 size_t size_x = i.first;
31 size_t size_y = i.second;
33 unsigned char uyvy_pattern[4] = { 'u', 'y', 'v', 'Y' };
34 size_t uyvy_buf_size = ((size_x + 1) & ~1) * 2 * size_y;
35
36 unsigned char uyvy_buf[uyvy_buf_size];
37 for (size_t i = 0; i < size_y * 2 * ((size_x + 1) & ~1); ++i) {
38 uyvy_buf[i] = uyvy_pattern[i % 4];
39 }
40
41 auto *i420_buf = (unsigned char *) malloc(vc_get_datalen(size_x, size_y, I420));
42 testcard_convert_buffer(UYVY, I420, i420_buf, uyvy_buf, size_x, size_y);
43 unsigned char *y_ptr = i420_buf;
44 for (size_t i = 0; i < size_y; ++i) {
45 for (size_t j = 0; j < size_x; ++j) {
46 ostringstream oss;
47 unsigned char expected = uyvy_pattern[((2 * j + 1) % 4)];
48 unsigned char actual = *y_ptr++;
49 oss << size_x << "X" << size_y << ": [" << i << ", " << j << "]";
50 ASSERT_EQUAL_MESSAGE(oss.str(), expected, actual);
51 }
52 }
53 // U
54 unsigned char *u_ptr = i420_buf + size_x * size_y;
55 for (size_t i = 0; i < (size_y + 1) / 2; ++i) {
56 for (size_t j = 0; j < (size_x + 1) / 2; ++j) {
57 ostringstream oss;
58 unsigned char expected = 'u';
59 unsigned char actual = *u_ptr++;
60 oss << "[" << i << ", " << j << "]";
61 ASSERT_EQUAL_MESSAGE(oss.str(), expected, actual);
62 }
63 }
64 // V
65 unsigned char *v_ptr = i420_buf + size_x * size_y + ((size_x + 1) / 2) * ((size_y + 1) / 2);
66 for (size_t i = 0; i < (size_y + 1) / 2; ++i) {
67 for (size_t j = 0; j < (size_x + 1) / 2; ++j) {
68 ostringstream oss;
69 unsigned char expected = 'v';
70 unsigned char actual = *v_ptr++;
71 oss << "[" << i << ", " << j << "]";
72 ASSERT_EQUAL_MESSAGE(oss.str(), expected, actual);
73 }
74 }
75 free(i420_buf);
76 }
77 return 0;
78}
void testcard_convert_buffer(codec_t in_c, codec_t out_c, unsigned char *out, unsigned const char *in, int width, int height)
@ UYVY
YCbCr 422 8-bit - Cb Y0 Cr Y1.
Definition types.h:71
@ I420
planar YCbCr 4:2:0
Definition types.h:97
#define ASSERT_EQUAL_MESSAGE(msg, expected, actual)
Definition unit_common.h:53
size_t vc_get_datalen(unsigned int width, unsigned int height, codec_t codec)

References ASSERT_EQUAL_MESSAGE, I420, testcard_convert_buffer(), UYVY, and vc_get_datalen().

Here is the call graph for this function: