std/jpeg: implement Inverse DCT

Updates #42
This commit is contained in:
Nigel Tao committed 2023-05-08 21:51:47 +10:00
1 parent cac4df3bde
commit 8cfe304f3c
7 files changed
+2662

No files matched your search

+67
View File
@@ -531,6 +531,72 @@ test_wuffs_jpeg_decode_dht_hard() {
&want_fast);
}
const char* //
test_wuffs_jpeg_decode_idct() {
CHECK_FOCUS(__func__);
// This is "test/data/bricks-color.jpeg"'s first MCU's first block, in
// natural (not zig-zag) order.
const uint16_t mcu_block[64] = {
0xFFC9, 0xFFD8, 0x0014, 0xFFF7, 0x0002, 0x0000, 0x0000, 0x0000, //
0x006A, 0xFFE3, 0x001C, 0xFFF9, 0x0002, 0x0000, 0x0000, 0x0000, //
0x0015, 0x0002, 0x0002, 0xFFFE, 0x0001, 0x0000, 0x0000, 0x0001, //
0x000D, 0xFFEC, 0x0005, 0xFFFE, 0x0000, 0x0000, 0x0000, 0x0000, //
0xFFFA, 0xFFFA, 0x0002, 0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, //
0x0001, 0xFFFD, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, //
0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, //
0x0001, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, //
};
// This is "test/data/bricks-color.jpeg"'s first quantization table, in
// natural (not zig-zag) order.
const uint8_t quant_table[64] = {
0x03, 0x02, 0x02, 0x03, 0x04, 0x06, 0x08, 0x0A, //
0x02, 0x02, 0x02, 0x03, 0x04, 0x09, 0x0A, 0x09, //
0x02, 0x02, 0x03, 0x04, 0x06, 0x09, 0x0B, 0x09, //
0x02, 0x03, 0x04, 0x05, 0x08, 0x0E, 0x0D, 0x0A, //
0x03, 0x04, 0x06, 0x09, 0x0B, 0x11, 0x10, 0x0C, //
0x04, 0x06, 0x09, 0x0A, 0x0D, 0x11, 0x12, 0x0F, //
0x08, 0x0A, 0x0C, 0x0E, 0x10, 0x13, 0x13, 0x10, //
0x0C, 0x0F, 0x0F, 0x10, 0x12, 0x10, 0x10, 0x10, //
};
// This is the IDCT's expected result (including dequantization), again in
// natural (not zig-zag) order.
const uint8_t want_array[64] = {
0x81, 0x7E, 0x82, 0x7E, 0x82, 0x92, 0xC5, 0xF2, //
0x81, 0x80, 0x84, 0x85, 0x85, 0x88, 0x9D, 0xB2, //
0x86, 0x81, 0x7A, 0x77, 0x72, 0x75, 0x7E, 0x8A, //
0x54, 0x58, 0x58, 0x5E, 0x5E, 0x6C, 0x79, 0x87, //
0x4D, 0x54, 0x56, 0x5B, 0x59, 0x65, 0x6E, 0x7A, //
0x4A, 0x4D, 0x4F, 0x53, 0x56, 0x5F, 0x67, 0x6E, //
0x4A, 0x4D, 0x54, 0x58, 0x5B, 0x58, 0x56, 0x54, //
0x4C, 0x4C, 0x52, 0x4F, 0x4D, 0x40, 0x3A, 0x35, //
};
wuffs_jpeg__decoder dec;
CHECK_STATUS("initialize", wuffs_jpeg__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__DEFAULT_OPTIONS));
const uint32_t b = 0;
memcpy(&dec.private_data.f_mcu_blocks[b], mcu_block, sizeof(mcu_block));
const uint32_t q = 0;
memcpy(&dec.private_impl.f_quant_tables[q], quant_table, sizeof(quant_table));
uint8_t dst_array[64] = {0};
wuffs_jpeg__decoder__decode_idct(
&dec, wuffs_base__make_slice_u8(&dst_array[0], 64), 8, b, q);
wuffs_base__io_buffer have =
wuffs_base__ptr_u8__reader(&dst_array[0], 64, true);
wuffs_base__io_buffer want =
wuffs_base__ptr_u8__reader((void*)(&want_array[0]), 64, true);
return check_io_buffers_equal("", &have, &want);
}
const char* //
test_wuffs_jpeg_decode_mcu() {
CHECK_FOCUS(__func__);
@@ -705,6 +771,7 @@ proc g_tests[] = {
test_wuffs_jpeg_decode_dht_easy,
test_wuffs_jpeg_decode_dht_hard,
test_wuffs_jpeg_decode_idct,
test_wuffs_jpeg_decode_mcu,
test_wuffs_jpeg_decode_interface,
test_wuffs_jpeg_decode_truncated_input,