[#3954] Fix OpenJPEG uploading small textures (again) #4708
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The previous fix provided here- #3955 turned out to only be a partial fix.
There continued to be an issue where if either width or height was MIN_IMAGE_SIZE <= x <=16 it would also error out and fail to encode. The cause of this was opj_start_compress was failing internally and outputting the error "Number of resolutions is too high in comparison to the size of tiles". This is because the parameter.numresolution was never being changed and left the default 6, however the maximum number of resolutions cannot exceed the following formula-
1+lower(log2(min(width, height)))
This PR changes it so, if either dimension is <=64, it calculates the new maximum parameter.numresolution based on the formula mentioned above. This means the value will never exceed the default value of 6 that has always existed, but will lower it where necessary when either dimension is too low.
Related Issues
Specifically this comment from that issue-
OpenJPEG issue uploading small textures can't convert to j2c #3954 (comment)
Testing steps: