Commit 06ff9f0a authored by Sreerenj Balachandran's avatar Sreerenj Balachandran Committed by Commit Bot

vaapi/jpeg_enc: Fix quantization scaling

This is a workaround to match with iHD media driver that
shifts the quantization values by 50 while encoding.
https://github.com/intel/media-driver/blob/master/media_driver/linux/common/codec/ddi/media_ddi_encode_jpeg.cpp#L694

The patch ensures the shifted value in the
middleware generated packed header.
Linux media stack test cases claiming to have a significant
psnr improvement in Y plane (41.27 to 48.31) with this quirk.

BUG=None
TEST=./jpeg_encode_accelerator_unittest

Change-Id: Ie2316cce2b5c86fefeb3879872c881868687011b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2446208
Commit-Queue: Sreerenj Balachandran <sreerenj.balachandran@intel.com>
Reviewed-by: default avatarAndres Calderon Jaramillo <andrescj@chromium.org>
Reviewed-by: default avatarHirokazu Honda <hiroh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814326}
parent fe3472b4
...@@ -205,8 +205,16 @@ size_t FillJpegHeader(const gfx::Size& input_size, ...@@ -205,8 +205,16 @@ size_t FillJpegHeader(const gfx::Size& input_size,
const JpegQuantizationTable& quant_table = kDefaultQuantTable[i]; const JpegQuantizationTable& quant_table = kDefaultQuantTable[i];
for (size_t j = 0; j < kDctSize; ++j) { for (size_t j = 0; j < kDctSize; ++j) {
// The iHD media driver shifts the quantization values
// by 50 while encoding. We should add 50 here to
// ensure the correctness in the packed header that is
// directly stuffed into the bitstream as JPEG headers.
// GStreamer test cases show a psnr improvement in
// Y plane (41.27 to 48.31) with this quirk.
const static uint32_t shift =
VaapiWrapper::GetImplementationType() == VAImplementation::kIntelIHD ? 50 : 0;
uint32_t scaled_quant_value = uint32_t scaled_quant_value =
(quant_table.value[kZigZag8x8[j]] * quality_normalized) / 100; (quant_table.value[kZigZag8x8[j]] * quality_normalized + shift) / 100;
scaled_quant_value = base::ClampToRange(scaled_quant_value, 1u, 255u); scaled_quant_value = base::ClampToRange(scaled_quant_value, 1u, 255u);
header[idx++] = static_cast<uint8_t>(scaled_quant_value); header[idx++] = static_cast<uint8_t>(scaled_quant_value);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment