diff options
author | Yin-Chia Yeh <yinchiayeh@google.com> | 2018-01-23 15:29:14 -0800 |
---|---|---|
committer | Yin-Chia Yeh <yinchiayeh@google.com> | 2018-01-25 18:47:51 +0000 |
commit | 4acd76e647a0e229fda04c244eedb80e3218795d (patch) | |
tree | 9d2f09a1a59ac3289e9785f763b72b69882238ff | |
parent | 406406fb90e8c8525e34f2d6d550b715c4f37c33 (diff) |
External Camera: fix aspect ratio/crop issue
Also switch to new EXTERNAL hardware level.
Test: ImageReaderTest#testAllOutputYUVResolutions pass
Bug: 72261912
Change-Id: I95f05a20827b413bfa480b0336fff395159678eb
-rw-r--r-- | camera/device/3.4/default/ExternalCameraDevice.cpp | 3 | ||||
-rw-r--r-- | camera/device/3.4/default/ExternalCameraDeviceSession.cpp | 20 |
2 files changed, 18 insertions, 5 deletions
diff --git a/camera/device/3.4/default/ExternalCameraDevice.cpp b/camera/device/3.4/default/ExternalCameraDevice.cpp index 4ad1768910..c1f6114577 100644 --- a/camera/device/3.4/default/ExternalCameraDevice.cpp +++ b/camera/device/3.4/default/ExternalCameraDevice.cpp @@ -227,8 +227,7 @@ do { \ status_t ExternalCameraDevice::initDefaultCharsKeys( ::android::hardware::camera::common::V1_0::helper::CameraMetadata* metadata) { - // TODO: changed to HARDWARELEVEL_EXTERNAL later - const uint8_t hardware_level = ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED; + const uint8_t hardware_level = ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_EXTERNAL; UPDATE(ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL, &hardware_level, 1); // android.colorCorrection diff --git a/camera/device/3.4/default/ExternalCameraDeviceSession.cpp b/camera/device/3.4/default/ExternalCameraDeviceSession.cpp index 507f092d7c..2face781d5 100644 --- a/camera/device/3.4/default/ExternalCameraDeviceSession.cpp +++ b/camera/device/3.4/default/ExternalCameraDeviceSession.cpp @@ -57,8 +57,9 @@ const float kMinAspectRatio = 1.f; HandleImporter ExternalCameraDeviceSession::sHandleImporter; bool isAspectRatioClose(float ar1, float ar2) { - const float kAspectRatioMatchThres = 0.01f; // This threshold is good enough to distinguish + const float kAspectRatioMatchThres = 0.025f; // This threshold is good enough to distinguish // 4:3/16:9/20:9 + // 1.33 / 1.78 / 2 return (std::abs(ar1 - ar2) < kAspectRatioMatchThres); } @@ -93,8 +94,8 @@ CroppingType ExternalCameraDeviceSession::initCroppingType( const std::vector<SupportedV4L2Format>& sortedFmts) { const auto& maxSize = sortedFmts[sortedFmts.size() - 1]; float maxSizeAr = ASPECT_RATIO(maxSize); - float minAr = kMinAspectRatio; - float maxAr = kMaxAspectRatio; + float minAr = kMaxAspectRatio; + float maxAr = kMinAspectRatio; for (const auto& fmt : sortedFmts) { float ar = ASPECT_RATIO(fmt); if (ar < minAr) { @@ -724,11 +725,24 @@ int ExternalCameraDeviceSession::OutputThread::getCropRect( ALOGE("%s: out is null", __FUNCTION__); return -1; } + uint32_t inW = inSize.width; uint32_t inH = inSize.height; uint32_t outW = outSize.width; uint32_t outH = outSize.height; + // Handle special case where aspect ratio is close to input but scaled + // dimension is slightly larger than input + float arIn = ASPECT_RATIO(inSize); + float arOut = ASPECT_RATIO(outSize); + if (isAspectRatioClose(arIn, arOut)) { + out->left = 0; + out->top = 0; + out->width = inW; + out->height = inH; + return 0; + } + if (ct == VERTICAL) { uint64_t scaledOutH = static_cast<uint64_t>(outH) * inW / outW; if (scaledOutH > inH) { |