mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Use WebP for compressing images.
This commit is contained in:
@@ -102,12 +102,10 @@ class AttachmentCreationTask {
|
||||
}
|
||||
InputStream is = contentResolver.openInputStream(uri);
|
||||
if (is == null) throw new IOException();
|
||||
is = imageCompressor
|
||||
.compressImage(is, contentType);
|
||||
is = imageCompressor.compressImage(is, contentType);
|
||||
long timestamp = System.currentTimeMillis();
|
||||
AttachmentHeader h = messagingManager
|
||||
.addLocalAttachment(groupId, timestamp,
|
||||
ImageCompressor.MIME_TYPE, is);
|
||||
AttachmentHeader h = messagingManager.addLocalAttachment(groupId,
|
||||
timestamp, ImageCompressor.MIME_TYPE, is);
|
||||
tryToClose(is, LOG, WARNING);
|
||||
logDuration(LOG, "Storing attachment", start);
|
||||
return h;
|
||||
|
||||
@@ -11,7 +11,7 @@ public interface ImageCompressor {
|
||||
/**
|
||||
* The MIME type of compressed images
|
||||
*/
|
||||
String MIME_TYPE = "image/jpeg";
|
||||
String MIME_TYPE = "image/webp";
|
||||
|
||||
/**
|
||||
* Load an image from {@code is}, compress it and return an InputStream
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static android.graphics.Bitmap.CompressFormat.JPEG;
|
||||
import static android.graphics.Bitmap.CompressFormat.WEBP;
|
||||
import static android.graphics.BitmapFactory.decodeStream;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
@@ -50,7 +50,7 @@ class ImageCompressorImpl implements ImageCompressor {
|
||||
public InputStream compressImage(Bitmap bitmap) throws IOException {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
for (int quality = 100; quality >= 0; quality -= 10) {
|
||||
if (!bitmap.compress(JPEG, quality, out))
|
||||
if (!bitmap.compress(WEBP, quality, out))
|
||||
throw new IOException();
|
||||
if (out.size() <= MAX_IMAGE_SIZE) {
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
|
||||
@@ -6,6 +6,9 @@ import java.io.InputStream;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public interface TestAvatarCreator {
|
||||
|
||||
String MIME_TYPE = "image/webp";
|
||||
|
||||
@Nullable
|
||||
InputStream getAvatarInputStream() throws IOException;
|
||||
}
|
||||
|
||||
@@ -316,7 +316,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
Message m;
|
||||
try {
|
||||
m = avatarMessageEncoder.encodeUpdateMessage(groupId, 0,
|
||||
"image/jpeg", is).getFirst();
|
||||
TestAvatarCreator.MIME_TYPE, is).getFirst();
|
||||
} catch (IOException e) {
|
||||
throw new DbException(e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user