mirror of
https://github.com/opencv/opencv.git
synced 2024-11-24 11:10:21 +08:00
added jpeg with optimized coding support.
This commit is contained in:
parent
04c857a4e8
commit
da34f1d58c
@ -217,6 +217,7 @@ enum { IMREAD_UNCHANGED = -1, // 8bit, color or not
|
||||
|
||||
enum { IMWRITE_JPEG_QUALITY = 1,
|
||||
IMWRITE_JPEG_PROGRESSIVE = 2,
|
||||
IMWRITE_JPEG_OPTIMIZE = 3,
|
||||
IMWRITE_PNG_COMPRESSION = 16,
|
||||
IMWRITE_PNG_STRATEGY = 17,
|
||||
IMWRITE_PNG_BILEVEL = 18,
|
||||
|
@ -221,6 +221,7 @@ enum
|
||||
{
|
||||
CV_IMWRITE_JPEG_QUALITY =1,
|
||||
CV_IMWRITE_JPEG_PROGRESSIVE =2,
|
||||
CV_IMWRITE_JPEG_OPTIMIZE =3,
|
||||
CV_IMWRITE_PNG_COMPRESSION =16,
|
||||
CV_IMWRITE_PNG_STRATEGY =17,
|
||||
CV_IMWRITE_PNG_BILEVEL =18,
|
||||
|
@ -599,6 +599,7 @@ bool JpegEncoder::write( const Mat& img, const std::vector<int>& params )
|
||||
|
||||
int quality = 95;
|
||||
int progressive = 0;
|
||||
int optimize = 0;
|
||||
|
||||
for( size_t i = 0; i < params.size(); i += 2 )
|
||||
{
|
||||
@ -612,6 +613,11 @@ bool JpegEncoder::write( const Mat& img, const std::vector<int>& params )
|
||||
{
|
||||
progressive = params[i+1];
|
||||
}
|
||||
|
||||
if( params[i] == CV_IMWRITE_JPEG_OPTIMIZE )
|
||||
{
|
||||
optimize = params[i+1];
|
||||
}
|
||||
}
|
||||
|
||||
jpeg_set_defaults( &cinfo );
|
||||
@ -619,6 +625,8 @@ bool JpegEncoder::write( const Mat& img, const std::vector<int>& params )
|
||||
TRUE /* limit to baseline-JPEG values */ );
|
||||
if( progressive )
|
||||
jpeg_simple_progression( &cinfo );
|
||||
if( optimize )
|
||||
cinfo.optimize_coding = TRUE;
|
||||
jpeg_start_compress( &cinfo, TRUE );
|
||||
|
||||
if( channels > 1 )
|
||||
|
@ -410,6 +410,30 @@ TEST(Highgui_Jpeg, encode_decode_progressive_jpeg)
|
||||
|
||||
remove(output_progressive.c_str());
|
||||
}
|
||||
|
||||
TEST(Highgui_Jpeg, encode_decode_optimize_jpeg)
|
||||
{
|
||||
cvtest::TS& ts = *cvtest::TS::ptr();
|
||||
string input = string(ts.get_data_path()) + "../cv/shared/lena.png";
|
||||
cv::Mat img = cv::imread(input);
|
||||
ASSERT_FALSE(img.empty());
|
||||
|
||||
std::vector<int> params;
|
||||
params.push_back(IMWRITE_JPEG_OPTIMIZE);
|
||||
params.push_back(1);
|
||||
|
||||
string output_optimized = cv::tempfile(".jpg");
|
||||
EXPECT_NO_THROW(cv::imwrite(output_optimized, img, params));
|
||||
cv::Mat img_jpg_optimized = cv::imread(output_optimized);
|
||||
|
||||
string output_normal = cv::tempfile(".jpg");
|
||||
EXPECT_NO_THROW(cv::imwrite(output_normal, img));
|
||||
cv::Mat img_jpg_normal = cv::imread(output_normal);
|
||||
|
||||
EXPECT_EQ(0, cv::norm(img_jpg_optimized, img_jpg_normal, NORM_INF));
|
||||
|
||||
remove(output_optimized.c_str());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user