A cheap attempt at a native Bluesky client for Android

Image Compression: Always compress to JPEG

Force image compression to use the JPEG format, regardless of the original image's mime type (e.g., PNG, WebP). This allows the compression loop to reduce file size more effectively by adjusting the quality, which was previously skipped for PNGs.

+6 -11
+6 -11
app/src/main/java/industries/geesawra/monarch/datalayer/Compressor.kt
··· 5 5 import android.graphics.BitmapFactory 6 6 import android.net.Uri 7 7 import android.provider.OpenableColumns 8 + import android.util.Log 8 9 import androidx.annotation.OptIn 9 10 import androidx.core.net.toUri 10 11 import androidx.media3.common.MediaItem ··· 81 82 82 83 ensureActive() 83 84 84 - val compressFormat = when (mimeType) { 85 - "image/png" -> Bitmap.CompressFormat.PNG 86 - "image/jpeg" -> Bitmap.CompressFormat.JPEG 87 - "image/webp" -> 88 - Bitmap.CompressFormat.WEBP_LOSSLESS 89 - 90 - else -> Bitmap.CompressFormat.JPEG 91 - } 92 - 85 + val compressFormat = Bitmap.CompressFormat.JPEG 93 86 var outputBytes: ByteArray 94 87 var quality = 90 88 + val ogSize = inputBytes.size 95 89 96 90 do { 97 91 ByteArrayOutputStream().use { outputStream -> ··· 101 95 } 102 96 } while (isActive && 103 97 outputBytes.size > compressionThreshold && 104 - quality > 5 && 105 - compressFormat != Bitmap.CompressFormat.PNG 98 + quality > 5 106 99 ) 107 100 108 101 val ob = BitmapFactory.decodeByteArray(outputBytes, 0, outputBytes.size) 102 + 103 + Log.d("Compressor", "before: $ogSize, after: ${outputBytes.size}") 109 104 110 105 CompressedImage( 111 106 data = outputBytes,