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