imodfile 0.1.0

A pure-Rust IMOD model file decoder/encoder — binary & ASCII, with Python bindings
Documentation
//! Four-byte chunk IDs used in the IMOD binary format — all UPPERCASE.
//!
//! The C code defines: `#define MakeID(c1,c2,c3,c4) ((u32)(c1) | ((u32)(c2)<<8) | ((u32)(c3)<<16) | ((u32)(c4)<<24))`
//! All values are stored big-endian in the file.

/// Helper to build a 4-char chunk ID (big-endian storage, as per IMOD spec).
const fn make_id(a: u8, b: u8, c: u8, d: u8) -> u32 {
    (a as u32) << 24 | (b as u32) << 16 | (c as u32) << 8 | d as u32
}

// ── Major chunks ──

/// "IMOD" — file header magic (all caps).
pub const ID_IMOD: u32 = make_id(b'I', b'M', b'O', b'D');

/// Version string — real files use e.g. "V1.2".
pub const ID_VERSION_V12: u32 = make_id(b'V', b'1', b'.', b'2');

/// "V0.1" — version 0.1 (very old files).
pub const ID_V01: u32 = make_id(b'V', b'0', b'.', b'1');

/// "OBJT" — object chunk.
pub const ID_OBJT: u32 = make_id(b'O', b'B', b'J', b'T');

/// "CONT" — contour chunk.
pub const ID_CONT: u32 = make_id(b'C', b'O', b'N', b'T');

/// "MESH" — mesh chunk.
pub const ID_MESH: u32 = make_id(b'M', b'E', b'S', b'H');

/// "IEOF" — end-of-file marker.
pub const ID_IEOF: u32 = make_id(b'I', b'E', b'O', b'F');

// ── Sub-chunks ──

/// "CLIP" — clipping planes.
pub const ID_CLIP: u32 = make_id(b'C', b'L', b'I', b'P');

/// "IMAT" — material properties.
pub const ID_IMAT: u32 = make_id(b'I', b'M', b'A', b'T');

/// "LABL" — contour label.
pub const ID_LABL: u32 = make_id(b'L', b'A', b'B', b'L');

/// "OLBL" — object label.
pub const ID_OLBL: u32 = make_id(b'O', b'L', b'B', b'L');

/// "SIZE" — per-point sizes.
pub const ID_SIZE: u32 = make_id(b'S', b'I', b'Z', b'E');

/// "VIEW" — view data.
pub const ID_VIEW: u32 = make_id(b'V', b'I', b'E', b'W');

/// "MCLP" — view clip planes.
pub const ID_MCLP: u32 = make_id(b'M', b'C', b'L', b'P');

/// "IMNX" — image native transform.
pub const ID_IMNX: u32 = make_id(b'I', b'M', b'N', b'X');

/// "MOST" — model general storage.
pub const ID_MOST: u32 = make_id(b'M', b'O', b'S', b'T');

/// "OBST" — object general storage.
pub const ID_OBST: u32 = make_id(b'O', b'B', b'S', b'T');

/// "COST" — contour general storage.
pub const ID_COST: u32 = make_id(b'C', b'O', b'S', b'T');

/// "MEST" — mesh general storage.
pub const ID_MEST: u32 = make_id(b'M', b'E', b'S', b'T');

/// "MEPA" — meshing parameters.
pub const ID_MEPA: u32 = make_id(b'M', b'E', b'P', b'A');

/// "SKLI" — mesh skip list.
pub const ID_SKLI: u32 = make_id(b'S', b'K', b'L', b'I');

/// "SLAN" — slicer angles.
pub const ID_SLAN: u32 = make_id(b'S', b'L', b'A', b'N');

/// "OGRP" — object groups.
pub const ID_OGRP: u32 = make_id(b'O', b'G', b'R', b'P');

/// "PNTS" — old-format contour points marker.
pub const ID_PNTS: u32 = make_id(b'P', b'N', b'T', b'S');

// ── Size constants ──

/// Base size of a clip data chunk (4 bytes of count+flags + 24 bytes for one plane).
pub const SIZE_CLIP: u32 = 28;

/// Size of a material data chunk (4×4 = 16 bytes).
pub const SIZE_IMAT: u32 = 16;

/// Base size of a slicer-angle data chunk (4 bytes time + 24 bytes floats + label).
pub const SIZE_SLAN: u32 = 4 + 24 + 128; // 156

/// String size for model name.
pub const IMOD_STRSIZE: usize = 128;

/// String size for object name.
pub const IOBJ_STRSIZE: usize = 64;

/// Number of extra ints in object (64 bytes = 16 ints, per spec).
pub const IOBJ_EXSIZE: usize = 16;

/// Maximum number of clip planes.
pub const IMOD_CLIPSIZE: usize = 10;

/// String size for view label.
pub const VIEW_STRSIZE: usize = 128;

/// String size for slicer-angle label.
pub const ANGLE_STRSIZE: usize = 128;

/// Bytes per object view structure in view chunk.
pub const BYTES_PER_OBJVIEW: i32 = 43 + 24 * IMOD_CLIPSIZE as i32;