Skip to content

Commit 463c78f

Browse files
committed
feat: Optimize avatar size multiplier for 2 << n px avatars
Instead of 2/3 which is not optimal for 512 px avatars usually passed to Core, use the sequence 3/4, 5/8, 4/8, 3/8... to do "smaller" downscaling steps and reduce aliasing effects. Before, it was discussed that just 3/4 can be used. However, if we repeat the reduction step, we get `3 << n` as a numerator and this way increase aliasing effects on each step. Better limit the numerator to 5.
1 parent 98b55ec commit 463c78f

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/blob.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,8 @@ impl<'a> BlobObject<'a> {
435435
});
436436

437437
if do_scale {
438+
let (mut m, mut d) = (3, 4);
439+
let wh = target_wh;
438440
loop {
439441
if mem::take(&mut add_white_bg) {
440442
self::add_white_bg(&mut img);
@@ -467,8 +469,11 @@ impl<'a> BlobObject<'a> {
467469
"Failed to scale image to below {max_bytes}B.",
468470
));
469471
}
470-
471-
target_wh = target_wh * 2 / 3;
472+
target_wh = wh * m / d;
473+
(m, d) = match m > 3 {
474+
true => (m - 1, d),
475+
false => (5, d * 2),
476+
};
472477
} else {
473478
info!(
474479
context,

0 commit comments

Comments
 (0)