-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rtpdec_jpeg: compute Q tables for 0-127
code taken directly from RFC 2435 text
- Loading branch information
1 parent
835a7c0
commit 0d3f3c8
Showing
1 changed file
with
66 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,7 @@ | |
* @author Martin Pulec <[email protected]> | ||
* | ||
* @todo | ||
* * handle predefined (0-127) quantization tables | ||
* * handle precision=1 (?) | ||
* * error meesage for zero-len quantization tables | ||
*/ | ||
/* | ||
* Copyright (c) 2024 CESNET | ||
|
@@ -191,6 +189,65 @@ skip_jpeg_headers(unsigned char **pckt_data) | |
} | ||
} | ||
|
||
/* | ||
* Table K.1 from JPEG spec. | ||
*/ | ||
static const int jpeg_luma_quantizer[64] = { | ||
16, 11, 10, 16, 24, 40, 51, 61, | ||
12, 12, 14, 19, 26, 58, 60, 55, | ||
14, 13, 16, 24, 40, 57, 69, 56, | ||
14, 17, 22, 29, 51, 87, 80, 62, | ||
18, 22, 37, 56, 68, 109, 103, 77, | ||
24, 35, 55, 64, 81, 104, 113, 92, | ||
49, 64, 78, 87, 103, 121, 120, 101, | ||
72, 92, 95, 98, 112, 100, 103, 99 | ||
}; | ||
|
||
/* | ||
* Table K.2 from JPEG spec. | ||
*/ | ||
static const int jpeg_chroma_quantizer[64] = { | ||
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 | ||
}; | ||
|
||
/* | ||
* Call MakeTables with the Q factor and two u_char[64] return arrays | ||
*/ | ||
static void | ||
MakeTables(int q, u_char *lqt, u_char *cqt) | ||
{ | ||
int i; | ||
int factor = q; | ||
|
||
if (q < 1) factor = 1; | ||
if (q > 99) factor = 99; | ||
if (q < 50) | ||
q = 5000 / factor; | ||
else | ||
q = 200 - factor*2; | ||
|
||
for (i=0; i < 64; i++) { | ||
int lq = (jpeg_luma_quantizer[i] * q + 50) / 100; | ||
int cq = (jpeg_chroma_quantizer[i] * q + 50) / 100; | ||
|
||
/* Limit the quantizers to 1 <= q <= 255 */ | ||
if (lq < 1) lq = 1; | ||
else if (lq > 255) lq = 255; | ||
lqt[i] = lq; | ||
|
||
if (cq < 1) cq = 1; | ||
else if (cq > 255) cq = 255; | ||
cqt[i] = cq; | ||
} | ||
} | ||
|
||
int | ||
decode_frame_jpeg(struct coded_data *cdata, void *decode_data) | ||
{ | ||
|
@@ -236,6 +293,13 @@ decode_frame_jpeg(struct coded_data *cdata, void *decode_data) | |
cdata = cdata->nxt; | ||
} | ||
|
||
if (!dec_data->jpeg.quantization_table_set[q] && | ||
q < QUANT_TAB_T_FIRST_STATIC) { | ||
MakeTables(q, dec_data->jpeg.quantization_tables[q][0], | ||
dec_data->jpeg.quantization_tables[q][1]); | ||
dec_data->jpeg.quantization_table_set[q] = true; | ||
} | ||
|
||
if (!dec_data->jpeg.quantization_table_set[q]) { | ||
MSG(WARNING, | ||
"Dropping frame - missing quantization tables for Q=%d!\n", | ||
|