-
Notifications
You must be signed in to change notification settings - Fork 85
Fixes bad upload quality issue with OpenJPEG #2054
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
Fixes bad upload quality issue with OpenJPEG #2054
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 the contribution!
Pre-commit check is unhappy about trailing whitespaces; the suggested changes should fix that. Please see secondlife/git-hooks for more info.
@chanayane, it looks like I can't directly apply those suggestions to your repo. Please fix them so we could proceed. |
raw diff:
|
Hello @marchcat, thank you for your review, I made the suggested changes. |
42ed648
to
11acae9
Compare
Will merge this after #2060, which should fix the pre-commit failure. |
11acae9
to
4d6d9ea
Compare
I recently noticed that in my self-compiled viewers, all my uploads looked very bad, with a lot of compression artifacts. The greater the dimensions of the texture, the ugliest it looked, like, over-compressed JPEGs.
I do not have a KDU license, so I have to use the OpenJPEG implementation in my viewer. This affected the uploading of textures and the saving of snapshots to inventory.
This bothered me a lot so I started to investigate the issue.
I discovered that the culprit was indeed the OpenJPEG implementation. The maximum size for all encoded images was set to 32KB. So 1024x1024 and especially 2048x2048 textures looked really, really bad (as good as a 32KB 2048x2048 texture can look...).
The bad line:
parameters.max_cs_size = (1 << 15);
This was set in the constructor of the JPEG2KEncode class and applied to all pictures regardless of their dimensions.
The documentations says the following for max_cs_size:
Maximum size (in bytes) for the whole codestream. If == 0, codestream size limitation is not considered. If it does not comply with tcp_rates, max_cs_size prevails and a warning is issued
.Also the number of layers was hardcoded to 5, which seemed wrong to me, it should depend on the surface of the texture.
My fix is:
So a big texture would be allowed more bytes and more layers than a tiny one.
After the fix, the quality of the uploaded textures has improved greatly. In some cases I can still see some very minor compression artefacts and blurriness but they are not too noticeable.