]> git.sesse.net Git - movit/blob - ycbcr_input_test.cpp
Add a unit test for YCbCrInput (not done yet).
[movit] / ycbcr_input_test.cpp
1 // Unit tests for YCbCrInput.
2 // FIXME: This class really ought to support mipmaps.
3
4 #include "test_util.h"
5 #include "gtest/gtest.h"
6 #include "ycbcr_input.h"
7
8 TEST(YCbCrInput, Simple444) {
9         const int width = 1;
10         const int height = 5;
11
12         // Pure-color test inputs, calculated with the formulas in Rec. 601
13         // section 2.5.4.
14         unsigned char y[width * height] = {
15                 16, 235, 81, 145, 41,
16         };
17         unsigned char cb[width * height] = {
18                 128, 128, 90, 54, 240,
19         };
20         unsigned char cr[width * height] = {
21                 128, 128, 240, 34, 110,
22         };
23         float expected_data[4 * width * height] = {
24                 0.0, 0.0, 0.0, 1.0,
25                 1.0, 1.0, 1.0, 1.0,
26                 1.0, 0.0, 0.0, 1.0,
27                 0.0, 1.0, 0.0, 1.0,
28                 0.0, 0.0, 1.0, 1.0,
29         };
30         float out_data[4 * width * height];
31
32         EffectChainTester tester(NULL, width, height);
33
34         ImageFormat format;
35         format.color_space = COLORSPACE_sRGB;
36         format.gamma_curve = GAMMA_sRGB;
37
38         YCbCrFormat ycbcr_format;
39         ycbcr_format.luma_coefficients = YCBCR_REC_601;
40         ycbcr_format.full_range = false;
41         ycbcr_format.chroma_subsampling_x = 1;
42         ycbcr_format.chroma_subsampling_y = 1;
43         ycbcr_format.chroma_x_position = 0.5f;
44         ycbcr_format.chroma_y_position = 0.5f;
45
46         YCbCrInput *input = new YCbCrInput(format, ycbcr_format, width, height);
47         input->set_pixel_data(0, y);
48         input->set_pixel_data(1, cb);
49         input->set_pixel_data(2, cr);
50         tester.get_chain()->add_input(input);
51
52         tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_sRGB);
53
54         // Y'CbCr isn't 100% accurate (the input values are rounded),
55         // so we need some leeway.
56         expect_equal(expected_data, out_data, 4 * width, height, 0.025, 0.002);
57 }