Resguardo inicial

This commit is contained in:
lastdragon
2026-09-06 12:53:21 -06:00
parent 662efe3c2a
commit ad2088d178
94853 changed files with 43200404 additions and 0 deletions
@@ -0,0 +1,4 @@
CONFIG_KUNIT=y
CONFIG_DRM=y
CONFIG_DRM_VKMS=y
CONFIG_DRM_VKMS_KUNIT_TEST=y
@@ -0,0 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only
vkms-kunit-tests-y := \
vkms_config_test.o \
vkms_format_test.o \
vkms_color_test.o
obj-$(CONFIG_DRM_VKMS_KUNIT_TEST) += vkms-kunit-tests.o
@@ -0,0 +1,414 @@
// SPDX-License-Identifier: GPL-2.0+
#include <kunit/test.h>
#include <drm/drm_fixed.h>
#include <drm/drm_mode.h>
#include "../vkms_composer.h"
#include "../vkms_drv.h"
#include "../vkms_luts.h"
#define TEST_LUT_SIZE 16
MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");
static struct drm_color_lut test_linear_array[TEST_LUT_SIZE] = {
{ 0x0, 0x0, 0x0, 0 },
{ 0x1111, 0x1111, 0x1111, 0 },
{ 0x2222, 0x2222, 0x2222, 0 },
{ 0x3333, 0x3333, 0x3333, 0 },
{ 0x4444, 0x4444, 0x4444, 0 },
{ 0x5555, 0x5555, 0x5555, 0 },
{ 0x6666, 0x6666, 0x6666, 0 },
{ 0x7777, 0x7777, 0x7777, 0 },
{ 0x8888, 0x8888, 0x8888, 0 },
{ 0x9999, 0x9999, 0x9999, 0 },
{ 0xaaaa, 0xaaaa, 0xaaaa, 0 },
{ 0xbbbb, 0xbbbb, 0xbbbb, 0 },
{ 0xcccc, 0xcccc, 0xcccc, 0 },
{ 0xdddd, 0xdddd, 0xdddd, 0 },
{ 0xeeee, 0xeeee, 0xeeee, 0 },
{ 0xffff, 0xffff, 0xffff, 0 },
};
/* lerp test parameters */
struct vkms_color_test_lerp_params {
s64 t;
__u16 a;
__u16 b;
__u16 expected;
};
/* lerp test cases */
static const struct vkms_color_test_lerp_params color_test_lerp_cases[] = {
/* Half-way round down */
{ 0x80000000 - 1, 0x0, 0x10, 0x8 },
{ 0x80000000 - 1, 0x1, 0x10, 0x8 }, /* Odd a */
{ 0x80000000 - 1, 0x1, 0xf, 0x8 }, /* Odd b */
{ 0x80000000 - 1, 0x10, 0x10, 0x10 }, /* b = a */
{ 0x80000000 - 1, 0x10, 0x11, 0x10 }, /* b = a + 1*/
/* Half-way round up */
{ 0x80000000, 0x0, 0x10, 0x8 },
{ 0x80000000, 0x1, 0x10, 0x9 }, /* Odd a */
{ 0x80000000, 0x1, 0xf, 0x8 }, /* Odd b */
{ 0x80000000, 0x10, 0x10, 0x10 }, /* b = a */
{ 0x80000000, 0x10, 0x11, 0x11 }, /* b = a + 1*/
/* t = 0.0 */
{ 0x0, 0x0, 0x10, 0x0 },
{ 0x0, 0x1, 0x10, 0x1 }, /* Odd a */
{ 0x0, 0x1, 0xf, 0x1 }, /* Odd b */
{ 0x0, 0x10, 0x10, 0x10 }, /* b = a */
{ 0x0, 0x10, 0x11, 0x10 }, /* b = a + 1*/
/* t = 1.0 */
{ 0x100000000, 0x0, 0x10, 0x10 },
{ 0x100000000, 0x1, 0x10, 0x10 }, /* Odd a */
{ 0x100000000, 0x1, 0xf, 0xf }, /* Odd b */
{ 0x100000000, 0x10, 0x10, 0x10 }, /* b = a */
{ 0x100000000, 0x10, 0x11, 0x11 }, /* b = a + 1*/
/* t = 0.0 + 1 */
{ 0x0 + 1, 0x0, 0x10, 0x0 },
{ 0x0 + 1, 0x1, 0x10, 0x1 }, /* Odd a */
{ 0x0 + 1, 0x1, 0xf, 0x1 }, /* Odd b */
{ 0x0 + 1, 0x10, 0x10, 0x10 }, /* b = a */
{ 0x0 + 1, 0x10, 0x11, 0x10 }, /* b = a + 1*/
/* t = 1.0 - 1 */
{ 0x100000000 - 1, 0x0, 0x10, 0x10 },
{ 0x100000000 - 1, 0x1, 0x10, 0x10 }, /* Odd a */
{ 0x100000000 - 1, 0x1, 0xf, 0xf }, /* Odd b */
{ 0x100000000 - 1, 0x10, 0x10, 0x10 }, /* b = a */
{ 0x100000000 - 1, 0x10, 0x11, 0x11 }, /* b = a + 1*/
/* t chosen to verify the flipping point of result a (or b) to a+1 (or b-1) */
{ 0x80000000 - 1, 0x0, 0x1, 0x0 },
{ 0x80000000, 0x0, 0x1, 0x1 },
};
static const struct vkms_color_lut test_linear_lut = {
.base = test_linear_array,
.lut_length = TEST_LUT_SIZE,
.channel_value2index_ratio = 0xf000fll
};
static void vkms_color_test_get_lut_index(struct kunit *test)
{
s64 lut_index;
int i;
lut_index = get_lut_index(&test_linear_lut, test_linear_array[0].red);
KUNIT_EXPECT_EQ(test, drm_fixp2int(lut_index), 0);
for (i = 0; i < TEST_LUT_SIZE; i++) {
lut_index = get_lut_index(&test_linear_lut, test_linear_array[i].red);
KUNIT_EXPECT_EQ(test, drm_fixp2int_ceil(lut_index), i);
}
KUNIT_EXPECT_EQ(test, drm_fixp2int(get_lut_index(&srgb_eotf, 0x0)), 0x0);
KUNIT_EXPECT_EQ(test, drm_fixp2int_ceil(get_lut_index(&srgb_eotf, 0x0)), 0x0);
KUNIT_EXPECT_EQ(test, drm_fixp2int_ceil(get_lut_index(&srgb_eotf, 0x101)), 0x1);
KUNIT_EXPECT_EQ(test, drm_fixp2int_ceil(get_lut_index(&srgb_eotf, 0x202)), 0x2);
KUNIT_EXPECT_EQ(test, drm_fixp2int(get_lut_index(&srgb_inv_eotf, 0x0)), 0x0);
KUNIT_EXPECT_EQ(test, drm_fixp2int_ceil(get_lut_index(&srgb_inv_eotf, 0x0)), 0x0);
KUNIT_EXPECT_EQ(test, drm_fixp2int_ceil(get_lut_index(&srgb_inv_eotf, 0x101)), 0x1);
KUNIT_EXPECT_EQ(test, drm_fixp2int_ceil(get_lut_index(&srgb_inv_eotf, 0x202)), 0x2);
KUNIT_EXPECT_EQ(test, drm_fixp2int_ceil(get_lut_index(&srgb_eotf, 0xfefe)), 0xfe);
KUNIT_EXPECT_EQ(test, drm_fixp2int_ceil(get_lut_index(&srgb_eotf, 0xffff)), 0xff);
}
static void vkms_color_test_lerp(struct kunit *test)
{
int i;
for (i = 0; i < ARRAY_SIZE(color_test_lerp_cases); i++) {
const struct vkms_color_test_lerp_params *params = &color_test_lerp_cases[i];
KUNIT_EXPECT_EQ(test, lerp_u16(params->a, params->b, params->t), params->expected);
}
}
static void vkms_color_test_linear(struct kunit *test)
{
for (int i = 0; i < LUT_SIZE; i++) {
int linear = apply_lut_to_channel_value(&linear_eotf, i * 0x101, LUT_RED);
KUNIT_EXPECT_EQ(test, DIV_ROUND_CLOSEST(linear, 0x101), i);
}
}
static void vkms_color_srgb_inv_srgb(struct kunit *test)
{
u16 srgb, final;
for (int i = 0; i < LUT_SIZE; i++) {
srgb = apply_lut_to_channel_value(&srgb_eotf, i * 0x101, LUT_RED);
final = apply_lut_to_channel_value(&srgb_inv_eotf, srgb, LUT_RED);
KUNIT_EXPECT_GE(test, final / 0x101, i - 1);
KUNIT_EXPECT_LE(test, final / 0x101, i + 1);
}
}
#define FIXPT_HALF (DRM_FIXED_ONE >> 1)
#define FIXPT_QUARTER (DRM_FIXED_ONE >> 2)
static const struct drm_color_ctm_3x4 test_matrix_3x4_50_desat = { {
FIXPT_HALF, FIXPT_QUARTER, FIXPT_QUARTER, 0,
FIXPT_QUARTER, FIXPT_HALF, FIXPT_QUARTER, 0,
FIXPT_QUARTER, FIXPT_QUARTER, FIXPT_HALF, 0
} };
static void vkms_color_ctm_3x4_50_desat(struct kunit *test)
{
struct pixel_argb_s32 ref, out;
/* full white */
ref.a = 0xffff;
ref.r = 0xffff;
ref.g = 0xffff;
ref.b = 0xffff;
memcpy(&out, &ref, sizeof(out));
apply_3x4_matrix(&out, &test_matrix_3x4_50_desat);
KUNIT_EXPECT_MEMEQ(test, &ref, &out, sizeof(out));
/* full black */
ref.a = 0xffff;
ref.r = 0x0;
ref.g = 0x0;
ref.b = 0x0;
memcpy(&out, &ref, sizeof(out));
apply_3x4_matrix(&out, &test_matrix_3x4_50_desat);
KUNIT_EXPECT_MEMEQ(test, &ref, &out, sizeof(out));
/* 50% grey */
ref.a = 0xffff;
ref.r = 0x8000;
ref.g = 0x8000;
ref.b = 0x8000;
memcpy(&out, &ref, sizeof(out));
apply_3x4_matrix(&out, &test_matrix_3x4_50_desat);
KUNIT_EXPECT_MEMEQ(test, &ref, &out, sizeof(out));
/* full red to 50% desat */
ref.a = 0xffff;
ref.r = 0x8000;
ref.g = 0x4000;
ref.b = 0x4000;
out.a = 0xffff;
out.r = 0xffff;
out.g = 0x0;
out.b = 0x0;
apply_3x4_matrix(&out, &test_matrix_3x4_50_desat);
KUNIT_EXPECT_MEMEQ(test, &ref, &out, sizeof(out));
}
/*
* BT.709 encoding matrix
*
* Values printed from within IGT when converting
* igt_matrix_3x4_bt709_enc to the fixed-point format expected
* by DRM/KMS.
*/
static const struct drm_color_ctm_3x4 test_matrix_3x4_bt709_enc = { {
0x00000000366cf400ull, 0x00000000b7175900ull, 0x0000000127bb300ull, 0,
0x800000001993b3a0ull, 0x800000005609fe80ull, 0x000000006f9db200ull, 0,
0x000000009d70a400ull, 0x800000008f011100ull, 0x800000000e6f9330ull, 0
} };
static void vkms_color_ctm_3x4_bt709(struct kunit *test)
{
struct pixel_argb_s32 out;
/* full white to bt709 */
out.a = 0xffff;
out.r = 0xffff;
out.g = 0xffff;
out.b = 0xffff;
apply_3x4_matrix(&out, &test_matrix_3x4_bt709_enc);
/* Y 255 */
KUNIT_EXPECT_GT(test, out.r, 0xfe00);
KUNIT_EXPECT_LT(test, out.r, 0x10000);
/* U 0 */
KUNIT_EXPECT_LT(test, out.g, 0x0100);
/* V 0 */
KUNIT_EXPECT_LT(test, out.b, 0x0100);
/* full black to bt709 */
out.a = 0xffff;
out.r = 0x0;
out.g = 0x0;
out.b = 0x0;
apply_3x4_matrix(&out, &test_matrix_3x4_bt709_enc);
/* Y 0 */
KUNIT_EXPECT_LT(test, out.r, 0x100);
/* U 0 */
KUNIT_EXPECT_LT(test, out.g, 0x0100);
/* V 0 */
KUNIT_EXPECT_LT(test, out.b, 0x0100);
/* gray to bt709 */
out.a = 0xffff;
out.r = 0x7fff;
out.g = 0x7fff;
out.b = 0x7fff;
apply_3x4_matrix(&out, &test_matrix_3x4_bt709_enc);
/* Y 127 */
KUNIT_EXPECT_GT(test, out.r, 0x7e00);
KUNIT_EXPECT_LT(test, out.r, 0x8000);
/* U 0 */
KUNIT_EXPECT_LT(test, out.g, 0x0100);
/* V 0 */
KUNIT_EXPECT_LT(test, out.b, 0x0100);
/* == red 255 - bt709 enc == */
out.a = 0xffff;
out.r = 0xffff;
out.g = 0x0;
out.b = 0x0;
apply_3x4_matrix(&out, &test_matrix_3x4_bt709_enc);
/* Y 54 */
KUNIT_EXPECT_GT(test, out.r, 0x3500);
KUNIT_EXPECT_LT(test, out.r, 0x3700);
/* U 0 */
KUNIT_EXPECT_LT(test, out.g, 0x0100);
/* V 157 */
KUNIT_EXPECT_GT(test, out.b, 0x9C00);
KUNIT_EXPECT_LT(test, out.b, 0x9E00);
/* == green 255 - bt709 enc == */
out.a = 0xffff;
out.r = 0x0;
out.g = 0xffff;
out.b = 0x0;
apply_3x4_matrix(&out, &test_matrix_3x4_bt709_enc);
/* Y 182 */
KUNIT_EXPECT_GT(test, out.r, 0xB500);
KUNIT_EXPECT_LT(test, out.r, 0xB780); /* laxed by half*/
/* U 0 */
KUNIT_EXPECT_LT(test, out.g, 0x0100);
/* V 0 */
KUNIT_EXPECT_LT(test, out.b, 0x0100);
/* == blue 255 - bt709 enc == */
out.a = 0xffff;
out.r = 0x0;
out.g = 0x0;
out.b = 0xffff;
apply_3x4_matrix(&out, &test_matrix_3x4_bt709_enc);
/* Y 18 */
KUNIT_EXPECT_GT(test, out.r, 0x1100);
KUNIT_EXPECT_LT(test, out.r, 0x1300);
/* U 111 */
KUNIT_EXPECT_GT(test, out.g, 0x6E00);
KUNIT_EXPECT_LT(test, out.g, 0x7000);
/* V 0 */
KUNIT_EXPECT_LT(test, out.b, 0x0100);
/* == red 140 - bt709 enc == */
out.a = 0xffff;
out.r = 0x8c8c;
out.g = 0x0;
out.b = 0x0;
apply_3x4_matrix(&out, &test_matrix_3x4_bt709_enc);
/* Y 30 */
KUNIT_EXPECT_GT(test, out.r, 0x1D00);
KUNIT_EXPECT_LT(test, out.r, 0x1F00);
/* U 0 */
KUNIT_EXPECT_LT(test, out.g, 0x100);
/* V 87 */
KUNIT_EXPECT_GT(test, out.b, 0x5600);
KUNIT_EXPECT_LT(test, out.b, 0x5800);
/* == green 140 - bt709 enc == */
out.a = 0xffff;
out.r = 0x0;
out.g = 0x8c8c;
out.b = 0x0;
apply_3x4_matrix(&out, &test_matrix_3x4_bt709_enc);
/* Y 30 */
KUNIT_EXPECT_GT(test, out.r, 0x6400);
KUNIT_EXPECT_LT(test, out.r, 0x6600);
/* U 0 */
KUNIT_EXPECT_LT(test, out.g, 0x100);
/* V 0 */
KUNIT_EXPECT_LT(test, out.b, 0x100);
/* == blue 140 - bt709 enc == */
out.a = 0xffff;
out.r = 0x0;
out.g = 0x0;
out.b = 0x8c8c;
apply_3x4_matrix(&out, &test_matrix_3x4_bt709_enc);
/* Y 30 */
KUNIT_EXPECT_GT(test, out.r, 0x900);
KUNIT_EXPECT_LT(test, out.r, 0xB00);
/* U 61 */
KUNIT_EXPECT_GT(test, out.g, 0x3C00);
KUNIT_EXPECT_LT(test, out.g, 0x3E00);
/* V 0 */
KUNIT_EXPECT_LT(test, out.b, 0x100);
}
static struct kunit_case vkms_color_test_cases[] = {
KUNIT_CASE(vkms_color_test_get_lut_index),
KUNIT_CASE(vkms_color_test_lerp),
KUNIT_CASE(vkms_color_test_linear),
KUNIT_CASE(vkms_color_srgb_inv_srgb),
KUNIT_CASE(vkms_color_ctm_3x4_50_desat),
KUNIT_CASE(vkms_color_ctm_3x4_bt709),
{}
};
static struct kunit_suite vkms_color_test_suite = {
.name = "vkms-color",
.test_cases = vkms_color_test_cases,
};
kunit_test_suite(vkms_color_test_suite);
MODULE_DESCRIPTION("Kunit test for VKMS LUT handling");
MODULE_LICENSE("GPL");
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,279 @@
// SPDX-License-Identifier: GPL-2.0+
#include <kunit/test.h>
#include <drm/drm_fixed.h>
#include <drm/drm_fourcc.h>
#include "../../drm_crtc_internal.h"
#include "../vkms_formats.h"
#define TEST_BUFF_SIZE 50
MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");
/**
* struct pixel_yuv_u16 - Internal representation of a pixel color.
* @y: Luma value, stored in 16 bits, without padding, using
* machine endianness
* @u: Blue difference chroma value, stored in 16 bits, without padding, using
* machine endianness
* @v: Red difference chroma value, stored in 16 bits, without padding, using
* machine endianness
*/
struct pixel_yuv_u16 {
u16 y, u, v;
};
/*
* struct yuv_u16_to_argb_u16_case - Reference values to test the color
* conversions in VKMS between YUV to ARGB
*
* @encoding: Encoding used to convert RGB to YUV
* @range: Range used to convert RGB to YUV
* @n_colors: Count of test colors in this case
* @format_pair.name: Name used for this color conversion, used to
* clarify the test results
* @format_pair.rgb: RGB color tested
* @format_pair.yuv: Same color as @format_pair.rgb, but converted to
* YUV using @encoding and @range.
*/
struct yuv_u16_to_argb_u16_case {
enum drm_color_encoding encoding;
enum drm_color_range range;
size_t n_colors;
struct format_pair {
char *name;
struct pixel_yuv_u16 yuv;
struct pixel_argb_u16 argb;
} colors[TEST_BUFF_SIZE];
};
/*
* The YUV color representation were acquired via the colour python framework.
* Below are the function calls used for generating each case.
*
* For more information got to the docs:
* https://colour.readthedocs.io/en/master/generated/colour.RGB_to_YCbCr.html
*/
static struct yuv_u16_to_argb_u16_case yuv_u16_to_argb_u16_cases[] = {
/*
* colour.RGB_to_YCbCr(<rgb color in 16 bit form>,
* K=colour.WEIGHTS_YCBCR["ITU-R BT.601"],
* in_bits = 16,
* in_legal = False,
* in_int = True,
* out_bits = 16,
* out_legal = False,
* out_int = True)
*
* Tests cases for color conversion generated by converting RGB
* values to YUV BT601 full range using the ITU-R BT.601 weights.
*/
{
.encoding = DRM_COLOR_YCBCR_BT601,
.range = DRM_COLOR_YCBCR_FULL_RANGE,
.n_colors = 6,
.colors = {
{ "white", { 0xffff, 0x8000, 0x8000 }, { 0xffff, 0xffff, 0xffff, 0xffff }},
{ "gray", { 0x8080, 0x8000, 0x8000 }, { 0xffff, 0x8080, 0x8080, 0x8080 }},
{ "black", { 0x0000, 0x8000, 0x8000 }, { 0xffff, 0x0000, 0x0000, 0x0000 }},
{ "red", { 0x4c8b, 0x54ce, 0xffff }, { 0xffff, 0xffff, 0x0000, 0x0000 }},
{ "green", { 0x9645, 0x2b33, 0x14d1 }, { 0xffff, 0x0000, 0xffff, 0x0000 }},
{ "blue", { 0x1d2f, 0xffff, 0x6b2f }, { 0xffff, 0x0000, 0x0000, 0xffff }},
}
},
/*
* colour.RGB_to_YCbCr(<rgb color in 16 bit form>,
* K=colour.WEIGHTS_YCBCR["ITU-R BT.601"],
* in_bits = 16,
* in_legal = False,
* in_int = True,
* out_bits = 16,
* out_legal = True,
* out_int = True)
* Tests cases for color conversion generated by converting RGB
* values to YUV BT601 limited range using the ITU-R BT.601 weights.
*/
{
.encoding = DRM_COLOR_YCBCR_BT601,
.range = DRM_COLOR_YCBCR_LIMITED_RANGE,
.n_colors = 6,
.colors = {
{ "white", { 0xeb00, 0x8000, 0x8000 }, { 0xffff, 0xffff, 0xffff, 0xffff }},
{ "gray", { 0x7dee, 0x8000, 0x8000 }, { 0xffff, 0x8080, 0x8080, 0x8080 }},
{ "black", { 0x1000, 0x8000, 0x8000 }, { 0xffff, 0x0000, 0x0000, 0x0000 }},
{ "red", { 0x517b, 0x5a34, 0xf000 }, { 0xffff, 0xffff, 0x0000, 0x0000 }},
{ "green", { 0x908e, 0x35cc, 0x2237 }, { 0xffff, 0x0000, 0xffff, 0x0000 }},
{ "blue", { 0x28f7, 0xf000, 0x6dc9 }, { 0xffff, 0x0000, 0x0000, 0xffff }},
}
},
/*
* colour.RGB_to_YCbCr(<rgb color in 16 bit form>,
* K=colour.WEIGHTS_YCBCR["ITU-R BT.709"],
* in_bits = 16,
* in_legal = False,
* in_int = True,
* out_bits = 16,
* out_legal = False,
* out_int = True)
* Tests cases for color conversion generated by converting RGB
* values to YUV BT709 full range using the ITU-R BT.709 weights.
*/
{
.encoding = DRM_COLOR_YCBCR_BT709,
.range = DRM_COLOR_YCBCR_FULL_RANGE,
.n_colors = 6,
.colors = {
{ "white", { 0xffff, 0x8000, 0x8000 }, { 0xffff, 0xffff, 0xffff, 0xffff }},
{ "gray", { 0x8080, 0x8000, 0x8000 }, { 0xffff, 0x8080, 0x8080, 0x8080 }},
{ "black", { 0x0000, 0x8000, 0x8000 }, { 0xffff, 0x0000, 0x0000, 0x0000 }},
{ "red", { 0x366d, 0x62ac, 0xffff }, { 0xffff, 0xffff, 0x0000, 0x0000 }},
{ "green", { 0xb717, 0x1d55, 0x0bbd }, { 0xffff, 0x0000, 0xffff, 0x0000 }},
{ "blue", { 0x127c, 0xffff, 0x7443 }, { 0xffff, 0x0000, 0x0000, 0xffff }},
}
},
/*
* colour.RGB_to_YCbCr(<rgb color in 16 bit form>,
* K=colour.WEIGHTS_YCBCR["ITU-R BT.709"],
* in_bits = 16,
* in_legal = False,
* in_int = True,
* out_bits = 16,
* out_legal = True,
* out_int = True)
* Tests cases for color conversion generated by converting RGB
* values to YUV BT709 limited range using the ITU-R BT.709 weights.
*/
{
.encoding = DRM_COLOR_YCBCR_BT709,
.range = DRM_COLOR_YCBCR_LIMITED_RANGE,
.n_colors = 6,
.colors = {
{ "white", { 0xeb00, 0x8000, 0x8000 }, { 0xffff, 0xffff, 0xffff, 0xffff }},
{ "gray", { 0x7dee, 0x8000, 0x8000 }, { 0xffff, 0x8080, 0x8080, 0x8080 }},
{ "black", { 0x1000, 0x8000, 0x8000 }, { 0xffff, 0x0000, 0x0000, 0x0000 }},
{ "red", { 0x3e8f, 0x6656, 0xf000 }, { 0xffff, 0xffff, 0x0000, 0x0000 }},
{ "green", { 0xaca1, 0x29aa, 0x1a45 }, { 0xffff, 0x0000, 0xffff, 0x0000 }},
{ "blue", { 0x1fd0, 0xf000, 0x75bb }, { 0xffff, 0x0000, 0x0000, 0xffff }},
}
},
/*
* colour.RGB_to_YCbCr(<rgb color in 16 bit form>,
* K=colour.WEIGHTS_YCBCR["ITU-R BT.2020"],
* in_bits = 16,
* in_legal = False,
* in_int = True,
* out_bits = 16,
* out_legal = False,
* out_int = True)
* Tests cases for color conversion generated by converting RGB
* values to YUV BT2020 full range using the ITU-R BT.2020 weights.
*/
{
.encoding = DRM_COLOR_YCBCR_BT2020,
.range = DRM_COLOR_YCBCR_FULL_RANGE,
.n_colors = 6,
.colors = {
{ "white", { 0xffff, 0x8000, 0x8000 }, { 0xffff, 0xffff, 0xffff, 0xffff }},
{ "gray", { 0x8080, 0x8000, 0x8000 }, { 0xffff, 0x8080, 0x8080, 0x8080 }},
{ "black", { 0x0000, 0x8000, 0x8000 }, { 0xffff, 0x0000, 0x0000, 0x0000 }},
{ "red", { 0x4340, 0x5c41, 0xffff }, { 0xffff, 0xffff, 0x0000, 0x0000 }},
{ "green", { 0xad91, 0x23bf, 0x0a4c }, { 0xffff, 0x0000, 0xffff, 0x0000 }},
{ "blue", { 0x0f2e, 0xffff, 0x75b5 }, { 0xffff, 0x0000, 0x0000, 0xffff }},
}
},
/*
* colour.RGB_to_YCbCr(<rgb color in 16 bit form>,
* K=colour.WEIGHTS_YCBCR["ITU-R BT.2020"],
* in_bits = 16,
* in_legal = False,
* in_int = True,
* out_bits = 16,
* out_legal = True,
* out_int = True)
* Tests cases for color conversion generated by converting RGB
* values to YUV BT2020 limited range using the ITU-R BT.2020 weights.
*/
{
.encoding = DRM_COLOR_YCBCR_BT2020,
.range = DRM_COLOR_YCBCR_LIMITED_RANGE,
.n_colors = 6,
.colors = {
{ "white", { 0xeb00, 0x8000, 0x8000 }, { 0xffff, 0xffff, 0xffff, 0xffff }},
{ "gray", { 0x7dee, 0x8000, 0x8000 }, { 0xffff, 0x8080, 0x8080, 0x8080 }},
{ "black", { 0x1000, 0x8000, 0x8000 }, { 0xffff, 0x0000, 0x0000, 0x0000 }},
{ "red", { 0x4988, 0x60b9, 0xf000 }, { 0xffff, 0xffff, 0x0000, 0x0000 }},
{ "green", { 0xa47b, 0x2f47, 0x1902 }, { 0xffff, 0x0000, 0xffff, 0x0000 }},
{ "blue", { 0x1cfd, 0xf000, 0x76fe }, { 0xffff, 0x0000, 0x0000, 0xffff }},
}
},
};
/*
* vkms_format_test_yuv_u16_to_argb_u16 - Testing the conversion between YUV
* colors to ARGB colors in VKMS
*
* This test will use the functions get_conversion_matrix_to_argb_u16 and
* argb_u16_from_yuv161616 to convert YUV colors (stored in
* yuv_u16_to_argb_u16_cases) into ARGB colors.
*
* The conversion between YUV and RGB is not totally reversible, so there may be
* some difference between the expected value and the result.
*/
static void vkms_format_test_yuv_u16_to_argb_u16(struct kunit *test)
{
const struct yuv_u16_to_argb_u16_case *param = test->param_value;
struct pixel_argb_u16 argb;
for (size_t i = 0; i < param->n_colors; i++) {
const struct format_pair *color = &param->colors[i];
struct conversion_matrix matrix;
get_conversion_matrix_to_argb_u16
(DRM_FORMAT_NV12, param->encoding, param->range, &matrix);
argb = argb_u16_from_yuv161616(&matrix, color->yuv.y, color->yuv.u,
color->yuv.v);
KUNIT_EXPECT_LE_MSG(test, abs_diff(argb.a, color->argb.a), 0x1ff,
"On the A channel of the color %s expected 0x%04x, got 0x%04x",
color->name, color->argb.a, argb.a);
KUNIT_EXPECT_LE_MSG(test, abs_diff(argb.r, color->argb.r), 0x1ff,
"On the R channel of the color %s expected 0x%04x, got 0x%04x",
color->name, color->argb.r, argb.r);
KUNIT_EXPECT_LE_MSG(test, abs_diff(argb.g, color->argb.g), 0x1ff,
"On the G channel of the color %s expected 0x%04x, got 0x%04x",
color->name, color->argb.g, argb.g);
KUNIT_EXPECT_LE_MSG(test, abs_diff(argb.b, color->argb.b), 0x1ff,
"On the B channel of the color %s expected 0x%04x, got 0x%04x",
color->name, color->argb.b, argb.b);
}
}
static void vkms_format_test_yuv_u16_to_argb_u16_case_desc(struct yuv_u16_to_argb_u16_case *t,
char *desc)
{
snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%s - %s",
drm_get_color_encoding_name(t->encoding), drm_get_color_range_name(t->range));
}
KUNIT_ARRAY_PARAM(yuv_u16_to_argb_u16, yuv_u16_to_argb_u16_cases,
vkms_format_test_yuv_u16_to_argb_u16_case_desc
);
static struct kunit_case vkms_format_test_cases[] = {
KUNIT_CASE_PARAM(vkms_format_test_yuv_u16_to_argb_u16, yuv_u16_to_argb_u16_gen_params),
{}
};
static struct kunit_suite vkms_format_test_suite = {
.name = "vkms-format",
.test_cases = vkms_format_test_cases,
};
kunit_test_suite(vkms_format_test_suite);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Kunit test for vkms format conversion");