feat: Don't scale down huge non-JPEGs, recode them first (#7977)#7992
feat: Don't scale down huge non-JPEGs, recode them first (#7977)#7992iequidoo wants to merge 1 commit into
Conversation
cbe06c0 to
13efe75
Compare
1208117 to
c780392
Compare
c780392 to
2e7e8c3
Compare
2e7e8c3 to
9a33977
Compare
9a33977 to
806c39d
Compare
There was a problem hiding this comment.
This whole logic chain
a && (b || c) || d && (e || f && g)
is extremely hard to read, while at it we should take few minutes to rewrite it, create some additional variables that makes it easier to comprehend. It will save us a lot of time reviewing changes around it later on.
There was a problem hiding this comment.
I've simplified the logic, maybe this is enough? Moreover, there was an already existing bug that i didn't notice before probably: a non-JPEG image mayn't have exceeds_max_bytes but after removing Exif it may become huge if it can't be encoded to JPEG effectively. Now such images are downscaled.
EDIT: Well, simplified too much: made a bug that a small JPEG may be downscaled after removing Exif if it becomes "large" for some reason, e.g. if we use a less effective encoder. We don't want to recode JPEGs twice in any case. This is a corner case, but is now fixed.
|
Is this PR supposed to be about improving the quality of screenshots specifically, or improving the quality of sent images in general? |
In general for non-JPEGs and, as a consequence, PNG screenshots. We'd like to have less format-specific code, so let's not add more PNG-specific code even if we already have some. Otherwise the next bug would be "i sent a BMP image and it was scaled down instead of just being recoded". |
806c39d to
ee2dc5b
Compare
If after recoding to JPEG an image isn't huge anymore, don't scale it down, this preserves quality of most screenshots. For JPEGs however we don't try to recode them w/o scaling down: - They are already JPEG-encoded, maybe with higher quality, but anyway. - We don't want extra CPU work for most photos.
ee2dc5b to
c9a8932
Compare
If after recoding to JPEG an image isn't huge anymore, don't scale it down, this preserves quality of most screenshots. For JPEGs however we don't try to recode them w/o scaling down:
Close #7977