Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Mirror selfies on Android #129

Merged
merged 5 commits into from May 3, 2021
Merged

fix: Mirror selfies on Android #129

merged 5 commits into from May 3, 2021

Conversation

mrousavy
Copy link
Owner

@mrousavy mrousavy commented May 3, 2021

What

This PR automatically horizontally flips (= mirrors) images taken from the front camera.

It is achieved by decoding the received byte[] to a Bitmap, applying a Matrix with a scaleX of -1, then converting it back to a byte[]. I am not fully happy with that approach, as I'd like to avoid the byte[] -> Bitmap -> byte[] approach if possible.

Benchmarks show that horizontally flipping an image takes ~24ms on my Huawai P10.

Back camera (no flipping):

2021-05-03 18:57:54.478 31448-31448/com.mrousavy.camera.example I/CameraView.performance: Session configured in 200 ms! Camera: androidx.camera.lifecycle.LifecycleCamera@c475d4
2021-05-03 18:58:17.609 31448-31729/com.mrousavy.camera.example I/CameraView.performance: Finished creating temp file in 1ms
2021-05-03 18:58:18.028 31448-31448/com.mrousavy.camera.example I/CameraView.performance: Finished image capture in 413ms
2021-05-03 18:58:18.033 31448-31729/com.mrousavy.camera.example I/CameraView.performance: Finished image saving in 3ms
2021-05-03 18:58:18.035 31448-31448/com.mrousavy.camera.example I/CameraView.performance: Finished function execution in 444ms

Front camera (flipping):

2021-05-03 18:58:50.155 31448-31448/com.mrousavy.camera.example I/CameraView.performance: Session configured in 129 ms! Camera: androidx.camera.lifecycle.LifecycleCamera@4e5ccc6
2021-05-03 18:58:52.032 31448-31729/com.mrousavy.camera.example I/CameraView.performance: Finished creating temp file in 2ms
2021-05-03 18:58:52.345 31448-31448/com.mrousavy.camera.example I/CameraView.performance: Finished image capture in 314ms
2021-05-03 18:58:52.379 31448-31729/com.mrousavy.camera.example I/CameraView.performance: Flipping Image took 31 ms.
2021-05-03 18:58:52.380 31448-31729/com.mrousavy.camera.example I/CameraView.performance: Finished image saving in 33ms
2021-05-03 18:58:52.381 31448-31448/com.mrousavy.camera.example I/CameraView.performance: Finished function execution in 353ms

Changes

  • Add flipImage to ImageProxy+save - a function that flips the given byte[].
  • Call flipImage in ImageProxy+save when flipHorizontally ist true

Side-effects

  • Taking selfies takes a few milliseconds longer (~24ms on my Huawai P10)

Tested on

  • Huawai P10

Related issues

Closes #74

@mrousavy mrousavy added 🐛 bug Something isn't working 🤖 android Issue affects the Android platform labels May 3, 2021
@mrousavy mrousavy merged commit f577147 into main May 3, 2021
@mrousavy mrousavy deleted the fix/mirror-selfies-android branch May 3, 2021 17:14
@mrousavy mrousavy mentioned this pull request May 3, 2021
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖 android Issue affects the Android platform 🐛 bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

✨ Mirror selfie images on Android
1 participant