feat: raw highlights shadows slider

This commit is contained in:
Hinnka committed 2026-06-13 20:29:45 +08:00
1 parent d67993cac6
commit 379a320352
20 files changed
+517 -232

No files matched your search

@@ -88,6 +88,8 @@ data class UserPreferences(
val rawNlmNoiseFactor: Float = 0f,
val rawExposureCompensation: Float = 0f,
val rawAutoExposure: Boolean = true,
val rawHighlightsAdjustment: Float = 0f,
val rawShadowsAdjustment: Float = 0f,
val rawMinShutterSpeedNs: Long = 0L,
val rawDROEnabled: Boolean = false,
val rawBlackPointCorrection: Float = 0f,
@@ -239,6 +241,8 @@ class UserPreferencesRepository(private val context: Context) {
private val RAW_NLM_NOISE_FACTOR_KEY = floatPreferencesKey("raw_nlm_noise_factor")
private val RAW_EXPOSURE_COMPENSATION_KEY = floatPreferencesKey("raw_exposure_compensation")
private val RAW_AUTO_EXPOSURE_KEY = booleanPreferencesKey("raw_auto_exposure")
private val RAW_HIGHLIGHTS_ADJUSTMENT_KEY = floatPreferencesKey("raw_highlights_adjustment")
private val RAW_SHADOWS_ADJUSTMENT_KEY = floatPreferencesKey("raw_shadows_adjustment")
private val RAW_MIN_SHUTTER_SPEED_NS_KEY = longPreferencesKey("raw_min_shutter_speed_ns")
private val RAW_DRO_ENABLED_KEY = booleanPreferencesKey("raw_dro_enabled")
private val RAW_BLACK_POINT_CORRECTION_KEY = floatPreferencesKey("raw_black_point_correction")
@@ -378,6 +382,8 @@ class UserPreferencesRepository(private val context: Context) {
rawNlmNoiseFactor = preferences[RAW_NLM_NOISE_FACTOR_KEY] ?: 0f,
rawExposureCompensation = preferences[RAW_EXPOSURE_COMPENSATION_KEY] ?: 0f,
rawAutoExposure = preferences[RAW_AUTO_EXPOSURE_KEY] ?: true,
rawHighlightsAdjustment = preferences[RAW_HIGHLIGHTS_ADJUSTMENT_KEY] ?: 0f,
rawShadowsAdjustment = preferences[RAW_SHADOWS_ADJUSTMENT_KEY] ?: 0f,
rawMinShutterSpeedNs = preferences[RAW_MIN_SHUTTER_SPEED_NS_KEY] ?: 0L,
rawDROEnabled = preferences[RAW_DRO_ENABLED_KEY] ?: false,
rawBlackPointCorrection = preferences[RAW_BLACK_POINT_CORRECTION_KEY] ?: 0f,
@@ -774,6 +780,18 @@ class UserPreferencesRepository(private val context: Context) {
}
}
suspend fun saveRawHighlightsAdjustment(value: Float) {
context.dataStore.edit { preferences ->
preferences[RAW_HIGHLIGHTS_ADJUSTMENT_KEY] = value
}
}
suspend fun saveRawShadowsAdjustment(value: Float) {
context.dataStore.edit { preferences ->
preferences[RAW_SHADOWS_ADJUSTMENT_KEY] = value
}
}
suspend fun saveRawMinShutterSpeedNs(value: Long) {
context.dataStore.edit { preferences ->
if (value > 0L) {
@@ -136,6 +136,17 @@ object GalleryManager {
?: (ContentRepository.getInstance(context).userPreferencesRepository.userPreferences.firstOrNull()
?.rawAutoExposure ?: true)
}
private fun MediaMetadata.withRawAutoAdjustments(
adjustments: RawDemosaicProcessor.RawAutoAdjustments
): MediaMetadata {
return copy(
rawExposureCompensation = adjustments.exposureCompensation,
rawHighlightsAdjustment = adjustments.highlights,
rawShadowsAdjustment = adjustments.shadows
)
}
private val _photoLibraryChangedEvents = MutableSharedFlow<Unit>(extraBufferCapacity = 16)
val photoLibraryChangedEvents: SharedFlow<Unit> = _photoLibraryChangedEvents.asSharedFlow()
private val hdrWorkLock = Any()
@@ -1288,33 +1299,41 @@ object GalleryManager {
exportDng(context, photoId, dngFile, metadata)
}
var updatedMetadata: MediaMetadata = metadata
val rawResult = RawDemosaicProcessor.getInstance().processForHdrSources(
context,
dngFile.absolutePath,
aspectRatio = aspectRatio,
cropRegion = metadata.cropRegion,
cropRegion = updatedMetadata.cropRegion,
rotation = rotation,
exposureBias = exposureBias ?: 0f,
rawExposureCompensation = metadata.rawExposureCompensation ?: 0f,
rawAutoExposure = resolveRawAutoExposure(context, metadata),
rawBlackPointCorrection = metadata.rawBlackPointCorrection ?: 0f,
rawWhitePointCorrection = metadata.rawWhitePointCorrection ?: 0f,
rawAutoWhiteBalanceEstimate = resolveRawAutoWhiteBalanceEstimate(context, metadata),
rawExposureCompensation = updatedMetadata.rawExposureCompensation ?: 0f,
rawAutoExposure = resolveRawAutoExposure(context, updatedMetadata),
rawHighlightsAdjustment = updatedMetadata.rawHighlightsAdjustment ?: 0f,
rawShadowsAdjustment = updatedMetadata.rawShadowsAdjustment ?: 0f,
rawBlackPointCorrection = updatedMetadata.rawBlackPointCorrection ?: 0f,
rawWhitePointCorrection = updatedMetadata.rawWhitePointCorrection ?: 0f,
rawAutoWhiteBalanceEstimate = resolveRawAutoWhiteBalanceEstimate(context, updatedMetadata),
sharpeningValue = 0.4f,
denoiseValue = metadata.rawDenoiseValue,
rawDcpId = metadata.rawDcpId,
spectralFilmEnabled = metadata.spectralFilmEnabled,
spectralFilmStock = metadata.spectralFilmStock,
spectralFilmPrint = metadata.spectralFilmPrint,
denoiseValue = updatedMetadata.rawDenoiseValue,
rawDcpId = updatedMetadata.rawDcpId,
spectralFilmEnabled = updatedMetadata.spectralFilmEnabled,
spectralFilmStock = updatedMetadata.spectralFilmStock,
spectralFilmPrint = updatedMetadata.spectralFilmPrint,
spectralFilmTuning = SpectralFilmTuning(
cDensityGain = metadata.spectralFilmCDensityGain,
mDensityGain = metadata.spectralFilmMDensityGain,
yDensityGain = metadata.spectralFilmYDensityGain
)
cDensityGain = updatedMetadata.spectralFilmCDensityGain,
mDensityGain = updatedMetadata.spectralFilmMDensityGain,
yDensityGain = updatedMetadata.spectralFilmYDensityGain
),
onRawAutoAdjustments = { adjustments ->
updatedMetadata = updatedMetadata.withRawAutoAdjustments(adjustments)
}
) ?: return@withContext
var bitmap = rawResult.sdrBitmap
if (metadata.isMirrored) {
saveMetadata(context, photoId, updatedMetadata)
if (updatedMetadata.isMirrored) {
bitmap = BitmapUtils.flipHorizontal(bitmap)
}
@@ -1322,13 +1341,13 @@ object GalleryManager {
writeFinalJpeg(bitmap, outputStream, photoQuality)
}
tempFile.renameTo(photoFile)
generateBokehPhoto(context, photoId, metadata, bitmap)
val preparedUltraHdrSource = if (metadata.manualHdrEffectEnabled) {
generateBokehPhoto(context, photoId, updatedMetadata, bitmap)
val preparedUltraHdrSource = if (updatedMetadata.manualHdrEffectEnabled) {
photoProcessor.prepareUltraHdrSourceFromRawResult(
context = context,
photoId = photoId,
rawResult = rawResult,
metadata = metadata,
metadata = updatedMetadata,
sharpening = sharpeningValue,
noiseReduction = noiseReductionValue,
chromaNoiseReduction = chromaNoiseReductionValue,
@@ -1340,7 +1359,7 @@ object GalleryManager {
val preparedGainmapResult = preparedUltraHdrSource?.let { source ->
var result: GainmapResult? = null
val gainmapElapsed = measureTimeMillis {
result = gainmapProducer.build(source, HdrGainmapStrength.coerce(metadata.hdrEffectStrength))
result = gainmapProducer.build(source, HdrGainmapStrength.coerce(updatedMetadata.hdrEffectStrength))
}
PLog.d(TAG, "saveRawPhoto prepared gainmap for reuse, took=${gainmapElapsed}ms")
result
@@ -1350,7 +1369,7 @@ object GalleryManager {
buildDetailHdrCache(
context = context,
photoId = photoId,
metadata = metadata,
metadata = updatedMetadata,
sharpening = sharpeningValue,
noiseReduction = noiseReductionValue,
chromaNoiseReduction = chromaNoiseReductionValue,
@@ -1358,14 +1377,14 @@ object GalleryManager {
preparedGainmapResult = preparedGainmapResult
)
}
updateThumbnail(context, photoId, photoProcessor, metadata, bitmap)
updateThumbnail(context, photoId, photoProcessor, updatedMetadata, bitmap)
if (shouldAutoSave) {
exportPhoto(
context,
photoId,
bitmap,
photoProcessor,
metadata,
updatedMetadata,
sharpeningValue,
noiseReductionValue,
chromaNoiseReductionValue,
@@ -1999,33 +2018,41 @@ object GalleryManager {
@Suppress("ExplicitGarbageCollectionCall")
System.gc()
var updatedMetadata: MediaMetadata = metadata
val rawResult = RawDemosaicProcessor.getInstance().processForHdrSources(
context,
dngFile.absolutePath,
aspectRatio = aspectRatio,
cropRegion = metadata.cropRegion,
cropRegion = updatedMetadata.cropRegion,
rotation = rotation,
exposureBias = exposureBias ?: 0f,
rawExposureCompensation = metadata.rawExposureCompensation ?: 0f,
rawAutoExposure = resolveRawAutoExposure(context, metadata),
rawBlackPointCorrection = metadata.rawBlackPointCorrection ?: 0f,
rawWhitePointCorrection = metadata.rawWhitePointCorrection ?: 0f,
rawAutoWhiteBalanceEstimate = resolveRawAutoWhiteBalanceEstimate(context, metadata),
rawExposureCompensation = updatedMetadata.rawExposureCompensation ?: 0f,
rawAutoExposure = resolveRawAutoExposure(context, updatedMetadata),
rawHighlightsAdjustment = updatedMetadata.rawHighlightsAdjustment ?: 0f,
rawShadowsAdjustment = updatedMetadata.rawShadowsAdjustment ?: 0f,
rawBlackPointCorrection = updatedMetadata.rawBlackPointCorrection ?: 0f,
rawWhitePointCorrection = updatedMetadata.rawWhitePointCorrection ?: 0f,
rawAutoWhiteBalanceEstimate = resolveRawAutoWhiteBalanceEstimate(context, updatedMetadata),
sharpeningValue = 0.4f,
denoiseValue = metadata.rawDenoiseValue,
rawDcpId = metadata.rawDcpId,
spectralFilmEnabled = metadata.spectralFilmEnabled,
spectralFilmStock = metadata.spectralFilmStock,
spectralFilmPrint = metadata.spectralFilmPrint,
denoiseValue = updatedMetadata.rawDenoiseValue,
rawDcpId = updatedMetadata.rawDcpId,
spectralFilmEnabled = updatedMetadata.spectralFilmEnabled,
spectralFilmStock = updatedMetadata.spectralFilmStock,
spectralFilmPrint = updatedMetadata.spectralFilmPrint,
spectralFilmTuning = SpectralFilmTuning(
cDensityGain = metadata.spectralFilmCDensityGain,
mDensityGain = metadata.spectralFilmMDensityGain,
yDensityGain = metadata.spectralFilmYDensityGain
)
cDensityGain = updatedMetadata.spectralFilmCDensityGain,
mDensityGain = updatedMetadata.spectralFilmMDensityGain,
yDensityGain = updatedMetadata.spectralFilmYDensityGain
),
onRawAutoAdjustments = { adjustments ->
updatedMetadata = updatedMetadata.withRawAutoAdjustments(adjustments)
}
) ?: return@withContext
var bitmap = rawResult.sdrBitmap
if (metadata.isMirrored) {
saveMetadata(context, photoId, updatedMetadata)
if (updatedMetadata.isMirrored) {
bitmap = BitmapUtils.flipHorizontal(bitmap)
}
@@ -2034,14 +2061,14 @@ object GalleryManager {
writeFinalJpeg(bitmap, outputStream, photoQuality)
}
tempFile.renameTo(photoFile)
generateBokehPhoto(context, photoId, metadata, bitmap)
generateBokehPhoto(context, photoId, updatedMetadata, bitmap)
val preparedUltraHdrSource = if (metadata.manualHdrEffectEnabled) {
val preparedUltraHdrSource = if (updatedMetadata.manualHdrEffectEnabled) {
photoProcessor.prepareUltraHdrSourceFromRawResult(
context = context,
photoId = photoId,
rawResult = rawResult,
metadata = metadata,
metadata = updatedMetadata,
sharpening = sharpeningValue,
noiseReduction = noiseReductionValue,
chromaNoiseReduction = chromaNoiseReductionValue,
@@ -2053,7 +2080,7 @@ object GalleryManager {
val preparedGainmapResult = preparedUltraHdrSource?.let { source ->
var result: GainmapResult? = null
val gainmapElapsed = measureTimeMillis {
result = gainmapProducer.build(source, HdrGainmapStrength.coerce(metadata.hdrEffectStrength))
result = gainmapProducer.build(source, HdrGainmapStrength.coerce(updatedMetadata.hdrEffectStrength))
}
PLog.d(TAG, "saveRawStackedPhoto prepared gainmap for reuse, took=${gainmapElapsed}ms")
result
@@ -2063,7 +2090,7 @@ object GalleryManager {
buildDetailHdrCache(
context = context,
photoId = photoId,
metadata = metadata,
metadata = updatedMetadata,
sharpening = sharpeningValue,
noiseReduction = noiseReductionValue,
chromaNoiseReduction = chromaNoiseReductionValue,
@@ -2072,7 +2099,7 @@ object GalleryManager {
)
}
updateThumbnail(context, photoId, photoProcessor, metadata, bitmap)
updateThumbnail(context, photoId, photoProcessor, updatedMetadata, bitmap)
// Auto Save
if (shouldAutoSave) {
exportPhoto(
@@ -2080,7 +2107,7 @@ object GalleryManager {
photoId,
bitmap,
photoProcessor,
metadata,
updatedMetadata,
sharpeningValue,
noiseReductionValue,
chromaNoiseReductionValue,
@@ -2381,33 +2408,41 @@ object GalleryManager {
val photoDir = getPhotoDir(context, photoId, true)
val photoFile = File(photoDir, PHOTO_FILE)
val tempFile = File(photoDir, "temp.jpg")
var updatedMetadata: MediaMetadata = metadata
val rawResult = RawDemosaicProcessor.getInstance().processForHdrSources(
context,
dngFile.absolutePath,
aspectRatio = aspectRatio,
cropRegion = metadata.cropRegion,
cropRegion = updatedMetadata.cropRegion,
rotation = rotation,
exposureBias = exposureBias ?: 0f,
rawExposureCompensation = metadata.rawExposureCompensation ?: 0f,
rawAutoExposure = resolveRawAutoExposure(context, metadata),
rawBlackPointCorrection = metadata.rawBlackPointCorrection ?: 0f,
rawWhitePointCorrection = metadata.rawWhitePointCorrection ?: 0f,
rawAutoWhiteBalanceEstimate = resolveRawAutoWhiteBalanceEstimate(context, metadata),
rawExposureCompensation = updatedMetadata.rawExposureCompensation ?: 0f,
rawAutoExposure = resolveRawAutoExposure(context, updatedMetadata),
rawHighlightsAdjustment = updatedMetadata.rawHighlightsAdjustment ?: 0f,
rawShadowsAdjustment = updatedMetadata.rawShadowsAdjustment ?: 0f,
rawBlackPointCorrection = updatedMetadata.rawBlackPointCorrection ?: 0f,
rawWhitePointCorrection = updatedMetadata.rawWhitePointCorrection ?: 0f,
rawAutoWhiteBalanceEstimate = resolveRawAutoWhiteBalanceEstimate(context, updatedMetadata),
sharpeningValue = 0.4f,
denoiseValue = metadata.rawDenoiseValue,
rawDcpId = metadata.rawDcpId,
spectralFilmEnabled = metadata.spectralFilmEnabled,
spectralFilmStock = metadata.spectralFilmStock,
spectralFilmPrint = metadata.spectralFilmPrint,
denoiseValue = updatedMetadata.rawDenoiseValue,
rawDcpId = updatedMetadata.rawDcpId,
spectralFilmEnabled = updatedMetadata.spectralFilmEnabled,
spectralFilmStock = updatedMetadata.spectralFilmStock,
spectralFilmPrint = updatedMetadata.spectralFilmPrint,
spectralFilmTuning = SpectralFilmTuning(
cDensityGain = metadata.spectralFilmCDensityGain,
mDensityGain = metadata.spectralFilmMDensityGain,
yDensityGain = metadata.spectralFilmYDensityGain
)
cDensityGain = updatedMetadata.spectralFilmCDensityGain,
mDensityGain = updatedMetadata.spectralFilmMDensityGain,
yDensityGain = updatedMetadata.spectralFilmYDensityGain
),
onRawAutoAdjustments = { adjustments ->
updatedMetadata = updatedMetadata.withRawAutoAdjustments(adjustments)
}
) ?: return
var bitmap = rawResult.sdrBitmap
if (metadata.isMirrored) {
saveMetadata(context, photoId, updatedMetadata)
if (updatedMetadata.isMirrored) {
bitmap = BitmapUtils.flipHorizontal(bitmap)
}
@@ -2415,14 +2450,14 @@ object GalleryManager {
writeFinalJpeg(bitmap, outputStream, photoQuality)
}
tempFile.renameTo(photoFile)
generateBokehPhoto(context, photoId, metadata, bitmap)
generateBokehPhoto(context, photoId, updatedMetadata, bitmap)
val preparedUltraHdrSource = if (metadata.manualHdrEffectEnabled) {
val preparedUltraHdrSource = if (updatedMetadata.manualHdrEffectEnabled) {
photoProcessor.prepareUltraHdrSourceFromRawResult(
context = context,
photoId = photoId,
rawResult = rawResult,
metadata = metadata,
metadata = updatedMetadata,
sharpening = sharpeningValue,
noiseReduction = noiseReductionValue,
chromaNoiseReduction = chromaNoiseReductionValue,
@@ -2434,7 +2469,7 @@ object GalleryManager {
val preparedGainmapResult = preparedUltraHdrSource?.let { source ->
var result: GainmapResult? = null
val gainmapElapsed = measureTimeMillis {
result = gainmapProducer.build(source, HdrGainmapStrength.coerce(metadata.hdrEffectStrength))
result = gainmapProducer.build(source, HdrGainmapStrength.coerce(updatedMetadata.hdrEffectStrength))
}
PLog.d(TAG, "renderRawDngPhotoOutputs prepared gainmap for reuse, took=${gainmapElapsed}ms")
result
@@ -2444,7 +2479,7 @@ object GalleryManager {
buildDetailHdrCache(
context = context,
photoId = photoId,
metadata = metadata,
metadata = updatedMetadata,
sharpening = sharpeningValue,
noiseReduction = noiseReductionValue,
chromaNoiseReduction = chromaNoiseReductionValue,
@@ -2453,14 +2488,14 @@ object GalleryManager {
)
}
updateThumbnail(context, photoId, photoProcessor, metadata, bitmap)
updateThumbnail(context, photoId, photoProcessor, updatedMetadata, bitmap)
if (shouldAutoSave) {
exportPhoto(
context,
photoId,
bitmap,
photoProcessor,
metadata,
updatedMetadata,
sharpeningValue,
noiseReductionValue,
chromaNoiseReductionValue,
@@ -3360,12 +3395,14 @@ object GalleryManager {
}
// 3. 处理 RAW 以生成 JPEG 预览
var updatedMetadata = metadata
var updatedMetadata: MediaMetadata = metadata
val processedBitmap = RawDemosaicProcessor.getInstance().process(
context,
dngFile.absolutePath, null, null, 0,
rawExposureCompensation = updatedMetadata.rawExposureCompensation ?: 0f,
rawAutoExposure = resolveRawAutoExposure(context, updatedMetadata),
rawHighlightsAdjustment = updatedMetadata.rawHighlightsAdjustment ?: 0f,
rawShadowsAdjustment = updatedMetadata.rawShadowsAdjustment ?: 0f,
rawBlackPointCorrection = updatedMetadata.rawBlackPointCorrection ?: 0f,
rawWhitePointCorrection = updatedMetadata.rawWhitePointCorrection ?: 0f,
rawAutoWhiteBalanceEstimate = resolveRawAutoWhiteBalanceEstimate(context, updatedMetadata),
@@ -3382,6 +3419,9 @@ object GalleryManager {
),
onMetadata = { raw ->
updatedMetadata = updatedMetadata.merge(raw)
},
onRawAutoAdjustments = { adjustments ->
updatedMetadata = updatedMetadata.withRawAutoAdjustments(adjustments)
}
)
@@ -3509,6 +3549,8 @@ object GalleryManager {
dngFile.absolutePath, metadata?.ratio, metadata?.cropRegion, 0,
rawExposureCompensation = updatedMetadata?.rawExposureCompensation ?: 0f,
rawAutoExposure = resolveRawAutoExposure(context, updatedMetadata),
rawHighlightsAdjustment = updatedMetadata?.rawHighlightsAdjustment ?: 0f,
rawShadowsAdjustment = updatedMetadata?.rawShadowsAdjustment ?: 0f,
rawBlackPointCorrection = updatedMetadata?.rawBlackPointCorrection ?: 0f,
rawWhitePointCorrection = updatedMetadata?.rawWhitePointCorrection ?: 0f,
rawAutoWhiteBalanceEstimate = resolveRawAutoWhiteBalanceEstimate(context, updatedMetadata),
@@ -3525,6 +3567,9 @@ object GalleryManager {
),
onMetadata = { raw ->
updatedMetadata = updatedMetadata?.merge(raw) ?: MediaMetadata().merge(raw)
},
onRawAutoAdjustments = { adjustments ->
updatedMetadata = (updatedMetadata ?: MediaMetadata()).withRawAutoAdjustments(adjustments)
}
)
@@ -24,7 +24,7 @@ import kotlin.math.log2
* 保存 LUT、边框水印、编辑信息和拍摄参数,用于非破坏性编辑和边框水印渲染
*/
data class MediaMetadata(
val version: Int = 16,
val version: Int = 17,
val mediaType: MediaType = MediaType.IMAGE,
// 编辑配置
val lutId: String? = null,
@@ -40,6 +40,8 @@ data class MediaMetadata(
val rawDenoiseValue: Float? = null,
val rawExposureCompensation: Float? = null,
val rawAutoExposure: Boolean? = null,
val rawHighlightsAdjustment: Float? = null,
val rawShadowsAdjustment: Float? = null,
val rawBlackPointCorrection: Float? = null,
val rawWhitePointCorrection: Float? = null,
val rawAutoWhiteBalanceEstimate: Boolean? = null,
@@ -257,6 +259,8 @@ data class MediaMetadata(
rawDenoiseValue = if (obj.isNull("denoiseValue")) null else obj.optDouble("denoiseValue").toFloat(),
rawExposureCompensation = if (obj.isNull("rawExposureCompensation")) null else obj.optDouble("rawExposureCompensation").toFloat(),
rawAutoExposure = if (obj.isNull("rawAutoExposure")) null else obj.optBoolean("rawAutoExposure"),
rawHighlightsAdjustment = if (obj.isNull("rawHighlightsAdjustment")) null else obj.optDouble("rawHighlightsAdjustment").toFloat(),
rawShadowsAdjustment = if (obj.isNull("rawShadowsAdjustment")) null else obj.optDouble("rawShadowsAdjustment").toFloat(),
rawBlackPointCorrection = if (obj.isNull("rawBlackPointCorrection")) null else obj.optDouble("rawBlackPointCorrection").toFloat(),
rawWhitePointCorrection = if (obj.isNull("rawWhitePointCorrection")) null else obj.optDouble("rawWhitePointCorrection").toFloat(),
rawAutoWhiteBalanceEstimate = if (obj.isNull("rawAutoWhiteBalanceEstimate")) null else obj.optBoolean("rawAutoWhiteBalanceEstimate"),
@@ -452,6 +452,8 @@ class PhotoProcessor(
exposureBias = metadata.exposureBias ?: 0f,
rawExposureCompensation = metadata.rawExposureCompensation ?: 0f,
rawAutoExposure = resolveRawAutoExposure(metadata),
rawHighlightsAdjustment = metadata.rawHighlightsAdjustment ?: 0f,
rawShadowsAdjustment = metadata.rawShadowsAdjustment ?: 0f,
rawBlackPointCorrection = metadata.rawBlackPointCorrection ?: 0f,
rawWhitePointCorrection = metadata.rawWhitePointCorrection ?: 0f,
rawAutoWhiteBalanceEstimate = resolveRawAutoWhiteBalanceEstimate(metadata),
@@ -521,6 +523,8 @@ class PhotoProcessor(
metadata.exposureBias ?: 0f,
rawExposureCompensation = metadata.rawExposureCompensation ?: 0f,
rawAutoExposure = resolveRawAutoExposure(metadata),
rawHighlightsAdjustment = metadata.rawHighlightsAdjustment ?: 0f,
rawShadowsAdjustment = metadata.rawShadowsAdjustment ?: 0f,
rawBlackPointCorrection = metadata.rawBlackPointCorrection ?: 0f,
rawWhitePointCorrection = metadata.rawWhitePointCorrection ?: 0f,
rawAutoWhiteBalanceEstimate = resolveRawAutoWhiteBalanceEstimate(metadata),
@@ -7,7 +7,7 @@ import androidx.room.RoomDatabase
@Database(
entities = [GalleryMediaEntity::class],
version = 7,
version = 8,
exportSchema = false
)
@androidx.room.TypeConverters(GalleryConverters::class)
@@ -60,6 +60,13 @@ abstract class GalleryDatabase : RoomDatabase() {
}
}
private val MIGRATION_7_8 = object : androidx.room.migration.Migration(7, 8) {
override fun migrate(db: androidx.sqlite.db.SupportSQLiteDatabase) {
db.execSQL("ALTER TABLE gallery_media ADD COLUMN rawHighlightsAdjustment REAL")
db.execSQL("ALTER TABLE gallery_media ADD COLUMN rawShadowsAdjustment REAL")
}
}
fun getInstance(context: Context): GalleryDatabase {
return INSTANCE ?: synchronized(this) {
INSTANCE ?: Room.databaseBuilder(
@@ -73,7 +80,8 @@ abstract class GalleryDatabase : RoomDatabase() {
MIGRATION_3_4,
MIGRATION_4_5,
MIGRATION_5_6,
MIGRATION_6_7
MIGRATION_6_7,
MIGRATION_7_8
)
.build()
.also { INSTANCE = it }
@@ -45,6 +45,8 @@ data class GalleryMediaEntity(
val rawDenoiseValue: Float?,
val rawExposureCompensation: Float?,
val rawAutoExposure: Boolean?,
val rawHighlightsAdjustment: Float?,
val rawShadowsAdjustment: Float?,
val rawBlackPointCorrection: Float?,
val rawWhitePointCorrection: Float?,
val rawAutoWhiteBalanceEstimate: Boolean?,
@@ -199,6 +199,8 @@ object GalleryMediaStore {
rawDenoiseValue = metadata.rawDenoiseValue,
rawExposureCompensation = metadata.rawExposureCompensation,
rawAutoExposure = metadata.rawAutoExposure,
rawHighlightsAdjustment = metadata.rawHighlightsAdjustment,
rawShadowsAdjustment = metadata.rawShadowsAdjustment,
rawBlackPointCorrection = metadata.rawBlackPointCorrection,
rawWhitePointCorrection = metadata.rawWhitePointCorrection,
rawAutoWhiteBalanceEstimate = metadata.rawAutoWhiteBalanceEstimate,
@@ -338,6 +340,8 @@ object GalleryMediaStore {
rawDenoiseValue = rawDenoiseValue,
rawExposureCompensation = rawExposureCompensation,
rawAutoExposure = rawAutoExposure,
rawHighlightsAdjustment = rawHighlightsAdjustment,
rawShadowsAdjustment = rawShadowsAdjustment,
rawBlackPointCorrection = rawBlackPointCorrection,
rawWhitePointCorrection = rawWhitePointCorrection,
rawAutoWhiteBalanceEstimate = rawAutoWhiteBalanceEstimate,
@@ -5,6 +5,7 @@ import android.util.Half
import com.hinnka.mycamera.utils.PLog
import java.nio.ByteBuffer
import java.nio.ShortBuffer
import kotlin.math.abs
import kotlin.math.exp
import kotlin.math.ln
import kotlin.math.pow
@@ -26,27 +27,35 @@ object MeteringSystem {
private const val LUMA_FLOOR = 0.001f
private const val MAX_LINEAR_LUMA = 16.0f
private const val MIN_DEPTH_SEPARATION = 0.08f
private const val RAW_CURVE_NEUTRAL_WHITE_POINT = 1.0f
private const val AUTO_DEVELOP_EPSILON = 0.0001f
private const val AUTO_CLIP_FRACTION = 0.0002f
private const val RAW_AUTO_HIGHLIGHT_LIMIT = 0.85f
private const val RAW_AUTO_SHADOW_LIMIT = 0.65f
private const val RAW_AUTO_HIGHLIGHT_RATIO_START = 0.02f
private const val RAW_AUTO_HIGHLIGHT_RATIO_FULL = 0.30f
private const val RAW_AUTO_SHADOW_GAP_DEAD_ZONE_EV = 0.45f
private const val RAW_AUTO_SHADOW_GAP_FULL_EV = 2.4f
private const val RAW_AUTO_DEEP_SHADOW_GAP_DEAD_ZONE_EV = 1.5f
private const val RAW_AUTO_DEEP_SHADOW_GAP_FULL_EV = 3.6f
data class MeteringResult(
val meteredEv: Float,
val dynamicRangeGap: Float,
val avgLuma: Float,
val p05: Float,
val p50: Float,
val p95: Float,
val p99: Float,
val p998: Float
val clipLow: Float,
val clipHigh: Float,
val highlights: Float,
val shadows: Float,
val curveWhitePoint: Float
) {
fun scaleLuma(scale: Float): MeteringResult {
val safeScale = if (scale.isFinite() && scale > 0f) scale else 1f
return copy(
avgLuma = (avgLuma * safeScale).coerceIn(0f, MAX_LINEAR_LUMA),
p05 = (p05 * safeScale).coerceIn(0f, MAX_LINEAR_LUMA),
p50 = (p50 * safeScale).coerceIn(0f, MAX_LINEAR_LUMA),
p95 = (p95 * safeScale).coerceIn(0f, MAX_LINEAR_LUMA),
p99 = (p99 * safeScale).coerceIn(0f, MAX_LINEAR_LUMA),
p998 = (p998 * safeScale).coerceIn(0f, MAX_LINEAR_LUMA)
clipLow = (clipLow * safeScale).coerceIn(0f, MAX_LINEAR_LUMA),
clipHigh = (clipHigh * safeScale).coerceIn(0f, MAX_LINEAR_LUMA)
)
}
@@ -55,11 +64,25 @@ object MeteringSystem {
meteredEv = 0f,
dynamicRangeGap = 0f,
avgLuma = 0f,
p05 = 0f,
p50 = 0f,
p95 = 0f,
p99 = 0f,
p998 = 0f
clipLow = 0f,
clipHigh = 0f,
highlights = 0f,
shadows = 0f,
curveWhitePoint = 0f
)
}
}
data class ShadowsHighlightsParams(
val highlights: Float,
val shadows: Float,
val curveWhitePoint: Float,
) {
companion object {
val NEUTRAL = ShadowsHighlightsParams(
highlights = 0f,
shadows = 0f,
curveWhitePoint = RAW_CURVE_NEUTRAL_WHITE_POINT,
)
}
}
@@ -94,6 +117,8 @@ object MeteringSystem {
val weight: Float
)
@SuppressLint("HalfFloat")
fun analyzeLinearHalfFloatExposureEv(
pixelBuffer: ShortBuffer,
@@ -118,6 +143,31 @@ object MeteringSystem {
}
}
fun hasManualRawDevelopAdjustments(
rawExposureCompensation: Float,
rawHighlightsAdjustment: Float,
rawShadowsAdjustment: Float
): Boolean {
return abs(rawExposureCompensation) > AUTO_DEVELOP_EPSILON ||
abs(rawHighlightsAdjustment) > AUTO_DEVELOP_EPSILON ||
abs(rawShadowsAdjustment) > AUTO_DEVELOP_EPSILON
}
fun resolveManualShadowsHighlightsParams(
rawHighlightsAdjustment: Float,
rawShadowsAdjustment: Float
): ShadowsHighlightsParams {
val highlights = rawHighlightsAdjustment.coerceIn(-1f, 1f)
val shadows = rawShadowsAdjustment.coerceIn(-1f, 1f)
if (abs(highlights) <= AUTO_DEVELOP_EPSILON && abs(shadows) <= AUTO_DEVELOP_EPSILON) {
return ShadowsHighlightsParams.NEUTRAL
}
return ShadowsHighlightsParams.NEUTRAL.copy(
highlights = highlights,
shadows = shadows
)
}
private inline fun analyzeExposureEv(
width: Int,
height: Int,
@@ -156,43 +206,49 @@ object MeteringSystem {
val midToneLuma = midToneReference.luma
lumas.sort()
val clipLow = percentile(lumas, AUTO_CLIP_FRACTION)
val p05 = percentile(lumas, 0.05f)
val p50 = percentile(lumas, 0.50f)
val p95 = percentile(lumas, 0.95f)
val p25 = percentile(lumas, 0.25f)
val p75 = percentile(lumas, 0.75f)
val p99 = percentile(lumas, 0.99f)
val p998 = percentile(lumas, 0.998f)
val clipHigh = percentile(lumas, 1f - AUTO_CLIP_FRACTION)
val highlightAnchorGain = 1f //linearExposureGain / p998.coerceAtLeast(0.01f)
val avgLuma = midToneLuma
val highlightAnchorGain = maxOf(linearExposureGain, clipHigh) / clipHigh.coerceAtLeast(0.01f)
val midToneGain = targetLuma / midToneLuma.coerceAtLeast(LUMA_FLOOR)
val dynamicRangeGap = midToneGain / highlightAnchorGain
val dynamicRangeGap = evDifference(clipHigh, clipLow)
val extra = smoothStep(0.66f, 2.2f, dynamicRangeGap)
val adaptiveGain = lerp(midToneGain * 1.2f, highlightAnchorGain * 1.2f, extra)
val extra = smoothStep(4f, 12f, dynamicRangeGap)
val adaptiveGain = lerp(midToneGain * 1.2f, highlightAnchorGain, extra)
val rawMeteredEv = log2(adaptiveGain.coerceIn(0.25f, 4.0f))
val highlights = 0f
val shadows = 0f
// Curve points
val curveWhitePoint = if (clipHigh > 1f) {
clipHigh.coerceIn(1.05f, 4.0f)
} else {
RAW_CURVE_NEUTRAL_WHITE_POINT
}
PLog.d(
TAG,
"$tag: p05=$p05 p50=$p50 p95=$p95 p99=$p99 p998=$p998 " +
"$tag: clipLow=$clipLow clipHigh=$clipHigh " +
"p05=$p05 p25=$p25 p75=$p75 p99=$p99 " +
"target=$targetLuma midToneLuma=$midToneLuma " +
"midToneZoneMedianLuma=${midToneReference.zoneMedianLuma} " +
"midToneBucketMedianLuma=${midToneReference.bucketMedianLuma} " +
"midToneZones=${midToneReference.retainedZoneCount} midToneBuckets=${midToneReference.retainedBucketCount} " +
"midToneGain=$midToneGain highlightAnchorGain=$highlightAnchorGain gain=$adaptiveGain " +
"ev=$rawMeteredEv gap=$dynamicRangeGap " +
"depth=${depthWeights?.enabled == true} depthSeparation=${depthWeights?.separation ?: 0f} " +
"sanitized=$sanitizedSampleCount"
"ev=$rawMeteredEv gap=$dynamicRangeGap "
)
return MeteringResult(
meteredEv = rawMeteredEv.coerceIn(-2f, 2f),
dynamicRangeGap = dynamicRangeGap,
avgLuma = avgLuma,
p05 = p05,
p50 = p50,
p95 = p95,
p99 = p99,
p998 = p998
avgLuma = midToneLuma,
clipLow = clipLow,
clipHigh = clipHigh,
highlights = highlights,
shadows = shadows,
curveWhitePoint = curveWhitePoint
)
}
@@ -595,6 +651,40 @@ object MeteringSystem {
}
}
private fun calculateHighlightRatio(sortedLumas: FloatArray, avgLuma: Float): Float {
if (sortedLumas.isEmpty()) {
return 0f
}
var weightedHighlightCount = 0.0
for (luma in sortedLumas) {
if (luma > avgLuma * 2.22f) {
weightedHighlightCount += 1
}
}
return (weightedHighlightCount / sortedLumas.size).toFloat().coerceIn(0f, 1f)
}
private fun calculateAutoHighlightCompression(highlightRatio: Float): Float {
return (
smoothStep(
RAW_AUTO_HIGHLIGHT_RATIO_START,
RAW_AUTO_HIGHLIGHT_RATIO_FULL,
highlightRatio.coerceIn(0f, 1f)
) * RAW_AUTO_HIGHLIGHT_LIMIT
).coerceIn(0f, RAW_AUTO_HIGHLIGHT_LIMIT)
}
private fun calculateAutoShadowLift(
shadowGapEv: Float,
deepShadowGapEv: Float
): Float {
val shadowLift = smoothStep(0f, RAW_AUTO_SHADOW_GAP_FULL_EV, shadowGapEv) * 0.42f
val deepShadowLift = smoothStep(0f, RAW_AUTO_DEEP_SHADOW_GAP_FULL_EV, deepShadowGapEv) * 0.23f
return (shadowLift + deepShadowLift).coerceIn(0f, RAW_AUTO_SHADOW_LIMIT)
}
private fun percentile(sortedValues: FloatArray, percentile: Float): Float {
if (sortedValues.isEmpty()) {
return 0f
@@ -604,6 +694,12 @@ object MeteringSystem {
return sortedValues[index]
}
private fun evDifference(brighter: Float, darker: Float): Float {
val safeBrighter = sanitizeLinearLuma(brighter).coerceAtLeast(LUMA_FLOOR)
val safeDarker = sanitizeLinearLuma(darker).coerceAtLeast(1e-5f)
return log2(safeBrighter / safeDarker)
}
private fun log2(value: Float): Float {
return (ln(value.toDouble()) / ln(2.0)).toFloat()
}
@@ -5,14 +5,21 @@ import android.content.Context
import android.graphics.Bitmap
import android.graphics.Rect
import android.media.Image
import android.opengl.*
import android.opengl.EGL14
import android.opengl.EGLConfig
import android.opengl.EGLContext
import android.opengl.EGLDisplay
import android.opengl.EGLSurface
import android.opengl.GLES30
import android.opengl.GLES31
import android.util.Half
import androidx.core.graphics.createBitmap
import com.hinnka.mycamera.camera.AspectRatio
import com.hinnka.mycamera.data.ContentRepository
import com.hinnka.mycamera.lut.ShadowsHighlightsShader
import com.hinnka.mycamera.lut.ChromaDenoiseShaders
import com.hinnka.mycamera.lut.ShadowsHighlightsShader
import com.hinnka.mycamera.ml.SharedDepthEstimator
import com.hinnka.mycamera.raw.MeteringSystem.ShadowsHighlightsParams
import com.hinnka.mycamera.utils.BitmapUtils
import com.hinnka.mycamera.utils.LargeDirectBuffer
import com.hinnka.mycamera.utils.PLog
@@ -33,6 +40,8 @@ import kotlin.math.pow
import kotlin.math.sqrt
import android.opengl.Matrix as GlMatrix
private typealias ShadowsHighlightsParams = MeteringSystem.ShadowsHighlightsParams
/**
* RAW 图像解马赛克处理器
*
@@ -49,22 +58,6 @@ import android.opengl.Matrix as GlMatrix
*/
class RawDemosaicProcessor {
private data class ShadowsHighlightsParams(
val highlights: Float,
val shadows: Float,
val curveWhitePoint: Float,
val curveShoulderStart: Float
) {
companion object {
val NEUTRAL = ShadowsHighlightsParams(
highlights = 0f,
shadows = 0f,
curveWhitePoint = 1f,
curveShoulderStart = 0.78f
)
}
}
/**
* DNG 数据容器(包含原始 DngRawData 用于清理)
*/
@@ -307,6 +300,12 @@ class RawDemosaicProcessor {
val curveLut: FloatArray? = null
)
data class RawAutoAdjustments(
val exposureCompensation: Float,
val highlights: Float,
val shadows: Float
)
private fun SceneStats.toRenderPlan(): RawRenderPlan {
return RawRenderPlan(
sceneNormalizationGain = exposureGain,
@@ -343,6 +342,8 @@ class RawDemosaicProcessor {
exposureBias: Float = 0f,
rawExposureCompensation: Float = 0f,
rawAutoExposure: Boolean = true,
rawHighlightsAdjustment: Float = 0f,
rawShadowsAdjustment: Float = 0f,
rawBlackPointCorrection: Float = 0f,
rawWhitePointCorrection: Float = 0f,
rawAutoWhiteBalanceEstimate: Boolean = false,
@@ -354,6 +355,7 @@ class RawDemosaicProcessor {
spectralFilmStock: String? = null,
spectralFilmPrint: String? = null,
spectralFilmTuning: SpectralFilmTuning = SpectralFilmTuning.DEFAULT,
onRawAutoAdjustments: ((RawAutoAdjustments) -> Unit)? = null,
onMetadata: ((RawMetadata) -> Unit)? = null
): Bitmap? = withContext(glDispatcher) {
val dngFile = File(dngFilePath)
@@ -371,6 +373,8 @@ class RawDemosaicProcessor {
exposureBias = exposureBias,
rawExposureCompensation = rawExposureCompensation,
rawAutoExposure = rawAutoExposure,
rawHighlightsAdjustment = rawHighlightsAdjustment,
rawShadowsAdjustment = rawShadowsAdjustment,
rawBlackPointCorrection = rawBlackPointCorrection,
rawWhitePointCorrection = rawWhitePointCorrection,
rawAutoWhiteBalanceEstimate = rawAutoWhiteBalanceEstimate,
@@ -383,6 +387,7 @@ class RawDemosaicProcessor {
spectralFilmPrint = spectralFilmPrint,
spectralFilmTuning = spectralFilmTuning,
dngFile = dngFile,
onRawAutoAdjustments = onRawAutoAdjustments,
onMetadata = onMetadata
)?.sdrBitmap
} catch (e: Exception) {
@@ -406,6 +411,8 @@ class RawDemosaicProcessor {
rotation: Int,
rawExposureCompensation: Float = 0f,
rawAutoExposure: Boolean = true,
rawHighlightsAdjustment: Float = 0f,
rawShadowsAdjustment: Float = 0f,
rawBlackPointCorrection: Float = 0f,
rawWhitePointCorrection: Float = 0f,
rawAutoWhiteBalanceEstimate: Boolean = false,
@@ -439,6 +446,8 @@ class RawDemosaicProcessor {
rotation = rotation,
rawExposureCompensation = rawExposureCompensation,
rawAutoExposure = rawAutoExposure,
rawHighlightsAdjustment = rawHighlightsAdjustment,
rawShadowsAdjustment = rawShadowsAdjustment,
rawBlackPointCorrection = rawBlackPointCorrection,
rawWhitePointCorrection = rawWhitePointCorrection,
rawAutoWhiteBalanceEstimate = rawAutoWhiteBalanceEstimate,
@@ -467,6 +476,8 @@ class RawDemosaicProcessor {
exposureBias: Float = 0f,
rawExposureCompensation: Float = 0f,
rawAutoExposure: Boolean = true,
rawHighlightsAdjustment: Float = 0f,
rawShadowsAdjustment: Float = 0f,
rawBlackPointCorrection: Float = 0f,
rawWhitePointCorrection: Float = 0f,
rawAutoWhiteBalanceEstimate: Boolean = false,
@@ -478,6 +489,7 @@ class RawDemosaicProcessor {
spectralFilmStock: String? = null,
spectralFilmPrint: String? = null,
spectralFilmTuning: SpectralFilmTuning = SpectralFilmTuning.DEFAULT,
onRawAutoAdjustments: ((RawAutoAdjustments) -> Unit)? = null,
onMetadata: ((RawMetadata) -> Unit)? = null
): RawHdrRenderResult? = withContext(glDispatcher) {
val dngFile = File(dngFilePath)
@@ -495,6 +507,8 @@ class RawDemosaicProcessor {
exposureBias = exposureBias,
rawExposureCompensation = rawExposureCompensation,
rawAutoExposure = rawAutoExposure,
rawHighlightsAdjustment = rawHighlightsAdjustment,
rawShadowsAdjustment = rawShadowsAdjustment,
rawBlackPointCorrection = rawBlackPointCorrection,
rawWhitePointCorrection = rawWhitePointCorrection,
rawAutoWhiteBalanceEstimate = rawAutoWhiteBalanceEstimate,
@@ -507,6 +521,7 @@ class RawDemosaicProcessor {
spectralFilmPrint = spectralFilmPrint,
spectralFilmTuning = spectralFilmTuning,
dngFile = dngFile,
onRawAutoAdjustments = onRawAutoAdjustments,
onMetadata = onMetadata,
includeHdrReference = true
)
@@ -532,6 +547,8 @@ class RawDemosaicProcessor {
exposureBias: Float = 0f,
rawExposureCompensation: Float = 0f,
rawAutoExposure: Boolean = true,
rawHighlightsAdjustment: Float = 0f,
rawShadowsAdjustment: Float = 0f,
rawBlackPointCorrection: Float = 0f,
rawWhitePointCorrection: Float = 0f,
rawAutoWhiteBalanceEstimate: Boolean = false,
@@ -545,6 +562,7 @@ class RawDemosaicProcessor {
spectralFilmPrint: String? = null,
spectralFilmTuning: SpectralFilmTuning = SpectralFilmTuning.DEFAULT,
dngFile: File? = null,
onRawAutoAdjustments: ((RawAutoAdjustments) -> Unit)? = null,
onMetadata: ((RawMetadata) -> Unit)? = null,
includeHdrReference: Boolean = false
): RawHdrRenderResult? = withContext(glDispatcher) {
@@ -662,8 +680,6 @@ class RawDemosaicProcessor {
// GPU 已消费 rawData,立即释放 CPU 侧引用,帮助 GC 回收(超分时约 288 MB)
actualRawData = null
var effectiveExposureCompensation = rawExposureCompensation
// Bayer RCD Compute Shader 处理路径 (1:1 直接映射自 darktable RCD)
val ssboIds = IntArray(9)
GLES31.glGenBuffers(9, ssboIds, 0)
@@ -932,13 +948,42 @@ class RawDemosaicProcessor {
useDepthWeighting = rawAutoExposure
)
if (rawAutoExposure) {
val autoExposureEv = meteringResult.meteredEv
effectiveExposureCompensation += autoExposureEv
}
val shadowsHighlightsParams = resolveShadowsHighlightsParams(
meteringResult = meteringResult.scaleLuma(2.0f.pow(effectiveExposureCompensation))
val useAutoDevelopAdjustments = rawAutoExposure && !MeteringSystem.hasManualRawDevelopAdjustments(
rawExposureCompensation = rawExposureCompensation,
rawHighlightsAdjustment = rawHighlightsAdjustment,
rawShadowsAdjustment = rawShadowsAdjustment
)
val effectiveExposureCompensation = if (useAutoDevelopAdjustments) {
meteringResult.meteredEv
} else {
rawExposureCompensation
}
val shadowsHighlightsParams = if (useAutoDevelopAdjustments) {
ShadowsHighlightsParams(
highlights = meteringResult.highlights,
shadows = meteringResult.shadows,
curveWhitePoint = meteringResult.curveWhitePoint
)
} else {
MeteringSystem.resolveManualShadowsHighlightsParams(
rawHighlightsAdjustment = rawHighlightsAdjustment,
rawShadowsAdjustment = rawShadowsAdjustment
)
}
if (useAutoDevelopAdjustments) {
RawAutoAdjustments(
exposureCompensation = effectiveExposureCompensation.coerceIn(-2f, 2f),
highlights = shadowsHighlightsParams.highlights,
shadows = shadowsHighlightsParams.shadows
).also { adjustments ->
PLog.d(
TAG,
"RAW auto develop sliders: exposure=${adjustments.exposureCompensation} " +
"highlights=${adjustments.highlights} shadows=${adjustments.shadows}"
)
onRawAutoAdjustments?.invoke(adjustments)
}
}
// 运行 linearRcdProgram 将 CCM & Exposure 应用在已解马赛克的浮点 RCD 图像上
checkGlError("Before LinearRcdPass")
@@ -3322,7 +3367,7 @@ class RawDemosaicProcessor {
"RAW Shadows/Highlights uniforms: " +
"uHighlightsLoc=$highlightsLocation uShadowsLoc=$shadowsLocation " +
"highlights=${params.highlights} shadows=${params.shadows} " +
"curveWhitePoint=${params.curveWhitePoint} curveShoulderStart=${params.curveShoulderStart}"
"curveWhitePoint=${params.curveWhitePoint}"
)
}
GLES30.glUniform1f(
@@ -3331,7 +3376,7 @@ class RawDemosaicProcessor {
)
GLES30.glUniform1f(
GLES30.glGetUniformLocation(combinedProgram, "uCurveShoulderStart"),
params.curveShoulderStart
0.4f
)
}
@@ -3542,97 +3587,6 @@ class RawDemosaicProcessor {
return normalizationGain * 2.0f.pow(rawExposureCompensation + dcpBaselineExposureOffset)
}
private fun resolveShadowsHighlightsParams(
meteringResult: MeteringSystem.MeteringResult
): ShadowsHighlightsParams {
if (meteringResult.p50 <= 0f || meteringResult.p998 <= 0f) {
return ShadowsHighlightsParams.NEUTRAL
}
val p05 = sanitizeToneLuma(meteringResult.p05)
val p50 = sanitizeToneLuma(meteringResult.p50).coerceAtLeast(p05 + 1e-4f)
val p95 = sanitizeToneLuma(meteringResult.p95).coerceAtLeast(p50 + 1e-4f)
val p99 = sanitizeToneLuma(meteringResult.p99).coerceAtLeast(p95 + 1e-4f)
val p998 = sanitizeToneLuma(meteringResult.p998).coerceAtLeast(p99 + 1e-4f)
val l05 = labLightnessSignal(p05)
val l50 = labLightnessSignal(p50).coerceAtLeast(l05 + 1e-4f)
val l95 = labLightnessSignal(p95).coerceAtLeast(l50 + 1e-4f)
val l99 = labLightnessSignal(p99).coerceAtLeast(l95 + 1e-4f)
val l998 = labLightnessSignal(p998).coerceAtLeast(l99 + 1e-4f)
val shadowTailRatio = (1f - l05 / l50.coerceAtLeast(1e-4f)).coerceIn(0f, 1f)
val shadowVisibility = smoothStep(0.035f, 0.16f, l50)
val lowKeyProtection = smoothStep(0.55f, 0.85f, l95)
val midtoneDeficit = (1f - smoothStep(0.20f, 0.42f, l50)).coerceIn(0f, 1f)
val shadowScale = 0.08f + 0.10f * lowKeyProtection
val highlightBodyPressure = smoothStep(0.72f, 0.92f, l95) * 0.65f
val highlightTailPressure = smoothStep(0.95f, 1.10f, l99)
val highlightPressure = max(highlightBodyPressure, highlightTailPressure)
val highlightTailSpread = smoothStep(0.04f, 0.16f, l998 - l95)
val highlightStrength = (highlightPressure * (0.45f + 0.55f * highlightTailSpread))
.coerceIn(0f, 0.95f)
val highlights = -highlightStrength
val highlightSuppression = 1f - highlightPressure * 0.78f
val shadows = (shadowTailRatio * shadowVisibility * midtoneDeficit * shadowScale * highlightSuppression)
.coerceIn(0f, 0.22f)
val curveWhitePoint = if (p99 > 1f || p998 > 1.05f) {
p998.coerceIn(1.05f, 4.0f)
} else {
1f
}
val curveShoulderStart = (0.78f - highlightPressure * 0.20f).coerceIn(0.56f, 0.82f)
val params = ShadowsHighlightsParams(
highlights = highlights,
shadows = shadows,
curveWhitePoint = curveWhitePoint,
curveShoulderStart = curveShoulderStart
)
PLog.d(
TAG,
"Histogram Shadows/Highlights: p05=$p05 p50=$p50 p95=$p95 p99=$p99 p998=$p998 " +
"labL=[$l05,$l50,$l95,$l99,$l998] " +
"shadowTail=$shadowTailRatio shadowVisibility=$shadowVisibility " +
"lowKeyProtection=$lowKeyProtection midtoneDeficit=$midtoneDeficit " +
"highlightPressure=$highlightPressure highlightSuppression=$highlightSuppression " +
"rawHighlightStrength=$highlightStrength sharedLocalTone=true " +
"curveWhitePoint=$curveWhitePoint curveShoulderStart=$curveShoulderStart " +
"sliders highlights=$highlights shadows=$shadows"
)
return params
}
private fun labLightnessSignal(luma: Float): Float {
val safeLuma = sanitizeToneLuma(luma)
val epsilon = 216f / 24389f
val kappa = 24389f / 27f
val fy = if (safeLuma > epsilon) {
safeLuma.pow(1f / 3f)
} else {
(kappa * safeLuma + 16f) / 116f
}
return ((116f * fy - 16f) / 100f).coerceAtLeast(0f)
}
private fun sanitizeToneLuma(value: Float): Float {
return if (value.isFinite() && value > 0f) {
value.coerceAtMost(16f)
} else {
0f
}
}
private fun smoothStep(edge0: Float, edge1: Float, x: Float): Float {
val width = edge1 - edge0
if (!edge0.isFinite() || !edge1.isFinite() || !x.isFinite() || abs(width) < 1e-6f) {
return if (x >= edge1) 1f else 0f
}
val t = ((x - edge0) / width).coerceIn(0f, 1f)
return t * t * (3f - 2f * t)
}
private fun renderLinearRcdPass(
metadata: RawMetadata,
sourceTextureId: Int,
@@ -467,7 +467,7 @@ object RawShaders {
void main() {
vec3 color = texture(uInputTexture, vTexCoord).rgb;
color = applyDcpMaps(color);
// color = highlightRolloff(color);
color = highlightRolloff(color);
color = applyDisplayTone(color);
color = uOutputTransform * color;
color = applyShadowsHighlights(color, vTexCoord);
@@ -197,6 +197,8 @@ fun CameraScreen(
val rawNlmNoiseFactor by viewModel.rawNlmNoiseFactor.collectAsState()
val rawExposureCompensation by viewModel.rawExposureCompensation.collectAsState()
val rawAutoExposure by viewModel.rawAutoExposure.collectAsState()
val rawHighlightsAdjustment by viewModel.rawHighlightsAdjustment.collectAsState()
val rawShadowsAdjustment by viewModel.rawShadowsAdjustment.collectAsState()
val rawBlackPointCorrection by viewModel.rawBlackPointCorrection.collectAsState()
val rawWhitePointCorrection by viewModel.rawWhitePointCorrection.collectAsState()
val droMode by viewModel.droMode.collectAsState()
@@ -1305,6 +1307,8 @@ fun CameraScreen(
rawNlmNoiseFactor = rawNlmNoiseFactor,
rawExposureCompensation = rawExposureCompensation,
rawAutoExposure = rawAutoExposure,
rawHighlightsAdjustment = rawHighlightsAdjustment,
rawShadowsAdjustment = rawShadowsAdjustment,
rawDROMode = droMode,
rawBlackPointCorrection = rawBlackPointCorrection,
rawWhitePointCorrection = rawWhitePointCorrection,
@@ -73,6 +73,8 @@ fun CameraTopSheet(
rawNlmNoiseFactor: Float,
rawExposureCompensation: Float,
rawAutoExposure: Boolean,
rawHighlightsAdjustment: Float,
rawShadowsAdjustment: Float,
rawDROMode: String,
rawBlackPointCorrection: Float,
rawWhitePointCorrection: Float,
@@ -500,6 +502,8 @@ fun CameraTopSheet(
rawNlmNoiseFactor = rawNlmNoiseFactor,
rawExposureCompensation = rawExposureCompensation,
rawAutoExposure = rawAutoExposure,
rawHighlightsAdjustment = rawHighlightsAdjustment,
rawShadowsAdjustment = rawShadowsAdjustment,
rawBlackPointCorrection = rawBlackPointCorrection,
rawWhitePointCorrection = rawWhitePointCorrection,
spectralFilmEnabled = rawSpectralFilmEnabled,
@@ -511,6 +515,8 @@ fun CameraTopSheet(
onRawNlmNoiseFactorChange = {},
onRawExposureCompensationChange = {},
onRawAutoExposureChange = {},
onRawHighlightsAdjustmentChange = {},
onRawShadowsAdjustmentChange = {},
onRawBlackPointCorrectionChange = {},
onRawWhitePointCorrectionChange = {},
onSpectralFilmEnabledChange = onRawSpectralFilmEnabledChange,
@@ -49,6 +49,8 @@ fun RawEditPanel(
rawNlmNoiseFactor: Float,
rawExposureCompensation: Float,
rawAutoExposure: Boolean,
rawHighlightsAdjustment: Float,
rawShadowsAdjustment: Float,
rawBlackPointCorrection: Float,
rawWhitePointCorrection: Float,
spectralFilmEnabled: Boolean,
@@ -60,6 +62,8 @@ fun RawEditPanel(
onRawNlmNoiseFactorChange: (Float) -> Unit,
onRawExposureCompensationChange: (Float) -> Unit,
onRawAutoExposureChange: (Boolean) -> Unit,
onRawHighlightsAdjustmentChange: (Float) -> Unit,
onRawShadowsAdjustmentChange: (Float) -> Unit,
onRawBlackPointCorrectionChange: (Float) -> Unit,
onRawWhitePointCorrectionChange: (Float) -> Unit,
onSpectralFilmEnabledChange: (Boolean) -> Unit,
@@ -200,6 +204,28 @@ fun RawEditPanel(
},
onValueChangeFinished = onAdjustmentEnd
)
SliderSettingItem(
title = stringResource(R.string.settings_raw_highlights_adjustment),
value = rawHighlightsAdjustment,
valueRange = -1f..1f,
resetValue = 0f,
onValueChange = {
onAdjustmentStart()
onRawHighlightsAdjustmentChange(it)
},
onValueChangeFinished = onAdjustmentEnd
)
SliderSettingItem(
title = stringResource(R.string.settings_raw_shadows_adjustment),
value = rawShadowsAdjustment,
valueRange = -1f..1f,
resetValue = 0f,
onValueChange = {
onAdjustmentStart()
onRawShadowsAdjustmentChange(it)
},
onValueChangeFinished = onAdjustmentEnd
)
SliderSettingItem(
title = stringResource(R.string.settings_raw_nlm_noise_factor),
value = rawNlmNoiseFactor,
@@ -108,6 +108,8 @@ private data class PreviewRenderSignature(
val editRawDenoise: Float,
val editRawExposureCompensation: Float,
val editRawAutoExposure: Boolean,
val editRawHighlightsAdjustment: Float,
val editRawShadowsAdjustment: Float,
val editRawBlackPointCorrection: Float,
val editRawWhitePointCorrection: Float,
val editRawDROMode: String,
@@ -183,6 +185,8 @@ fun GalleryEditScreen(
val editRawNlmNoiseFactor by viewModel.editRawDenoise.collectAsState()
val editRawExposureCompensation by viewModel.editRawExposureCompensation.collectAsState()
val editRawAutoExposure by viewModel.editRawAutoExposure.collectAsState()
val editRawHighlightsAdjustment by viewModel.editRawHighlightsAdjustment.collectAsState()
val editRawShadowsAdjustment by viewModel.editRawShadowsAdjustment.collectAsState()
val editRawBlackPointCorrection by viewModel.editRawBlackPointCorrection.collectAsState()
val editRawWhitePointCorrection by viewModel.editRawWhitePointCorrection.collectAsState()
val editRawDROMode by viewModel.editRawDROMode.collectAsState()
@@ -246,6 +250,8 @@ fun GalleryEditScreen(
editRawDenoise = editRawNlmNoiseFactor,
editRawExposureCompensation = editRawExposureCompensation,
editRawAutoExposure = editRawAutoExposure,
editRawHighlightsAdjustment = editRawHighlightsAdjustment,
editRawShadowsAdjustment = editRawShadowsAdjustment,
editRawBlackPointCorrection = editRawBlackPointCorrection,
editRawWhitePointCorrection = editRawWhitePointCorrection,
editRawDROMode = editRawDROMode,
@@ -1080,6 +1086,8 @@ fun GalleryEditScreen(
rawNlmNoiseFactor = editRawNlmNoiseFactor,
rawExposureCompensation = editRawExposureCompensation,
rawAutoExposure = editRawAutoExposure,
rawHighlightsAdjustment = editRawHighlightsAdjustment,
rawShadowsAdjustment = editRawShadowsAdjustment,
rawBlackPointCorrection = editRawBlackPointCorrection,
rawWhitePointCorrection = editRawWhitePointCorrection,
spectralFilmEnabled = editRawSpectralFilmEnabled,
@@ -1122,10 +1130,21 @@ fun GalleryEditScreen(
viewModel.saveRawExposureCompensationValue(currentPhoto, it)
},
onRawAutoExposureChange = {
if (it) {
viewModel.saveRawExposureCompensationValue(currentPhoto, 0f)
viewModel.saveRawHighlightsAdjustmentValue(currentPhoto, 0f)
viewModel.saveRawShadowsAdjustmentValue(currentPhoto, 0f)
}
viewModel.saveRawAutoExposureValue(currentPhoto, it) {
requestRawPreviewRefresh()
}
},
onRawHighlightsAdjustmentChange = {
viewModel.saveRawHighlightsAdjustmentValue(currentPhoto, it)
},
onRawShadowsAdjustmentChange = {
viewModel.saveRawShadowsAdjustmentValue(currentPhoto, it)
},
onRawBlackPointCorrectionChange = {
viewModel.saveRawBlackPointCorrectionValue(currentPhoto, it)
},
@@ -260,6 +260,8 @@ fun SettingsScreen(
val rawNlmNoiseFactor by viewModel.rawNlmNoiseFactor.collectAsState()
val rawExposureCompensation by viewModel.rawExposureCompensation.collectAsState()
val rawAutoExposure by viewModel.rawAutoExposure.collectAsState()
val rawHighlightsAdjustment by viewModel.rawHighlightsAdjustment.collectAsState()
val rawShadowsAdjustment by viewModel.rawShadowsAdjustment.collectAsState()
val rawMinShutterSpeedNs by viewModel.rawMinShutterSpeedNs.collectAsState()
val droMode by viewModel.droMode.collectAsState()
val rawBlackPointCorrection by viewModel.rawBlackPointCorrection.collectAsState()
@@ -280,16 +282,27 @@ fun SettingsScreen(
var mainCameraIdOptions by remember { mutableStateOf<List<String>>(emptyList()) }
var rawNlmNoiseFactorUi by remember { mutableStateOf(rawNlmNoiseFactor) }
var rawExposureCompensationUi by remember { mutableStateOf(rawExposureCompensation) }
var rawHighlightsAdjustmentUi by remember { mutableStateOf(rawHighlightsAdjustment) }
var rawShadowsAdjustmentUi by remember { mutableStateOf(rawShadowsAdjustment) }
var rawBlackPointCorrectionUi by remember { mutableStateOf(rawBlackPointCorrection) }
var rawWhitePointCorrectionUi by remember { mutableStateOf(rawWhitePointCorrection) }
var aiFocusScoreThresholdUi by remember(aiFocusScoreThreshold) { mutableStateOf(aiFocusScoreThreshold) }
var showAspectRatioDialog by remember { mutableStateOf(false) }
var backupOperation by remember { mutableStateOf<BackupOperation?>(null) }
LaunchedEffect(rawNlmNoiseFactor, rawExposureCompensation, rawBlackPointCorrection, rawWhitePointCorrection) {
LaunchedEffect(
rawNlmNoiseFactor,
rawExposureCompensation,
rawHighlightsAdjustment,
rawShadowsAdjustment,
rawBlackPointCorrection,
rawWhitePointCorrection
) {
if (!isRawSliderAdjusting) {
rawNlmNoiseFactorUi = rawNlmNoiseFactor
rawExposureCompensationUi = rawExposureCompensation
rawHighlightsAdjustmentUi = rawHighlightsAdjustment
rawShadowsAdjustmentUi = rawShadowsAdjustment
rawBlackPointCorrectionUi = rawBlackPointCorrection
rawWhitePointCorrectionUi = rawWhitePointCorrection
}
@@ -307,6 +320,8 @@ fun SettingsScreen(
isRawSliderAdjusting = false
viewModel.setRawNlmNoiseFactor(rawNlmNoiseFactorUi)
viewModel.setRawExposureCompensation(rawExposureCompensationUi)
viewModel.setRawHighlightsAdjustment(rawHighlightsAdjustmentUi)
viewModel.setRawShadowsAdjustment(rawShadowsAdjustmentUi)
viewModel.setRawBlackPointCorrection(rawBlackPointCorrectionUi)
viewModel.setRawWhitePointCorrection(rawWhitePointCorrectionUi)
}
@@ -1345,6 +1360,8 @@ fun SettingsScreen(
rawNlmNoiseFactor = rawNlmNoiseFactorUi,
rawExposureCompensation = rawExposureCompensationUi,
rawAutoExposure = rawAutoExposure,
rawHighlightsAdjustment = rawHighlightsAdjustmentUi,
rawShadowsAdjustment = rawShadowsAdjustmentUi,
rawBlackPointCorrection = rawBlackPointCorrectionUi,
rawWhitePointCorrection = rawWhitePointCorrectionUi,
spectralFilmEnabled = rawSpectralFilmEnabled,
@@ -1363,7 +1380,19 @@ fun SettingsScreen(
},
onRawNlmNoiseFactorChange = { rawNlmNoiseFactorUi = it },
onRawExposureCompensationChange = { rawExposureCompensationUi = it },
onRawAutoExposureChange = { viewModel.setRawAutoExposure(it) },
onRawAutoExposureChange = {
if (it) {
rawExposureCompensationUi = 0f
rawHighlightsAdjustmentUi = 0f
rawShadowsAdjustmentUi = 0f
viewModel.setRawExposureCompensation(0f)
viewModel.setRawHighlightsAdjustment(0f)
viewModel.setRawShadowsAdjustment(0f)
}
viewModel.setRawAutoExposure(it)
},
onRawHighlightsAdjustmentChange = { rawHighlightsAdjustmentUi = it },
onRawShadowsAdjustmentChange = { rawShadowsAdjustmentUi = it },
onRawBlackPointCorrectionChange = { rawBlackPointCorrectionUi = it },
onRawWhitePointCorrectionChange = { rawWhitePointCorrectionUi = it },
onSpectralFilmEnabledChange = { enabled ->
@@ -841,6 +841,12 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
val rawAutoExposure: StateFlow<Boolean> = userPreferencesRepository.userPreferences
.map { it.rawAutoExposure }
.stateIn(viewModelScope, SharingStarted.Eagerly, true)
val rawHighlightsAdjustment: StateFlow<Float> = userPreferencesRepository.userPreferences
.map { it.rawHighlightsAdjustment }
.stateIn(viewModelScope, SharingStarted.Eagerly, 0f)
val rawShadowsAdjustment: StateFlow<Float> = userPreferencesRepository.userPreferences
.map { it.rawShadowsAdjustment }
.stateIn(viewModelScope, SharingStarted.Eagerly, 0f)
val rawMinShutterSpeedNs: StateFlow<Long> = userPreferencesRepository.userPreferences
.map { it.rawMinShutterSpeedNs }
.stateIn(viewModelScope, SharingStarted.Eagerly, 0L)
@@ -1499,6 +1505,12 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
fun setRawAutoExposure(enabled: Boolean) {
viewModelScope.launch { userPreferencesRepository.saveRawAutoExposure(enabled) }
}
fun setRawHighlightsAdjustment(value: Float) {
viewModelScope.launch { userPreferencesRepository.saveRawHighlightsAdjustment(value) }
}
fun setRawShadowsAdjustment(value: Float) {
viewModelScope.launch { userPreferencesRepository.saveRawShadowsAdjustment(value) }
}
fun setRawMinShutterSpeedNs(value: Long) {
viewModelScope.launch { userPreferencesRepository.saveRawMinShutterSpeedNs(value) }
}
@@ -1732,6 +1744,8 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
rawDenoiseValue = userPrefs?.rawNlmNoiseFactor ?: 0f,
rawExposureCompensation = userPrefs?.rawExposureCompensation ?: 0f,
rawAutoExposure = effectiveRawAutoExposure,
rawHighlightsAdjustment = userPrefs?.rawHighlightsAdjustment ?: 0f,
rawShadowsAdjustment = userPrefs?.rawShadowsAdjustment ?: 0f,
rawBlackPointCorrection = userPrefs?.rawBlackPointCorrection ?: 0f,
rawWhitePointCorrection = userPrefs?.rawWhitePointCorrection ?: 0f,
rawAutoWhiteBalanceEstimate = userPrefs?.rawAutoWhiteBalanceEstimate ?: false,
@@ -3747,6 +3761,8 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
rawDenoiseValue = userPrefs?.rawNlmNoiseFactor ?: 0f,
rawExposureCompensation = userPrefs?.rawExposureCompensation ?: 0f,
rawAutoExposure = effectiveRawAutoExposure,
rawHighlightsAdjustment = userPrefs?.rawHighlightsAdjustment ?: 0f,
rawShadowsAdjustment = userPrefs?.rawShadowsAdjustment ?: 0f,
rawBlackPointCorrection = userPrefs?.rawBlackPointCorrection ?: 0f,
rawWhitePointCorrection = userPrefs?.rawWhitePointCorrection ?: 0f,
rawAutoWhiteBalanceEstimate = userPrefs?.rawAutoWhiteBalanceEstimate ?: false,
@@ -3880,6 +3896,8 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
rawDenoiseValue = userPrefs?.rawNlmNoiseFactor ?: 0f,
rawExposureCompensation = userPrefs?.rawExposureCompensation ?: 0f,
rawAutoExposure = effectiveRawAutoExposure,
rawHighlightsAdjustment = userPrefs?.rawHighlightsAdjustment ?: 0f,
rawShadowsAdjustment = userPrefs?.rawShadowsAdjustment ?: 0f,
rawBlackPointCorrection = userPrefs?.rawBlackPointCorrection ?: 0f,
rawWhitePointCorrection = userPrefs?.rawWhitePointCorrection ?: 0f,
rawAutoWhiteBalanceEstimate = userPrefs?.rawAutoWhiteBalanceEstimate ?: false,
@@ -4029,6 +4047,8 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
rawDenoiseValue = userPrefs?.rawNlmNoiseFactor ?: 0f,
rawExposureCompensation = userPrefs?.rawExposureCompensation ?: 0f,
rawAutoExposure = effectiveRawAutoExposure,
rawHighlightsAdjustment = userPrefs?.rawHighlightsAdjustment ?: 0f,
rawShadowsAdjustment = userPrefs?.rawShadowsAdjustment ?: 0f,
rawBlackPointCorrection = userPrefs?.rawBlackPointCorrection ?: 0f,
rawWhitePointCorrection = userPrefs?.rawWhitePointCorrection ?: 0f,
rawAutoWhiteBalanceEstimate = userPrefs?.rawAutoWhiteBalanceEstimate ?: false,
@@ -4429,6 +4449,8 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
rawDenoiseValue = userPrefs?.rawNlmNoiseFactor ?: 0f,
rawExposureCompensation = userPrefs?.rawExposureCompensation ?: 0f,
rawAutoExposure = effectiveRawAutoExposure,
rawHighlightsAdjustment = userPrefs?.rawHighlightsAdjustment ?: 0f,
rawShadowsAdjustment = userPrefs?.rawShadowsAdjustment ?: 0f,
rawBlackPointCorrection = userPrefs?.rawBlackPointCorrection ?: 0f,
rawWhitePointCorrection = userPrefs?.rawWhitePointCorrection ?: 0f,
rawAutoWhiteBalanceEstimate = userPrefs?.rawAutoWhiteBalanceEstimate ?: false,
@@ -315,6 +315,10 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
private set
var editRawAutoExposure = MutableStateFlow(true)
private set
var editRawHighlightsAdjustment = MutableStateFlow(0f)
private set
var editRawShadowsAdjustment = MutableStateFlow(0f)
private set
var editRawBlackPointCorrection = MutableStateFlow(0f)
private set
var editRawWhitePointCorrection = MutableStateFlow(0f)
@@ -1051,6 +1055,8 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
editRawDenoise.value = m.rawDenoiseValue ?: 0f
editRawExposureCompensation.value = m.rawExposureCompensation ?: 0f
editRawAutoExposure.value = m.rawAutoExposure ?: true
editRawHighlightsAdjustment.value = m.rawHighlightsAdjustment ?: 0f
editRawShadowsAdjustment.value = m.rawShadowsAdjustment ?: 0f
editRawBlackPointCorrection.value = m.rawBlackPointCorrection ?: 0f
editRawWhitePointCorrection.value = m.rawWhitePointCorrection ?: 0f
editRawDcpId.value = m.rawDcpId
@@ -1596,6 +1602,13 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
}
}
private fun applyRawDevelopMetadataToEditState(metadata: MediaMetadata) {
editRawExposureCompensation.value = metadata.rawExposureCompensation ?: 0f
editRawAutoExposure.value = metadata.rawAutoExposure ?: true
editRawHighlightsAdjustment.value = metadata.rawHighlightsAdjustment ?: 0f
editRawShadowsAdjustment.value = metadata.rawShadowsAdjustment ?: 0f
}
/**
* 进入编辑模式
*/
@@ -1649,6 +1662,8 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
editRawDenoise.value = metadata.rawDenoiseValue ?: 0f
editRawExposureCompensation.value = metadata.rawExposureCompensation ?: 0f
editRawAutoExposure.value = metadata.rawAutoExposure ?: true
editRawHighlightsAdjustment.value = metadata.rawHighlightsAdjustment ?: 0f
editRawShadowsAdjustment.value = metadata.rawShadowsAdjustment ?: 0f
editRawBlackPointCorrection.value = metadata.rawBlackPointCorrection ?: 0f
editRawWhitePointCorrection.value = metadata.rawWhitePointCorrection ?: 0f
editRawDROMode.value = RawProcessingPreferences.DROMode.fromPersistedName(metadata.droMode).name
@@ -1669,6 +1684,8 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
editRawDenoise.value = 0.2f
editRawExposureCompensation.value = 0f
editRawAutoExposure.value = true
editRawHighlightsAdjustment.value = 0f
editRawShadowsAdjustment.value = 0f
editRawBlackPointCorrection.value = 0f
editRawWhitePointCorrection.value = 0f
editRawDROMode.value = "OFF"
@@ -1712,6 +1729,8 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
editRawDenoise.value = 0.2f
editRawExposureCompensation.value = 0f
editRawAutoExposure.value = true
editRawHighlightsAdjustment.value = 0f
editRawShadowsAdjustment.value = 0f
editRawBlackPointCorrection.value = 0f
editRawWhitePointCorrection.value = 0f
editRawDROMode.value = "OFF"
@@ -1839,6 +1858,8 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
val denoise = editRawDenoise.value
val exposure = editRawExposureCompensation.value
val autoExposure = editRawAutoExposure.value
val highlights = editRawHighlightsAdjustment.value
val shadows = editRawShadowsAdjustment.value
val blackPoint = editRawBlackPointCorrection.value
val whitePoint = editRawWhitePointCorrection.value
val droMode = editRawDROMode.value
@@ -1863,6 +1884,8 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
rawDenoiseValue = denoise,
rawExposureCompensation = exposure,
rawAutoExposure = autoExposure,
rawHighlightsAdjustment = highlights,
rawShadowsAdjustment = shadows,
rawBlackPointCorrection = blackPoint,
rawWhitePointCorrection = whitePoint,
droMode = droMode,
@@ -1917,6 +1940,16 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
persistRawEditMetadata(mediaData, onComplete)
}
fun saveRawHighlightsAdjustmentValue(mediaData: MediaData, value: Float, onComplete: ((Boolean) -> Unit)? = null) {
editRawHighlightsAdjustment.value = value
persistRawEditMetadata(mediaData, onComplete)
}
fun saveRawShadowsAdjustmentValue(mediaData: MediaData, value: Float, onComplete: ((Boolean) -> Unit)? = null) {
editRawShadowsAdjustment.value = value
persistRawEditMetadata(mediaData, onComplete)
}
fun saveRawDROModeValue(mediaData: MediaData, mode: String, onComplete: ((Boolean) -> Unit)? = null) {
val resolvedMode = RawProcessingPreferences.DROMode.fromPersistedName(mode)
editRawDROMode.value = resolvedMode.name
@@ -2192,6 +2225,8 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
rawDenoiseValue = editRawDenoise.value,
rawExposureCompensation = editRawExposureCompensation.value,
rawAutoExposure = editRawAutoExposure.value,
rawHighlightsAdjustment = editRawHighlightsAdjustment.value,
rawShadowsAdjustment = editRawShadowsAdjustment.value,
rawBlackPointCorrection = editRawBlackPointCorrection.value,
rawWhitePointCorrection = editRawWhitePointCorrection.value,
rawDcpId = editRawDcpId.value,
@@ -2503,6 +2538,8 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
rawDenoiseValue = editRawDenoise.value,
rawExposureCompensation = editRawExposureCompensation.value,
rawAutoExposure = editRawAutoExposure.value,
rawHighlightsAdjustment = editRawHighlightsAdjustment.value,
rawShadowsAdjustment = editRawShadowsAdjustment.value,
rawBlackPointCorrection = editRawBlackPointCorrection.value,
rawWhitePointCorrection = editRawWhitePointCorrection.value,
rawDcpId = editRawDcpId.value,
@@ -2586,7 +2623,8 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
val context = getApplication<Application>()
val result = GalleryManager.refreshRawPreview(context, photo.id)
if (result != null) {
updatePhotoMetadata(photo.id) { it }
val updatedMetadata = updatePhotoMetadata(photo.id) { it }
updatedMetadata?.let { applyRawDevelopMetadataToEditState(it) }
// 更新刷新密钥以强制 UI 重新加载
photoRefreshKeys[photo.id] = System.currentTimeMillis()
invalidatePreviewCache(photo.id)
@@ -646,6 +646,8 @@
<string name="settings_default_focal_length">默认焦段</string>
<string name="settings_raw_nlm_noise_factor">降噪</string>
<string name="settings_raw_exposure_compensation">曝光补偿</string>
<string name="settings_raw_highlights_adjustment">高光</string>
<string name="settings_raw_shadows_adjustment">阴影</string>
<string name="settings_spectral_film">光谱胶片模拟</string>
<string name="settings_spectral_film_description">模拟经典底片和打印介质的色彩响应与物理特征曲线。</string>
<string name="settings_negative_film">底片胶卷</string>
@@ -396,6 +396,8 @@
<string name="settings_dro_dr200">DR200</string>
<string name="settings_dro_dr400">DR400</string>
<string name="settings_raw_nlm_noise_factor">降噪</string>
<string name="settings_raw_highlights_adjustment">高光</string>
<string name="settings_raw_shadows_adjustment">陰影</string>
<string name="settings_use_p010">P010 (10 位 YUV)</string>
<string name="settings_use_p010_description">啟用 10 位 YUV 輸出以獲得更好的影像資料精度。僅在支援的裝置上且 RAW 關閉時生效。</string>
<string name="settings_use_hlg10">HLG10 HDR</string>
+2
View File
@@ -630,6 +630,8 @@
<string name="settings_dro_dr400">DR400</string>
<string name="settings_raw_nlm_noise_factor">Denoise</string>
<string name="settings_raw_exposure_compensation">Exposure Compensation</string>
<string name="settings_raw_highlights_adjustment">Highlights</string>
<string name="settings_raw_shadows_adjustment">Shadows</string>
<string name="settings_spectral_film">Spectral Film Simulation</string>
<string name="settings_spectral_film_description">Simulate classic negative film and print medium color curves.</string>
<string name="settings_negative_film">Negative Film</string>