feat: implement lens shading power scaling and adjust chroma denoise strength
This commit is contained in:
1 parent
110e2905ac
commit
a1c6b7a1a1
2 files changed
+46
-3
No files matched your search
@@ -24,6 +24,7 @@ import java.nio.ShortBuffer
|
||||
import java.util.concurrent.Executors
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.ln
|
||||
import kotlin.math.max
|
||||
import kotlin.math.pow
|
||||
import kotlin.math.sqrt
|
||||
import android.opengl.Matrix as GlMatrix
|
||||
@@ -1164,7 +1165,7 @@ class RawDemosaicProcessor {
|
||||
|
||||
val noiseAdaptiveScale = computeDenoiseStrengthScale(s, o)
|
||||
val h = denoiseValue.coerceAtLeast(0f) * BM3D_SIGMA_STRENGTH_AT_SLIDER_ONE * noiseAdaptiveScale
|
||||
val ch = chromaDenoiseValue.coerceAtLeast(0f) * BM3D_SIGMA_STRENGTH_AT_SLIDER_ONE * noiseAdaptiveScale + 0.2f
|
||||
val ch = chromaDenoiseValue.coerceAtLeast(0f) * BM3D_SIGMA_STRENGTH_AT_SLIDER_ONE * noiseAdaptiveScale + 0.3f
|
||||
PLog.d(
|
||||
TAG,
|
||||
"Dynamic BM3D: s=$s o=$o, h=$h ch=$ch scale=$noiseAdaptiveScale iso=${metadata.iso} linearGain=$linearExposureGain"
|
||||
@@ -1948,6 +1949,10 @@ class RawDemosaicProcessor {
|
||||
GLES30.glGetUniformLocation(combinedProgram, "uLensShadingEnabled"),
|
||||
if (hasLensShading) 1 else 0
|
||||
)
|
||||
GLES30.glUniform1f(
|
||||
GLES30.glGetUniformLocation(combinedProgram, "uLensShadingPower"),
|
||||
computeLensShadingPower(metadata)
|
||||
)
|
||||
|
||||
bindDcpCombinedResources(dcpRenderPlan)
|
||||
|
||||
@@ -1972,6 +1977,39 @@ class RawDemosaicProcessor {
|
||||
return t * t * (3f - 2f * t)
|
||||
}
|
||||
|
||||
private fun computeLensShadingPower(metadata: RawMetadata): Float {
|
||||
val map = metadata.lensShadingMap ?: return 1f
|
||||
val width = metadata.lensShadingMapWidth
|
||||
val height = metadata.lensShadingMapHeight
|
||||
if (width <= 0 || height <= 0 || map.size < width * height * 4) return 1f
|
||||
|
||||
fun lumaGainAt(index: Int): Float {
|
||||
val base = index * 4
|
||||
val r = map.getOrElse(base) { 1f }
|
||||
val gr = map.getOrElse(base + 1) { 1f }
|
||||
val gb = map.getOrElse(base + 2) { gr }
|
||||
val b = map.getOrElse(base + 3) { 1f }
|
||||
return (0.2126f * r + 0.7152f * ((gr + gb) * 0.5f) + 0.0722f * b)
|
||||
.coerceAtLeast(1e-4f)
|
||||
}
|
||||
|
||||
val centerIndex = (height / 2) * width + (width / 2)
|
||||
val centerGain = lumaGainAt(centerIndex)
|
||||
var maxRelativeGain = 1f
|
||||
for (i in 0 until width * height) {
|
||||
maxRelativeGain = max(maxRelativeGain, lumaGainAt(i) / centerGain)
|
||||
}
|
||||
|
||||
// Limit the strongest post-denoise LSC lift to one stop:
|
||||
// applied = relativeGain^power, so power = log(2) / log(maxRelativeGain).
|
||||
val maxAllowedLift = 2f
|
||||
return if (maxRelativeGain <= maxAllowedLift) {
|
||||
1f
|
||||
} else {
|
||||
(ln(maxAllowedLift) / ln(maxRelativeGain)).coerceIn(0f, 1f)
|
||||
}
|
||||
}
|
||||
|
||||
private fun logProgramLinkResult(program: Int, name: String): Boolean {
|
||||
if (program == 0) {
|
||||
PLog.e(TAG, "$name creation failed")
|
||||
|
||||
@@ -141,6 +141,7 @@ object RawShaders {
|
||||
uniform float uCurveSize;
|
||||
uniform bool uCurveEnabled;
|
||||
uniform bool uLensShadingEnabled;
|
||||
uniform float uLensShadingPower;
|
||||
uniform bool uDcpHueSatEnabled;
|
||||
uniform bool uDcpLookTableEnabled;
|
||||
uniform ivec3 uDcpHueSatDivisions;
|
||||
@@ -157,8 +158,12 @@ object RawShaders {
|
||||
return color;
|
||||
}
|
||||
vec4 gain = texture(uLensShadingMap, vTexCoord);
|
||||
vec3 rgbGain = vec3(gain.r, 0.5 * (gain.g + gain.b), gain.a);
|
||||
return color * max(rgbGain, vec3(0.0));
|
||||
vec4 centerGain = texture(uLensShadingMap, vec2(0.5));
|
||||
float lumaGain = dot(vec3(gain.r, 0.5 * (gain.g + gain.b), gain.a), vec3(0.2126, 0.7152, 0.0722));
|
||||
float centerLumaGain = dot(vec3(centerGain.r, 0.5 * (centerGain.g + centerGain.b), centerGain.a), vec3(0.2126, 0.7152, 0.0722));
|
||||
lumaGain /= max(centerLumaGain, 1e-4);
|
||||
lumaGain = pow(max(lumaGain, 1e-4), clamp(uLensShadingPower, 0.0, 1.0));
|
||||
return color * max(lumaGain, 0.0);
|
||||
}
|
||||
|
||||
float sampleCurve(float value) {
|
||||
|
||||
Reference in new issue
Block a user