Better tev preset table

This commit is contained in:
minjaesong
2025-08-27 17:45:37 +09:00
parent cda9a34b23
commit 6f7e407a1c
6 changed files with 189 additions and 133 deletions

View File

@@ -43,39 +43,39 @@ static inline float FCLAMP(float x, float min, float max) {
static const int MP2_RATE_TABLE[5] = {80, 128, 192, 224, 384};
static const int QUANT_MULT_Y[5] = {40, 10, 6, 4, 1};
static const int QUANT_MULT_X[5] = {40, 10, 6, 4, 1};
static const int QUANT_MULT_B[5] = {106, 22, 10, 5, 1}; // X[i] * sqrt(7 - 2i) - B channel aggressively quantized
static const int QUANT_MULT_B[5] = {80, 40, 20, 10, 2}; // B channel aggressively quantized
// only leave (4, 6, 7)
// Quality settings for quantisation (Y channel) - 16x16 tables
static const uint32_t QUANT_TABLE_Y[256] =
// Quality 7 (highest)
{2, 1, 1, 2, 3, 5, 6, 7, 6, 7, 8, 9, 10, 11, 12, 13,
1, 1, 1, 2, 3, 6, 7, 9, 7, 9, 10, 11, 12, 13, 14, 15,
1, 1, 2, 3, 5, 6, 7, 9, 7, 9, 10, 11, 12, 13, 14, 15,
1, 2, 3, 4, 6, 7, 9, 10, 9, 10, 11, 12, 13, 14, 15, 16,
2, 3, 5, 6, 7, 9, 10, 11, 10, 11, 12, 13, 14, 15, 16, 17,
3, 4, 6, 7, 9, 10, 11, 12, 11, 12, 13, 14, 15, 16, 17, 18,
6, 6, 7, 9, 10, 11, 12, 13, 12, 13, 14, 15, 16, 17, 18, 19,
6, 7, 9, 10, 11, 12, 13, 14, 13, 14, 15, 16, 17, 18, 19, 20,
6, 7, 9, 10, 11, 12, 13, 14, 13, 14, 15, 16, 17, 18, 19, 20,
7, 9, 10, 11, 12, 13, 14, 15, 14, 15, 16, 17, 18, 19, 20, 21,
9, 10, 11, 12, 13, 14, 15, 16, 15, 16, 17, 18, 19, 20, 21, 22,
10, 11, 12, 13, 14, 15, 16, 17, 16, 17, 18, 19, 20, 21, 22, 23,
11, 12, 13, 14, 15, 16, 17, 18, 17, 18, 19, 20, 21, 22, 23, 24,
12, 13, 14, 15, 16, 17, 18, 19, 18, 19, 20, 21, 22, 23, 24, 25,
13, 14, 15, 16, 17, 18, 19, 20, 19, 20, 21, 22, 23, 24, 25, 26,
14, 15, 16, 17, 18, 19, 20, 21, 20, 21, 22, 23, 24, 25, 26, 27};
{16, 14, 12, 11, 11, 13, 16, 20, 24, 30, 39, 48, 54, 61, 67, 73,
14, 13, 12, 12, 12, 15, 18, 21, 25, 33, 46, 57, 61, 65, 67, 70,
13, 12, 12, 13, 14, 17, 19, 23, 27, 36, 53, 66, 68, 69, 68, 67,
13, 13, 13, 14, 15, 18, 22, 26, 32, 41, 56, 67, 71, 74, 70, 67,
14, 14, 14, 15, 17, 20, 24, 30, 38, 47, 58, 68, 74, 79, 73, 67,
15, 15, 15, 17, 19, 22, 27, 34, 44, 55, 68, 79, 83, 85, 78, 70,
15, 16, 17, 20, 22, 26, 30, 38, 49, 63, 81, 94, 93, 91, 83, 74,
16, 18, 20, 24, 28, 33, 38, 47, 57, 73, 93, 108, 105, 101, 91, 81,
19, 21, 23, 29, 35, 43, 52, 60, 68, 83, 105, 121, 118, 115, 102, 89,
21, 24, 27, 35, 43, 53, 62, 70, 78, 91, 113, 128, 127, 125, 112, 99,
25, 30, 34, 43, 53, 61, 68, 76, 85, 97, 114, 127, 130, 132, 120, 108,
31, 38, 44, 54, 64, 71, 76, 84, 94, 105, 118, 129, 135, 138, 127, 116,
45, 52, 60, 69, 78, 84, 90, 97, 107, 118, 130, 139, 142, 143, 133, 122,
59, 68, 76, 84, 91, 97, 102, 110, 120, 129, 139, 147, 147, 146, 137, 127,
73, 82, 92, 98, 103, 107, 110, 117, 126, 132, 134, 136, 138, 138, 133, 127,
86, 98, 109, 112, 114, 116, 118, 124, 133, 135, 129, 125, 128, 130, 128, 127};
// Quality settings for quantisation (X channel - 8x8)
static const uint32_t QUANT_TABLE_C[64] =
{2, 3, 4, 6, 8, 12, 16, 20,
3, 4, 6, 8, 12, 16, 20, 24,
4, 6, 8, 12, 16, 20, 24, 28,
6, 8, 12, 16, 20, 24, 28, 32,
8, 12, 16, 20, 24, 28, 32, 36,
12, 16, 20, 24, 28, 32, 36, 40,
16, 20, 24, 28, 32, 36, 40, 44,
20, 24, 28, 32, 36, 40, 44, 48};
{17, 18, 24, 47, 99, 99, 99, 99,
18, 21, 26, 66, 99, 99, 99, 99,
24, 26, 56, 99, 99, 99, 99, 99,
47, 66, 99, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99};
// Audio constants (reuse MP2 from existing system)
@@ -239,9 +239,9 @@ static void rgb_to_xyb(uint8_t r, uint8_t g, uint8_t b, int *y, int *x, int *xyb
// Y: range 0 to 0.85, map to 0 to 255 (improved scale)
const double Y_MAX = 0.85;
*y = CLAMP((int)((y_val / Y_MAX) * 255.0), 0, 255);
// B: range 0 to 0.85, map to -128 to +127 (improved precision with +1 offset for yellow-green)
// B: range 0 to 0.85, map to -128 to +127 (optimized precision)
const double B_MAX = 0.85;
*xyb_b = CLAMP((int)(((b_val / B_MAX) * 255.0) - 128.0 + 1.0), -128, 127);
*xyb_b = CLAMP((int)(((b_val / B_MAX) * 255.0) - 128.0), -128, 127);
}
// XYB to RGB transform (for verification)
@@ -252,7 +252,7 @@ static void xyb_to_rgb(int y, int x, int xyb_b, uint8_t *r, uint8_t *g, uint8_t
const double Y_MAX = 0.85;
double y_val = (y / 255.0) * Y_MAX; // Y: inverse of improved scale
const double B_MAX = 0.85;
double b_val = (((xyb_b - 1.0) + 128.0) / 255.0) * B_MAX; // B: inverse of ((val/B_MAX*255)-128+1)
double b_val = ((xyb_b + 128.0) / 255.0) * B_MAX; // B: inverse of ((val/B_MAX*255)-128)
// Debug print for red color
if (x == 127 && y == 147 && xyb_b == 28) {