From 579f3ae271f9506f150cd504cad88193f0c91efb Mon Sep 17 00:00:00 2001 From: AskaEth Date: Mon, 2 Nov 2026 09:56:30 +0800 Subject: [PATCH] =?UTF-8?q?feat(palette-extract):=20=E8=A1=A5=20bmp=20?= =?UTF-8?q?=E8=A7=A3=E7=A0=81=E5=99=A8=EF=BC=88=E5=A4=8D=E5=AE=A1=20r1=20p?= =?UTF-8?q?2-2=EF=BC=8C=E5=AE=9A=E6=A1=88=E5=8A=A0=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit M73 的 Windows 壁纸探测只读注册表/.theme 里的路径,不筛扩展名,.bmp 壁纸真会出现; image 的 bmp 是独立 feature 且无额外传递依赖(bmp = []),代价≈0。 - features 加 "bmp",Cargo.toml 与 lib.rs 注释的口径对齐(原来注释说支持 bmp 但没开) - 新增 bmp_is_supported(真编一张 BMP 再解码取色) --- crates/palette-extract/Cargo.toml | 14 ++++++++++---- crates/palette-extract/src/lib.rs | 4 +++- crates/palette-extract/src/tests.rs | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/crates/palette-extract/Cargo.toml b/crates/palette-extract/Cargo.toml index d70a98f..5944084 100644 --- a/crates/palette-extract/Cargo.toml +++ b/crates/palette-extract/Cargo.toml @@ -16,11 +16,17 @@ unlucky-design = { path = "../design", version = "0.1" } # 只开两个编解码器(MIT OR Apache-2.0,deny.toml 白名单内): # - png:启动器背景图最常见的无损格式,也是截图通道用的格式; -# - jpeg:Windows 壁纸与用户照片的绝对主力(不引它等于「取色对一半用户不可用」)。 +# - jpeg:Windows 壁纸与用户照片的绝对主力(不引它等于「取色对一半用户不可用」); +# - bmp:Windows 壁纸的真会出现(M73 的探测只读注册表/`.theme` 里的路径,**不筛扩展名**), +# 而 `image` 的 `bmp` 是独立 feature 且**无额外传递依赖**(`bmp = []`),代价≈0。 # 不开 `default-features`(默认会拖进 rayon + avif/ravif + webp + tiff + gif + exr + qoi -# 等一整套编码器,体积与审计面都翻倍);不开 webp/tiff/avif 是因为 M73 的壁纸探测拿到的 -# 就是 png/jpg/bmp 三类,等真有人需要再单开一个 feature。 -image = { workspace = true, default-features = false, features = ["png", "jpeg"] } +# 等一整套编码器,体积与审计面都翻倍);不开 webp/tiff/avif 是因为 M73 拿到的格式只有 +# png/jpg/bmp 三类,等真有人需要再单开一个 feature。 +image = { workspace = true, default-features = false, features = [ + "png", + "jpeg", + "bmp", +] } [lints] workspace = true diff --git a/crates/palette-extract/src/lib.rs b/crates/palette-extract/src/lib.rs index 232e2cc..ab38838 100644 --- a/crates/palette-extract/src/lib.rs +++ b/crates/palette-extract/src/lib.rs @@ -40,10 +40,12 @@ //! //! 许可:`image` 是 `MIT OR Apache-2.0`,在 `deny.toml` 白名单内(`[licenses].allow`)。 //! -//! ## 体积影响(`image` 只开 png + jpeg,关掉 default-features) +//! ## 体积影响(`image` 只开 png + jpeg + bmp,关掉 default-features) //! //! 拉进的传递依赖就这几个:`png`(+ `fdeflate`/`miniz_oxide`/`crc32fast`/`flate2` 已在树里)、 //! `zune-jpeg` + `zune-core`、`byteorder-lite`、`num-traits`、`moxcms`/`pxfm`(色彩转换)。 +//! `bmp` 是 `image` 的独立 feature 且**不带任何传递依赖**(`bmp = []`),加它只是因为 +//! M73 的 Windows 壁纸探测不筛扩展名、`.bmp` 壁纸真会出现。 //! 关掉的默认特性里有 `rayon`(省一个线程池)、`avif`/`ravif`(最大的一个,编解码器整套)、 //! `webp`/`tiff`/`gif`/`exr`/`qoi`/`hdr`/`dds`/`ff`。实测增量见 M87 报告(`cargo tree` 前后对比)。 //! diff --git a/crates/palette-extract/src/tests.rs b/crates/palette-extract/src/tests.rs index 7ba9755..1465523 100644 --- a/crates/palette-extract/src/tests.rs +++ b/crates/palette-extract/src/tests.rs @@ -61,6 +61,22 @@ fn extension_is_ignored_and_format_is_sniffed() { assert_eq!((decoded.width(), decoded.height()), (16, 16)); } +#[test] +fn bmp_is_supported() { + // M73 的 Windows 壁纸探测不筛扩展名,`.bmp` 壁纸会真的出现在取色路径上。 + // BMP 编码不是无损于色的(24 bit 存 RGB,这里是 32 bit Rgba),所以逐通道比对即可。 + let mut bytes = Cursor::new(Vec::new()); + DynamicImage::ImageRgba8(solid_image(32, 32, [0xB2, 0x3A, 0x48])) + .write_to(&mut bytes, ImageFormat::Bmp) + .expect("BMP 编码应当成功"); + let seed = seed_from_bytes(&bytes.into_inner()).expect("BMP 应当能解码并取色"); + assert_eq!( + seed.color, + unlucky_design::color::Color::rgb(0xB2, 0x3A, 0x48) + ); + assert!(seed.chroma > 8.0); +} + #[test] fn garbage_bytes_fail_and_map_to_undecodable() { let loaded = decode_bytes(b"this is definitely not an image");