-
-
Notifications
You must be signed in to change notification settings - Fork 56.2k
implementation closer to TIFF-spec, less boilerplate-code #27412
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
base: 4.x
Are you sure you want to change the base?
Conversation
@janstarzy Could you describe you issue and what problem do you solve? Problematic code / image are useful too. |
This does not fix a visible bug, but it gets the implementation closer to the TIFF-spec for SamplesPerPixel (as described at the bottom of the description. The change concerning BitsPerSample is a matter of clean code, achieving the same effect with less lines of code. I wondered, why it was handled differently to SamplesPerPixel. |
4785ea4
to
3f1eb2a
Compare
Hello, this fix may changes ncn(number of channels) and bpp(bit per pixel) behaviours.
ncn ( number of channnels)
To simplify, opencv/3rdparty/libtiff/tiff.h Lines 219 to 232 in d97e926
CV_TIFF_CHECK_CALL_DEBUG()opencv/modules/imgcodecs/src/grfmt_tiff.cpp Lines 611 to 617 in d97e926
If Currently implemtation write over to default value, so bpp should not be undefined value. |
d9a0726
to
091d8f2
Compare
Hi, I was not quoting libtiff, but the TIFF 6.0 Spec. There the default values are defined. |
|
The longer I think about the matter, the more I come to the conclusion |
I'm very sorry, but I also find it difficult to understand what you were trying to solve with this pull request.
opencv/modules/imgcodecs/src/grfmt_tiff.cpp Lines 268 to 298 in 4b69cc5
My understanding is ...
Index number of palette is 1-dim, but palette has R,G,B elements. So destination Mat for palette-color image shall have 3 colorant. |
This is another suggestion. SamplesPerPixel tag is required for RGB Images only, but it does not for other colormetric. - CV_TIFF_CHECK_CALL_DEBUG(TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &ncn));
+ switch(photometric)
+ {
+ case PHOTOMETRIC_RGB:
+ // SamplesPerPixel tag is required for RGB Images(From TIFF6.0 Section 6).
+ CV_TIFF_CHECK_CALL(TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &ncn));
+ CV_CheckEQ(ncn, 3);
+ break;
+ case PHOTOMETRIC_MINISWHITE:
+ case PHOTOMETRIC_MINISBLACK:
+ ncn = 1; // GRAY output
+ break;
+ default:
+ ncn = 3; // Color output(RGB).
+ break;
+ } |
I mean to follow the TIFF-Spec strictly. Only this way we can ensure that spec-complying tiff-files will be processed correctly. So, my understanding is:
The proper number of channels on For the other My initial intention was just cleaner code, but in the course of work this changed to complying to the specs (both TIFF and libtiff). |
Strictly your fix seems not be according to TIFF 6.0. Default value of If you disagree it, |
091d8f2
to
32d590a
Compare
Yes, the default value for |
Thank you very much. OK, I know See https://libtiff.gitlab.io/libtiff/specification/coverage.html If it complies with TIFF 6.0 and/or libtiff, we have to valid SamplesPerPixel. Current implementation Tiff image which has
How about this suggestion ? |
I'll have a look into the code to see what validation is necessary. |
32d590a
to
954cfcf
Compare
Nothing exiting new code until now, only a little cleanup. More to come, you do not need to look yet. |
I agree with your suggestion. Let's play it save here, I'll implement the validation. May be there is a more sophisticated solution, but I don't see it yet. And the code is complicated enough already. |
954cfcf
to
f15c8af
Compare
Unfortunately "coverage.html" covers only baseline-tiff: with these rules the tests fail. I coded something I found reasonable... |
f15c8af
to
4e13855
Compare
But the work is not done yet. |
I converted the PR to draft. Please change its status, when it's ready for review. |
@janstarzy, thanks for the contribution!
|
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: covered by existing tests
From the TIFF-Spec:
So the default is 1 unless RGB (not 3 as before).
The original code does this with more lines of code. I wondered, why it was different to the retrieval of SamplesPerPixel.