#2992: update after review
This commit is contained in:
parent
9d107fb2d5
commit
eaec132091
@ -56,17 +56,17 @@ enum { IMREAD_UNCHANGED = -1, // 8bit, color or not
|
|||||||
IMREAD_ANYCOLOR = 4 // ?, any color
|
IMREAD_ANYCOLOR = 4 // ?, any color
|
||||||
};
|
};
|
||||||
|
|
||||||
enum { IMWRITE_JPEG_QUALITY = 1,
|
enum { IMWRITE_JPEG_QUALITY = 1,
|
||||||
IMWRITE_JPEG_PROGRESSIVE = 2,
|
IMWRITE_JPEG_PROGRESSIVE = 2,
|
||||||
IMWRITE_JPEG_OPTIMIZE = 3,
|
IMWRITE_JPEG_OPTIMIZE = 3,
|
||||||
IMWRITE_JPEG_RST_INTERVAL = 4,
|
IMWRITE_JPEG_RST_INTERVAL = 4,
|
||||||
IMWRITE_JPEG_LUM_QUALITY = 5,
|
IMWRITE_JPEG_LUMA_QUALITY = 5,
|
||||||
IMWRITE_JPEG_CHROM_QUALITY = 6,
|
IMWRITE_JPEG_CHROMA_QUALITY = 6,
|
||||||
IMWRITE_PNG_COMPRESSION = 16,
|
IMWRITE_PNG_COMPRESSION = 16,
|
||||||
IMWRITE_PNG_STRATEGY = 17,
|
IMWRITE_PNG_STRATEGY = 17,
|
||||||
IMWRITE_PNG_BILEVEL = 18,
|
IMWRITE_PNG_BILEVEL = 18,
|
||||||
IMWRITE_PXM_BINARY = 32,
|
IMWRITE_PXM_BINARY = 32,
|
||||||
IMWRITE_WEBP_QUALITY = 64
|
IMWRITE_WEBP_QUALITY = 64
|
||||||
};
|
};
|
||||||
|
|
||||||
enum { IMWRITE_PNG_STRATEGY_DEFAULT = 0,
|
enum { IMWRITE_PNG_STRATEGY_DEFAULT = 0,
|
||||||
|
@ -77,8 +77,8 @@ enum
|
|||||||
CV_IMWRITE_JPEG_PROGRESSIVE =2,
|
CV_IMWRITE_JPEG_PROGRESSIVE =2,
|
||||||
CV_IMWRITE_JPEG_OPTIMIZE =3,
|
CV_IMWRITE_JPEG_OPTIMIZE =3,
|
||||||
CV_IMWRITE_JPEG_RST_INTERVAL =4,
|
CV_IMWRITE_JPEG_RST_INTERVAL =4,
|
||||||
CV_IMWRITE_JPEG_LUM_QUALITY =5,
|
CV_IMWRITE_JPEG_LUMA_QUALITY =5,
|
||||||
CV_IMWRITE_JPEG_CHROM_QUALITY =6,
|
CV_IMWRITE_JPEG_CHROMA_QUALITY =6,
|
||||||
CV_IMWRITE_PNG_COMPRESSION =16,
|
CV_IMWRITE_PNG_COMPRESSION =16,
|
||||||
CV_IMWRITE_PNG_STRATEGY =17,
|
CV_IMWRITE_PNG_STRATEGY =17,
|
||||||
CV_IMWRITE_PNG_BILEVEL =18,
|
CV_IMWRITE_PNG_BILEVEL =18,
|
||||||
|
@ -601,8 +601,8 @@ bool JpegEncoder::write( const Mat& img, const std::vector<int>& params )
|
|||||||
int progressive = 0;
|
int progressive = 0;
|
||||||
int optimize = 0;
|
int optimize = 0;
|
||||||
int rst_interval = 0;
|
int rst_interval = 0;
|
||||||
int lum_quality = 100;
|
int luma_quality = -1;
|
||||||
int chrom_quality = 100;
|
int chroma_quality = -1;
|
||||||
|
|
||||||
for( size_t i = 0; i < params.size(); i += 2 )
|
for( size_t i = 0; i < params.size(); i += 2 )
|
||||||
{
|
{
|
||||||
@ -622,16 +622,27 @@ bool JpegEncoder::write( const Mat& img, const std::vector<int>& params )
|
|||||||
optimize = params[i+1];
|
optimize = params[i+1];
|
||||||
}
|
}
|
||||||
|
|
||||||
if( params[i] == CV_IMWRITE_JPEG_LUM_QUALITY )
|
if( params[i] == CV_IMWRITE_JPEG_LUMA_QUALITY )
|
||||||
{
|
{
|
||||||
lum_quality = params[i+1];
|
if (params[i+1] >= 0)
|
||||||
lum_quality = MIN(MAX(lum_quality, 0), 100);
|
{
|
||||||
|
luma_quality = MIN(MAX(params[i+1], 0), 100);
|
||||||
|
|
||||||
|
quality = luma_quality;
|
||||||
|
|
||||||
|
if (chroma_quality < 0)
|
||||||
|
{
|
||||||
|
chroma_quality = luma_quality;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( params[i] == CV_IMWRITE_JPEG_CHROM_QUALITY )
|
if( params[i] == CV_IMWRITE_JPEG_CHROMA_QUALITY )
|
||||||
{
|
{
|
||||||
chrom_quality = params[i+1];
|
if (params[i+1] >= 0)
|
||||||
chrom_quality = MIN(MAX(chrom_quality, 0), 100);
|
{
|
||||||
|
chroma_quality = MIN(MAX(params[i+1], 0), 100);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( params[i] == CV_IMWRITE_JPEG_RST_INTERVAL )
|
if( params[i] == CV_IMWRITE_JPEG_RST_INTERVAL )
|
||||||
@ -643,6 +654,7 @@ bool JpegEncoder::write( const Mat& img, const std::vector<int>& params )
|
|||||||
|
|
||||||
jpeg_set_defaults( &cinfo );
|
jpeg_set_defaults( &cinfo );
|
||||||
cinfo.restart_interval = rst_interval;
|
cinfo.restart_interval = rst_interval;
|
||||||
|
|
||||||
jpeg_set_quality( &cinfo, quality,
|
jpeg_set_quality( &cinfo, quality,
|
||||||
TRUE /* limit to baseline-JPEG values */ );
|
TRUE /* limit to baseline-JPEG values */ );
|
||||||
if( progressive )
|
if( progressive )
|
||||||
@ -651,17 +663,20 @@ bool JpegEncoder::write( const Mat& img, const std::vector<int>& params )
|
|||||||
cinfo.optimize_coding = TRUE;
|
cinfo.optimize_coding = TRUE;
|
||||||
|
|
||||||
#if JPEG_LIB_VERSION >= 70
|
#if JPEG_LIB_VERSION >= 70
|
||||||
cinfo.q_scale_factor[0] = jpeg_quality_scaling(lum_quality);
|
if (luma_quality >= 0 && chroma_quality >= 0)
|
||||||
cinfo.q_scale_factor[1] = jpeg_quality_scaling(chrom_quality);
|
|
||||||
if ( lum_quality != chrom_quality )
|
|
||||||
{
|
{
|
||||||
/* disable subsampling - ref. Libjpeg.txt */
|
cinfo.q_scale_factor[0] = jpeg_quality_scaling(luma_quality);
|
||||||
cinfo.comp_info[0].v_samp_factor = 1;
|
cinfo.q_scale_factor[1] = jpeg_quality_scaling(chroma_quality);
|
||||||
cinfo.comp_info[0].h_samp_factor = 1;
|
if ( luma_quality != chroma_quality )
|
||||||
cinfo.comp_info[1].v_samp_factor = 1;
|
{
|
||||||
cinfo.comp_info[1].h_samp_factor = 1;
|
/* 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 );
|
||||||
}
|
}
|
||||||
jpeg_default_qtables( &cinfo, TRUE );
|
|
||||||
#endif // #if JPEG_LIB_VERSION >= 70
|
#endif // #if JPEG_LIB_VERSION >= 70
|
||||||
|
|
||||||
jpeg_start_compress( &cinfo, TRUE );
|
jpeg_start_compress( &cinfo, TRUE );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user