From d3d6e81975db5b13276ac56c2ab9df89f1e9d90e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 4 Dec 2026 16:12:00 -0800 Subject: [PATCH 1/3] Targa export: a Color Model option writes grayscale files Targa Options gets a Color Model menu, RGB or Grayscale, and `document.export` takes it as `colorModel` (`rgb` or `gray`, as BMP does). Grayscale writes an uncompressed grayscale file (image type 3) at 8 bits per pixel, flattened on white, or 16 bits with an 8-bit alpha; omitting `depth` with `gray` gives 8 bits. `cmyk`, an unknown model and a grayscale depth of 24 or 32 bits are refused with an error. Switching the model in the dialog moves a depth the new model lacks to that model's default. The transparency rule of the dialog's background list now follows the depth: 16 and 32 bits keep transparency, 8 and 24 bits are flattened. Docs: docs/mcp.md, docs/control-protocol.md, docs/target-app-parity.md. --- crates/engine/src/cmd/fileio/encode.rs | 9 ++-- crates/engine/src/cmd/fileio/formats.rs | 8 ++- crates/engine/src/cmd/fileio/tests_tiffbmp.rs | 34 +++++++++++- crates/render/src/encode/tests_tga.rs | 30 +++++++++-- crates/render/src/encode/tga.rs | 54 +++++++++++++------ crates/ui-egui/src/dialogs/png_options.rs | 6 ++- .../ui-egui/src/dialogs/tests_tiff_bmp_tga.rs | 27 +++++++++- crates/ui-egui/src/dialogs/tiff_bmp_tga.rs | 36 ++++++++++--- docs/control-protocol.md | 7 +-- docs/mcp.md | 5 +- docs/target-app-parity.md | 1 + 11 files changed, 177 insertions(+), 40 deletions(-) diff --git a/crates/engine/src/cmd/fileio/encode.rs b/crates/engine/src/cmd/fileio/encode.rs index 96e5d2210f..42dc278e30 100644 --- a/crates/engine/src/cmd/fileio/encode.rs +++ b/crates/engine/src/cmd/fileio/encode.rs @@ -388,7 +388,10 @@ impl RasterOptions { top_down: self.flip_rows.unwrap_or(false), gray: color_model == jpeg::ColorModel::Gray, }, - tga: tga::TgaOptions { depth: self.depth.unwrap_or(24) }, + tga: { + let gray = color_model == jpeg::ColorModel::Gray; + tga::TgaOptions { depth: self.depth.unwrap_or_else(|| tga::TgaOptions::default_depth(gray)), gray } + }, psd: psd::PsdOptions { color_model, layers: self.layers.unwrap_or(true), @@ -412,12 +415,12 @@ fn bmp_layout(s: &str) -> Option { } /// Refuse options `format` can't write together: BMP and Targa depths and layouts, and colour -/// models (BMP is RGB or grey, Targa RGB). +/// models (BMP and Targa are RGB or grey). fn check_options(format: RasterFormat, o: &RasterExportOptions) -> Result<()> { let model = o.jpeg.color_model; let r = match format { RasterFormat::Bmp if model == jpeg::ColorModel::Cmyk => Err("BMP files are RGB or grayscale: colorModel rgb or gray".to_string()), - RasterFormat::Tga if model != jpeg::ColorModel::Rgb => Err("Targa files are RGB: colorModel rgb".to_string()), + RasterFormat::Tga if model == jpeg::ColorModel::Cmyk => Err("Targa files are RGB or grayscale: colorModel rgb or gray".to_string()), RasterFormat::Psd if o.psd.preserve_text && !o.psd.layers => Err("preserveText writes type layers: it needs layers: true".to_string()), RasterFormat::Bmp => o.bmp.check(), RasterFormat::Tga => o.tga.check(), diff --git a/crates/engine/src/cmd/fileio/formats.rs b/crates/engine/src/cmd/fileio/formats.rs index f8da5b941c..feea9d5478 100644 --- a/crates/engine/src/cmd/fileio/formats.rs +++ b/crates/engine/src/cmd/fileio/formats.rs @@ -315,14 +315,18 @@ const BMP_OPTIONS: &[FormatOption] = &[ DITHER_AMOUNT, ]; +const TGA_COLOR_MODEL: FormatOption = + FormatOption { name: "colorModel", ty: "string", default: "\"rgb\"", description: "rgb (true color) or gray (grayscale)" }; + const TGA_DEPTH: FormatOption = FormatOption { name: "depth", ty: "integer", default: "24", - description: "bits per pixel: 16 (one-bit alpha), 24 (flattened on white) or 32 (keeps transparency)", + description: "bits per pixel: with rgb 16 (one-bit alpha), 24 (flattened on white) or 32 (keeps transparency); with gray 8 (the default, flattened on white) or 16 (keeps transparency)", }; -const TGA_OPTIONS: &[FormatOption] = &[ARTBOARD, ARTBOARDS, RANGE, USE_ARTBOARDS, RECT, PPI, SCALE, WIDTH, HEIGHT, BACKGROUND, ANTI_ALIAS, TGA_DEPTH]; +const TGA_OPTIONS: &[FormatOption] = + &[ARTBOARD, ARTBOARDS, RANGE, USE_ARTBOARDS, RECT, PPI, SCALE, WIDTH, HEIGHT, BACKGROUND, ANTI_ALIAS, TGA_COLOR_MODEL, TGA_DEPTH]; const PSD_LAYERS: FormatOption = FormatOption { name: "layers", diff --git a/crates/engine/src/cmd/fileio/tests_tiffbmp.rs b/crates/engine/src/cmd/fileio/tests_tiffbmp.rs index 74df5216aa..9a00ad28e0 100644 --- a/crates/engine/src/cmd/fileio/tests_tiffbmp.rs +++ b/crates/engine/src/cmd/fileio/tests_tiffbmp.rs @@ -138,8 +138,38 @@ fn targa_depth_reaches_the_file() { } let tga = export(&mut s, json!({"format": "tga"})); assert_eq!(tga[16], 24, "24 bits by default"); - for bad in [json!({"depth": 8}), json!({"colorModel": "gray"})] { - assert!(s.execute("document.export", &merge(json!({"format": "tga"}), bad.clone())).is_err(), "{bad}"); + for bad in [ + json!({"depth": 8}), + json!({"colorModel": "cmyk"}), + json!({"colorModel": "lab"}), + json!({"colorModel": "gray", "depth": 24}), + json!({"colorModel": "gray", "depth": 32}), + ] { + let e = s.execute("document.export", &merge(json!({"format": "tga"}), bad.clone())).unwrap_err(); + assert!(matches!(e, EngineError::BadParams { .. }), "{bad}: {e}"); + } +} + +#[test] +fn targa_color_model_gray_writes_grayscale() { + let mut s = session(); + let gray = export(&mut s, json!({"format": "tga", "colorModel": "gray"})); + assert_eq!((gray[2], gray[16], gray[17]), (3, 8, 0), "grayscale, 8 bits by default, no alpha"); + let img = image::load_from_memory_with_format(&gray, image::ImageFormat::Tga).unwrap().to_rgba8(); + assert_eq!(img.dimensions(), (60, 40)); + assert_eq!(img.get_pixel(5, 5).0, [255; 4], "flattened on white"); + let black = img.get_pixel(40, 20).0; + assert!(black[0] == black[1] && black[1] == black[2] && black[0] < 80, "{black:?}"); + + let alpha = export(&mut s, json!({"format": "tga", "colorModel": "gray", "depth": 16})); + assert_eq!((alpha[2], alpha[16], alpha[17]), (3, 16, 8), "grayscale with an 8-bit alpha"); + let img = image::load_from_memory_with_format(&alpha, image::ImageFormat::Tga).unwrap().to_rgba8(); + assert_eq!(img.get_pixel(5, 5).0[3], 0, "transparent where nothing is drawn"); + assert_eq!(img.get_pixel(40, 20).0[3], 255); + + for file in [gray, alpha] { + let r = s.execute("document.open", &json!({"name": "back.tga", "dataBase64": vectorcraft_format::base64_encode(&file)})).unwrap(); + assert_eq!(r["format"], "tga"); } } diff --git a/crates/render/src/encode/tests_tga.rs b/crates/render/src/encode/tests_tga.rs index 2851a25873..823d53cd82 100644 --- a/crates/render/src/encode/tests_tga.rs +++ b/crates/render/src/encode/tests_tga.rs @@ -1,4 +1,4 @@ -//! Targa export: depths, alpha and the footer. +//! Targa export: depths, grayscale, alpha and the footer. use super::on_white; use super::tests_bmp::{art, decode, u16_at}; @@ -9,7 +9,7 @@ fn targa_depths_alpha_and_footer() { let (w, h) = (7, 3); let px = art(w, h); for (depth, alpha_bits) in [(16, 1), (24, 0), (32, 8)] { - let file = tga::encode(&px, w, h, &TgaOptions { depth }).unwrap(); + let file = tga::encode(&px, w, h, &TgaOptions { depth, gray: false }).unwrap(); assert_eq!((file[2], file[16], file[17]), (2, depth, alpha_bits), "true colour, the depth byte, alpha bits"); assert_eq!((u16_at(&file, 12), u16_at(&file, 14)), (7, 3)); assert_eq!(file.len(), 18 + (w * h) as usize * usize::from(depth / 8) + 26); @@ -25,6 +25,30 @@ fn targa_depths_alpha_and_footer() { _ => {} } } - assert!(tga::encode(&px, w, h, &TgaOptions { depth: 8 }).is_err()); + assert!(tga::encode(&px, w, h, &TgaOptions { depth: 8, gray: false }).is_err()); assert!(tga::encode(&px, 70_000, 1, &TgaOptions::default()).is_err(), "too wide"); } + +/// Grayscale Targa files are image type 3: 8 bits flattened on white, or 16 with an 8-bit alpha. +#[test] +fn targa_grayscale_writes_lightness() { + let (w, h) = (7, 3); + let px = art(w, h); + for (depth, alpha_bits) in [(8, 0), (16, 8)] { + let file = tga::encode(&px, w, h, &TgaOptions { depth, gray: true }).unwrap(); + assert_eq!((file[2], file[16], file[17]), (3, depth, alpha_bits), "grayscale, the depth byte, alpha bits"); + assert_eq!(file.len(), 18 + (w * h) as usize * usize::from(depth / 8) + 26); + let img = decode(&file, craft_image_codecs::Format::Tga); + assert_eq!(img.dimensions(), (w, h)); + // (0, 2) is opaque red 230, 40, 30: Rec. 601 lightness 96, the same in every channel. + let [r, g, b, a] = img.get_pixel(0, 2).0; + assert!(r == g && g == b && r.abs_diff(96) <= 1 && a == 255, "depth {depth}: {:?}", [r, g, b, a]); + match depth { + 8 => assert_eq!(img.get_pixel(0, 0).0, [255; 4], "flattened on white"), + _ => assert_eq!((img.get_pixel(0, 0).0[3], img.get_pixel(1, 0).0[3]), (0, 128), "8-bit alpha"), + } + } + for depth in [24, 32] { + assert!(tga::encode(&px, w, h, &TgaOptions { depth, gray: true }).is_err(), "{depth} bits gray"); + } +} diff --git a/crates/render/src/encode/tga.rs b/crates/render/src/encode/tga.rs index 031b5f1b61..94cee10461 100644 --- a/crates/render/src/encode/tga.rs +++ b/crates/render/src/encode/tga.rs @@ -1,33 +1,55 @@ //! Targa export: uncompressed true colour at 16 bits per pixel (5-5-5 and a one-bit alpha), 24 or -//! 32 (8-bit alpha), rows bottom-up, with the version 2 footer. +//! 32 (8-bit alpha), or uncompressed grayscale at 8 bits or 16 (8-bit alpha), rows bottom-up, with +//! the version 2 footer. use super::on_white; +use super::quantize::luma; -/// Bits per pixel a Targa export can have. +/// Bits per pixel a true-colour Targa export can have. pub const DEPTHS: [u8; 3] = [16, 24, 32]; +/// Bits per pixel a grayscale Targa export can have. +pub const GRAY_DEPTHS: [u8; 2] = [8, 16]; + /// The Targa options of a raster export. #[derive(Clone, Debug, PartialEq)] pub struct TgaOptions { - /// Bits per pixel ([`DEPTHS`]). + /// Bits per pixel ([`DEPTHS`], or [`GRAY_DEPTHS`] when `gray`). pub depth: u8, + /// Grayscale (image type 3) instead of true colour (image type 2). + pub gray: bool, } impl Default for TgaOptions { fn default() -> Self { - Self { depth: 24 } + Self { depth: Self::default_depth(false), gray: false } } } impl TgaOptions { + /// The depth a colour model starts with: 24 bits for true colour, 8 for grayscale. + pub fn default_depth(gray: bool) -> u8 { + if gray { 8 } else { 24 } + } + + /// The depths the colour model can be written at. + pub fn depths(gray: bool) -> &'static [u8] { + if gray { &GRAY_DEPTHS } else { &DEPTHS } + } + /// Why these options can't be written, if they can't. pub fn check(&self) -> Result<(), String> { - if DEPTHS.contains(&self.depth) { Ok(()) } else { Err(format!("Targa depth {}: 16, 24 or 32 bits per pixel", self.depth)) } + match (self.gray, Self::depths(self.gray).contains(&self.depth)) { + (_, true) => Ok(()), + (false, false) => Err(format!("Targa depth {}: 16, 24 or 32 bits per pixel", self.depth)), + (true, false) => Err(format!("grayscale Targa depth {}: 8 or 16 bits per pixel", self.depth)), + } } } -/// Straight-alpha RGBA pixels as a Targa file. 24 bits blend partly transparent pixels over white; -/// at 16 bits a pixel is opaque from half opacity up, else transparent. +/// Straight-alpha RGBA pixels as a Targa file. 24 bits and 8-bit grayscale blend partly +/// transparent pixels over white; at 16 bits true colour a pixel is opaque from half opacity up, +/// else transparent. pub fn encode(rgba: &[u8], width: u32, height: u32, o: &TgaOptions) -> Result, String> { o.check()?; let (Ok(w16), Ok(h16)) = (u16::try_from(width), u16::try_from(height)) else { @@ -40,21 +62,23 @@ pub fn encode(rgba: &[u8], width: u32, height: u32, o: &TgaOptions) -> Result().0; let mut out = Vec::with_capacity((w * h).saturating_mul(usize::from(o.depth / 8)).saturating_add(18 + 26)); - // No image id or colour map, uncompressed true colour, origin (0, 0). - out.extend([0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0]); + // No image id or colour map, uncompressed true colour (2) or grayscale (3), origin (0, 0). + out.extend([0, 0, if o.gray { 3 } else { 2 }, 0, 0, 0, 0, 0, 0, 0, 0, 0]); out.extend(w16.to_le_bytes()); out.extend(h16.to_le_bytes()); // Bits per pixel, then the alpha bits (rows bottom-up, left to right). - let alpha_bits = match o.depth { - 16 => 1, - 32 => 8, + let alpha_bits = match (o.gray, o.depth) { + (false, 16) => 1, + (true, 16) | (false, 32) => 8, _ => 0, }; out.extend([o.depth, alpha_bits]); for row in px.chunks(w).rev() { for p in row { - match o.depth { - 16 => { + match (o.gray, o.depth) { + (true, 8) => out.push(luma(on_white(p))), + (true, _) => out.extend([luma([p[0], p[1], p[2]]), p[3]]), + (false, 16) => { let v = if p[3] >= 128 { let [r, g, b] = [p[0], p[1], p[2]].map(|c| u16::from(c >> 3)); 0x8000 | r << 10 | g << 5 | b @@ -63,7 +87,7 @@ pub fn encode(rgba: &[u8], width: u32, height: u32, o: &TgaOptions) -> Result { + (false, 24) => { let [r, g, b] = on_white(p); out.extend([b, g, r]); } diff --git a/crates/ui-egui/src/dialogs/png_options.rs b/crates/ui-egui/src/dialogs/png_options.rs index 44990cf783..9a86efdb54 100644 --- a/crates/ui-egui/src/dialogs/png_options.rs +++ b/crates/ui-egui/src/dialogs/png_options.rs @@ -93,8 +93,10 @@ pub(crate) fn open_with(app: &mut VectorcraftApp, f: &Format, mut params: Value, let initial = fields_of(&raster_rows(id, false, size, &DialogFields::new()), &map); let dialog = HostedParamDialog::new(&ctx, key.clone(), initial, move |fields| { normalize_colors(fields); - if id == "bmp" { - tiff_bmp_tga::normalize_bmp(fields); + match id { + "bmp" => tiff_bmp_tga::normalize_bmp(fields), + "tga" => tiff_bmp_tga::normalize_tga(fields), + _ => {} } ParamDialog::new(key.clone(), heading(label), raster_rows(id, false, size, fields)).values(Bind::bound(fields)).ok_label(tl!("Export").into()) }); diff --git a/crates/ui-egui/src/dialogs/tests_tiff_bmp_tga.rs b/crates/ui-egui/src/dialogs/tests_tiff_bmp_tga.rs index 012c42705d..04e23c5d91 100644 --- a/crates/ui-egui/src/dialogs/tests_tiff_bmp_tga.rs +++ b/crates/ui-egui/src/dialogs/tests_tiff_bmp_tga.rs @@ -39,9 +39,32 @@ fn bmp_options_keep_their_choices_writable() { assert_eq!((&bmp[..2], bmp[28], bmp[30]), (&b"BM"[..], 8, 1), "8-bit RLE8"); } -/// Targa at 24 bits is flattened on white; its other depths keep transparency. +/// Targa at 24 bits, and grayscale at 8, is flattened on white; 16 and 32 bits keep transparency. #[test] -fn targa_keeps_transparency_above_24_bits() { +fn targa_keeps_transparency_at_16_and_32_bits() { assert!(!tiff_bmp_tga::keeps_alpha("tga", &DialogFields::from_pairs([("depth", "24")]))); assert!(tiff_bmp_tga::keeps_alpha("tga", &DialogFields::from_pairs([("depth", "32")]))); + assert!(!tiff_bmp_tga::keeps_alpha("tga", &DialogFields::from_pairs([("colorModel", "gray"), ("depth", "8")]))); + assert!(tiff_bmp_tga::keeps_alpha("tga", &DialogFields::from_pairs([("colorModel", "gray"), ("depth", "16")]))); +} + +/// Targa Options' Color Model writes a grayscale file, and a change of model moves the depth to +/// one that model has. +#[test] +fn targa_color_model_reaches_the_file() { + let (mut app, written) = app(1); + app.run("file.exportAs", json!({"format": "tga"})).unwrap(); + confirm(&mut app); + assert_eq!(kind(&app).as_deref(), Some("tgaOptions")); + let f = fields(&app); + assert_eq!((f.text("colorModel"), f.text("depth")), (Some("rgb"), Some("24"))); + frame(&mut app); + // Grayscale has no 24 bits: the depth moves to 8. + set(&mut app, "colorModel", json!("gray")); + frame(&mut app); + assert_eq!(fields(&app).text("depth"), Some("8")); + confirm(&mut app); + let (path, tga) = written.borrow()[0].clone(); + assert_eq!(path, "/out/Untitled-1.tga"); + assert_eq!((tga[2], tga[16]), (3, 8), "8-bit grayscale"); } diff --git a/crates/ui-egui/src/dialogs/tiff_bmp_tga.rs b/crates/ui-egui/src/dialogs/tiff_bmp_tga.rs index 9e70f59ee7..d969a2a8f6 100644 --- a/crates/ui-egui/src/dialogs/tiff_bmp_tga.rs +++ b/crates/ui-egui/src/dialogs/tiff_bmp_tga.rs @@ -1,5 +1,5 @@ //! The options of TIFF (colour model, byte order, LZW, profile), BMP (colour model, layout, depth, -//! palette, RLE, row order) and Targa (depth), after the raster export rows they share with PNG +//! palette, RLE, row order) and Targa (colour model, depth), after the raster export rows they share with PNG //! Options ([`super::png_options`]): the `tiffOptions`, `bmpOptions` and `tgaOptions` dialogs. use craft::ui::patterns::form_dialogs::{DialogFields, Param}; @@ -12,14 +12,15 @@ use vectorcraft_render::encode::tiff::{ByteOrder, TiffOptions}; use super::png_options::{check, choice}; -/// BMP colour models and layouts: param values and labels. +/// BMP and Targa colour models and BMP layouts: param values and labels. const BMP_MODELS: [&str; 2] = ["rgb", "gray"]; const BMP_MODEL_LABELS: [&str; 2] = ["RGB", "Grayscale"]; const LAYOUTS: [&str; 2] = ["windows", "os2"]; const LAYOUT_LABELS: [&str; 2] = ["Windows", "OS/2"]; -/// Labels of [`bmp::DEPTHS`] and [`tga::DEPTHS`]. +/// Labels of [`bmp::DEPTHS`], [`tga::DEPTHS`] and [`tga::GRAY_DEPTHS`]. const BMP_DEPTH_LABELS: [&str; 6] = ["1 bit", "4 bit", "8 bit", "16 bit", "24 bit", "32 bit"]; const TGA_DEPTH_LABELS: [&str; 3] = ["16 bits/pixel", "24 bits/pixel", "32 bits/pixel"]; +const TGA_GRAY_DEPTH_LABELS: [&str; 2] = ["8 bits/pixel", "16 bits/pixel"]; /// The options format `id` starts with (`cmyk`: a CMYK document exports CMYK TIFFs). pub(super) fn defaults(id: &str, cmyk: bool, o: &mut Map) { @@ -47,7 +48,8 @@ pub(super) fn defaults(id: &str, cmyk: bool, o: &mut Map) { ]); } "tga" => { - o.insert("depth".into(), json!(TgaOptions::default().depth.to_string())); + let t = TgaOptions::default(); + o.extend([("colorModel".into(), json!(BMP_MODELS[usize::from(t.gray)])), ("depth".into(), json!(t.depth.to_string()))]); } _ => {} } @@ -64,7 +66,7 @@ pub(super) fn keeps_alpha(id: &str, f: &DialogFields) -> bool { "jpg" => false, "tiff" => ColorModel::from_id(f.text("colorModel").unwrap_or_default()).unwrap_or_default() == ColorModel::Rgb, "bmp" => depth(f) == 32.0, - "tga" => depth(f) != 24.0, + "tga" => matches!(depth(f) as u8, 16 | 32), // A flat PSD is flattened; its layers keep transparency. "psd" => f.text("layers") == Some("true"), _ => true, @@ -81,11 +83,33 @@ pub(super) fn params(id: &str, fields: &DialogFields) -> Vec { check("embedIcc", tl!("Embed ICC Profile"), true), ], "bmp" => bmp_params(fields), - "tga" => vec![choice("depth", tl!("Depth:"), &tga::DEPTHS.map(|d| d.to_string()), &TGA_DEPTH_LABELS)], + "tga" => { + let depth = if tga_gray(fields) { + choice("depth", tl!("Depth:"), &tga::GRAY_DEPTHS.map(|d| d.to_string()), &TGA_GRAY_DEPTH_LABELS) + } else { + choice("depth", tl!("Depth:"), &tga::DEPTHS.map(|d| d.to_string()), &TGA_DEPTH_LABELS) + }; + vec![choice("colorModel", tl!("Color Model:"), &BMP_MODELS, &BMP_MODEL_LABELS), depth] + } _ => Vec::new(), } } +/// Does the Targa dialog hold the grayscale colour model? +fn tga_gray(f: &DialogFields) -> bool { + f.text("colorModel") == Some(BMP_MODELS[1]) +} + +/// Keep the Targa depth one the colour model has: a change of model starts the depth at that +/// model's default (24 bits for RGB, 8 for grayscale). +pub(super) fn normalize_tga(f: &mut DialogFields) { + let gray = tga_gray(f); + let bits = depth(f); + if !TgaOptions::depths(gray).iter().any(|d| f64::from(*d) == bits) { + f.set("depth", TgaOptions::default_depth(gray).to_string()); + } +} + fn bmp_params(fields: &DialogFields) -> Vec { let os2 = fields.text("fileFormat") == Some(LAYOUTS[1]); let depths = bmp::DEPTHS.map(|d| d.to_string()); diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 1180f20319..e70de287f0 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -1005,9 +1005,10 @@ TIFF, BMP and Targa Options: Export As… with the TIFF, BMP or Targa format (`f the save dialog) opens `tiffOptions`, `bmpOptions` or `tgaOptions`: the raster rows of PNG Options (`ppi`, `background`, `antiAlias`), then TIFF's `colorModel` (`rgb`, `cmyk`, `gray`; a CMYK document starts on `cmyk`), `byteOrder` (`little`, `big`), `lzw` and `embedIcc`; BMP's `colorModel` (`rgb`, `gray`), `fileFormat` (`windows`, -`os2`), `depth` (1, 4, 8, 16, 24, 32), `reduction` and `dither` (4 and 8 bits), `rle` and `flipRows`; Targa's `depth` -(16, 24, 32). The BMP dialog keeps its choices writable together (OS/2 falls back to 24 bits and turns RLE and flipped -rows off; RLE turns flipped rows off). `ui.dialog.set` the fields and `ui.dialog.confirm` writes the file(s) with +`os2`), `depth` (1, 4, 8, 16, 24, 32), `reduction` and `dither` (4 and 8 bits), `rle` and `flipRows`; Targa's `colorModel` +(`rgb`, `gray`) and `depth` (16, 24, 32 for `rgb`; 8, 16 for `gray`). The BMP dialog keeps its choices writable together +(OS/2 falls back to 24 bits and turns RLE and flipped rows off; RLE turns flipped rows off), and the Targa dialog moves +a depth the new color model lacks to that model's default (24 bits, or 8 for `gray`). `ui.dialog.set` the fields and `ui.dialog.confirm` writes the file(s) with `document.export`. Save for Web: File → Export → Save for Web (Legacy)… (`file.saveForWeb`, Ctrl/Cmd+Alt+Shift+S) opens the `save-for-web` diff --git a/docs/mcp.md b/docs/mcp.md index 93dff42eba..77c64a5c25 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -13455,8 +13455,9 @@ and `embedIcc` (sRGB, the working CMYK profile or grey). BMP takes `depth` (1 is palette chosen by `reduction` and `dither`; 16, 24, or 32, which keeps transparency), `colorModel` (`rgb` or `gray`), `fileFormat` (`windows` or `os2`: 1, 4, 8 or 24 bits only), `rle` (RLE4/RLE8 for 4- and 8-bit Windows bitmaps) and `flipRows` (rows top-down, a negative height; not with `rle` or `os2`); impossible combinations are refused. Targa -takes `depth`: 16 (a one-bit alpha), 24 (default) or 32 (with alpha). Formats and depths without alpha are flattened -on white. TIFF, BMP and Targa files open again (a 16-bit Targa file with its one-bit alpha); `document.formats` lists +takes `colorModel` (`rgb`, true color, or `gray`, grayscale) and `depth`: with `rgb` 16 (a one-bit alpha), 24 (default) +or 32 (with alpha); with `gray` 8 (default) or 16 (with alpha). Formats and depths without alpha are flattened on +white. TIFF, BMP and Targa files open again (a 16-bit Targa file with its one-bit alpha); `document.formats` lists every option. ```json diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index bfccfd4a5a..aaeb9ca5bf 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -2531,6 +2531,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur EPS export writes a linear or radial gradient of tints of one spot color (and paper white) in that ink's Separation space, at Level 2 and 3, and at Level 3 one that mixes a spot color with process or gray colors, or two spot colors, in a DeviceN space of the spot inks and the process inks its stops use, so each spot ink prints on its own plate; an off-center midpoint is written as a stop with the inks halfway between its two stops. At Level 2, such a mix is written in process colors with a warning. In an RGB export, a gradient that mixes a spot color with RGB or Lab colors is written without the spot ink, with a warning; a CMYK export converts those stops to CMYK first, and the gradient follows the rules above. A Perceptual gradient of spot colors, and a mix whose DeviceN space would need more than 32 inks or a spot color named Cyan, Magenta, Yellow or Black, are also written in process colors with a warning (`crates/eps/src/tests.rs`). A spot color named All or None (in a Separation space, the names of every plate and of no plate: [ISO 32000-1:2008](https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf), 8.6.6.4), is written as the ink All Spot or None Spot (All Spot 2 and on when a spot swatch already has that name) in its fills, strokes, gradients and DSC comments; Registration still prints on every plate (`tests::spot_inks_named_all_or_none_are_written_under_names_of_their_own`). EPS export and EPS Save make each file's PNG thumbnail from its TIFF preview, averaging the preview's pixels down to the thumbnail's size on white, instead of drawing the document a second time; a file without a preview still draws its thumbnail (`crates/engine/src/cmd/fileio/tests_eps.rs`). - Targa files (`.tga`, `.vda`, `.icb`, `.vst`) open, place linked or embedded, relink and update at their pixel size: color-mapped, true-color and black-and-white, raw or run-length encoded, in any of the four row orders. The image descriptor's attribute bits and the extension area's Attributes Type decide the transparency: a file with no attribute bits, or with attribute data the Attributes Type calls undefined, opens opaque; with one bit, a 16-bit true-color pixel takes that bit as its alpha, and a color-mapped pixel takes the bit of the 16-bit color map entry it indexes; premultiplied colors are divided by their alpha. Open and Place recognize a Targa file by its extension, and `clipboard.importImage` and Glass's Load Texture… by its header; a Targa file copied in a file manager pastes as a bitmap (`crates/engine/src/cmd/fileio/tests_tiffbmp.rs`, `crates/engine/src/tests/links.rs`). + - Targa Options has a Color Model menu: RGB writes true color at 16, 24 or 32 bits per pixel, and Grayscale writes a grayscale file (image type 3) at 8 bits, flattened on white, or 16 bits with an 8-bit alpha. `document.export` takes it as `colorModel` (`rgb` or `gray`, as BMP does; `cmyk` is refused), and a grayscale depth of 24 or 32 bits is refused (`crates/render/src/encode/tests_tga.rs`, `crates/engine/src/cmd/fileio/tests_tiffbmp.rs`). - BMP files named `.dib` or `.rle` (run-length encoded bitmaps included), Photoshop files named `.pdd` and PNG files named `.pns` open and place, linked or embedded, as BMP, PSD and PNG files, in any letter case: the Open and Place dialogs list them with their format, the Links panel names their format, and Edit Original opens them. Exports write only `.bmp`, `.psd` and `.png` (`crates/engine/src/cmd/fileio/tests_tiffbmp.rs`, `crates/engine/src/cmd/fileio/tests_psdread.rs`, `crates/engine/src/tests/links.rs`). - File › Open converts a PSD or PSB file's layers to objects, keeping the layer structure, merging clipped layers into one layer, merging a layer that uses a Knockout option with the layers below it, and leaving out hidden layers that would need a merge, as [PSD import options](https://helpx.adobe.com/illustrator/desktop/add-and-import-files/import-from-other-apps/photoshop-import-options.html) describes for the option that converts layers to objects; hidden layers come in with `hiddenLayers`, as Import Hidden Layers brings them in, and `layers: false` opens the merged image. VectorCraft's own rules: each layer becomes a layer holding its pixels with its name, visibility, opacity and blend mode, groups become layers of sublayers, layers in Dissolve, Linear Burn, Linear Dodge, Vivid Light, Linear Light, Pin Light, Hard Mix, Subtract, Divide, Darker Color and Lighter Color are merged with the layers below, layer masks become opacity masks, fill opacity multiplies the opacity (in a layer that others are clipped to, it fades only that layer's own pixels), a Knockout value of 1 is read as a shallow knockout and applied to a layer or group inside a group, which is merged with the visible layers below it in that group (its pixels clear them to transparency, it is drawn there at its fill opacity, and its opacity fades the result; in a pass-through group only when it and the visible layers below it are in the Normal mode; a knockout at 0 opacity, or at 0 fill where it covers none of their painted pixels, isn't merged for the knockout), and adjustment layers other than Invert, Threshold and Posterize, layer effects, vector masks and the other knockouts (top-level layers, clipped layers, layers that others are clipped to, pass-through groups with layers in other modes, other Knockout values, and merges that need more memory than allowed) aren't applied and are counted in the warnings. 8-, 16- and 32-bit files, PSB, raw, PackBits and zipped channels (`crates/engine/src/cmd/fileio/tests_psdlayers.rs`). - File › Open with a PSD or PSB file's layers as objects applies Invert, Threshold and Posterize adjustment layers (the `nvrt`, `thrs` and `post` blocks of the [PSD file format specification](https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/)): each is merged with the visible layers below it in its group, which it changes, as [PSD import options](https://helpx.adobe.com/illustrator/desktop/add-and-import-files/import-from-other-apps/photoshop-import-options.html) describes for adjustment layers; clipped to a layer, it changes only that layer and the layers clipped to it. Each adjustment works on the colors as [the help page](https://helpx.adobe.com/photoshop/desktop/adjust-color/color-effects-techniques/apply-special-color-effects-to-images.html) describes them. VectorCraft's own rules: each channel is taken as an 8-bit sRGB value; Invert turns `v` into `255 − v`; Threshold compares the Rec. 709 luminance of linear sRGB, encoded back to 0..255, with its level (1 to 255), white above it and black at or below it; Posterize maps each channel to the nearest of its 2 to 255 evenly spaced levels, the higher one on a tie; the adjusted color is composited over the color below in the layer's blend mode at its opacity and fill opacity, through its layer mask, and transparency is kept. A hidden one is left out; one with nothing visible below it in its group that draws (a layer that stores no pixels, other than a solid color fill drawn over the canvas, a layer whose pixels are all transparent, or one at 0 opacity or 0 fill with nothing clipped to it doesn't, nor does a group of only such layers, nor a layer or group whose layer mask hides all of it) changes nothing, and so does one at 0 opacity or 0 fill; in a pass-through group it changes what is below the group only when the group is merged; one that layers are clipped to, one clipped to another adjustment layer, one whose data can't be read (a level out of range, too short, or two adjustment blocks on one layer), and one whose merge, its layer mask included, needs more memory than allowed aren't applied and are counted in the warnings; a clip, or a merge for another layer, that one with a layer mask too large to read is part of goes on without it (`crates/engine/src/cmd/fileio/tests_psdlayers.rs`). From 68dea71151827b6cc238b79202e9acf725d31b7e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 4 Dec 2026 17:52:27 -0800 Subject: [PATCH 2/3] Docs: Targa's 16-bit gray files carry an 8-bit alpha The MCP export notes said a 16-bit Targa file opens with its one-bit alpha. That holds for 16-bit RGB files only; a 16-bit gray file stores an 8-bit alpha. --- docs/mcp.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/mcp.md b/docs/mcp.md index 77c64a5c25..c196454366 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -13456,8 +13456,9 @@ palette chosen by `reduction` and `dither`; 16, 24, or 32, which keeps transpare `fileFormat` (`windows` or `os2`: 1, 4, 8 or 24 bits only), `rle` (RLE4/RLE8 for 4- and 8-bit Windows bitmaps) and `flipRows` (rows top-down, a negative height; not with `rle` or `os2`); impossible combinations are refused. Targa takes `colorModel` (`rgb`, true color, or `gray`, grayscale) and `depth`: with `rgb` 16 (a one-bit alpha), 24 (default) -or 32 (with alpha); with `gray` 8 (default) or 16 (with alpha). Formats and depths without alpha are flattened on -white. TIFF, BMP and Targa files open again (a 16-bit Targa file with its one-bit alpha); `document.formats` lists +or 32 (with alpha); with `gray` 8 (default) or 16 (an 8-bit alpha). Formats and depths without alpha are flattened on +white. TIFF, BMP and Targa files open again (a 16-bit RGB Targa file with its one-bit alpha, a 16-bit gray one with its +8-bit alpha); `document.formats` lists every option. ```json From e76423a1e24eab5f60478515b5869fd287869967 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 4 Dec 2026 19:10:05 -0800 Subject: [PATCH 3/3] Tests: check each Targa color channel on its own test-lint rejects assert!(...all(...)) without a length check, which failed the gate. The test now compares the three channels one at a time with the same tolerance. --- crates/render/src/encode/tests_tga.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/render/src/encode/tests_tga.rs b/crates/render/src/encode/tests_tga.rs index 823d53cd82..21281286b5 100644 --- a/crates/render/src/encode/tests_tga.rs +++ b/crates/render/src/encode/tests_tga.rs @@ -18,7 +18,9 @@ fn targa_depths_alpha_and_footer() { assert_eq!(img.dimensions(), (w, h)); let want = on_white(px[(2 * w as usize + 3) * 4..][..4].try_into().unwrap()); let got = img.get_pixel(3, 2).0; - assert!(got[..3].iter().zip(want).all(|(a, b)| a.abs_diff(b) <= 8), "depth {depth}: {got:?} vs {want:?}"); + for c in 0..3 { + assert!(got[c].abs_diff(want[c]) <= 8, "depth {depth}, channel {c}: {got:?} vs {want:?}"); + } match depth { 32 => assert_eq!((img.get_pixel(0, 0).0[3], img.get_pixel(1, 0).0[3]), (0, 128), "8-bit alpha"), 24 => assert_eq!(img.get_pixel(0, 0).0, [255; 4], "flattened on white"),