interpolate-lab gives the same result as RGB interpolate (rgb2xyz/xyz2rgb scale 0-1 channels by 255)

未关闭 适合新手
#13,751 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript
领域
backend, testing

调研方向

从 src/style-spec/util/color_spaces.ts 开始,追踪 Color 通道值经过 rgb2xyz 和 xyz2rgb 的过程;issue 指出该转换应用了不必要的 255 倍缩放。检查 issue 中提到的色彩空间 fixtures,并更新反映当前输出的 fixtures。完成标准是 repro 产生预期的 Lab 和 HCL 值,且没有负通道值。

由索引模型根据 Issue 内容生成。

描述

auto-triaged bug :lady_beetle:
mapbox-gl-js version

style-spec only: @mapbox/mapbox-gl-style-spec 14.34.2 (same code on main 1f3879d)

Browser and version

Not browser specific (Node v26.13.0)

Expected behavior

interpolate-lab and interpolate-hcl interpolate in CIELAB/HCL. For the repro below, MapLibre's style spec (26.5.1, which fixed the same code in maplibre/maplibre-style-spec#94) gives:

lab black->white: [ 0.4663, 0.4663, 0.4663, 1 ]
lab red->blue: [ 0.7568, 0, 0.534, 1 ]
hcl red->blue: [ 0.9606, 0, 0.5259, 1 ]

(d3-interpolate gives the same values to 8-bit precision.)

Actual behavior
lab black->white: [ 0.5, 0.5, 0.5, 1 ]
rgb black->white: [ 0.5, 0.5, 0.5, 1 ]
lab red->blue: [ 0.5, 0, 0.5, 1 ]
hcl red->blue: [ 0.7783, -0.0837, 0.5091, 1 ]

interpolate-lab is identical to interpolate, and interpolate-hcl produces a negative channel (#10054).

Link to the demonstration

Not applicable: reproduced with the style-spec package in Node.

Steps to trigger the unexpected behavior
const { expression } = require("@mapbox/mapbox-gl-style-spec");
const spec = { type: "color", "property-type": "data-driven", expression: { interpolated: true, parameters: ["zoom", "feature"] } };
const ev = (e) => {
  const c = expression.createExpression(e, spec).value.evaluate({ zoom: 0 }, { properties: {} });
  return [c.r, c.g, c.b, c.a].map((v) => +v.toFixed(4));
};

console.log("lab black->white:", ev(["interpolate-lab", ["linear"], 0.5, 0, "black", 1, "white"]));
console.log("rgb black->white:", ev(["interpolate", ["linear"], 0.5, 0, "black", 1, "white"]));
console.log("lab red->blue:", ev(["interpolate-lab", ["linear"], 0.5, 0, "red", 1, "blue"]));
console.log("hcl red->blue:", ev(["interpolate-hcl", ["linear"], 0.5, 0, "red", 1, "blue"]));

src/style-spec/util/color_spaces.ts has x /= 255 in rgb2xyz and 255 * (...) in xyz2rgb, but Color channels are in [0, 1]. The values therefore always fall in the linear segments of the sRGB and Lab transfer functions. Removing the 255 factor in both places fixes it (fixtures generated with the current code would need updating).

Relevant log output

Nothing beyond the output shown in the steps above.

Credit: https://ucsbplse.github.io/

主要语言
TypeScript
星标
12.5k
派生
2.4k
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

mapbox/mapbox-gl-js 的其他 Issue

查看 mapbox/mapbox-gl-js 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。