UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
misc_test.cpp
Go to the documentation of this file.
1#include <cstring> // for strcmp
2#include <cmath> // for abs
3#include <list>
4#include <sstream>
5#include <string> // for allocator, basic_string, operator+, string
6
7#include "color.h"
8#include "types.h"
9#include "utils/string.h"
10#include "unit_common.h"
11#include "video.h"
12#include "video_frame.h"
13
14extern "C" {
18}
19
20using namespace std;
21
26int
28{
29 const int depths[] = { 8, 10, 12, 16 };
30
31 for (unsigned i = 0; i < sizeof depths / sizeof depths[0]; ++i) {
32 const int d = depths[i];
33 const int d_max = (1 << d) - 1;
34 const int max_diff = 1 << (d - 8);
35
36 // Y
38 "min Y diverges from nominal range min", max_diff,
39 abs((RGB_TO_Y_709_SCALED(d, 0, 0, 0) >> COMP_BASE) +
40 LIMIT_LO(d)) -
41 LIMIT_LO(d));
43 "max Y diverges from nominal range max", max_diff,
44 abs((RGB_TO_Y_709_SCALED(d, d_max, d_max, d_max) >>
45 COMP_BASE) +
46 LIMIT_LO(d) - LIMIT_HI_Y(d)));
47 // Cb
49 "min Cb diverges from nominal range min", max_diff,
50 abs((RGB_TO_CB_709_SCALED(d, d_max, d_max, 0) >>
51 COMP_BASE) +
52 (1 << (d - 1)) - LIMIT_LO(d)));
54 "max Cb diverges from nominal range max", max_diff,
55 abs((RGB_TO_CB_709_SCALED(d, 0, 0, d_max) >> COMP_BASE) +
56 (1 << (d - 1)) - LIMIT_HI_CBCR(d)));
57 // Cr
59 "min Cr diverges from nominal range min", max_diff,
60 abs((RGB_TO_CR_709_SCALED(d, 0, d_max, d_max) >>
61 COMP_BASE) +
62 (1 << (d - 1)) - LIMIT_LO(d)));
64 "max Cr diverges from nominal range max", max_diff,
65 abs((RGB_TO_CR_709_SCALED(d, d_max, 0, 0) >> COMP_BASE) +
66 (1 << (d - 1)) - LIMIT_HI_CBCR(d)));
67 }
68
69 return 0;
70}
71
72#ifdef __clang__
73#pragma clang diagnostic ignored "-Wstring-concatenation"
74#endif
76{
77 char test[][20] = { DELDEL DELDEL DELDEL, DELDEL DELDEL, "XYZX" DELDEL, "XXXyX" };
78 const char *repl_from[] = { DELDEL , DELDEL, "X", "X" };
79 const char *repl_to[] = { ":" , ESCAPED_COLON, "x", "" };
80 const char *res[] = { ":::" , ESCAPED_COLON ESCAPED_COLON, "xYZx" DELDEL, "y" };
81 for (unsigned i = 0; i < sizeof test / sizeof test[0]; ++i) {
82 replace_all(test[i], repl_from[i], repl_to[i]);
83 ASSERT(strcmp(test[i], res[i]) == 0);
84 }
85 return 0;
86}
87
89{
90 const std::list<video_desc> test_desc = {
91 {1920, 1080, DXT5, 60, PROGRESSIVE, 4},
92 {640, 480, H264, 15, PROGRESSIVE, 1}};
93 for (const auto & i : test_desc) {
94 video_desc tmp;
95
96 ostringstream oss;
97 oss << i;
98 istringstream iss(oss.str());
99 iss >> tmp;
100
101 // Check
102 ostringstream oss2;
103 oss2 << tmp;
104 string err_elem = oss.str() + " vs " + oss2.str();
105 ASSERT_MESSAGE(err_elem, video_desc_eq(tmp, i));
106 ASSERT_EQUAL_MESSAGE(err_elem, tmp, i);
107 }
108 return 0;
109}
#define LIMIT_LO(depth)
Definition color.h:131
#define LIMIT_HI_CBCR(depth)
Definition color.h:133
#define RGB_TO_CB_709_SCALED(out_depth, r, g, b)
Definition color.h:122
#define LIMIT_HI_Y(depth)
Definition color.h:132
#define COMP_BASE
Definition color.h:66
#define RGB_TO_CR_709_SCALED(out_depth, r, g, b)
Definition color.h:124
#define RGB_TO_Y_709_SCALED(out_depth, r, g, b)
Definition color.h:120
static __device__ vec2 abs(const vec2 &v)
Definition cuda_dxt.cu:118
int misc_test_video_desc_io_op_symmetry()
Definition misc_test.cpp:88
int misc_test_replace_all()
Definition misc_test.cpp:75
int misc_test_color_coeff_range()
Definition misc_test.cpp:27
void replace_all(char *in, const char *from, const char *to)
Replaces all occurencies of 'from' to 'to' in string 'in'.
Definition string.c:71
#define DELDEL
Definition string.h:50
#define ESCAPED_COLON
Definition string.h:51
@ PROGRESSIVE
progressive frame
Definition types.h:164
@ H264
H.264 frame.
Definition types.h:83
@ DXT5
S3 Texture Compression DXT5.
Definition types.h:79
#define ASSERT_EQUAL_MESSAGE(msg, expected, actual)
Definition unit_common.h:53
#define ASSERT(expr)
Definition unit_common.h:13
#define ASSERT_LE_MESSAGE(msg, expected, actual)
Definition unit_common.h:79
#define ASSERT_MESSAGE(msg, expr)
Definition unit_common.h:20
This is an umbrella header for video functions.
bool video_desc_eq(struct video_desc a, struct video_desc b)
Compares two video descriptions.