catwalk3d 2.3.0

Headless model thumbnails rendered entirely in Rust
//! Saved images extracted from document containers without opening model geometry.
//!
//! Supported carriers and versions are documented in `docs/format-coverage.md`.
//! A document can be valid while containing no saved preview.
/// Saved PNG extraction from Autodesk Fusion archives.
pub mod autodesk;
/// Addressed thumbnail extraction from Blender and AutoCAD containers.
pub mod blend_dwg;
/// Addressed PNG extraction from qualified FreeCAD document archives.
pub mod freecad;
/// Inventor property-set image selection and normalization.
pub mod inventor;
/// Direct XML thumbnail extraction from qualified LightBurn projects.
pub mod lightburn;
/// Addressed PNG extraction from qualified Lychee Mango scene containers.
pub mod lychee;
/// Addressed 3ds Max property-set metafile thumbnail extraction.
pub mod max;
/// Addressed Rhino document-properties bitmap extraction.
pub mod rhino;
/// Addressed model thumbnails from qualified `SketchUp` document containers.
pub mod sketchup;
/// Document-level `SolidWorks` part and assembly thumbnails from compound storage.
pub mod solidworks;

use crate::{Result, formats};
use image::RgbaImage;
use std::path::Path;

/// Extension aliases dispatched to the saved-image readers.
pub const EXTENSIONS: &[&str] = &[
    "ipt", "iam", "lbrn", "lbrn2", "blend", "f3d", "dwg", "lys", "fcstd", "3dm", "skp", "sldprt",
    "sldasm", "max",
];

/// A supported document has no usable saved thumbnail carrier.
#[derive(Debug)]
pub struct NoSavedPreview;

impl std::fmt::Display for NoSavedPreview {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str("document contains no supported saved preview")
    }
}

impl std::error::Error for NoSavedPreview {}

/// Return the saved image at its original size, or `None` when absent.
/// Inventor also returns `None` for a complete unsupported image carrier,
/// while malformed data and unsupported document versions return an error.
///
/// # Errors
/// Returns an error for missing or unsupported extensions, unreadable files,
/// malformed or unsupported document carriers, codec failures, or reader limits.
pub fn extract(path: &Path) -> Result<Option<RgbaImage>> {
    match formats::extension(path)?.as_str() {
        "ipt" | "iam" => inventor::extract(path),
        "lbrn" | "lbrn2" => lightburn::extract(path),
        "blend" => blend_dwg::extract_blend(path),
        "f3d" => autodesk::extract_fusion(path),
        "dwg" => blend_dwg::extract_dwg(path),
        "lys" => lychee::extract(path),
        "fcstd" => freecad::extract(path),
        "3dm" => rhino::extract(path),
        "skp" => sketchup::extract(path),
        "sldprt" | "sldasm" => solidworks::extract(path),
        "max" => max::extract(path),
        extension => Err(format!("no saved-preview reader for .{extension}").into()),
    }
}