do not run alpha check on jpegs

This commit is contained in:
Daniel Gultsch 2021-02-20 10:08:43 +01:00
parent 6bfe16f044
commit 0812bae1ab
3 changed files with 9 additions and 16 deletions

View file

@ -425,7 +425,7 @@ public class HttpDownloadConnection implements Transferable {
private void download() throws Exception { private void download() throws Exception {
InputStream is = null; InputStream is = null;
HttpURLConnection connection = null; HttpURLConnection connection = null;
PowerManager.WakeLock wakeLock = mHttpConnectionManager.createWakeLock("http_download_" + message.getUuid()); final PowerManager.WakeLock wakeLock = mHttpConnectionManager.createWakeLock("http_download_" + message.getUuid());
try { try {
wakeLock.acquire(); wakeLock.acquire();
if (mUseTor || message.getConversation().getAccount().isOnion()) { if (mUseTor || message.getConversation().getAccount().isOnion()) {

View file

@ -296,12 +296,7 @@ public class FileBackend {
if (dimensions != null) { if (dimensions != null) {
return dimensions; return dimensions;
} }
final int rotation; final int rotation = extractRotationFromMediaRetriever(metadataRetriever);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
rotation = extractRotationFromMediaRetriever(metadataRetriever);
} else {
rotation = 0;
}
boolean rotated = rotation == 90 || rotation == 270; boolean rotated = rotation == 90 || rotation == 270;
int height; int height;
try { try {
@ -322,7 +317,6 @@ public class FileBackend {
return rotated ? new Dimensions(width, height) : new Dimensions(height, width); return rotated ? new Dimensions(width, height) : new Dimensions(height, width);
} }
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
private static int extractRotationFromMediaRetriever(MediaMetadataRetriever metadataRetriever) { private static int extractRotationFromMediaRetriever(MediaMetadataRetriever metadataRetriever) {
String r = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION); String r = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION);
try { try {
@ -727,9 +721,9 @@ public class FileBackend {
if (is == null) { if (is == null) {
throw new FileCopyException(R.string.error_not_an_image_file); throw new FileCopyException(R.string.error_not_an_image_file);
} }
Bitmap originalBitmap; final Bitmap originalBitmap;
BitmapFactory.Options options = new BitmapFactory.Options(); final BitmapFactory.Options options = new BitmapFactory.Options();
int inSampleSize = (int) Math.pow(2, sampleSize); final int inSampleSize = (int) Math.pow(2, sampleSize);
Log.d(Config.LOGTAG, "reading bitmap with sample size " + inSampleSize); Log.d(Config.LOGTAG, "reading bitmap with sample size " + inSampleSize);
options.inSampleSize = inSampleSize; options.inSampleSize = inSampleSize;
originalBitmap = BitmapFactory.decodeStream(is, null, options); originalBitmap = BitmapFactory.decodeStream(is, null, options);
@ -737,12 +731,12 @@ public class FileBackend {
if (originalBitmap == null) { if (originalBitmap == null) {
throw new ImageCompressionException("Source file was not an image"); throw new ImageCompressionException("Source file was not an image");
} }
if (hasAlpha(originalBitmap)) { if (!"image/jpeg".equals(options.outMimeType) && hasAlpha(originalBitmap)) {
originalBitmap.recycle(); originalBitmap.recycle();
throw new ImageCompressionException("Source file had alpha channel"); throw new ImageCompressionException("Source file had alpha channel");
} }
Bitmap scaledBitmap = resize(originalBitmap, Config.IMAGE_SIZE); Bitmap scaledBitmap = resize(originalBitmap, Config.IMAGE_SIZE);
int rotation = getRotation(image); final int rotation = getRotation(image);
scaledBitmap = rotate(scaledBitmap, rotation); scaledBitmap = rotate(scaledBitmap, rotation);
boolean targetSizeReached = false; boolean targetSizeReached = false;
int quality = Config.IMAGE_QUALITY; int quality = Config.IMAGE_QUALITY;
@ -758,7 +752,7 @@ public class FileBackend {
quality -= 5; quality -= 5;
} }
scaledBitmap.recycle(); scaledBitmap.recycle();
} catch (FileNotFoundException e) { } catch (final FileNotFoundException e) {
throw new FileCopyException(R.string.error_file_not_found); throw new FileCopyException(R.string.error_file_not_found);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

View file

@ -54,7 +54,7 @@ public class AttachFileToConversationRunnable implements Runnable, MediaTranscod
} }
boolean isVideoMessage() { boolean isVideoMessage() {
return this.isVideoMessage && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2; return this.isVideoMessage;
} }
private void processAsFile() { private void processAsFile() {
@ -89,7 +89,6 @@ public class AttachFileToConversationRunnable implements Runnable, MediaTranscod
} }
} }
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
private void processAsVideo() throws FileNotFoundException { private void processAsVideo() throws FileNotFoundException {
Log.d(Config.LOGTAG,"processing file as video"); Log.d(Config.LOGTAG,"processing file as video");
mXmppConnectionService.startForcingForegroundNotification(); mXmppConnectionService.startForcingForegroundNotification();