根据新版本调整set_pattern:0~65535

This commit is contained in:
xinzhu.yin
2026-07-07 18:59:44 +08:00
parent 9fa811a9eb
commit 32aaef1c0f
24 changed files with 3016 additions and 279 deletions

View File

@@ -3,6 +3,13 @@ import json
import copy
from pathlib import Path
from app.solid_color_scale import (
SOLID_COLOR_MAX,
ensure_solid_color_pattern,
pct_to_solid_color,
solid_color_rgb as _rgb,
)
# =============================================================================
# Pattern 文件读写工具统一存储格式settings/patterns/{name}.json
@@ -25,7 +32,7 @@ def load_pattern_file(filepath) -> dict:
}
"""
with open(filepath, encoding="utf-8") as f:
return json.load(f)
return ensure_solid_color_pattern(json.load(f))
def save_pattern_file(filepath, pattern: dict) -> None:
@@ -137,9 +144,9 @@ _PATTERN_RGB = {
"measurement_bit_depth": 8,
"measurement_max_value": 2,
"pattern_params": [
[255, 0, 0], # 红色
[0, 255, 0], # 绿色
[0, 0, 255], # 蓝色
_rgb(255, 0, 0), # 红色
_rgb(0, 255, 0), # 绿色
_rgb(0, 0, 255), # 蓝色
],
}
@@ -149,17 +156,17 @@ _PATTERN_GRAY_FALLBACK = {
"measurement_bit_depth": 8,
"measurement_max_value": 10,
"pattern_params": [
[255, 255, 255], # 100% 白色
[230, 230, 230], # 90%
[205, 205, 205], # 80%
[179, 179, 179], # 70%
[154, 154, 154], # 60%
[128, 128, 128], # 50%
[102, 102, 102], # 40%
[78, 78, 78], # 30%
[52, 52, 52], # 20%
[26, 26, 26], # 10%
[0, 0, 0], # 0% 黑色
_rgb(255, 255, 255), # 100% 白色
_rgb(230, 230, 230), # 90%
_rgb(205, 205, 205), # 80%
_rgb(179, 179, 179), # 70%
_rgb(154, 154, 154), # 60%
_rgb(128, 128, 128), # 50%
_rgb(102, 102, 102), # 40%
_rgb(78, 78, 78), # 30%
_rgb(52, 52, 52), # 20%
_rgb(26, 26, 26), # 10%
_rgb(0, 0, 0), # 0% 黑色
],
}
# 灰阶 pattern 从文件加载,支持用户编辑;文件缺失时回退到硬编码兜底
@@ -171,37 +178,37 @@ _PATTERN_ACCURACY = {
"measurement_max_value": 28, # 29个颜色最大索引是28
"pattern_params": [
# ========== 灰阶 (5个) ==========
[255, 255, 255], # 0: White
[230, 230, 230], # 1: Gray 80
[209, 209, 209], # 2: Gray 65
[186, 186, 186], # 3: Gray 50
[158, 158, 158], # 4: Gray 35
_rgb(255, 255, 255), # 0: White
_rgb(230, 230, 230), # 1: Gray 80
_rgb(209, 209, 209), # 2: Gray 65
_rgb(186, 186, 186), # 3: Gray 50
_rgb(158, 158, 158), # 4: Gray 35
# ========== ColorChecker 24色 (18个) ==========
[115, 82, 66], # 5: Dark Skin
[194, 150, 130], # 6: Light Skin
[94, 122, 156], # 7: Blue Sky
[89, 107, 66], # 8: Foliage
[130, 128, 176], # 9: Blue Flower
[99, 189, 168], # 10: Bluish Green
[217, 120, 41], # 11: Orange
[74, 92, 163], # 12: Purplish Blue
[194, 84, 97], # 13: Moderate Red
[92, 61, 107], # 14: Purple
[158, 186, 64], # 15: Yellow Green
[230, 161, 46], # 16: Orange Yellow
[51, 61, 150], # 17: Blue (Legacy)
[71, 148, 71], # 18: Green (Legacy)
[176, 48, 59], # 19: Red (Legacy)
[237, 199, 33], # 20: Yellow (Legacy)
[186, 84, 145], # 21: Magenta (Legacy)
[0, 133, 163], # 22: Cyan (Legacy)
_rgb(115, 82, 66), # 5: Dark Skin
_rgb(194, 150, 130), # 6: Light Skin
_rgb(94, 122, 156), # 7: Blue Sky
_rgb(89, 107, 66), # 8: Foliage
_rgb(130, 128, 176), # 9: Blue Flower
_rgb(99, 189, 168), # 10: Bluish Green
_rgb(217, 120, 41), # 11: Orange
_rgb(74, 92, 163), # 12: Purplish Blue
_rgb(194, 84, 97), # 13: Moderate Red
_rgb(92, 61, 107), # 14: Purple
_rgb(158, 186, 64), # 15: Yellow Green
_rgb(230, 161, 46), # 16: Orange Yellow
_rgb(51, 61, 150), # 17: Blue (Legacy)
_rgb(71, 148, 71), # 18: Green (Legacy)
_rgb(176, 48, 59), # 19: Red (Legacy)
_rgb(237, 199, 33), # 20: Yellow (Legacy)
_rgb(186, 84, 145), # 21: Magenta (Legacy)
_rgb(0, 133, 163), # 22: Cyan (Legacy)
# ========== 100% 饱和色 (6个) ==========
[255, 0, 0], # 23: 100% Red
[0, 255, 0], # 24: 100% Green
[0, 0, 255], # 25: 100% Blue
[0, 255, 255], # 26: 100% Cyan
[255, 0, 255], # 27: 100% Magenta
[255, 255, 0], # 28: 100% Yellow
_rgb(255, 0, 0), # 23: 100% Red
_rgb(0, 255, 0), # 24: 100% Green
_rgb(0, 0, 255), # 25: 100% Blue
_rgb(0, 255, 255), # 26: 100% Cyan
_rgb(255, 0, 255), # 27: 100% Magenta
_rgb(255, 255, 0), # 28: 100% Yellow
],
}
@@ -505,7 +512,7 @@ def _gen_even_gray(n: int) -> list[list[int]]:
out = []
for i in range(n):
pct = 100.0 - (100.0 / (n - 1)) * i
v = int(round(pct / 100.0 * 255))
v = pct_to_solid_color(pct)
out.append([v, v, v])
return out
@@ -521,7 +528,7 @@ def _gen_pq_gray(n: int) -> list[list[int]]:
out = []
for i in range(n):
v_pq = 1.0 - i / (n - 1)
v = int(round(v_pq * 255))
v = int(round(v_pq * SOLID_COLOR_MAX))
out.append([v, v, v])
return out
@@ -534,7 +541,7 @@ def _gen_gamma_gray(n: int, gamma: float = 2.2) -> list[list[int]]:
for i in range(n):
lin = 1.0 - i / (n - 1) # 线性光 1→0
code = lin ** (1.0 / gamma) # gamma 编码
v = int(round(code * 255))
v = int(round(code * SOLID_COLOR_MAX))
out.append([v, v, v])
return out