PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Merge upstream/main into fix/bmp-indexed-export
Sir Starch0ed0f286ce72
diff --cc crates/io/src/flat.rsindex 492cbe80e,39fd2dc63..ef9ada7b2--- a/crates/io/src/flat.rs+++ b/crates/io/src/flat.rs@@@ -798,30 -813,32 +813,40 @@@ fn cmyk_image_to_srgb(img: &Image) -> ROk(Image::from_normalized(w, h, layout, sample, &out)?.with_icc(Some(dst.to_bytes().to_vec())).with_meta(img.meta.clone()))}-/// Indexed Color → PNG-8 with its colour table; Duotone → the inks rendered as RGB.+/// Indexed Color → PNG-8 or an 8-bit BMP with its colour table; Duotone → the inks rendered as RGB.fn export_mode_specific(doc: &Document, format: Format, opts: &ExportOptions) -> Result<Option<ExportResult>, IoError> {match doc.mode {- ColorMode::Indexed if format == Format::Png => {+ ColorMode::Indexed if matches!(format, Format::Png | Format::Bmp) => {let Some(table) = doc.color_table.as_ref().filter(|t| !t.colors.is_empty() && t.colors.len() <= 256) else { return Ok(None) };+ // PNG transparency belongs to a palette index, not its RGB value. Keep the+ // transparent entry out of opaque lookup, even when it duplicates an opaque colour.+ let (opaque_indices, colors): (Vec<u8>, Vec<_>) =+ table.colors.iter().copied().enumerate().filter(|(i, _)| Some(*i) != table.transparent.map(usize::from)).map(|(i, c)| (i as u8, c)).unzip();+ let opaque = photocraft_doc::ColorTable { colors, transparent: None };let mut idx = try_buffer(doc.size.area() as usize, 1)?;- let _ = photocraft_compose::render_bands(doc, doc.bounds(), 0, |band| -> Result<(), ()> {- idx.extend(band.px.iter().map(|p| match table.transparent {- Some(t) if p[3] < 0.5 => t,- _ => table.nearest([p[0], p[1], p[2]]) as u8,- }));+ photocraft_compose::render_bands(doc, doc.bounds(), 0, |band| -> Result<(), IoError> {+ for p in &band.px {+ let i = match table.transparent {+ Some(t) if p[3] < 0.5 => t,+ _ => *opaque_indices+ .get(opaque.nearest([p[0], p[1], p[2]]))+ .ok_or_else(|| IoError::Unsupported("Indexed PNG palette has no opaque entry; add an opaque colour or convert to RGB".into()))?,+ };+ idx.push(i);+ }Ok(())- });+ })?;+ if format == Format::Bmp {+ let bytes = codecs::encode_bmp_indexed(doc.size.width, doc.size.height, &idx, &table.colors)?;+ let mut warnings = vec![format!("written as an 8-bit palette BMP ({} colours)", table.colors.len())];+ if let Some(t) = table.transparent {+ warnings.push(format!("BMP has no transparency; transparent pixels are written in the colour of palette entry {t}"));+ }+ return Ok(Some(ExportResult { bytes, warnings }));+ }// Same rule as the ordinary PNG encoder: the resolution goes into `pHYs` with the metadata.let dpi = opts.encode.embed_metadata.then_some((doc.resolution_dpi, doc.resolution_dpi));- let bytes = codecs::encode_png_indexed(doc.size.width, doc.size.height, &idx, &table.colors, table.transparent, dpi)?;+ let bytes = codecs::encode_png_indexed(doc.size.width, doc.size.height, &idx, &table.colors, table.transparent, dpi, opts.encode.png_stereo)?;let mut warnings = vec![format!("written as an 8-bit palette PNG ({} colours)", table.colors.len())];if opts.encode.embed_metadata && opts.xmp == XmpEmbed::All && !doc.metadata.text.is_empty() {warnings.push("text metadata is not supported by the palette PNG exporter; it will be dropped".into());diff --cc docs/file-format-parity.mdindex 45c25964d,938a723b6..2e4609db8--- a/docs/file-format-parity.md+++ b/docs/file-format-parity.md@@@ -26,9 -26,9 +26,9 @@@ XL are missing (gap G10). Remaining: 30| Cloud PSD (.psdc) | R/W | no | no | Out of scope (Adobe cloud) || TIFF | R/W | yes | yes | 8/16/32f, Gray/RGB/CMYK, BigTIFF, every IFD, banded parallel decode; layered TIFF both byte orders (FILE-215-7: extra alpha channels not written) || JPEG | R/W | yes | yes | 8-bit Gray/RGB/CMYK, ICC/EXIF/XMP; Save keeps the opened file's quality (estimated from its quantisation tables, #2399); no JPEG Options dialog (quality 0–12, baseline/progressive) (FILE-215-19) |- | PNG | R/W | yes | yes | 8/16-bit, ICC/text; APNG first frame only; alpha channels on open (#2225); palette PNGs open in Indexed Color mode with their transparent entry (#4804) |+ | PNG | R/W | yes | yes | 8/16-bit, ICC/text; APNG first frame only; alpha channels on open (#2225); palette PNGs open in Indexed Color mode with their transparent entry (#4804); Save keeps a stereo PNG's `sTER` pairing (#6063) || GIF | R/W | yes | yes | File › Open keeps the first frame; New Video Layer from File and Video Frames to Layers take every frame, with the timeline rate from the delays (#572). Per-frame delays and keeping the frames in `.pcraft` are not done |-| BMP | R/W | yes | yes | 8-bit; palette BMPs open in Indexed Color mode |+| BMP | R/W | yes | yes | 8-bit; palette BMPs open in Indexed Color mode and Indexed Color documents save as palette BMPs (no transparency) || WebP | R/W | yes | yes | Lossless and our own lossy VP8 encoder; ICC/EXIF/XMP; Save keeps an opened file lossy (at its quality) or lossless (#2399) || AVIF | R/W | no (#463) | optional feature, off by default | || JPEG XL | R/W | inside DNG only | no | |@@@ -142,7 -142,11 +142,12 @@@ remaining gaps in #1606 stay tracked wi| Date | Change | Summary ||---|---|---|+ | 2026-10-15 | minor | DDS textures save (#1327): uncompressed or BC1/BC2/BC3 (DXT1/3/5) from a clean-room block encoder, optional box-filtered mip chain, legacy header; DDS Options in Save As and Save a Copy, `ddsCompression`/`ddsMipmaps` for scripts, the CLI and MCP |+ | 2026-10-15 | minor | PNG: a stereo PNG's `sTER` pairing (PNG Extensions 1.4.0 §3.6) is read on open and written back on save, so the file still says it is a stereo pair (#6063) |+| 2026-10-15 | minor | Indexed Color documents save as 8-bit palette BMPs with their colour table instead of 24-bit RGB; a palette BMP opens with its declared number of colours, not 256 |+ | 2026-10-15 | minor | PSD guides: image resource 1092 (guides v2) gives guides their own colours on import; 1092 and 1097 (guide GUIDs) are written back only while they still describe the document's guides, so an edit no longer leaves Photoshop a stale second guide list (#5966) |+ | 2026-10-14 | minor | PSD smart filter masks: Photoshop stores a smart object's filtered pixels without its filter mask and mixes the unfiltered ones (`FEid`) back in; import now mixes them and export writes them that way, so sf-filter-mask-hard, -gradient and sf-stack-blend-and-mask pass; Photoshop-oracle floor 185 → 188 of 258 |+ | 2026-10-13 | minor | Lossy DNG (compression 34892) decodes: 8-bit baseline JPEG tiles and strips, CFA and LinearRaw, partial edge tiles; the stored values take the normal levels and LinearizationTable (FILE-215-11, lossy DNG part) || 2026-10-14 | minor | Corpus floors raised to the measured results of the CMYK, Lab, 32-bit, Levels, Threshold, Posterize, feather and pass-through fixes landed together: Photoshop-authored 165 → 185 of 258, io 146 → 148 of 170, psd-tools 242 → 249 of 309 || 2026-10-13 | minor | CMYK Hue/Saturation (not Colorize) and Color Balance work on C, M and Y as inverted RGB with black kept, on the inks for display, export and destructive edits; cmyk8/16 hue-saturation 100% → 0.4–0.7% bad pixels, color-balance 74% → 25% || 2026-10-13 | minor | CMYK Posterize works on the stored values (1 − ink), as Photoshop does: psd-tools posterize_cmyk passes (13.8 % → 0 of pixels off on the ink path); psd-tools floor → 242 of 309 |