fix: hdr expo
This commit is contained in:
1 parent
d12904db82
commit
9bbe4b9acb
3 files changed
+93
-25
No files matched your search
@@ -1410,6 +1410,7 @@ class RawDemosaicProcessor {
|
||||
dcpRenderPlan = activeDcpRenderPlan
|
||||
)
|
||||
logRawDcpPipeline(
|
||||
metadata = actualMetadata,
|
||||
profilePlanSource = profilePlanSource,
|
||||
requestedColorEngine = requestedColorEngine,
|
||||
colorEngine = colorEngine,
|
||||
@@ -1850,7 +1851,12 @@ class RawDemosaicProcessor {
|
||||
"engineDefaultEv=${colorEngine.defaultExposureCompensationEv} " +
|
||||
"engineCompensationDomain=${colorEngine.exposureCompensationDomain} " +
|
||||
"profileExposureEv=${profileExposureUniforms.exposureEv} " +
|
||||
"defaultBlackRender=${if (useProfileExposureRamp) dcpDefaultBlackRenderOrAuto(activeDcpRenderPlan) else DcpDefaultBlackRender.None} " +
|
||||
"defaultBlackRender=${resolveProfileDefaultBlackRender(
|
||||
metadata = actualMetadata,
|
||||
dcpRenderPlan = activeDcpRenderPlan,
|
||||
applyDngBaselineExposure = applyProfileDngBaselineExposure,
|
||||
useRamp = useProfileExposureRamp,
|
||||
)} " +
|
||||
"profileRampBlack=${profileExposureUniforms.rampBlack} " +
|
||||
"profileSupportOverrange=${profileExposureUniforms.supportOverrange} " +
|
||||
"dngShadowScale=${actualMetadata.shadowScale} " +
|
||||
@@ -7732,6 +7738,7 @@ class RawDemosaicProcessor {
|
||||
}
|
||||
|
||||
private fun logRawDcpPipeline(
|
||||
metadata: RawMetadata,
|
||||
profilePlanSource: String?,
|
||||
requestedColorEngine: RawRenderingEngine,
|
||||
colorEngine: RawRenderingEngine,
|
||||
@@ -7753,7 +7760,12 @@ class RawDemosaicProcessor {
|
||||
val hueSatMap = dcpRenderPlan?.hueSatMap?.takeIf { it.isValid }
|
||||
val lookEnabled = dcpRenderPlan?.lookTable?.isValid == true
|
||||
val profileToneCurveEnabled = useAdobeProfilePipeline && dcpRenderPlan?.toneCurveLut != null
|
||||
val defaultBlackRender = dcpDefaultBlackRenderOrAuto(dcpRenderPlan)
|
||||
val defaultBlackRender = resolveProfileDefaultBlackRender(
|
||||
metadata = metadata,
|
||||
dcpRenderPlan = dcpRenderPlan,
|
||||
applyDngBaselineExposure = useAdobeProfilePipeline,
|
||||
useRamp = useProfileExposureRamp,
|
||||
)
|
||||
val dcpBaselineExposureOffset = if (applyDcpBaselineExposureOffset) {
|
||||
dcpBaselineExposureOffsetOrZero(dcpRenderPlan)
|
||||
} else {
|
||||
@@ -7822,7 +7834,7 @@ class RawDemosaicProcessor {
|
||||
dcpRenderPlan: DcpRenderPlan?,
|
||||
applyDcpBaselineExposureOffset: Boolean,
|
||||
applyDngBaselineExposure: Boolean,
|
||||
useRamp: Boolean
|
||||
useRamp: Boolean,
|
||||
): ProfileExposureUniforms {
|
||||
val dngBaselineExposure = if (applyDngBaselineExposure) {
|
||||
DngBaselineExposure.sanitize(metadata.baselineExposure)
|
||||
@@ -7838,17 +7850,36 @@ class RawDemosaicProcessor {
|
||||
profileExposureCompensation = profileExposureCompensation,
|
||||
dngBaselineExposure = dngBaselineExposure,
|
||||
dcpBaselineExposureOffset = dcpBaselineExposureOffset,
|
||||
defaultBlackRender = if (useRamp) {
|
||||
dcpDefaultBlackRenderOrAuto(dcpRenderPlan)
|
||||
} else {
|
||||
DcpDefaultBlackRender.None
|
||||
},
|
||||
defaultBlackRender = resolveProfileDefaultBlackRender(
|
||||
metadata = metadata,
|
||||
dcpRenderPlan = dcpRenderPlan,
|
||||
applyDngBaselineExposure = applyDngBaselineExposure,
|
||||
useRamp = useRamp,
|
||||
),
|
||||
shadowScale = metadata.shadowScale,
|
||||
supportOverrange = useRamp && dcpRenderPlan?.supportsOverrange == true,
|
||||
useRamp = useRamp
|
||||
)
|
||||
}
|
||||
|
||||
private fun resolveProfileDefaultBlackRender(
|
||||
metadata: RawMetadata,
|
||||
dcpRenderPlan: DcpRenderPlan?,
|
||||
applyDngBaselineExposure: Boolean,
|
||||
useRamp: Boolean,
|
||||
): DcpDefaultBlackRender {
|
||||
if (!useRamp) return DcpDefaultBlackRender.None
|
||||
val dngBaselineExposure = if (applyDngBaselineExposure) {
|
||||
DngBaselineExposure.sanitize(metadata.baselineExposure)
|
||||
} else {
|
||||
0f
|
||||
}
|
||||
return RawProfileExposureGl.resolveDefaultBlackRender(
|
||||
dngBaselineExposure = dngBaselineExposure,
|
||||
requested = dcpDefaultBlackRenderOrAuto(dcpRenderPlan),
|
||||
)
|
||||
}
|
||||
|
||||
private fun computeLinearExposureGain(
|
||||
metadata: RawMetadata,
|
||||
rawExposureCompensation: Float,
|
||||
@@ -8215,6 +8246,12 @@ class RawDemosaicProcessor {
|
||||
"samplesPerPixel=$samplesPerPixel size=${metadata.width}x${metadata.height} " +
|
||||
"sourceBaselineEv=$sourceBaselineEv " +
|
||||
"profileBaselineExposureOffsetEv=$profileBaselineExposureOffsetEv " +
|
||||
"defaultBlackRender=${resolveProfileDefaultBlackRender(
|
||||
metadata = metadata,
|
||||
dcpRenderPlan = dcpRenderPlan,
|
||||
applyDngBaselineExposure = applyProfileDngBaselineExposure,
|
||||
useRamp = useProfileExposureRamp,
|
||||
)} " +
|
||||
"candidateDomain=${if (useAdobeSdkExposure) "ADOBE_DNG_SDK" else "LINEAR_GAIN"}"
|
||||
)
|
||||
try {
|
||||
@@ -8381,7 +8418,7 @@ class RawDemosaicProcessor {
|
||||
dcpRenderPlan = dcpRenderPlan,
|
||||
applyDcpBaselineExposureOffset = applyProfileDcpBaselineExposureOffset,
|
||||
applyDngBaselineExposure = applyProfileDngBaselineExposure,
|
||||
useRamp = useProfileExposureRamp
|
||||
useRamp = useProfileExposureRamp,
|
||||
)
|
||||
val rendered = renderCombinedPass(
|
||||
metadata = metadata,
|
||||
|
||||
@@ -7,6 +7,7 @@ import kotlin.math.pow
|
||||
|
||||
object RawProfileExposureGl {
|
||||
const val DEFAULT_BLACK_RENDER_SHADOWS = 5f
|
||||
private const val DEFAULT_BLACK_RENDER_DISABLE_BASELINE_EV = 2f
|
||||
private const val DEFAULT_BLACK_RENDER_SHADOW_SCALE = 1f
|
||||
private const val DEFAULT_BLACK_RENDER_STAGE3_GAIN = 1f
|
||||
|
||||
@@ -81,7 +82,11 @@ object RawProfileExposureGl {
|
||||
} else {
|
||||
DEFAULT_BLACK_RENDER_SHADOW_SCALE
|
||||
}
|
||||
val black = when (defaultBlackRender) {
|
||||
val resolvedDefaultBlackRender = resolveDefaultBlackRender(
|
||||
dngBaselineExposure = dngBaselineExposure,
|
||||
requested = defaultBlackRender,
|
||||
)
|
||||
val black = when (resolvedDefaultBlackRender) {
|
||||
DcpDefaultBlackRender.Auto -> blackRenderShadows.coerceAtLeast(0f) *
|
||||
safeShadowScale *
|
||||
DEFAULT_BLACK_RENDER_STAGE3_GAIN *
|
||||
@@ -132,6 +137,20 @@ object RawProfileExposureGl {
|
||||
)
|
||||
}
|
||||
|
||||
fun resolveDefaultBlackRender(
|
||||
dngBaselineExposure: Float,
|
||||
requested: DcpDefaultBlackRender,
|
||||
): DcpDefaultBlackRender {
|
||||
val baselineExposure = DngBaselineExposure.sanitize(dngBaselineExposure)
|
||||
// A large BaselineExposure is a source-domain normalization. Applying the Adobe Auto
|
||||
// stage-3 black point before that gain removes valid source signal, so keep zero as black.
|
||||
return if (baselineExposure >= DEFAULT_BLACK_RENDER_DISABLE_BASELINE_EV) {
|
||||
DcpDefaultBlackRender.None
|
||||
} else {
|
||||
requested
|
||||
}
|
||||
}
|
||||
|
||||
fun bindUniforms(program: Int, exposure: Uniforms) {
|
||||
GLES30.glUniform1f(
|
||||
GLES30.glGetUniformLocation(program, "uProfileExposureLinearGain"),
|
||||
|
||||
@@ -7,37 +7,49 @@ import kotlin.math.pow
|
||||
|
||||
class RawProfileExposureGlTest {
|
||||
@Test
|
||||
fun profileGainToneMapKeepsLargeBaselineExposureNormalizationLinear() {
|
||||
fun baselineExposureAtOrAboveTwoDisablesDefaultBlackRender() {
|
||||
val belowThreshold = RawProfileExposureGl.compute(
|
||||
profileExposureCompensation = 0f,
|
||||
dngBaselineExposure = 1.999f,
|
||||
defaultBlackRender = DcpDefaultBlackRender.Auto,
|
||||
useRamp = true,
|
||||
)
|
||||
val atThreshold = RawProfileExposureGl.compute(
|
||||
profileExposureCompensation = 0f,
|
||||
dngBaselineExposure = 2f,
|
||||
defaultBlackRender = DcpDefaultBlackRender.Auto,
|
||||
useRamp = true,
|
||||
)
|
||||
|
||||
assertTrue(belowThreshold.rampBlack > 0f)
|
||||
assertEquals(0f, atThreshold.rampBlack, 0f)
|
||||
assertEquals(
|
||||
DcpDefaultBlackRender.None,
|
||||
RawProfileExposureGl.resolveDefaultBlackRender(2f, DcpDefaultBlackRender.Auto),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun largeBaselineExposureNormalizationStaysLinearWhenAutoBlackWasRequested() {
|
||||
val baselineExposureEv = 6.588512f
|
||||
val baselineGain = 2.0f.pow(baselineExposureEv)
|
||||
val sceneInput = 0.5500106f
|
||||
val profileGain = 0.75050706f
|
||||
val preRampValue = sceneInput * profileGain / baselineGain
|
||||
|
||||
val profileGainToneMapRamp = RawProfileExposureGl.compute(
|
||||
profileExposureCompensation = 0f,
|
||||
dngBaselineExposure = baselineExposureEv,
|
||||
defaultBlackRender = DcpDefaultBlackRender.None,
|
||||
useRamp = true,
|
||||
)
|
||||
val autoBlackRamp = RawProfileExposureGl.compute(
|
||||
val ramp = RawProfileExposureGl.compute(
|
||||
profileExposureCompensation = 0f,
|
||||
dngBaselineExposure = baselineExposureEv,
|
||||
defaultBlackRender = DcpDefaultBlackRender.Auto,
|
||||
useRamp = true,
|
||||
)
|
||||
|
||||
assertEquals(0f, profileGainToneMapRamp.rampBlack, 0f)
|
||||
assertEquals(0f, ramp.rampBlack, 0f)
|
||||
assertEquals(
|
||||
sceneInput * profileGain,
|
||||
preRampValue * profileGainToneMapRamp.rampSlope,
|
||||
preRampValue * ramp.rampSlope,
|
||||
1e-5f,
|
||||
)
|
||||
assertTrue(
|
||||
"preRampValue=$preRampValue autoBlack=${autoBlackRamp.rampBlack} " +
|
||||
"autoRadius=${autoBlackRamp.rampRadius}",
|
||||
preRampValue <= autoBlackRamp.rampBlack - autoBlackRamp.rampRadius,
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user