-
-
Notifications
You must be signed in to change notification settings - Fork 56.2k
tiff need check TIFFTAG_SAMPLEFORMAT, should not always use unsigned. #21400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for contribution!
modules/imgcodecs/src/grfmt_tiff.cpp
Outdated
@@ -295,24 +295,30 @@ bool TiffDecoder::readHeader() | |||
(ncn != 1 && ncn != 3 && ncn != 4))) | |||
bpp = 8; | |||
|
|||
char depth; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int depth;
It is better to move it below into "case" code blocks:
case XXX:
{
int depth = ...
.. use depth ...
break;
}
modules/imgcodecs/src/grfmt_tiff.cpp
Outdated
@@ -295,24 +295,30 @@ bool TiffDecoder::readHeader() | |||
(ncn != 1 && ncn != 3 && ncn != 4))) | |||
bpp = 8; | |||
|
|||
char depth; | |||
uint16 fmt = SAMPLEFORMAT_UINT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fmt -> sample_format
modules/imgcodecs/src/grfmt_tiff.cpp
Outdated
int wanted_channels = normalizeChannelsNumber(ncn); | ||
switch(bpp) | ||
{ | ||
case 1: | ||
m_type = CV_MAKETYPE(CV_8U, !isGrayScale ? wanted_channels : 1); | ||
depth = fmt == SAMPLEFORMAT_INT ? CV_8S : CV_8U; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to validate its value first:
CV_Check((int)sample_format, sample_format == SAMPLEFORMAT_UINT || sample_format == SAMPLEFORMAT_INT, "");
modules/imgcodecs/src/grfmt_tiff.cpp
Outdated
result = true; | ||
break; | ||
case 16: | ||
m_type = CV_MAKETYPE(CV_16U, !isGrayScale ? wanted_channels : 1); | ||
depth = fmt == SAMPLEFORMAT_INT ? CV_16S : CV_16U; | ||
m_type = CV_MAKETYPE(depth, !isGrayScale ? wanted_channels : 1); | ||
result = true; | ||
break; | ||
case 32: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
32 and 64 cases:
CV_CheckEQ((int)sample_format, SAMPLEFORMAT_IEEEFP, "");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, for 32 case, since OpenCV has CV_32S, so 32 case should allow SAMPLEFORMAT_INT?
thanks for reviewing, I updated the code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done! Thank you 👍
tiff need check TIFFTAG_SAMPLEFORMAT, should not always use unsigned.
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.