#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/errno.h>
+#include <linux/amlogic/media/vfm/vframe.h>
#include <linux/amlogic/media/amvecm/amvecm.h>
#include <linux/amlogic/media/amdolbyvision/dolby_vision.h>
#include "set_hdr2_v0.h"
0x146e, 0x1482
};
+int eo_y_lut_hdr_def[143] = {
+ 1032192, 1032192, 1032192, 1032192, 16384, 16384, 16384, 16384,
+ 32768, 32768, 32768, 32768, 40960, 40960, 40960, 49152, 49152,
+ 73728, 86016, 94208, 100352, 104448, 108544, 112640, 117760, 123904,
+ 128000, 133632, 137728, 141824, 146944, 150272, 153344, 157440,
+ 161536, 165248, 167808, 170880, 174208, 177792, 181056, 183360,
+ 185792, 188480, 191552, 194880, 197536, 199520, 201696, 204128,
+ 206688, 209568, 212640, 214480, 216336, 218320, 220464, 222832,
+ 225360, 228112, 230248, 231864, 233608, 235496, 237544, 239752,
+ 242136, 244712, 246628, 248132, 249748, 251492, 253364, 255388,
+ 257564, 259908, 262290, 263646, 265106, 266678, 268366, 270182,
+ 272134, 274230, 276486, 278717, 280017, 281415, 282915, 284525,
+ 286255, 288113, 290107, 292247, 294545, 295961, 297284, 298705,
+ 300229, 301866, 303622, 305507, 307530, 309701, 311664, 312915,
+ 314257, 315698, 317246, 318907, 320690, 322605, 324662, 326871,
+ 328461, 329735, 331104, 332575, 334155, 335853, 337679, 339642,
+ 341752, 344021, 345263, 346576, 347989, 349509, 351145, 352907,
+ 354805, 356848, 359050, 360935, 362214, 363593, 365080, 366684,
+ 368414, 370283, 372300, 374478, 376832
+};
+
static int num_eo_y_lut_hdr = 143;
int eo_y_lut_hdr[143] = {
1032192, 1032192, 1032192, 1032192, 16384, 16384, 16384, 16384,
};
static int num_oe_y_lut_sdr = 149;
-int oe_y_lut_sdr[149] = {0, 1, 1, 2, 2, 3, 5, 7, 9, 10, 11, 12, 12, 13,
- 15, 16, 16, 18, 20, 21, 22, 24, 26, 28, 30, 33, 35, 38, 40, 44, 47,
- 50, 53, 59, 63, 67, 71, 78, 85, 90, 95, 105, 113, 121, 127, 134, 140,
- 146, 151, 156, 161, 166, 170, 179, 187, 195, 202, 209, 215, 222, 228,
- 239, 250, 260, 270, 279, 287, 296, 304, 319, 334, 347, 360, 372, 384,
- 395, 406, 426, 445, 464, 481, 497, 513, 528, 542, 569, 595, 619, 642,
- 664, 684, 704, 724, 760, 794, 826, 857, 886, 914, 940, 966, 1015, 1060,
- 1103, 1144, 1183, 1220, 1255, 1290, 1355, 1415, 1473, 1527, 1579, 1628,
- 1676, 1722, 1808, 1889, 1966, 2039, 2108, 2174, 2237, 2298, 2414, 2522,
- 2624, 2721, 2814, 2902, 2987, 3068, 3147, 3222, 3296, 3367, 3436, 3503,
- 3569, 3633, 3695, 3756, 3816, 3874, 3931, 3987, 4042, 4095
+int oe_y_lut_sdr[149] = {
+ 0, 0, 0, 1, 1, 2, 2, 4, 5, 6, 6, 7, 7, 8, 9, 9, 10, 11, 12, 13,
+ 14, 15, 16, 18, 19, 21, 23, 24, 26, 29, 31, 34, 36, 40, 43, 46,
+ 49, 55, 59, 64, 68, 75, 81, 87, 93, 98, 103, 107, 112, 116, 120,
+ 124, 128, 135, 141, 147, 153, 159, 165, 170, 175, 185, 194, 202,
+ 210, 218, 226, 233, 240, 253, 266, 277, 289, 299, 309, 319, 329,
+ 347, 364, 380, 396, 410, 424, 438, 451, 476, 499, 521, 542, 562,
+ 582, 600, 618, 652, 684, 714, 743, 771, 797, 823, 847, 894, 938,
+ 979, 1019, 1056, 1093, 1127, 1161, 1225, 1285, 1342, 1396, 1448,
+ 1497, 1545, 1591, 1679, 1761, 1839, 1913, 1984, 2052, 2118, 2181,
+ 2301, 2414, 2520, 2622, 2719, 2812, 2902, 2989, 3072, 3153, 3231,
+ 3308, 3382, 3454, 3525, 3593, 3661, 3727, 3791, 3854, 3916, 3977,
+ 4037, 4095
};
module_param_array(oe_y_lut_sdr, int, &num_oe_y_lut_sdr, 0664);
MODULE_PARM_DESC(oe_y_lut_sdr, "\n eo_y_lut_hdr\n");
152, 149, 145, 142, 139, 136, 133, 130, 128
};
+int oo_y_lut_hdr_sdr_def[149] = {
+ 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200,
+ 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200,
+ 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200,
+ 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200,
+ 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200,
+ 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200,
+ 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200,
+ 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200,
+ 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200,
+ 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3034, 2830, 2653,
+ 2498, 2240, 2033, 1864, 1722, 1603, 1500, 1411, 1332, 1202,
+ 1097, 1011, 939, 878, 825, 779, 739, 671, 616, 570,
+ 531, 498, 469, 443, 420, 381, 349, 322, 299, 279,
+ 262, 246, 233, 221, 210, 201, 192, 184, 177, 170,
+ 164, 158, 153, 148, 143, 139, 135, 131, 128
+};
+
static int num_hdr_sdr_lut = 149;
int oo_y_lut_hdr_sdr[149] = {
3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200,
509, 509, 509, 510, 510, 511, 511, 511, 512
};
+static int eo_y_hdr_10000[143] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 7, 7,
+ 8, 9, 10, 11, 12, 14, 15, 17, 18, 20, 22, 24, 26,
+ 29, 31, 34, 37, 41, 44, 48, 52, 57, 62, 67, 72, 78,
+ 85, 92, 99, 107, 116, 125, 135, 146, 158, 170, 183,
+ 198, 213, 229, 247, 266, 287, 309, 332, 357, 384, 413,
+ 445, 478, 514, 553, 594, 639, 686, 737, 792, 851, 915,
+ 983, 1056, 1134, 1219, 1309, 1406, 1511, 1623, 1744,
+ 1873, 2012, 2162, 2323, 2496, 2683, 2883, 3098, 3330,
+ 3580, 3849, 4138, 4450, 4786, 5148, 5539, 5959, 6413,
+ 6903, 7431, 8001, 8616, 9281, 10000
+};
+
+static int oo_y_hdr_sdr_10000[149] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 6, 6, 7,
+ 7, 8, 9, 9, 10, 12, 13, 14, 15, 17, 18, 19, 21, 24, 26,
+ 29, 31, 34, 36, 39, 43, 48, 53, 58, 63, 68, 73, 78, 87,
+ 97, 107, 117, 126, 136, 146, 156, 175, 195, 214, 234, 253,
+ 273, 292, 312, 351, 390, 429, 468, 507, 546, 585, 625, 703,
+ 781, 859, 937, 1015, 1093, 1171, 1250, 1406, 1562, 1718,
+ 1875, 2031, 2187, 2343, 2500, 2812, 3125, 3437, 3750, 4062,
+ 4375, 4687, 5000, 5312, 5625, 5937, 6250, 6562, 6875, 7187,
+ 7500, 7812, 8125, 8437, 8750, 9062, 9375, 9687, 10000
+};
+
+unsigned int hdr10_pr;
+unsigned int hdr10_clip_disable;
+unsigned int hdr10_force_clip;
+unsigned int hdr10_clip_luma;
+/*margin: margin / 10*/
+unsigned int hdr10_clip_margin = 2;
+/*clip mode: 0->eo clip, 1->oo clip*/
+unsigned int hdr10_clip_mode;
#else //HDR2_MODULE
int64_t FloatRev(int64_t ia)
{
int gamut_bypass_8bit[9] = {
256, 0, 0, 0, 256, 0, 0, 0, 256};
+/* standard2020->709-d65 8bit*/
+int ncl_2020_709_8bit[9] = {
+ 425, -150, -18, -31, 290, -2, -4, -25, 286
+};
+
/*for iptv special primary->709rgb*/
int ncl_sp_709[9] = {
2684, -489, -147, -201, 2266, -17, -29, -171, 2248};
return ret;
}
+void hdr_highclip_by_luma(
+ struct vframe_master_display_colour_s *master_info)
+{
+ unsigned int clip_index;
+ unsigned int max_luma;
+ int i;
+
+ if (hdr10_clip_disable) {
+ if (hdr10_pr & 0x1)
+ pr_info("clip_disable = %d\n", hdr10_clip_disable);
+ return;
+ }
+
+ if (hdr10_force_clip) {
+ for (i = HDR2_EOTF_LUT_SIZE - 1; i >= 0; i--) {
+ if (eo_y_hdr_10000[i] < hdr10_clip_luma) {
+ clip_index = i + 1;
+ break;
+ }
+ clip_index = HDR2_EOTF_LUT_SIZE - 1;
+ }
+ if (clip_index > HDR2_EOTF_LUT_SIZE - 1)
+ clip_index = HDR2_EOTF_LUT_SIZE - 1;
+
+ for (i = clip_index; i < HDR2_EOTF_LUT_SIZE; i++)
+ eo_y_lut_hdr[i] = eo_y_lut_hdr[clip_index];
+ return;
+ }
+
+ if (master_info->luminance[0] > 10000)
+ master_info->luminance[0] /= 10000;
+
+ /*invalid luminance*/
+ if (master_info->luminance[0] < 100)
+ master_info->luminance[0] = 0;
+
+ max_luma = master_info->luminance[0] +
+ (master_info->luminance[0] * hdr10_clip_margin) / 10;
+
+ if (max_luma > 10000)
+ max_luma = 10000;
+
+ if (hdr10_clip_mode == 1) {
+ for (i = HDR2_EOTF_LUT_SIZE - 1; i >= 0; i--) {
+ if ((master_info->luminance[0] == 0) ||
+ (master_info->present_flag == 0)) {
+ /*default 1000 luminance*/
+ if (oo_y_hdr_sdr_10000[i] < 1200) {
+ clip_index = i + 1;
+ break;
+ }
+ }
+
+ if (oo_y_hdr_sdr_10000[i] < max_luma) {
+ clip_index = i + 1;
+ break;
+ }
+
+ clip_index = HDR2_OOTF_LUT_SIZE - 1;
+ }
+
+ if (clip_index > HDR2_OOTF_LUT_SIZE - 1)
+ clip_index = HDR2_OOTF_LUT_SIZE - 1;
+ for (i = 0; i < HDR2_OOTF_LUT_SIZE; i++) {
+ if (i < clip_index)
+ oo_y_lut_hdr_sdr[i] = oo_y_lut_hdr_sdr_def[i];
+ if (i >= clip_index)
+ oo_y_lut_hdr_sdr[i] =
+ oo_y_lut_hdr_sdr_def[clip_index];
+ }
+
+ if (hdr10_pr & 0x1) {
+ pr_info("luma=%d,oo_lut[%d]=%d,clip_margin=%d\n",
+ master_info->luminance[0], clip_index,
+ oo_y_lut_hdr_sdr[clip_index],
+ hdr10_clip_margin);
+ if (hdr10_clip_luma)
+ pr_info("clip_luma = %d\n", hdr10_clip_luma);
+ }
+
+ return;
+ }
+
+ for (i = HDR2_EOTF_LUT_SIZE - 1; i >= 0; i--) {
+ if ((master_info->luminance[0] == 0) ||
+ (master_info->present_flag == 0)) {
+ /*default 1000 luminance*/
+ if (eo_y_hdr_10000[i] < 1200) {
+ clip_index = i + 1;
+ break;
+ }
+ }
+
+ if (eo_y_hdr_10000[i] < max_luma) {
+ clip_index = i + 1;
+ break;
+ }
+
+ clip_index = HDR2_EOTF_LUT_SIZE - 1;
+ }
+
+ if (clip_index > HDR2_EOTF_LUT_SIZE - 1)
+ clip_index = HDR2_EOTF_LUT_SIZE - 1;
+ for (i = 0; i < HDR2_EOTF_LUT_SIZE; i++) {
+ if (i < clip_index)
+ eo_y_lut_hdr[i] = eo_y_lut_hdr_def[i];
+ if (i >= clip_index)
+ eo_y_lut_hdr[i] = eo_y_lut_hdr_def[clip_index];
+ }
+
+ if (hdr10_pr & 0x1) {
+ pr_info("luma=%d,eo_lut[%d]=%d,clip_margin=%d\n",
+ master_info->luminance[0], clip_index,
+ eo_y_lut_hdr[clip_index], hdr10_clip_margin);
+ if (hdr10_clip_luma)
+ pr_info("clip_luma = %d\n", hdr10_clip_luma);
+ }
+}
+
/*in/out matrix*/
void set_hdr_matrix(
enum hdr_module_sel module_sel,
ncl_2020_709[i];
} else {
hdr_mtx_param.mtx_gamut[i] =
- ncl_2020_p3[i]; /* 1.0 = 256 */
+ ncl_2020_709_8bit[i];
}
}
}