mirror of
https://github.com/opencv/opencv.git
synced 2024-11-23 18:50:21 +08:00
Update grfmt_jpeg2000_openjpeg.cpp
This commit is contained in:
parent
a50dec88d5
commit
b7f5bfcd95
@ -323,30 +323,30 @@ opj_dparameters setupDecoderParameters()
|
||||
return parameters;
|
||||
}
|
||||
|
||||
opj_cparameters setupEncoderParameters(const std::vector<int>& params)
|
||||
opj_cparameters setupEncoderParameters(const std::vector<int>& params, const int numChannels)
|
||||
{
|
||||
opj_cparameters parameters;
|
||||
opj_set_default_encoder_parameters(¶meters);
|
||||
bool rate_is_specified = false;
|
||||
parameters.tcp_rates[0] = 4.0f;
|
||||
parameters.tcp_numlayers = 1;
|
||||
parameters.cp_disto_alloc = 1;
|
||||
parameters.tcp_mct = numChannels >= 3 ? 1 : 0;
|
||||
|
||||
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;
|
||||
if (params[i + 1] > 0)
|
||||
{
|
||||
parameters.tcp_rates[0] = 1000.f / std::min(params[i + 1], 1000);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
CV_LOG_WARNING(NULL, "OpenJPEG2000(encoder): skip unsupported parameter: " << params[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
parameters.tcp_numlayers = 1;
|
||||
parameters.cp_disto_alloc = 1;
|
||||
if (!rate_is_specified)
|
||||
{
|
||||
parameters.tcp_rates[0] = 4;
|
||||
}
|
||||
return parameters;
|
||||
}
|
||||
|
||||
@ -713,7 +713,7 @@ bool Jpeg2KOpjEncoder::write(const Mat& img, const std::vector<int>& params)
|
||||
cv::format("OpenJPEG2000: image precision > 16 not supported. Got: %d", depth));
|
||||
}();
|
||||
|
||||
opj_cparameters parameters = setupEncoderParameters(params);
|
||||
opj_cparameters parameters = setupEncoderParameters(params, img.channels());
|
||||
|
||||
std::vector<opj_image_cmptparm_t> compparams(channels);
|
||||
for (int i = 0; i < channels; i++) {
|
||||
|
@ -758,8 +758,8 @@ void addDataSearchSubDirectory(const std::string& subdir);
|
||||
0. TS::data_search_path (search sub-directories are not used)
|
||||
1. OPENCV_TEST_DATA_PATH environment variable
|
||||
2. One of these:
|
||||
a. OpenCV testdata based on build location: "./" + "share/OpenCV/testdata"
|
||||
b. OpenCV testdata at install location: CMAKE_INSTALL_PREFIX + "share/OpenCV/testdata"
|
||||
a. OpenCV testdata based on build location: "./" + "share/opencv4/testdata"
|
||||
b. OpenCV testdata at install location: CMAKE_INSTALL_PREFIX + "share/opencv4/testdata"
|
||||
|
||||
Search sub-directories:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user