more lazy q table prep

This commit is contained in:
minjaesong
2025-08-23 20:12:35 +09:00
parent 6f6d10cc1b
commit f1dab59495
2 changed files with 59 additions and 595 deletions

View File

@@ -33,127 +33,12 @@ static inline int CLAMP(int x, int min, int max) {
return x < min ? min : (x > max ? max : x);
}
static const int QUANT_MULT_Y[8] = {40, 20, 10, 8, 6, 5, 4, 1};
static const int QUANT_MULT_CO[8] = {40, 20, 10, 8, 6, 5, 4, 1};
static const int QUANT_MULT_CG[8] = {80, 40, 20, 16, 12, 10, 8, 2};
// Quality settings for quantization (Y channel) - 16x16 tables
static const uint8_t QUANT_TABLES_Y[8][256] = {
// Quality 0 (lowest) - 16x16 table
{80, 60, 50, 80, 120, 200, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
55, 60, 70, 95, 130, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
70, 65, 80, 120, 200, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
70, 85, 110, 145, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
90, 110, 185, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
120, 175, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
245, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
// Quality 1
{40, 30, 25, 40, 60, 100, 128, 150, 128, 150, 180, 200, 220, 240, 250, 255,
28, 30, 35, 48, 65, 128, 150, 180, 150, 180, 200, 220, 240, 250, 255, 255,
35, 33, 40, 60, 100, 128, 150, 180, 150, 180, 200, 220, 240, 250, 255, 255,
35, 43, 55, 73, 128, 150, 180, 200, 180, 200, 220, 240, 250, 255, 255, 255,
45, 55, 93, 128, 150, 180, 200, 220, 200, 220, 240, 250, 255, 255, 255, 255,
60, 88, 128, 150, 180, 200, 220, 240, 220, 240, 250, 255, 255, 255, 255, 255,
123, 128, 150, 180, 200, 220, 240, 250, 240, 250, 255, 255, 255, 255, 255, 255,
128, 150, 180, 200, 220, 240, 250, 255, 250, 255, 255, 255, 255, 255, 255, 255,
128, 150, 180, 200, 220, 240, 250, 255, 250, 255, 255, 255, 255, 255, 255, 255,
150, 180, 200, 220, 240, 250, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
180, 200, 220, 240, 250, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
200, 220, 240, 250, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
220, 240, 250, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
240, 250, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
250, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
// Quality 2
{20, 15, 13, 20, 30, 50, 64, 75, 64, 75, 90, 100, 110, 120, 125, 128,
14, 15, 18, 24, 33, 64, 75, 90, 75, 90, 100, 110, 120, 125, 128, 140,
18, 17, 20, 30, 50, 64, 75, 90, 75, 90, 100, 110, 120, 125, 128, 140,
18, 22, 28, 37, 64, 75, 90, 100, 90, 100, 110, 120, 125, 128, 140, 150,
23, 28, 47, 64, 75, 90, 100, 110, 100, 110, 120, 125, 128, 140, 150, 160,
30, 44, 64, 75, 90, 100, 110, 120, 110, 120, 125, 128, 140, 150, 160, 170,
62, 64, 75, 90, 100, 110, 120, 125, 120, 125, 128, 140, 150, 160, 170, 180,
64, 75, 90, 100, 110, 120, 125, 128, 125, 128, 140, 150, 160, 170, 180, 190,
64, 75, 90, 100, 110, 120, 125, 128, 125, 128, 140, 150, 160, 170, 180, 190,
75, 90, 100, 110, 120, 125, 128, 140, 128, 140, 150, 160, 170, 180, 190, 200,
90, 100, 110, 120, 125, 128, 140, 150, 140, 150, 160, 170, 180, 190, 200, 210,
100, 110, 120, 125, 128, 140, 150, 160, 150, 160, 170, 180, 190, 200, 210, 220,
110, 120, 125, 128, 140, 150, 160, 170, 160, 170, 180, 190, 200, 210, 220, 230,
120, 125, 128, 140, 150, 160, 170, 180, 170, 180, 190, 200, 210, 220, 230, 240,
125, 128, 140, 150, 160, 170, 180, 190, 180, 190, 200, 210, 220, 230, 240, 250,
128, 140, 150, 160, 170, 180, 190, 200, 190, 200, 210, 220, 230, 240, 250, 255},
// Quality 3
{16, 12, 10, 16, 24, 40, 51, 60, 51, 60, 72, 80, 88, 96, 100, 102,
11, 12, 14, 19, 26, 51, 60, 72, 60, 72, 80, 88, 96, 100, 102, 110,
14, 13, 16, 24, 40, 51, 60, 72, 60, 72, 80, 88, 96, 100, 102, 110,
14, 17, 22, 29, 51, 60, 72, 80, 72, 80, 88, 96, 100, 102, 110, 120,
18, 22, 37, 51, 60, 72, 80, 88, 80, 88, 96, 100, 102, 110, 120, 130,
24, 35, 51, 60, 72, 80, 88, 96, 88, 96, 100, 102, 110, 120, 130, 140,
49, 51, 60, 72, 80, 88, 96, 100, 96, 100, 102, 110, 120, 130, 140, 150,
51, 60, 72, 80, 88, 96, 100, 102, 100, 102, 110, 120, 130, 140, 150, 160,
51, 60, 72, 80, 88, 96, 100, 102, 100, 102, 110, 120, 130, 140, 150, 160,
60, 72, 80, 88, 96, 100, 102, 110, 102, 110, 120, 130, 140, 150, 160, 170,
72, 80, 88, 96, 100, 102, 110, 120, 110, 120, 130, 140, 150, 160, 170, 180,
80, 88, 96, 100, 102, 110, 120, 130, 120, 130, 140, 150, 160, 170, 180, 190,
88, 96, 100, 102, 110, 120, 130, 140, 130, 140, 150, 160, 170, 180, 190, 200,
96, 100, 102, 110, 120, 130, 140, 150, 140, 150, 160, 170, 180, 190, 200, 210,
100, 102, 110, 120, 130, 140, 150, 160, 150, 160, 170, 180, 190, 200, 210, 220,
102, 110, 120, 130, 140, 150, 160, 170, 160, 170, 180, 190, 200, 210, 220, 230},
// Quality 4
{12, 9, 8, 12, 18, 30, 38, 45, 38, 45, 54, 60, 66, 72, 75, 77,
8, 9, 11, 14, 20, 38, 45, 54, 45, 54, 60, 66, 72, 75, 77, 85,
11, 10, 12, 18, 30, 38, 45, 54, 45, 54, 60, 66, 72, 75, 77, 85,
11, 13, 17, 22, 38, 45, 54, 60, 54, 60, 66, 72, 75, 77, 85, 95,
14, 17, 28, 38, 45, 54, 60, 66, 60, 66, 72, 75, 77, 85, 95, 105,
18, 26, 38, 45, 54, 60, 66, 72, 66, 72, 75, 77, 85, 95, 105, 115,
37, 38, 45, 54, 60, 66, 72, 75, 72, 75, 77, 85, 95, 105, 115, 125,
38, 45, 54, 60, 66, 72, 75, 77, 75, 77, 85, 95, 105, 115, 125, 135,
38, 45, 54, 60, 66, 72, 75, 77, 75, 77, 85, 95, 105, 115, 125, 135,
45, 54, 60, 66, 72, 75, 77, 85, 77, 85, 95, 105, 115, 125, 135, 145,
54, 60, 66, 72, 75, 77, 85, 95, 85, 95, 105, 115, 125, 135, 145, 155,
60, 66, 72, 75, 77, 85, 95, 105, 95, 105, 115, 125, 135, 145, 155, 165,
66, 72, 75, 77, 85, 95, 105, 115, 105, 115, 125, 135, 145, 155, 165, 175,
72, 75, 77, 85, 95, 105, 115, 125, 115, 125, 135, 145, 155, 165, 175, 185,
75, 77, 85, 95, 105, 115, 125, 135, 125, 135, 145, 155, 165, 175, 185, 195,
77, 85, 95, 105, 115, 125, 135, 145, 135, 145, 155, 165, 175, 185, 195, 205},
// Quality 5
{10, 7, 6, 10, 15, 25, 32, 38, 32, 38, 45, 50, 55, 60, 63, 65,
7, 7, 9, 12, 16, 32, 38, 45, 38, 45, 50, 55, 60, 63, 65, 70,
9, 8, 10, 15, 25, 32, 38, 45, 38, 45, 50, 55, 60, 63, 65, 70,
9, 11, 14, 18, 32, 38, 45, 50, 45, 50, 55, 60, 63, 65, 70, 75,
12, 14, 23, 32, 38, 45, 50, 55, 50, 55, 60, 63, 65, 70, 75, 80,
15, 22, 32, 38, 45, 50, 55, 60, 55, 60, 63, 65, 70, 75, 80, 85,
31, 32, 38, 45, 50, 55, 60, 63, 60, 63, 65, 70, 75, 80, 85, 90,
32, 38, 45, 50, 55, 60, 63, 65, 63, 65, 70, 75, 80, 85, 90, 95,
32, 38, 45, 50, 55, 60, 63, 65, 63, 65, 70, 75, 80, 85, 90, 95,
38, 45, 50, 55, 60, 63, 65, 70, 65, 70, 75, 80, 85, 90, 95, 100,
45, 50, 55, 60, 63, 65, 70, 75, 70, 75, 80, 85, 90, 95, 100, 105,
50, 55, 60, 63, 65, 70, 75, 80, 75, 80, 85, 90, 95, 100, 105, 110,
55, 60, 63, 65, 70, 75, 80, 85, 80, 85, 90, 95, 100, 105, 110, 115,
60, 63, 65, 70, 75, 80, 85, 90, 85, 90, 95, 100, 105, 110, 115, 120,
63, 65, 70, 75, 80, 85, 90, 95, 90, 95, 100, 105, 110, 115, 120, 125,
65, 70, 75, 80, 85, 90, 95, 100, 95, 100, 105, 110, 115, 120, 125, 130},
// Quality 6
{8, 6, 5, 8, 12, 20, 26, 30, 26, 30, 36, 40, 44, 48, 50, 52,
6, 6, 7, 10, 13, 26, 30, 36, 30, 36, 40, 44, 48, 50, 52, 56,
7, 7, 8, 12, 20, 26, 30, 36, 30, 36, 40, 44, 48, 50, 52, 56,
7, 9, 11, 15, 26, 30, 36, 40, 36, 40, 44, 48, 50, 52, 56, 60,
10, 11, 19, 26, 30, 36, 40, 44, 40, 44, 48, 50, 52, 56, 60, 64,
12, 17, 26, 30, 36, 40, 44, 48, 44, 48, 50, 52, 56, 60, 64, 68,
25, 26, 30, 36, 40, 44, 48, 50, 48, 50, 52, 56, 60, 64, 68, 72,
26, 30, 36, 40, 44, 48, 50, 52, 50, 52, 56, 60, 64, 68, 72, 76,
26, 30, 36, 40, 44, 48, 50, 52, 50, 52, 56, 60, 64, 68, 72, 76,
30, 36, 40, 44, 48, 50, 52, 56, 52, 56, 60, 64, 68, 72, 76, 80,
36, 40, 44, 48, 50, 52, 56, 60, 56, 60, 64, 68, 72, 76, 80, 84,
40, 44, 48, 50, 52, 56, 60, 64, 60, 64, 68, 72, 76, 80, 84, 88,
44, 48, 50, 52, 56, 60, 64, 68, 64, 68, 72, 76, 80, 84, 88, 92,
48, 50, 52, 56, 60, 64, 68, 72, 68, 72, 76, 80, 84, 88, 92, 96,
50, 52, 56, 60, 64, 68, 72, 76, 72, 76, 80, 84, 88, 92, 96, 100,
52, 56, 60, 64, 68, 72, 76, 80, 76, 80, 84, 88, 92, 96, 100, 104},
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,
@@ -170,153 +55,10 @@ static const uint8_t QUANT_TABLES_Y[8][256] = {
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}
};
14, 15, 16, 17, 18, 19, 20, 21, 20, 21, 22, 23, 24, 25, 26, 27};
// Quality settings for quantization (Co channel - 8x8)
static const uint8_t QUANT_TABLES_CO[8][64] = {
// Quality 0 (lowest) - 2x more aggressive than before
{240, 180, 150, 240, 255, 255, 255, 255,
166, 180, 210, 255, 255, 255, 255, 255,
210, 196, 240, 255, 255, 255, 255, 255,
210, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255},
// Quality 1 - 1.8x more aggressive
{108, 81, 68, 108, 162, 255, 255, 255,
76, 81, 95, 130, 176, 255, 255, 255,
95, 88, 108, 162, 255, 255, 255, 255,
95, 115, 149, 196, 255, 255, 255, 255,
122, 149, 250, 255, 255, 255, 255, 255,
162, 238, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255},
// Quality 2 - 1.7x more aggressive
{51, 39, 32, 51, 77, 128, 163, 192,
36, 39, 46, 61, 83, 163, 192, 230,
46, 43, 51, 77, 128, 163, 192, 230,
46, 54, 71, 94, 163, 192, 230, 255,
58, 71, 119, 163, 192, 230, 255, 255,
77, 112, 163, 192, 230, 255, 255, 255,
158, 163, 192, 230, 255, 255, 255, 255,
163, 192, 230, 255, 255, 255, 255, 255},
// Quality 3 - 1.6x more aggressive
{38, 29, 24, 38, 58, 96, 123, 144,
27, 29, 34, 46, 62, 123, 144, 173,
34, 32, 38, 58, 96, 123, 144, 173,
34, 42, 53, 70, 123, 144, 173, 192,
43, 53, 90, 123, 144, 173, 192, 211,
58, 85, 123, 144, 173, 192, 211, 230,
118, 123, 144, 173, 192, 211, 230, 240,
123, 144, 173, 192, 211, 230, 240, 246},
// Quality 4 - 1.5x more aggressive
{27, 21, 18, 27, 41, 68, 86, 102,
20, 21, 24, 33, 45, 86, 102, 122,
24, 23, 27, 41, 68, 86, 102, 122,
24, 30, 38, 50, 86, 102, 122, 135,
30, 38, 63, 86, 102, 122, 135, 149,
41, 59, 86, 102, 122, 135, 149, 162,
84, 86, 102, 122, 135, 149, 162, 170,
86, 102, 122, 135, 149, 162, 170, 174},
// Quality 5 - 1.4x more aggressive
{21, 15, 13, 21, 32, 53, 67, 80,
15, 15, 18, 25, 34, 67, 80, 95,
18, 17, 21, 32, 53, 67, 80, 95,
18, 22, 29, 39, 67, 80, 95, 105,
24, 29, 49, 67, 80, 95, 105, 116,
32, 46, 67, 80, 95, 105, 116, 126,
64, 67, 80, 95, 105, 116, 126, 132,
67, 80, 95, 105, 116, 126, 132, 134},
// Quality 6 - 1.3x more aggressive
{16, 12, 10, 16, 23, 39, 51, 59,
12, 12, 14, 18, 26, 51, 59, 70,
14, 13, 16, 23, 39, 51, 59, 70,
14, 17, 22, 29, 51, 59, 70, 78,
18, 22, 36, 51, 59, 70, 78, 86,
23, 34, 51, 59, 70, 78, 86, 94,
49, 51, 59, 70, 78, 86, 94, 98,
51, 59, 70, 78, 86, 94, 98, 100},
// Quality 7 (highest) - 1.2x more aggressive for subtle improvement
{1, 1, 1, 1, 1, 2, 2, 4,
1, 1, 1, 1, 2, 3, 4, 5,
1, 1, 1, 2, 3, 4, 5, 6,
1, 1, 2, 3, 4, 5, 6, 7,
1, 2, 3, 4, 5, 6, 7, 8,
2, 3, 4, 5, 6, 7, 8, 10,
3, 4, 5, 6, 7, 8, 10, 11,
4, 5, 6, 7, 8, 10, 11, 12}
};
// Quality settings for quantization (Cg channel - 8x8, much more aggressive than Co)
// Similar to NTSC Q channel reduction - exploit reduced human sensitivity to green-magenta
// Now using 3x-5x more aggressive quantization, similar to actual NTSC Q bandwidth reduction
static const uint8_t QUANT_TABLES_CG[8][64] = {
// Quality 0 (lowest) - 5x more aggressive than Co, maximum compression
{255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255},
// Quality 1 - 4.5x more aggressive, very low bandwidth
{255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255},
// Quality 2 - 4x more aggressive, preserve only DC and very low frequencies
{120, 180, 240, 255, 255, 255, 255, 255,
180, 240, 255, 255, 255, 255, 255, 255,
240, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255},
// Quality 3 - 3.5x more aggressive, basic low frequency preservation
{84, 108, 144, 192, 255, 255, 255, 255,
108, 144, 192, 255, 255, 255, 255, 255,
144, 192, 255, 255, 255, 255, 255, 255,
192, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255},
// Quality 4 - 3x more aggressive, moderate compression
{54, 72, 96, 128, 180, 255, 255, 255,
72, 96, 128, 180, 255, 255, 255, 255,
96, 128, 180, 255, 255, 255, 255, 255,
128, 180, 255, 255, 255, 255, 255, 255,
180, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255},
// Quality 5 - 2.8x more aggressive, balanced compression
{42, 56, 75, 100, 140, 200, 255, 255,
56, 75, 100, 140, 200, 255, 255, 255,
75, 100, 140, 200, 255, 255, 255, 255,
100, 140, 200, 255, 255, 255, 255, 255,
140, 200, 255, 255, 255, 255, 255, 255,
200, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255},
// Quality 6 - 2.5x more aggressive, good quality but still compressed
{30, 40, 54, 72, 100, 144, 200, 255,
40, 54, 72, 100, 144, 200, 255, 255,
54, 72, 100, 144, 200, 255, 255, 255,
72, 100, 144, 200, 255, 255, 255, 255,
100, 144, 200, 255, 255, 255, 255, 255,
144, 200, 255, 255, 255, 255, 255, 255,
200, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255},
// Quality 7 (highest) - 2x more aggressive, preserve more detail
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,
@@ -324,8 +66,8 @@ static const uint8_t QUANT_TABLES_CG[8][64] = {
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}
};
20, 24, 28, 32, 36, 40, 44, 48};
// Audio constants (reuse MP2 from existing system)
#define MP2_SAMPLE_RATE 32000
@@ -959,31 +701,34 @@ static void encode_block(tev_encoder_t *enc, int block_x, int block_y, int is_ke
}
}
// Apply fast DCT transform - 8x performance improvement
// Apply fast DCT transform
dct_16x16_fast(enc->y_workspace, enc->dct_workspace);
// Quantize Y coefficients (luma)
const uint8_t *y_quant = QUANT_TABLES_Y[enc->quality];
const uint32_t *y_quant = QUANT_TABLE_Y;
const uint32_t qmult_y = QUANT_MULT_Y[enc->quality];
for (int i = 0; i < 256; i++) {
block->y_coeffs[i] = quantize_coeff(enc->dct_workspace[i], y_quant[i], i == 0, 0);
block->y_coeffs[i] = quantize_coeff(enc->dct_workspace[i], y_quant[i] * qmult_y, i == 0, 0);
}
// Apply fast DCT transform to chroma - 4x performance improvement
// Apply fast DCT transform to chroma
dct_8x8_fast(enc->co_workspace, enc->dct_workspace);
// Quantize Co coefficients (chroma - orange-blue)
const uint8_t *co_quant = QUANT_TABLES_CO[enc->quality];
const uint32_t *co_quant = QUANT_TABLE_C;
const uint32_t qmult_co = QUANT_MULT_CO[enc->quality];
for (int i = 0; i < 64; i++) {
block->co_coeffs[i] = quantize_coeff(enc->dct_workspace[i], co_quant[i], i == 0, 1);
block->co_coeffs[i] = quantize_coeff(enc->dct_workspace[i], co_quant[i] * qmult_co, i == 0, 1);
}
// Apply fast DCT transform to Cg - 4x performance improvement
// Apply fast DCT transform to Cg
dct_8x8_fast(enc->cg_workspace, enc->dct_workspace);
// Quantize Cg coefficients (chroma - green-magenta, more aggressive like NTSC Q)
const uint8_t *cg_quant = QUANT_TABLES_CG[enc->quality];
// Quantize Cg coefficients (chroma - green-magenta, qmult_cg is more aggressive like NTSC Q)
const uint32_t *cg_quant = QUANT_TABLE_C;
const uint32_t qmult_cg = QUANT_MULT_CG[enc->quality];
for (int i = 0; i < 64; i++) {
block->cg_coeffs[i] = quantize_coeff(enc->dct_workspace[i], cg_quant[i], i == 0, 1);
block->cg_coeffs[i] = quantize_coeff(enc->dct_workspace[i], cg_quant[i] * qmult_cg, i == 0, 1);
}
// Set CBP (simplified - always encode all channels)