补全256种颜色映射

qdj
邱德佳 4 months ago
parent cc4abf0955
commit 1735d04ae4

@ -0,0 +1,264 @@
pub const ACI_COLORS: [(u8,u8,u8); 255] = [
(0,0,0),
(255,0,0),
(255,255,0),
(0,255,0),
(0,255,255),
(0,0,255),
(255,0,255),
// (255,255,255), //白色/黑色。先判空
(128,128,128),
(192,192,192),
(255,0,0),
(230,0,0),
(204,0,0),
(178,0,0),
(153,0,0),
(128,0,0),
(102,0,0),
(76,0,0),
(51,0,0),
(25,0,0),
(255,64,0),
(230,57,0),
(204,51,0),
(178,45,0),
(153,38,0),
(128,32,0),
(102,25,0),
(76,19,0),
(51,13,0),
(25,6,0),
(255,128,0),
(230,115,0),
(204,102,0),
(178,89,0),
(153,76,0),
(128,64,0),
(102,51,0),
(76,38,0),
(51,25,0),
(25,13,0),
(255,191,0),
(230,172,0),
(204,153,0),
(178,134,0),
(153,115,0),
(128,96,0),
(102,76,0),
(76,57,0),
(51,38,0),
(25,19,0),
(255,255,0),
(230,230,0),
(204,204,0),
(178,178,0),
(153,153,0),
(128,128,0),
(102,102,0),
(76,76,0),
(51,51,0),
(25,25,0),
(191,255,0),
(172,230,0),
(153,204,0),
(134,178,0),
(115,153,0),
(96,128,0),
(76,102,0),
(57,76,0),
(38,51,0),
(19,25,0),
(128,255,0),
(115,230,0),
(102,204,0),
(89,178,0),
(76,153,0),
(64,128,0),
(51,102,0),
(38,76,0),
(25,51,0),
(13,25,0),
(64,255,0),
(57,230,0),
(51,204,0),
(45,178,0),
(38,153,0),
(32,128,0),
(25,102,0),
(19,76,0),
(13,51,0),
(6,25,0),
(0,255,0),
(0,230,0),
(0,204,0),
(0,178,0),
(0,153,0),
(0,128,0),
(0,102,0),
(0,76,0),
(0,51,0),
(0,25,0),
(0,255,64),
(0,230,57),
(0,204,51),
(0,178,45),
(0,153,38),
(0,128,32),
(0,102,25),
(0,76,19),
(0,51,13),
(0,25,6),
(0,255,128),
(0,230,115),
(0,204,102),
(0,178,89),
(0,153,76),
(0,128,64),
(0,102,51),
(0,76,38),
(0,51,25),
(0,25,13),
(0,255,191),
(0,230,172),
(0,204,153),
(0,178,134),
(0,153,115),
(0,128,96),
(0,102,76),
(0,76,57),
(0,51,38),
(0,25,19),
(0,255,255),
(0,230,230),
(0,204,204),
(0,178,178),
(0,153,153),
(0,128,128),
(0,102,102),
(0,76,76),
(0,51,51),
(0,25,25),
(0,191,255),
(0,172,230),
(0,153,204),
(0,134,178),
(0,115,153),
(0,96,128),
(0,76,102),
(0,57,76),
(0,38,51),
(0,19,25),
(0,128,255),
(0,115,230),
(0,102,204),
(0,89,178),
(0,76,153),
(0,64,128),
(0,51,102),
(0,38,76),
(0,25,51),
(0,13,25),
(0,64,255),
(0,57,230),
(0,51,204),
(0,45,178),
(0,38,153),
(0,32,128),
(0,25,102),
(0,19,76),
(0,13,51),
(0,6,25),
(0,0,255),
(0,0,230),
(0,0,204),
(0,0,178),
(0,0,153),
(0,0,128),
(0,0,102),
(0,0,76),
(0,0,51),
(0,0,25),
(64,0,255),
(57,0,230),
(51,0,204),
(45,0,178),
(38,0,153),
(32,0,128),
(25,0,102),
(19,0,76),
(13,0,51),
(6,0,25),
(128,0,255),
(115,0,230),
(102,0,204),
(89,0,178),
(76,0,153),
(64,0,128),
(51,0,102),
(38,0,76),
(25,0,51),
(13,0,25),
(191,0,255),
(172,0,230),
(153,0,204),
(134,0,178),
(115,0,153),
(96,0,128),
(76,0,102),
(57,0,76),
(38,0,51),
(19,0,25),
(255,0,255),
(230,0,230),
(204,0,204),
(178,0,178),
(153,0,153),
(128,0,128),
(102,0,102),
(76,0,76),
(51,0,51),
(25,0,25),
(255,0,191),
(230,0,172),
(204,0,153),
(178,0,134),
(153,0,115),
(128,0,96),
(102,0,76),
(76,0,57),
(51,0,38),
(25,0,19),
(255,0,128),
(230,0,115),
(204,0,102),
(178,0,89),
(153,0,76),
(128,0,64),
(102,0,51),
(76,0,38),
(51,0,25),
(25,0,13),
(255,0,64),
(230,0,57),
(204,0,51),
(178,0,45),
(153,0,38),
(128,0,32),
(102,0,25),
(76,0,19),
(51,0,13),
(25,0,6),
(255,255,255),
(192,192,192),
(128,128,128),
(64,64,64),
(32,32,32),
(0,0,0),
];
pub fn aci_to_rgb(aci: u8) -> (u8,u8,u8) {
ACI_COLORS[aci as usize]
}

@ -13,6 +13,9 @@ use uuid::Uuid;
use tracing::{error, info, span, trace, Level};
pub mod aci_colors;
use crate::qelmt::aci_colors::aci_to_rgb;
pub mod arc;
pub use arc::Arc;
@ -31,6 +34,8 @@ pub use polygon::Polygon;
pub mod ellipse;
pub use ellipse::Ellipse;
// 在 DXF 图纸中根据名称查找特定的块Block
fn find_block<'a>(drw: &'a Drawing, name: &str) -> Option<&'a Block> {
//this is ugly there has to be a cleaner way to filter this....but for my first attempt at pulling the
@ -1736,24 +1741,24 @@ enum TextEntity<'a> {
}
// AutoCAD Color Index (ACI) 到 RGB 转换函数
fn aci_to_rgb(aci: u8) -> (u8, u8, u8) {
match aci {
1 => (255, 0, 0), // 红色
2 => (255, 255, 0), // 黄色
3 => (0, 255, 0), // 绿色
4 => (0, 255, 255), // 青色
5 => (0, 0, 255), // 蓝色
6 => (255, 0, 255), // 洋红色
// 7 => (255, 255, 255), // 白色
8 => (128, 128, 128), // 深灰色
9 => (192, 192, 192), // 浅灰色
94 => (0, 129, 0), // 深绿色
15 => (129, 86, 86), // 深棕色
// 更多标准颜色可以根据需要添加
_ => (0, 0, 0), // 默认黑色
}
}
// fn aci_to_rgb(aci: u8) -> (u8, u8, u8) {
// match aci {
// 1 => (255, 0, 0), // 红色
// 2 => (255, 255, 0), // 黄色
// 3 => (0, 255, 0), // 绿色
// 4 => (0, 255, 255), // 青色
// 5 => (0, 0, 255), // 蓝色
// 6 => (255, 0, 255), // 洋红色
// // 7 => (255, 255, 255), // 白色
// 8 => (128, 128, 128), // 深灰色
// 9 => (192, 192, 192), // 浅灰色
// 94 => (0, 129, 0), // 深绿色
// 15 => (129, 86, 86), // 深棕色
// // 更多标准颜色可以根据需要添加
// _ => (0, 0, 0), // 默认黑色
// }
// }
// ACI 转换为 HexColor
fn aci_to_hex_color(aci: u8) -> HexColor {

@ -0,0 +1,70 @@
# generate_aci_colors.py
# 生成 AutoCAD ACI 颜色表 (0-255),输出 Rust 源码文件 aci_colors.rs
import math
def hsv_to_rgb(h, s, v):
c = v * s
x = c * (1 - abs((h / 60) % 2 - 1))
m = v - c
if 0 <= h < 60:
r, g, b = c, x, 0
elif 60 <= h < 120:
r, g, b = x, c, 0
elif 120 <= h < 180:
r, g, b = 0, c, x
elif 180 <= h < 240:
r, g, b = 0, x, c
elif 240 <= h < 300:
r, g, b = x, 0, c
else:
r, g, b = c, 0, x
return (
int(round((r + m) * 255)),
int(round((g + m) * 255)),
int(round((b + m) * 255)),
)
# 固定颜色09 + 250255
fixed_colors = {
0: (0, 0, 0), # BYBLOCK
1: (255, 0, 0), # 红
2: (255, 255, 0), # 黄
3: (0, 255, 0), # 绿
4: (0, 255, 255), # 青
5: (0, 0, 255), # 蓝
6: (255, 0, 255), # 洋红
7: (255, 255, 255), # 白
8: (128, 128, 128), # 深灰
9: (192, 192, 192), # 浅灰
250: (255, 255, 255),
251: (192, 192, 192),
252: (128, 128, 128),
253: (64, 64, 64),
254: (32, 32, 32),
255: (0, 0, 0),
}
colors = []
for i in range(256):
if i in fixed_colors:
colors.append(fixed_colors[i])
elif 10 <= i <= 249:
idx = i - 10
hue = (idx // 10) * 15.0 # 每 10 个色 → 色相 +15°
val = 1.0 - (idx % 10) * 0.1 # 亮度从 1.0 → 0.1
colors.append(hsv_to_rgb(hue, 1.0, val))
else:
colors.append((0, 0, 0)) # 兜底(不会用到)
# 写 Rust 文件
with open("aci_colors.rs", "w", encoding="utf-8") as f:
f.write("// Auto-generated ACI color table (0255)\n")
f.write("pub const ACI_COLORS: [(u8,u8,u8); 256] = [\n")
for c in colors:
f.write(f" ({c[0]},{c[1]},{c[2]}),\n")
f.write("];\n\n")
f.write("pub fn aci_to_rgb(aci: u8) -> (u8,u8,u8) {\n")
f.write(" ACI_COLORS[aci as usize]\n")
f.write("}\n")
Loading…
Cancel
Save