Thanks to visit codestin.com
Credit goes to github.com

Skip to content

3rdparty: libjpeg-turbo: IMWRITE_JPEG_LUMA/CHROMA_QUALITY doesn't work with internal libjpeg-turbo #25646

@Kumataro

Description

@Kumataro

System Information

OpenCV version: 4.10.0-pre ( 4.9.0-522-g1fa96b161f )
Operating System / Platform: Ubuntu 24.04
Compiler & compiler version: GCC 13.2.0

Detailed description

Internal libjpeg-turbo is JPEG_LIB_VERSION=62.

set(JPEG_LIB_VERSION 62)

However, IMWRITE_JPEG_LUMA_QUALITY and IMWRITE_JPEG_CHROMA_QUALITY requests JPEG_LIB_VERSION >= 70.

#if JPEG_LIB_VERSION >= 70
if (luma_quality >= 0 && chroma_quality >= 0)
{
cinfo.q_scale_factor[0] = jpeg_quality_scaling(luma_quality);
cinfo.q_scale_factor[1] = jpeg_quality_scaling(chroma_quality);
if ( luma_quality != chroma_quality )
{
/* disable subsampling - ref. Libjpeg.txt */
cinfo.comp_info[0].v_samp_factor = 1;
cinfo.comp_info[0].h_samp_factor = 1;
cinfo.comp_info[1].v_samp_factor = 1;
cinfo.comp_info[1].h_samp_factor = 1;
}
jpeg_default_qtables( &cinfo, TRUE );
}
#endif // #if JPEG_LIB_VERSION >= 70

Steps to reproduce

    std::vector<uint8_t> jpegNormal;
    cv::imencode(".jpg", src, jpegNormal);

    std::vector<int> param;
    param.push_back(IMWRITE_JPEG_LUMA_QUALITY);
    param.push_back(95);
    param.push_back(IMWRITE_JPEG_CHROMA_QUALITY);
    param.push_back(80);

    std::vector<uint8_t> jpegCustom;
    cv::imencode(".jpg", src, jpegCustom, param);

and compare jpegNormal and jpegCustom.

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions