From 9dadb32efccc0af2aa7556e3c95f52250781378c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20K=C3=BCrten?= <sebastian@mobanisto.de>
Date: Wed, 19 Feb 2025 09:09:43 +0100
Subject: [PATCH] When compressing images to <32K, try lower quality values if
 necessary

---
 .idea/codeStyles/Project.xml                                 | 5 -----
 .../briar/desktop/attachment/media/ImageCompressorImpl.kt    | 4 ++--
 2 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
index 8f275854f4..56af15b70a 100644
--- a/.idea/codeStyles/Project.xml
+++ b/.idea/codeStyles/Project.xml
@@ -28,11 +28,6 @@
       <option name="JD_ALIGN_EXCEPTION_COMMENTS" value="false" />
     </JavaCodeStyleSettings>
     <JetCodeStyleSettings>
-      <option name="PACKAGES_TO_USE_STAR_IMPORTS">
-        <value />
-      </option>
-      <option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="2147483647" />
-      <option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="2147483647" />
       <option name="ALLOW_TRAILING_COMMA" value="true" />
       <option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
     </JetCodeStyleSettings>
diff --git a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/attachment/media/ImageCompressorImpl.kt b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/attachment/media/ImageCompressorImpl.kt
index 853c25e7c5..897fda0985 100644
--- a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/attachment/media/ImageCompressorImpl.kt
+++ b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/attachment/media/ImageCompressorImpl.kt
@@ -64,8 +64,8 @@ class ImageCompressorImpl @Inject internal constructor() : ImageCompressor {
         val scaled = if (factor != 1) scaleDown(withoutAlpha, factor) else withoutAlpha
 
         // After that, compress image. Try with maximum quality and reduce until we can compress below
-        // a size of [MAX_IMAGE_SIZE]. We try quality levels 100, 90, ..., 20, 10.
-        for (quality in 100 downTo 1 step 10) {
+        // a size of [MAX_IMAGE_SIZE]. We try quality levels 100, 90, ..., 20, 10, 9, 8, ..., 2, 1.
+        for (quality in (100 downTo 1 step 10) + (9 downTo 1 step 1)) {
             val jpgWriter = ImageIO.getImageWritersByFormatName("jpg").next()
             jpgWriter.output = ImageIO.createImageOutputStream(out)
 
-- 
GitLab