Merge branch 'main' of https://github.com/Bitkoala/PhotonCamera
This commit is contained in:
commit
dae477b267
39 files changed
+1946
-386
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -63,16 +63,19 @@ class CameraDiscovery(private val context: Context) {
|
||||
fun discoverAllCameras(): List<CameraInfo> {
|
||||
val cameras = mutableListOf<CameraInfo>()
|
||||
val preferredMainCameraId = loadPreferredMainCameraId()
|
||||
val preferredMacroCameraId = loadPreferredMacroCameraId()
|
||||
|
||||
val discoveredCameras = discoverCameraCandidates(
|
||||
includeDuplicateMainCameraIds = false,
|
||||
preferredMainCameraId = preferredMainCameraId
|
||||
preferredMainCameraId = preferredMainCameraId,
|
||||
preferredMacroCameraId = preferredMacroCameraId
|
||||
)
|
||||
|
||||
val iszVirtualCameras = createIszVirtualCameraCandidates(discoveredCameras.backCameras)
|
||||
val classifiedBackCameras = classifyBackCameras(
|
||||
cameras = discoveredCameras.backCameras + iszVirtualCameras,
|
||||
preferredMainCameraId = preferredMainCameraId
|
||||
preferredMainCameraId = preferredMainCameraId,
|
||||
preferredMacroCameraId = preferredMacroCameraId
|
||||
)
|
||||
cameras.addAll(classifiedBackCameras)
|
||||
|
||||
@@ -94,8 +97,15 @@ class CameraDiscovery(private val context: Context) {
|
||||
}
|
||||
|
||||
fun discoverMainCameraIdOptions(): List<String> {
|
||||
val discoveredCameras = discoverCameraCandidates(includeDuplicateMainCameraIds = true)
|
||||
val adjustedCameras = adjustMacroCandidatesByFocalLength(discoveredCameras.backCameras)
|
||||
val preferredMacroCameraId = loadPreferredMacroCameraId()
|
||||
val discoveredCameras = discoverCameraCandidates(
|
||||
includeDuplicateMainCameraIds = true,
|
||||
preferredMacroCameraId = preferredMacroCameraId
|
||||
)
|
||||
val adjustedCameras = adjustMacroCandidatesByFocalLength(
|
||||
cameras = discoveredCameras.backCameras,
|
||||
preferredMacroCameraId = preferredMacroCameraId
|
||||
)
|
||||
val options = adjustedCameras
|
||||
.filter { !it.isMacro && isSameFocalLength(it.intrinsicZoomRatio, 1f) }
|
||||
.sortedWith(
|
||||
@@ -111,9 +121,25 @@ class CameraDiscovery(private val context: Context) {
|
||||
return options
|
||||
}
|
||||
|
||||
fun discoverMacroCameraIdOptions(): List<String> {
|
||||
val preferredMacroCameraId = loadPreferredMacroCameraId()
|
||||
val discoveredCameras = discoverCameraCandidates(
|
||||
includeDuplicateMainCameraIds = true,
|
||||
preferredMacroCameraId = preferredMacroCameraId
|
||||
)
|
||||
val options = discoveredCameras.backCameras
|
||||
.map { it.info.cameraId }
|
||||
.distinct()
|
||||
.sortedWith(compareCameraIdsForSettings())
|
||||
|
||||
PLog.d(TAG, "Macro camera ID options: $options")
|
||||
return options
|
||||
}
|
||||
|
||||
private fun discoverCameraCandidates(
|
||||
includeDuplicateMainCameraIds: Boolean,
|
||||
preferredMainCameraId: String? = null
|
||||
preferredMainCameraId: String? = null,
|
||||
preferredMacroCameraId: String? = null
|
||||
): DiscoveredCameraCandidates {
|
||||
val customLensIdSet = loadCustomLensIds().toSet()
|
||||
val baseCameraIds = getAllCameraIds(includeDuplicateMainCameraIds)
|
||||
@@ -127,8 +153,13 @@ class CameraDiscovery(private val context: Context) {
|
||||
preferredMainCameraId = preferredMainCameraId,
|
||||
logicalCameraBindings = logicalCameraBindings
|
||||
)
|
||||
val preferredDirectCameraIds = appendPreferredMacroCameraId(
|
||||
baseIds = directCameraIds,
|
||||
preferredMacroCameraId = preferredMacroCameraId,
|
||||
logicalCameraBindings = logicalCameraBindings
|
||||
)
|
||||
// 获取完整的 Camera ID 列表(包括探测的隐藏摄像头和逻辑多摄暴露的物理摄像头)
|
||||
val allCameraIds = (directCameraIds + logicalCameraBindings.keys).distinct()
|
||||
val allCameraIds = (preferredDirectCameraIds + logicalCameraBindings.keys).distinct()
|
||||
PLog.d(TAG, "Camera2 discovered IDs: $allCameraIds")
|
||||
|
||||
val backCameras = mutableListOf<CameraInfoWithZoom>()
|
||||
@@ -143,7 +174,8 @@ class CameraDiscovery(private val context: Context) {
|
||||
val intrinsicZoomRatio = calculateIntrinsicZoomRatio(cameraId, characteristics, lensFacing)
|
||||
|
||||
// 检测是否为微距镜头
|
||||
val isMacro = isMacroLens(characteristics)
|
||||
val isMacro = isMacroLens(characteristics) ||
|
||||
isPreferredCameraId(cameraId, preferredMacroCameraId)
|
||||
|
||||
val info = createCameraInfo(
|
||||
cameraId = cameraId,
|
||||
@@ -281,6 +313,37 @@ class CameraDiscovery(private val context: Context) {
|
||||
return (baseIds + cameraId).distinct()
|
||||
}
|
||||
|
||||
private fun appendPreferredMacroCameraId(
|
||||
baseIds: List<String>,
|
||||
preferredMacroCameraId: String?,
|
||||
logicalCameraBindings: Map<String, LogicalCameraBinding>
|
||||
): List<String> {
|
||||
val cameraId = preferredMacroCameraId?.trim()?.takeIf { it.isNotEmpty() } ?: return baseIds
|
||||
if (baseIds.contains(cameraId)) return baseIds
|
||||
logicalCameraBindings[cameraId]?.let { binding ->
|
||||
PLog.d(
|
||||
TAG,
|
||||
"Preferred macro camera ID $cameraId uses logical camera ${binding.logicalCameraId}"
|
||||
)
|
||||
return baseIds
|
||||
}
|
||||
if (!isCustomCameraIdAvailable(cameraId)) return baseIds
|
||||
|
||||
PLog.d(TAG, "Preferred macro camera ID $cameraId added to discovery IDs")
|
||||
return (baseIds + cameraId).distinct()
|
||||
}
|
||||
|
||||
private fun isPreferredCameraId(cameraId: String, preferredCameraId: String?): Boolean {
|
||||
return preferredCameraId?.trim()?.takeIf { it.isNotEmpty() } == cameraId
|
||||
}
|
||||
|
||||
private fun compareCameraIdsForSettings(): Comparator<String> {
|
||||
return compareBy<String>(
|
||||
{ it.toIntOrNull() ?: Int.MAX_VALUE },
|
||||
{ it }
|
||||
)
|
||||
}
|
||||
|
||||
private fun findLogicalCameraBindings(
|
||||
publicCameraIdSet: Set<String>,
|
||||
config: LogicalCameraDiscoveryConfig
|
||||
@@ -637,6 +700,17 @@ class CameraDiscovery(private val context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadPreferredMacroCameraId(): String? {
|
||||
return try {
|
||||
runBlocking {
|
||||
userPreferencesRepository.userPreferences.firstOrNull()?.preferredMacroCameraId
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
PLog.w(TAG, "Failed to load preferred macro camera ID", e)
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadLogicalCameraDiscoveryConfig(): LogicalCameraDiscoveryConfig {
|
||||
return try {
|
||||
runBlocking {
|
||||
@@ -878,14 +952,21 @@ class CameraDiscovery(private val context: Context) {
|
||||
*/
|
||||
private fun classifyBackCameras(
|
||||
cameras: List<CameraInfoWithZoom>,
|
||||
preferredMainCameraId: String?
|
||||
preferredMainCameraId: String?,
|
||||
preferredMacroCameraId: String?
|
||||
): List<CameraInfo> {
|
||||
if (cameras.isEmpty()) return emptyList()
|
||||
|
||||
val adjustedCameras = adjustMacroCandidatesByFocalLength(cameras)
|
||||
val adjustedCameras = adjustMacroCandidatesByFocalLength(
|
||||
cameras = cameras,
|
||||
preferredMacroCameraId = preferredMacroCameraId
|
||||
)
|
||||
|
||||
// 分离微距镜头和普通镜头
|
||||
val macroCameras = preferCustomCameraForSameFocalLength(adjustedCameras.filter { it.isMacro })
|
||||
val macroCameras = preferCustomCameraForSameFocalLength(
|
||||
cameras = adjustedCameras.filter { it.isMacro },
|
||||
preferredMacroCameraId = preferredMacroCameraId
|
||||
)
|
||||
val normalCameras = preferCustomCameraForSameFocalLength(
|
||||
cameras = adjustedCameras.filter { !it.isMacro },
|
||||
preferredMainCameraId = preferredMainCameraId
|
||||
@@ -950,7 +1031,10 @@ class CameraDiscovery(private val context: Context) {
|
||||
return sortedCameras.indices.minByOrNull { abs(sortedCameras[it].intrinsicZoomRatio - 1f) } ?: 0
|
||||
}
|
||||
|
||||
private fun adjustMacroCandidatesByFocalLength(cameras: List<CameraInfoWithZoom>): List<CameraInfoWithZoom> {
|
||||
private fun adjustMacroCandidatesByFocalLength(
|
||||
cameras: List<CameraInfoWithZoom>,
|
||||
preferredMacroCameraId: String? = null
|
||||
): List<CameraInfoWithZoom> {
|
||||
if (cameras.size <= 1) return cameras
|
||||
|
||||
val shortestFocalLength = cameras
|
||||
@@ -963,6 +1047,9 @@ class CameraDiscovery(private val context: Context) {
|
||||
if (camera.isMacro && camera.info.isVirtualIszMacroLens) {
|
||||
return@map camera
|
||||
}
|
||||
if (camera.isMacro && isPreferredCameraId(camera.info.cameraId, preferredMacroCameraId)) {
|
||||
return@map camera
|
||||
}
|
||||
if (!camera.isMacro || !isSameFocalLength(getComparableFocalLength(camera), shortestFocalLength)) {
|
||||
camera
|
||||
} else {
|
||||
@@ -985,7 +1072,8 @@ class CameraDiscovery(private val context: Context) {
|
||||
|
||||
private fun preferCustomCameraForSameFocalLength(
|
||||
cameras: List<CameraInfoWithZoom>,
|
||||
preferredMainCameraId: String? = null
|
||||
preferredMainCameraId: String? = null,
|
||||
preferredMacroCameraId: String? = null
|
||||
): List<CameraInfoWithZoom> {
|
||||
val selectedCameras = mutableListOf<CameraInfoWithZoom>()
|
||||
|
||||
@@ -1000,7 +1088,12 @@ class CameraDiscovery(private val context: Context) {
|
||||
}
|
||||
|
||||
val existing = selectedCameras[sameFocalIndex]
|
||||
if (shouldReplaceSameFocalCamera(existing, camera, preferredMainCameraId)) {
|
||||
if (shouldKeepSameFocalVirtualIszVariant(existing.info, camera.info)) {
|
||||
selectedCameras.add(camera)
|
||||
continue
|
||||
}
|
||||
|
||||
if (shouldReplaceSameFocalCamera(existing, camera, preferredMainCameraId, preferredMacroCameraId)) {
|
||||
PLog.d(
|
||||
TAG,
|
||||
"Camera ID ${camera.info.cameraId} overrides same focal ID ${existing.info.cameraId} " +
|
||||
@@ -1020,11 +1113,22 @@ class CameraDiscovery(private val context: Context) {
|
||||
return selectedCameras
|
||||
}
|
||||
|
||||
private fun shouldKeepSameFocalVirtualIszVariant(existing: CameraInfo, candidate: CameraInfo): Boolean {
|
||||
return existing.isVirtualIszLens &&
|
||||
candidate.isVirtualIszLens &&
|
||||
existing.cameraId != candidate.cameraId
|
||||
}
|
||||
|
||||
private fun shouldReplaceSameFocalCamera(
|
||||
existing: CameraInfoWithZoom,
|
||||
candidate: CameraInfoWithZoom,
|
||||
preferredMainCameraId: String?
|
||||
preferredMainCameraId: String?,
|
||||
preferredMacroCameraId: String?
|
||||
): Boolean {
|
||||
val existingIsPreferredMacro = isPreferredCameraId(existing.info.cameraId, preferredMacroCameraId)
|
||||
val candidateIsPreferredMacro = isPreferredCameraId(candidate.info.cameraId, preferredMacroCameraId)
|
||||
if (existingIsPreferredMacro != candidateIsPreferredMacro) return candidateIsPreferredMacro
|
||||
|
||||
if (isSameFocalLength(candidate.intrinsicZoomRatio, 1f)) {
|
||||
val existingIsPreferred = existing.info.cameraId == preferredMainCameraId
|
||||
val candidateIsPreferred = candidate.info.cameraId == preferredMainCameraId
|
||||
|
||||
@@ -248,6 +248,13 @@ enum class FocusPointSource {
|
||||
AI
|
||||
}
|
||||
|
||||
data class WhiteBalanceGains(
|
||||
val red: Float,
|
||||
val greenEven: Float,
|
||||
val greenOdd: Float,
|
||||
val blue: Float
|
||||
)
|
||||
|
||||
/**
|
||||
* 相机状态数据类
|
||||
*/
|
||||
@@ -269,6 +276,13 @@ data class CameraState(
|
||||
|
||||
val awbMode: Int = 1, // 自动白平衡模式
|
||||
val awbTemperature: Int = 5000, // 色温 (K)
|
||||
val actualAwbTemperature: Int? = null, // 相机当前实际/估算色温 (K)
|
||||
val actualAwbTint: Int? = null,
|
||||
val actualAwbGains: WhiteBalanceGains? = null,
|
||||
val canAdjustWhiteBalance: Boolean = false,
|
||||
val supportsCctWhiteBalance: Boolean = false,
|
||||
val awbTemperatureMin: Int = 2000,
|
||||
val awbTemperatureMax: Int = 8000,
|
||||
|
||||
// 测光模式
|
||||
val meteringMode: MeteringMode = MeteringMode.SYSTEM_DEFAULT,
|
||||
|
||||
@@ -25,7 +25,7 @@ data class CaptureInfo(
|
||||
val software: String = "PhotonCamera",
|
||||
|
||||
// 拍摄参数
|
||||
val whiteBalance: Int? = null, // AWB 模式
|
||||
val whiteBalance: Int? = null, // EXIF 白平衡: 0=Auto, 1=Manual
|
||||
val flashState: Int? = null, // 闪光灯状态
|
||||
val orientation: Int = 0, // JPEG 方向 (0, 90, 180, 270)
|
||||
|
||||
|
||||
@@ -10,16 +10,20 @@ data class IszLensConfig(
|
||||
val baseCameraId: String,
|
||||
val iszZoomRatio: Float,
|
||||
val isMacro: Boolean = false,
|
||||
val rawBlackBorderCrop: RawBlackBorderCrop = RawBlackBorderCrop()
|
||||
val rawBlackBorderCrop: RawBlackBorderCrop = RawBlackBorderCrop(),
|
||||
val vendorCaptureProfileId: String? = null
|
||||
) {
|
||||
val virtualCameraId: String
|
||||
get() = createVirtualCameraId(baseCameraId, iszZoomRatio)
|
||||
get() = createVirtualCameraId(baseCameraId, iszZoomRatio, vendorCaptureProfileId)
|
||||
|
||||
fun toJsonObject(): JSONObject {
|
||||
return JSONObject().apply {
|
||||
put(KEY_BASE_CAMERA_ID, baseCameraId)
|
||||
put(KEY_ISZ_ZOOM_RATIO, iszZoomRatio)
|
||||
put(KEY_IS_MACRO, isMacro)
|
||||
sanitizeVendorCaptureProfileId(vendorCaptureProfileId)?.let {
|
||||
put(KEY_VENDOR_CAPTURE_PROFILE_ID, it)
|
||||
}
|
||||
val sanitizedCrop = sanitizeRawBlackBorderCrop(rawBlackBorderCrop)
|
||||
put(KEY_RAW_BLACK_BORDER_CROP_LEFT_PX, sanitizedCrop.leftPx)
|
||||
put(KEY_RAW_BLACK_BORDER_CROP_TOP_PX, sanitizedCrop.topPx)
|
||||
@@ -32,6 +36,7 @@ data class IszLensConfig(
|
||||
private const val KEY_BASE_CAMERA_ID = "base_camera_id"
|
||||
private const val KEY_ISZ_ZOOM_RATIO = "isz_zoom_ratio"
|
||||
private const val KEY_IS_MACRO = "is_macro"
|
||||
private const val KEY_VENDOR_CAPTURE_PROFILE_ID = "vendor_capture_profile_id"
|
||||
private const val KEY_RAW_BLACK_BORDER_CROP_PX = "raw_black_border_crop_px"
|
||||
private const val KEY_RAW_BLACK_BORDER_CROP_LEFT_PX = "raw_black_border_crop_left_px"
|
||||
private const val KEY_RAW_BLACK_BORDER_CROP_TOP_PX = "raw_black_border_crop_top_px"
|
||||
@@ -40,8 +45,14 @@ data class IszLensConfig(
|
||||
private const val MAX_RAW_BLACK_BORDER_CROP_PX = 4096
|
||||
private const val VIRTUAL_CAMERA_ID_PREFIX = "isz"
|
||||
|
||||
fun createVirtualCameraId(baseCameraId: String, iszZoomRatio: Float): String {
|
||||
return "$VIRTUAL_CAMERA_ID_PREFIX:$baseCameraId:${formatRatioForId(iszZoomRatio)}"
|
||||
fun createVirtualCameraId(
|
||||
baseCameraId: String,
|
||||
iszZoomRatio: Float,
|
||||
vendorCaptureProfileId: String? = null
|
||||
): String {
|
||||
val baseId = "$VIRTUAL_CAMERA_ID_PREFIX:$baseCameraId:${formatRatioForId(iszZoomRatio)}"
|
||||
val profileId = sanitizeVendorCaptureProfileId(vendorCaptureProfileId) ?: return baseId
|
||||
return "$baseId:$profileId"
|
||||
}
|
||||
|
||||
fun deserializeList(value: String?): List<IszLensConfig> {
|
||||
@@ -53,6 +64,9 @@ data class IszLensConfig(
|
||||
val baseCameraId = obj.optString(KEY_BASE_CAMERA_ID).trim()
|
||||
val iszZoomRatio = obj.optDouble(KEY_ISZ_ZOOM_RATIO, 0.0).toFloat()
|
||||
val isMacro = obj.optBoolean(KEY_IS_MACRO, false)
|
||||
val vendorCaptureProfileId = sanitizeVendorCaptureProfileId(
|
||||
obj.optString(KEY_VENDOR_CAPTURE_PROFILE_ID, "")
|
||||
)
|
||||
val legacyLeftCropPx = obj.optInt(KEY_RAW_BLACK_BORDER_CROP_PX, 0)
|
||||
val rawBlackBorderCrop = sanitizeRawBlackBorderCrop(
|
||||
RawBlackBorderCrop(
|
||||
@@ -63,7 +77,15 @@ data class IszLensConfig(
|
||||
)
|
||||
)
|
||||
if (baseCameraId.isNotEmpty() && iszZoomRatio >= 1f) {
|
||||
add(IszLensConfig(baseCameraId, iszZoomRatio, isMacro, rawBlackBorderCrop))
|
||||
add(
|
||||
IszLensConfig(
|
||||
baseCameraId = baseCameraId,
|
||||
iszZoomRatio = iszZoomRatio,
|
||||
isMacro = isMacro,
|
||||
rawBlackBorderCrop = rawBlackBorderCrop,
|
||||
vendorCaptureProfileId = vendorCaptureProfileId
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}.distinctBy { it.virtualCameraId }
|
||||
@@ -91,6 +113,21 @@ data class IszLensConfig(
|
||||
return displayRatioLabel(ratio).dropLast(1)
|
||||
}
|
||||
|
||||
fun sanitizeVendorCaptureProfileId(value: String?): String? {
|
||||
val trimmed = value?.trim()?.takeIf { it.isNotEmpty() } ?: return null
|
||||
return trimmed
|
||||
.map { char ->
|
||||
if (char.isLetterOrDigit() || char == '_' || char == '-' || char == '.') {
|
||||
char
|
||||
} else {
|
||||
'_'
|
||||
}
|
||||
}
|
||||
.joinToString(separator = "")
|
||||
.take(160)
|
||||
.takeIf { it.isNotBlank() }
|
||||
}
|
||||
|
||||
fun sanitizeRawBlackBorderCropPx(value: Int): Int {
|
||||
return value.coerceIn(0, MAX_RAW_BLACK_BORDER_CROP_PX)
|
||||
}
|
||||
|
||||
@@ -33,6 +33,16 @@ data class VendorCaptureSettings(
|
||||
return withOverride(key, enabled = true, value = value)
|
||||
}
|
||||
|
||||
fun toVirtualLensProfileId(): String? {
|
||||
if (!isEnabled) return null
|
||||
return values.entries
|
||||
.sortedBy { it.key.ordinal }
|
||||
.joinToString("-") { (key, value) ->
|
||||
"${key.persistedName}_${formatProfileValue(key.normalizeValue(value))}"
|
||||
}
|
||||
.takeIf { it.isNotBlank() }
|
||||
}
|
||||
|
||||
internal fun toJsonObject(): JSONObject {
|
||||
return JSONObject().apply {
|
||||
VendorCaptureKey.entries.forEach { key ->
|
||||
@@ -44,6 +54,14 @@ data class VendorCaptureSettings(
|
||||
companion object {
|
||||
val Empty = VendorCaptureSettings()
|
||||
|
||||
private fun formatProfileValue(value: Int): String {
|
||||
return if (value < 0) {
|
||||
"n${value.toString().drop(1)}"
|
||||
} else {
|
||||
value.toString()
|
||||
}
|
||||
}
|
||||
|
||||
internal fun fromJsonObject(json: JSONObject): VendorCaptureSettings {
|
||||
val parsedValues = VendorCaptureKey.entries
|
||||
.mapNotNull { key ->
|
||||
|
||||
@@ -113,6 +113,7 @@ data class UserPreferences(
|
||||
val rawBlackLevelModes: Map<String, String> = emptyMap(),
|
||||
val rawCustomBlackLevels: Map<String, Float> = emptyMap(),
|
||||
val rawWhiteLevelModes: Map<String, String> = emptyMap(),
|
||||
val rawCustomWhiteLevels: Map<String, Float> = emptyMap(),
|
||||
val rawCfaCorrectionModes: Map<String, String> = emptyMap(),
|
||||
val exportDngWithRawExport: Boolean = false,
|
||||
val frameId: String? = null,
|
||||
@@ -207,6 +208,7 @@ data class UserPreferences(
|
||||
val lensIdBlacklist: List<String> = emptyList(), // 主动探测黑名单镜头 ID,逗号分隔存储
|
||||
val iszLensConfigs: List<IszLensConfig> = emptyList(), // 用户新增的 ISZ 虚拟镜头
|
||||
val preferredMainCameraId: String? = null, // 用户选择的主摄 ID
|
||||
val preferredMacroCameraId: String? = null, // 用户选择的微距镜头 ID
|
||||
val enableLogicalMultiCameraDiscovery: Boolean = false, // 是否自动探测逻辑多摄物理镜头绑定
|
||||
val logicalCameraBindingWhitelist: List<String> = emptyList(), // 强制启用的逻辑/物理镜头绑定,格式 logical/physical
|
||||
val hiddenFocalLengths: List<Float> = emptyList(), // 隐藏的焦段 (35mm等效)
|
||||
@@ -308,6 +310,7 @@ class UserPreferencesRepository(private val context: Context) {
|
||||
private val RAW_BLACK_LEVEL_MODES_KEY = stringPreferencesKey("raw_black_level_modes")
|
||||
private val RAW_CUSTOM_BLACK_LEVELS_KEY = stringPreferencesKey("raw_custom_black_levels")
|
||||
private val RAW_WHITE_LEVEL_MODES_KEY = stringPreferencesKey("raw_white_level_modes")
|
||||
private val RAW_CUSTOM_WHITE_LEVELS_KEY = stringPreferencesKey("raw_custom_white_levels")
|
||||
private val RAW_CFA_CORRECTION_MODES_KEY = stringPreferencesKey("raw_cfa_correction_modes")
|
||||
private val EXPORT_DNG_WITH_RAW_EXPORT_KEY = booleanPreferencesKey("export_dng_with_raw_export")
|
||||
private val PHANTOM_BASELINE_LUT_ID_KEY = stringPreferencesKey("phantom_baseline_lut_id")
|
||||
@@ -413,6 +416,7 @@ class UserPreferencesRepository(private val context: Context) {
|
||||
private val LENS_ID_BLACKLIST = stringPreferencesKey("lens_id_blacklist")
|
||||
private val ISZ_LENS_CONFIGS = stringPreferencesKey("isz_lens_configs")
|
||||
private val PREFERRED_MAIN_CAMERA_ID = stringPreferencesKey("preferred_main_camera_id")
|
||||
private val PREFERRED_MACRO_CAMERA_ID = stringPreferencesKey("preferred_macro_camera_id")
|
||||
private val ENABLE_LOGICAL_MULTI_CAMERA_DISCOVERY = booleanPreferencesKey("enable_logical_multi_camera_discovery")
|
||||
private val LOGICAL_CAMERA_BINDING_WHITELIST = stringPreferencesKey("logical_camera_binding_whitelist")
|
||||
private val HIDDEN_FOCAL_LENGTHS = stringPreferencesKey("hidden_focal_lengths")
|
||||
@@ -482,6 +486,7 @@ class UserPreferencesRepository(private val context: Context) {
|
||||
rawBlackLevelModes = parseMapString(preferences[RAW_BLACK_LEVEL_MODES_KEY]),
|
||||
rawCustomBlackLevels = parseMapFloat(preferences[RAW_CUSTOM_BLACK_LEVELS_KEY]),
|
||||
rawWhiteLevelModes = parseMapString(preferences[RAW_WHITE_LEVEL_MODES_KEY]),
|
||||
rawCustomWhiteLevels = parseMapFloat(preferences[RAW_CUSTOM_WHITE_LEVELS_KEY]),
|
||||
rawCfaCorrectionModes = parseMapString(preferences[RAW_CFA_CORRECTION_MODES_KEY]),
|
||||
exportDngWithRawExport = preferences[EXPORT_DNG_WITH_RAW_EXPORT_KEY] ?: false,
|
||||
phantomBaselineLutId = preferences[PHANTOM_BASELINE_LUT_ID_KEY],
|
||||
@@ -615,6 +620,7 @@ class UserPreferencesRepository(private val context: Context) {
|
||||
lensIdBlacklist = parseLensIds(preferences[LENS_ID_BLACKLIST]),
|
||||
iszLensConfigs = IszLensConfig.deserializeList(preferences[ISZ_LENS_CONFIGS]),
|
||||
preferredMainCameraId = preferences[PREFERRED_MAIN_CAMERA_ID]?.takeIf { it.isNotBlank() },
|
||||
preferredMacroCameraId = preferences[PREFERRED_MACRO_CAMERA_ID]?.takeIf { it.isNotBlank() },
|
||||
enableLogicalMultiCameraDiscovery = preferences[ENABLE_LOGICAL_MULTI_CAMERA_DISCOVERY] ?: false,
|
||||
logicalCameraBindingWhitelist = parseLogicalCameraBindingWhitelist(
|
||||
preferences[LOGICAL_CAMERA_BINDING_WHITELIST]
|
||||
@@ -1075,6 +1081,15 @@ class UserPreferencesRepository(private val context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun saveRawCustomWhiteLevel(cameraId: String, value: Float) {
|
||||
context.dataStore.edit { preferences ->
|
||||
val current = parseMapFloat(preferences[RAW_CUSTOM_WHITE_LEVELS_KEY])
|
||||
val updated = current.toMutableMap()
|
||||
updated[cameraId] = value
|
||||
preferences[RAW_CUSTOM_WHITE_LEVELS_KEY] = serializeMapFloat(updated)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun saveRawCfaCorrectionMode(cameraId: String, mode: String) {
|
||||
context.dataStore.edit { preferences ->
|
||||
val current = parseMapString(preferences[RAW_CFA_CORRECTION_MODES_KEY])
|
||||
@@ -1448,6 +1463,17 @@ class UserPreferencesRepository(private val context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun savePreferredMacroCameraId(cameraId: String?) {
|
||||
context.dataStore.edit { preferences ->
|
||||
val normalizedCameraId = cameraId?.trim()?.takeIf { it.isNotEmpty() }
|
||||
if (normalizedCameraId == null) {
|
||||
preferences.remove(PREFERRED_MACRO_CAMERA_ID)
|
||||
} else {
|
||||
preferences[PREFERRED_MACRO_CAMERA_ID] = normalizedCameraId
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun saveEnableLogicalMultiCameraDiscovery(enabled: Boolean) {
|
||||
context.dataStore.edit { preferences ->
|
||||
preferences[ENABLE_LOGICAL_MULTI_CAMERA_DISCOVERY] = enabled
|
||||
|
||||
@@ -45,6 +45,7 @@ import com.hinnka.mycamera.raw.SpectralFilmTuning
|
||||
import com.hinnka.mycamera.utils.BitmapUtils
|
||||
import com.hinnka.mycamera.utils.DngBlackLevelPatcher
|
||||
import com.hinnka.mycamera.utils.DngCfaPatternPatcher
|
||||
import com.hinnka.mycamera.utils.DngWhiteLevelPatcher
|
||||
import com.hinnka.mycamera.utils.LargeDirectBuffer
|
||||
import com.hinnka.mycamera.utils.PLog
|
||||
import com.hinnka.mycamera.utils.RawProcessor
|
||||
@@ -1824,6 +1825,7 @@ object GalleryManager {
|
||||
blackLevelMode = metadata.rawBlackLevelMode,
|
||||
customBlackLevel = metadata.rawCustomBlackLevel,
|
||||
whiteLevelMode = metadata.rawWhiteLevelMode,
|
||||
customWhiteLevel = metadata.rawCustomWhiteLevel,
|
||||
cfaCorrectionMode = metadata.rawCfaCorrectionMode
|
||||
)
|
||||
} catch (e: Throwable) {
|
||||
@@ -1870,6 +1872,7 @@ object GalleryManager {
|
||||
rawBlackLevelMode = updatedMetadata.rawBlackLevelMode,
|
||||
rawCustomBlackLevel = updatedMetadata.rawCustomBlackLevel,
|
||||
rawWhiteLevelMode = updatedMetadata.rawWhiteLevelMode,
|
||||
rawCustomWhiteLevel = updatedMetadata.rawCustomWhiteLevel,
|
||||
sharpeningValue = rawSharpening,
|
||||
denoiseValue = rawNoiseReduction,
|
||||
chromaDenoiseValue = rawChromaNoiseReduction,
|
||||
@@ -2651,7 +2654,8 @@ object GalleryManager {
|
||||
}
|
||||
val stackWhiteLevel = RawProcessor.resolveWhiteLevelForMode(
|
||||
defaultWhiteLevel = rawMetadata.whiteLevel,
|
||||
whiteLevelMode = metadata.rawWhiteLevelMode
|
||||
whiteLevelMode = metadata.rawWhiteLevelMode,
|
||||
customWhiteLevel = metadata.rawCustomWhiteLevel
|
||||
).toInt()
|
||||
if (stackWhiteLevel != rawMetadata.whiteLevel.toInt()) {
|
||||
PLog.d(TAG, "RAW stack white level override mode=${metadata.rawWhiteLevelMode} value=$stackWhiteLevel")
|
||||
@@ -2747,6 +2751,7 @@ object GalleryManager {
|
||||
rawBlackLevelMode = updatedMetadata.rawBlackLevelMode,
|
||||
rawCustomBlackLevel = updatedMetadata.rawCustomBlackLevel,
|
||||
rawWhiteLevelMode = updatedMetadata.rawWhiteLevelMode,
|
||||
rawCustomWhiteLevel = updatedMetadata.rawCustomWhiteLevel,
|
||||
sharpeningValue = rawSharpening,
|
||||
denoiseValue = rawNoiseReduction,
|
||||
chromaDenoiseValue = rawChromaNoiseReduction,
|
||||
@@ -2950,7 +2955,8 @@ object GalleryManager {
|
||||
}
|
||||
val stackWhiteLevel = RawProcessor.resolveWhiteLevelForMode(
|
||||
defaultWhiteLevel = rawMetadata.whiteLevel,
|
||||
whiteLevelMode = metadata.rawWhiteLevelMode
|
||||
whiteLevelMode = metadata.rawWhiteLevelMode,
|
||||
customWhiteLevel = metadata.rawCustomWhiteLevel
|
||||
).toInt()
|
||||
if (stackWhiteLevel != rawMetadata.whiteLevel.toInt()) {
|
||||
PLog.d(TAG, "RAW HDR white level override mode=${metadata.rawWhiteLevelMode} value=$stackWhiteLevel")
|
||||
@@ -3101,7 +3107,8 @@ object GalleryManager {
|
||||
private fun MediaMetadata.withNormalizedRawLevelCorrectionsCleared(source: String): MediaMetadata {
|
||||
val hasLevelOverride = rawBlackLevelMode != null ||
|
||||
rawCustomBlackLevel != null ||
|
||||
rawWhiteLevelMode != null
|
||||
rawWhiteLevelMode != null ||
|
||||
rawCustomWhiteLevel != null
|
||||
if (!hasLevelOverride) {
|
||||
return this
|
||||
}
|
||||
@@ -3112,7 +3119,8 @@ object GalleryManager {
|
||||
return copy(
|
||||
rawBlackLevelMode = null,
|
||||
rawCustomBlackLevel = null,
|
||||
rawWhiteLevelMode = null
|
||||
rawWhiteLevelMode = null,
|
||||
rawCustomWhiteLevel = null
|
||||
)
|
||||
}
|
||||
|
||||
@@ -3187,6 +3195,7 @@ object GalleryManager {
|
||||
rawBlackLevelMode = updatedMetadata.rawBlackLevelMode,
|
||||
rawCustomBlackLevel = updatedMetadata.rawCustomBlackLevel,
|
||||
rawWhiteLevelMode = updatedMetadata.rawWhiteLevelMode,
|
||||
rawCustomWhiteLevel = updatedMetadata.rawCustomWhiteLevel,
|
||||
sharpeningValue = rawSharpening,
|
||||
denoiseValue = rawNoiseReduction,
|
||||
chromaDenoiseValue = rawChromaNoiseReduction,
|
||||
@@ -3402,6 +3411,14 @@ object GalleryManager {
|
||||
if (patched) {
|
||||
PLog.d(TAG, "Applied DNG BlackLevel correction (${metadata.rawBlackLevelMode}) to ${dngFile.name}")
|
||||
}
|
||||
val whitePatched = DngWhiteLevelPatcher.patchFromMode(
|
||||
file = dngFile,
|
||||
mode = metadata.rawWhiteLevelMode,
|
||||
customWhiteLevel = metadata.rawCustomWhiteLevel
|
||||
)
|
||||
if (whitePatched) {
|
||||
PLog.d(TAG, "Applied DNG WhiteLevel correction (${metadata.rawWhiteLevelMode}) to ${dngFile.name}")
|
||||
}
|
||||
val cfaPatched = DngCfaPatternPatcher.patchFromMode(
|
||||
file = dngFile,
|
||||
mode = metadata.rawCfaCorrectionMode
|
||||
@@ -3409,7 +3426,7 @@ object GalleryManager {
|
||||
if (cfaPatched) {
|
||||
PLog.d(TAG, "Applied DNG CFA correction (${metadata.rawCfaCorrectionMode}) to ${dngFile.name}")
|
||||
}
|
||||
return patched || cfaPatched
|
||||
return patched || whitePatched || cfaPatched
|
||||
}
|
||||
|
||||
|
||||
@@ -4330,6 +4347,7 @@ object GalleryManager {
|
||||
rawBlackLevelMode = updatedMetadata.rawBlackLevelMode,
|
||||
rawCustomBlackLevel = updatedMetadata.rawCustomBlackLevel,
|
||||
rawWhiteLevelMode = updatedMetadata.rawWhiteLevelMode,
|
||||
rawCustomWhiteLevel = updatedMetadata.rawCustomWhiteLevel,
|
||||
sharpeningValue = RawSharpeningDefaults.CAPTURE_DEFAULT,
|
||||
denoiseValue = rawNoiseReduction,
|
||||
chromaDenoiseValue = rawChromaNoiseReduction,
|
||||
@@ -4487,6 +4505,7 @@ object GalleryManager {
|
||||
rawBlackLevelMode = updatedMetadata?.rawBlackLevelMode,
|
||||
rawCustomBlackLevel = updatedMetadata?.rawCustomBlackLevel,
|
||||
rawWhiteLevelMode = updatedMetadata?.rawWhiteLevelMode,
|
||||
rawCustomWhiteLevel = updatedMetadata?.rawCustomWhiteLevel,
|
||||
sharpeningValue = updatedMetadata?.sharpening ?: RawSharpeningDefaults.CAPTURE_DEFAULT,
|
||||
denoiseValue = rawNoiseReduction,
|
||||
chromaDenoiseValue = rawChromaNoiseReduction,
|
||||
|
||||
@@ -29,7 +29,7 @@ const val TONEMAP_MODE_NATURAL_LIGHT = "NATURAL_LIGHT"
|
||||
* 保存 LUT、边框水印、编辑信息和拍摄参数,用于非破坏性编辑和边框水印渲染
|
||||
*/
|
||||
data class MediaMetadata(
|
||||
val version: Int = 23,
|
||||
val version: Int = 24,
|
||||
val mediaType: MediaType = MediaType.IMAGE,
|
||||
// 编辑配置
|
||||
val lutId: String? = null,
|
||||
@@ -117,6 +117,7 @@ data class MediaMetadata(
|
||||
val rawBlackLevelMode: String? = null,
|
||||
val rawCustomBlackLevel: Float? = null,
|
||||
val rawWhiteLevelMode: String? = null,
|
||||
val rawCustomWhiteLevel: Float? = null,
|
||||
val rawCfaCorrectionMode: String? = null,
|
||||
val rawBlackBorderCrop: RawBlackBorderCrop = RawBlackBorderCrop(),
|
||||
val applyEffectsToVideo: Boolean = false,
|
||||
@@ -344,6 +345,7 @@ data class MediaMetadata(
|
||||
rawBlackLevelMode = if (obj.isNull("rawBlackLevelMode")) null else obj.optString("rawBlackLevelMode"),
|
||||
rawCustomBlackLevel = if (obj.isNull("rawCustomBlackLevel")) null else obj.optDouble("rawCustomBlackLevel").toFloat(),
|
||||
rawWhiteLevelMode = if (obj.isNull("rawWhiteLevelMode")) null else obj.optString("rawWhiteLevelMode"),
|
||||
rawCustomWhiteLevel = if (obj.isNull("rawCustomWhiteLevel")) null else obj.optDouble("rawCustomWhiteLevel").toFloat(),
|
||||
rawCfaCorrectionMode = if (obj.isNull("rawCfaCorrectionMode")) null else obj.optString("rawCfaCorrectionMode"),
|
||||
cameraId = if (obj.isNull("cameraId")) null else obj.optString("cameraId"),
|
||||
frameId = if (obj.isNull("frameId")) null else obj.optString("frameId"),
|
||||
|
||||
@@ -502,6 +502,7 @@ class PhotoProcessor(
|
||||
rawBlackLevelMode = metadata.rawBlackLevelMode,
|
||||
rawCustomBlackLevel = metadata.rawCustomBlackLevel,
|
||||
rawWhiteLevelMode = metadata.rawWhiteLevelMode,
|
||||
rawCustomWhiteLevel = metadata.rawCustomWhiteLevel,
|
||||
sharpeningValue = rawSharpening,
|
||||
denoiseValue = rawNoiseReduction,
|
||||
chromaDenoiseValue = rawChromaNoiseReduction,
|
||||
@@ -580,6 +581,7 @@ class PhotoProcessor(
|
||||
rawBlackLevelMode = metadata.rawBlackLevelMode,
|
||||
rawCustomBlackLevel = metadata.rawCustomBlackLevel,
|
||||
rawWhiteLevelMode = metadata.rawWhiteLevelMode,
|
||||
rawCustomWhiteLevel = metadata.rawCustomWhiteLevel,
|
||||
sharpeningValue = finalSharpening,
|
||||
denoiseValue = finalNoiseReduction,
|
||||
chromaDenoiseValue = finalChromaNoiseReduction,
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.hinnka.mycamera.raw.RawToneMappingParameters
|
||||
|
||||
@Database(
|
||||
entities = [GalleryMediaEntity::class],
|
||||
version = 20,
|
||||
version = 21,
|
||||
exportSchema = false
|
||||
)
|
||||
@androidx.room.TypeConverters(GalleryConverters::class)
|
||||
@@ -166,6 +166,12 @@ abstract class GalleryDatabase : RoomDatabase() {
|
||||
}
|
||||
}
|
||||
|
||||
private val MIGRATION_20_21 = object : androidx.room.migration.Migration(20, 21) {
|
||||
override fun migrate(db: androidx.sqlite.db.SupportSQLiteDatabase) {
|
||||
db.execSQL("ALTER TABLE gallery_media ADD COLUMN rawCustomWhiteLevel REAL")
|
||||
}
|
||||
}
|
||||
|
||||
private fun rebuildGalleryMediaWithoutLegacyGoogleToneMapFlag(
|
||||
db: androidx.sqlite.db.SupportSQLiteDatabase
|
||||
) {
|
||||
@@ -517,7 +523,8 @@ abstract class GalleryDatabase : RoomDatabase() {
|
||||
MIGRATION_16_17,
|
||||
MIGRATION_17_18,
|
||||
MIGRATION_18_19,
|
||||
MIGRATION_19_20
|
||||
MIGRATION_19_20,
|
||||
MIGRATION_20_21
|
||||
)
|
||||
.fallbackToDestructiveMigrationOnDowngrade(false)
|
||||
.fallbackToDestructiveMigration(false)
|
||||
|
||||
@@ -120,6 +120,7 @@ data class GalleryMediaEntity(
|
||||
val rawBlackLevelMode: String?,
|
||||
val rawCustomBlackLevel: Float?,
|
||||
val rawWhiteLevelMode: String?,
|
||||
val rawCustomWhiteLevel: Float?,
|
||||
val rawCfaCorrectionMode: String?,
|
||||
val rawBlackBorderCropLeftPx: Int,
|
||||
val rawBlackBorderCropTopPx: Int,
|
||||
|
||||
@@ -294,6 +294,7 @@ object GalleryMediaStore {
|
||||
rawBlackLevelMode = metadata.rawBlackLevelMode,
|
||||
rawCustomBlackLevel = metadata.rawCustomBlackLevel,
|
||||
rawWhiteLevelMode = metadata.rawWhiteLevelMode,
|
||||
rawCustomWhiteLevel = metadata.rawCustomWhiteLevel,
|
||||
rawCfaCorrectionMode = metadata.rawCfaCorrectionMode,
|
||||
rawBlackBorderCropLeftPx = metadata.rawBlackBorderCrop.leftPx,
|
||||
rawBlackBorderCropTopPx = metadata.rawBlackBorderCrop.topPx,
|
||||
@@ -469,6 +470,7 @@ object GalleryMediaStore {
|
||||
rawBlackLevelMode = rawBlackLevelMode,
|
||||
rawCustomBlackLevel = rawCustomBlackLevel,
|
||||
rawWhiteLevelMode = rawWhiteLevelMode,
|
||||
rawCustomWhiteLevel = rawCustomWhiteLevel,
|
||||
rawCfaCorrectionMode = rawCfaCorrectionMode,
|
||||
rawBlackBorderCrop = RawBlackBorderCrop(
|
||||
leftPx = rawBlackBorderCropLeftPx,
|
||||
|
||||
@@ -53,6 +53,7 @@ private fun MediaMetadata.thumbnailTransformCacheKey(): Int {
|
||||
rawBlackLevelMode = null,
|
||||
rawCustomBlackLevel = null,
|
||||
rawWhiteLevelMode = null,
|
||||
rawCustomWhiteLevel = null,
|
||||
rawCfaCorrectionMode = null,
|
||||
cameraId = null,
|
||||
sourceUri = null,
|
||||
|
||||
@@ -296,7 +296,7 @@ class GlesRawStacker(
|
||||
GlesGpuScheduler.waitForGpuCheckpoint(TAG, "hdr normal frame $frameIndex accumulation")
|
||||
}
|
||||
|
||||
computeHdrRecoveryMask()
|
||||
computeHdrRecoveryMask(shortToReferenceExposureScale = shortAlignmentScale)
|
||||
GlesGpuScheduler.yieldToUiRenderer()
|
||||
normalizeOutput(
|
||||
hdrMode = true,
|
||||
@@ -931,8 +931,8 @@ class GlesRawStacker(
|
||||
currentAccumulatorTexture = outputAccumulator
|
||||
}
|
||||
|
||||
private fun computeHdrRecoveryMask() {
|
||||
computeInitialHdrRecoveryMask()
|
||||
private fun computeHdrRecoveryMask(shortToReferenceExposureScale: Float) {
|
||||
computeInitialHdrRecoveryMask(shortToReferenceExposureScale)
|
||||
filterHdrRecoveryMask(
|
||||
program = hdrRecoveryDilateProgram,
|
||||
input = hdrRecoveryOrigMaskTexture,
|
||||
@@ -947,15 +947,21 @@ class GlesRawStacker(
|
||||
)
|
||||
}
|
||||
|
||||
private fun computeInitialHdrRecoveryMask() {
|
||||
private fun computeInitialHdrRecoveryMask(shortToReferenceExposureScale: Float) {
|
||||
bindFramebufferOutput(hdrRecoveryOrigMaskTexture, "computeHdrRecoveryMask initial")
|
||||
GLES30.glViewport(0, 0, planeWidth, planeHeight)
|
||||
GLES30.glUseProgram(hdrRecoveryMaskProgram)
|
||||
bindTexture(hdrRecoveryMaskProgram, "uAccumulator", 0, currentAccumulatorTexture)
|
||||
bindTexture(hdrRecoveryMaskProgram, "uReferenceRaw", 1, refRaw)
|
||||
bindTexture(hdrRecoveryMaskProgram, "uShortRaw", 2, hdrShortRaw)
|
||||
bindTexture(hdrRecoveryMaskProgram, "uShortGlobalAlignment", 3, hdrShortAlignmentTexture)
|
||||
setCommonUniforms(hdrRecoveryMaskProgram)
|
||||
GLES31.glUniform2i(GLES31.glGetUniformLocation(hdrRecoveryMaskProgram, "uImageSize"), width, height)
|
||||
GLES31.glUniform2i(GLES31.glGetUniformLocation(hdrRecoveryMaskProgram, "uPlaneSize"), planeWidth, planeHeight)
|
||||
GLES31.glUniform1f(
|
||||
GLES31.glGetUniformLocation(hdrRecoveryMaskProgram, "uShortToReferenceExposureScale"),
|
||||
shortToReferenceExposureScale,
|
||||
)
|
||||
GLES30.glDrawArrays(GLES30.GL_TRIANGLES, 0, 3)
|
||||
finishFramebufferPass("computeHdrRecoveryMask initial")
|
||||
}
|
||||
@@ -2286,11 +2292,14 @@ class GlesRawStacker(
|
||||
out vec4 fragColor;
|
||||
uniform sampler2D uAccumulator;
|
||||
uniform highp usampler2D uReferenceRaw;
|
||||
uniform highp usampler2D uShortRaw;
|
||||
uniform sampler2D uShortGlobalAlignment;
|
||||
uniform ivec2 uImageSize;
|
||||
uniform ivec2 uPlaneSize;
|
||||
uniform int uCfaPattern;
|
||||
uniform float uBlackLevel[4];
|
||||
uniform float uWhiteLevel;
|
||||
uniform float uShortToReferenceExposureScale;
|
||||
|
||||
ivec2 clampRaw(ivec2 p) {
|
||||
return clamp(p, ivec2(0), uImageSize - ivec2(1));
|
||||
@@ -2304,6 +2313,24 @@ class GlesRawStacker(
|
||||
return clamp(max(raw - uBlackLevel[bayerIndex], 0.0) / range, 0.0, 1.0);
|
||||
}
|
||||
|
||||
ivec2 shortAlignedPos(ivec2 p) {
|
||||
ivec2 rawOffset = ivec2(round(texelFetch(uShortGlobalAlignment, ivec2(0), 0).rg)) * 2;
|
||||
return clampRaw(p + rawOffset);
|
||||
}
|
||||
|
||||
float shortSensorNorm(ivec2 p) {
|
||||
p = clampRaw(p);
|
||||
ivec2 shortPos = shortAlignedPos(p);
|
||||
int bayerIndex = bayerIndexAt(uCfaPattern, p);
|
||||
float raw = float(texelFetch(uShortRaw, shortPos, 0).r);
|
||||
float range = max(uWhiteLevel - uBlackLevel[bayerIndex], 1.0);
|
||||
return clamp(max(raw - uBlackLevel[bayerIndex], 0.0) / range, 0.0, 1.0);
|
||||
}
|
||||
|
||||
float shortReferenceNorm(ivec2 p) {
|
||||
return clamp(shortSensorNorm(p) * uShortToReferenceExposureScale, 0.0, 1.0);
|
||||
}
|
||||
|
||||
float referenceBlockMax(ivec2 base) {
|
||||
float m = 0.0;
|
||||
for (int y = 0; y <= 1; ++y) {
|
||||
@@ -2314,6 +2341,26 @@ class GlesRawStacker(
|
||||
return m;
|
||||
}
|
||||
|
||||
float shortReferenceBlockMax(ivec2 base) {
|
||||
float m = 0.0;
|
||||
for (int y = 0; y <= 1; ++y) {
|
||||
for (int x = 0; x <= 1; ++x) {
|
||||
m = max(m, shortReferenceNorm(base + ivec2(x, y)));
|
||||
}
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
float shortReferenceBlockMean(ivec2 base) {
|
||||
float sum = 0.0;
|
||||
for (int y = 0; y <= 1; ++y) {
|
||||
for (int x = 0; x <= 1; ++x) {
|
||||
sum += shortReferenceNorm(base + ivec2(x, y));
|
||||
}
|
||||
}
|
||||
return sum * 0.25;
|
||||
}
|
||||
|
||||
float blockClipRatioMax(ivec2 base) {
|
||||
float m = 0.0;
|
||||
for (int y = 0; y <= 1; ++y) {
|
||||
@@ -2326,28 +2373,48 @@ class GlesRawStacker(
|
||||
return m;
|
||||
}
|
||||
|
||||
float referenceAroundMax(ivec2 base) {
|
||||
float m = 0.0;
|
||||
float shortReferenceConsistency(ivec2 base) {
|
||||
float residualSum = 0.0;
|
||||
float count = 0.0;
|
||||
for (int y = -1; y <= 2; ++y) {
|
||||
for (int x = -1; x <= 2; ++x) {
|
||||
m = max(m, sensorNorm(uReferenceRaw, base + ivec2(x, y)));
|
||||
ivec2 p = base + ivec2(x, y);
|
||||
float reference = sensorNorm(uReferenceRaw, p);
|
||||
if (reference <= 0.035 || reference >= 0.860) {
|
||||
continue;
|
||||
}
|
||||
float shortReference = shortReferenceNorm(p);
|
||||
float residual = abs(shortReference - reference) / max(max(shortReference, reference), 0.08);
|
||||
residualSum += residual;
|
||||
count += 1.0;
|
||||
}
|
||||
}
|
||||
return m;
|
||||
float support = smoothstep(2.0, 8.0, count);
|
||||
float averageResidual = residualSum / max(count, 1.0);
|
||||
float consistency = 1.0 - smoothstep(0.26, 0.58, averageResidual);
|
||||
return mix(1.0, consistency, support);
|
||||
}
|
||||
|
||||
void main() {
|
||||
const float saturationThreshold = 0.990;
|
||||
ivec2 block = clamp(ivec2(gl_FragCoord.xy), ivec2(0), uPlaneSize - ivec2(1));
|
||||
ivec2 base = block * 2;
|
||||
float refMax = referenceBlockMax(base);
|
||||
float clipRatio = blockClipRatioMax(base);
|
||||
float aroundMax = referenceAroundMax(base);
|
||||
float shortMax = shortReferenceBlockMax(base);
|
||||
float shortMean = shortReferenceBlockMean(base);
|
||||
float consistency = shortReferenceConsistency(base);
|
||||
|
||||
float saturatedAround = step(saturationThreshold, aroundMax);
|
||||
float accumulatedClip = step(0.50, clipRatio) * step(0.900, refMax);
|
||||
float sourceMask = max(saturatedAround, accumulatedClip);
|
||||
float saturationPush = clamp((aroundMax - saturationThreshold) / (1.0 - saturationThreshold), 0.0, 1.0);
|
||||
float saturatedCore = smoothstep(0.970, 0.995, refMax);
|
||||
float accumulatedClip = smoothstep(0.35, 0.65, clipRatio) * smoothstep(0.880, 0.960, refMax);
|
||||
float sourceMask = max(saturatedCore, accumulatedClip);
|
||||
|
||||
float shortPeakConfidence = smoothstep(0.46, 0.78, shortMax);
|
||||
float shortMeanConfidence = smoothstep(0.16, 0.42, shortMean);
|
||||
float shortSignalConfidence = shortPeakConfidence * (0.45 + 0.55 * shortMeanConfidence);
|
||||
float recoveryConfidence = clamp(shortSignalConfidence * consistency, 0.0, 1.0);
|
||||
|
||||
sourceMask = clamp(sourceMask * recoveryConfidence, 0.0, 1.0);
|
||||
float saturationPush = smoothstep(0.990, 0.999, refMax) * recoveryConfidence;
|
||||
fragColor = vec4(sourceMask, saturationPush, 0.0, 1.0);
|
||||
}
|
||||
""".trimIndent()
|
||||
@@ -2711,7 +2778,16 @@ class GlesRawStacker(
|
||||
recoveryMix = clamp(recoveryMix, 0.0, 1.0);
|
||||
fused = mix(reference, fused, normalConfidence);
|
||||
if (recoveryMix > 0.0001) {
|
||||
fused = mix(fused, shortRecoveryNorm(p, bayerIndex), recoveryMix);
|
||||
float shortValue = shortRecoveryNorm(p, bayerIndex);
|
||||
float shortPresenceFloor = max(0.012, reference * 0.25);
|
||||
float shortPresenceWidth = max(0.035, reference * 0.45);
|
||||
float shortPresence = smoothstep(
|
||||
shortPresenceFloor,
|
||||
shortPresenceFloor + shortPresenceWidth,
|
||||
shortValue
|
||||
);
|
||||
recoveryMix *= shortPresence;
|
||||
fused = mix(fused, shortValue, recoveryMix);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -502,10 +502,15 @@ class RawDemosaicProcessor {
|
||||
return metadata.copy(blackLevel = resolvedBlackLevel)
|
||||
}
|
||||
|
||||
private fun applyWhiteLevelOverride(metadata: RawMetadata, mode: String?): RawMetadata {
|
||||
private fun applyWhiteLevelOverride(
|
||||
metadata: RawMetadata,
|
||||
mode: String?,
|
||||
customWhiteLevel: Float?
|
||||
): RawMetadata {
|
||||
val resolvedWhiteLevel = RawWhiteLevelCorrection.resolveWhiteLevel(
|
||||
defaultWhiteLevel = metadata.whiteLevel,
|
||||
mode = mode
|
||||
mode = mode,
|
||||
customWhiteLevel = customWhiteLevel
|
||||
)
|
||||
if (metadata.whiteLevel == resolvedWhiteLevel) {
|
||||
return metadata
|
||||
@@ -519,12 +524,14 @@ class RawDemosaicProcessor {
|
||||
rawBlackLevelMode: String?,
|
||||
rawCustomBlackLevel: Float?,
|
||||
rawWhiteLevelMode: String?,
|
||||
rawCustomWhiteLevel: Float?,
|
||||
rawCfaCorrectionMode: String?
|
||||
): RawMetadata {
|
||||
return applyCfaCorrectionOverride(
|
||||
metadata = applyWhiteLevelOverride(
|
||||
metadata = applyBlackLevelOverride(metadata, rawBlackLevelMode, rawCustomBlackLevel),
|
||||
mode = rawWhiteLevelMode
|
||||
mode = rawWhiteLevelMode,
|
||||
customWhiteLevel = rawCustomWhiteLevel
|
||||
),
|
||||
mode = rawCfaCorrectionMode
|
||||
)
|
||||
@@ -889,6 +896,7 @@ class RawDemosaicProcessor {
|
||||
rawBlackLevelMode: String? = null,
|
||||
rawCustomBlackLevel: Float? = null,
|
||||
rawWhiteLevelMode: String? = null,
|
||||
rawCustomWhiteLevel: Float? = null,
|
||||
sharpeningValue: Float = 0f,
|
||||
denoiseValue: Float? = null,
|
||||
chromaDenoiseValue: Float? = null,
|
||||
@@ -929,6 +937,7 @@ class RawDemosaicProcessor {
|
||||
rawBlackLevelMode = rawBlackLevelMode,
|
||||
rawCustomBlackLevel = rawCustomBlackLevel,
|
||||
rawWhiteLevelMode = rawWhiteLevelMode,
|
||||
rawCustomWhiteLevel = rawCustomWhiteLevel,
|
||||
sharpeningValue = sharpeningValue,
|
||||
denoiseValue = denoiseValue,
|
||||
chromaDenoiseValue = chromaDenoiseValue,
|
||||
@@ -1140,6 +1149,7 @@ class RawDemosaicProcessor {
|
||||
rawBlackLevelMode: String? = null,
|
||||
rawCustomBlackLevel: Float? = null,
|
||||
rawWhiteLevelMode: String? = null,
|
||||
rawCustomWhiteLevel: Float? = null,
|
||||
sharpeningValue: Float = 0f,
|
||||
denoiseValue: Float? = null,
|
||||
chromaDenoiseValue: Float? = null,
|
||||
@@ -1180,6 +1190,7 @@ class RawDemosaicProcessor {
|
||||
rawBlackLevelMode = rawBlackLevelMode,
|
||||
rawCustomBlackLevel = rawCustomBlackLevel,
|
||||
rawWhiteLevelMode = rawWhiteLevelMode,
|
||||
rawCustomWhiteLevel = rawCustomWhiteLevel,
|
||||
sharpeningValue = sharpeningValue,
|
||||
denoiseValue = denoiseValue,
|
||||
chromaDenoiseValue = chromaDenoiseValue,
|
||||
@@ -1229,6 +1240,7 @@ class RawDemosaicProcessor {
|
||||
rawBlackLevelMode: String? = null,
|
||||
rawCustomBlackLevel: Float? = null,
|
||||
rawWhiteLevelMode: String? = null,
|
||||
rawCustomWhiteLevel: Float? = null,
|
||||
sharpeningValue: Float = 0f,
|
||||
denoiseValue: Float? = null,
|
||||
chromaDenoiseValue: Float? = null,
|
||||
@@ -1297,6 +1309,7 @@ class RawDemosaicProcessor {
|
||||
rawBlackLevelMode = rawBlackLevelMode,
|
||||
rawCustomBlackLevel = rawCustomBlackLevel,
|
||||
rawWhiteLevelMode = rawWhiteLevelMode,
|
||||
rawCustomWhiteLevel = rawCustomWhiteLevel,
|
||||
rawCfaCorrectionMode = rawCfaCorrectionMode
|
||||
).copy(profileGainTableMap = profileGainTableMap ?: actualMetadata?.profileGainTableMap)
|
||||
profileGainTableMap?.let {
|
||||
|
||||
@@ -6,13 +6,19 @@ object RawWhiteLevelCorrection {
|
||||
const val MODE_RAW12 = "RAW12"
|
||||
const val MODE_RAW14 = "RAW14"
|
||||
const val MODE_RAW_SENSOR = "RAW_SENSOR_65535"
|
||||
const val MODE_CUSTOM = "Custom"
|
||||
|
||||
fun resolveWhiteLevel(defaultWhiteLevel: Float, mode: String?): Float {
|
||||
fun resolveWhiteLevel(
|
||||
defaultWhiteLevel: Float,
|
||||
mode: String?,
|
||||
customWhiteLevel: Float? = null
|
||||
): Float {
|
||||
return when (mode) {
|
||||
MODE_RAW10 -> 1023f
|
||||
MODE_RAW12 -> 4095f
|
||||
MODE_RAW14 -> 16383f
|
||||
MODE_RAW_SENSOR -> 65535f
|
||||
MODE_CUSTOM -> customWhiteLevel?.takeIf { it > 0f } ?: defaultWhiteLevel
|
||||
else -> defaultWhiteLevel
|
||||
}
|
||||
}
|
||||
@@ -22,7 +28,8 @@ object RawWhiteLevelCorrection {
|
||||
MODE_RAW10,
|
||||
MODE_RAW12,
|
||||
MODE_RAW14,
|
||||
MODE_RAW_SENSOR -> true
|
||||
MODE_RAW_SENSOR,
|
||||
MODE_CUSTOM -> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,14 +73,10 @@ fun CameraParameterBar(
|
||||
)
|
||||
ParameterItem(
|
||||
label = "AWB",
|
||||
value = when (state.awbMode) {
|
||||
CameraMetadata.CONTROL_AWB_MODE_OFF -> "${state.awbTemperature}K"
|
||||
CameraMetadata.CONTROL_AWB_MODE_AUTO -> "AUTO"
|
||||
else -> "UNK"
|
||||
},
|
||||
value = formatWhiteBalanceValue(state),
|
||||
labelColor = yellow,
|
||||
isSelected = selectedParameter == CameraParameter.WHITE_BALANCE,
|
||||
isEnabled = true,
|
||||
isEnabled = state.canAdjustWhiteBalance || state.actualAwbTemperature != null,
|
||||
onClick = { onParameterClick(CameraParameter.WHITE_BALANCE) }
|
||||
)
|
||||
}
|
||||
@@ -135,3 +131,11 @@ internal fun formatFocusDistance(value: Float): String {
|
||||
else String.format("%dcm", (meters * 100).toInt())
|
||||
}
|
||||
}
|
||||
|
||||
internal fun formatWhiteBalanceValue(state: CameraState): String {
|
||||
return when (state.awbMode) {
|
||||
CameraMetadata.CONTROL_AWB_MODE_OFF -> "${state.awbTemperature}K"
|
||||
CameraMetadata.CONTROL_AWB_MODE_AUTO -> state.actualAwbTemperature?.let { "${it}K" } ?: "AUTO"
|
||||
else -> state.actualAwbTemperature?.let { "${it}K" } ?: "UNK"
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.hinnka.mycamera.ui.camera
|
||||
|
||||
import android.hardware.camera2.CameraMetadata
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
@@ -75,14 +74,10 @@ fun CameraParameterBarVerticel(
|
||||
)
|
||||
ParameterItem(
|
||||
label = "AWB",
|
||||
value = when (state.awbMode) {
|
||||
CameraMetadata.CONTROL_AWB_MODE_OFF -> "${state.awbTemperature}K"
|
||||
CameraMetadata.CONTROL_AWB_MODE_AUTO -> "AUTO"
|
||||
else -> "UNK"
|
||||
},
|
||||
value = formatWhiteBalanceValue(state),
|
||||
labelColor = yellow,
|
||||
isSelected = selectedParameter == CameraParameter.WHITE_BALANCE,
|
||||
isEnabled = true,
|
||||
isEnabled = state.canAdjustWhiteBalance || state.actualAwbTemperature != null,
|
||||
onClick = { onParameterClick(CameraParameter.WHITE_BALANCE) }
|
||||
)
|
||||
}
|
||||
|
||||
@@ -814,6 +814,13 @@ fun CameraScreen(
|
||||
}
|
||||
|
||||
val parameterRuler = @Composable {
|
||||
val whiteBalanceCurrentValue = if (
|
||||
state.awbMode == android.hardware.camera2.CameraMetadata.CONTROL_AWB_MODE_AUTO
|
||||
) {
|
||||
state.actualAwbTemperature?.toFloat() ?: state.awbTemperature.toFloat()
|
||||
} else {
|
||||
state.awbTemperature.toFloat()
|
||||
}
|
||||
ParameterRuler(
|
||||
parameter = selectedParameter,
|
||||
currentValue = when (selectedParameter) {
|
||||
@@ -821,33 +828,39 @@ fun CameraScreen(
|
||||
CameraParameter.SHUTTER_SPEED -> state.shutterSpeed.toFloat()
|
||||
CameraParameter.ISO -> state.iso.toFloat()
|
||||
CameraParameter.FOCUS -> state.focusDistance
|
||||
CameraParameter.WHITE_BALANCE -> state.awbTemperature.toFloat()
|
||||
CameraParameter.WHITE_BALANCE -> whiteBalanceCurrentValue
|
||||
},
|
||||
minValue = when (selectedParameter) {
|
||||
CameraParameter.EXPOSURE_COMPENSATION -> state.getExposureCompensationRange().lower * state.getExposureCompensationStep()
|
||||
CameraParameter.SHUTTER_SPEED -> state.getShutterSpeedRange().lower.toFloat()
|
||||
CameraParameter.ISO -> state.getIsoRange().lower.toFloat()
|
||||
CameraParameter.FOCUS -> 0f
|
||||
CameraParameter.WHITE_BALANCE -> 2000f
|
||||
CameraParameter.WHITE_BALANCE -> state.awbTemperatureMin.toFloat()
|
||||
},
|
||||
maxValue = when (selectedParameter) {
|
||||
CameraParameter.EXPOSURE_COMPENSATION -> state.getExposureCompensationRange().upper * state.getExposureCompensationStep()
|
||||
CameraParameter.SHUTTER_SPEED -> maxOf(state.getShutterSpeedRange().upper, 1_000_000_000L * 15).toFloat()
|
||||
CameraParameter.ISO -> maxOf(state.getIsoRange().upper, 3200).toFloat()
|
||||
CameraParameter.FOCUS -> state.minimumFocusDistance
|
||||
CameraParameter.WHITE_BALANCE -> 10000f
|
||||
CameraParameter.WHITE_BALANCE -> state.awbTemperatureMax.toFloat()
|
||||
},
|
||||
isAdjustable = when (selectedParameter) {
|
||||
CameraParameter.EXPOSURE_COMPENSATION -> state.isAutoExposure
|
||||
CameraParameter.SHUTTER_SPEED -> !state.isShutterSpeedAuto
|
||||
CameraParameter.ISO -> !state.isIsoAuto
|
||||
CameraParameter.FOCUS -> !state.isAutoFocus
|
||||
CameraParameter.WHITE_BALANCE -> state.awbMode != android.hardware.camera2.CameraMetadata.CONTROL_AWB_MODE_AUTO
|
||||
CameraParameter.WHITE_BALANCE ->
|
||||
state.canAdjustWhiteBalance &&
|
||||
state.awbMode != android.hardware.camera2.CameraMetadata.CONTROL_AWB_MODE_AUTO
|
||||
},
|
||||
showAutoButton = when (selectedParameter) {
|
||||
CameraParameter.SHUTTER_SPEED, CameraParameter.ISO, CameraParameter.WHITE_BALANCE, CameraParameter.FOCUS -> true
|
||||
else -> false
|
||||
},
|
||||
isAutoModeToggleEnabled = when (selectedParameter) {
|
||||
CameraParameter.WHITE_BALANCE -> state.canAdjustWhiteBalance
|
||||
else -> true
|
||||
},
|
||||
resetValue = selectedParameter.defaultResetValue(),
|
||||
showHyperfocalButton = selectedParameter == CameraParameter.FOCUS && state.minimumFocusDistance > 0f,
|
||||
hyperfocalEnabled = state.isHyperfocalFocusEnabled,
|
||||
@@ -869,10 +882,12 @@ fun CameraScreen(
|
||||
CameraParameter.SHUTTER_SPEED -> viewModel.setShutterSpeedAuto(!state.isShutterSpeedAuto)
|
||||
CameraParameter.ISO -> viewModel.setIsoAuto(!state.isIsoAuto)
|
||||
CameraParameter.WHITE_BALANCE -> {
|
||||
if (state.awbMode == android.hardware.camera2.CameraMetadata.CONTROL_AWB_MODE_AUTO) {
|
||||
viewModel.setAwbMode(android.hardware.camera2.CameraMetadata.CONTROL_AWB_MODE_OFF)
|
||||
} else {
|
||||
viewModel.setAwbMode(android.hardware.camera2.CameraMetadata.CONTROL_AWB_MODE_AUTO)
|
||||
if (state.canAdjustWhiteBalance) {
|
||||
if (state.awbMode == android.hardware.camera2.CameraMetadata.CONTROL_AWB_MODE_AUTO) {
|
||||
viewModel.setAwbMode(android.hardware.camera2.CameraMetadata.CONTROL_AWB_MODE_OFF)
|
||||
} else {
|
||||
viewModel.setAwbMode(android.hardware.camera2.CameraMetadata.CONTROL_AWB_MODE_AUTO)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ fun ParameterRuler(
|
||||
maxValue: Float,
|
||||
isAdjustable: Boolean,
|
||||
showAutoButton: Boolean,
|
||||
isAutoModeToggleEnabled: Boolean = true,
|
||||
resetValue: Float? = null,
|
||||
showHyperfocalButton: Boolean = false,
|
||||
hyperfocalEnabled: Boolean = false,
|
||||
@@ -91,12 +92,15 @@ fun ParameterRuler(
|
||||
if (showAutoButton) {
|
||||
Button(
|
||||
onClick = onAutoModeToggle,
|
||||
enabled = isAutoModeToggleEnabled,
|
||||
modifier = Modifier
|
||||
.padding(start = 8.dp)
|
||||
.size(25.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = if (!isAdjustable) yellow else Color.Gray.copy(alpha = 0.5f),
|
||||
contentColor = if (!isAdjustable) Color.Black else Color.White
|
||||
contentColor = if (!isAdjustable) Color.Black else Color.White,
|
||||
disabledContainerColor = Color.Gray.copy(alpha = 0.25f),
|
||||
disabledContentColor = Color.White.copy(alpha = 0.35f)
|
||||
),
|
||||
shape = CircleShape,
|
||||
contentPadding = PaddingValues(0.dp)
|
||||
@@ -137,8 +141,8 @@ fun ParameterRuler(
|
||||
onTap = {
|
||||
if (isAdjustableState) {
|
||||
val width = size.width
|
||||
val stepWidth = width / scaleValues.size
|
||||
val index = (it.x / stepWidth).toInt().coerceIn(0, scaleValues.lastIndex)
|
||||
val stepWidth = width / (scaleValues.size - 1).coerceAtLeast(1)
|
||||
val index = (it.x / stepWidth).roundToInt().coerceIn(0, scaleValues.lastIndex)
|
||||
selectedValue = scaleValues[index]
|
||||
if (selectedValue != currentValueState) {
|
||||
onValueChange(selectedValue)
|
||||
@@ -152,8 +156,9 @@ fun ParameterRuler(
|
||||
if (isAdjustableState) {
|
||||
change.consume()
|
||||
val width = size.width
|
||||
val stepWidth = width / scaleValues.size
|
||||
val index = (change.position.x / stepWidth).toInt().coerceIn(0, scaleValues.lastIndex)
|
||||
val stepWidth = width / (scaleValues.size - 1).coerceAtLeast(1)
|
||||
val index =
|
||||
(change.position.x / stepWidth).roundToInt().coerceIn(0, scaleValues.lastIndex)
|
||||
selectedValue = scaleValues[index]
|
||||
if (selectedValue != currentValueState) {
|
||||
onValueChange(selectedValue)
|
||||
@@ -256,17 +261,12 @@ private fun RulerScale(
|
||||
|
||||
// Find current value position
|
||||
val currentPosition = findValuePosition(currentValue, scaleValues, stepWidth)
|
||||
val currentIndex = findClosestIndex(currentValue, scaleValues, parameter)
|
||||
|
||||
// Draw each scale value
|
||||
scaleValues.forEachIndexed { index, value ->
|
||||
val x = index * stepWidth
|
||||
|
||||
val isCurrent = if (parameter == CameraParameter.SHUTTER_SPEED) {
|
||||
abs(value - currentValue) < 1000
|
||||
} else {
|
||||
abs(value - currentValue) < 1e-3f
|
||||
}
|
||||
val isCurrent = isSameParameterValue(value, currentValue, parameter)
|
||||
|
||||
// Determine if we should show label
|
||||
val shouldShowLabel = isCurrent || index == 0 || index == scaleValues.lastIndex || value == 0f
|
||||
@@ -333,8 +333,21 @@ private fun isValueOnScale(
|
||||
scaleValues: List<Float>,
|
||||
parameter: CameraParameter
|
||||
): Boolean {
|
||||
val tolerance = if (parameter == CameraParameter.SHUTTER_SPEED) 1000f else 1e-3f
|
||||
return scaleValues.any { abs(it - currentValue) < tolerance }
|
||||
return scaleValues.any { isSameParameterValue(it, currentValue, parameter) }
|
||||
}
|
||||
|
||||
private fun isSameParameterValue(
|
||||
value: Float,
|
||||
currentValue: Float,
|
||||
parameter: CameraParameter
|
||||
): Boolean {
|
||||
val tolerance = when (parameter) {
|
||||
CameraParameter.SHUTTER_SPEED -> 1000f
|
||||
CameraParameter.ISO -> 1f
|
||||
CameraParameter.WHITE_BALANCE -> 25f
|
||||
else -> 1e-3f
|
||||
}
|
||||
return abs(value - currentValue) < tolerance
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -372,21 +385,6 @@ private fun findValuePosition(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find closest scale index to current value
|
||||
*/
|
||||
private fun findClosestIndex(
|
||||
currentValue: Float,
|
||||
scaleValues: List<Float>,
|
||||
parameter: CameraParameter
|
||||
): Int {
|
||||
if (scaleValues.isEmpty()) return 0
|
||||
|
||||
return scaleValues.indices.minByOrNull { index ->
|
||||
abs(scaleValues[index] - currentValue)
|
||||
} ?: 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a triangle indicator at the current value position
|
||||
*/
|
||||
@@ -518,7 +516,7 @@ private fun getScaleValues(parameter: CameraParameter, minValue: Float, maxValue
|
||||
|
||||
CameraParameter.WHITE_BALANCE -> {
|
||||
// Color temperature presets
|
||||
generateSequence(minValue) { it + 500f }
|
||||
generateSequence(minValue) { it + 100f }
|
||||
.takeWhile { it <= maxValue }
|
||||
.filter { it in minValue..maxValue }
|
||||
.toList()
|
||||
|
||||
@@ -86,18 +86,6 @@ fun ZoomControlBar(
|
||||
val customFocalLengths by viewModel.customFocalLengths.collectAsState(initial = emptyList())
|
||||
val hiddenFocalLengths by viewModel.hiddenFocalLengths.collectAsState(initial = emptyList())
|
||||
val lensZoomStops = viewModel.calculateLensZoomStops(availableCameras, currentCamera)
|
||||
val customLensZoomStops = remember(availableCameras, currentCamera) {
|
||||
availableCameras
|
||||
.filter { camera ->
|
||||
camera.isCustomLensId &&
|
||||
if (currentCamera?.lensType == LensType.FRONT) {
|
||||
camera.lensType == LensType.FRONT
|
||||
} else {
|
||||
camera.lensType != LensType.FRONT && camera.lensType != LensType.BACK_MACRO
|
||||
}
|
||||
}
|
||||
.map { it.displayIntrinsicZoomRatio }
|
||||
}
|
||||
val zoomStops = viewModel.allZoomStops(lensZoomStops, mainCamera, currentCamera, customFocalLengths, hiddenFocalLengths)
|
||||
|
||||
val macroCameras = remember(availableCameras) {
|
||||
@@ -300,11 +288,16 @@ fun ZoomControlBar(
|
||||
replacedStopIndex = replacedStopIndex
|
||||
)
|
||||
}
|
||||
val stopItems = remember(effectiveStops, availableCameras, currentCamera) {
|
||||
buildZoomStopItems(
|
||||
stops = effectiveStops,
|
||||
availableCameras = availableCameras,
|
||||
currentCamera = currentCamera
|
||||
)
|
||||
}
|
||||
ZoomRuler(
|
||||
zoomRatio = internalZoomRatio,
|
||||
lensStops = lensZoomStops,
|
||||
customLensStops = customLensZoomStops,
|
||||
stops = effectiveStops,
|
||||
stopItems = stopItems,
|
||||
macroCameras = macroCameras,
|
||||
currentCameraId = currentCameraIdState,
|
||||
mainCamera = mainCamera,
|
||||
@@ -341,11 +334,9 @@ private fun buildEffectiveZoomStops(
|
||||
|
||||
|
||||
@Composable
|
||||
fun ZoomRuler(
|
||||
private fun ZoomRuler(
|
||||
zoomRatio: Float,
|
||||
lensStops: List<Float>,
|
||||
customLensStops: List<Float>,
|
||||
stops: List<Float>,
|
||||
stopItems: List<ZoomStopItem>,
|
||||
macroCameras: List<CameraInfo>,
|
||||
currentCameraId: String,
|
||||
mainCamera: CameraInfo?,
|
||||
@@ -357,7 +348,7 @@ fun ZoomRuler(
|
||||
val activeColor = Color(0xFFFFD700)
|
||||
val inactiveColor = Color.White.copy(alpha = 0.5f)
|
||||
|
||||
val stopsState by rememberUpdatedState(stops)
|
||||
val stopsState by rememberUpdatedState(stopItems)
|
||||
|
||||
BoxWithConstraints(
|
||||
modifier = modifier,
|
||||
@@ -380,12 +371,17 @@ fun ZoomRuler(
|
||||
) {
|
||||
val isCurrentMacro = macroCameras.any { it.cameraId == currentCameraId }
|
||||
val selectedStopIndex = if (isCurrentMacro) -1 else stopsState.indices.minByOrNull {
|
||||
abs(stopsState[it] - zoomRatio)
|
||||
val item = stopsState[it]
|
||||
if (item.containsCamera(currentCameraId) && abs(item.zoomRatio - zoomRatio) <= 0.01f) {
|
||||
-1f
|
||||
} else {
|
||||
abs(item.zoomRatio - zoomRatio)
|
||||
}
|
||||
}
|
||||
|
||||
stopsState.forEachIndexed { index, stop ->
|
||||
stopsState.forEachIndexed { index, item ->
|
||||
val stop = item.zoomRatio
|
||||
val isSelected = index == selectedStopIndex && abs(stop - zoomRatio) <= 0.01f
|
||||
val isCustomLensStop = customLensStops.any { abs(it - stop) <= 0.01f }
|
||||
|
||||
// 显示文本
|
||||
val text = when (displayMode) {
|
||||
@@ -396,22 +392,29 @@ fun ZoomRuler(
|
||||
ZoomDisplayMode.FOCAL_LENGTH -> {
|
||||
zoomRatioToFocalLength(stop, mainCamera)
|
||||
}
|
||||
} + if (isCustomLensStop) "*" else ""
|
||||
} + if (item.isCustomLensStop) "*" else ""
|
||||
|
||||
val style = TextStyle(
|
||||
fontSize = if (isSelected) adaptiveMetrics.selectedFontSize else adaptiveMetrics.normalFontSize,
|
||||
fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Normal,
|
||||
color = if (isSelected) activeColor else inactiveColor,
|
||||
textAlign = TextAlign.Center,
|
||||
textDecoration = if (lensStops.contains(stop)) TextDecoration.Underline else TextDecoration.None
|
||||
textDecoration = if (item.isLensStop) TextDecoration.Underline else TextDecoration.None
|
||||
)
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(adaptiveMetrics.itemSize)
|
||||
.autoRotate()
|
||||
.pointerInput(stop) {
|
||||
detectTapGestures { onZoomChange(stop) }
|
||||
.pointerInput(item.cameraIds, stop, currentCameraId) {
|
||||
detectTapGestures {
|
||||
val cameraId = item.targetCameraId(currentCameraId)
|
||||
if (cameraId != null && cameraId != currentCameraId) {
|
||||
onLensSwitch(cameraId)
|
||||
} else {
|
||||
onZoomChange(stop)
|
||||
}
|
||||
}
|
||||
},
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
@@ -422,6 +425,22 @@ fun ZoomRuler(
|
||||
softWrap = false,
|
||||
overflow = TextOverflow.Clip
|
||||
)
|
||||
if (item.hasVariantBadge) {
|
||||
val badgeText = item.selectedVariantIndex(currentCameraId)
|
||||
?.takeIf { isSelected }
|
||||
?.toString()
|
||||
?: item.variantCount.toString()
|
||||
ZoomStopVariantBadge(
|
||||
text = badgeText,
|
||||
isSelected = isSelected,
|
||||
activeColor = activeColor,
|
||||
inactiveColor = inactiveColor,
|
||||
itemSize = adaptiveMetrics.itemSize,
|
||||
modifier = Modifier
|
||||
.align(Alignment.TopEnd)
|
||||
.padding(top = 1.dp, end = 1.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -67,18 +67,6 @@ fun ZoomControlBarVerticel(
|
||||
val customFocalLengths by viewModel.customFocalLengths.collectAsState(initial = emptyList())
|
||||
val hiddenFocalLengths by viewModel.hiddenFocalLengths.collectAsState(initial = emptyList())
|
||||
val lensZoomStops = viewModel.calculateLensZoomStops(availableCameras, currentCamera)
|
||||
val customLensZoomStops = remember(availableCameras, currentCamera) {
|
||||
availableCameras
|
||||
.filter { camera ->
|
||||
camera.isCustomLensId &&
|
||||
if (currentCamera?.lensType == LensType.FRONT) {
|
||||
camera.lensType == LensType.FRONT
|
||||
} else {
|
||||
camera.lensType != LensType.FRONT && camera.lensType != LensType.BACK_MACRO
|
||||
}
|
||||
}
|
||||
.map { it.displayIntrinsicZoomRatio }
|
||||
}
|
||||
val zoomStops = viewModel.allZoomStops(lensZoomStops, mainCamera, currentCamera, customFocalLengths, hiddenFocalLengths)
|
||||
|
||||
val macroCameras = remember(availableCameras) {
|
||||
@@ -278,11 +266,16 @@ fun ZoomControlBarVerticel(
|
||||
replacedStopIndex = replacedStopIndex
|
||||
)
|
||||
}
|
||||
val stopItems = remember(effectiveStops, availableCameras, currentCamera) {
|
||||
buildZoomStopItems(
|
||||
stops = effectiveStops,
|
||||
availableCameras = availableCameras,
|
||||
currentCamera = currentCamera
|
||||
)
|
||||
}
|
||||
ZoomRulerVertical(
|
||||
zoomRatio = internalZoomRatio,
|
||||
lensStops = lensZoomStops,
|
||||
customLensStops = customLensZoomStops,
|
||||
stops = effectiveStops,
|
||||
stopItems = stopItems,
|
||||
macroCameras = macroCameras,
|
||||
currentCameraId = currentCameraIdState,
|
||||
mainCamera = mainCamera,
|
||||
@@ -319,11 +312,9 @@ private fun buildEffectiveZoomStops(
|
||||
|
||||
|
||||
@Composable
|
||||
fun ZoomRulerVertical(
|
||||
private fun ZoomRulerVertical(
|
||||
zoomRatio: Float,
|
||||
lensStops: List<Float>,
|
||||
customLensStops: List<Float>,
|
||||
stops: List<Float>,
|
||||
stopItems: List<ZoomStopItem>,
|
||||
macroCameras: List<CameraInfo>,
|
||||
currentCameraId: String,
|
||||
mainCamera: CameraInfo?,
|
||||
@@ -335,7 +326,7 @@ fun ZoomRulerVertical(
|
||||
val activeColor = Color(0xFFFFD700)
|
||||
val inactiveColor = Color.White.copy(alpha = 0.5f)
|
||||
|
||||
val stopsState by rememberUpdatedState(stops)
|
||||
val stopsState by rememberUpdatedState(stopItems)
|
||||
|
||||
BoxWithConstraints(
|
||||
modifier = modifier,
|
||||
@@ -358,12 +349,17 @@ fun ZoomRulerVertical(
|
||||
) {
|
||||
val isCurrentMacro = macroCameras.any { it.cameraId == currentCameraId }
|
||||
val selectedStopIndex = if (isCurrentMacro) -1 else stopsState.indices.minByOrNull {
|
||||
abs(stopsState[it] - zoomRatio)
|
||||
val item = stopsState[it]
|
||||
if (item.containsCamera(currentCameraId) && abs(item.zoomRatio - zoomRatio) <= 0.01f) {
|
||||
-1f
|
||||
} else {
|
||||
abs(item.zoomRatio - zoomRatio)
|
||||
}
|
||||
}
|
||||
|
||||
stopsState.forEachIndexed { index, stop ->
|
||||
stopsState.forEachIndexed { index, item ->
|
||||
val stop = item.zoomRatio
|
||||
val isSelected = index == selectedStopIndex && abs(stop - zoomRatio) <= 0.01f
|
||||
val isCustomLensStop = customLensStops.any { abs(it - stop) <= 0.01f }
|
||||
|
||||
// 显示文本
|
||||
val text = when (displayMode) {
|
||||
@@ -374,22 +370,29 @@ fun ZoomRulerVertical(
|
||||
ZoomDisplayMode.FOCAL_LENGTH -> {
|
||||
zoomRatioToFocalLengthV(stop, mainCamera)
|
||||
}
|
||||
} + if (isCustomLensStop) "*" else ""
|
||||
} + if (item.isCustomLensStop) "*" else ""
|
||||
|
||||
val style = TextStyle(
|
||||
fontSize = if (isSelected) adaptiveMetrics.selectedFontSize else adaptiveMetrics.normalFontSize,
|
||||
fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Normal,
|
||||
color = if (isSelected) activeColor else inactiveColor,
|
||||
textAlign = TextAlign.Center,
|
||||
textDecoration = if (lensStops.contains(stop)) TextDecoration.Underline else TextDecoration.None
|
||||
textDecoration = if (item.isLensStop) TextDecoration.Underline else TextDecoration.None
|
||||
)
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(adaptiveMetrics.itemSize)
|
||||
.autoRotate()
|
||||
.pointerInput(stop) {
|
||||
detectTapGestures { onZoomChange(stop) }
|
||||
.pointerInput(item.cameraIds, stop, currentCameraId) {
|
||||
detectTapGestures {
|
||||
val cameraId = item.targetCameraId(currentCameraId)
|
||||
if (cameraId != null && cameraId != currentCameraId) {
|
||||
onLensSwitch(cameraId)
|
||||
} else {
|
||||
onZoomChange(stop)
|
||||
}
|
||||
}
|
||||
},
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
@@ -400,6 +403,22 @@ fun ZoomRulerVertical(
|
||||
softWrap = false,
|
||||
overflow = TextOverflow.Clip
|
||||
)
|
||||
if (item.hasVariantBadge) {
|
||||
val badgeText = item.selectedVariantIndex(currentCameraId)
|
||||
?.takeIf { isSelected }
|
||||
?.toString()
|
||||
?: item.variantCount.toString()
|
||||
ZoomStopVariantBadge(
|
||||
text = badgeText,
|
||||
isSelected = isSelected,
|
||||
activeColor = activeColor,
|
||||
inactiveColor = inactiveColor,
|
||||
itemSize = adaptiveMetrics.itemSize,
|
||||
modifier = Modifier
|
||||
.align(Alignment.TopEnd)
|
||||
.padding(top = 1.dp, end = 1.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,13 @@ private fun buildZoomRulerAdaptiveMetrics(
|
||||
separatorCount: Int,
|
||||
gapCount: Int
|
||||
): ZoomRulerAdaptiveMetrics {
|
||||
val scale = (itemSize / DefaultItemSize).coerceIn(0.3f, 1f)
|
||||
val itemScale = (itemSize / DefaultItemSize).coerceIn(0.3f, 1f)
|
||||
val pitchScale = if (gapCount == 0) {
|
||||
itemScale
|
||||
} else {
|
||||
((itemSize + spacing) / (DefaultItemSize + DefaultSpacing)).coerceIn(0.3f, 1f)
|
||||
}
|
||||
val scale = minOf(itemScale, pitchScale)
|
||||
return ZoomRulerAdaptiveMetrics(
|
||||
itemSize = itemSize.dp,
|
||||
spacing = spacing.dp,
|
||||
@@ -113,8 +119,8 @@ private fun buildZoomRulerAdaptiveMetrics(
|
||||
separatorCount = separatorCount,
|
||||
gapCount = gapCount
|
||||
).dp,
|
||||
selectedFontSize = (13f * scale).coerceIn(5f, 13f).sp,
|
||||
normalFontSize = (10f * scale).coerceIn(5f, 10f).sp,
|
||||
selectedFontSize = (13f * scale).coerceIn(8f, 13f).sp,
|
||||
normalFontSize = (10f * scale).coerceIn(7f, 10f).sp,
|
||||
selectedIconSize = (16f * scale).coerceIn(6f, 16f).dp,
|
||||
normalIconSize = (14f * scale).coerceIn(6f, 14f).dp,
|
||||
separatorLength = (12f * scale).coerceIn(4f, 12f).dp
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
package com.hinnka.mycamera.ui.camera
|
||||
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.hinnka.mycamera.camera.CameraInfo
|
||||
import com.hinnka.mycamera.camera.LensType
|
||||
import kotlin.math.abs
|
||||
|
||||
internal data class ZoomStopItem(
|
||||
val zoomRatio: Float,
|
||||
val cameraIds: List<String> = emptyList(),
|
||||
val isLensStop: Boolean = false,
|
||||
val isCustomLensStop: Boolean = false
|
||||
) {
|
||||
val hasVariantBadge: Boolean
|
||||
get() = cameraIds.size > 1
|
||||
|
||||
val variantCount: Int
|
||||
get() = cameraIds.size
|
||||
|
||||
fun containsCamera(cameraId: String): Boolean {
|
||||
return cameraIds.contains(cameraId)
|
||||
}
|
||||
|
||||
fun selectedVariantIndex(cameraId: String): Int? {
|
||||
val index = cameraIds.indexOf(cameraId)
|
||||
return if (index >= 0) index + 1 else null
|
||||
}
|
||||
|
||||
fun targetCameraId(currentCameraId: String): String? {
|
||||
if (cameraIds.isEmpty()) return null
|
||||
val currentIndex = cameraIds.indexOf(currentCameraId)
|
||||
return if (currentIndex >= 0 && cameraIds.size > 1) {
|
||||
cameraIds[(currentIndex + 1) % cameraIds.size]
|
||||
} else {
|
||||
cameraIds.first()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal fun buildZoomStopItems(
|
||||
stops: List<Float>,
|
||||
availableCameras: List<CameraInfo>,
|
||||
currentCamera: CameraInfo?
|
||||
): List<ZoomStopItem> {
|
||||
val zoomableLensCameras = availableCameras
|
||||
.filter { camera ->
|
||||
val isMatchingFacing = if (currentCamera?.lensType == LensType.FRONT) {
|
||||
camera.lensType == LensType.FRONT
|
||||
} else {
|
||||
camera.lensType != LensType.FRONT && camera.lensType != LensType.BACK_MACRO
|
||||
}
|
||||
camera.displayIntrinsicZoomRatio > 0f && isMatchingFacing
|
||||
}
|
||||
.sortedWith(
|
||||
compareBy<CameraInfo>(
|
||||
{ it.displayIntrinsicZoomRatio },
|
||||
{ it.cameraId }
|
||||
)
|
||||
)
|
||||
|
||||
return stops.map { stop ->
|
||||
val matchingLensCameras = zoomableLensCameras.filter {
|
||||
abs(it.displayIntrinsicZoomRatio - stop) <= 0.01f
|
||||
}
|
||||
if (matchingLensCameras.isEmpty()) {
|
||||
ZoomStopItem(zoomRatio = stop)
|
||||
} else {
|
||||
ZoomStopItem(
|
||||
zoomRatio = stop,
|
||||
cameraIds = matchingLensCameras.map { it.cameraId },
|
||||
isLensStop = true,
|
||||
isCustomLensStop = matchingLensCameras.any { it.isCustomLensId }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun ZoomStopVariantBadge(
|
||||
text: String,
|
||||
isSelected: Boolean,
|
||||
activeColor: Color,
|
||||
inactiveColor: Color,
|
||||
itemSize: Dp,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val fontSize = (itemSize.value * 0.26f).coerceIn(7f, 9f).sp
|
||||
Text(
|
||||
text = text,
|
||||
modifier = modifier,
|
||||
color = if (isSelected) activeColor else inactiveColor,
|
||||
fontSize = fontSize,
|
||||
fontWeight = FontWeight.Bold,
|
||||
textAlign = TextAlign.Center,
|
||||
maxLines = 1,
|
||||
softWrap = false,
|
||||
overflow = TextOverflow.Clip
|
||||
)
|
||||
}
|
||||
@@ -90,6 +90,7 @@ fun RawEditPanel(
|
||||
rawBlackLevelMode: String = RawCfaCorrection.MODE_DEFAULT,
|
||||
rawCustomBlackLevel: Float = 0f,
|
||||
rawWhiteLevelMode: String = RawWhiteLevelCorrection.MODE_DEFAULT,
|
||||
rawCustomWhiteLevel: Float = 0f,
|
||||
rawCfaCorrectionMode: String = RawCfaCorrection.MODE_DEFAULT,
|
||||
rawRenderingEngine: RawRenderingEngine,
|
||||
rawToneMappingParameters: RawToneMappingParameters = RawToneMappingParameters.DEFAULT,
|
||||
@@ -108,6 +109,7 @@ fun RawEditPanel(
|
||||
onRawBlackLevelModeChange: (String) -> Unit = {},
|
||||
onRawCustomBlackLevelChange: (Float) -> Unit = {},
|
||||
onRawWhiteLevelModeChange: (String) -> Unit = {},
|
||||
onRawCustomWhiteLevelChange: (Float) -> Unit = {},
|
||||
onRawCfaCorrectionModeChange: (String) -> Unit = {},
|
||||
onRawColorEngineChange: (RawRenderingEngine) -> Unit,
|
||||
onRawToneMappingParametersChange: (RawToneMappingParameters) -> Unit = {},
|
||||
@@ -279,11 +281,19 @@ fun RawEditPanel(
|
||||
RawWhiteLevelCorrection.MODE_RAW10 to stringResource(R.string.settings_white_level_raw10),
|
||||
RawWhiteLevelCorrection.MODE_RAW12 to stringResource(R.string.settings_white_level_raw12),
|
||||
RawWhiteLevelCorrection.MODE_RAW14 to stringResource(R.string.settings_white_level_raw14),
|
||||
RawWhiteLevelCorrection.MODE_RAW_SENSOR to stringResource(R.string.settings_white_level_raw_sensor)
|
||||
RawWhiteLevelCorrection.MODE_RAW_SENSOR to stringResource(R.string.settings_white_level_raw_sensor),
|
||||
RawWhiteLevelCorrection.MODE_CUSTOM to stringResource(R.string.settings_white_level_custom)
|
||||
),
|
||||
currentLevel = rawWhiteLevelMode,
|
||||
onLevelSelected = onRawWhiteLevelModeChange
|
||||
)
|
||||
if (rawWhiteLevelMode == RawWhiteLevelCorrection.MODE_CUSTOM) {
|
||||
RawNumberInputSetting(
|
||||
title = stringResource(R.string.settings_white_level_custom),
|
||||
value = rawCustomWhiteLevel,
|
||||
onValueChange = onRawCustomWhiteLevelChange
|
||||
)
|
||||
}
|
||||
RawChoiceSetting(
|
||||
title = stringResource(R.string.settings_raw_cfa_correction),
|
||||
description = stringResource(R.string.settings_raw_cfa_correction_description),
|
||||
|
||||
@@ -115,6 +115,7 @@ private data class PreviewRenderSignature(
|
||||
val editRawBlackLevelMode: String,
|
||||
val editRawCustomBlackLevel: Float,
|
||||
val editRawWhiteLevelMode: String,
|
||||
val editRawCustomWhiteLevel: Float,
|
||||
val editRawCfaCorrectionMode: String,
|
||||
val editRawDcpId: String?,
|
||||
val editRawRenderingEngine: String,
|
||||
@@ -198,6 +199,7 @@ fun GalleryEditScreen(
|
||||
val editRawBlackLevelMode by viewModel.editRawBlackLevelMode.collectAsState()
|
||||
val editRawCustomBlackLevel by viewModel.editRawCustomBlackLevel.collectAsState()
|
||||
val editRawWhiteLevelMode by viewModel.editRawWhiteLevelMode.collectAsState()
|
||||
val editRawCustomWhiteLevel by viewModel.editRawCustomWhiteLevel.collectAsState()
|
||||
val editRawCfaCorrectionMode by viewModel.editRawCfaCorrectionMode.collectAsState()
|
||||
val editRawDcpId by viewModel.editRawDcpId.collectAsState()
|
||||
val editRawBaselineLutId by viewModel.editRawBaselineLutId.collectAsState()
|
||||
@@ -267,6 +269,7 @@ fun GalleryEditScreen(
|
||||
editRawBlackLevelMode = if (fast) "" else editRawBlackLevelMode,
|
||||
editRawCustomBlackLevel = if (fast) 0f else editRawCustomBlackLevel,
|
||||
editRawWhiteLevelMode = if (fast) "" else editRawWhiteLevelMode,
|
||||
editRawCustomWhiteLevel = if (fast) 0f else editRawCustomWhiteLevel,
|
||||
editRawCfaCorrectionMode = if (fast) "" else editRawCfaCorrectionMode,
|
||||
editRawDcpId = if (fast) null else editRawDcpId,
|
||||
editRawRenderingEngine = if (fast) "" else editRawColorEngine.name,
|
||||
@@ -1123,6 +1126,7 @@ fun GalleryEditScreen(
|
||||
rawBlackLevelMode = editRawBlackLevelMode,
|
||||
rawCustomBlackLevel = editRawCustomBlackLevel,
|
||||
rawWhiteLevelMode = editRawWhiteLevelMode,
|
||||
rawCustomWhiteLevel = editRawCustomWhiteLevel,
|
||||
rawCfaCorrectionMode = editRawCfaCorrectionMode,
|
||||
rawRenderingEngine = editRawColorEngine,
|
||||
rawToneMappingParameters = editRawToneMappingParameters,
|
||||
@@ -1201,6 +1205,11 @@ fun GalleryEditScreen(
|
||||
requestRawPreviewRefresh()
|
||||
}
|
||||
},
|
||||
onRawCustomWhiteLevelChange = {
|
||||
viewModel.saveRawCustomWhiteLevel(currentEditSourcePhoto, it) {
|
||||
requestRawPreviewRefresh()
|
||||
}
|
||||
},
|
||||
onRawCfaCorrectionModeChange = {
|
||||
viewModel.saveRawCfaCorrectionMode(currentEditSourcePhoto, it) {
|
||||
requestRawPreviewRefresh()
|
||||
|
||||
@@ -291,7 +291,7 @@ fun GalleryScreen(
|
||||
)
|
||||
} else {
|
||||
Text(
|
||||
text = stringResource(R.string.gallery_photon),
|
||||
text = stringResource(R.string.gallery),
|
||||
color = Color.White,
|
||||
fontSize = 18.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
|
||||
@@ -267,6 +267,7 @@ fun SettingsScreen(
|
||||
val lensIdBlacklist by viewModel.lensIdBlacklist.collectAsState(initial = emptyList())
|
||||
val iszLensConfigs by viewModel.iszLensConfigs.collectAsState(initial = emptyList())
|
||||
val preferredMainCameraId by viewModel.preferredMainCameraId.collectAsState(initial = null)
|
||||
val preferredMacroCameraId by viewModel.preferredMacroCameraId.collectAsState(initial = null)
|
||||
val enableLogicalMultiCameraDiscovery by viewModel.enableLogicalMultiCameraDiscovery.collectAsState(initial = false)
|
||||
val logicalCameraBindingWhitelist by viewModel.logicalCameraBindingWhitelist.collectAsState(initial = emptyList())
|
||||
val multiFrameCount by viewModel.multiFrameCount.collectAsState()
|
||||
@@ -324,6 +325,7 @@ fun SettingsScreen(
|
||||
val rawBlackLevelMode by viewModel.rawBlackLevelMode.collectAsState()
|
||||
val rawCustomBlackLevel by viewModel.rawCustomBlackLevel.collectAsState()
|
||||
val rawWhiteLevelMode by viewModel.rawWhiteLevelMode.collectAsState()
|
||||
val rawCustomWhiteLevel by viewModel.rawCustomWhiteLevel.collectAsState()
|
||||
val rawCfaCorrectionMode by viewModel.rawCfaCorrectionMode.collectAsState()
|
||||
val rawColorEngine by viewModel.rawRenderingEngine.collectAsState()
|
||||
val rawToneMappingParameters by viewModel.rawToneMappingParameters.collectAsState()
|
||||
@@ -338,6 +340,7 @@ fun SettingsScreen(
|
||||
var isRawSliderAdjusting by remember { mutableStateOf(false) }
|
||||
var isSoftwareProcessingSliderAdjusting by remember { mutableStateOf(false) }
|
||||
var mainCameraIdOptions by remember { mutableStateOf<List<String>>(emptyList()) }
|
||||
var macroCameraIdOptions by remember { mutableStateOf<List<String>>(emptyList()) }
|
||||
var rawExposureCompensationUi by remember { mutableStateOf(rawExposureCompensation) }
|
||||
var rawHighlightsAdjustmentUi by remember { mutableStateOf(rawHighlightsAdjustment) }
|
||||
var rawShadowsAdjustmentUi by remember { mutableStateOf(rawShadowsAdjustment) }
|
||||
@@ -383,6 +386,7 @@ fun SettingsScreen(
|
||||
LaunchedEffect(
|
||||
customLensIds,
|
||||
lensIdBlacklist,
|
||||
preferredMacroCameraId,
|
||||
enableLogicalMultiCameraDiscovery,
|
||||
logicalCameraBindingWhitelist
|
||||
) {
|
||||
@@ -391,6 +395,11 @@ fun SettingsScreen(
|
||||
}.getOrElse {
|
||||
emptyList()
|
||||
}
|
||||
macroCameraIdOptions = runCatching {
|
||||
viewModel.discoverMacroCameraIdOptions()
|
||||
}.getOrElse {
|
||||
emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
fun applyTonemapMode(mode: String) {
|
||||
@@ -1002,6 +1011,39 @@ fun SettingsScreen(
|
||||
)
|
||||
}
|
||||
|
||||
if (macroCameraIdOptions.size > 1) {
|
||||
HorizontalDivider(
|
||||
color = Color.White.copy(alpha = 0.1f),
|
||||
modifier = Modifier.padding(vertical = 8.dp)
|
||||
)
|
||||
|
||||
val macroCameraAutoLabel = stringResource(R.string.settings_macro_camera_id_auto)
|
||||
val selectedMacroCameraId = preferredMacroCameraId
|
||||
?.takeIf { macroCameraIdOptions.contains(it) }
|
||||
val macroCameraIdLabels: List<Pair<String?, String>> =
|
||||
listOf(null to macroCameraAutoLabel) + macroCameraIdOptions.map { cameraId ->
|
||||
cameraId to stringResource(R.string.settings_main_camera_id_option, cameraId)
|
||||
}
|
||||
val selectedMacroCameraLabel = macroCameraIdLabels
|
||||
.firstOrNull { it.first == selectedMacroCameraId }
|
||||
?.second
|
||||
?: macroCameraAutoLabel
|
||||
|
||||
DropdownSettingItem(
|
||||
title = stringResource(R.string.settings_macro_camera_id),
|
||||
description = stringResource(R.string.settings_macro_camera_id_description),
|
||||
value = selectedMacroCameraLabel,
|
||||
options = macroCameraIdLabels.map { it.second },
|
||||
isLoading = false,
|
||||
onExpanded = {},
|
||||
onOptionSelected = { label ->
|
||||
macroCameraIdLabels.firstOrNull { it.second == label }?.let {
|
||||
viewModel.setPreferredMacroCameraId(it.first)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
HorizontalDivider(
|
||||
color = Color.White.copy(alpha = 0.1f),
|
||||
modifier = Modifier.padding(vertical = 8.dp)
|
||||
@@ -1837,11 +1879,24 @@ fun SettingsScreen(
|
||||
RawWhiteLevelCorrection.MODE_RAW10 to stringResource(R.string.settings_white_level_raw10),
|
||||
RawWhiteLevelCorrection.MODE_RAW12 to stringResource(R.string.settings_white_level_raw12),
|
||||
RawWhiteLevelCorrection.MODE_RAW14 to stringResource(R.string.settings_white_level_raw14),
|
||||
RawWhiteLevelCorrection.MODE_RAW_SENSOR to stringResource(R.string.settings_white_level_raw_sensor)
|
||||
RawWhiteLevelCorrection.MODE_RAW_SENSOR to stringResource(R.string.settings_white_level_raw_sensor),
|
||||
RawWhiteLevelCorrection.MODE_CUSTOM to stringResource(R.string.settings_white_level_custom)
|
||||
),
|
||||
currentLevel = rawWhiteLevelMode,
|
||||
onLevelSelected = { viewModel.setRawWhiteLevelMode(it) }
|
||||
)
|
||||
|
||||
if (rawWhiteLevelMode == RawWhiteLevelCorrection.MODE_CUSTOM) {
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
TextInputSettingItem(
|
||||
title = stringResource(R.string.settings_white_level_custom),
|
||||
description = null,
|
||||
value = if (rawCustomWhiteLevel == 0f) "" else rawCustomWhiteLevel.toString(),
|
||||
onValueChange = {
|
||||
it.toFloatOrNull()?.let { value -> viewModel.setRawCustomWhiteLevel(value) }
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
SettingsTab.PHANTOM -> {
|
||||
@@ -3466,7 +3521,11 @@ private fun AddIszLensDialog(
|
||||
val selectedBaseCamera = baseLensCandidates.firstOrNull { it.cameraId == selectedBaseCameraId }
|
||||
val selectedBaseLabel = selectedBaseCamera?.let { iszBaseLensLabel(it) }.orEmpty()
|
||||
val baseLensLabels = baseLensCandidates.map { it.cameraId to iszBaseLensLabel(it) }
|
||||
val virtualLensId = IszLensConfig.createVirtualCameraId(selectedBaseCameraId, selectedIszZoomRatio)
|
||||
val virtualLensId = IszLensConfig.createVirtualCameraId(
|
||||
selectedBaseCameraId,
|
||||
selectedIszZoomRatio,
|
||||
settings.toVirtualLensProfileId()
|
||||
)
|
||||
val virtualLensName = selectedBaseCamera?.let {
|
||||
stringResource(
|
||||
R.string.settings_isz_virtual_lens_name,
|
||||
@@ -3627,6 +3686,8 @@ private fun AddIszLensDialog(
|
||||
val displayRatio = baseCamera?.let {
|
||||
IszLensConfig.displayRatioLabel(it.displayIntrinsicZoomRatio * config.iszZoomRatio)
|
||||
} ?: IszLensConfig.displayRatioLabel(config.iszZoomRatio)
|
||||
val vendorSettings = vendorCaptureSettingsByLens.settingsFor(config.virtualCameraId)
|
||||
val vendorProfileSummary = vendorCaptureSettingsSummary(vendorSettings)
|
||||
val lensKind = stringResource(
|
||||
if (config.isMacro) {
|
||||
R.string.settings_isz_lens_kind_macro
|
||||
@@ -3645,7 +3706,7 @@ private fun AddIszLensDialog(
|
||||
config.virtualCameraId,
|
||||
displayRatio,
|
||||
lensKind,
|
||||
vendorCaptureSettingsByLens.settingsFor(config.virtualCameraId).values.size,
|
||||
vendorProfileSummary,
|
||||
stringResource(
|
||||
R.string.settings_isz_raw_black_border_crop_summary,
|
||||
config.rawBlackBorderCrop.leftPx,
|
||||
@@ -3767,6 +3828,23 @@ private fun iszBaseLensLabel(camera: CameraInfo): String {
|
||||
return stringResource(R.string.settings_isz_lens_label, prefix, camera.cameraId, focalLength)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun vendorCaptureSettingsSummary(settings: VendorCaptureSettings): String {
|
||||
if (!settings.isEnabled) {
|
||||
return stringResource(R.string.settings_isz_vendor_profile_none)
|
||||
}
|
||||
|
||||
val parts = mutableListOf<String>()
|
||||
for ((key, value) in settings.values.entries.sortedBy { it.key.ordinal }) {
|
||||
parts += stringResource(
|
||||
R.string.settings_isz_vendor_profile_entry,
|
||||
key.displayName(),
|
||||
key.normalizeValue(value)
|
||||
)
|
||||
}
|
||||
return parts.joinToString(" / ")
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun VendorCaptureSettingsPanel(
|
||||
currentLensId: String,
|
||||
|
||||
@@ -0,0 +1,280 @@
|
||||
package com.hinnka.mycamera.utils
|
||||
|
||||
import com.hinnka.mycamera.raw.RawWhiteLevelCorrection
|
||||
import java.io.File
|
||||
import java.io.RandomAccessFile
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.ByteOrder
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
object DngWhiteLevelPatcher {
|
||||
private const val TAG = "DngWhiteLevelPatcher"
|
||||
private const val TIFF_TAG_SUB_IFDS = 330
|
||||
private const val TIFF_TAG_WHITE_LEVEL = 50717
|
||||
private const val TYPE_SHORT = 3
|
||||
private const val TYPE_LONG = 4
|
||||
private const val MAX_IFD_VISITS = 64
|
||||
|
||||
private data class IfdScanResult(
|
||||
val whiteLevelEntryOffset: Long,
|
||||
val subIfdOffsets: List<Long>,
|
||||
val nextIfdOffset: Long
|
||||
)
|
||||
|
||||
fun patchFromMode(file: File, mode: String?, customWhiteLevel: Float?): Boolean {
|
||||
val level = resolveWhiteLevel(mode, customWhiteLevel) ?: return false
|
||||
return patchWhiteLevel(file, level)
|
||||
}
|
||||
|
||||
private fun resolveWhiteLevel(mode: String?, customWhiteLevel: Float?): Float? {
|
||||
return when (mode) {
|
||||
RawWhiteLevelCorrection.MODE_RAW10 -> 1023f
|
||||
RawWhiteLevelCorrection.MODE_RAW12 -> 4095f
|
||||
RawWhiteLevelCorrection.MODE_RAW14 -> 16383f
|
||||
RawWhiteLevelCorrection.MODE_RAW_SENSOR -> 65535f
|
||||
RawWhiteLevelCorrection.MODE_CUSTOM -> customWhiteLevel?.takeIf { it > 0f }
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
private fun patchWhiteLevel(file: File, level: Float): Boolean {
|
||||
if (!file.exists() || file.length() < 16L) {
|
||||
return false
|
||||
}
|
||||
|
||||
return runCatching {
|
||||
RandomAccessFile(file, "rw").use { raf ->
|
||||
val header = ByteArray(8)
|
||||
raf.seek(0)
|
||||
raf.readFully(header)
|
||||
|
||||
val byteOrder = when {
|
||||
header[0] == 'I'.code.toByte() && header[1] == 'I'.code.toByte() -> ByteOrder.LITTLE_ENDIAN
|
||||
header[0] == 'M'.code.toByte() && header[1] == 'M'.code.toByte() -> ByteOrder.BIG_ENDIAN
|
||||
else -> return@use false
|
||||
}
|
||||
val magic = readUnsignedShort(header, 2, byteOrder)
|
||||
if (magic != 42) {
|
||||
return@use false
|
||||
}
|
||||
|
||||
val firstIfdOffset = readUnsignedInt(header, 4, byteOrder)
|
||||
if (firstIfdOffset <= 0L || firstIfdOffset + 2L > raf.length()) {
|
||||
return@use false
|
||||
}
|
||||
|
||||
val pendingIfds = mutableListOf(firstIfdOffset)
|
||||
val visitedIfds = mutableSetOf<Long>()
|
||||
var patchedCount = 0
|
||||
|
||||
while (pendingIfds.isNotEmpty() && visitedIfds.size < MAX_IFD_VISITS) {
|
||||
val ifdOffset = pendingIfds.removeAt(0)
|
||||
if (ifdOffset <= 0L || ifdOffset in visitedIfds) {
|
||||
continue
|
||||
}
|
||||
visitedIfds += ifdOffset
|
||||
|
||||
val scan = scanIfd(raf, ifdOffset, byteOrder) ?: continue
|
||||
if (scan.whiteLevelEntryOffset >= 0L) {
|
||||
val entry = ByteArray(12)
|
||||
raf.seek(scan.whiteLevelEntryOffset)
|
||||
raf.readFully(entry)
|
||||
val type = readUnsignedShort(entry, 2, byteOrder)
|
||||
val count = readUnsignedInt(entry, 4, byteOrder)
|
||||
val valueBytes = valueByteCount(type, count) ?: continue
|
||||
val valueOffset = valueOffsetForEntry(
|
||||
entry = entry,
|
||||
entryOffset = scan.whiteLevelEntryOffset,
|
||||
valueBytes = valueBytes,
|
||||
byteOrder = byteOrder
|
||||
)
|
||||
if (valueOffset >= 0L && valueOffset + valueBytes <= raf.length()) {
|
||||
writeWhiteLevelValues(raf, valueOffset, type, count, byteOrder, level)
|
||||
patchedCount++
|
||||
PLog.d(TAG, "Patched DNG WhiteLevel to $level ifd=$ifdOffset in ${file.name}")
|
||||
}
|
||||
}
|
||||
|
||||
if (scan.nextIfdOffset > 0L) {
|
||||
pendingIfds += scan.nextIfdOffset
|
||||
}
|
||||
scan.subIfdOffsets.forEach { subIfdOffset ->
|
||||
if (subIfdOffset > 0L && subIfdOffset !in visitedIfds) {
|
||||
pendingIfds += subIfdOffset
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (patchedCount == 0) {
|
||||
PLog.w(TAG, "DNG WhiteLevel tag missing in ${file.name}; scannedIfds=${visitedIfds.size}")
|
||||
return@use false
|
||||
}
|
||||
true
|
||||
}
|
||||
}.onFailure {
|
||||
PLog.w(TAG, "Failed to patch DNG WhiteLevel: ${file.absolutePath}", it)
|
||||
}.getOrDefault(false)
|
||||
}
|
||||
|
||||
private fun scanIfd(raf: RandomAccessFile, ifdOffset: Long, byteOrder: ByteOrder): IfdScanResult? {
|
||||
if (ifdOffset <= 0L || ifdOffset + 2L > raf.length()) {
|
||||
return null
|
||||
}
|
||||
|
||||
raf.seek(ifdOffset)
|
||||
val entryCountBytes = ByteArray(2)
|
||||
raf.readFully(entryCountBytes)
|
||||
val entryCount = readUnsignedShort(entryCountBytes, 0, byteOrder)
|
||||
val entriesStart = ifdOffset + 2L
|
||||
val nextIfdPointerOffset = entriesStart + entryCount * 12L
|
||||
if (nextIfdPointerOffset + 4L > raf.length()) {
|
||||
return null
|
||||
}
|
||||
|
||||
var whiteLevelEntryOffset = -1L
|
||||
val subIfdOffsets = mutableListOf<Long>()
|
||||
|
||||
for (entryIndex in 0 until entryCount) {
|
||||
val entryOffset = entriesStart + entryIndex * 12L
|
||||
val entry = ByteArray(12)
|
||||
raf.seek(entryOffset)
|
||||
raf.readFully(entry)
|
||||
when (readUnsignedShort(entry, 0, byteOrder)) {
|
||||
TIFF_TAG_WHITE_LEVEL -> whiteLevelEntryOffset = entryOffset
|
||||
TIFF_TAG_SUB_IFDS -> {
|
||||
val type = readUnsignedShort(entry, 2, byteOrder)
|
||||
val count = readUnsignedInt(entry, 4, byteOrder)
|
||||
subIfdOffsets += readUnsignedValues(raf, entry, entryOffset, type, count, byteOrder)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
raf.seek(nextIfdPointerOffset)
|
||||
val nextIfdBytes = ByteArray(4)
|
||||
raf.readFully(nextIfdBytes)
|
||||
return IfdScanResult(
|
||||
whiteLevelEntryOffset = whiteLevelEntryOffset,
|
||||
subIfdOffsets = subIfdOffsets,
|
||||
nextIfdOffset = readUnsignedInt(nextIfdBytes, 0, byteOrder)
|
||||
)
|
||||
}
|
||||
|
||||
private fun readUnsignedValues(
|
||||
raf: RandomAccessFile,
|
||||
entry: ByteArray,
|
||||
entryOffset: Long,
|
||||
type: Int,
|
||||
count: Long,
|
||||
byteOrder: ByteOrder
|
||||
): List<Long> {
|
||||
if (count <= 0L || count > 64L) {
|
||||
return emptyList()
|
||||
}
|
||||
val typeSize = when (type) {
|
||||
TYPE_SHORT -> 2L
|
||||
TYPE_LONG -> 4L
|
||||
else -> return emptyList()
|
||||
}
|
||||
val valueBytes = typeSize * count
|
||||
val valueOffset = valueOffsetForEntry(entry, entryOffset, valueBytes, byteOrder)
|
||||
if (valueOffset < 0L || valueOffset + valueBytes > raf.length()) {
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
return buildList {
|
||||
raf.seek(valueOffset)
|
||||
repeat(count.toInt()) {
|
||||
when (type) {
|
||||
TYPE_SHORT -> {
|
||||
val bytes = ByteArray(2)
|
||||
raf.readFully(bytes)
|
||||
add(readUnsignedShort(bytes, 0, byteOrder).toLong())
|
||||
}
|
||||
TYPE_LONG -> {
|
||||
val bytes = ByteArray(4)
|
||||
raf.readFully(bytes)
|
||||
add(readUnsignedInt(bytes, 0, byteOrder))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun valueOffsetForEntry(
|
||||
entry: ByteArray,
|
||||
entryOffset: Long,
|
||||
valueBytes: Long,
|
||||
byteOrder: ByteOrder
|
||||
): Long {
|
||||
return if (valueBytes <= 4L) {
|
||||
entryOffset + 8L
|
||||
} else {
|
||||
readUnsignedInt(entry, 8, byteOrder)
|
||||
}
|
||||
}
|
||||
|
||||
private fun writeWhiteLevelValues(
|
||||
raf: RandomAccessFile,
|
||||
valueOffset: Long,
|
||||
type: Int,
|
||||
count: Long,
|
||||
byteOrder: ByteOrder,
|
||||
level: Float
|
||||
) {
|
||||
raf.seek(valueOffset)
|
||||
val rounded = level.roundToInt().coerceAtLeast(1)
|
||||
repeat(count.coerceAtMost(4096L).toInt()) {
|
||||
when (type) {
|
||||
3 -> raf.write(shortBytes(rounded.coerceAtMost(0xFFFF), byteOrder))
|
||||
4 -> raf.write(intBytes(rounded, byteOrder))
|
||||
5 -> {
|
||||
raf.write(intBytes(rounded, byteOrder))
|
||||
raf.write(intBytes(1, byteOrder))
|
||||
}
|
||||
9 -> raf.write(intBytes(rounded, byteOrder))
|
||||
10 -> {
|
||||
raf.write(intBytes(rounded, byteOrder))
|
||||
raf.write(intBytes(1, byteOrder))
|
||||
}
|
||||
11 -> raf.write(floatBytes(level, byteOrder))
|
||||
12 -> raf.write(doubleBytes(level.toDouble(), byteOrder))
|
||||
else -> return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun valueByteCount(type: Int, count: Long): Long? {
|
||||
val typeSize = when (type) {
|
||||
1, 2, 6, 7 -> 1L
|
||||
3, 8 -> 2L
|
||||
4, 9, 11 -> 4L
|
||||
5, 10, 12 -> 8L
|
||||
else -> return null
|
||||
}
|
||||
return typeSize * count
|
||||
}
|
||||
|
||||
private fun readUnsignedShort(bytes: ByteArray, offset: Int, byteOrder: ByteOrder): Int {
|
||||
return ByteBuffer.wrap(bytes, offset, 2).order(byteOrder).short.toInt() and 0xFFFF
|
||||
}
|
||||
|
||||
private fun readUnsignedInt(bytes: ByteArray, offset: Int, byteOrder: ByteOrder): Long {
|
||||
return ByteBuffer.wrap(bytes, offset, 4).order(byteOrder).int.toLong() and 0xFFFFFFFFL
|
||||
}
|
||||
|
||||
private fun shortBytes(value: Int, byteOrder: ByteOrder): ByteArray {
|
||||
return ByteBuffer.allocate(2).order(byteOrder).putShort(value.toShort()).array()
|
||||
}
|
||||
|
||||
private fun intBytes(value: Int, byteOrder: ByteOrder): ByteArray {
|
||||
return ByteBuffer.allocate(4).order(byteOrder).putInt(value).array()
|
||||
}
|
||||
|
||||
private fun floatBytes(value: Float, byteOrder: ByteOrder): ByteArray {
|
||||
return ByteBuffer.allocate(4).order(byteOrder).putFloat(value).array()
|
||||
}
|
||||
|
||||
private fun doubleBytes(value: Double, byteOrder: ByteOrder): ByteArray {
|
||||
return ByteBuffer.allocate(8).order(byteOrder).putDouble(value).array()
|
||||
}
|
||||
}
|
||||
@@ -59,8 +59,12 @@ object RawProcessor {
|
||||
return RawCfaCorrection.resolveCfaPattern(defaultCfaPattern, cfaCorrectionMode)
|
||||
}
|
||||
|
||||
fun resolveWhiteLevelForMode(defaultWhiteLevel: Float, whiteLevelMode: String?): Float {
|
||||
return RawWhiteLevelCorrection.resolveWhiteLevel(defaultWhiteLevel, whiteLevelMode)
|
||||
fun resolveWhiteLevelForMode(
|
||||
defaultWhiteLevel: Float,
|
||||
whiteLevelMode: String?,
|
||||
customWhiteLevel: Float? = null
|
||||
): Float {
|
||||
return RawWhiteLevelCorrection.resolveWhiteLevel(defaultWhiteLevel, whiteLevelMode, customWhiteLevel)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -147,6 +151,7 @@ object RawProcessor {
|
||||
blackLevelMode: String? = null,
|
||||
customBlackLevel: Float? = null,
|
||||
whiteLevelMode: String? = null,
|
||||
customWhiteLevel: Float? = null,
|
||||
cfaCorrectionMode: String? = null,
|
||||
): Boolean {
|
||||
if (!isRawImage(image)) {
|
||||
@@ -163,6 +168,7 @@ object RawProcessor {
|
||||
blackLevelMode = blackLevelMode,
|
||||
customBlackLevel = customBlackLevel,
|
||||
whiteLevelMode = whiteLevelMode,
|
||||
customWhiteLevel = customWhiteLevel,
|
||||
cfaCorrectionMode = cfaCorrectionMode
|
||||
)
|
||||
}
|
||||
@@ -177,6 +183,7 @@ object RawProcessor {
|
||||
blackLevelMode: String?,
|
||||
customBlackLevel: Float?,
|
||||
whiteLevelMode: String?,
|
||||
customWhiteLevel: Float?,
|
||||
cfaCorrectionMode: String?,
|
||||
): Boolean {
|
||||
if (image.format != ImageFormat.RAW_SENSOR) {
|
||||
@@ -210,6 +217,7 @@ object RawProcessor {
|
||||
blackLevelMode = blackLevelMode,
|
||||
customBlackLevel = customBlackLevel,
|
||||
whiteLevelMode = whiteLevelMode,
|
||||
customWhiteLevel = customWhiteLevel,
|
||||
cfaCorrectionMode = cfaCorrectionMode
|
||||
)
|
||||
}
|
||||
@@ -261,6 +269,7 @@ object RawProcessor {
|
||||
blackLevelMode: String? = null,
|
||||
customBlackLevel: Float? = null,
|
||||
whiteLevelMode: String? = null,
|
||||
customWhiteLevel: Float? = null,
|
||||
cfaCorrectionMode: String? = null,
|
||||
baselineExposureEv: Float = 0f,
|
||||
profileGainTableMap: DngProfileGainTableMap? = null,
|
||||
@@ -270,7 +279,7 @@ object RawProcessor {
|
||||
inputColStepSamples: Int? = null,
|
||||
): Boolean {
|
||||
val resolvedCfaPattern = resolveCfaPatternForMode(cfaPattern, cfaCorrectionMode)
|
||||
val resolvedWhiteLevel = resolveWhiteLevelForMode(whiteLevel.toFloat(), whiteLevelMode).toInt()
|
||||
val resolvedWhiteLevel = resolveWhiteLevelForMode(whiteLevel.toFloat(), whiteLevelMode, customWhiteLevel).toInt()
|
||||
val hasCfaOverride = RawCfaCorrection.isOverrideMode(cfaCorrectionMode)
|
||||
val hasWhiteLevelOverride = RawWhiteLevelCorrection.isOverrideMode(whiteLevelMode)
|
||||
val requiresCustomWriter = imageLayout != SuperResolutionDngWriter.ImageLayout.CFA ||
|
||||
@@ -305,6 +314,7 @@ object RawProcessor {
|
||||
blackLevelMode = blackLevelMode,
|
||||
customBlackLevel = customBlackLevel,
|
||||
whiteLevelMode = whiteLevelMode,
|
||||
customWhiteLevel = customWhiteLevel,
|
||||
baselineExposureEv = baselineExposureEv,
|
||||
profileGainTableMap = profileGainTableMap,
|
||||
imageLayout = imageLayout,
|
||||
|
||||
@@ -133,6 +133,7 @@ object SuperResolutionDngWriter {
|
||||
blackLevelMode: String? = null,
|
||||
customBlackLevel: Float? = null,
|
||||
whiteLevelMode: String? = null,
|
||||
customWhiteLevel: Float? = null,
|
||||
baselineExposureEv: Float = 0f,
|
||||
profileGainTableMap: DngProfileGainTableMap? = null,
|
||||
imageLayout: ImageLayout = ImageLayout.CFA,
|
||||
@@ -155,7 +156,8 @@ object SuperResolutionDngWriter {
|
||||
val hasBlackLevelOverride = blackLevelMode != null && !blackLevel.contentEquals(resolvedBlackLevel)
|
||||
val resolvedWhiteLevel = RawWhiteLevelCorrection.resolveWhiteLevel(
|
||||
defaultWhiteLevel = whiteLevel.toFloat(),
|
||||
mode = whiteLevelMode
|
||||
mode = whiteLevelMode,
|
||||
customWhiteLevel = customWhiteLevel
|
||||
).toInt()
|
||||
|
||||
val encodedBlackLevel = if (valueDomain == RawProcessor.RawBufferValueDomain.NORMALIZED_SENSOR_RANGE) {
|
||||
|
||||
@@ -1084,6 +1084,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
val lensIdBlacklist: Flow<List<String>> = userPreferencesRepository.userPreferences.map { it.lensIdBlacklist }
|
||||
val iszLensConfigs: Flow<List<IszLensConfig>> = userPreferencesRepository.userPreferences.map { it.iszLensConfigs }
|
||||
val preferredMainCameraId: Flow<String?> = userPreferencesRepository.userPreferences.map { it.preferredMainCameraId }
|
||||
val preferredMacroCameraId: Flow<String?> = userPreferencesRepository.userPreferences.map { it.preferredMacroCameraId }
|
||||
val enableLogicalMultiCameraDiscovery: Flow<Boolean> =
|
||||
userPreferencesRepository.userPreferences.map { it.enableLogicalMultiCameraDiscovery }
|
||||
val logicalCameraBindingWhitelist: Flow<List<String>> =
|
||||
@@ -1153,6 +1154,12 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
) { cameraId, prefs ->
|
||||
prefs.rawWhiteLevelModes[cameraId] ?: RawWhiteLevelCorrection.MODE_DEFAULT
|
||||
}.stateIn(viewModelScope, SharingStarted.Eagerly, RawWhiteLevelCorrection.MODE_DEFAULT)
|
||||
val rawCustomWhiteLevel: StateFlow<Float> = combine(
|
||||
state.map { it.currentCameraId }.distinctUntilChanged(),
|
||||
userPreferencesRepository.userPreferences
|
||||
) { cameraId, prefs ->
|
||||
prefs.rawCustomWhiteLevels[cameraId] ?: 0f
|
||||
}.stateIn(viewModelScope, SharingStarted.Eagerly, 0f)
|
||||
val rawCfaCorrectionMode: StateFlow<String> = combine(
|
||||
state.map { it.currentCameraId }.distinctUntilChanged(),
|
||||
userPreferencesRepository.userPreferences
|
||||
@@ -1900,6 +1907,11 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
userPreferencesRepository.saveRawWhiteLevelMode(state.value.currentCameraId, mode)
|
||||
}
|
||||
}
|
||||
fun setRawCustomWhiteLevel(value: Float) {
|
||||
viewModelScope.launch {
|
||||
userPreferencesRepository.saveRawCustomWhiteLevel(state.value.currentCameraId, value)
|
||||
}
|
||||
}
|
||||
fun setRawCfaCorrectionMode(mode: String) {
|
||||
viewModelScope.launch {
|
||||
userPreferencesRepository.saveRawCfaCorrectionMode(state.value.currentCameraId, mode)
|
||||
@@ -2158,6 +2170,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
rawCustomBlackLevel = userPrefs?.rawCustomBlackLevels?.get(currentCameraId) ?: 0f,
|
||||
rawWhiteLevelMode = userPrefs?.rawWhiteLevelModes?.get(currentCameraId)
|
||||
?: RawWhiteLevelCorrection.MODE_DEFAULT,
|
||||
rawCustomWhiteLevel = userPrefs?.rawCustomWhiteLevels?.get(currentCameraId) ?: 0f,
|
||||
rawCfaCorrectionMode = userPrefs?.rawCfaCorrectionModes?.get(currentCameraId) ?: RawCfaCorrection.MODE_DEFAULT,
|
||||
cameraId = currentCameraId,
|
||||
rawBlackBorderCrop = currentRawBlackBorderCrop(),
|
||||
@@ -4338,10 +4351,11 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
if (normalizedBaseCameraId.isEmpty() || iszZoomRatio < 1f) return@launch
|
||||
|
||||
val config = IszLensConfig(
|
||||
normalizedBaseCameraId,
|
||||
iszZoomRatio,
|
||||
isMacro,
|
||||
IszLensConfig.sanitizeRawBlackBorderCrop(rawBlackBorderCrop)
|
||||
baseCameraId = normalizedBaseCameraId,
|
||||
iszZoomRatio = iszZoomRatio,
|
||||
isMacro = isMacro,
|
||||
rawBlackBorderCrop = IszLensConfig.sanitizeRawBlackBorderCrop(rawBlackBorderCrop),
|
||||
vendorCaptureProfileId = settings.toVirtualLensProfileId()
|
||||
)
|
||||
val prefs = userPreferencesRepository.userPreferences.first()
|
||||
val updatedConfigs = (prefs.iszLensConfigs
|
||||
@@ -4371,6 +4385,10 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
CameraDiscovery(getApplication()).discoverMainCameraIdOptions()
|
||||
}
|
||||
|
||||
suspend fun discoverMacroCameraIdOptions(): List<String> = withContext(Dispatchers.IO) {
|
||||
CameraDiscovery(getApplication()).discoverMacroCameraIdOptions()
|
||||
}
|
||||
|
||||
fun setPreferredMainCameraId(cameraId: String?) {
|
||||
viewModelScope.launch {
|
||||
userPreferencesRepository.savePreferredMainCameraId(cameraId)
|
||||
@@ -4378,6 +4396,13 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
}
|
||||
|
||||
fun setPreferredMacroCameraId(cameraId: String?) {
|
||||
viewModelScope.launch {
|
||||
userPreferencesRepository.savePreferredMacroCameraId(cameraId)
|
||||
cameraController.refreshCameraList()
|
||||
}
|
||||
}
|
||||
|
||||
fun setEnableLogicalMultiCameraDiscovery(enabled: Boolean) {
|
||||
viewModelScope.launch {
|
||||
userPreferencesRepository.saveEnableLogicalMultiCameraDiscovery(enabled)
|
||||
@@ -4542,6 +4567,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
rawCustomBlackLevel = userPrefs?.rawCustomBlackLevels?.get(currentCameraId) ?: 0f,
|
||||
rawWhiteLevelMode = userPrefs?.rawWhiteLevelModes?.get(currentCameraId)
|
||||
?: RawWhiteLevelCorrection.MODE_DEFAULT,
|
||||
rawCustomWhiteLevel = userPrefs?.rawCustomWhiteLevels?.get(currentCameraId) ?: 0f,
|
||||
rawCfaCorrectionMode = userPrefs?.rawCfaCorrectionModes?.get(currentCameraId) ?: RawCfaCorrection.MODE_DEFAULT,
|
||||
cameraId = currentCameraId,
|
||||
rawBlackBorderCrop = currentRawBlackBorderCrop(),
|
||||
@@ -4711,6 +4737,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
rawCustomBlackLevel = userPrefs?.rawCustomBlackLevels?.get(currentCameraId) ?: 0f,
|
||||
rawWhiteLevelMode = userPrefs?.rawWhiteLevelModes?.get(currentCameraId)
|
||||
?: RawWhiteLevelCorrection.MODE_DEFAULT,
|
||||
rawCustomWhiteLevel = userPrefs?.rawCustomWhiteLevels?.get(currentCameraId) ?: 0f,
|
||||
rawCfaCorrectionMode = userPrefs?.rawCfaCorrectionModes?.get(currentCameraId) ?: RawCfaCorrection.MODE_DEFAULT,
|
||||
cameraId = currentCameraId,
|
||||
rawBlackBorderCrop = currentRawBlackBorderCrop(),
|
||||
@@ -4855,6 +4882,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
rawCustomBlackLevel = userPrefs?.rawCustomBlackLevels?.get(currentCameraId) ?: 0f,
|
||||
rawWhiteLevelMode = userPrefs?.rawWhiteLevelModes?.get(currentCameraId)
|
||||
?: RawWhiteLevelCorrection.MODE_DEFAULT,
|
||||
rawCustomWhiteLevel = userPrefs?.rawCustomWhiteLevels?.get(currentCameraId) ?: 0f,
|
||||
rawCfaCorrectionMode = userPrefs?.rawCfaCorrectionModes?.get(currentCameraId) ?: RawCfaCorrection.MODE_DEFAULT,
|
||||
cameraId = currentCameraId,
|
||||
rawBlackBorderCrop = currentRawBlackBorderCrop(),
|
||||
@@ -5038,6 +5066,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
rawCustomBlackLevel = userPrefs?.rawCustomBlackLevels?.get(currentCameraId) ?: 0f,
|
||||
rawWhiteLevelMode = userPrefs?.rawWhiteLevelModes?.get(currentCameraId)
|
||||
?: RawWhiteLevelCorrection.MODE_DEFAULT,
|
||||
rawCustomWhiteLevel = userPrefs?.rawCustomWhiteLevels?.get(currentCameraId) ?: 0f,
|
||||
rawCfaCorrectionMode = userPrefs?.rawCfaCorrectionModes?.get(currentCameraId) ?: RawCfaCorrection.MODE_DEFAULT,
|
||||
cameraId = currentCameraId,
|
||||
rawBlackBorderCrop = currentRawBlackBorderCrop(),
|
||||
@@ -5583,6 +5612,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
rawCustomBlackLevel = userPrefs?.rawCustomBlackLevels?.get(currentCameraId) ?: 0f,
|
||||
rawWhiteLevelMode = userPrefs?.rawWhiteLevelModes?.get(currentCameraId)
|
||||
?: RawWhiteLevelCorrection.MODE_DEFAULT,
|
||||
rawCustomWhiteLevel = userPrefs?.rawCustomWhiteLevels?.get(currentCameraId) ?: 0f,
|
||||
rawCfaCorrectionMode = userPrefs?.rawCfaCorrectionModes?.get(currentCameraId) ?: RawCfaCorrection.MODE_DEFAULT,
|
||||
cameraId = currentCameraId,
|
||||
rawBlackBorderCrop = currentRawBlackBorderCrop(),
|
||||
|
||||
@@ -344,6 +344,8 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
private set
|
||||
var editRawWhiteLevelMode = MutableStateFlow(RawWhiteLevelCorrection.MODE_DEFAULT)
|
||||
private set
|
||||
var editRawCustomWhiteLevel = MutableStateFlow(0f)
|
||||
private set
|
||||
var editRawCfaCorrectionMode = MutableStateFlow(RawCfaCorrection.MODE_DEFAULT)
|
||||
private set
|
||||
var editRawDcpId = MutableStateFlow<String?>(null)
|
||||
@@ -1284,6 +1286,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
editRawBlackLevelMode.value = m.rawBlackLevelMode ?: RawCfaCorrection.MODE_DEFAULT
|
||||
editRawCustomBlackLevel.value = m.rawCustomBlackLevel ?: 0f
|
||||
editRawWhiteLevelMode.value = m.rawWhiteLevelMode ?: RawWhiteLevelCorrection.MODE_DEFAULT
|
||||
editRawCustomWhiteLevel.value = m.rawCustomWhiteLevel ?: 0f
|
||||
editRawCfaCorrectionMode.value = m.rawCfaCorrectionMode ?: RawCfaCorrection.MODE_DEFAULT
|
||||
editRawDcpId.value = m.rawDcpId
|
||||
editRawRenderingEngine.value = m.rawRenderingEngine
|
||||
@@ -1908,6 +1911,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
editRawBlackLevelMode.value = metadata.rawBlackLevelMode ?: RawCfaCorrection.MODE_DEFAULT
|
||||
editRawCustomBlackLevel.value = metadata.rawCustomBlackLevel ?: 0f
|
||||
editRawWhiteLevelMode.value = metadata.rawWhiteLevelMode ?: RawWhiteLevelCorrection.MODE_DEFAULT
|
||||
editRawCustomWhiteLevel.value = metadata.rawCustomWhiteLevel ?: 0f
|
||||
editRawCfaCorrectionMode.value = metadata.rawCfaCorrectionMode ?: RawCfaCorrection.MODE_DEFAULT
|
||||
editRawDROMode.value = RawProcessingPreferences.DROMode.fromPersistedName(metadata.droMode).name
|
||||
editComputationalAperture.value = metadata.computationalAperture
|
||||
@@ -1933,6 +1937,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
editRawBlackLevelMode.value = RawCfaCorrection.MODE_DEFAULT
|
||||
editRawCustomBlackLevel.value = 0f
|
||||
editRawWhiteLevelMode.value = RawWhiteLevelCorrection.MODE_DEFAULT
|
||||
editRawCustomWhiteLevel.value = 0f
|
||||
editRawCfaCorrectionMode.value = RawCfaCorrection.MODE_DEFAULT
|
||||
editRawDROMode.value = "OFF"
|
||||
editRawDcpId.value = null
|
||||
@@ -2039,6 +2044,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
editRawBlackLevelMode.value = RawCfaCorrection.MODE_DEFAULT
|
||||
editRawCustomBlackLevel.value = 0f
|
||||
editRawWhiteLevelMode.value = RawWhiteLevelCorrection.MODE_DEFAULT
|
||||
editRawCustomWhiteLevel.value = 0f
|
||||
editRawCfaCorrectionMode.value = RawCfaCorrection.MODE_DEFAULT
|
||||
editRawDROMode.value = "OFF"
|
||||
editRawDcpId.value = null
|
||||
@@ -2177,6 +2183,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
val blackLevelMode = editRawBlackLevelMode.value
|
||||
val customBlackLevel = editRawCustomBlackLevel.value
|
||||
val whiteLevelMode = editRawWhiteLevelMode.value
|
||||
val customWhiteLevel = editRawCustomWhiteLevel.value
|
||||
val cfaCorrectionMode = editRawCfaCorrectionMode.value
|
||||
val dcpId = editRawDcpId.value
|
||||
val baselineLutId = editRawBaselineLutId.value
|
||||
@@ -2210,6 +2217,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
rawBlackLevelMode = blackLevelMode,
|
||||
rawCustomBlackLevel = customBlackLevel,
|
||||
rawWhiteLevelMode = whiteLevelMode,
|
||||
rawCustomWhiteLevel = customWhiteLevel,
|
||||
rawCfaCorrectionMode = cfaCorrectionMode,
|
||||
droMode = droMode,
|
||||
rawDcpId = dcpId,
|
||||
@@ -2337,6 +2345,11 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
persistRawEditMetadata(mediaData, onComplete)
|
||||
}
|
||||
|
||||
fun saveRawCustomWhiteLevel(mediaData: MediaData, value: Float, onComplete: ((Boolean) -> Unit)? = null) {
|
||||
editRawCustomWhiteLevel.value = value
|
||||
persistRawEditMetadata(mediaData, onComplete)
|
||||
}
|
||||
|
||||
fun saveRawCfaCorrectionMode(mediaData: MediaData, mode: String, onComplete: ((Boolean) -> Unit)? = null) {
|
||||
editRawCfaCorrectionMode.value = mode
|
||||
persistRawEditMetadata(mediaData, onComplete)
|
||||
@@ -2620,6 +2633,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
rawBlackLevelMode = editRawBlackLevelMode.value,
|
||||
rawCustomBlackLevel = editRawCustomBlackLevel.value,
|
||||
rawWhiteLevelMode = editRawWhiteLevelMode.value,
|
||||
rawCustomWhiteLevel = editRawCustomWhiteLevel.value,
|
||||
rawCfaCorrectionMode = editRawCfaCorrectionMode.value,
|
||||
rawDcpId = editRawDcpId.value,
|
||||
baselineTarget = editRawBaselineLutId.value?.let { BaselineColorCorrectionTarget.RAW },
|
||||
@@ -2950,6 +2964,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
rawBlackLevelMode = editRawBlackLevelMode.value,
|
||||
rawCustomBlackLevel = editRawCustomBlackLevel.value,
|
||||
rawWhiteLevelMode = editRawWhiteLevelMode.value,
|
||||
rawCustomWhiteLevel = editRawCustomWhiteLevel.value,
|
||||
rawCfaCorrectionMode = editRawCfaCorrectionMode.value,
|
||||
rawDcpId = editRawDcpId.value,
|
||||
baselineTarget = rawBaselineLutId?.let { BaselineColorCorrectionTarget.RAW },
|
||||
|
||||
@@ -682,6 +682,7 @@
|
||||
<string name="settings_white_level_raw12">RAW12</string>
|
||||
<string name="settings_white_level_raw14">RAW14</string>
|
||||
<string name="settings_white_level_raw_sensor">RAW Sensor(65535)</string>
|
||||
<string name="settings_white_level_custom">ปรับแต่ง</string>
|
||||
<string name="settings_raw_cfa_correction">การแก้ไขช่อง CFA</string>
|
||||
<string name="settings_raw_cfa_correction_with_lens">การแก้ไขช่อง CFA (เลนส์ %1$s · %2$d มม.)</string>
|
||||
<string name="settings_raw_cfa_correction_description">แทนที่รูปแบบช่อง RAW CFA ที่เขียนลง DNG การตั้งค่าส่วนบุคคลสำหรับเลนส์</string>
|
||||
|
||||
@@ -298,7 +298,9 @@
|
||||
<string name="settings_isz_lens_no_physical_lens">没有可用的后置物理镜头。</string>
|
||||
<string name="settings_isz_added_lenses">已新增的虚拟镜头</string>
|
||||
<string name="settings_isz_existing_lens_title">%1$s + ISZ %2$s</string>
|
||||
<string name="settings_isz_existing_lens_description">%1$s · 显示 %2$s · %3$s · 厂商 Key %4$d · %5$s</string>
|
||||
<string name="settings_isz_existing_lens_description">%1$s · 显示 %2$s · %3$s · %4$s · %5$s</string>
|
||||
<string name="settings_isz_vendor_profile_none">无厂商 Key</string>
|
||||
<string name="settings_isz_vendor_profile_entry">%1$s=%2$d</string>
|
||||
<string name="settings_isz_lens_kind_normal">普通</string>
|
||||
<string name="settings_isz_lens_kind_macro">微距</string>
|
||||
<string name="settings_isz_add_lens_confirm">新增镜头</string>
|
||||
@@ -687,6 +689,9 @@
|
||||
<string name="settings_main_camera_id">主摄 ID</string>
|
||||
<string name="settings_main_camera_id_description">选择将哪个 1x 后置相机 ID 作为主摄。</string>
|
||||
<string name="settings_main_camera_id_option">相机 ID %1$s</string>
|
||||
<string name="settings_macro_camera_id">微距镜头 ID</string>
|
||||
<string name="settings_macro_camera_id_description">选择一个后置相机 ID 强制作为微距镜头。自动识别会保留当前相机发现逻辑。</string>
|
||||
<string name="settings_macro_camera_id_auto">自动识别</string>
|
||||
<string name="settings_logical_multi_camera_discovery">逻辑多摄探测</string>
|
||||
<string name="settings_logical_multi_camera_discovery_description">探测逻辑多摄 ID 暴露的物理镜头。默认关闭以提高兼容性。</string>
|
||||
<string name="settings_logical_camera_binding_whitelist">逻辑/物理摄像头白名单</string>
|
||||
@@ -786,6 +791,7 @@
|
||||
<string name="settings_white_level_raw12">RAW12</string>
|
||||
<string name="settings_white_level_raw14">RAW14</string>
|
||||
<string name="settings_white_level_raw_sensor">RAW Sensor(65535)</string>
|
||||
<string name="settings_white_level_custom">自定义</string>
|
||||
<string name="settings_raw_cfa_correction">CFA 通道校正</string>
|
||||
<string name="settings_raw_cfa_correction_with_lens">CFA 通道校正(镜头 %1$s · %2$dmm)</string>
|
||||
<string name="settings_raw_cfa_correction_description">覆盖写入 DNG 的 RAW CFA 通道排列。针对镜头单独设置。</string>
|
||||
@@ -991,4 +997,5 @@
|
||||
<string name="preset_restore_defaults_confirm">恢复默认预设将清除所有自定义覆盖,是否继续?</string>
|
||||
<string name="preset_custom_badge">自定义</string>
|
||||
<string name="preset_builtin_badge">内置</string>
|
||||
<string name="gallery">相册</string>
|
||||
</resources>
|
||||
@@ -298,7 +298,9 @@
|
||||
<string name="settings_isz_lens_no_physical_lens">沒有可用的后置物理鏡頭。</string>
|
||||
<string name="settings_isz_added_lenses">已新增的虛擬鏡頭</string>
|
||||
<string name="settings_isz_existing_lens_title">%1$s + ISZ %2$s</string>
|
||||
<string name="settings_isz_existing_lens_description">%1$s · 顯示 %2$s · %3$s · 廠商 Key %4$d · %5$s</string>
|
||||
<string name="settings_isz_existing_lens_description">%1$s · 顯示 %2$s · %3$s · %4$s · %5$s</string>
|
||||
<string name="settings_isz_vendor_profile_none">無廠商 Key</string>
|
||||
<string name="settings_isz_vendor_profile_entry">%1$s=%2$d</string>
|
||||
<string name="settings_isz_lens_kind_normal">普通</string>
|
||||
<string name="settings_isz_lens_kind_macro">微距</string>
|
||||
<string name="settings_isz_add_lens_confirm">新增鏡頭</string>
|
||||
@@ -687,10 +689,13 @@
|
||||
<string name="settings_main_camera_id">主攝 ID</string>
|
||||
<string name="settings_main_camera_id_description">選擇將哪個 1x 后置相機 ID 作為主攝。</string>
|
||||
<string name="settings_main_camera_id_option">相機 ID %1$s</string>
|
||||
<string name="settings_logical_multi_camera_discovery">邏輯多攝探測</string>
|
||||
<string name="settings_logical_multi_camera_discovery_description">探測邏輯多攝 ID 暴露的物理鏡頭。預設關閉以提高相容性。</string>
|
||||
<string name="settings_logical_camera_binding_whitelist">邏輯/物理攝像頭白名單</string>
|
||||
<string name="settings_logical_camera_binding_whitelist_description">強制啟用類似 0/2、0/3 的邏輯/物理綁定。即使自動探測關閉也會生效。</string>
|
||||
<string name="settings_macro_camera_id">微距鏡頭 ID</string>
|
||||
<string name="settings_macro_camera_id_description">選擇一個後置相機 ID 強制作為微距鏡頭。自動識別會保留目前相機偵測邏輯。</string>
|
||||
<string name="settings_macro_camera_id_auto">自動識別</string>
|
||||
<string name="settings_logical_multi_camera_discovery">邏輯多攝偵測</string>
|
||||
<string name="settings_logical_multi_camera_discovery_description">偵測邏輯多攝 ID 暴露的物理鏡頭。預設關閉以提高相容性。</string>
|
||||
<string name="settings_logical_camera_binding_whitelist">邏輯/物理相機白名單</string>
|
||||
<string name="settings_logical_camera_binding_whitelist_description">強制啟用類似 0/2、0/3 的邏輯/物理綁定。即使自動偵測關閉也會生效。</string>
|
||||
<string name="settings_custom_lens_ids">自訂鏡頭 ID</string>
|
||||
<string name="settings_custom_lens_ids_description">手動添加相機 ID,多個 ID 用逗號分隔。檢測可用后會加入鏡頭列表并顯示特殊標識。</string>
|
||||
<string name="settings_lens_id_blacklist">鏡頭 ID 黑名單</string>
|
||||
@@ -786,6 +791,7 @@
|
||||
<string name="settings_white_level_raw12">RAW12</string>
|
||||
<string name="settings_white_level_raw14">RAW14</string>
|
||||
<string name="settings_white_level_raw_sensor">RAW Sensor(65535)</string>
|
||||
<string name="settings_white_level_custom">自訂</string>
|
||||
<string name="settings_raw_cfa_correction">CFA 通道校正</string>
|
||||
<string name="settings_raw_cfa_correction_with_lens">CFA 通道校正(鏡頭 %1$s · %2$dmm)</string>
|
||||
<string name="settings_raw_cfa_correction_description">覆蓋寫入 DNG 的 RAW CFA 通道排列。針對鏡頭單獨設定。</string>
|
||||
@@ -991,4 +997,5 @@
|
||||
<string name="preset_restore_defaults_confirm">還原預設預設將清除所有自訂覆蓋,是否繼續?</string>
|
||||
<string name="preset_custom_badge">自訂</string>
|
||||
<string name="preset_builtin_badge">內置</string>
|
||||
<string name="gallery">相簿</string>
|
||||
</resources>
|
||||
@@ -300,7 +300,9 @@
|
||||
<string name="settings_isz_lens_no_physical_lens">No usable rear physical lens is available.</string>
|
||||
<string name="settings_isz_added_lenses">Added ISZ/DCG Lenses</string>
|
||||
<string name="settings_isz_existing_lens_title">%1$s + ISZ %2$s</string>
|
||||
<string name="settings_isz_existing_lens_description">%1$s · visible %2$s · %3$s · vendor keys %4$d · %5$s</string>
|
||||
<string name="settings_isz_existing_lens_description">%1$s · visible %2$s · %3$s · %4$s · %5$s</string>
|
||||
<string name="settings_isz_vendor_profile_none">no vendor key</string>
|
||||
<string name="settings_isz_vendor_profile_entry">%1$s=%2$d</string>
|
||||
<string name="settings_isz_lens_kind_normal">normal</string>
|
||||
<string name="settings_isz_lens_kind_macro">macro</string>
|
||||
<string name="settings_isz_add_lens_confirm">Add Lens</string>
|
||||
@@ -696,6 +698,9 @@
|
||||
<string name="settings_main_camera_id">Main Camera ID</string>
|
||||
<string name="settings_main_camera_id_description">Choose which 1x rear camera ID is used as the main camera.</string>
|
||||
<string name="settings_main_camera_id_option">Camera ID %1$s</string>
|
||||
<string name="settings_macro_camera_id">Macro Camera ID</string>
|
||||
<string name="settings_macro_camera_id_description">Choose a rear camera ID to force as the macro lens. Auto keeps the current camera discovery behavior.</string>
|
||||
<string name="settings_macro_camera_id_auto">Auto</string>
|
||||
<string name="settings_logical_multi_camera_discovery">Logical Multi-Camera Discovery</string>
|
||||
<string name="settings_logical_multi_camera_discovery_description">Detect physical lenses exposed by logical multi-camera IDs. Off by default for compatibility.</string>
|
||||
<string name="settings_logical_camera_binding_whitelist">Logical/Physical Camera Whitelist</string>
|
||||
@@ -770,6 +775,7 @@
|
||||
<string name="settings_white_level_raw12">RAW12</string>
|
||||
<string name="settings_white_level_raw14">RAW14</string>
|
||||
<string name="settings_white_level_raw_sensor">RAW Sensor(65535)</string>
|
||||
<string name="settings_white_level_custom">Custom</string>
|
||||
<string name="settings_raw_cfa_correction">CFA Channel Correction</string>
|
||||
<string name="settings_raw_cfa_correction_with_lens">CFA Channel Correction (Lens %1$s · %2$dmm)</string>
|
||||
<string name="settings_raw_cfa_correction_description">Override the RAW CFA channel pattern written to DNG. Applied per camera lens.</string>
|
||||
@@ -993,4 +999,5 @@
|
||||
<string name="preset_restore_defaults_confirm">Restoring default presets will clear all custom modifications. Do you want to continue?</string>
|
||||
<string name="preset_custom_badge">Custom</string>
|
||||
<string name="preset_builtin_badge">Built-in</string>
|
||||
<string name="gallery">Gallery</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.hinnka.mycamera.camera
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotEquals
|
||||
import org.junit.Test
|
||||
|
||||
class IszLensConfigTest {
|
||||
@Test
|
||||
fun createVirtualCameraId_withoutVendorProfileKeepsLegacyId() {
|
||||
assertEquals(
|
||||
"isz:0:2",
|
||||
IszLensConfig.createVirtualCameraId(
|
||||
baseCameraId = "0",
|
||||
iszZoomRatio = 2f
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun createVirtualCameraId_withVendorProfileDistinguishesSameBaseAndRatio() {
|
||||
val legacyId = IszLensConfig.createVirtualCameraId(
|
||||
baseCameraId = "0",
|
||||
iszZoomRatio = 2f
|
||||
)
|
||||
val profiledId = IszLensConfig.createVirtualCameraId(
|
||||
baseCameraId = "0",
|
||||
iszZoomRatio = 2f,
|
||||
vendorCaptureProfileId = "insensor_zoom_1"
|
||||
)
|
||||
|
||||
assertEquals("isz:0:2:insensor_zoom_1", profiledId)
|
||||
assertNotEquals(legacyId, profiledId)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun serializeList_keepsSameBaseAndRatioWhenVendorProfilesDiffer() {
|
||||
val configs = listOf(
|
||||
IszLensConfig(
|
||||
baseCameraId = "0",
|
||||
iszZoomRatio = 2f,
|
||||
vendorCaptureProfileId = "insensor_zoom_1"
|
||||
),
|
||||
IszLensConfig(
|
||||
baseCameraId = "0",
|
||||
iszZoomRatio = 2f,
|
||||
vendorCaptureProfileId = "qcom_sensor_current_mode_1"
|
||||
)
|
||||
)
|
||||
|
||||
val restored = IszLensConfig.deserializeList(IszLensConfig.serializeList(configs))
|
||||
|
||||
assertEquals(2, restored.size)
|
||||
assertEquals(2, restored.map { it.virtualCameraId }.distinct().size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun vendorCaptureSettingsProfileId_isStableAndValueAware() {
|
||||
val settings = VendorCaptureSettings(
|
||||
mapOf(
|
||||
VendorCaptureKey.QCOM_SENSOR_CURRENT_MODE to 2,
|
||||
VendorCaptureKey.INSENSOR_ZOOM to 1
|
||||
)
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
"insensor_zoom_1-qcom_sensor_current_mode_2",
|
||||
settings.toVirtualLensProfileId()
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user