关于「线性光与相对亮度:WCAG 对比度算了什么、没算什么」,《色觉缺陷模拟与配色可辨性》给出的定量结论是什么?

结论:表的下半部分更值得注意。编码 128 看起来是「中灰」,归一化后是 0.5020,可它携带的线性光只有 0.2159,约为白色的五分之一。要得到一半的线性光,需要编码 188,其线性值为 0.5029。编码 119 的线性值为 0.1845,这个数后面会反复出现:它非常接近白字与黑字都勉强合格的那个亮度。编码 64 的线性值是 0.0513,编码 11 只有 0.0033。

数据口径:书中参数为示意;全部计算由书中程序生成;模拟不对应任何具体的人,本书不对任何个人的色觉作判断,属于非个人化经营建议。 本书用色觉模拟与色差计算推翻这条推理。

English version

对照数据表

下表数字由本章 Python 程序原样打印,可重新运行复现。 程序只用 Python 标准库与结论吻合的打印值: 0.0033, 0.0513, 0.1845, 0.2159, 0.5020, 0.5029

8-bit codes between the two thresholds0
largest change in linear value over 256 codes0.0e+00
code 100.039, code 11 -> 0.043 (as fraction of 255)
code encoded linear (linear share of white)
00.0000 0.0000
110.0431 0.0033
640.2510 0.0513
1190.4667 0.1845
1280.5020 0.2159
1880.7373 0.5029
2551.0000 1.0000
code nearest half the light188 (0.5029)
code 128 carries only 0.2159 of white
查看完整验算程序
# Chapter 2. p21: the sRGB transfer curve and the WCAG threshold change.
# Model: IEC 61966-2-1 sRGB decoding; WCAG 2.2 notes that its threshold
# 0.04045 replaced 0.03928 in May 2021. We check every 8-bit code with
# both thresholds and print where mid-grey sits in linear light.
import math


def lin(c):
    v = c / 255.0
    if v <= 0.04045:
        return v / 12.92
    return ((v + 0.055) / 1.055) ** 2.4


def rgb(h):
    h = h.lstrip("#")
    return tuple(lin(int(h[i:i + 2], 16)) for i in (0, 2, 4))


def lum(c):
    return math.fsum((0.2126 * c[0], 0.7152 * c[1], 0.0722 * c[2]))


def contrast(a, b):
    hi, lo = sorted((lum(a), lum(b)), reverse=True)
    return (hi + 0.05) / (lo + 0.05)

def lin_old(c):
    v = c / 255.0
    if v <= 0.03928:
        return v / 12.92
    return ((v + 0.055) / 1.055) ** 2.4


if __name__ == "__main__":
    diff = [abs(lin(c) - lin_old(c)) for c in range(256)]
    between = [c for c in range(256)
               if 0.03928 < c / 255.0 <= 0.04045]
    print("8-bit codes between the two thresholds: {}".format(len(between)))
    print("largest change in linear value over 256 codes: {:.1e}".format(
        max(diff)))
    print("code 10 -> {:.3f}, code 11 -> {:.3f} (as fraction of 255)"
          .format(10 / 255.0, 11 / 255.0))
    print("code   encoded  linear   (linear share of white)")
    for c in (0, 11, 64, 119, 128, 188, 255):
        print("{:4d}   {:7.4f}  {:7.4f}".format(c, c / 255.0, lin(c)))
    half = min(range(256), key=lambda c: abs(lin(c) - 0.5))
    print("code nearest half the light: {} ({:.4f})".format(half,
                                                           lin(half)))
    print("code 128 carries only {:.4f} of white".format(lin(128)))

唯一数据源与引用

范雅福(Fan, Y.). (2026). 《色觉缺陷模拟与配色可辨性、红绿色弱用户眼中的按钮与图表母典》第 2 章「线性光与相对亮度:WCAG 对比度算了什么、没算什么」(版本 1.0.0). 5D Library. DOI 待发布

DOI 待发布 · 专著页正式发布后上线(本站暂无专著页) · 5DL-B-324 · v1.0.0 · CC-BY-NC-ND-4.0

BibTeX
@book{fan2026324,
  author    = {Fan, Yafu},
  title     = {Simulating Colour-Vision Deficiency and Colour Discriminability: Buttons and Charts as Seen by Red-Green Colour-Deficient Users},
  year      = {2026},
  publisher = {5D Library},
  edition   = {1.0.0},
  note      = {DOI pending}
}

本书其他章节结论