From 138040baa8788f79ea4df543d49121dcd2890e47 Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 24 Apr 2025 10:37:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=AE=97=E6=B3=95=E7=9A=84?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/camera2/ndkcamera.cpp | 124 +++++++++++++++++++++++++ app/src/main/cpp/camera2/ndkcamera.h | 1 + 2 files changed, 125 insertions(+) diff --git a/app/src/main/cpp/camera2/ndkcamera.cpp b/app/src/main/cpp/camera2/ndkcamera.cpp index f29a52d1..c9b265c0 100644 --- a/app/src/main/cpp/camera2/ndkcamera.cpp +++ b/app/src/main/cpp/camera2/ndkcamera.cpp @@ -1041,6 +1041,10 @@ NdkCamera::CaptureRequest* NdkCamera::CreateRequest(bool isPreviewRequest, int32 { Setup3DNR(mCharacteristics.get(), request->request, sensitivity); } + else if (m_params.burstRawCapture == 5) + { + SetupTonemapCurve(mCharacteristics.get(), request->request); + } } return request; @@ -2527,6 +2531,19 @@ void NdkCamera::SetupMFNR(ACameraMetadata* characteristics, ACaptureRequest* req ALOGE("Failed to set MTK_MFNR_FEATURE_MFB_MODE, status: %d", status); } + int32_t aeTargetMode = MTK_3A_FEATURE_AE_TARGET_MODE_LE_FIX; + status = ACaptureRequest_setEntry_i32(request, MTK_3A_FEATURE_AE_TARGET_MODE, 1, &aeTargetMode); + if (status != ACAMERA_OK) { + ALOGE("Failed to set MTK_3A_FEATURE_AE_TARGET_MODE: %d", status); + } + + // 设置为长曝光级别(3) + int32_t exposureLevel = MTK_3A_FEATURE_AE_EXPOSURE_LEVEL_LONG; // MTK_3A_FEATURE_AE_EXPOSURE_LEVEL_LONG + status = ACaptureRequest_setEntry_i32(request, MTK_3A_FEATURE_AE_EXPOSURE_LEVEL, 1,&exposureLevel); + if (status != ACAMERA_OK) { + ALOGE("Failed to set exposure level: %d", status); + } + int32_t ispTuning = MTK_CONTROL_CAPTURE_HINT_FOR_ISP_TUNING_MFNR; status = ACaptureRequest_setEntry_i32(request, MTK_CONTROL_CAPTURE_HINT_FOR_ISP_TUNING, 1, &ispTuning); @@ -2671,3 +2688,110 @@ void NdkCamera::SetupHDR(ACameraMetadata* characteristics, ACaptureRequest* requ } } } + +bool NdkCamera::SetupTonemapCurve(ACameraMetadata* characteristics, ACaptureRequest* request) +{ + camera_status_t status; + +#if 1 + int32_t tagCount = 0; + const uint32_t* tags = nullptr; + ACameraMetadata_getAllTags(characteristics, &tagCount, &tags); + for (int32_t i = 0; i < tagCount; i++) { + if (MTK_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES == tags[i]) + { + ALOGI("MTK_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES Tag ID: 0x%x\n", tags[i]); + } + } + + ACameraMetadata_const_entry entry; + status = ACameraMetadata_getConstEntry(characteristics, MTK_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES, &entry); + if (status == ACAMERA_OK) + { + for (int i = 0; i < entry.count; i++) + { + ALOGI("MTK_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES: %d\n", entry.data.i32[i]); + } + } + + +#endif + // MTK_CONTROL_AE_TARGET_FPS_RANGE + // 4. 构建范围值 + int32_t fpsRange[2] = {60, 60}; + + // 5. 设置请求参数 + status = ACaptureRequest_setEntry_i32(request, MTK_CONTROL_AE_TARGET_FPS_RANGE, 2, fpsRange); + if (status != ACAMERA_OK) { + ALOGE("Failed to set MTK_CONTROL_AE_TARGET_FPS_RANGE: %d", status); + return false; + } + + int32_t aeTargetMode = MTK_3A_FEATURE_AE_TARGET_MODE_STAGGER_3EXP; + status = ACaptureRequest_setEntry_i32(request, MTK_3A_FEATURE_AE_TARGET_MODE, 1, &aeTargetMode); + if (status != ACAMERA_OK) { + ALOGE("Failed to set MTK_3A_FEATURE_AE_TARGET_MODE: %d", status); + return false; + } + + + + +#if 0 + + // 创建色调映射曲线点 - 每个点包含(x,y)坐标,表示输入和输出亮度值的映射 + // 这个曲线用于压制高光,减少过曝 + const int numPoints = 5; + float curve[numPoints * 2] = { + 0.0f, 0.0f, // 阴影部分保持不变 + 0.25f, 0.22f, // 稍微压暗中间调 + 0.5f, 0.45f, // 中间调较明显压暗 + 0.75f, 0.65f, // 高光部分明显压暗 + 1.0f, 0.85f // 最亮部分显著压暗 + }; + + // 红色通道曲线 + ACameraMetadata_const_entry entry; + int result = ACaptureRequest_setEntry_float(request, + ACAMERA_TONEMAP_CURVE_RED, + numPoints * 2, + curve); + if (result != ACAMERA_OK) { + ALOGE("Failed to set red tonemap curve: %d", result); + return false; + } + + // 绿色通道曲线 (使用相同的曲线) + result = ACaptureRequest_setEntry_float(request, + ACAMERA_TONEMAP_CURVE_GREEN, + numPoints * 2, + curve); + if (result != ACAMERA_OK) { + ALOGE("Failed to set green tonemap curve: %d", result); + return false; + } + + // 蓝色通道曲线 (使用相同的曲线) + result = ACaptureRequest_setEntry_float(request, + ACAMERA_TONEMAP_CURVE_BLUE, + numPoints * 2, + curve); + if (result != ACAMERA_OK) { + ALOGE("Failed to set blue tonemap curve: %d", result); + return false; + } + + // 设置色调映射模式为曲线模式 + uint8_t tonemapMode = ACAMERA_TONEMAP_MODE_CONTRAST_CURVE; + result = ACaptureRequest_setEntry_u8(request, + ACAMERA_TONEMAP_MODE, + 1, + &tonemapMode); + if (result != ACAMERA_OK) { + ALOGE("Failed to set tonemap mode: %d", result); + return false; + } +#endif + + return true; +} \ No newline at end of file diff --git a/app/src/main/cpp/camera2/ndkcamera.h b/app/src/main/cpp/camera2/ndkcamera.h index af33ea05..ebaea678 100644 --- a/app/src/main/cpp/camera2/ndkcamera.h +++ b/app/src/main/cpp/camera2/ndkcamera.h @@ -209,6 +209,7 @@ protected: void SetupMFNR(ACameraMetadata* characteristics, ACaptureRequest* request, bool ais, int32_t sensitivity); void Setup3DNR(ACameraMetadata* characteristics, ACaptureRequest* request, int32_t sensitivity); void SetupHDR(ACameraMetadata* characteristics, ACaptureRequest* request, int32_t sensitivity); + bool SetupTonemapCurve(ACameraMetadata* characteristics, ACaptureRequest* request); protected: std::mutex m_locker;