Merge pull request #18210 from VadimLevin:dev/vlevin/openjpeg-reduce-filesize

This commit is contained in:
Alexander Alekhin 2020-08-28 18:29:44 +00:00
commit 2e6e9c14b5
2 changed files with 14 additions and 2 deletions

View File

@ -327,12 +327,14 @@ opj_cparameters setupEncoderParameters(const std::vector<int>& params)
{
opj_cparameters parameters;
opj_set_default_encoder_parameters(&parameters);
bool rate_is_specified = false;
for (size_t i = 0; i < params.size(); i += 2)
{
switch (params[i])
{
case cv::IMWRITE_JPEG2000_COMPRESSION_X1000:
parameters.tcp_rates[0] = 1000.f / std::min(std::max(params[i + 1], 1), 1000);
rate_is_specified = true;
break;
default:
CV_LOG_WARNING(NULL, "OpenJPEG2000(encoder): skip unsupported parameter: " << params[i]);
@ -341,6 +343,10 @@ opj_cparameters setupEncoderParameters(const std::vector<int>& params)
}
parameters.tcp_numlayers = 1;
parameters.cp_disto_alloc = 1;
if (!rate_is_specified)
{
parameters.tcp_rates[0] = 4;
}
return parameters;
}

View File

@ -228,9 +228,12 @@ TEST_P(Imgcodecs_Image, read_write_BGR)
double psnrThreshold = 100;
if (ext == "jpg")
psnrThreshold = 32;
#ifdef HAVE_JASPER
#if defined(HAVE_JASPER)
if (ext == "jp2")
psnrThreshold = 95;
#elif defined(HAVE_OPENJPEG)
if (ext == "jp2")
psnrThreshold = 35;
#endif
Mat image = generateTestImageBGR();
@ -254,9 +257,12 @@ TEST_P(Imgcodecs_Image, read_write_GRAYSCALE)
double psnrThreshold = 100;
if (ext == "jpg")
psnrThreshold = 40;
#ifdef HAVE_JASPER
#if defined(HAVE_JASPER)
if (ext == "jp2")
psnrThreshold = 70;
#elif defined(HAVE_OPENJPEG)
if (ext == "jp2")
psnrThreshold = 35;
#endif
Mat image = generateTestImageGrayscale();