From 53c1e9c376646fc341deec27ae1ee644476722a0 Mon Sep 17 00:00:00 2001 From: Matthew Date: Sat, 20 Jul 2024 11:49:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=99=BD=E5=B9=B3=E8=A1=A1?= =?UTF-8?q?=E7=9A=84=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/PhoneDevice.cpp | 1 + app/src/main/cpp/camera2/ndkcamera.cpp | 33 ++++++++++++++++---------- app/src/main/cpp/camera2/ndkcamera.h | 8 ++++++- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index 98a00b22..759725b4 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -1177,6 +1177,7 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector< params.zoom = mPhotoInfo.zoom; params.zoomRatio = mPhotoInfo.zoomRatio; params.requestTemplate = mPhotoInfo.requestTemplate; + params.awbMode = mPhotoInfo.awbMode; params.wait3ALocked = mPhotoInfo.wait3ALocked; if (params.requestTemplate <= 0 || params.requestTemplate > 5) { diff --git a/app/src/main/cpp/camera2/ndkcamera.cpp b/app/src/main/cpp/camera2/ndkcamera.cpp index 1edb9595..4c06a806 100644 --- a/app/src/main/cpp/camera2/ndkcamera.cpp +++ b/app/src/main/cpp/camera2/ndkcamera.cpp @@ -118,6 +118,7 @@ NdkCamera::NdkCamera(int32_t width, int32_t height, const NdkCamera::CAMERA_PARA m_imagesCaptured = ~0; afSupported = false; + awbMode = ACAMERA_CONTROL_AWB_MODE_AUTO; aeLockAvailable = false; awbLockAvailable = false; @@ -275,7 +276,7 @@ int NdkCamera::open(const std::string& cameraId) { { ACameraMetadata_const_entry e = {0}; - camera_status_t status = ACameraMetadata_getConstEntry(camera_metadata,ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS, &e); + status = ACameraMetadata_getConstEntry(camera_metadata,ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS, &e); // format of the data: format, width, height, input?, type int32 // DisplayDimension foundRes(4000, 4000); @@ -383,9 +384,9 @@ int NdkCamera::open(const std::string& cameraId) { { for (int idx = 0; idx < e.count; idx++) { - if (ACAMERA_CONTROL_AWB_MODE_AUTO == e.data.u8[idx]) + if (m_params.awbMode == e.data.u8[idx]) { - awbSupported = true; + awbMode = m_params.awbMode; break; } // unsigned int m = e.data.u8[idx]; @@ -592,8 +593,8 @@ int NdkCamera::open(const std::string& cameraId) { uint8_t edgeMode = ACAMERA_EDGE_MODE_FAST; status = ACaptureRequest_setEntry_u8(capture_request, ACAMERA_EDGE_MODE, 1, &edgeMode); - if (afSupported && m_params.autoFocus) { - + if (afSupported && m_params.autoFocus) + { if (!m_params.zoom) { if (maxRegions[2] > 0) @@ -715,9 +716,9 @@ int NdkCamera::open(const std::string& cameraId) { // TODO: // m_imagesCaptured = 0; - if (awbSupported) + // if (awbSupported) { - uint8_t awbMode = ACAMERA_CONTROL_AWB_MODE_AUTO; + // uint8_t awbMode = ACAMERA_CONTROL_AWB_MODE_AUTO; status = ACaptureRequest_setEntry_u8(capture_request, ACAMERA_CONTROL_AWB_MODE, 1, &awbMode); } @@ -1214,12 +1215,17 @@ void NdkCamera::onCaptureCompleted(ACameraCaptureSession* session, ACaptureReque status = ACameraMetadata_getConstEntry(result, ACAMERA_CONTROL_AF_STATE, &val); mResult.afState = (status == ACAMERA_OK) ? *(val.data.u8) : ACAMERA_CONTROL_AF_STATE_INACTIVE; - ALOGW("3ASTATE: ae=%u awb=%u af=%u", (uint32_t)mResult.aeState, (uint32_t)mResult.awbState, (uint32_t)mResult.afState); + val = { 0 }; + status = ACameraMetadata_getConstEntry(result, ACAMERA_CONTROL_AWB_MODE, &val); + mResult.awbMode = (status == ACAMERA_OK) ? *(val.data.u8) : ACAMERA_CONTROL_AWB_MODE_OFF; + + ALOGW("3ASTATE: AES=%u AWBS=%u AFS=%u", (uint32_t)mResult.aeState, (uint32_t)mResult.awbState, (uint32_t)mResult.afState); - if (awbSupported && awbLockAvailable && mResult.awbState == ACAMERA_CONTROL_AWB_STATE_CONVERGED) + if ((mResult.awbMode == ACAMERA_CONTROL_AWB_MODE_AUTO) && awbLockAvailable && !mResult.awbLockSetted && mResult.awbState == ACAMERA_CONTROL_AWB_STATE_CONVERGED) { uint8_t awbLock = ACAMERA_CONTROL_AWB_LOCK_ON; status = ACaptureRequest_setEntry_u8(capture_request, ACAMERA_CONTROL_AWB_LOCK, 1, &awbLock); + mResult.awbLockSetted = 1; } if (m_params.autoExposure != 0) @@ -1230,10 +1236,11 @@ void NdkCamera::onCaptureCompleted(ACameraCaptureSession* session, ACaptureReque status = ACaptureRequest_setEntry_u8(capture_request, ACAMERA_CONTROL_AE_PRECAPTURE_TRIGGER, 1, &aePrecatureTrigger); } - if (aeLockAvailable && (mResult.aeState == ACAMERA_CONTROL_AE_STATE_CONVERGED || mResult.aeState == ACAMERA_CONTROL_AE_STATE_FLASH_REQUIRED)) + if (aeLockAvailable && !mResult.aeLockSetted && (mResult.aeState == ACAMERA_CONTROL_AE_STATE_CONVERGED || mResult.aeState == ACAMERA_CONTROL_AE_STATE_FLASH_REQUIRED)) { uint8_t aeLock = ACAMERA_CONTROL_AE_LOCK_ON; status = ACaptureRequest_setEntry_u8(capture_request, ACAMERA_CONTROL_AE_LOCK, 1,&aeLock); + mResult.aeLockSetted = 1; } } @@ -1267,7 +1274,7 @@ void NdkCamera::onCaptureCompleted(ACameraCaptureSession* session, ACaptureReque } else { - if (awbSupported) + if (awbMode == ACAMERA_CONTROL_AWB_MODE_AUTO) { if (m_params.wait3ALocked) { @@ -1278,7 +1285,7 @@ void NdkCamera::onCaptureCompleted(ACameraCaptureSession* session, ACaptureReque } else { - if (mResult.awbState != ACAMERA_CONTROL_AWB_STATE_CONVERGED) + if (mResult.awbState != ACAMERA_CONTROL_AWB_STATE_CONVERGED && mResult.awbState != ACAMERA_CONTROL_AWB_STATE_LOCKED) { return; } @@ -1296,7 +1303,7 @@ void NdkCamera::onCaptureCompleted(ACameraCaptureSession* session, ACaptureReque } else { - if (mResult.aeState != ACAMERA_CONTROL_AE_STATE_CONVERGED && mResult.aeState != ACAMERA_CONTROL_AE_STATE_FLASH_REQUIRED) + if (mResult.aeState != ACAMERA_CONTROL_AE_STATE_CONVERGED && mResult.aeState != ACAMERA_CONTROL_AE_STATE_FLASH_REQUIRED && mResult.aeState != ACAMERA_CONTROL_AE_STATE_LOCKED) { return; } diff --git a/app/src/main/cpp/camera2/ndkcamera.h b/app/src/main/cpp/camera2/ndkcamera.h index 260a8e78..d4fef490 100644 --- a/app/src/main/cpp/camera2/ndkcamera.h +++ b/app/src/main/cpp/camera2/ndkcamera.h @@ -82,6 +82,7 @@ public: int compensation; float zoomRatio; uint8_t requestTemplate; + uint8_t awbMode; }; @@ -97,9 +98,14 @@ public: int32_t sensitivity; int32_t compensation; uint8_t sceneMode; + uint8_t awbMode; float zoomRatio; uint8_t avgY; uint64_t duration; + + uint8_t awbLockSetted : 1; + uint8_t aeLockSetted : 1; + uint8_t afLockSetted : 1; }; NdkCamera(int32_t width, int32_t height, const CAMERA_PARAMS& params); @@ -145,7 +151,7 @@ protected: bool sceneModeSupported; bool afSupported; - bool awbSupported; + uint8_t awbMode; bool aeLockAvailable; bool awbLockAvailable;