Updated image compression parameters.

This commit is contained in:
Greyson Parrelli
2021-02-08 15:39:04 -05:00
committed by Cody Henthorne
parent 3bdf2e7e2c
commit 236e1ba885
7 changed files with 227 additions and 32 deletions

View File

@@ -33,6 +33,13 @@ public abstract class MediaConstraints {
public abstract int getImageMaxHeight(Context context);
public abstract int getImageMaxSize(Context context);
/**
* Provide a list of dimensions that should be attempted during compression. We will keep moving
* down the list until the image can be scaled to fit under {@link #getImageMaxSize(Context)}.
* The first entry in the list should match your max width/height.
*/
public abstract int[] getImageDimensionTargets(Context context);
public abstract int getGifMaxSize(Context context);
public abstract int getVideoMaxSize(Context context);

View File

@@ -24,6 +24,19 @@ final class MmsMediaConstraints extends MediaConstraints {
return Math.max(MIN_IMAGE_DIMEN, getOverriddenMmsConfig(context).getMaxImageHeight());
}
@Override
public int[] getImageDimensionTargets(Context context) {
int[] targets = new int[4];
targets[0] = getImageMaxHeight(context);
for (int i = 1; i < targets.length; i++) {
targets[i] = targets[i - 1] / 2;
}
return targets;
}
@Override
public int getImageMaxSize(Context context) {
return getMaxMessageSize(context);

View File

@@ -7,10 +7,13 @@ import org.thoughtcrime.securesms.util.Util;
public class PushMediaConstraints extends MediaConstraints {
private static final int MAX_IMAGE_DIMEN_LOWMEM = 768;
private static final int MAX_IMAGE_DIMEN = 4096;
private static final int MAX_IMAGE_DIMEN = 1599;
private static final int KB = 1024;
private static final int MB = 1024 * KB;
private static final int[] FALLBACKS = { MAX_IMAGE_DIMEN, 1024, 768, 512 };
private static final int[] FALLBACKS_LOWMEM = { MAX_IMAGE_DIMEN_LOWMEM, 512 };
@Override
public int getImageMaxWidth(Context context) {
return Util.isLowMemory(context) ? MAX_IMAGE_DIMEN_LOWMEM : MAX_IMAGE_DIMEN;
@@ -23,7 +26,13 @@ public class PushMediaConstraints extends MediaConstraints {
@Override
public int getImageMaxSize(Context context) {
return 6 * MB;
//noinspection PointlessArithmeticExpression
return 1 * MB;
}
@Override
public int[] getImageDimensionTargets(Context context) {
return Util.isLowMemory(context) ? FALLBACKS_LOWMEM : FALLBACKS;
}
@Override