feat: chroma denoise value adjust
This commit is contained in:
1 parent
8516f3750f
commit
b5d00a9bd6
6 files changed
+61
-21
No files matched your search
@@ -26,6 +26,7 @@ import com.hinnka.mycamera.hdr.SourceKind
|
||||
import com.hinnka.mycamera.hdr.UltraHdrWriter
|
||||
import com.hinnka.mycamera.hdr.UnifiedGainmapProducer
|
||||
import com.hinnka.mycamera.livephoto.MotionPhotoWriter
|
||||
import com.hinnka.mycamera.lut.ChromaDenoiseDefaults
|
||||
import com.hinnka.mycamera.lut.applyEffectsToVideoFile
|
||||
import com.hinnka.mycamera.lut.isVideoTransformerExportSupported
|
||||
import com.hinnka.mycamera.model.SafeImage
|
||||
@@ -1889,7 +1890,8 @@ object GalleryManager {
|
||||
var updatedMetadata: MediaMetadata = metadata
|
||||
val rawSharpening = updatedMetadata.sharpening ?: RawSharpeningDefaults.forCapture(sharpeningValue)
|
||||
val rawNoiseReduction = resolveNoiseReduction(updatedMetadata, noiseReductionValue)
|
||||
val rawChromaNoiseReduction = resolveChromaNoiseReduction(updatedMetadata, chromaNoiseReductionValue)
|
||||
val rawChromaNoiseReduction = updatedMetadata.chromaNoiseReduction
|
||||
?: ChromaDenoiseDefaults.forRawCapture(chromaNoiseReductionValue)
|
||||
val rawResult = RawDemosaicProcessor.getInstance().processForHdrSources(
|
||||
context,
|
||||
dngFile.absolutePath,
|
||||
@@ -1935,7 +1937,8 @@ object GalleryManager {
|
||||
updatedMetadata = updatedMetadata.copy(
|
||||
width = bitmap.width,
|
||||
height = bitmap.height,
|
||||
sharpening = rawSharpening
|
||||
sharpening = rawSharpening,
|
||||
chromaNoiseReduction = rawChromaNoiseReduction
|
||||
)
|
||||
|
||||
FileOutputStream(tempFile).use { outputStream ->
|
||||
@@ -2792,7 +2795,8 @@ object GalleryManager {
|
||||
var updatedMetadata: MediaMetadata = stackedMetadata
|
||||
val rawSharpening = updatedMetadata.sharpening ?: RawSharpeningDefaults.forCapture(sharpeningValue)
|
||||
val rawNoiseReduction = resolveNoiseReduction(updatedMetadata, noiseReductionValue)
|
||||
val rawChromaNoiseReduction = resolveChromaNoiseReduction(updatedMetadata, chromaNoiseReductionValue)
|
||||
val rawChromaNoiseReduction = updatedMetadata.chromaNoiseReduction
|
||||
?: ChromaDenoiseDefaults.forRawCapture(chromaNoiseReductionValue)
|
||||
val rawResult = RawDemosaicProcessor.getInstance().processForHdrSources(
|
||||
context,
|
||||
dngFile.absolutePath,
|
||||
@@ -2838,7 +2842,8 @@ object GalleryManager {
|
||||
updatedMetadata = updatedMetadata.copy(
|
||||
width = bitmap.width,
|
||||
height = bitmap.height,
|
||||
sharpening = rawSharpening
|
||||
sharpening = rawSharpening,
|
||||
chromaNoiseReduction = rawChromaNoiseReduction
|
||||
)
|
||||
|
||||
// Save Original (Stacked Result)
|
||||
@@ -3231,7 +3236,8 @@ object GalleryManager {
|
||||
var updatedMetadata: MediaMetadata = metadata.withEmbeddedDngToneMapDefaults(dngFile)
|
||||
val rawSharpening = updatedMetadata.sharpening ?: RawSharpeningDefaults.forCapture(sharpeningValue)
|
||||
val rawNoiseReduction = resolveNoiseReduction(updatedMetadata, noiseReductionValue)
|
||||
val rawChromaNoiseReduction = resolveChromaNoiseReduction(updatedMetadata, chromaNoiseReductionValue)
|
||||
val rawChromaNoiseReduction = updatedMetadata.chromaNoiseReduction
|
||||
?: ChromaDenoiseDefaults.forRawCapture(chromaNoiseReductionValue)
|
||||
val rawResult = RawDemosaicProcessor.getInstance().processForHdrSources(
|
||||
context,
|
||||
dngFile.absolutePath,
|
||||
@@ -3277,7 +3283,8 @@ object GalleryManager {
|
||||
updatedMetadata = updatedMetadata.copy(
|
||||
width = bitmap.width,
|
||||
height = bitmap.height,
|
||||
sharpening = rawSharpening
|
||||
sharpening = rawSharpening,
|
||||
chromaNoiseReduction = rawChromaNoiseReduction
|
||||
)
|
||||
|
||||
FileOutputStream(tempFile).use { outputStream ->
|
||||
@@ -4564,6 +4571,12 @@ object GalleryManager {
|
||||
var updatedMetadata: MediaMetadata = metadata
|
||||
.withImportedRawToneMapPreference(context)
|
||||
.withEmbeddedDngToneMapDefaults(dngFile)
|
||||
.let { rawMetadata ->
|
||||
rawMetadata.copy(
|
||||
chromaNoiseReduction = rawMetadata.chromaNoiseReduction
|
||||
?: ChromaDenoiseDefaults.RAW_CAPTURE_DEFAULT_STRENGTH
|
||||
)
|
||||
}
|
||||
if (deferRawPreview) {
|
||||
val metadataSaved = saveMetadata(context, photoId, updatedMetadata)
|
||||
if (!metadataSaved) {
|
||||
@@ -4573,7 +4586,8 @@ object GalleryManager {
|
||||
} else {
|
||||
// 3. 处理 RAW 以生成 JPEG 预览
|
||||
val rawNoiseReduction = resolveNoiseReduction(updatedMetadata, 0f)
|
||||
val rawChromaNoiseReduction = resolveChromaNoiseReduction(updatedMetadata, 0f)
|
||||
val rawChromaNoiseReduction = updatedMetadata.chromaNoiseReduction
|
||||
?: ChromaDenoiseDefaults.RAW_CAPTURE_DEFAULT_STRENGTH
|
||||
val processedBitmap = RawDemosaicProcessor.getInstance().process(
|
||||
context,
|
||||
dngFile.absolutePath, null, null, 0,
|
||||
@@ -4621,7 +4635,8 @@ object GalleryManager {
|
||||
updatedMetadata = updatedMetadata.copy(
|
||||
width = processedBitmap.width,
|
||||
height = processedBitmap.height,
|
||||
rotation = 0
|
||||
rotation = 0,
|
||||
chromaNoiseReduction = rawChromaNoiseReduction
|
||||
)
|
||||
saveMetadata(context, photoId, updatedMetadata)
|
||||
// if (updatedMetadata.computationalAperture != null) {
|
||||
@@ -4737,7 +4752,8 @@ object GalleryManager {
|
||||
var updatedMetadata = metadata
|
||||
val rawMetadata = updatedMetadata ?: MediaMetadata()
|
||||
val rawNoiseReduction = resolveNoiseReduction(rawMetadata, 0f)
|
||||
val rawChromaNoiseReduction = resolveChromaNoiseReduction(rawMetadata, 0f)
|
||||
val rawChromaNoiseReduction = rawMetadata.chromaNoiseReduction
|
||||
?: ChromaDenoiseDefaults.RAW_CAPTURE_DEFAULT_STRENGTH
|
||||
val processedBitmap = RawDemosaicProcessor.getInstance().process(
|
||||
context,
|
||||
dngFile.absolutePath, metadata?.ratio, metadata?.cropRegion, 0,
|
||||
@@ -4792,7 +4808,8 @@ object GalleryManager {
|
||||
val finalMetadata = it.copy(
|
||||
width = processedBitmap.width,
|
||||
height = processedBitmap.height,
|
||||
hasAiDenoisedBase = false
|
||||
hasAiDenoisedBase = false,
|
||||
chromaNoiseReduction = rawChromaNoiseReduction
|
||||
)
|
||||
generateBokehPhoto(context, photoId, finalMetadata, processedBitmap.copy(Bitmap.Config.ARGB_8888, true))
|
||||
saveMetadata(context, photoId, finalMetadata)
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
package com.hinnka.mycamera.lut
|
||||
|
||||
object ChromaDenoiseDefaults {
|
||||
const val RAW_HIDDEN_BASE_STRENGTH = 0.25f
|
||||
const val RAW_CAPTURE_DEFAULT_STRENGTH = 0.25f
|
||||
private const val MIN_ACTIVE_NOISE_BANDWIDTH = 1.0f
|
||||
private const val MAX_NOISE_BANDWIDTH = 8.0f
|
||||
private const val FULL_OUTPUT_STRENGTH_POINT = 0.25f
|
||||
private const val EDGE_GUIDANCE_START_POINT = 0.75f
|
||||
|
||||
fun rawDefaultStrength(userStrength: Float): Float {
|
||||
val clamped = userStrength.coerceIn(0f, 1f)
|
||||
return RAW_HIDDEN_BASE_STRENGTH + clamped * (1f - RAW_HIDDEN_BASE_STRENGTH)
|
||||
}
|
||||
fun forRawCapture(requested: Float): Float =
|
||||
maxOf(requested, RAW_CAPTURE_DEFAULT_STRENGTH)
|
||||
|
||||
/**
|
||||
* Keeps the bilateral kernel wide enough to recognize noise at every active
|
||||
|
||||
@@ -1759,7 +1759,7 @@ class LutImageProcessor {
|
||||
applyNaturalLightDefault: Boolean
|
||||
): Float {
|
||||
return if (applyNaturalLightDefault) {
|
||||
ChromaDenoiseDefaults.rawDefaultStrength(userStrength)
|
||||
ChromaDenoiseDefaults.forRawCapture(userStrength)
|
||||
} else {
|
||||
userStrength.coerceIn(0f, 1f)
|
||||
}
|
||||
|
||||
@@ -3894,7 +3894,7 @@ class RawDemosaicProcessor {
|
||||
metadata: RawMetadata,
|
||||
chromaDenoiseValue: Float?,
|
||||
): Int {
|
||||
val strength = ChromaDenoiseDefaults.rawDefaultStrength(chromaDenoiseValue ?: 0f)
|
||||
val strength = chromaDenoiseValue?.coerceIn(0f, 1f) ?: 0f
|
||||
if (strength <= 0f || width * height < 2) {
|
||||
return sourceTextureId
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ import com.hinnka.mycamera.raw.ColorSpace
|
||||
import com.hinnka.mycamera.raw.DcpProfileParser
|
||||
import com.hinnka.mycamera.raw.DcpInfo
|
||||
import com.hinnka.mycamera.color.TransferCurve
|
||||
import com.hinnka.mycamera.lut.ChromaDenoiseDefaults
|
||||
import com.hinnka.mycamera.model.EffectParams
|
||||
import com.hinnka.mycamera.raw.RawProcessingPreferences
|
||||
import com.hinnka.mycamera.raw.RawProfile
|
||||
@@ -4588,7 +4589,12 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
requestedSharpeningValue
|
||||
}
|
||||
val noiseReductionValue = noiseReduction.firstOrNull() ?: 0f
|
||||
val chromaNoiseReductionValue = chromaNoiseReduction.firstOrNull() ?: 0f
|
||||
val requestedChromaNoiseReductionValue = chromaNoiseReduction.firstOrNull() ?: 0f
|
||||
val chromaNoiseReductionValue = if (isRawCaptureFormat(image.format)) {
|
||||
ChromaDenoiseDefaults.forRawCapture(requestedChromaNoiseReductionValue)
|
||||
} else {
|
||||
requestedChromaNoiseReductionValue
|
||||
}
|
||||
val photoQualityValue = photoQuality.firstOrNull() ?: 95
|
||||
val droModeString = droMode.value
|
||||
val droModeForProcessing =
|
||||
@@ -5172,7 +5178,12 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
requestedSharpeningValue
|
||||
}
|
||||
val noiseReductionValue = noiseReduction.firstOrNull() ?: 0f
|
||||
val chromaNoiseReductionValue = chromaNoiseReduction.firstOrNull() ?: 0f
|
||||
val requestedChromaNoiseReductionValue = chromaNoiseReduction.firstOrNull() ?: 0f
|
||||
val chromaNoiseReductionValue = if (isRawStack) {
|
||||
ChromaDenoiseDefaults.forRawCapture(requestedChromaNoiseReductionValue)
|
||||
} else {
|
||||
requestedChromaNoiseReductionValue
|
||||
}
|
||||
val photoQualityValue = photoQuality.firstOrNull() ?: 95
|
||||
val droModeString = droMode.value
|
||||
val currentCameraId = cameraController.getCurrentCameraId()
|
||||
@@ -5646,7 +5657,9 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
val shouldAutoSave = autoSaveAfterCapture.firstOrNull() ?: false
|
||||
val sharpeningValue = RawSharpeningDefaults.forCapture(sharpening.firstOrNull() ?: 0f)
|
||||
val noiseReductionValue = noiseReduction.firstOrNull() ?: 0f
|
||||
val chromaNoiseReductionValue = chromaNoiseReduction.firstOrNull() ?: 0f
|
||||
val chromaNoiseReductionValue = ChromaDenoiseDefaults.forRawCapture(
|
||||
chromaNoiseReduction.firstOrNull() ?: 0f
|
||||
)
|
||||
val photoQualityValue = photoQuality.firstOrNull() ?: 95
|
||||
val captureMode = if (state.value.useMFNR) "raw_hdr_mfnr" else "raw_hdr_bracket"
|
||||
val baseImage = images.first()
|
||||
@@ -5724,7 +5737,12 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
requestedSharpeningValue
|
||||
}
|
||||
val noiseReductionValue = noiseReduction.firstOrNull() ?: 0f
|
||||
val chromaNoiseReductionValue = chromaNoiseReduction.firstOrNull() ?: 0f
|
||||
val requestedChromaNoiseReductionValue = chromaNoiseReduction.firstOrNull() ?: 0f
|
||||
val chromaNoiseReductionValue = if (isRawCaptureFormat(image.format)) {
|
||||
ChromaDenoiseDefaults.forRawCapture(requestedChromaNoiseReductionValue)
|
||||
} else {
|
||||
requestedChromaNoiseReductionValue
|
||||
}
|
||||
val currentCameraId = cameraController.getCurrentCameraId()
|
||||
|
||||
// 计算旋转角度
|
||||
|
||||
@@ -4,6 +4,13 @@ import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class ChromaDenoiseDefaultsTest {
|
||||
@Test
|
||||
fun rawCaptureUsesAnExplicitDefaultWithoutScalingUserValues() {
|
||||
assertEquals(0.25f, ChromaDenoiseDefaults.forRawCapture(0f), 0f)
|
||||
assertEquals(0.25f, ChromaDenoiseDefaults.forRawCapture(0.1f), 0f)
|
||||
assertEquals(0.5f, ChromaDenoiseDefaults.forRawCapture(0.5f), 0f)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun activeNoiseBandwidthRespondsAcrossTheWholeSliderRange() {
|
||||
assertEquals(0f, ChromaDenoiseDefaults.noiseBandwidth(0f), 0f)
|
||||
|
||||
Reference in new issue
Block a user