Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Merge remote-tracking branch 'origin/main' into feat/dicom-read

Vikram Bhaskaran529fb667f9f6
diff --cc apps/photocraft-web/src/web.rs
index 290561ee2,eb350d17e..83b8c2006
--- a/apps/photocraft-web/src/web.rs
+++ b/apps/photocraft-web/src/web.rs
@@@ -18,8 -18,8 +18,8 @@@ type Inbox = Arc<Mutex<Vec<(String, Vec
/// Photoshop brushes (.abr), gradients (.grd) and swatches (.aco, .ase), which go to the preset libraries.
const OPEN_EXTS: &[&str] = &[
"pcraft", "pdn", "ora", "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", "dcm", "dicom", "dc3", "heic", "heif", "hif", "dng", "cr2", "cr3", "nef", "nrw",
- "arw", "pef", "orf", "rw2", "raf", "abr", "grd", "svg", "svgz", "aco", "ase", "af", "afdesign", "afphoto", "afpub",
- "pbm", "pgm", "ppm", "pam", "pfm", "dds", "fits", "fit", "fts", "dpx", "cin", "heic", "heif", "hif", "dng", "cr2", "cr3", "nef", "nrw", "arw", "pef",
++ "pbm", "pgm", "ppm", "pam", "pfm", "dds", "fits", "fit", "fts", "dpx", "cin", "dcm", "dicom", "dc3", "heic", "heif", "hif", "dng", "cr2", "cr3", "nef", "nrw", "arw", "pef",
+ "orf", "rw2", "raf", "abr", "grd", "svg", "svgz", "aco", "ase", "af", "afdesign", "afphoto", "afpub",
];
const SVG_EXTS: &[&str] = &["svg", "svgz"];
const CANVAS_ID: &str = "photocraft_canvas";
diff --cc apps/photocraft/src/services.rs
index f359aea96,9de1c475e..9cffaf284
--- a/apps/photocraft/src/services.rs
+++ b/apps/photocraft/src/services.rs
@@@ -21,8 -21,8 +21,8 @@@ mod recovery_tests
/// (.kys), which go to the preset libraries and Edit › Keyboard Shortcuts.
const OPEN_EXTS: &[&str] = &[
"pcraft", "pdn", "ora", "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", "dcm", "dicom", "dc3", "heic", "heif", "hif", "dng", "cr2", "cr3",
- "nef", "nrw", "arw", "pef", "orf", "rw2", "raf", "abr", "grd", "svg", "svgz", "aco", "ase", "kys", "af", "afdesign", "afphoto", "afpub",
- "pbm", "pgm", "ppm", "pam", "pfm", "pcx", "dds", "xpm", "fits", "fit", "fts", "dpx", "cin", "heic", "heif", "hif", "dng", "cr2", "cr3", "nef", "nrw",
++ "pbm", "pgm", "ppm", "pam", "pfm", "pcx", "dds", "xpm", "fits", "fit", "fts", "dpx", "cin", "dcm", "dicom", "dc3", "heic", "heif", "hif", "dng", "cr2", "cr3", "nef", "nrw",
+ "arw", "pef", "orf", "rw2", "raf", "abr", "grd", "svg", "svgz", "aco", "ase", "kys", "af", "afdesign", "afphoto", "afpub",
];
const SVG_EXTS: &[&str] = &["svg", "svgz"];
diff --cc crates/codecs/README.md
index 51f51c3f0,d4f709489..2c9bba48a
--- a/crates/codecs/README.md
+++ b/crates/codecs/README.md
@@@ -47,7 -47,7 +47,8 @@@ let out = encode(&img, Format::Tiff, &E
| Radiance HDR | yes | yes | F32 | RGB | no | no | no | no | no | no | yes (RGBE) | `image` |
| FITS | yes | yes | U8, U16, F32 | Gray, RGB | no | no | no | no | no | yes (header cards) | no | built in |
| 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 |
| 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` |
@@@ -94,17 -94,16 +95,25 @@@ embedded table (and a PNG's transparen
big-endian, one unencoded element, at `EncodeOptions::dpx_bits` (8/10/12/16; by default 8 for
U8 and 16 otherwise), packing 1 for 10 and 12 bits; gray with alpha is written as luma.
Other descriptors, signed or run-length-encoded data and other bit depths return
- `CodecError::Unsupported` naming the field. Cineon (`.cin`) is not supported.
+ `CodecError::Unsupported` naming the field.
+
+ * **Cineon (read-only).** Kodak's 10-bit logarithmic film-scan format (the one DPX grew from),
+ read from the same Kodak header family: the generic 1024-byte header, big-endian, one (Gray)
+ or three (RGB) channels, three 10-bit samples packed into each 32-bit word, lines on a word
+ boundary. The 10-bit code values open as U16 `round(c × 65535 / 1023)`; the file's black/white
+ reference points are a log-conversion choice and are not applied. A depth other than 10 bits or
+ a channel count other than 1/3 returns `CodecError::Unsupported`; truncation errors rather than
+ panicking. There is no Cineon writer (`ASYMMETRIC_EXCEPTIONS`); save as DPX, TIFF or EXR.
+* **DICOM (read-only).** Single-frame medical images over the uncompressed transfer syntaxes
+ (implicit VR little-endian, explicit VR little/big-endian): MONOCHROME1/2 gray (with the
+ 1 = white inversion) and RGB/YBR_FULL, 8- and 16-bit allocated samples, interleaved or planar,
+ scaled from `BitsStored`/`HighBit` and mapped up when `PixelRepresentation` is signed.
+ Undefined-length sequences outside the pixel data are skipped, as clinical files contain them.
+ Compressed transfer syntaxes, sequences over the pixel data and other photometric
+ interpretations return `Unsupported`/`Malformed`. There is no DICOM writer
+ (`ASYMMETRIC_EXCEPTIONS`).
+
* **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.
diff --cc crates/codecs/src/format.rs
index de6ecafb2,fa2e1e6cb..f4672da9e
--- a/crates/codecs/src/format.rs
+++ b/crates/codecs/src/format.rs
@@@ -33,8 -33,8 +33,10 @@@ pub enum Format
Fits,
/// DPX (SMPTE 268M Digital Picture Exchange): luma, RGB or RGBA film and video frames.
Dpx,
+ /// Kodak Cineon (`.cin`, the 10-bit film-scan format DPX grew from): read-only.
+ Cineon,
+ /// DICOM single-frame images (uncompressed): read-only.
+ Dicom,
}
/// What a format can hold **and** what this crate reads/writes for it.
@@@ -101,7 -104,7 +110,7 @@@ const TIFF_LAYOUTS: &[ChannelLayout] =
impl Format {
/// Every format known to the crate (enabled or not).
-- pub const ALL: [Format; 20] = [
++ pub const ALL: [Format; 21] = [
Format::Png,
Format::Jpeg,
Format::Tiff,
@@@ -121,7 -124,7 +130,8 @@@
Format::Heif,
Format::Fits,
Format::Dpx,
+ Format::Cineon,
+ Format::Dicom,
];
pub fn caps(self) -> FormatCaps {
@@@ -155,7 -158,7 +165,8 @@@
Format::Heif => "HEIF",
Format::Fits => "FITS",
Format::Dpx => "DPX",
+ Format::Cineon => "Cineon",
+ Format::Dicom => "DICOM",
}
}
@@@ -182,7 -185,7 +193,8 @@@
Format::Heif => &["heic", "heif", "hif"],
Format::Fits => &["fits", "fit", "fts"],
Format::Dpx => &["dpx"],
+ Format::Cineon => &["cin"],
+ Format::Dicom => &["dcm", "dicom", "dc3"],
}
}
@@@ -207,7 -210,7 +219,8 @@@
Format::Heif => "image/heif",
Format::Fits => "image/fits",
Format::Dpx => "image/x-dpx",
+ Format::Cineon => "image/x-cin",
+ Format::Dicom => "application/dicom",
}
}
@@@ -263,7 -266,7 +276,8 @@@ pub fn caps(format: Format) -> FormatCa
Format::Fits => FormatCaps { depths: &[S::U8, S::U16, S::F32], layouts: &[L::Gray, L::Rgb], alpha: false, text: true, ..base },
// `text`: the DPX header fields only (see `fidelity_warnings_with`).
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 },
}
}
@@@ -318,9 -321,9 +332,12 @@@ pub fn detect(bytes: &[u8]) -> Option<F
if b.starts_with(b"SDPX") || b.starts_with(b"XPDS") {
return Some(Format::Dpx);
}
+ if crate::codecs::dpx::is_cineon(b) {
+ return Some(Format::Cineon);
+ }
+ if crate::codecs::dicom::is_dicom(b) {
+ return Some(Format::Dicom);
+ }
if b.starts_with(b"SIMPLE =") {
return Some(Format::Fits);
}
diff --cc crates/codecs/src/lib.rs
index bef7623d1,86611599d..9b93bc708
--- a/crates/codecs/src/lib.rs
+++ b/crates/codecs/src/lib.rs
@@@ -79,7 -80,7 +80,8 @@@ pub fn decode_as_with(format: Format, b
Format::Dds => dds::decode(bytes, l),
Format::Fits => fits::decode(bytes, l),
Format::Dpx => dpx::decode(bytes, l),
+ Format::Cineon => dpx::decode_cineon(bytes, l),
+ Format::Dicom => dicom::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),
@@@ -232,7 -255,7 +256,8 @@@ pub fn encode(image: &Image, format: Fo
Format::Dds => Err(CodecError::unsupported(format, "DDS is import-only; save as PNG instead")),
Format::Fits => fits::encode(image, plan, opts),
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::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),
diff --cc docs/file-format-parity.md
index 74a159a25,ba7462370..8efc6a541
--- a/docs/file-format-parity.md
+++ b/docs/file-format-parity.md
@@@ -43,8 -43,8 +43,8 @@@ XL are missing (gap G10). Remaining: 30
| Generic EPS / AI | R (rasterize) | no | no | |
| SVG | R (rasterize) | yes, as editable shape layers or a vector smart object | no | Better than Photoshop for editing; gradients approximated (FILE-215-9) |
| JPEG 2000 | R/W | no (#1047) | no | |
- | Cineon / DPX | R (DPX), R/W (CIN) | DPX: luma, RGB, RGBA at 8/10/12/16 bits, both byte orders (#1049); Cineon no | DPX: 8/10/12/16 bits (`dpxBits`, `--dpx-bits`); Cineon no | Writes DPX, which Photoshop only reads; header fields (creator, project, copyright, transfer, frame rate, time code…) round-trip; no Cineon, no RLE |
+ | Cineon / DPX | R (DPX), R/W (CIN) | DPX: luma, RGB, RGBA at 8/10/12/16 bits, both byte orders (#1049); Cineon: 10-bit gray/RGB, read-only | DPX: 8/10/12/16 bits (`dpxBits`, `--dpx-bits`); Cineon no | Writes DPX, which Photoshop only reads; header fields (creator, project, copyright, transfer, frame rate, time code…) round-trip; Cineon read-only, no RLE |
-| DICOM | R/W | no | no | |
+| 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 | |