mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge PR #4713: Codecs: open Amiga IFF/ILBM bitmaps read-only
apps/photocraft-web/src/web.rs: OPEN_EXTS kept main's list (with the DICOM extensions) and added iff, lbm, ilbm. apps/photocraft/src/services.rs: OPEN_EXTS kept main's list (with the DICOM extensions) and added iff, lbm, ilbm. crates/codecs/README.md: kept both the DICOM and the Amiga IFF table row and section. crates/codecs/src/format.rs: kept both the Dicom and the Iff variants in every match, detect runs the DICOM check then the IFF check, Format::ALL length re-counted (22). crates/codecs/src/lib.rs: one use line importing dicom and iff; both decode and encode arms kept. docs/gaps.md: header line kept from main, with the PR's 'Cineon and Amiga IFF read' wording.
This commit is contained in:
commit
96cce9b2f9
10 files changed
+404
-7
No files matched your search
@@ -20,7 +20,7 @@ type Inbox = Arc<Mutex<Vec<(String, Vec<u8>)>>>;
|
||||
/// Photoshop brushes (.abr), gradients (.grd) and swatches (.aco, .act, .ase), which go to the preset libraries.
|
||||
const OPEN_EXTS: &[&str] = &[
|
||||
"pcraft", "pdn", "ora", "xcf", "xcfgz", "gz", "kra", "krz", "psd", "psb", "psdt", "png", "jpg", "jpeg", "tif", "tiff", "webp", "gif", "bmp", "tga", "ico",
|
||||
"qoi", "exr", "hdr", "pbm", "pgm", "ppm", "pam", "pfm", "dds", "fits", "fit", "fts", "dpx", "cin", "dcm", "dicom", "dc3", "heic", "heif", "hif", "dng", "cr2", "cr3", "nef",
|
||||
"qoi", "exr", "hdr", "pbm", "pgm", "ppm", "pam", "pfm", "dds", "fits", "fit", "fts", "dpx", "cin", "dcm", "dicom", "dc3", "iff", "lbm", "ilbm", "heic", "heif", "hif", "dng", "cr2", "cr3", "nef",
|
||||
"nrw", "arw", "pef", "orf", "rw2", "raf", "abr", "grd", "svg", "svgz", "aco", "act", "ase", "af", "afdesign", "afphoto", "afpub",
|
||||
];
|
||||
const SVG_EXTS: &[&str] = &["svg", "svgz"];
|
||||
|
||||
@@ -21,7 +21,7 @@ mod recovery_tests;
|
||||
/// (.kys), which go to the preset libraries and Edit › Keyboard Shortcuts.
|
||||
const OPEN_EXTS: &[&str] = &[
|
||||
"pcraft", "pdn", "ora", "xcf", "xcfgz", "gz", "kra", "krz", "psd", "psb", "psdt", "png", "jpg", "jpeg", "tif", "tiff", "webp", "gif", "bmp", "tga", "ico",
|
||||
"qoi", "exr", "hdr", "pbm", "pgm", "ppm", "pam", "pfm", "pcx", "dds", "xpm", "fits", "fit", "fts", "dpx", "cin", "dcm", "dicom", "dc3", "heic", "heif", "hif", "dng", "cr2",
|
||||
"qoi", "exr", "hdr", "pbm", "pgm", "ppm", "pam", "pfm", "pcx", "dds", "xpm", "fits", "fit", "fts", "dpx", "cin", "dcm", "dicom", "dc3", "iff", "lbm", "ilbm", "heic", "heif", "hif", "dng", "cr2",
|
||||
"cr3", "nef", "nrw", "arw", "pef", "orf", "rw2", "raf", "abr", "grd", "svg", "svgz", "aco", "act", "ase", "kys", "af", "afdesign", "afphoto", "afpub",
|
||||
];
|
||||
const SVG_EXTS: &[&str] = &["svg", "svgz"];
|
||||
@@ -67,6 +67,7 @@ const OPEN_FILTERS: &[(&str, &[&str])] = &[
|
||||
("Radiance HDR", &["hdr"]),
|
||||
("FITS", &["fits", "fit", "fts"]),
|
||||
("DPX and Cineon", &["dpx", "cin"]),
|
||||
("Amiga IFF", &["iff", "lbm", "ilbm"]),
|
||||
("Camera Raw", &["dng", "cr2", "cr3", "nef", "nrw", "arw", "pef", "orf", "rw2", "raf"]),
|
||||
("Brushes", &["abr"]),
|
||||
("Gradients", &["grd"]),
|
||||
|
||||
@@ -49,6 +49,7 @@ let out = encode(&img, Format::Tiff, &EncodeOptions::default())?;
|
||||
| DPX | yes | yes | U8, U16 (10/12-bit code values read and written exactly through U16) | Gray, RGB, RGBA | yes | no | no | no | no | DPX header fields only (creator, project, copyright, creation time, transfer, colorimetric, frame position, frame rate, time code) | no | built in |
|
||||
| Cineon | yes | **no** | U16 (10-bit code values) | Gray, RGB | no | no | no | no | no | no | n/a | built in |
|
||||
| DICOM | yes | **no** | U8, U16 | Gray, RGB | no | no | no | no | no | no | n/a | built in |
|
||||
| Amiga IFF (ILBM/PBM) | yes | **no** | U8 | RGB, RGBA | yes | no | no | no | no | no | n/a | built in |
|
||||
| AVIF | **no** | only with feature `avif` | U8 | RGB, RGBA | yes | no | no | no | no | no | yes | `image` + `ravif` |
|
||||
| HEIF/HEIC | with feature `heif` | **no** | U8, U16 (10/12-bit decodes to U16) | RGB, RGBA | yes (auxiliary alpha) | yes (`colr` prof) | yes | yes | no | no | n/a | `heic-rs` |
|
||||
|
||||
@@ -124,6 +125,13 @@ embedded table (and a PNG's transparent entry) so `photocraft-io` can open them
|
||||
interpretations return `Unsupported`/`Malformed`. There is no DICOM writer
|
||||
(`ASYMMETRIC_EXCEPTIONS`).
|
||||
|
||||
* **Amiga IFF (read-only).** `FORM ... ILBM` stores interleaved 1–8 bitplanes;
|
||||
`FORM ... PBM ` stores 8-bit chunky palette indices with even-padded rows. Both support
|
||||
stored and ByteRun1 compression, a `CMAP` palette (grey ramp when absent, black for missing
|
||||
entries), and transparent-colour masking. ILBM also supports a separate mask plane. HAM/EHB
|
||||
viewport modes, PBM mask planes, other bit depths and compressions return
|
||||
`CodecError::Unsupported`. There is no IFF writer; save as PNG.
|
||||
|
||||
* **Camera raw files** (DNG, CR2, NEF, ARW… which are TIFF-structured) are recognised and refused
|
||||
with `CodecError::Unsupported`: they are sensor data, not flat images. `photocraft-raw` decodes
|
||||
and develops them, and `photocraft-io` routes them there.
|
||||
|
||||
@@ -0,0 +1,354 @@
|
||||
//! Amiga IFF/ILBM reader (EA "Interchange File Format", "InterLeaved BitMap" and the chunky
|
||||
//! "PBM " variant). Written from the published IFF/ILBM layout: a `FORM` chunk of four-byte
|
||||
//! chunks (`BMHD` bitmap header, `CMAP` palette, `CAMG` Amiga viewport mode, `BODY` pixel data).
|
||||
//! Read-only: modern saves should use PNG.
|
||||
//!
|
||||
//! Supported: 1–8 bitplanes with a palette (or a grey ramp when there is none), masking 0/1/2,
|
||||
//! and both stored (0) and ByteRun1/PackBits (1) compression. Anything else is a clear
|
||||
//! `Unsupported`/`Malformed` error, never a panic.
|
||||
|
||||
use crate::error::CodecError;
|
||||
use crate::format::Format;
|
||||
use crate::image::{ChannelLayout, Image, SampleType};
|
||||
use crate::options::Limits;
|
||||
|
||||
const F: Format = Format::Iff;
|
||||
|
||||
fn bad(msg: impl std::fmt::Display) -> CodecError {
|
||||
CodecError::malformed(F, msg)
|
||||
}
|
||||
|
||||
fn unsupported(msg: impl Into<String>) -> CodecError {
|
||||
CodecError::unsupported(F, msg)
|
||||
}
|
||||
|
||||
fn be32(b: &[u8], at: usize) -> Option<u32> {
|
||||
let s = b.get(at..at.checked_add(4)?)?.try_into().ok()?;
|
||||
Some(u32::from_be_bytes(s))
|
||||
}
|
||||
|
||||
fn be16(b: &[u8], at: usize) -> Option<u16> {
|
||||
let s = b.get(at..at.checked_add(2)?)?.try_into().ok()?;
|
||||
Some(u16::from_be_bytes(s))
|
||||
}
|
||||
|
||||
/// `FORM` + a bitmap type (`ILBM` interleaved, `PBM ` chunky) at offset 8.
|
||||
pub(crate) fn looks_like_iff(b: &[u8]) -> bool {
|
||||
b.get(0..4) == Some(b"FORM") && matches!(b.get(8..12), Some(b"ILBM" | b"PBM "))
|
||||
}
|
||||
|
||||
/// The bitmap header fields decoding needs.
|
||||
struct Header {
|
||||
width: u32,
|
||||
height: u32,
|
||||
planes: u8,
|
||||
masking: u8,
|
||||
compression: u8,
|
||||
transparent: u16,
|
||||
/// `PBM ` stores one palette index per byte, padded to even row lengths.
|
||||
chunky: bool,
|
||||
}
|
||||
|
||||
/// One four-byte chunk's id and byte range.
|
||||
struct Chunk<'a> {
|
||||
id: [u8; 4],
|
||||
data: &'a [u8],
|
||||
}
|
||||
|
||||
/// Walk the `FORM`'s chunks from offset 12 to `end` (the form length), stopping at the first
|
||||
/// malformed length so a hostile file can't run past the buffer.
|
||||
fn chunks(b: &[u8]) -> impl Iterator<Item = Chunk<'_>> {
|
||||
let end = be32(b, 4).map_or(b.len(), |n| (n as usize).saturating_add(8).min(b.len()));
|
||||
let mut pos = 12usize;
|
||||
std::iter::from_fn(move || {
|
||||
if pos + 8 > end {
|
||||
return None;
|
||||
}
|
||||
let id = b.get(pos..pos + 4)?.try_into().ok()?;
|
||||
let len = be32(b, pos + 4)? as usize;
|
||||
let start = pos + 8;
|
||||
let data = b.get(start..start.checked_add(len)?)?;
|
||||
// Chunks are padded to an even length.
|
||||
pos = start.checked_add(len)?.checked_add(len & 1)?;
|
||||
Some(Chunk { id, data })
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_header(b: &[u8], chunky: bool) -> Result<Header, CodecError> {
|
||||
let bmhd = chunks(b).find(|c| &c.id == b"BMHD").ok_or_else(|| bad("no BMHD chunk"))?;
|
||||
let d = bmhd.data;
|
||||
if d.len() < 20 {
|
||||
return Err(bad("BMHD chunk is too short"));
|
||||
}
|
||||
let width = u32::from(be16(d, 0).ok_or_else(|| bad("BMHD width"))?);
|
||||
let height = u32::from(be16(d, 2).ok_or_else(|| bad("BMHD height"))?);
|
||||
let planes = *d.get(8).ok_or_else(|| bad("BMHD planes"))?;
|
||||
let masking = *d.get(9).ok_or_else(|| bad("BMHD masking"))?;
|
||||
let compression = *d.get(10).ok_or_else(|| bad("BMHD compression"))?;
|
||||
if width == 0 || height == 0 {
|
||||
return Err(bad("zero-sized bitmap"));
|
||||
}
|
||||
if !(1..=8).contains(&planes) {
|
||||
return Err(unsupported(format!("{planes} bitplanes (1–8, with a palette)")));
|
||||
}
|
||||
if masking > 2 {
|
||||
return Err(unsupported(format!("masking {masking}")));
|
||||
}
|
||||
if compression > 1 {
|
||||
return Err(unsupported(format!("compression {compression} (only stored and ByteRun1)")));
|
||||
}
|
||||
if chunky && (planes != 8 || masking == 1) {
|
||||
return Err(unsupported("PBM requires 8-bit indices without a mask plane"));
|
||||
}
|
||||
let transparent = be16(d, 12).ok_or_else(|| bad("BMHD transparent colour"))?;
|
||||
Ok(Header { width, height, planes, masking, compression, transparent, chunky })
|
||||
}
|
||||
|
||||
/// ByteRun1 / PackBits decode of one plane row into `out`; returns the bytes consumed. A `0x80`
|
||||
/// control byte is a no-op, as the layout specifies.
|
||||
fn unpack_byte_run1(src: &[u8], out: &mut [u8]) -> Result<usize, CodecError> {
|
||||
let (mut i, mut o) = (0usize, 0usize);
|
||||
while o < out.len() {
|
||||
let n = *src.get(i).ok_or_else(|| bad("truncated ByteRun1 data"))? as i8;
|
||||
i += 1;
|
||||
if n >= 0 {
|
||||
let count = n as usize + 1;
|
||||
let lit = src.get(i..i.checked_add(count).ok_or_else(|| bad("ByteRun1 overflow"))?).ok_or_else(|| bad("truncated ByteRun1 run"))?;
|
||||
if count > out.len() - o {
|
||||
return Err(bad("ByteRun1 run crosses the plane row"));
|
||||
}
|
||||
out[o..o + count].copy_from_slice(lit);
|
||||
i += count;
|
||||
o += count;
|
||||
} else if n != -128 {
|
||||
let count = (1 - n as i32) as usize;
|
||||
let value = *src.get(i).ok_or_else(|| bad("truncated ByteRun1 repeat"))?;
|
||||
i += 1;
|
||||
if count > out.len() - o {
|
||||
return Err(bad("ByteRun1 repeat crosses the plane row"));
|
||||
}
|
||||
out[o..o + count].fill(value);
|
||||
o += count;
|
||||
}
|
||||
}
|
||||
Ok(i)
|
||||
}
|
||||
|
||||
pub(crate) fn decode(b: &[u8], limits: &Limits) -> Result<Image, CodecError> {
|
||||
if !looks_like_iff(b) {
|
||||
return Err(bad("not an IFF/ILBM file (no FORM ... ILBM)"));
|
||||
}
|
||||
let h = parse_header(b, b.get(8..12) == Some(b"PBM "))?;
|
||||
if let Some(camg) = chunks(b).find(|c| &c.id == b"CAMG") {
|
||||
let mode = be32(camg.data, 0).ok_or_else(|| bad("short CAMG chunk"))?;
|
||||
if mode & (0x80 | 0x800) != 0 {
|
||||
return Err(unsupported("EHB and HAM viewport modes"));
|
||||
}
|
||||
}
|
||||
let layout = if h.masking == 0 { ChannelLayout::Rgb } else { ChannelLayout::Rgba };
|
||||
limits.check(h.width, h.height, layout, SampleType::U8)?;
|
||||
|
||||
// Palette: three bytes per colour; missing entries read as black.
|
||||
let cmap = chunks(b).find(|c| &c.id == b"CMAP").map(|c| c.data).filter(|p| !p.is_empty());
|
||||
let colors = 1usize << h.planes;
|
||||
let palette = |idx: usize| -> [u8; 3] {
|
||||
if let Some(p) = cmap {
|
||||
p.get(idx * 3..idx * 3 + 3).map(|c| [c[0], c[1], c[2]]).unwrap_or([0; 3])
|
||||
} else {
|
||||
let v = ((idx as u32 * 255) / (colors as u32 - 1).max(1)) as u8;
|
||||
[v, v, v]
|
||||
}
|
||||
};
|
||||
|
||||
let body = chunks(b).find(|c| &c.id == b"BODY").map(|c| c.data).ok_or_else(|| bad("no BODY chunk"))?;
|
||||
let (w, hh) = (h.width as usize, h.height as usize);
|
||||
// Each plane row is stored as a whole number of 16-bit words.
|
||||
let plane_row = if h.chunky { w.div_ceil(2) * 2 } else { w.div_ceil(16) * 2 };
|
||||
// A masking type 1 bitmap carries one extra (mask) plane per row.
|
||||
let rows_planes: usize = if h.chunky { 1 } else { usize::from(h.planes) + usize::from(h.masking == 1) };
|
||||
|
||||
// Decode every stored plane row up front, then recombine.
|
||||
let total_rows = hh.checked_mul(rows_planes).ok_or_else(|| CodecError::LimitExceeded("bitmap too large".into()))?;
|
||||
let total_bytes = total_rows.checked_mul(plane_row).ok_or_else(|| CodecError::LimitExceeded("bitmap too large".into()))?;
|
||||
if total_bytes as u64 > limits.max_alloc {
|
||||
return Err(CodecError::LimitExceeded("bitmap storage exceeds max_alloc".into()));
|
||||
}
|
||||
Limits::check_plausible(total_bytes as u64, body.len(), if h.compression == 0 { 1 } else { 128 })?;
|
||||
let mut stored = crate::options::alloc_zeroed::<u8>(total_bytes)?;
|
||||
let mut cursor = 0usize;
|
||||
for row in stored.chunks_mut(plane_row.max(1)).take(total_rows) {
|
||||
match h.compression {
|
||||
0 => {
|
||||
let src = body.get(cursor..cursor.checked_add(plane_row).ok_or_else(|| bad("BODY overflow"))?).ok_or_else(|| bad("truncated BODY data"))?;
|
||||
let n = row.len().min(src.len());
|
||||
row[..n].copy_from_slice(&src[..n]);
|
||||
cursor += plane_row;
|
||||
}
|
||||
_ => {
|
||||
let tail = body.get(cursor..).ok_or_else(|| bad("truncated BODY data"))?;
|
||||
cursor += unpack_byte_run1(tail, row)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut out = Vec::new();
|
||||
out.try_reserve_exact(w.saturating_mul(hh).saturating_mul(layout.channels())).map_err(|_| CodecError::LimitExceeded("cannot allocate the image".into()))?;
|
||||
let planes = usize::from(h.planes);
|
||||
for y in 0..hh {
|
||||
for x in 0..w {
|
||||
let index = if h.chunky {
|
||||
usize::from(*stored.get(y * plane_row + x).ok_or_else(|| bad("PBM pixel outside BODY"))?)
|
||||
} else {
|
||||
(0..planes).filter(|&p| bit_at(&stored, (y * rows_planes + p) * plane_row, x)).fold(0usize, |acc, p| acc | (1 << p))
|
||||
};
|
||||
let c = palette(index);
|
||||
out.extend_from_slice(&c);
|
||||
if h.masking != 0 {
|
||||
let opaque = if h.masking == 1 { bit_at(&stored, (y * rows_planes + planes) * plane_row, x) } else { index != usize::from(h.transparent) };
|
||||
out.push(if opaque { 255 } else { 0 });
|
||||
}
|
||||
}
|
||||
}
|
||||
Image::from_u8(h.width, h.height, layout, out)
|
||||
}
|
||||
|
||||
/// The bit for pixel `x` of a stored plane row at `base` (bits run MSB-first).
|
||||
fn bit_at(stored: &[u8], base: usize, x: usize) -> bool {
|
||||
stored.get(base + x / 8).is_some_and(|byte| byte & (0x80 >> (x % 8)) != 0)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// A `FORM ILBM` with a `BMHD`, `CMAP` and `BODY`. `planes` plane rows per row,
|
||||
/// `compression` 0 (stored) or 1 (ByteRun1), MSB-first.
|
||||
fn ilbm(w: u16, h: u16, planes: u8, palette: &[[u8; 3]], compression: u8, body: &[u8]) -> Vec<u8> {
|
||||
let mut b = b"FORM".to_vec();
|
||||
b.extend_from_slice(&0u32.to_be_bytes()); // patched below
|
||||
b.extend_from_slice(b"ILBM");
|
||||
// BMHD (20 bytes)
|
||||
b.extend_from_slice(b"BMHD");
|
||||
b.extend_from_slice(&20u32.to_be_bytes());
|
||||
b.extend_from_slice(&w.to_be_bytes());
|
||||
b.extend_from_slice(&h.to_be_bytes());
|
||||
b.extend_from_slice(&[0, 0, 0, 0]); // x/y origin
|
||||
b.push(planes);
|
||||
b.push(0); // masking
|
||||
b.push(compression);
|
||||
b.push(0); // pad
|
||||
b.extend_from_slice(&[0, 0]); // transparent colour
|
||||
b.extend_from_slice(&[1, 1]); // aspect
|
||||
b.extend_from_slice(&[0, 0, 0, 0]); // page size
|
||||
// CMAP
|
||||
b.extend_from_slice(b"CMAP");
|
||||
b.extend_from_slice(&((palette.len() * 3) as u32).to_be_bytes());
|
||||
for c in palette {
|
||||
b.extend_from_slice(c);
|
||||
}
|
||||
if palette.len() % 2 == 1 {
|
||||
b.push(0);
|
||||
}
|
||||
// BODY
|
||||
b.extend_from_slice(b"BODY");
|
||||
b.extend_from_slice(&(body.len() as u32).to_be_bytes());
|
||||
b.extend_from_slice(body);
|
||||
if body.len() % 2 == 1 {
|
||||
b.push(0);
|
||||
}
|
||||
let size = (b.len() - 8) as u32;
|
||||
b[4..8].copy_from_slice(&size.to_be_bytes());
|
||||
b
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reads_a_stored_two_plane_bitmap() {
|
||||
// 2×1, 2 planes: pixel 0 index 0 (plane bits 0,0), pixel 1 index 3 (bits 1,1).
|
||||
// Plane 0 = 0b0100_0000, plane 1 = 0b0100_0000, each padded to 2 bytes.
|
||||
let body = [0b0100_0000, 0, 0b0100_0000, 0];
|
||||
let pal = [[10, 20, 30], [40, 50, 60], [70, 80, 90], [100, 110, 120]];
|
||||
let b = ilbm(2, 1, 2, &pal, 0, &body);
|
||||
assert!(looks_like_iff(&b));
|
||||
let img = decode(&b, &Limits::default()).unwrap();
|
||||
assert_eq!((img.width(), img.height(), img.layout()), (2, 1, ChannelLayout::Rgb));
|
||||
assert_eq!(img.data(), &[10, 20, 30, 100, 110, 120]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reads_byte_run1_compressed_rows() {
|
||||
// Same image, ByteRun1: literal run of two bytes (0x01) then the two plane bytes each row.
|
||||
let body = [0x01, 0b0100_0000, 0, 0x01, 0b0100_0000, 0];
|
||||
let pal = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [250, 251, 252]];
|
||||
let b = ilbm(2, 1, 2, &pal, 1, &body);
|
||||
let img = decode(&b, &Limits::default()).unwrap();
|
||||
assert_eq!(img.data(), &[1, 2, 3, 250, 251, 252]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_palette_falls_back_to_a_grey_ramp() {
|
||||
// 2×1, 1 plane, no CMAP: indices 0 and 1 → black and white.
|
||||
let body = [0b0100_0000, 0];
|
||||
let b = ilbm(2, 1, 1, &[], 0, &body);
|
||||
let img = decode(&b, &Limits::default()).unwrap();
|
||||
assert_eq!(img.data(), &[0, 0, 0, 255, 255, 255]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pbm_reads_chunky_indices_with_odd_width_padding() {
|
||||
let pal = [[10, 20, 30], [40, 50, 60], [70, 80, 90]];
|
||||
for (compression, body) in [(0, vec![2, 0, 1, 255, 1, 2, 0, 255]), (1, vec![3, 2, 0, 1, 255, 3, 1, 2, 0, 255])] {
|
||||
let mut b = ilbm(3, 2, 8, &pal, compression, &body);
|
||||
b[8..12].copy_from_slice(b"PBM ");
|
||||
let img = decode(&b, &Limits::default()).unwrap();
|
||||
assert_eq!(img.data(), &[70, 80, 90, 10, 20, 30, 40, 50, 60, 40, 50, 60, 70, 80, 90, 10, 20, 30]);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transparency_uses_the_mask_plane_or_transparent_index() {
|
||||
for masking in [1, 2] {
|
||||
let mut b = ilbm(2, 1, 1, &[[10, 20, 30], [40, 50, 60]], 0, if masking == 1 { &[0x40, 0, 0x40, 0] } else { &[0x40, 0] });
|
||||
b[29] = masking;
|
||||
let img = decode(&b, &Limits::default()).unwrap();
|
||||
assert_eq!(img.layout(), ChannelLayout::Rgba);
|
||||
assert_eq!(img.data(), &[10, 20, 30, 0, 40, 50, 60, 255]);
|
||||
}
|
||||
let mut b = ilbm(2, 1, 8, &[[10, 20, 30], [40, 50, 60]], 0, &[0, 1]);
|
||||
b[8..12].copy_from_slice(b"PBM ");
|
||||
b[29] = 2;
|
||||
b[32..34].copy_from_slice(&1u16.to_be_bytes());
|
||||
assert_eq!(decode(&b, &Limits::default()).unwrap().data(), &[10, 20, 30, 255, 40, 50, 60, 0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_ham_and_ehb_instead_of_returning_wrong_colours() {
|
||||
for mode in [0x80u32, 0x800] {
|
||||
let mut b = ilbm(1, 1, 1, &[], 0, &[0, 0]);
|
||||
b.extend_from_slice(b"CAMG");
|
||||
b.extend_from_slice(&4u32.to_be_bytes());
|
||||
b.extend_from_slice(&mode.to_be_bytes());
|
||||
let len = (b.len() - 8) as u32;
|
||||
b[4..8].copy_from_slice(&len.to_be_bytes());
|
||||
assert!(matches!(decode(&b, &Limits::default()), Err(CodecError::Unsupported { .. })));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_palette_entries_are_black() {
|
||||
let b = ilbm(1, 1, 2, &[[10, 20, 30]], 0, &[0x80, 0, 0x80, 0]);
|
||||
assert_eq!(decode(&b, &Limits::default()).unwrap().data(), &[0, 0, 0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hostile_input_errors_not_panics() {
|
||||
// Truncations of a valid file never panic.
|
||||
let body = [0b0100_0000, 0, 0b0100_0000, 0];
|
||||
let full = ilbm(2, 1, 2, &[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], 0, &body);
|
||||
for cut in [0, 4, 8, 12, 40, full.len() - 1] {
|
||||
assert!(decode(&full[..cut.min(full.len())], &Limits::default()).is_err(), "cut {cut}");
|
||||
}
|
||||
// Too many planes is unsupported.
|
||||
let bad = ilbm(1, 1, 9, &[], 0, &[0, 0]);
|
||||
assert!(matches!(decode(&bad, &Limits::default()), Err(CodecError::Unsupported { .. })));
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ pub(crate) mod fits;
|
||||
pub(crate) mod gif_frames;
|
||||
pub(crate) mod gif_palette;
|
||||
pub(crate) mod heif;
|
||||
pub(crate) mod iff;
|
||||
pub(crate) mod jpeg;
|
||||
pub(crate) mod pcx;
|
||||
pub(crate) mod png;
|
||||
|
||||
@@ -38,6 +38,8 @@ pub enum Format {
|
||||
Cineon,
|
||||
/// DICOM single-frame images (uncompressed): read-only.
|
||||
Dicom,
|
||||
/// Amiga IFF/ILBM (`FORM ... ILBM`): planar bitplanes with a palette, read-only.
|
||||
Iff,
|
||||
}
|
||||
|
||||
/// What a format can hold **and** what this crate reads/writes for it.
|
||||
@@ -70,6 +72,7 @@ pub struct FormatCaps {
|
||||
/// The test-suite asserts that every other enabled format is read+write.
|
||||
pub const ASYMMETRIC_EXCEPTIONS: &[(Format, &str)] = &[
|
||||
(Format::Xpm, "XPM is a legacy Unix icon interchange format. Reading existing XPM icons is supported; writing modern image assets should use PNG instead."),
|
||||
(Format::Iff, "Amiga IFF/ILBM is supported for opening legacy Amiga artwork; this crate has no IFF writer, so save as PNG instead."),
|
||||
(
|
||||
Format::Dicom,
|
||||
"DICOM single-frame images are imported for medical review; this crate has no DICOM writer, so save an imported frame as TIFF or PNG instead.",
|
||||
@@ -107,7 +110,7 @@ const TIFF_LAYOUTS: &[ChannelLayout] = &[L::Gray, L::GrayA, L::Rgb, L::Rgba, L::
|
||||
|
||||
impl Format {
|
||||
/// Every format known to the crate (enabled or not).
|
||||
pub const ALL: [Format; 21] = [
|
||||
pub const ALL: [Format; 22] = [
|
||||
Format::Png,
|
||||
Format::Jpeg,
|
||||
Format::Tiff,
|
||||
@@ -129,6 +132,7 @@ impl Format {
|
||||
Format::Dpx,
|
||||
Format::Cineon,
|
||||
Format::Dicom,
|
||||
Format::Iff,
|
||||
];
|
||||
|
||||
pub fn caps(self) -> FormatCaps {
|
||||
@@ -164,6 +168,7 @@ impl Format {
|
||||
Format::Dpx => "DPX",
|
||||
Format::Cineon => "Cineon",
|
||||
Format::Dicom => "DICOM",
|
||||
Format::Iff => "Amiga IFF",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,6 +197,7 @@ impl Format {
|
||||
Format::Dpx => &["dpx"],
|
||||
Format::Cineon => &["cin"],
|
||||
Format::Dicom => &["dcm", "dicom", "dc3"],
|
||||
Format::Iff => &["iff", "lbm", "ilbm"],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,6 +224,7 @@ impl Format {
|
||||
Format::Dpx => "image/x-dpx",
|
||||
Format::Cineon => "image/x-cin",
|
||||
Format::Dicom => "application/dicom",
|
||||
Format::Iff => "image/x-iff",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,6 +283,7 @@ pub fn caps(format: Format) -> FormatCaps {
|
||||
Format::Dpx => FormatCaps { depths: &[S::U8, S::U16], layouts: &[L::Gray, L::Rgb, L::Rgba], text: true, ..base },
|
||||
Format::Cineon => FormatCaps { read: true, write: false, depths: &[S::U16], layouts: &[L::Gray, L::Rgb], alpha: false, ..base },
|
||||
Format::Dicom => FormatCaps { read: true, write: false, depths: &[S::U8, S::U16], layouts: &[L::Gray, L::Rgb], alpha: false, ..base },
|
||||
Format::Iff => FormatCaps { read: true, write: false, depths: &[S::U8], layouts: &[L::Rgb, L::Rgba], alpha: true, ..base },
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,6 +344,9 @@ pub fn detect(bytes: &[u8]) -> Option<Format> {
|
||||
if crate::codecs::dicom::is_dicom(b) {
|
||||
return Some(Format::Dicom);
|
||||
}
|
||||
if crate::codecs::iff::looks_like_iff(b) {
|
||||
return Some(Format::Iff);
|
||||
}
|
||||
if b.starts_with(b"SIMPLE =") {
|
||||
return Some(Format::Fits);
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ pub use crate::resolution::{exif_resolution, export_exif, export_xmp, photoshop_
|
||||
pub use crate::source_settings::{WebpEncoding, jpeg_quality, webp_encoding};
|
||||
pub use half::f16;
|
||||
|
||||
use crate::codecs::{dds, dicom, dpx, exr, fits, heif, jpeg, pcx, png, pnm, tiff, via_image, webp, xpm};
|
||||
use crate::codecs::{dds, dicom, dpx, exr, fits, heif, iff, jpeg, pcx, png, pnm, tiff, via_image, webp, xpm};
|
||||
|
||||
/// Detect the format and decode with default [`Limits`].
|
||||
pub fn decode(bytes: &[u8]) -> Result<Image, CodecError> {
|
||||
@@ -85,6 +85,7 @@ pub fn decode_as_with(format: Format, bytes: &[u8], opts: &DecodeOptions) -> Res
|
||||
Format::Dpx => dpx::decode(bytes, l),
|
||||
Format::Cineon => dpx::decode_cineon(bytes, l),
|
||||
Format::Dicom => dicom::decode(bytes, l),
|
||||
Format::Iff => iff::decode(bytes, l),
|
||||
Format::OpenExr => exr::decode(bytes, l),
|
||||
Format::Heif => heif::decode(bytes, l, opts.keep_orientation),
|
||||
Format::Gif | Format::Bmp | Format::Tga | Format::Ico | Format::Qoi | Format::Hdr | Format::Avif => via_image::decode(format, bytes, l),
|
||||
@@ -285,6 +286,7 @@ pub fn encode(image: &Image, format: Format, opts: &EncodeOptions) -> Result<Vec
|
||||
Format::Dpx => dpx::encode(image, plan, opts),
|
||||
Format::Cineon => Err(CodecError::unsupported(format, "Cineon is import-only; save as DPX, TIFF or EXR instead")),
|
||||
Format::Dicom => Err(CodecError::unsupported(format, "DICOM is import-only; save as TIFF or PNG instead")),
|
||||
Format::Iff => Err(CodecError::unsupported(format, "IFF/ILBM is import-only; save as PNG instead")),
|
||||
Format::OpenExr => exr::encode(image, plan, opts),
|
||||
Format::Heif => Err(CodecError::unsupported(format, "encoding is not available in this build")),
|
||||
Format::Gif | Format::Bmp | Format::Tga | Format::Ico | Format::Qoi | Format::Hdr | Format::Avif => via_image::encode(format, image, plan, opts),
|
||||
|
||||
@@ -199,6 +199,22 @@ fn detect_magic_cineon() {
|
||||
// A bare magic is an error, never a panic.
|
||||
assert!(decode_as(Format::Cineon, &b).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn detect_magic_iff() {
|
||||
// FORM + a four-byte length + the bitmap type.
|
||||
assert_eq!(detect(b"FORM\0\0\0\x14ILBM"), Some(Format::Iff));
|
||||
assert_eq!(detect(b"FORM\0\0\0\x14PBM "), Some(Format::Iff));
|
||||
assert_eq!(from_extension("art.LBM"), Some(Format::Iff));
|
||||
assert_eq!(from_extension("art.ilbm"), Some(Format::Iff));
|
||||
assert!(caps(Format::Iff).read && !caps(Format::Iff).write, "IFF is read-only");
|
||||
assert!(caps(Format::Iff).alpha);
|
||||
assert!(caps(Format::Iff).layouts.contains(&photocraft_codecs::ChannelLayout::Rgba));
|
||||
assert!(ASYMMETRIC_EXCEPTIONS.iter().any(|(f, _)| *f == Format::Iff));
|
||||
// A bare FORM without a bitmap type is not IFF.
|
||||
assert_eq!(detect(b"FORM\0\0\0\x14AIFF"), None);
|
||||
assert!(decode_as(Format::Iff, b"FORM\0\0\0\x14ILBM").is_err());
|
||||
}
|
||||
#[test]
|
||||
fn detect_magic_avif() {
|
||||
assert_eq!(detect(b"\0\0\0\x1cftypavif\0\0\0\0avifmif1miaf"), Some(Format::Avif));
|
||||
|
||||
@@ -47,7 +47,7 @@ XL are missing (gap G10). Remaining: 300–500 h including PSD fidelity.
|
||||
| DICOM | R/W | yes (#1048) | no | Read-only, uncompressed syntaxes: MONOCHROME1/2, RGB, YBR_FULL |
|
||||
| PCX | R/W | no | no | |
|
||||
| Pixar | R/W | no | no | |
|
||||
| Amiga IFF | R/W | no | no | |
|
||||
| Amiga IFF | R/W | yes | no | Read-only: 1–8 planes with CMAP, stored and ByteRun1 |
|
||||
| Wireless Bitmap | R/W | no | no | |
|
||||
| MPO / JPS (stereo) | R/W | no | no | |
|
||||
| PICT | R | no | no | Legacy |
|
||||
|
||||
+6
-2
@@ -1,6 +1,6 @@
|
||||
# Where PhotoCraft falls short of Photoshop
|
||||
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-18 · **Change:** minor (G9: Preferences › File Handling › Save in Background takes effect, #6207, 24 of 169 preferences do nothing; G7: Content-Aware Move previews every selection the command takes, coarse then exact, TOOL-213-4 done, #6680; G4: Pattern Stamp and Background Eraser draw live, TOOL-213-7; G9: Animated Zoom pref read: holding the Zoom tool zooms continuously, #6210, prefs that do nothing 25 of 166; G2: a cancelled 24 MP Gaussian Blur job stops in at most 44 ms, P25 under its 200 ms budget in local runs, baseline not re-run, #6205; G1: generated large-file fixtures, a 4.38 GB PSB opens on Windows through io, FILE-216-2 done, #5107; G9: fill and adjustment layers copy and paste whole, #2344; G1: smart filter masks show on PSD open, Photoshop-oracle floor 188/258; G10: DPX read and write, #1049, Cineon read; G1: CMYK Hue/Saturation and Color Balance keep the black ink; G1: CMYK Posterize on the stored values, psd-tools oracle floor 242/309; G1: CMYK adjustment layers composite on the document's inks, Photoshop-oracle floor 165/258; G1: CMYK Brightness/Contrast on the inks, CMYK Threshold's luma; G1: modern Brightness/Contrast's brightness curve matches Photoshop, Photoshop-oracle floor 151/258; G1: Lab documents composite on their stored L, a, b, Photoshop-oracle floor 152/258; G1: Levels on whole levels at every step, Photoshop-oracle floor 146/258, psd-tools 238/309; G1: 32-bit Brightness/Contrast legacy, Channel Mixer, Photo Filter and Black & White tint unclipped as in Photoshop, Photoshop-oracle floor 149/258; G1: mask feathers blur with their exact variance, psd-tools oracle floor 240/309; G1: Threshold splits on Photoshop's luminosity, psd-tools oracle floor 241/309; G1: pass-through clipping base with an adjustment renders isolated, psd-tools oracle floor 240/309; G1: 16-bit Posterize as Photoshop bins it, psd-tools oracle floor 241/309; G1: Gradient Map driven by the W3C luminosity, Photoshop-oracle floor 147/258; G7: Field Blur's on-canvas pins, #3373; G4: Hue Jitter amount track, #3825 partial; G4: minimum field interaction, #3825 partial; G1: CMYK Invert, Posterize and Threshold on the inks, 16-bit Lab Invert; Photoshop-oracle floor 145/258; G11: `.atn` import maps 112 events: Select and Mask, Filter Gallery Spatter, Ripple, Crystallize, Pattern Fill layers, mask targeting, Step Backward, nudges in points, Bitmap mode; G5: Free Transform H/V skew fields; G9: toolbar tool shortcut editing; refreshed against main: G2, G5, G7, G9, G10, G13, G14, G17 items that landed; G10: DPX read and write, #1049; G4: checkbox-only Brush Settings rows; G11: Load/Save Actions `.atn` landed, AUTO-219-2 partial; G5: hold-a-key spring-loaded tools landed, #2672; G1: #2465 fixed; stale missing-tool rows corrected: Color Replacement, Red Eye and Add/Delete Anchor Point are live tools, so only Art History Brush is missing; no estimate changed) · **Target:** Adobe Photoshop 2026
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-18 · **Change:** minor (G9: Preferences › File Handling › Save in Background takes effect, #6207, 24 of 169 preferences do nothing; G7: Content-Aware Move previews every selection the command takes, coarse then exact, TOOL-213-4 done, #6680; G4: Pattern Stamp and Background Eraser draw live, TOOL-213-7; G9: Animated Zoom pref read: holding the Zoom tool zooms continuously, #6210, prefs that do nothing 25 of 166; G2: a cancelled 24 MP Gaussian Blur job stops in at most 44 ms, P25 under its 200 ms budget in local runs, baseline not re-run, #6205; G1: generated large-file fixtures, a 4.38 GB PSB opens on Windows through io, FILE-216-2 done, #5107; G9: fill and adjustment layers copy and paste whole, #2344; G1: smart filter masks show on PSD open, Photoshop-oracle floor 188/258; G10: DPX read and write, #1049, Cineon and Amiga IFF read; G1: CMYK Hue/Saturation and Color Balance keep the black ink; G1: CMYK Posterize on the stored values, psd-tools oracle floor 242/309; G1: CMYK adjustment layers composite on the document's inks, Photoshop-oracle floor 165/258; G1: CMYK Brightness/Contrast on the inks, CMYK Threshold's luma; G1: modern Brightness/Contrast's brightness curve matches Photoshop, Photoshop-oracle floor 151/258; G1: Lab documents composite on their stored L, a, b, Photoshop-oracle floor 152/258; G1: Levels on whole levels at every step, Photoshop-oracle floor 146/258, psd-tools 238/309; G1: 32-bit Brightness/Contrast legacy, Channel Mixer, Photo Filter and Black & White tint unclipped as in Photoshop, Photoshop-oracle floor 149/258; G1: mask feathers blur with their exact variance, psd-tools oracle floor 240/309; G1: Threshold splits on Photoshop's luminosity, psd-tools oracle floor 241/309; G1: pass-through clipping base with an adjustment renders isolated, psd-tools oracle floor 240/309; G1: 16-bit Posterize as Photoshop bins it, psd-tools oracle floor 241/309; G1: Gradient Map driven by the W3C luminosity, Photoshop-oracle floor 147/258; G7: Field Blur's on-canvas pins, #3373; G4: Hue Jitter amount track, #3825 partial; G4: minimum field interaction, #3825 partial; G1: CMYK Invert, Posterize and Threshold on the inks, 16-bit Lab Invert; Photoshop-oracle floor 145/258; G11: `.atn` import maps 112 events: Select and Mask, Filter Gallery Spatter, Ripple, Crystallize, Pattern Fill layers, mask targeting, Step Backward, nudges in points, Bitmap mode; G5: Free Transform H/V skew fields; G9: toolbar tool shortcut editing; refreshed against main: G2, G5, G7, G9, G10, G13, G14, G17 items that landed; G10: DPX read and write, #1049; G4: checkbox-only Brush Settings rows; G11: Load/Save Actions `.atn` landed, AUTO-219-2 partial; G5: hold-a-key spring-loaded tools landed, #2672; G1: #2465 fixed; stale missing-tool rows corrected: Color Replacement, Red Eye and Add/Delete Anchor Point are live tools, so only Art History Brush is missing; no estimate changed) · **Target:** Adobe Photoshop 2026
|
||||
|
||||
Every known shortfall against Photoshop 2026 (27.11.0), one entry each, ranked by user impact
|
||||
on the way to beta. This is the work list agents pick from: take the highest-ranked entry that
|
||||
@@ -245,12 +245,15 @@ what an agent can't finish alone.
|
||||
- **Missing:** JPEG Options dialog (FILE-215-19), Photoshop PDF read and its vector/text/multi-page
|
||||
write (FILE-215-10, #2541; a single flattened page now saves via Save As / Save a Copy / CLI,
|
||||
2026-10-11, #3401), AVIF read (#463) and default-build AVIF write, JPEG XL, JPEG 2000 (#1047),
|
||||
Cineon write (read landed), DICOM, EPS/DCS, Pixar, IFF, WBMP, MPO/JPS, PICT, Scitex CT, Photoshop
|
||||
Cineon write (read landed), DICOM, EPS/DCS, Pixar, IFF write (read landed), WBMP, MPO/JPS, PICT, Scitex CT, Photoshop
|
||||
Raw; layered TIFF extra alpha channels (FILE-215-7); spot plates (FILE-215-17); .atn, .asl,
|
||||
.shc, .csh presets (FILE-215-15); C2PA (#1050).
|
||||
- **Detail:** [`file-format-parity.md`](file-format-parity.md).
|
||||
- **Progress (2026-10-13):** Cineon (`.cin`) 10-bit gray/RGB frames open read-only, sharing the
|
||||
DPX header/unpacking (`crates/codecs/src/codecs/dpx.rs`); writing is still open.
|
||||
- **Progress (2026-10-13):** Amiga IFF/ILBM (`FORM ... ILBM`/`PBM `) 1–8-plane paletted bitmaps
|
||||
open read-only, stored or ByteRun1-compressed (`crates/codecs/src/codecs/iff.rs`); writing is
|
||||
still open.
|
||||
- **Estimate:** 120–220 h.
|
||||
|
||||
## Hardware gaps
|
||||
@@ -315,6 +318,7 @@ what an agent can't finish alone.
|
||||
| 2026-10-13 | minor | G1: 16-bit Posterize bins the 16-bit sample, as Photoshop does (exact on two oracles); psd-tools floor → 241 of 309 |
|
||||
| 2026-10-13 | minor | G1: Gradient Map driven by the W3C luminosity (0.3, 0.59, 0.11), as Photoshop is; rgb8/rgb16 gradient-map pass; Photoshop-oracle floor 145 → 147 of 258 |
|
||||
| 2026-10-13 | minor | G6: stale "missing tool" list corrected against `main` — Color Replacement (`paint.colorReplacement`), Red Eye (`paint.redEye`) and Add/Delete Anchor Point (P flyout, #4144) are live tools, so the toolbox is 67 of 68 and Art History Brush is the only one missing; no percentage or estimate changed |
|
||||
| 2026-10-13 | minor | G10: Amiga IFF/ILBM read landed (1–8 planes, CMAP, stored and ByteRun1); IFF write remains open |
|
||||
| 2026-10-13 | minor | G4: Hue Jitter amount-track appearance (#3825, partial); no readiness percentage or estimate changed |
|
||||
| 2026-10-13 | minor | G4: minimum inputs in Shape Dynamics and Transfer follow their Control (#3825, partial); no readiness percentage or estimate changed |
|
||||
| 2026-10-12 | minor | G5: Free Transform options bar H/V skew fields done |
|
||||
|
||||
Reference in new issue
Block a user