fix: photon curve highlight color error

This commit is contained in:
Hinnka committed 2026-07-26 11:28:31 +08:00
1 parent 6c09a4da72
commit 87b40ab2fb
7 files changed
+116 -34

No files matched your search

@@ -35,6 +35,8 @@ internal object DngHdrProfileGainTableGpuShaders {
uniform int uHueSatEnabled;
uniform ivec3 uHueSatDivisions;
uniform int uHueSatEncoding;
uniform int uHueSatSupportOverrange;
uniform int uUseMaxRgbInput;
uniform int uWriteCellSamples;
uniform int uWarpCount;
@@ -135,12 +137,13 @@ internal object DngHdrProfileGainTableGpuShaders {
uHueSatMap,
uHueSatDivisions,
uHueSatEncoding,
false
uHueSatSupportOverrange != 0
);
}
profileRgb = clamp(profileRgb, 0.0, 1.0) * uBaselineGain;
float rgbMin = min(profileRgb.r, min(profileRgb.g, profileRgb.b));
float rgbMax = max(profileRgb.r, max(profileRgb.g, profileRgb.b));
if (uUseMaxRgbInput != 0) return rgbMax;
return max(
0.1495 * profileRgb.r +
0.2935 * profileRgb.g +
@@ -5,7 +5,7 @@ import kotlin.math.ln
import kotlin.math.min
/**
* GLES 3.1 compute passes for the Photon Local Laplacian + scalar Google BGU pipeline.
* GLES 3.1 compute passes for the Photon max-RGB Local Laplacian + scalar Google BGU pipeline.
*
* The equations and boundary handling intentionally mirror [DngPhotonLocalToneMapper]. Each
* pyramid level occupies a disjoint range in one SSBO so a pass can read one level and write the
@@ -472,8 +472,8 @@ internal object DngPhotonLocalToneMapGpuShaders {
);
float filteredLog = minimumLog +
reconstructed[uSourceOffset + index] * (maximumLog - minimumLog);
// Local Laplacian operates on the already-exposed input. Its reconstructed
// linear radiance is the definitive SDR target; no second global curve follows it.
// Photon PGTM has a normalized SDR output contract. Keep max RGB inside that
// contract before later nonlinear profile stages can change channel ratios.
target[index] = clamp(exp(filteredLog) - SOURCE_EPS, 0.0, 1.0);
}
""".trimIndent()
@@ -27,7 +27,7 @@ import kotlin.math.roundToInt
* Photon local tone mapping for DNG ProfileGainTableMap.
*
* Algorithm lineage:
* 1. Paris/Hasinoff/Kautz Local Laplacian HDR remapping in log luminance.
* 1. Paris/Hasinoff/Kautz Local Laplacian HDR remapping on Photon max-RGB intensity.
* 2. Aubry et al. intensity-discretized Local Laplacian evaluation.
* 3. Google's fit-and-slice affine bilateral grid (BGU).
*
@@ -126,9 +126,10 @@ internal object DngPhotonLocalToneMapper {
}
/**
* Fast general Local Laplacian evaluation from llf_general.m. [exposureGain] already contains
* BaselineExposure and the fixed ACR3 +1.1 EV placement. The middle 99% determines only the
* Local Laplacian large-edge slope; reconstructed linear radiance is the final SDR target.
* Fast general Local Laplacian evaluation from llf_general.m. The caller supplies max-RGB
* intensity, and [exposureGain] already contains BaselineExposure and the fixed ACR3 +1.25 EV
* placement. The middle 99% determines the Local Laplacian large-edge slope. Reconstructed
* max-RGB intensity is bounded to Photon PGTM's normalized SDR output contract.
*/
internal fun localLaplacianToneMap(
source: FloatArray,
@@ -13,6 +13,8 @@ internal object DngPhotonProfileGainTableGenerator {
private const val MIN_TABLE_GAIN = 1f / 4096f
private const val MAX_TABLE_GAIN = 4096f
internal val MAX_RGB_INPUT_WEIGHTS = floatArrayOf(0f, 0f, 0f, 0f, 1f)
fun plan(
grid: HdrPgtmGrid,
pointCount: Int,
@@ -35,8 +37,8 @@ internal object DngPhotonProfileGainTableGenerator {
// DNG renderers include BaselineExposure before calculating the table coordinate.
// Dividing the weights by that exact gain makes the BGU guide the sampled source-linear
// scene input, while the gain itself still acts on the exposed signal.
val mapWeights = FloatArray(DngHdrProfileGainTableGenerator.BASE_INPUT_WEIGHTS.size) {
DngHdrProfileGainTableGenerator.BASE_INPUT_WEIGHTS[it] / exposureGain
val mapWeights = FloatArray(MAX_RGB_INPUT_WEIGHTS.size) {
MAX_RGB_INPUT_WEIGHTS[it] / exposureGain
}
return HdrProfileGainTablePlan(
curveModel = HdrPgtmCurveModel.PHOTON,
@@ -60,9 +62,13 @@ internal object DngPhotonProfileGainTableGenerator {
* Parameters copied from the published Local Laplacian and Google BGU reference code.
*
* The Local Laplacian edge slope is the compression ratio required to reach the reference target
* dynamic range. ACR3's fixed +1.1 EV gray placement is applied to scene-linear input before Local
* dynamic range. ACR3's fixed +1.25 EV gray placement is applied to scene-linear input before Local
* Laplacian; scene highlights therefore do not determine exposure. The resulting SDR target is
* then projected directly into ProfileGainTableMap's RGB-uniform multiplicative representation.
* Photon uses max RGB as both the Local Laplacian intensity and the DNG table coordinate, so the
* gain follows and bounds the brightest channel without changing RGB ratios. A luma-like guide
* can reach one while a saturated channel is still far above one after gain, which turns
* downstream profile rendering into a color-changing operation.
* The MATLAB example's final display gamma is omitted because output encoding is performed by the
* renderer after the DNG profile pipeline.
*/
@@ -449,6 +449,7 @@ class RawDemosaicProcessor {
useProfileExposureRamp = true,
applyProfileDcpBaselineExposureOffset = false,
supportProfileOverrange = false,
hueSatMapSupportsOverrange = false,
) != null
val warmedProfileMap = when (profileToneMapMode) {
RawProfileToneMapMode.Photon,
@@ -464,6 +465,7 @@ class RawDemosaicProcessor {
colorCorrectionMatrix = identity,
cameraWhite = metadata.cameraWhite,
hueSatMap = null,
hueSatMapSupportsOverrange = false,
)
else -> null
@@ -492,6 +494,7 @@ class RawDemosaicProcessor {
profileBaselineExposureOffsetEv = 0f,
clampProfileRgb = true,
supportProfileOverrange = false,
hueSatMapSupportsOverrange = false,
label = "CaptureWarmupLinearRcdPass",
)
PLog.d(
@@ -854,6 +857,7 @@ class RawDemosaicProcessor {
val applyDcpBaselineExposureOffset: Boolean,
val clampProfileRgb: Boolean,
val supportProfileOverrange: Boolean,
val hueSatMapSupportsOverrange: Boolean,
val hncsCameraDomainGains: FloatArray?,
val colorEngine: RawRenderingEngine,
val activeDcpRenderPlan: DcpRenderPlan?,
@@ -1879,6 +1883,9 @@ class RawDemosaicProcessor {
?: actualMetadata.colorCorrectionMatrix,
cameraWhite = resolvedDcpRenderPlan?.cameraWhite ?: actualMetadata.cameraWhite,
hueSatMap = resolvedDcpRenderPlan?.hueSatMap,
hueSatMapSupportsOverrange =
requestedProfileToneMapMode != RawProfileToneMapMode.Photon &&
resolvedDcpRenderPlan?.supportsOverrange == true,
warpRectilinear = dngWarpRectilinear,
)?.takeIf { it.isValid }
if (generated != null) {
@@ -1998,8 +2005,23 @@ class RawDemosaicProcessor {
val applyDcpBaselineExposureOffset =
shouldApplyDcpBaselineExposureOffset(activeDcpRenderPlan)
val useProfileExposureRamp = useAdobeProfilePipeline
val photonPgtmNormalizedSdr = profileGainToneMapActive &&
requestedProfileToneMapMode == RawProfileToneMapMode.Photon
val supportProfileOverrange =
useAdobeProfilePipeline && activeDcpRenderPlan?.supportsOverrange == true
useAdobeProfilePipeline &&
!photonPgtmNormalizedSdr &&
activeDcpRenderPlan?.supportsOverrange == true
val hueSatMapSupportsOverrange = useAdobeProfilePipeline && if (
photonPgtmNormalizedSdr
) {
false
} else if (
profileGainToneMapActive
) {
profileBaseDcpRenderPlan?.supportsOverrange == true
} else {
activeDcpRenderPlan?.supportsOverrange == true
}
val clampProfileRgb = useAdobeProfilePipeline
val engineWorkingColorSpace = colorEngine.workingColorSpace
val profileToEngineTransform = computeWorkingToOutputTransform(
@@ -2057,7 +2079,8 @@ class RawDemosaicProcessor {
profileToEngineTransform = profileToEngineTransform,
useAdobeProfilePipeline = useAdobeProfilePipeline,
useProfileExposureRamp = useProfileExposureRamp,
applyDcpBaselineExposureOffset = applyDcpBaselineExposureOffset
applyDcpBaselineExposureOffset = applyDcpBaselineExposureOffset,
hueSatMapSupportsOverrange = hueSatMapSupportsOverrange,
)
PLog.d(
TAG,
@@ -2183,6 +2206,7 @@ class RawDemosaicProcessor {
useProfileExposureRamp = useProfileExposureRamp,
applyProfileDcpBaselineExposureOffset = applyDcpBaselineExposureOffset,
supportProfileOverrange = supportProfileOverrange,
hueSatMapSupportsOverrange = hueSatMapSupportsOverrange,
hncsCameraDomainGains = hncsCameraDomainGains,
)
}
@@ -2211,6 +2235,7 @@ class RawDemosaicProcessor {
colorCorrectionMatrix = linearColorCorrectionMatrix,
cameraWhite = linearCameraWhite,
hueSatMap = activeDcpRenderPlan?.hueSatMap,
hueSatMapSupportsOverrange = hueSatMapSupportsOverrange,
warpRectilinear = dngWarpRectilinear,
)
else -> null
@@ -2296,6 +2321,7 @@ class RawDemosaicProcessor {
applyDcpBaselineExposureOffset = applyDcpBaselineExposureOffset,
clampProfileRgb = clampProfileRgb,
supportProfileOverrange = supportProfileOverrange,
hueSatMapSupportsOverrange = hueSatMapSupportsOverrange,
hncsCameraDomainGains = hncsCameraDomainGains,
colorEngine = colorEngine,
activeDcpRenderPlan = activeDcpRenderPlan,
@@ -2401,6 +2427,7 @@ class RawDemosaicProcessor {
},
clampProfileRgb = clampProfileRgb,
supportProfileOverrange = supportProfileOverrange,
hueSatMapSupportsOverrange = hueSatMapSupportsOverrange,
hncsCameraDomainGains = hncsCameraDomainGains,
label = "LinearRcdPass"
)
@@ -2797,6 +2824,7 @@ class RawDemosaicProcessor {
},
clampProfileRgb = config.clampProfileRgb,
supportProfileOverrange = config.supportProfileOverrange,
hueSatMapSupportsOverrange = config.hueSatMapSupportsOverrange,
hncsCameraDomainGains = config.hncsCameraDomainGains,
globalOriginX = working.left,
globalOriginY = working.top,
@@ -3107,6 +3135,7 @@ class RawDemosaicProcessor {
colorCorrectionMatrix: FloatArray,
cameraWhite: FloatArray,
hueSatMap: DcpHueSatMap?,
hueSatMapSupportsOverrange: Boolean,
warpRectilinear: FloatArray? = null,
): DngProfileGainTableMap? {
if (rawTextureId == 0 || width <= 0 || height <= 0 ||
@@ -3255,6 +3284,10 @@ class RawDemosaicProcessor {
GLES31.glGetUniformLocation(pgtmCellStatsProgram, "uHueSatEncoding"),
activeHueSatMap?.encoding ?: DcpHueSatMap.ENCODING_LINEAR,
)
GLES31.glUniform1i(
GLES31.glGetUniformLocation(pgtmCellStatsProgram, "uHueSatSupportOverrange"),
if (hueSatMapSupportsOverrange) 1 else 0,
)
GLES31.glUniform2i(
GLES31.glGetUniformLocation(pgtmCellStatsProgram, "uImageSize"),
rawTextureWidth,
@@ -3299,6 +3332,10 @@ class RawDemosaicProcessor {
GLES31.glGetUniformLocation(pgtmCellStatsProgram, "uBaselineGain"),
if (curveModel == HdrPgtmCurveModel.PHOTON) 1f else exposureGain,
)
GLES31.glUniform1i(
GLES31.glGetUniformLocation(pgtmCellStatsProgram, "uUseMaxRgbInput"),
if (curveModel == HdrPgtmCurveModel.PHOTON) 1 else 0,
)
GLES31.glUniform1f(
GLES31.glGetUniformLocation(pgtmCellStatsProgram, "uHighlightThreshold"),
if (curveModel == HdrPgtmCurveModel.PHOTON) 1f / exposureGain else 0.92f,
@@ -3388,6 +3425,8 @@ class RawDemosaicProcessor {
"grid=${gridWidth}x$gridHeight samplesPerPixel=$samplesPerPixel " +
"lsc=${lensShadingLogString(metadata)} " +
"warpCount=${activeWarpParameters.size / 8} " +
"photonGuide=maxRgb " +
"hueSatOverrange=$hueSatMapSupportsOverrange " +
"photonBaselineGain=${photonPlan.exposureGain} " +
"photonPreToneMapGain=$photonPreToneMapGain " +
"photonLlfLevels=${photonPlan.parameters.localLaplacianIntensityLevels} " +
@@ -4893,7 +4932,7 @@ class RawDemosaicProcessor {
uniform float uHncsHrMax;
uniform int uClampProfileRgb;
uniform int uClampProfileGainOutput;
uniform int uProfileSupportOverrange;
uniform int uHueSatSupportOverrange;
uniform int uProfileGainEnabled;
uniform ivec3 uProfileGainTableSize;
uniform vec4 uProfileGainGrid;
@@ -4994,7 +5033,7 @@ class RawDemosaicProcessor {
uLinearDcpHueSatMap,
uLinearDcpHueSatDivisions,
uLinearDcpHueSatEncoding,
uProfileSupportOverrange != 0
uHueSatSupportOverrange != 0
);
}
vec3 profileInputRgb = rgb * uProfileGainBaselineGain;
@@ -10483,9 +10522,9 @@ class RawDemosaicProcessor {
workingColorSpace = basePlan?.workingColorSpace ?: workingColorSpace,
baselineExposureOffset = basePlan?.baselineExposureOffset ?: 0f,
defaultBlackRender = basePlan?.defaultBlackRender ?: DcpDefaultBlackRender.None,
// Photon endpoint normalization may require a value above 1 before a negative
// BaselineExposure gain. Preserve it until exposure and the tone curve are applied.
supportsOverrange = mode == RawProfileToneMapMode.Photon ||
// Photon PGTM has a normalized SDR contract. Do not inherit profile overrange:
// later nonlinear profile stages would otherwise change highlight channel ratios.
supportsOverrange = mode != RawProfileToneMapMode.Photon &&
basePlan?.supportsOverrange == true,
colorCorrectionMatrix = basePlan?.colorCorrectionMatrix ?: metadata.colorCorrectionMatrix,
cameraWhite = basePlan?.cameraWhite ?: metadata.cameraWhite,
@@ -10566,7 +10605,8 @@ class RawDemosaicProcessor {
profileToEngineTransform: FloatArray,
useAdobeProfilePipeline: Boolean,
useProfileExposureRamp: Boolean,
applyDcpBaselineExposureOffset: Boolean
applyDcpBaselineExposureOffset: Boolean,
hueSatMapSupportsOverrange: Boolean,
) {
if (profilePlanSource == null) return
@@ -10607,6 +10647,7 @@ class RawDemosaicProcessor {
"profileToneCurve=$profileToneCurveEnabled " +
"profileExposureRamp=$useProfileExposureRamp " +
"profileSupportsOverrange=${dcpRenderPlan?.supportsOverrange == true} " +
"hueSatSupportsOverrange=$hueSatMapSupportsOverrange " +
"defaultBlackRender=$defaultBlackRender " +
"baselineExposureOffset=$dcpBaselineExposureOffset " +
"cameraWhite=${cameraWhite.contentToString()} " +
@@ -10730,6 +10771,7 @@ class RawDemosaicProcessor {
profileBaselineExposureOffsetEv: Float,
clampProfileRgb: Boolean,
supportProfileOverrange: Boolean,
hueSatMapSupportsOverrange: Boolean,
hncsCameraDomainGains: FloatArray? = null,
globalOriginX: Int = 0,
globalOriginY: Int = 0,
@@ -10829,8 +10871,8 @@ class RawDemosaicProcessor {
if (clampProfileRgb && !supportProfileOverrange) 1 else 0
)
GLES30.glUniform1i(
GLES30.glGetUniformLocation(linearRcdProgram, "uProfileSupportOverrange"),
if (supportProfileOverrange) 1 else 0
GLES30.glGetUniformLocation(linearRcdProgram, "uHueSatSupportOverrange"),
if (hueSatMapSupportsOverrange) 1 else 0
)
GLES30.glUniform2f(
GLES30.glGetUniformLocation(linearRcdProgram, "uGlobalUvOrigin"),
@@ -11053,6 +11095,7 @@ class RawDemosaicProcessor {
useProfileExposureRamp: Boolean,
applyProfileDcpBaselineExposureOffset: Boolean,
supportProfileOverrange: Boolean,
hueSatMapSupportsOverrange: Boolean,
hncsCameraDomainGains: FloatArray? = null,
): Float? {
val previewSize = resolveLongEdgePreviewSize(
@@ -11088,6 +11131,7 @@ class RawDemosaicProcessor {
profileBaselineExposureOffsetEv = profileBaselineExposureOffsetEv,
clampProfileRgb = clampProfileRgb,
supportProfileOverrange = supportProfileOverrange,
hueSatMapSupportsOverrange = hueSatMapSupportsOverrange,
hncsCameraDomainGains = hncsCameraDomainGains,
label = "AdobeExposurePreviewLinearPass"
)
@@ -11163,6 +11207,7 @@ class RawDemosaicProcessor {
profileBaselineExposureOffsetEv = profileBaselineExposureOffsetEv,
clampProfileRgb = clampProfileRgb,
supportProfileOverrange = supportProfileOverrange,
hueSatMapSupportsOverrange = hueSatMapSupportsOverrange,
hncsCameraDomainGains = hncsCameraDomainGains,
label = "LinearExposurePreviewPass"
)
@@ -30,7 +30,7 @@ class DngPhotonProfileGainTableGeneratorTest {
}
@Test
fun dngCoordinatesUseSourceLinearGuideAtTileCenters() {
fun dngCoordinatesUseMaxRgbGuideAtTileCenters() {
val plan = plan(
gridWidth = 4,
gridHeight = 2,
@@ -48,7 +48,7 @@ class DngPhotonProfileGainTableGeneratorTest {
assertEquals(0.375, plan.grid.mapSpacingV, 0.0)
assertEquals(0.3125, plan.grid.mapOriginH, 0.0)
assertEquals(0.3125, plan.grid.mapOriginV, 0.0)
DngHdrProfileGainTableGenerator.BASE_INPUT_WEIGHTS.forEachIndexed { index, weight ->
DngPhotonProfileGainTableGenerator.MAX_RGB_INPUT_WEIGHTS.forEachIndexed { index, weight ->
assertEquals(weight / exposureGain, plan.mapInputWeights[index], 1e-7f)
}
val map = requireNotNull(
@@ -90,6 +90,28 @@ class DngPhotonProfileGainTableGeneratorTest {
}
}
@Test
fun localLaplacianClampsSparsePeakBeforeNonlinearProfileStages() {
val width = 16
val height = 16
val source = FloatArray(width * height) { 0.1f }
source[source.lastIndex] = 1f
val result = DngPhotonLocalToneMapper.localLaplacianToneMap(
source = source,
width = width,
height = height,
exposureGain = 2f,
parameters = PhotonLocalToneMappingParameters(
targetDynamicRange = 1_000_000f,
),
)
assertEquals(0.2f, result.target.first(), 2e-4f)
assertEquals(1f, result.target.last(), 0f)
assertEquals(0, result.target.count { it > 1f })
}
private fun plan(
gridWidth: Int,
gridHeight: Int,
+16 -11
View File
@@ -18,14 +18,14 @@
| 阶段 | 参考实现 | Photon 实现 | 差异 |
| --- | --- | --- | --- |
| 输入域 | `lapfilter.m`: `log(I + eps)` | RAW 先执行与 demosaic 相同的 Lens Shading Correction 和 WarpRectilinear 空间映射,再变换为 source-linear scene input;进入 Local Laplacian 前固定乘 `BaselineExposure × 2^1.1` | `+1.1 EV` 是 ACR3 灰点曝光,在线性 0.18 上得到 `0.18 × 2^1.1`,顺序在 LTM 之前;RAW 可以精确为 0,因此保留 `1e-6` 正值到 log 域;统计域和最终应用域使用同一 LSC/warp |
| 输入域 | `lapfilter.m`: `log(I + eps)` | RAW 先执行与 demosaic 相同的 Lens Shading Correction 和 WarpRectilinear 空间映射,再变换为 profile RGB 并取 `max(R,G,B)`;进入 Local Laplacian 前固定乘 `BaselineExposure × 2^1.25` | `+1.25 EV` 是固定灰点曝光,顺序在 LTM 之前;max RGB 使 PGTM 的公共标量 gain 以最亮颜色通道为准,不改变 RGB 比例;RAW 可以精确为 0,因此保留 `1e-6` 正值到 log 域 |
| HDR remap | `sigma_r=log(2.5)`, `alpha=1`;HDR 展示脚本手工选择 `beta=0` | `sigma_r`、`alpha` 相同;`beta=min(1, log(100)/log(input DR))` | 官方 API 把 `beta` 定义为 large-edge slope;展示脚本的 `0` 是特定 HDR 图的最强压缩参数,不是通用自动参数。Photon 直接用达到相同目标 DR 所需的全局压缩比,无需调参;输入 DR≤100 时为恒等斜率 1 |
| 强度离散 | `llf_general.m` general remap 示例 `N=20` | 20 个等距 reference levels | 无 |
| 金字塔层数 | `ceil(log(min(h,w))-log(2))+2` | 相同,并受实际可构造层数约束 | 只防止尺寸小于公式要求 |
| 金字塔核 | `[.05,.25,.4,.25,.05]`,越界样本重新归一化 | GPU pass 直接计算可分离核的二维外积 | 数学上与先横后纵相同,减少一次中间写入和 dispatch |
| Laplacian residual | 最粗层直接取输入 Gaussian residual | 相同 | 无 |
| HDR 输出范围 | 展示脚本在 LTM 后按 99.5% 分位归一化并执行显示 gamma | `beta=min(1, log(100)/log(input DR))` 已在 Local Laplacian 内完成 large-edge 压缩;重建后的线性 radiance 直接 clamp 为 SDR target | 不再执行会抵消固定预曝光的 `R/Rmax`,也不在 LTM 后增加第二条 compression/pivot 曲线;tone curve 和输出编码由后续 profile renderer 执行 |
| BGU guide | Google BGU:`x / lerp(1,x,curve_alpha)`,`curve_alpha=0.8`,`r_sigma=1/8` | 相同;guide 只选择 range plane,仍使用 source-linear input | 无 |
| HDR 输出范围 | 展示脚本在 LTM 后按 99.5% 分位归一化并执行显示 gamma | `beta=min(1, log(100)/log(input DR))` 已在 Local Laplacian 内完成 large-edge 压缩;重建后的 max-RGB radiance clamp 为 SDR target | 不执行会抵消固定预曝光的 `R/Rmax`,也不在 LTM 后增加第二条 compression/pivot 曲线;Photon 不把 overrange 交给后续非线性 profile 阶段 |
| BGU guide | Google BGU:`x / lerp(1,x,curve_alpha)`,`curve_alpha=0.8`,`r_sigma=1/8` | 相同;guide 只选择 range plane,Photon 的 `x` 为 source-linear max RGB | DNG `MapInputWeights=[0,0,0,0,1/BaselineExposure]`,与生成 target 的输入域完全一致 |
| BGU spatial bin | `s_sigma=16` | 每个 DNG 空间点 16×16 个 GPU RAW 样本 | DNG map origin/spacing 由实际 `statsBounds` 归一化,并平移半个 bin,使点精确位于采样 tile 中心 |
| BGU histogram | RGB 3×4 affine normal equations,输入/输出为已完成变换的图像对 | 直接使用 source-linear `I` 与 Local Laplacian 的最终 SDR target `T`,求解 `T/BaselineExposure = gain × I` | BGU 只负责把已经确定的 `(I,T)` 图像对编码成 PGTM,不再定义第二套影调;DNG PGTM 只能存 RGB 共用乘法 gain,因此去掉 affine intercept,避免写表后退化为 `b/x` |
| BGU blur | 7 taps:中心 `1`,距离 1/2/3 为 `1/8,1/27,1/64` | 相同,按 z/y/x 分离执行 | 无 |
@@ -37,26 +37,31 @@
1. `DNG_PGTM_CELL_STATS` 在 GPU 上从最终输出坐标反向组合有效 DNG WarpRectilinear
opcodes,再从 RAW 读取与 demosaic 完全相同的 DNG/Camera2 Lens Shading Gain,经
ColorMatrix 和 HueSatMap 得到 scene input;每个空间 tile 保留 16×16 个有序空间样本。
ColorMatrix 和 HueSatMap 得到 profile RGB,并以 max RGB 作为 Photon scene input;
每个空间 tile 保留 16×16 个有序空间样本。
2. compute pass 先执行固定线性曝光
`Iₑ = I × BaselineExposure × 2^1.1`,再在 SSBO 中完成 log normalization、20 个强度
reference 的 Gaussian/Laplacian pyramid 和重建;重建 radiance clamp 后就是最终 SDR
target `T`。
`Iₑ = I × BaselineExposure × 2^1.25`,再在 SSBO 中完成 log normalization、20 个强度
reference 的 Gaussian/Laplacian pyramid 和重建;重建 max-RGB radiance clamp 后就是
最终 SDR target `T`。
3. GPU histogram 只统计预曝光输入的 0.5%/50%/99.5% 分位数;CPU 扫描一个
32768-bin 计数表,计算 Local Laplacian large-edge slope。LTM 后不再估算曝光或生成
全局 compression 曲线。
4. 标量 BGU 直接以 `I` 为 guide/fit input,以 `T/BaselineExposure` 为 fit target,
经过 z/y/x 7-tap blur 后求解过原点的 gain;它只把已经完成的 LTM 结果投影到 DNG
可表达的乘法模型。
4. 标量 BGU 直接以 max RGB `I` 为 guide/fit input,以 `T/BaselineExposure` 为 fit
target,经过 z/y/x 7-tap blur 后求解过原点的 gain;DNG 查表使用相同的 max RGB
coordinate,并把所得单一 gain 同乘 RGB,因此不会在 PGTM 内改变色相或饱和度。
5. GPU slice 每个空间格的 257 个 DNG gain 点;CPU 只回读最终 gain table 并封装 DNG
metadata,DNG renderer 在空间和输入强度上插值。
Photon PGTM 使用归一化 SDR contract:Local Laplacian target、PGTM gain 输出、
HueSatMap、曝光和 ProfileToneCurve 均不启用 overrange。Google PGTM 和普通 DCP
仍按各自 profile 的能力决定 overrange。
`DngPhotonLocalToneMapper` 保留为可读的 CPU 方程参考,不在拍摄生产路径调用。
## 全局曲线职责
Photon `ProfileToneCurve` 只负责 profile 的全局输出风格,不接收场景统计量。RAW 默认
亮度由 Local Tone Mapping 之前的固定 `+1.1 EV` 建立。PGTM 只编码 Local Laplacian
亮度由 Local Tone Mapping 之前的固定 `+1.25 EV` 建立。PGTM 只编码 Local Laplacian
已经产生的 SDR target;tone curve 不参与曝光估计,只提供基础的全局输出风格。
旧实现中的全局 gray pivot、global shoulder、highlight pressure、cell contrast warp 和