Skip to main content

Crate dcm4rs

Crate dcm4rs 

Source
Expand description

DICOM data model and file I/O.

Four constraints shape this crate:

  1. Stored as-is: element values are kept as the raw bytes defined by the standard; number and text interpretation is deferred until read time. Data under any transfer syntax (explicit/implicit VR, big endian, and whatever is added later) can therefore be written back byte for byte, and the parser never has to guess.
  2. Explicit endianness: numeric decoding always takes an Endian; there is no hidden global byte-order state.
  3. Lean dependencies: character set decoding uses encoding_rs; JPEG decoding uses zune-jpeg behind the default pixel-jpeg feature, JPEG-LS uses charls behind the pixel-jpegls feature, JPEG 2000 uses jpeg2k (with the pure-Rust openjp2 port) behind pixel-j2k, JPEG XL uses jxl-oxide behind pixel-jxl, and further codecs stay feature-gated, so dcm4rs stays embeddable in long-lived products such as a PACS.
  4. Canonical writing: sequences are written with defined lengths and group length elements are dropped, so a data set read from an undefined-length file comes back canonicalized while decoded content stays identical.
use dcm4rs::{DataSet, Tag, Value, Vr};

let mut ds = DataSet::new();
ds.set(Tag::new(0x0010, 0x0010), Vr::Pn, Value::from_str("Doe^John"));
ds.set(Tag::new(0x0028, 0x0010), Vr::Us, Value::from_u16s(&[512]));

assert_eq!(ds.string(Tag::new(0x0010, 0x0010)).unwrap(), "Doe^John");
assert_eq!(ds.u16(Tag::new(0x0028, 0x0010)).unwrap(), 512);

let syntax = dcm4rs::TransferSyntax::ExplicitVrLittleEndian;
let bytes = ds.write(syntax).unwrap();
assert_eq!(DataSet::read(&bytes, syntax).unwrap(), ds);

Re-exports§

pub use pixels::PhotometricInterpretation;
pub use pixels::PixelDescriptor;
pub use pixels::PixelRepresentation;
pub use pixels::PlanarConfiguration;
pub use uid::Uid;
pub use valuerep::Date;
pub use valuerep::DateTime;
pub use valuerep::DecimalString;
pub use valuerep::IntegerString;
pub use valuerep::PersonName;
pub use valuerep::Time;

Modules§

dictionary
DICOM data dictionary (PS3.6 Chapter 6, Registry of DICOM Data Elements).
encaps
Encapsulated pixel data: fragments, items and the offset tables.
mpeg
MPEG-2 sequence headers, and nothing beyond them.
pixels
Pixel data decoding: descriptors, frame extraction and codecs.
uid
DICOM unique identifiers: validation and the PS3.6 registry.
valuerep
Typed views over the values this crate stores as bytes.
waveform
Waveform decoding: the multiplex groups of (5400,0100) (PS3.3 C.10.9.1).

Structs§

DataSet
An ordered collection of data elements, corresponding to one DICOM Data Set or one Item.
DeferredElement
An element whose value a read skipped because it reached ReadOptions::defer_size.
DicomDir
A media storage directory: the File-set attributes plus the directory records.
DicomFile
A DICOM Part 10 file: the file meta information plus the main data set.
DirectoryRecord
A directory record and the records below it.
Element
A DICOM data element: tag, VR and value.
PrivateBlock
The elements one private creator owns in one group.
PrivateDictionary
A mapping from private creators and element offsets to value representations.
ReadOptions
Reading behaviour for files written by implementations that depart from the standard.
Tag
A DICOM data element tag: a 16-bit group number plus a 16-bit element number.

Enums§

Charset
The character set a data set declares for its text values.
Endian
Byte order.
Error
Errors the data model and the encoders can produce.
TransferSyntax
A DICOM transfer syntax.
Value
The raw value of an element.
Vr
DICOM Value Representation: the 34 VRs defined by PS3.5.

Type Aliases§

Result
Convenience result alias.