Skip to content

feat: Don't scale down huge non-JPEGs, recode them first (#7977)#7992

Open
iequidoo wants to merge 1 commit into
mainfrom
iequidoo/dont-resize-non-jpeg
Open

feat: Don't scale down huge non-JPEGs, recode them first (#7977)#7992
iequidoo wants to merge 1 commit into
mainfrom
iequidoo/dont-resize-non-jpeg

Conversation

@iequidoo

@iequidoo iequidoo commented Mar 15, 2026

Copy link
Copy Markdown
Collaborator

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.

Close #7977

@iequidoo iequidoo force-pushed the iequidoo/dont-resize-non-jpeg branch from cbe06c0 to 13efe75 Compare March 15, 2026 14:35
Comment thread src/tests/pre_messages/additional_text.rs Outdated
@iequidoo iequidoo force-pushed the iequidoo/dont-resize-non-jpeg branch 4 times, most recently from 1208117 to c780392 Compare March 15, 2026 15:19
@iequidoo iequidoo requested review from Hocuri and r10s March 15, 2026 15:36
@iequidoo iequidoo force-pushed the iequidoo/dont-resize-non-jpeg branch from c780392 to 2e7e8c3 Compare April 16, 2026 17:35
@j-g00da j-g00da self-requested a review June 9, 2026 12:44
@iequidoo iequidoo force-pushed the iequidoo/dont-resize-non-jpeg branch from 2e7e8c3 to 9a33977 Compare June 15, 2026 04:34
@iequidoo iequidoo marked this pull request as draft June 17, 2026 02:18
@iequidoo iequidoo force-pushed the iequidoo/dont-resize-non-jpeg branch from 9a33977 to 806c39d Compare June 17, 2026 02:21
@iequidoo iequidoo marked this pull request as ready for review June 17, 2026 02:24
Comment thread src/blob.rs Outdated
Comment on lines 418 to 443

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@iequidoo iequidoo Jun 17, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

Comment thread src/blob.rs Outdated
@72374

72374 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Is this PR supposed to be about improving the quality of screenshots specifically, or improving the quality of sent images in general?

@iequidoo

iequidoo commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator Author

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".

@iequidoo iequidoo force-pushed the iequidoo/dont-resize-non-jpeg branch from 806c39d to ee2dc5b Compare June 17, 2026 18:58
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.
@iequidoo iequidoo force-pushed the iequidoo/dont-resize-non-jpeg branch from ee2dc5b to c9a8932 Compare June 18, 2026 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

screenshots are sometimes sent in poor quality

3 participants