color coeff computing updates

Mainly depth is included in Y_ and CBCR_LIMIT - the used denominator
255.0 matched only 8 bits.

Add (substract) epsilon 0.5 when converting the to integer to round the
value correctly.
This commit is contained in:
Martin Pulec
2024-09-17 15:25:06 +02:00
parent cad561ead6
commit 4fe65769f0
9 changed files with 425 additions and 205 deletions

View File

@@ -1,12 +1,10 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#include "config_unix.h"
#include "config_win32.h"
#endif
#include <cstring> // for strcmp
#include <cmath> // for abs
#include <list>
#include <sstream>
#include <string> // for allocator, basic_string, operator+, string
#include "color.h"
#include "types.h"
#include "utils/string.h"
#include "unit_common.h"
@@ -14,12 +12,63 @@
#include "video_frame.h"
extern "C" {
int misc_test_replace_all();
int misc_test_video_desc_io_op_symmetry();
int misc_test_color_coeff_range();
int misc_test_replace_all();
int misc_test_video_desc_io_op_symmetry();
}
using namespace std;
/**
* check that scaled coefficient for minimal values match approximately minimal
* value of nominal range (== there is not significant shift)
*/
int
misc_test_color_coeff_range()
{
const int depths[] = { 8, 10, 12, 16 };
for (unsigned i = 0; i < sizeof depths / sizeof depths[0]; ++i) {
const int d = depths[i];
const int d_max = (1 << d) - 1;
const int max_diff = 1 << (d - 8);
// Y
ASSERT_LE_MESSAGE(
"min Y diverges from nominal range min", max_diff,
abs((RGB_TO_Y_709_SCALED(d, 0, 0, 0) >> COMP_BASE) +
LIMIT_LO(d)) -
LIMIT_LO(d));
ASSERT_LE_MESSAGE(
"max Y diverges from nominal range max", max_diff,
abs((RGB_TO_Y_709_SCALED(d, d_max, d_max, d_max) >>
COMP_BASE) +
LIMIT_LO(d) - LIMIT_HI_Y(d)));
// Cb
ASSERT_LE_MESSAGE(
"min Cb diverges from nominal range min", max_diff,
abs((RGB_TO_CB_709_SCALED(d, d_max, d_max, 0) >>
COMP_BASE) +
(1 << (d - 1)) - LIMIT_LO(d)));
ASSERT_LE_MESSAGE(
"max Cb diverges from nominal range max", max_diff,
abs((RGB_TO_CB_709_SCALED(d, 0, 0, d_max) >> COMP_BASE) +
(1 << (d - 1)) - LIMIT_HI_CBCR(d)));
// Cr
ASSERT_LE_MESSAGE(
"min Cr diverges from nominal range min", max_diff,
abs((RGB_TO_CR_709_SCALED(d, 0, d_max, d_max) >>
COMP_BASE) +
(1 << (d - 1)) - LIMIT_LO(d)));
ASSERT_LE_MESSAGE(
"max Cr diverges from nominal range max", max_diff,
abs((RGB_TO_CR_709_SCALED(d, d_max, 0, 0) >> COMP_BASE) +
(1 << (d - 1)) - LIMIT_HI_CBCR(d)));
}
return 0;
}
#ifdef __clang__
#pragma clang diagnostic ignored "-Wstring-concatenation"
#endif