diff --git a/src/blob.rs b/src/blob.rs index 601acd9cf1..bdfd86bdab 100644 --- a/src/blob.rs +++ b/src/blob.rs @@ -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) diff --git a/src/tests/pre_messages/additional_text.rs b/src/tests/pre_messages/additional_text.rs index 0af33ec8c6..a7da5548da 100644 --- a/src/tests/pre_messages/additional_text.rs +++ b/src/tests/pre_messages/additional_text.rs @@ -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(()) } diff --git a/src/tests/pre_messages/receiving.rs b/src/tests/pre_messages/receiving.rs index 2f0147e5e3..3060f2119c 100644 --- a/src/tests/pre_messages/receiving.rs +++ b/src/tests/pre_messages/receiving.rs @@ -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);