feat: implement camera metering modes and scene change detection

This commit is contained in:
Hinnka committed 2026-05-04 14:07:21 +08:00
1 parent c5f2dc51d3
commit 7ff18f902a
14 files changed
+344 -45

No files matched your search

+2 -1
View File
@@ -5,7 +5,8 @@
"Bash(./gradlew :app:compileDefaultDebugKotlin)",
"Bash(./gradlew :app:compileDebugKotlin)",
"Bash(grep:*)",
"Bash(./gradlew compileDebugKotlin)"
"Bash(./gradlew compileDebugKotlin)",
"Bash(./gradlew assembleDebug)"
]
}
}
@@ -83,6 +83,10 @@ class Camera2Controller(private val context: Context) {
private const val STATE_WAITING_NON_PRECAPTURE =
3 // Waiting for the exposure state to be something other than precapture.
private const val STATE_PICTURE_TAKEN = 4 // Picture is already taken.
// 场景变化检测阈值
private const val SCENE_CHANGE_EXPOSURE_RATIO = 3.0 // 曝光乘积变化超过 3x (~1.6 EV) 判定为场景变化
private const val SCENE_CHANGE_CONFIRM_FRAMES = 3 // 连续 N 帧检测到变化才确认
}
private val cameraManager: CameraManager by lazy {
@@ -192,6 +196,21 @@ class Camera2Controller(private val context: Context) {
@Volatile
private var lastCaptureResult: TotalCaptureResult? = null
// 场景变化检测:用于替代固定延迟恢复连续对焦
private var isFocusLockedWaitingForSceneChange = false
private var focusLockedReferenceIso: Int = 0
private var focusLockedReferenceExposureNs: Long = 0L
private var sceneChangeFrameCount = 0
// 高光优先测光:最亮区域坐标(归一化 0-1)及平滑状态
@Volatile
private var highlightPointX: Float = 0.5f
@Volatile
private var highlightPointY: Float = 0.5f
private var highlightPointSmoothedX: Float = 0.5f
private var highlightPointSmoothedY: Float = 0.5f
private var highlightPointInitialized = false
// 图片拍摄回调(携带 CaptureInfo, CameraCharacteristics 和 CaptureResult 用于 RAW 处理)
var onImageCaptured: ((SafeImage, CaptureInfo, CameraCharacteristics?, CaptureResult?) -> Unit)? = null
@@ -311,11 +330,37 @@ class Camera2Controller(private val context: Context) {
CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED -> {
// 对焦成功并锁定
_state.value = _state.value.copy(focusSuccess = true)
// 记录当前曝光值作为场景变化检测的参考基准
recordFocusLockExposure(result)
}
CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED -> {
// 对焦失败但已锁定
_state.value = _state.value.copy(focusSuccess = false)
recordFocusLockExposure(result)
}
}
}
// 场景变化检测:对焦锁定后持续监测曝光变化
if (isFocusLockedWaitingForSceneChange) {
val currentIso = result.get(CaptureResult.SENSOR_SENSITIVITY) ?: 0
val currentExposure = result.get(CaptureResult.SENSOR_EXPOSURE_TIME) ?: 0L
if (focusLockedReferenceIso > 0 && focusLockedReferenceExposureNs > 0 &&
currentIso > 0 && currentExposure > 0L
) {
val refProduct = focusLockedReferenceIso.toDouble() * focusLockedReferenceExposureNs.toDouble()
val curProduct = currentIso.toDouble() * currentExposure.toDouble()
if (refProduct > 0) {
val ratio = if (curProduct > refProduct) curProduct / refProduct else refProduct / curProduct
if (ratio > SCENE_CHANGE_EXPOSURE_RATIO) {
sceneChangeFrameCount++
if (sceneChangeFrameCount >= SCENE_CHANGE_CONFIRM_FRAMES) {
restoreContinuousAf()
}
} else {
sceneChangeFrameCount = 0
}
}
}
}
@@ -1161,6 +1206,9 @@ class Camera2Controller(private val context: Context) {
captureSession = session
try {
// 根据测光模式设置默认 AE 区域
applyMeteringRegions()
// 开始预览
// 关键修复: 不再动态添加 surface,因为已经在创建 builder 时添加了
previewRequestBuilder?.let { builder ->
@@ -2164,6 +2212,111 @@ class Camera2Controller(private val context: Context) {
}
}
/**
* 设置测光模式
*/
fun setMeteringMode(mode: MeteringMode) {
_state.value = _state.value.copy(meteringMode = mode)
applyMeteringRegions()
updatePreview()
PLog.d(TAG, "测光模式: $mode")
}
/**
* 更新高光区域坐标(由 GL 测光回调调用)
* 使用 EMA 平滑防止 AE 频繁跳动
*/
fun updateHighlightPoint(x: Float, y: Float) {
highlightPointX = x
highlightPointY = y
if (!highlightPointInitialized) {
highlightPointSmoothedX = x
highlightPointSmoothedY = y
highlightPointInitialized = true
} else {
val alpha = 0.3
highlightPointSmoothedX = (alpha * x + (1 - alpha) * highlightPointSmoothedX).toFloat()
highlightPointSmoothedY = (alpha * y + (1 - alpha) * highlightPointSmoothedY).toFloat()
}
if (_state.value.meteringMode == MeteringMode.HIGHLIGHT_PRIORITY) {
applyMeteringRegions()
}
}
/**
* 根据当前测光模式设置默认 AE 区域
*
* 点测光和中央重点模式在画面中心(或对焦点)设置加权区域;
* 平均测光模式清除 AE 区域,使用硬件默认全画面测光。
*/
private fun applyMeteringRegions() {
if (maxAeRegions <= 0) return
val builder = previewRequestBuilder ?: return
val mode = _state.value.meteringMode
if (mode == MeteringMode.AVERAGE) {
builder.set(CaptureRequest.CONTROL_AE_REGIONS, null)
return
}
try {
val characteristics = cachedCharacteristics ?: return
val activeRect = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE) ?: return
val sensorOrientation = getSensorOrientation()
val lensFacing = getLensFacing()
// 选择测光坐标:高光优先使用最亮区域,其他模式使用对焦点或画面中心
val normX: Float
val normY: Float
if (mode == MeteringMode.HIGHLIGHT_PRIORITY && highlightPointInitialized) {
normX = highlightPointSmoothedX
normY = highlightPointSmoothedY
} else {
val focus = _state.value.focusPoint
normX = focus?.first ?: 0.5f
normY = focus?.second ?: 0.5f
}
val (sensorX, sensorY) = when (sensorOrientation) {
0 -> Pair(normX, normY)
90 -> Pair(normY, 1 - normX)
180 -> Pair(1 - normX, 1 - normY)
270 -> Pair(1 - normY, normX)
else -> Pair(normX, normY)
}
val (finalX, finalY) = if (lensFacing == CameraCharacteristics.LENS_FACING_FRONT) {
Pair(1 - sensorX, sensorY)
} else {
Pair(sensorX, sensorY)
}
val centerX = (finalX * activeRect.width()).toInt()
val centerY = (finalY * activeRect.height()).toInt()
val regionSizeFraction = when (mode) {
MeteringMode.SPOT -> 0.03f
MeteringMode.CENTER_WEIGHTED -> 0.1f
MeteringMode.HIGHLIGHT_PRIORITY -> 0.15f
}
val regionSize = (activeRect.width() * regionSizeFraction).toInt()
val rect = android.graphics.Rect(
(centerX - regionSize).coerceAtLeast(0),
(centerY - regionSize).coerceAtLeast(0),
(centerX + regionSize).coerceAtMost(activeRect.width()),
(centerY + regionSize).coerceAtMost(activeRect.height())
)
builder.set(
CaptureRequest.CONTROL_AE_REGIONS,
arrayOf(android.hardware.camera2.params.MeteringRectangle(
rect,
android.hardware.camera2.params.MeteringRectangle.METERING_WEIGHT_MAX
))
)
} catch (e: Exception) {
PLog.e(TAG, "Failed to apply metering regions", e)
}
}
/**
* 将色温转换为最接近的预设 AWB 模式
*
@@ -2386,6 +2539,32 @@ class Camera2Controller(private val context: Context) {
// ==================== 对焦控制 ====================
private fun recordFocusLockExposure(result: CaptureResult) {
val iso = result.get(CaptureResult.SENSOR_SENSITIVITY) ?: return
val exposure = result.get(CaptureResult.SENSOR_EXPOSURE_TIME) ?: return
focusLockedReferenceIso = iso
focusLockedReferenceExposureNs = exposure
isFocusLockedWaitingForSceneChange = true
sceneChangeFrameCount = 0
}
private fun restoreContinuousAf() {
isFocusLockedWaitingForSceneChange = false
sceneChangeFrameCount = 0
focusLockedReferenceIso = 0
focusLockedReferenceExposureNs = 0L
previewRequestBuilder?.apply {
set(CaptureRequest.CONTROL_AF_TRIGGER, CaptureRequest.CONTROL_AF_TRIGGER_IDLE)
val afMode = resolveAutoFocusMode(_state.value.captureMode)
set(CaptureRequest.CONTROL_AF_MODE, afMode)
_state.value = _state.value.copy(currentAfMode = afMode)
applyMeteringRegions()
updatePreview()
}
_state.value = _state.value.copy(isFocusing = false, focusSuccess = null)
}
/**
* 点击对焦
*/
@@ -2393,6 +2572,10 @@ class Camera2Controller(private val context: Context) {
val cameraId = _state.value.currentCameraId
if (cameraId.isEmpty()) return
// 重置场景变化检测状态(新的对焦覆盖旧的)
isFocusLockedWaitingForSceneChange = false
sceneChangeFrameCount = 0
try {
val characteristics = cachedCharacteristics ?: cameraManager.getCameraCharacteristics(cameraId)
val activeRect = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE) ?: return
@@ -2430,7 +2613,13 @@ class Camera2Controller(private val context: Context) {
// 映射到传感器坐标
val focusX = (finalX * activeRect.width()).toInt()
val focusY = (finalY * activeRect.height()).toInt()
val focusSize = (activeRect.width() * 0.1f).toInt() // 对焦区域大小为传感器宽度的10%
val focusSizeFraction = when (_state.value.meteringMode) {
MeteringMode.SPOT -> 0.03f // 点测光: 3% 传感器宽度
MeteringMode.CENTER_WEIGHTED -> 0.1f // 中央重点: 10% 传感器宽度
MeteringMode.AVERAGE -> 0.1f // 平均测光: AF 区域不变,仅跳过 AE 区域
MeteringMode.HIGHLIGHT_PRIORITY -> 0.15f // 高光优先: 15% 传感器宽度
}
val focusSize = (activeRect.width() * focusSizeFraction).toInt()
val focusRect = android.graphics.Rect(
(focusX - focusSize).coerceAtLeast(0),
@@ -2444,13 +2633,14 @@ class Camera2Controller(private val context: Context) {
android.hardware.camera2.params.MeteringRectangle.METERING_WEIGHT_MAX
)
PLog.d(TAG, "Focus: UI($normX, $normY) -> Sensor($finalX, $finalY) -> Rect($focusX, $focusY)")
PLog.d(TAG, "Focus: UI($normX, $normY) -> Sensor($finalX, $finalY) -> Rect($focusX, $focusY), metering=${_state.value.meteringMode}")
previewRequestBuilder?.apply {
if (maxAfRegions > 0) {
set(CaptureRequest.CONTROL_AF_REGIONS, arrayOf(meteringRectangle))
}
if (maxAeRegions > 0) {
// 平均测光模式下不设置 AE 区域,让硬件使用全画面默认测光
if (maxAeRegions > 0 && _state.value.meteringMode != MeteringMode.AVERAGE) {
set(CaptureRequest.CONTROL_AE_REGIONS, arrayOf(meteringRectangle))
}
val afMode = CaptureRequest.CONTROL_AF_MODE_AUTO
@@ -2460,17 +2650,7 @@ class Camera2Controller(private val context: Context) {
updatePreview()
}
// 延迟恢复连续对焦
cameraHandler?.postDelayed({
previewRequestBuilder?.apply {
set(CaptureRequest.CONTROL_AF_TRIGGER, CaptureRequest.CONTROL_AF_TRIGGER_IDLE)
val afMode = resolveAutoFocusMode(_state.value.captureMode)
set(CaptureRequest.CONTROL_AF_MODE, afMode)
_state.value = _state.value.copy(currentAfMode = afMode)
updatePreview()
}
_state.value = _state.value.copy(isFocusing = false, focusSuccess = null)
}, 3000)
// 对焦后通过场景变化检测自动恢复连续对焦(不再使用固定延迟)
} catch (e: Exception) {
PLog.e(TAG, "Failed to focus", e)
@@ -51,6 +51,16 @@ enum class LensType {
BACK_MACRO
}
/**
* 测光模式
*/
enum class MeteringMode {
SPOT, // 点测光 - 对焦点附近小区域
CENTER_WEIGHTED, // 中央重点 - 中等区域,中心加权
AVERAGE, // 平均测光 - 全画面均匀
HIGHLIGHT_PRIORITY // 高光优先 - 亮部加权,防止过曝
}
/**
* 相机信息数据类
*/
@@ -137,6 +147,9 @@ data class CameraState(
val awbMode: Int = 1, // 自动白平衡模式
val awbTemperature: Int = 5000, // 色温 (K)
// 测光模式
val meteringMode: MeteringMode = MeteringMode.CENTER_WEIGHTED,
val isVirtualApertureEnabled: Boolean = false,
val physicalAperture: Float = 2.0f, // 物理光圈值
val virtualAperture: Float = 2.0f, // 虚拟光圈值 (f-number)
@@ -8,6 +8,7 @@ import com.hinnka.mycamera.livephoto.LivePhotoRecorder
import com.hinnka.mycamera.raw.ColorSpace
import com.hinnka.mycamera.color.TransferCurve
import com.hinnka.mycamera.screencapture.PhantomPipCrop
import com.hinnka.mycamera.camera.MeteringMode
import com.hinnka.mycamera.utils.PLog
import com.hinnka.mycamera.video.VideoLogProfile
import com.hinnka.mycamera.video.VideoRecorder
@@ -330,6 +331,9 @@ class LutRenderer : GLSurfaceView.Renderer {
@Volatile
var focusPoint: PointF? = null
@Volatile
var meteringMode: MeteringMode = MeteringMode.CENTER_WEIGHTED
@Volatile
var aperture: Float = 0f
private val cropRect = floatArrayOf(0f, 0f, 1f, 1f)
@@ -426,6 +430,7 @@ class LutRenderer : GLSurfaceView.Renderer {
var onPreviewFrameCaptured: ((Bitmap) -> Unit)? = null
var onHistogramUpdated: ((IntArray) -> Unit)? = null
var onMeteringUpdated: ((Double, Double) -> Unit)? = null
var onHighlightPointUpdated: ((Float, Float) -> Unit)? = null
// Live Photo 录制器
var livePhotoRecorder: LivePhotoRecorder? = null
@@ -2283,8 +2288,15 @@ class LutRenderer : GLSurfaceView.Renderer {
var totalWeight = 0.0
val focus = focusPoint
val weightCenter = 4.0
val weightEdge = 1.0
val mode = meteringMode
// 根据测光模式设置权重参数
val (weightCenter, weightEdge, radiusSq) = when (mode) {
MeteringMode.SPOT -> Triple(8.0, 0.0, (METERING_SIZE * METERING_SIZE) / 64.0) // 半径 METERING_SIZE/8
MeteringMode.CENTER_WEIGHTED -> Triple(4.0, 1.0, (METERING_SIZE * METERING_SIZE) / 16.0) // 半径 METERING_SIZE/4
MeteringMode.AVERAGE -> Triple(1.0, 1.0, 0.0) // 所有像素等权
MeteringMode.HIGHLIGHT_PRIORITY -> Triple(2.0, 1.0, (METERING_SIZE * METERING_SIZE) / 8.0) // 大区域,亮部加权在下方处理
}
for (y in 0 until METERING_SIZE) {
for (x in 0 until METERING_SIZE) {
@@ -2298,16 +2310,28 @@ class LutRenderer : GLSurfaceView.Renderer {
histogram[luma]++
// 权重计算
var weight = weightEdge
if (focus != null) {
val spatialWeight = if (mode == MeteringMode.AVERAGE) {
weightEdge
} else if (focus != null) {
val fx = focus.x * METERING_SIZE
val fy = (1.0f - focus.y) * METERING_SIZE
val dx = x.toDouble() - fx.toDouble()
val dy = y.toDouble() - fy.toDouble()
if (dx * dx + dy * dy < (METERING_SIZE * METERING_SIZE) / 16.0) {
weight = weightCenter
}
if (dx * dx + dy * dy < radiusSq) weightCenter else weightEdge
} else {
// 无对焦点时,点测光回退到中心
val cx = METERING_SIZE / 2.0
val cy = METERING_SIZE / 2.0
val dx = x.toDouble() - cx
val dy = y.toDouble() - cy
if (dx * dx + dy * dy < radiusSq) weightCenter else weightEdge
}
// 高光优先:用亮度^2 加权,亮部像素对测光影响更大
val weight = if (mode == MeteringMode.HIGHLIGHT_PRIORITY) {
val lumaNorm = luma / 255.0
spatialWeight * (0.1 + 0.9 * lumaNorm * lumaNorm)
} else {
spatialWeight
}
weightedSumLuminance += luma * weight
@@ -2317,6 +2341,34 @@ class LutRenderer : GLSurfaceView.Renderer {
onHistogramUpdated?.invoke(histogram)
onMeteringUpdated?.invoke(totalWeight, weightedSumLuminance)
// 高光优先模式:找到最亮区域坐标,供 AE 区域定位使用
if (mode == MeteringMode.HIGHLIGHT_PRIORITY) {
val highlightThreshold = 200
var sumX = 0.0
var sumY = 0.0
var count = 0
for (y in 0 until METERING_SIZE) {
for (x in 0 until METERING_SIZE) {
val idx = (y * METERING_SIZE + x) * 4
val r = meteringBytes[idx].toInt() and 0xFF
val g = meteringBytes[idx + 1].toInt() and 0xFF
val b = meteringBytes[idx + 2].toInt() and 0xFF
val luma = (0.2126 * r + 0.7152 * g + 0.0722 * b).toInt()
if (luma >= highlightThreshold) {
sumX += x
sumY += y
count++
}
}
}
if (count >= 3) {
// 归一化到 0-1,注意 GL 坐标 Y 轴翻转
val hx = (sumX / count / METERING_SIZE).toFloat()
val hy = (1.0f - (sumY / count / METERING_SIZE).toFloat())
onHighlightPointUpdated?.invoke(hx, hy)
}
}
}
/**
@@ -8,6 +8,7 @@ import android.opengl.GLSurfaceView
import android.util.AttributeSet
import android.view.Surface
import com.hinnka.mycamera.livephoto.LivePhotoRecorder
import com.hinnka.mycamera.camera.MeteringMode
import com.hinnka.mycamera.lut.LutConfig
import com.hinnka.mycamera.lut.LutRenderer
import com.hinnka.mycamera.model.ColorRecipeParams
@@ -36,6 +37,7 @@ class CameraGLSurfaceView @JvmOverloads constructor(
var onHistogramUpdated: ((IntArray) -> Unit)? = null
var onMeteringUpdated: ((Double, Double) -> Unit)? = null
var onHighlightPointUpdated: ((Float, Float) -> Unit)? = null
var onDepthInputAvailable: ((Bitmap) -> Unit)? = null
var onSurfaceReady: ((Surface) -> Unit)? = null
@@ -77,6 +79,10 @@ class CameraGLSurfaceView @JvmOverloads constructor(
onMeteringUpdated?.invoke(totalWeight, weightedSumLuminance)
}
renderer.onHighlightPointUpdated = { hx, hy ->
onHighlightPointUpdated?.invoke(hx, hy)
}
renderer.onDepthInputAvailable = { bitmap ->
onDepthInputAvailable?.invoke(bitmap)
}
@@ -130,6 +136,10 @@ class CameraGLSurfaceView @JvmOverloads constructor(
renderer.focusPoint = point
}
fun setMeteringMode(mode: MeteringMode) {
renderer.meteringMode = mode
}
fun setMeteringEnabled(enabled: Boolean) {
renderer.meteringEnabled = enabled
}
@@ -8,9 +8,11 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.hinnka.mycamera.R
import com.hinnka.mycamera.camera.CameraState
@Composable
@@ -18,6 +18,7 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.compose.LocalLifecycleOwner
import com.hinnka.mycamera.livephoto.LivePhotoRecorder
import com.hinnka.mycamera.camera.MeteringMode
import com.hinnka.mycamera.lut.LutConfig
import com.hinnka.mycamera.model.ColorRecipeParams
import com.hinnka.mycamera.ui.components.FocusIndicator
@@ -44,11 +45,13 @@ fun CameraPreviewGL(
focusPoint: Pair<Float, Float>?,
isFocusing: Boolean,
focusSuccess: Boolean?,
meteringMode: MeteringMode = MeteringMode.CENTER_WEIGHTED,
onSurfaceTextureReady: (SurfaceTexture) -> Unit,
onSurfaceDestroyed: () -> Unit,
onTap: (Float, Float, Int, Int) -> Unit,
onHistogramUpdated: ((IntArray) -> Unit)? = null,
onMeteringUpdated: ((Double, Double) -> Unit)? = null,
onHighlightPointUpdated: ((Float, Float) -> Unit)? = null,
onDepthInputAvailable: ((android.graphics.Bitmap) -> Unit)? = null,
livePhotoRecorder: LivePhotoRecorder? = null,
videoRecorder: VideoRecorder? = null,
@@ -161,6 +164,7 @@ fun CameraPreviewGL(
glSurfaceView.onHistogramUpdated = { onHistogramUpdated?.invoke(it) }
glSurfaceView.onMeteringUpdated = { w, l -> onMeteringUpdated?.invoke(w, l) }
glSurfaceView.onHighlightPointUpdated = { hx, hy -> onHighlightPointUpdated?.invoke(hx, hy) }
glSurfaceView.onDepthInputAvailable = { onDepthInputAvailable?.invoke(it) }
viewWidth = glSurfaceView.width
@@ -205,6 +209,7 @@ fun CameraPreviewGL(
it.second / viewHeight
)
})
glSurfaceView.setMeteringMode(meteringMode)
glSurfaceView.setLivePhotoRecorder(livePhotoRecorder)
glSurfaceView.setVideoRecorder(videoRecorder)
glSurfaceView.setVideoLogProfile(videoLogProfile)
@@ -706,6 +706,7 @@ fun CameraScreen(
focusPoint = state.focusPoint,
isFocusing = state.isFocusing,
focusSuccess = state.focusSuccess,
meteringMode = state.meteringMode,
onSurfaceTextureReady = { surfaceTexture ->
viewModel.openCamera(surfaceTexture)
cameraOpened = true
@@ -725,6 +726,7 @@ fun CameraScreen(
},
onHistogramUpdated = { viewModel.handleHistogramUpdate(it) },
onMeteringUpdated = { w, l -> viewModel.handleMeteringUpdate(w, l) },
onHighlightPointUpdated = { hx, hy -> viewModel.handleHighlightPointUpdate(hx, hy) },
onDepthInputAvailable = { viewModel.handleDepthMapUpdate(it) },
onGLSurfaceViewReady = {
viewModel.glSurfaceView = it
@@ -1088,9 +1090,8 @@ fun CameraScreen(
useRaw = useRaw && state.isRawSupported,
onRawToggle = { viewModel.toggleRaw() },
isRawSupported = state.isRawSupported,
nrLevel = state.nrLevel,
availableNrLevels = state.availableNrModes,
onNRLevelChange = { viewModel.setNRLevel(it) },
meteringMode = state.meteringMode,
onMeteringModeChange = { viewModel.setMeteringMode(it) },
onFilterManageClick = {
activePanel = ActivePanel.NONE
onFilterManagementClick()
@@ -26,6 +26,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.hinnka.mycamera.R
import com.hinnka.mycamera.camera.AspectRatio
import com.hinnka.mycamera.camera.MeteringMode
import com.hinnka.mycamera.utils.DeviceUtil
import com.hinnka.mycamera.video.*
import com.hinnka.mycamera.video.VideoCodec
@@ -59,9 +60,8 @@ fun CameraTopSheet(
useRaw: Boolean,
onRawToggle: (Boolean) -> Unit,
isRawSupported: Boolean,
nrLevel: Int,
availableNrLevels: IntArray,
onNRLevelChange: (Int) -> Unit,
meteringMode: MeteringMode,
onMeteringModeChange: (MeteringMode) -> Unit,
onFilterManageClick: () -> Unit,
onFrameManageClick: () -> Unit,
phantomMode: Boolean,
@@ -177,25 +177,23 @@ fun CameraTopSheet(
modifier = Modifier.weight(1f)
)
val nrLevelNames = availableNrLevels.map {
when (it) {
5 -> stringResource(R.string.settings_nr_level_auto)
0 -> stringResource(R.string.settings_nr_level_off)
1 -> stringResource(R.string.settings_nr_level_fast)
2 -> stringResource(R.string.settings_nr_level_high_quality)
3 -> stringResource(R.string.settings_nr_level_zsl)
4 -> stringResource(R.string.settings_nr_level_minimal)
else -> "Unknown"
}
val meteringLabel = when (meteringMode) {
MeteringMode.SPOT -> stringResource(R.string.metering_spot)
MeteringMode.CENTER_WEIGHTED -> stringResource(R.string.metering_center_weighted)
MeteringMode.AVERAGE -> stringResource(R.string.metering_average)
MeteringMode.HIGHLIGHT_PRIORITY -> stringResource(R.string.metering_highlight_priority)
}
QuickSettingValue(
title = stringResource(R.string.settings_nr_level),
value = nrLevelNames.getOrElse(availableNrLevels.indexOf(nrLevel)) { "Unknown" },
title = stringResource(R.string.metering_mode),
value = meteringLabel,
onClick = {
val nextIndex =
(availableNrLevels.indexOf(nrLevel) + 1) % availableNrLevels.size
val nextLevel = availableNrLevels[nextIndex]
onNRLevelChange(nextLevel)
val next = when (meteringMode) {
MeteringMode.SPOT -> MeteringMode.CENTER_WEIGHTED
MeteringMode.CENTER_WEIGHTED -> MeteringMode.AVERAGE
MeteringMode.AVERAGE -> MeteringMode.HIGHLIGHT_PRIORITY
MeteringMode.HIGHLIGHT_PRIORITY -> MeteringMode.SPOT
}
onMeteringModeChange(next)
},
modifier = Modifier.weight(1f)
)
@@ -451,6 +451,7 @@ private fun getScaleValues(parameter: CameraParameter, minValue: Float, maxValue
}
list
}
}
}
@@ -494,5 +495,6 @@ private fun formatParameterValue(parameter: CameraParameter, value: Float): Stri
else String.format("%dcm", (meters * 100).toInt())
}
}
}
}
@@ -1514,6 +1514,10 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
cameraController.setAwbTemperature(kelvin)
}
fun setMeteringMode(mode: com.hinnka.mycamera.camera.MeteringMode) {
cameraController.setMeteringMode(mode)
}
// ==================== 计费相关方法 ====================
/**
@@ -1912,6 +1916,10 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
cameraController.calculateAutoMetering(totalWeight, weightedSumLuminance)
}
fun handleHighlightPointUpdate(x: Float, y: Float) {
cameraController.updateHighlightPoint(x, y)
}
fun handleDepthMapUpdate(bitmap: android.graphics.Bitmap) {
cameraController.previewDepthProcessor.processBitmap(bitmap)
}
@@ -805,4 +805,14 @@
<string name="ai_denoise_success">AI 降噪成功</string>
<string name="ai_denoise_failed">AI 降噪失败</string>
<string name="ai_denoise_strength">AI 降噪强度</string>
<!-- 测光模式 -->
<string name="metering_mode">测光</string>
<string name="metering_spot">点测光</string>
<string name="metering_center_weighted">中央重点</string>
<string name="metering_average">平均测光</string>
<string name="metering_highlight_priority">高光优先</string>
<string name="center_weight">中央重点</string>
<string name="avg">平均</string>
<string name="spot">点测光</string>
</resources>
@@ -590,4 +590,11 @@
<string name="settings_raw_nlm_base_h">RAW NLM 基础强度</string>
<string name="settings_raw_nlm_gain_factor">RAW NLM 增益响应</string>
<string name="ai_service">AI服务</string>
<!-- 測光模式 -->
<string name="metering_mode">測光</string>
<string name="metering_spot">點測光</string>
<string name="metering_center_weighted">中央重點</string>
<string name="metering_average">平均測光</string>
<string name="metering_highlight_priority">高光優先</string>
</resources>
+10
View File
@@ -805,4 +805,14 @@
<string name="ai_denoise_success">AI Denoise Success</string>
<string name="ai_denoise_failed">AI Denoise Failed</string>
<string name="ai_denoise_strength">AI Denoise Strength</string>
<!-- Metering Mode -->
<string name="metering_mode">Metering</string>
<string name="metering_spot">Spot</string>
<string name="metering_center_weighted">Center Weighted</string>
<string name="metering_average">Average</string>
<string name="metering_highlight_priority">Highlight</string>
<string name="center_weight">CW</string>
<string name="avg">AVG</string>
<string name="spot">SPOT</string>
</resources>