imgcodecs: ensure parameters are key-value pairs, fix HDR encoder#22830
imgcodecs: ensure parameters are key-value pairs, fix HDR encoder#22830asmorkalov merged 1 commit intoopencv:3.4from
Conversation
modules/imgcodecs/src/grfmt_hdr.cpp
Outdated
| { | ||
| switch (params[i]) | ||
| { | ||
| case CV_IMWRITE_JPEG_QUALITY: |
There was a problem hiding this comment.
I feel that it is need to fix the conditional here.
- case CV_IMWRITE_JPEG_QUALITY:
+ case IMWRITE_HDR_COMPRESSION:
Test code is following.
$ git --no-pager diff
diff --git a/modules/imgcodecs/src/grfmt_hdr.cpp b/modules/imgcodecs/src/grfmt_hdr.cpp
index 4c37549..6e2f565 100644
--- a/modules/imgcodecs/src/grfmt_hdr.cpp
+++ b/modules/imgcodecs/src/grfmt_hdr.cpp
@@ -147,7 +147,7 @@ bool HdrEncoder::write( const Mat& input_img, const std::vector<int>& params )
{
switch (params[i])
{
- case CV_IMWRITE_JPEG_QUALITY:
+ case IMWRITE_HDR_COMPRESSION:
compression = params[i + 1];
break;
default:
diff --git a/modules/imgcodecs/test/test_grfmt.cpp b/modules/imgcodecs/test/test_grfmt.cpp
index 520ba4a..2e4130c 100644
--- a/modules/imgcodecs/test/test_grfmt.cpp
+++ b/modules/imgcodecs/test/test_grfmt.cpp
@@ -316,6 +316,27 @@ TEST(Imgcodecs_Hdr, regression)
ASSERT_FALSE(max > DBL_EPSILON);
}
remove(tmp_file_name.c_str());
+
+ {
+ // Default
+ vector<uchar> buf_noparams;
+ imencode(".hdr", img_no_rle, buf_noparams);
+
+ // IMWRITE_HDR_COMPRESSION_NONE
+ param[0] = IMWRITE_HDR_COMPRESSION;
+ param[1] = IMWRITE_HDR_COMPRESSION_NONE;
+ vector<uchar> buf_comp_none;
+ imencode(".hdr", img_no_rle, buf_comp_none, param);
+
+ // IMWRITE_HDR_COMPRESSION_RLE
+ param[0] = IMWRITE_HDR_COMPRESSION;
+ param[1] = IMWRITE_HDR_COMPRESSION_RLE;
+ vector<uchar> buf_comp_rle;
+ imencode(".hdr", img_no_rle, buf_comp_rle, param);
+
+ ASSERT_EQ( buf_noparams, buf_comp_rle);
+ ASSERT_TRUE( buf_comp_rle.size() < buf_comp_none.size());
+ }
}
#endifThere was a problem hiding this comment.
@Kumataro Thank you! Fixed.
Also fixed imencode() and added tests.
BTW, C API is on hold. We don't modify it anymore.
There was a problem hiding this comment.
Thank you to fix it , and I agree with you.
CV_IMWRITE_HDR_COMPRESSION is not necessary and will not be defined.
|
Thank you very much to fix it !! (Perhaps I'm overthinking.) opencv/modules/imgcodecs/include/opencv2/imgcodecs/imgcodecs_c.h Lines 80 to 106 in 7592d58 CV_IMWRITE_WEBP_QUALITY =64,
+ CV_IMWRITE_HDR_COMPRESSION =80,
CV_IMWRITE_PAM_TUPLETYPE = 128, |
|
@Kumataro I don't think so. IIRC the C API was deprecated in 3.x, and now is history. Doesn't seem to make much sense to touch that. |
|
@Kumataro May I merge the PR? |
|
Yes, I think there are no problem,, thank you very much to fix !! |
resolves #22752