8000 tiff need check TIFFTAG_SAMPLEFORMAT, should not always use unsigned. by Harvey-Huang · Pull Request #21400 · opencv/opencv · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 3 commits into from
Jan 11, 2022

Conversation

Harvey-Huang
Copy link
Contributor
@Harvey-Huang Harvey-Huang commented Jan 6, 2022

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake
force_builders=linux,win64,mac,docs

Copy link
Member
@alalek alalek left a 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!

@@ -295,24 +295,30 @@ bool TiffDecoder::readHeader()
(ncn != 1 && ncn != 3 && ncn != 4)))
bpp = 8;

char depth;
Copy link
Member

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;
}

@@ -295,24 +295,30 @@ bool TiffDecoder::readHeader()
(ncn != 1 && ncn != 3 && ncn != 4)))
bpp = 8;

char depth;
uint16 fmt = SAMPLEFORMAT_UINT;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fmt -> sample_format

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;
Copy link
Member

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, "");

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:
Copy link
Member

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, "");

Copy link
Contributor Author

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?

@Harvey-Huang
Copy link
Contributor Author

thanks for reviewing, I updated the code.

Copy link
Member
@alalek alalek left a 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 👍

@alalek alalek merged commit c3e27bc into opencv:4.x Jan 11, 2022
@alalek alalek mentioned this pull request Feb 22, 2022
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
tiff need check TIFFTAG_SAMPLEFORMAT, should not always use unsigned.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0