From 7946313a6963790a96b141e609635aeb9d8af1d7 Mon Sep 17 00:00:00 2001 From: zhoubinjia Date: Thu, 17 Sep 2026 18:17:27 +0800 Subject: [PATCH] fix: Bento slice spatial merge weight --- .../processor/GlesMgcRawSpatialStacker.kt | 30 +++++++++++++++++-- .../canon-rendering-engine-integration.md | 20 ++++++------- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/hinnka/mycamera/processor/GlesMgcRawSpatialStacker.kt b/app/src/main/java/com/hinnka/mycamera/processor/GlesMgcRawSpatialStacker.kt index 2b58d68b..0d3d49ff 100644 --- a/app/src/main/java/com/hinnka/mycamera/processor/GlesMgcRawSpatialStacker.kt +++ b/app/src/main/java/com/hinnka/mycamera/processor/GlesMgcRawSpatialStacker.kt @@ -1201,9 +1201,32 @@ internal class GlesMgcRawSpatialStacker( if (assessment.accepted) { bentoAccepted = true acceptedBentoExposureRatio = exposureRatio - bentoCalibration = normalizedCalibration + // V25 SpatialMerge (0x367abf4) replaces the accepted Bento slice's + // MaximumMergeWeight with 1, then derives its kernel sigma from that + // weight. Keeping the exposure-scaled noise weight here makes an R8 + // mask's last step to 1 abruptly switch from clipped base to ultrashort. + // Share this calibration with Bayer/RGB merge and strength capture so + // their weights and kernel sigmas describe the same selected frame. + val selectedMergeWeight = SPATIAL_IDENTITY_MULTIPLIER + val selectedCalibration = normalizedCalibration.copy( + globalFrameWeight = selectedMergeWeight, + rejectionWeightScale = selectedMergeWeight, + kernelSigma = MgcSpatialMergeTuning.kernelSigma( + baseSpatialScale = bayerKernelTuning.baseSpatialScale, + mergeWeight = selectedMergeWeight, + ), + ) + bentoCalibration = selectedCalibration bentoFlowTexture = flow.texture bentoBayerAlignmentTexture = bayerAlignment + PLog.i( + TAG, + "MGC Bento selected calibration index=$ultrashortIndex " + + "noiseWeight=${normalizedCalibration.globalFrameWeight} " + + "mergeWeight=${selectedCalibration.globalFrameWeight} " + + "kernelSigma=${selectedCalibration.kernelSigma} " + + "inputGain=${selectedCalibration.inputGain}", + ) } bentoPostAlignNs = System.nanoTime() - postAlignStartNs } finally { @@ -3664,8 +3687,9 @@ internal class GlesMgcRawSpatialStacker( ) val globalFrameWeight = if (processorPipeline == MgcRawProcessorPipeline.SPATIAL) { // V25 SpatialMerge stores sub_38B1274's shadow-domain MaximumMergeWeight in the - // frame_weights buffer consumed by MergeRgbRaw16F16. The signal-domain expected - // weight is computed only for the diagnostic table and is not the AOT input. + // frame_weights buffer consumed by MergeRgbRaw16F16, except that the accepted + // Bento frame is overridden after assessment. The signal-domain expected weight + // is computed only for the diagnostic table and is not the AOT input. MgcSpatialMergeTuning.maximumMergeWeight( baseReadVariance = kernelTuning.referenceGreenReadVariance, alternateReadVariance = sourceRead.getOrElse(1) { 0f }, diff --git a/docs/research/canon-rendering-engine-integration.md b/docs/research/canon-rendering-engine-integration.md index 30caa163..867b3154 100644 --- a/docs/research/canon-rendering-engine-integration.md +++ b/docs/research/canon-rendering-engine-integration.md @@ -1,6 +1,6 @@ # Canon Picture Style:公共 PGTM 之后的色彩与调性渲染引擎 -> 偏色修正:旧实现错误地使用了 `0x1e58a0`。已由原机型分派确认并替换为 R5 `0x1f5b20`,补齐遗漏的色度参数与 YUV→RGB 节点。详细原因、原生对照与验证范围见 [颜色内核证据](../../research/canon_dpp/r5-color-kernel.md)。 +> 偏色修正:旧实现错误地使用了 `0x1e58a0`。已由原机型分派确认并替换为 R5 `0x1f5b20`,补齐遗漏的色度参数与 YUV→RGB 节点。详细原因、原生对照与验证范围见 [颜色内核证据](../../.codex-tmp/canon_dpp/r5-color-kernel.md)。 2026-09-17。Canon 已接入现有渲染引擎接口,RAW 编辑面板提供 Canon 引擎和六种照片风格选择,设置、照片及预设保存恢复同一风格。EOS R5 最终曲线、完整整数颜色内核和真实 MLIB ICC 链已接入代码。本轮 Kotlin 编译与8类54项JVM测试通过;原指令数值对照及静态shader编译不等同于实机 GPU 验证。 @@ -34,7 +34,7 @@ Canon 不接管 RAW 前端、PGTM、公共曝光或公共 HDR。DPP `HDRProcessM `RawRenderingEngine.Canon` 使用 shader ID 8、线性曝光语义和默认额外曝光 0 EV。`RawEditPanel.kt` 的引擎列表包含 Canon;选中后显示 `CanonPictureStyleSelector`。`PresetEditorScreen.kt` 同样提供引擎和风格选择,并从原预设恢复、保存当前选项。名称及说明使用多语言资源。 -`RawToneMappingParameters.canonPictureStyle` 贯通 DataStore 的读取、单项保存和批量保存,照片 JSON、Room 字段与预设映射。DataStore 键为 `raw_canon_picture_style`;Room 已加入 43→44 迁移;旧记录或未知持久化值回到 Standard。拍摄和照片重编辑使用该参数构建相同类型的 render plan,具体数据通路见 [配置审计](../../research/canon_dpp/app-config-audit.md)。 +`RawToneMappingParameters.canonPictureStyle` 贯通 DataStore 的读取、单项保存和批量保存,照片 JSON、Room 字段与预设映射。DataStore 键为 `raw_canon_picture_style`;Room 已加入 43→44 迁移;旧记录或未知持久化值回到 Standard。拍摄和照片重编辑使用该参数构建相同类型的 render plan,具体数据通路见 [配置审计](../../.codex-tmp/canon_dpp/app-config-audit.md)。 仅开放这六种风格。Auto、Fine Detail、User1–3、AtCapture 和 PF2/PF3 导入不在当前支持范围。原生 Canon 对比度、色调、饱和度以及 Mono 滤镜/调色固定为本次导出配方的中性/关闭值,没有宣称开放这些参数的独立控件。App 公共调整继续位于原有位置,不能据参数名称相似就等同为 DPP 原生调整。 @@ -44,11 +44,11 @@ Canon 提供独立的宿主曝光设置 `canonExposureCompensationEv`,默认 固定目标为 EOS R5,ModelID `0x80000421`、原模型索引 `0x67`。`EquivalentCameraCalibration` 复用公共源标定,把 PGTM/曝光后的 ProPhoto 转为目标白平衡 camera RGB。源白平衡、曝光均已消费,Canon 不再重复执行。 -目标配方固定 ISO100,原生属性 `0x1000a` 与公开属性 `0x10026` 必须同时提供。Model provider 实际读取前者;只提供后者会退到 ISO0 分支,生成错误的 `gamma_c`,造成亮度基本正常但色彩不够鲜艳。它与手机拍摄 ISO 无关,不动态套用手机 ISO。`CanonProfile` 加载时验证这一来源契约;原指令、真实 R5 RAW/JPG 对照见 [ISO 配方审计](../../research/canon_dpp/iso-property-audit.md)。 +目标配方固定 ISO100,原生属性 `0x1000a` 与公开属性 `0x10026` 必须同时提供。Model provider 实际读取前者;只提供后者会退到 ISO0 分支,生成错误的 `gamma_c`,造成亮度基本正常但色彩不够鲜艳。它与手机拍摄 ISO 无关,不动态套用手机 ISO。`CanonProfile` 加载时验证这一来源契约;原指令、真实 R5 RAW/JPG 对照见 [ISO 配方审计](../../.codex-tmp/canon_dpp/iso-property-audit.md)。 目标标定在 `assets/canon/eos_r5/calibration.json`,来源是有 SHA 记录的 `Canon EOS R5 Adobe Standard.dcp`,**仅使用 ColorMatrix 与标定光源**。不使用 Adobe tone curve、LookTable 或风格处理。它负责不同相机之间的三通道线性颜色域适配;Canon Picture Style 来自 Canon 原生资源。矩阵标定不能消除不同传感器光谱响应的一切差异,不能据此宣称手机输入与真实 R5 RAW 完全等价。 -标称线性白 1 映射至原 14-bit 白码 **16383**。shader 将输入乘以 16383,截断到整数并限于 UInt16 范围,保留超过标称白的输入,再按原内核执行其内部限幅。没有猜测的 EV 补偿。原 `0x056be0` 生成的默认色阶块为 312 字节,见 [levels-20302.bin](../../research/canon_dpp/r5-model-recipes/levels-20302.bin)。 +标称线性白 1 映射至原 14-bit 白码 **16383**。shader 将输入乘以 16383,截断到整数并限于 UInt16 范围,保留超过标称白的输入,再按原内核执行其内部限幅。没有猜测的 EV 补偿。原 `0x056be0` 生成的默认色阶块为 312 字节,见 [levels-20302.bin](../../.codex-tmp/canon_dpp/r5-model-recipes/levels-20302.bin)。 原 RawRecipe 在缺失第四输入平面时用 `0x027990` 从同一输入 RGB 生成辅助值: @@ -56,7 +56,7 @@ Canon 提供独立的宿主曝光设置 `canonExposureCompensationEv`,默认 aux = (R * 1224 + G * 2404 + B * 468) >> 12 ``` -无额外半舍入、白平衡或 gamma。生产者、通道位置及内核第四平面读取已闭合,详见 [辅助输入证据](../../research/canon_dpp/rawrecipe-auxiliary-input.md)。因此提取的颜色内核无需空间辅助图;该辅助值直接由当前像素生成。 +无额外半舍入、白平衡或 gamma。生产者、通道位置及内核第四平面读取已闭合,详见 [辅助输入证据](../../.codex-tmp/canon_dpp/rawrecipe-auxiliary-input.md)。因此提取的颜色内核无需空间辅助图;该辅助值直接由当前像素生成。 ## 实际颜色运算顺序 @@ -73,9 +73,9 @@ aux = (R * 1224 + G * 2404 + B * 468) >> 12 → sRGB 传递函数解码 → 线性 sRGB → 公共输出 ``` -`gamma_y`、`gamma_c` 和 `gamma_uv` 属于有合流关系的亮度与色度支路,不能写成三次串联的 RGB 曲线。`CanonRecipeColorMath.renderR5Pixel` 实现普通入口完整整数函数,`CanonToneAlgorithm` 按同一顺序实现 GLSL。其矩阵、分支、舍入、限幅、符号色差增益及 Mono 系数来自实际内核参数,不用经验 tone curve 或额外转灰代替。详见 [完整颜色内核证据](../../research/canon_dpp/r5-color-kernel.md)。 +`gamma_y`、`gamma_c` 和 `gamma_uv` 属于有合流关系的亮度与色度支路,不能写成三次串联的 RGB 曲线。`CanonRecipeColorMath.renderR5Pixel` 实现普通入口完整整数函数,`CanonToneAlgorithm` 按同一顺序实现 GLSL。其矩阵、分支、舍入、限幅、符号色差增益及 Mono 系数来自实际内核参数,不用经验 tone curve 或额外转灰代替。详见 [完整颜色内核证据](../../.codex-tmp/canon_dpp/r5-color-kernel.md)。 -本次固定配方未启用 DPP RGBRecipe 自定义总曲线/分通道编辑、8Axis 或用户 PF;这些条件性处理不作为额外效果强行加入。DPP 完整调度的研究见 [静态流程](../../research/canon_dpp/RENDER_PIPELINE.md),该图中所有节点并非本引擎的功能要求。 +本次固定配方未启用 DPP RGBRecipe 自定义总曲线/分通道编辑、8Axis 或用户 PF;这些条件性处理不作为额外效果强行加入。DPP 完整调度的研究见 [静态流程](../../.codex-tmp/canon_dpp/RENDER_PIPELINE.md),该图中所有节点并非本引擎的功能要求。 ## 最终 gamma 与原生参数的来源 @@ -91,7 +91,7 @@ aux = (R * 1224 + G * 2404 + B * 468) >> 12 | `chroma_weights.u16le` | 4×1024 个 UInt16,原生生成的色度权重 | | `gamma-manifest.json` | 原 DLL 指纹、配方读取、文件长度与 SHA | -资源位于 `assets/canon/eos_r5/