-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Workaround for hardware JPEG rotation bug on some Samsung devices #3305
Workaround for hardware JPEG rotation bug on some Samsung devices #3305
Conversation
…ge has Exif attribute TAG_ORIENTATION equals to ORIENTATION_NORMAL and does not need to be rotated again
This looks promising. We have been getting reports of gray images on SM-T813 devices too and just assumed the devices were too old. "Blacklisting" all samsung devices is probably a really bad idea, but using this kind of list of affected devices should be good. I don't know how this list could be maintained easier than what you have done so far. Any issues on unaffected devices? Slower captures or something? Isn't it dangerous to change the camera parameters right before requesting a capture? |
Also, do you know if the code could be improved in a way that Here's another device we saw the gray photos issue: SM-T307U and SM-T713 |
I tested this on SM-T813 with 1920x1080 photos, could not tell the difference in performance. Did not measure it precisely though. Normal devices not affected (tested on Xiaomi M1803E7SG).
The previous implementation changes parameters before capture as well. The Android documentation states that's how you do it (https://developer.android.com/reference/android/hardware/Camera). We do the calls on the same thread so no concurrency issues here.
I don't think so. My fix relies on the fact that |
Thanks for the details, I believe it makes sense. Impressive detective work finding this bug! I need some time before being able to test this as I have to catch up with the MLKit changes from another PR, but I would love to see this getting merged. Thoughts @MateusAndrade @mikehardy ? |
android/src/main/java/com/google/android/cameraview/Camera1.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems fine to me. In my experience Samsung has some buggy hardware (they messed up webview hardware rendering for Android 8 too, that was fun to find) just like MIUI has a buggy AOSP implementation. There's nothing to do but trust those that are directly probing the affected devices and accept their workarounds I think.
This seems like a nice way to handle an irritating problem 👍
## [4.0.1](v4.0.0...v4.0.1) (2021-08-06) ### Bug Fixes * Workaround for hardware JPEG rotation bug on some Samsung devices ([#3305](#3305)) ([381f958](381f958)), closes [/github.com//issues/3060#issuecomment-892583205](https://github.com//github.com/react-native-camera/react-native-camera/issues/3060/issues/issuecomment-892583205) [/github.com//pull/3305#issuecomment-893819348](https://github.com//github.com/react-native-camera/react-native-camera/pull/3305/issues/issuecomment-893819348)
🎉 This PR is included in version 4.0.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
@cristianoccazinsp Would it be possible to have this fix in the 3.44 line as well? That's what we use since we aren't ready to move to Google ML Kit for all projects. |
@drash-course that's really up to @MateusAndrade . However, if you are in such situation, I recommend forking the 3.44 yourself and cherry picking specific commits you may be interested in (like this). You can then change your package file to point to your github fork/branch instead. This is what we also do since we stay behind the master branch a few commits and gradually merge from it in order to test all changes thoroughly first and be able to use important fixes right away. |
Description
This PR implements a workaround to avoid this issue: #3060
What is the root cause
Android's
Camera.PictureCallback::onPictureTaken(byte[] data, Camera camera)
is returning a corrupted file. The byte[] data array is full of 0x00 after a few kB of data. This happens when mCameraParameters.setRotation(...) is set to any rotation besides 0 on our Galaxy Tab S2 9.7 Wi-Fi SM-T813.What is the workaround / fix
The facilities in
ResolveTakenPictureAsyncTask.java
can handle the rotation in software. The workaround is to setmCameraParameters.setRotation(0)
, take the picture, and perform the rotation in the async task. To differentiate this "backup" rotation from the rotation performed when "fixOrientation" is set, a new parametersoftwareRotation
has been added toResolveTakenPictureAsyncTask
.The
softwareRotation
is only used for the known affected devices, set inBROKEN_ROTATION_DEVICE_MODELS
. Other devices will continue to use hardware rotation (which is probably faster).How to test
If you don't have an affected device on hand, you can still test this alternate implementation by changing
Camera1::fallbackToSoftwareRotation()
to return true or add your test device model toBROKEN_ROTATION_DEVICE_MODELS
.What can be improved
I only added "SM-G532M" and "SM-T813" which we know have this problem. More devices are probably affected. Since it seems to always be Samsung devices, we could enable this alternate rotation mode for all of them.