use of org.thoughtcrime.securesms.util.Stopwatch in project Signal-Android by WhisperSystems.
the class CameraXUtil method transformByteArray.
private static byte[] transformByteArray(@NonNull byte[] data, @Nullable Rect cropRect, int rotation, boolean flip) throws IOException {
Stopwatch stopwatch = new Stopwatch("transform");
Bitmap in;
if (cropRect != null) {
BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(data, 0, data.length, false);
in = decoder.decodeRegion(cropRect, new BitmapFactory.Options());
decoder.recycle();
stopwatch.split("crop");
} else {
in = BitmapFactory.decodeByteArray(data, 0, data.length);
}
Bitmap out = in;
if (rotation != 0 || flip) {
Matrix matrix = new Matrix();
matrix.postRotate(rotation);
if (flip) {
matrix.postScale(-1, 1);
matrix.postTranslate(in.getWidth(), 0);
}
out = Bitmap.createBitmap(in, 0, 0, in.getWidth(), in.getHeight(), matrix, true);
}
byte[] transformedData = toJpegBytes(out);
stopwatch.split("transcode");
in.recycle();
out.recycle();
stopwatch.stop(TAG);
return transformedData;
}
use of org.thoughtcrime.securesms.util.Stopwatch in project Signal-Android by WhisperSystems.
the class Camera1Fragment method onCaptureClicked.
private void onCaptureClicked() {
orderEnforcer.reset();
Stopwatch fastCaptureTimer = new Stopwatch("Capture");
camera.capture((jpegData, frontFacing) -> {
fastCaptureTimer.split("captured");
Transformation<Bitmap> transformation = frontFacing ? new MultiTransformation<>(new CenterCrop(), new FlipTransformation()) : new CenterCrop();
GlideApp.with(this).asBitmap().load(jpegData).transform(transformation).override(cameraPreview.getWidth(), cameraPreview.getHeight()).into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
fastCaptureTimer.split("transform");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
resource.compress(Bitmap.CompressFormat.JPEG, 80, stream);
fastCaptureTimer.split("compressed");
byte[] data = stream.toByteArray();
fastCaptureTimer.split("bytes");
fastCaptureTimer.stop(TAG);
controller.onImageCaptured(data, resource.getWidth(), resource.getHeight());
}
@Override
public void onLoadFailed(@Nullable Drawable errorDrawable) {
controller.onCameraError();
}
});
});
}
use of org.thoughtcrime.securesms.util.Stopwatch in project Signal-Android by WhisperSystems.
the class MediaRepository method getMediaInBucket.
@WorkerThread
@NonNull
private List<Media> getMediaInBucket(@NonNull Context context, @NonNull String bucketId) {
Stopwatch stopwatch = new Stopwatch("getMediaInBucket");
List<Media> images = getMediaInBucket(context, bucketId, Images.Media.EXTERNAL_CONTENT_URI, true);
List<Media> videos = getMediaInBucket(context, bucketId, Video.Media.EXTERNAL_CONTENT_URI, false);
List<Media> media = new ArrayList<>(images.size() + videos.size());
stopwatch.split("post fetch");
media.addAll(images);
media.addAll(videos);
Collections.sort(media, (o1, o2) -> Long.compare(o2.getDate(), o1.getDate()));
stopwatch.split("post sort");
stopwatch.stop(TAG);
return media;
}
use of org.thoughtcrime.securesms.util.Stopwatch in project Signal-Android by WhisperSystems.
the class LiveRecipientCache method warmUp.
@AnyThread
public void warmUp() {
if (warmedUp.getAndSet(true)) {
return;
}
Stopwatch stopwatch = new Stopwatch("recipient-warm-up");
SignalExecutors.BOUNDED.execute(() -> {
ThreadDatabase threadDatabase = SignalDatabase.threads();
List<Recipient> recipients = new ArrayList<>();
try (ThreadDatabase.Reader reader = threadDatabase.readerFor(threadDatabase.getRecentConversationList(THREAD_CACHE_WARM_MAX, false, false))) {
int i = 0;
ThreadRecord record = null;
while ((record = reader.getNext()) != null && i < THREAD_CACHE_WARM_MAX) {
recipients.add(record.getRecipient());
i++;
}
}
Log.d(TAG, "Warming up " + recipients.size() + " thread recipients.");
addToCache(recipients);
stopwatch.split("thread");
if (SignalStore.registrationValues().isRegistrationComplete() && SignalStore.account().getAci() != null) {
try (Cursor cursor = SignalDatabase.recipients().getNonGroupContacts(false)) {
int count = 0;
while (cursor != null && cursor.moveToNext() && count < CONTACT_CACHE_WARM_MAX) {
RecipientId id = RecipientId.from(CursorUtil.requireLong(cursor, RecipientDatabase.ID));
Recipient.resolved(id);
count++;
}
Log.d(TAG, "Warmed up " + count + " contact recipient.");
stopwatch.split("contact");
}
}
stopwatch.stop(TAG);
});
}
use of org.thoughtcrime.securesms.util.Stopwatch in project Signal-Android by WhisperSystems.
the class QrCode method create.
@NonNull
public static Bitmap create(@Nullable String data, @ColorInt int foregroundColor, @ColorInt int backgroundColor) {
if (data == null || data.length() == 0) {
Log.w(TAG, "No data");
return Bitmap.createBitmap(512, 512, Bitmap.Config.ARGB_8888);
}
try {
Stopwatch stopwatch = new Stopwatch("QrGen");
QRCodeWriter qrCodeWriter = new QRCodeWriter();
BitMatrix qrData = qrCodeWriter.encode(data, BarcodeFormat.QR_CODE, 512, 512);
int qrWidth = qrData.getWidth();
int qrHeight = qrData.getHeight();
int[] pixels = new int[qrWidth * qrHeight];
for (int y = 0; y < qrHeight; y++) {
int offset = y * qrWidth;
for (int x = 0; x < qrWidth; x++) {
pixels[offset + x] = qrData.get(x, y) ? foregroundColor : backgroundColor;
}
}
stopwatch.split("Write pixels");
Bitmap bitmap = Bitmap.createBitmap(pixels, qrWidth, qrHeight, Bitmap.Config.ARGB_8888);
stopwatch.split("Create bitmap");
stopwatch.stop(TAG);
return bitmap;
} catch (WriterException e) {
Log.w(TAG, e);
return Bitmap.createBitmap(512, 512, Bitmap.Config.ARGB_8888);
}
}
Aggregations