Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,15 +437,13 @@ impl<'a> BlobObject<'a> {
self::add_white_bg(&mut img);
}

// resize() results in often slightly better quality,
// however, comes at high price of being 4+ times slower than thumbnail().
// for a typical camera image that is sent, this may be a change from "instant" (500ms) to "long time waiting" (3s).
// as we do not have recoding in background while chat has already a preview,
// we vote for speed.
// exception is the avatar image: this is far more often sent than recoded,
// usually has less pixels by cropping, UI that needs to wait anyways,
// and also benefits from slightly better (5%) encoding of Triangle-filtered images.
let new_img = if is_avatar {
// resize() results in better quality than thumbnail(),
// however, comes at the price of being 4+ times slower.
// For a typical camera-image that is sent (often more than 8 megapixels),
// this may be a change from "instant" (500ms) to "long time waiting" (3s).
// As we do not have recoding in the background while the chat already has a preview,
// we vote for speed, if the original image has a high resolution (> 2.56 megapixels).
let new_img = if is_avatar || img.width() * img.height() <= 1600 * 1600 {
img.resize(target_wh, target_wh, image::imageops::FilterType::Triangle)
} else {
img.thumbnail(target_wh, target_wh)
Expand Down
2 changes: 1 addition & 1 deletion src/tests/pre_messages/additional_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async fn test_additional_text_on_different_viewtypes() -> Result<()> {
let (pre_message, _, _) = send_large_image_message(alice, a_group_id).await?;
let msg = bob.recv_msg(&pre_message).await;
assert_eq!(msg.text, "test".to_owned());
assert_eq!(msg.get_text(), "test [Image – 146.12 KiB]".to_owned());
assert_eq!(msg.get_text(), "test [Image – 137.04 KiB]".to_owned());

Ok(())
}
2 changes: 1 addition & 1 deletion src/tests/pre_messages/receiving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ async fn test_receive_pre_message_image() -> Result<()> {
// test that metadata is correctly returned by methods
assert_eq!(msg.get_post_message_viewtype(), Some(Viewtype::Image));
// recoded image dimensions
assert_eq!(msg.get_filebytes(bob).await?, Some(149632));
assert_eq!(msg.get_filebytes(bob).await?, Some(140327));
assert_eq!(msg.get_height(), 1280);
assert_eq!(msg.get_width(), 720);

Expand Down
Loading