mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 08:13:04 +04:00
Merge pull request #22064 from Kumataro:3.4-fix22052
* imgcodecs: jpeg: add IMWRITE_JPEG_SAMPLING_FACTOR parameter * fix compile error * imgcodecs: jpeg: add CV_LOG_WARNING() and fix how to initilize Mat * imgcodecs: jpeg: fix for C++98 mode. * samples: imgcodec_jpeg: Remove license
This commit is contained in:
@@ -44,6 +44,8 @@
|
||||
|
||||
#ifdef HAVE_JPEG
|
||||
|
||||
#include <opencv2/core/utils/logger.hpp>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
//interaction between '_setjmp' and C++ object destruction is non-portable
|
||||
#pragma warning(disable: 4611)
|
||||
@@ -640,6 +642,7 @@ bool JpegEncoder::write( const Mat& img, const std::vector<int>& params )
|
||||
int rst_interval = 0;
|
||||
int luma_quality = -1;
|
||||
int chroma_quality = -1;
|
||||
uint32_t sampling_factor = 0; // same as 0x221111
|
||||
|
||||
for( size_t i = 0; i < params.size(); i += 2 )
|
||||
{
|
||||
@@ -687,6 +690,27 @@ bool JpegEncoder::write( const Mat& img, const std::vector<int>& params )
|
||||
rst_interval = params[i+1];
|
||||
rst_interval = MIN(MAX(rst_interval, 0), 65535L);
|
||||
}
|
||||
|
||||
if( params[i] == IMWRITE_JPEG_SAMPLING_FACTOR )
|
||||
{
|
||||
sampling_factor = static_cast<uint32_t>(params[i+1]);
|
||||
|
||||
switch ( sampling_factor )
|
||||
{
|
||||
case IMWRITE_JPEG_SAMPLING_FACTOR_411:
|
||||
case IMWRITE_JPEG_SAMPLING_FACTOR_420:
|
||||
case IMWRITE_JPEG_SAMPLING_FACTOR_422:
|
||||
case IMWRITE_JPEG_SAMPLING_FACTOR_440:
|
||||
case IMWRITE_JPEG_SAMPLING_FACTOR_444:
|
||||
// OK.
|
||||
break;
|
||||
|
||||
default:
|
||||
CV_LOG_WARNING(NULL, cv::format("Unknown value for IMWRITE_JPEG_SAMPLING_FACTOR: 0x%06x", sampling_factor ) );
|
||||
sampling_factor = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jpeg_set_defaults( &cinfo );
|
||||
@@ -699,6 +723,14 @@ bool JpegEncoder::write( const Mat& img, const std::vector<int>& params )
|
||||
if( optimize )
|
||||
cinfo.optimize_coding = TRUE;
|
||||
|
||||
if( (channels > 1) && ( sampling_factor != 0 ) )
|
||||
{
|
||||
cinfo.comp_info[0].v_samp_factor = (sampling_factor >> 16 ) & 0xF;
|
||||
cinfo.comp_info[0].h_samp_factor = (sampling_factor >> 20 ) & 0xF;
|
||||
cinfo.comp_info[1].v_samp_factor = 1;
|
||||
cinfo.comp_info[1].h_samp_factor = 1;
|
||||
}
|
||||
|
||||
#if JPEG_LIB_VERSION >= 70
|
||||
if (luma_quality >= 0 && chroma_quality >= 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user