diff options
author | Christian Schneppe <christian@pix-art.de> | 2017-03-24 22:20:34 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2017-03-26 21:44:05 +0200 |
commit | 0e29554b975262c47772b8579a4344c68f6f22a6 (patch) | |
tree | 7e6fd88623aeda4f0ea09b6b4c763f6e673d59f6 /src/main/java/de/pixart | |
parent | b02745073c3bc324054326b15a934c57ee36d1e9 (diff) |
make image compression configurable
Diffstat (limited to 'src/main/java/de/pixart')
3 files changed, 30 insertions, 6 deletions
diff --git a/src/main/java/de/pixart/messenger/Config.java b/src/main/java/de/pixart/messenger/Config.java index 1b8290970..3bd5171ae 100644 --- a/src/main/java/de/pixart/messenger/Config.java +++ b/src/main/java/de/pixart/messenger/Config.java @@ -72,10 +72,8 @@ public final class Config { public static final int AVATAR_SIZE = 480; public static final Bitmap.CompressFormat AVATAR_FORMAT = Bitmap.CompressFormat.JPEG; - public static final int IMAGE_SIZE = 3840; public static final Bitmap.CompressFormat IMAGE_FORMAT = Bitmap.CompressFormat.JPEG; public static final int IMAGE_QUALITY = 75; - public static final int IMAGE_MAX_SIZE = 1 * 1024 * 1024; // 1 MiB public static final int DEFAULT_ZOOM = 15; //for locations diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java index 7f367f2b7..01a4070f1 100644 --- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java @@ -249,7 +249,7 @@ public class FileBackend { } File file = new File(path); long size = file.length(); - if (size == 0 || size >= Config.IMAGE_MAX_SIZE) { + if (size == 0 || size >= mXmppConnectionService.getCompressImageSizePreference()) { return false; } BitmapFactory.Options options = new BitmapFactory.Options(); @@ -259,7 +259,7 @@ public class FileBackend { if (options == null || options.outMimeType == null || options.outHeight <= 0 || options.outWidth <= 0) { return false; } - return (options.outWidth <= Config.IMAGE_SIZE && options.outHeight <= Config.IMAGE_SIZE && options.outMimeType.contains(Config.IMAGE_FORMAT.name().toLowerCase())); + return (options.outWidth <= mXmppConnectionService.getCompressImageResolutionPreference() && options.outHeight <= mXmppConnectionService.getCompressImageResolutionPreference() && options.outMimeType.contains(Config.IMAGE_FORMAT.name().toLowerCase())); } catch (FileNotFoundException e) { return false; } @@ -370,7 +370,7 @@ public class FileBackend { if (originalBitmap == null) { throw new FileCopyException(R.string.error_not_an_image_file); } - Bitmap scaledBitmap = resize(originalBitmap, Config.IMAGE_SIZE); + Bitmap scaledBitmap = resize(originalBitmap, mXmppConnectionService.getCompressImageResolutionPreference()); int rotation = getRotation(image); scaledBitmap = rotate(scaledBitmap, rotation); boolean targetSizeReached = false; @@ -382,7 +382,7 @@ public class FileBackend { throw new FileCopyException(R.string.error_compressing_image); } os.flush(); - targetSizeReached = file.length() <= Config.IMAGE_MAX_SIZE || quality <= 50; + targetSizeReached = file.length() <= mXmppConnectionService.getCompressImageSizePreference() || quality <= 50; quality -= 5; } scaledBitmap.recycle(); diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index 936a4591f..6cfef225b 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -888,6 +888,32 @@ public class XmppConnectionService extends Service { return getPreferences().getString("picture_compression", "auto"); } + public int getCompressImageResolutionPreference() { + switch (getPreferences().getString("image_compression", "high")) { + case "low": + return 720; + case "mid": + return 1920; + case "high": + return 3840; + default: + return 3840; + } + } + + public int getCompressImageSizePreference() { + switch (getPreferences().getString("image_compression", "high")) { + case "low": + return 209715; // 0.2 * 1024 * 1024 = 209715 (0.2 MiB) + case "mid": + return 524288; // 0.5 * 1024 * 1024 = 524288 (0.5 MiB) + case "high": + return 1048576; // 1 * 1024 * 1024 = 1048576 (1 MiB) + default: + return 1048576; + } + } + private int getCompressVideoResolutionPreference() { switch (getPreferences().getString("video_compression", "high")) { case "low": |