walkzzz/image.core/types does not have a README file

    ImageLike

    pub(open) trait ImageLike {
    fn width(Self) -> Int
    fn height(Self) -> Int
    fn channels(Self) -> Int
    fn data(Self) -> Bytes
    fn bytes_per_pixel(Self) -> Int
    fn pixel_count(Self) -> Int = _
    fn byte_count(Self) -> Int = _
    fn is_grayscale(Self) -> Bool = _
    fn is_rgb(Self) -> Bool = _
    fn is_rgba(Self) -> Bool = _
    }

    图像统一接口 trait,抽象 8-bit / 16-bit / float 三种像素精度

    所有图像类型(Image / Image16 / ImageF / AnyImage)均实现此 trait, 允许泛型算法以统一方式访问图像几何信息与像素数据

    ImageError

    pub(all) suberror ImageError {
    Decode(ErrorCode, String)
    Encode(ErrorCode, String)
    Process(ErrorCode, String)
    Budget(ErrorCode, String)
    Cancelled(String)
    }

    统一图像错误 Unified image error

    变体 Variants:
    • Decode(ErrorCode, String) - 解码阶段 Decode phase
    • Encode(ErrorCode, String) - 编码阶段 Encode phase
    • Process(ErrorCode, String) - 像素处理阶段 Process phase
    • Budget(ErrorCode, String) - 预算/限额拒绝 Budget rejection
    • Cancelled(String) - 调用方取消 Caller cancelled

    ImageError::code

    fn ImageError::code(self : ImageError) -> String

    稳定错误码字符串,形如 decode/truncated、budget/limit_pixels、cancelled。 Stable code string such as decode/truncated, budget/limit_pixels, cancelled.

    ImageError::message

    fn ImageError::message(self : ImageError) -> String

    错误消息(面向人,含具体数值)。Human-readable message (may include concrete numbers).

    LoadError

    pub(all) suberror LoadError {
    FileIO(String)
    UnsupportedFormat(String)
    DecodeFailed(String)
    EncodeFailed(String)
    }

    加载失败领域错误 Load error domain type

    变体 Variants:
    • FileIO(String) - 文件 I/O 错误 File I/O error
    • UnsupportedFormat(String) - 不支持的图像格式 Unsupported image format
    • DecodeFailed(String) - 解码失败 Decode failure
    • EncodeFailed(String) - 编码失败 Encode failure
    impl Show for LoadError

    LoadError::output

    fn LoadError::output(self : LoadError, logger : &Logger) -> Unit

    补齐 Show 的 to_string 派生方法。Add the derived to_string from Show.

    LoadError::to_string

    fn LoadError::to_string(self : LoadError) -> String

    补齐 Show 的 to_string 派生方法。Add the derived to_string from Show.

    AllocBudget

    pub(all) struct AllocBudget {
    max_bytes : Int64
    }

    内存分配预算(供像素级算子使用)。Allocation budget for pixel operators.

    AllocBudget::check_image

    fn AllocBudget::check_image(self : AllocBudget, width : Int64, height : Int64, channels : Int64, what : String) -> Unit raise ImageError

    需要 width × height × channels 字节时的准入检查。Admission check for an allocation.

    AllocBudget::default_budget

    fn AllocBudget::default_budget() -> AllocBudget

    默认分配预算(512 MiB)。Default allocation budget.

    AnyImage

    pub(all) enum AnyImage {
    U8(Image)
    U16(Image16)
    F32(ImageF)
    } derive(Eq,
    Debug
    )

    统一图像容器,包装三种像素精度的图像

    用于需要统一处理不同精度图像的场景,如编解码器接口 #non_exhaustive 表示未来可能添加新构造器

    AnyImage::byte_count

    fn AnyImage::byte_count(self : AnyImage) -> Int

    AnyImage::bytes_per_pixel

    fn AnyImage::bytes_per_pixel(self : AnyImage) -> Int

    AnyImage::channels

    fn AnyImage::channels(self : AnyImage) -> Int

    AnyImage::data

    fn AnyImage::data(self : AnyImage) -> Bytes

    AnyImage::equal

    fn AnyImage::equal(AnyImage, AnyImage) -> Bool
    automatically derived

    AnyImage::height

    fn AnyImage::height(self : AnyImage) -> Int

    AnyImage::is_grayscale

    fn AnyImage::is_grayscale(self : AnyImage) -> Bool

    AnyImage::is_rgb

    fn AnyImage::is_rgb(self : AnyImage) -> Bool

    AnyImage::is_rgba

    fn AnyImage::is_rgba(self : AnyImage) -> Bool

    AnyImage::not_equal

    fn AnyImage::not_equal(x : AnyImage, y : AnyImage) -> Bool
    automatically derived

    AnyImage::pixel_count

    fn AnyImage::pixel_count(self : AnyImage) -> Int

    AnyImage::to_repr

    automatically derived

    AnyImage::width

    fn AnyImage::width(self : AnyImage) -> Int

    DecodeLimits

    pub(all) struct DecodeLimits {
    max_pixels : Int64
    max_bytes : Int64
    max_ms : Int64
    }

    解码/处理预算(默认保守)。Decode/process limits with conservative defaults.

    • max_pixels:总像素上限(默认 5 亿,与 MAX_TOTAL_PIXELS 一致)
    • max_bytes:输入字节上限(默认 256 MiB)
    • max_ms:单次处理时间上限(默认 10 秒;纯 MoonBit 同步实现下为"准入检查 + 事后判定",不能强杀)

    DecodeLimits::check_bytes

    fn DecodeLimits::check_bytes(self : DecodeLimits, bytes : Int64) -> Unit raise ImageError

    校验输入字节数是否超预算。Reject input whose byte length exceeds the budget.

    DecodeLimits::check_pixels

    fn DecodeLimits::check_pixels(self : DecodeLimits, width : Int64, height : Int64) -> Unit raise ImageError

    校验像素数是否超预算。Reject pixel counts exceeding the budget.

    DecodeLimits::default_limits

    fn DecodeLimits::default_limits() -> DecodeLimits

    默认预算。Default limits.

    DecodeLimits::strict_limits

    fn DecodeLimits::strict_limits() -> DecodeLimits

    严格预算(面向不可信输入的批处理/服务端)。Strict limits for untrusted input.

    DecodeLimits::with_max_pixels

    fn DecodeLimits::with_max_pixels(max_pixels : Int64) -> DecodeLimits

    按格式上限构造预算(只覆盖像素数,字节/时间沿用默认)。 Build limits overriding only the pixel budget.

    ErrorCode

    pub(all) enum ErrorCode {
    UnsupportedFormat
    InvalidHeader
    InvalidDimensions
    InvalidArgument
    Truncated
    DecodeFailed
    EncodeFailed
    ProcessFailed
    LimitBytes
    LimitPixels
    LimitTime
    Cancelled
    } derive(Eq,
    Debug
    )

    稳定错误码(字符串形式是小写蛇形,可直接出现在 JSON 的 code 字段)。 Stable error codes; the string form is lower_snake_case and safe for a JSON code field.

    ErrorCode::is_budget

    fn ErrorCode::is_budget(self : ErrorCode) -> Bool

    是否属于资源限额类错误(调用方可据此决定"换大预算重试"还是"直接拒绝")。 Whether the code is a budget/limit failure (caller may raise the budget and retry).

    ErrorCode::to_string

    fn ErrorCode::to_string(self : ErrorCode) -> String

    错误码 → 稳定字符串(小写蛇形,跨版本不变)。Error code to stable lower_snake_case string.

    GifAnimation

    pub(all) struct GifAnimation {
    frames : Array[Image]
    delays : Array[Int]
    } derive(Eq,
    Debug
    )

    动画 GIF 解码结果,包含多帧图像和每帧延迟(毫秒) Animated GIF decode result, containing multiple frames and per-frame delays (milliseconds)

    字段 Fields:
    • frames - 帧图像数组 Array of frame images
    • delays - 每帧延迟时间(毫秒)Per-frame delay in milliseconds

    GifAnimation::equal

    automatically derived

    GifAnimation::not_equal

    fn GifAnimation::not_equal(x : GifAnimation, y : GifAnimation) -> Bool
    automatically derived

    GifAnimation::to_repr

    automatically derived

    Image

    pub(all) struct Image {
    width : Int
    height : Int
    channels : Int
    data : Bytes
    } derive(Eq,
    Debug
    )

    字段 Fields:
    • width - 图像宽度(像素)Image width in pixels
    • height - 图像高度(像素)Image height in pixels
    • channels - 通道数(1/3/4)Number of channels (1/3/4)
    • data - 像素数据(长度 = width * height * channels)Pixel data (length = width * height * channels)
    impl ImageLike for Image

    Image::byte_count

    fn Image::byte_count(self : Image) -> Int

    Image::bytes_per_pixel

    fn Image::bytes_per_pixel(_ : Image) -> Int

    Image::channels

    fn Image::channels(self : Image) -> Int

    Image::data

    fn Image::data(self : Image) -> Bytes

    Image::equal

    fn Image::equal(Image, Image) -> Bool
    automatically derived

    Image::height

    fn Image::height(self : Image) -> Int

    Image::is_grayscale

    fn Image::is_grayscale(self : Image) -> Bool

    Image::is_rgb

    fn Image::is_rgb(self : Image) -> Bool

    Image::is_rgba

    fn Image::is_rgba(self : Image) -> Bool

    Image::not_equal

    fn Image::not_equal(x : Image, y : Image) -> Bool
    automatically derived

    Image::pixel_count

    fn Image::pixel_count(self : Image) -> Int

    Image::region

    fn Image::region(self : Image, x : Int, y : Int, w : Int, h : Int) -> ImageRegion

    取图像的一块区域视图(越界部分自动裁掉,不报错)。 区域为空时 width() / height() 为 0,to_image() 得到 0×0 图。

    Image::region_with

    fn Image::region_with(self : Image, region : Region) -> ImageRegion

    用现成的 Region 取区域视图(同样自动裁剪)。

    Image::to_repr

    automatically derived

    Image::width

    fn Image::width(self : Image) -> Int

    Image16

    pub(all) struct Image16 {
    width : Int
    height : Int
    channels : Int
    data : Bytes
    } derive(Eq,
    Debug
    )

    16-bit 解码结果值对象,像素数据为 16-bit 无符号整数(little-endian,每像素 2 字节) 16-bit decoded image value object, pixel data as 16-bit unsigned integers (little-endian, 2 bytes per pixel)

    字段 Fields:
    • width - 图像宽度(像素)Image width in pixels
    • height - 图像高度(像素)Image height in pixels
    • channels - 通道数(1/3/4)Number of channels (1/3/4)
    • data - 像素数据(长度 = width * height * channels * 2)Pixel data (length = width * height * channels * 2)

    Image16::byte_count

    fn Image16::byte_count(self : Image16) -> Int

    Image16::bytes_per_pixel

    fn Image16::bytes_per_pixel(_ : Image16) -> Int

    Image16::channels

    fn Image16::channels(self : Image16) -> Int

    Image16::data

    fn Image16::data(self : Image16) -> Bytes

    Image16::equal

    fn Image16::equal(Image16, Image16) -> Bool
    automatically derived

    Image16::height

    fn Image16::height(self : Image16) -> Int

    Image16::is_grayscale

    fn Image16::is_grayscale(self : Image16) -> Bool

    Image16::is_rgb

    fn Image16::is_rgb(self : Image16) -> Bool

    Image16::is_rgba

    fn Image16::is_rgba(self : Image16) -> Bool

    Image16::not_equal

    fn Image16::not_equal(x : Image16, y : Image16) -> Bool
    automatically derived

    Image16::pixel_count

    fn Image16::pixel_count(self : Image16) -> Int

    Image16::to_repr

    automatically derived

    Image16::width

    fn Image16::width(self : Image16) -> Int

    ImageF

    pub(all) struct ImageF {
    width : Int
    height : Int
    channels : Int
    data : Bytes
    } derive(Eq,
    Debug
    )

    HDR float 解码结果值对象,像素数据为 32-bit IEEE float(little-endian,每像素 4 字节) HDR float decoded image value object, pixel data as 32-bit IEEE float (little-endian, 4 bytes per pixel)

    字段 Fields:
    • width - 图像宽度(像素)Image width in pixels
    • height - 图像高度(像素)Image height in pixels
    • channels - 通道数(1/3/4)Number of channels (1/3/4)
    • data - 像素数据(长度 = width * height * channels * 4)Pixel data (length = width * height * channels * 4)
    impl ImageLike for ImageF

    ImageF::byte_count

    fn ImageF::byte_count(self : ImageF) -> Int

    ImageF::bytes_per_pixel

    fn ImageF::bytes_per_pixel(_ : ImageF) -> Int

    ImageF::channels

    fn ImageF::channels(self : ImageF) -> Int

    ImageF::data

    fn ImageF::data(self : ImageF) -> Bytes

    ImageF::equal

    fn ImageF::equal(ImageF, ImageF) -> Bool
    automatically derived

    ImageF::height

    fn ImageF::height(self : ImageF) -> Int

    ImageF::is_grayscale

    fn ImageF::is_grayscale(self : ImageF) -> Bool

    ImageF::is_rgb

    fn ImageF::is_rgb(self : ImageF) -> Bool

    ImageF::is_rgba

    fn ImageF::is_rgba(self : ImageF) -> Bool

    ImageF::not_equal

    fn ImageF::not_equal(x : ImageF, y : ImageF) -> Bool
    automatically derived

    ImageF::pixel_count

    fn ImageF::pixel_count(self : ImageF) -> Int

    ImageF::to_repr

    automatically derived

    ImageF::width

    fn ImageF::width(self : ImageF) -> Int

    ImageFormat

    pub(all) enum ImageFormat {
    Png
    Jpeg
    Bmp
    Gif
    Tga
    Psd
    Hdr
    Pnm
    Qoi
    Webp
    Tiff
    Ico
    Cur
    Icns
    Apng
    Avif
    Heif
    JpegXl
    Unknown
    } derive(Eq,
    Debug
    )

    图像格式枚举 Image format enum

    标识支持的图像编解码格式。#non_exhaustive 表示未来可能添加新格式。 Identifies supported image codec formats. #non_exhaustive means new formats may be added in the future.

    ImageFormat::equal

    fn ImageFormat::equal(ImageFormat, ImageFormat) -> Bool
    automatically derived

    ImageFormat::not_equal

    fn ImageFormat::not_equal(x : ImageFormat, y : ImageFormat) -> Bool
    automatically derived

    ImageFormat::to_repr

    automatically derived

    ImageInfo

    pub(all) struct ImageInfo {
    width : Int
    height : Int
    channels : Int
    } derive(Eq,
    Debug
    )

    图像信息查询结果,仅含几何元信息,不加载像素数据 Image info query result, geometry metadata only, no pixel data loaded

    字段 Fields:
    • width - 图像宽度(像素)Image width in pixels
    • height - 图像高度(像素)Image height in pixels
    • channels - 通道数(1/3/4)Number of channels (1/3/4)

    ImageInfo::equal

    fn ImageInfo::equal(ImageInfo, ImageInfo) -> Bool
    automatically derived

    ImageInfo::not_equal

    fn ImageInfo::not_equal(x : ImageInfo, y : ImageInfo) -> Bool
    automatically derived

    ImageInfo::to_repr

    automatically derived

    ImageRegion

    pub(all) struct ImageRegion {
    base : Image
    region : Region
    } derive(Eq,
    Debug
    )

    图像上的区域视图。持有 base 的共享引用,不复制像素。

    ImageRegion::channels

    fn ImageRegion::channels(self : ImageRegion) -> Int

    区域视图的通道数(与原图一致)。

    ImageRegion::get

    fn ImageRegion::get(self : ImageRegion, x : Int, y : Int, channel : Int) -> Byte

    读区域内的单通道字节;坐标相对区域左上角。越界返回 0(不 panic),便于算子边界处理。

    ImageRegion::height

    fn ImageRegion::height(self : ImageRegion) -> Int

    区域视图的高(可能因裁剪小于请求值)。

    ImageRegion::is_empty

    fn ImageRegion::is_empty(self : ImageRegion) -> Bool

    区域视图是否为空。

    ImageRegion::pixel

    fn ImageRegion::pixel(self : ImageRegion, x : Int, y : Int) -> Array[Byte]

    读区域内一个像素的全部通道,返回长度 channels 的数组。

    ImageRegion::region_of

    fn ImageRegion::region_of(self : ImageRegion) -> Region

    区域视图对应的 Region(已裁剪到图像内)。

    ImageRegion::to_image

    fn ImageRegion::to_image(self : ImageRegion) -> Image

    把区域视图物化为独立 Image(这一步才真正分配像素)。 与 crop 的差别:越界不报错,按裁剪后的有效区域输出。

    ImageRegion::width

    fn ImageRegion::width(self : ImageRegion) -> Int

    区域视图的宽(可能因裁剪小于请求值)。

    PngAnimation

    pub(all) struct PngAnimation {
    frames : Array[Image]
    delays : Array[Int]
    } derive(Eq,
    Debug
    )

    APNG 动画解码结果 APNG animation decode result

    字段 Fields:
    • frames - 帧图像数组 Array of frame images
    • delays - 每帧延迟时间(毫秒)Per-frame delay in milliseconds

    PngAnimation::equal

    automatically derived

    PngAnimation::not_equal

    fn PngAnimation::not_equal(x : PngAnimation, y : PngAnimation) -> Bool
    automatically derived

    PngAnimation::to_repr

    automatically derived

    Region

    pub(all) struct Region {
    x : Int
    y : Int
    w : Int
    h : Int
    } derive(Eq,
    Debug
    )

    矩形区域(左上角 + 宽高,单位像素)。坐标可为负或越界, 由 Region::clamp / Image::region 负责裁到图像边界内。

    Region::area

    fn Region::area(self : Region) -> Int

    区域像素数(宽 * 高)。非正尺寸时返回 0。

    Region::clamp

    fn Region::clamp(self : Region, width : Int, height : Int) -> Region

    把区域裁到 width * height 的画布内,返回可能缩小甚至为空的区域。 负宽/负高视为空;部分越界时保留交集。

    Region::is_empty

    fn Region::is_empty(self : Region) -> Bool

    区域是否为空(宽或高非正)。

    Region::new

    fn Region::new(x : Int, y : Int, w : Int, h : Int) -> Region

    构造区域。不做边界检查(越界由使用方或 clamp 处理)。

    ResizeEdge

    pub(all) enum ResizeEdge {
    Clamp
    Reflect
    Wrap
    Zero
    } derive(Eq,
    Debug
    )

    resize 边缘处理模式 Resize edge handling mode

    定义图像缩放时如何处理超出边界的像素坐标。 Defines how pixel coordinates beyond image boundaries are handled during resizing. #non_exhaustive 表示未来可能添加新构造器

    ResizeEdge::equal

    fn ResizeEdge::equal(ResizeEdge, ResizeEdge) -> Bool
    automatically derived

    ResizeEdge::not_equal

    fn ResizeEdge::not_equal(x : ResizeEdge, y : ResizeEdge) -> Bool
    automatically derived

    ResizeEdge::to_repr

    automatically derived

    ResizeFilter

    pub(all) enum ResizeFilter {
    Default
    Box
    Triangle
    CubicBSPline
    CatmullROM
    Mitchell
    PointSample
    } derive(Eq,
    Debug
    )

    resize 滤波器类型 Resize filter type

    用于图像缩放时的插值算法选择。 Selects interpolation algorithm for image resizing. #non_exhaustive 表示未来可能添加新构造器

    ResizeFilter::equal

    automatically derived

    ResizeFilter::not_equal

    fn ResizeFilter::not_equal(x : ResizeFilter, y : ResizeFilter) -> Bool
    automatically derived

    ResizeFilter::to_repr

    automatically derived

    DOC_TEST_BMP_1X1

    let DOC_TEST_BMP_1X1 : Bytes

    文档测试用 1×1 24-bit BMP 字节串(58 字节,红色像素 R=255 G=0 B=0) 1×1 24-bit BMP byte string for doc tests (58 bytes, red pixel R=255 G=0 B=0)

    DOC_TEST_PNG_1X1_RGBA

    let DOC_TEST_PNG_1X1_RGBA : Bytes

    文档测试用 1×1 RGBA PNG 字节串(73 字节,红色像素 R=255 G=0 B=0 A=255) 1×1 RGBA PNG byte string for doc tests (73 bytes, red pixel R=255 G=0 B=0 A=255)

    DOC_TEST_PNM_1X1

    let DOC_TEST_PNM_1X1 : Bytes

    文档测试用 1×1 RGB PNM (P6) 字节串(14 字节,红色像素 R=255 G=0 B=0) 1×1 RGB PNM (P6) byte string for doc tests (14 bytes, red pixel R=255 G=0 B=0)

    DOC_TEST_QOI_1X1

    let DOC_TEST_QOI_1X1 : Bytes

    文档测试用 1×1 RGBA QOI 字节串(26 字节,红色像素 R=255 G=0 B=0 A=255) 1×1 RGBA QOI byte string for doc tests (26 bytes, red pixel R=255 G=0 B=0 A=255)

    MAX_IMAGE_DIMENSION

    let MAX_IMAGE_DIMENSION : Int

    图像维度上限(单边最大像素数) Maximum image dimension limit (max pixels per side)

    防止恶意图像声明超大尺寸导致 OOM 或整数溢出。 Prevents malicious images from declaring oversized dimensions causing OOM or integer overflow. 65535 覆盖常见图像格式最大尺寸(PNG/TIFF 32-bit、JPEG 65500、BMP 32-bit)。 65535 covers max sizes of common formats (PNG/TIFF 32-bit, JPEG 65500, BMP 32-bit).

    MAX_TOTAL_PIXELS

    let MAX_TOTAL_PIXELS : Int

    (confirmed value 5e8; peak memory: RGB ≈ 1.5 GB, ImageF HDR ≈ 12 GB).

    any_image_to_u8

    fn any_image_to_u8(img : AnyImage) -> Image

    将 AnyImage 转换为 8-bit Image

    U8 直接返回;U16 截断高位;F32 量化到 [0,255]

    check_dims

    fn check_dims(width : Int, height : Int, channels : Int) -> Unit raise LoadError

    参数 Parameters:
    • width - 图像宽度 Image width
    • height - 图像高度 Image height
    • channels - 通道数 Number of channels

    错误 Errors:
    • LoadError::DecodeFailed - 维度无效、超过上限或溢出 Invalid dimensions, exceeds limit, or overflow

    示例 Example:
    test "doc_check_dims_valid" {
    @types.check_dims(1, 1, 3)
    assert_true(true)
    }

    test "doc_check_dims_total_pixels_ok" {
    @types.check_dims(25000, 20000, 3) // 5e8 边界内(总像素上限 5 亿)
    assert_true(true)
    }

    test "doc_check_dims_total_pixels_exceeded" {
    try {
    @types.check_dims(25001, 20000, 3) // 500,020,000 > 5e8
    assert_true(false)
    } catch {
    @types.LoadError::DecodeFailed(_) => assert_true(true)
    _ => assert_true(false)
    }
    }

    clamp_byte

    fn clamp_byte(Int) -> Byte

    字节钳制:将 Int32 值限制在 [0, 255] 并转为 Byte。 Byte clamp: constrains Int32 value to [0, 255] and converts to Byte.

    等价于 clamp_pixel_value(v).to_byte(),用于像素赋值。 Equivalent to clamp_pixel_value(v).to_byte(), used for pixel assignment. 实际实现在 core/safe_math 包中。 Actual implementation is in the core/safe_math package.

    参数 Parameters:
    • v - 输入值 Input value

    返回 Return:
    • 钳制后的字节 Clamped byte

    clamp_coord

    fn clamp_coord(Int, Int) -> Int

    坐标钳制:将坐标 v 限制在 [0, max_val-1] 范围内。 Coordinate clamp: constrains coordinate v to [0, max_val-1] range.

    用于图像像素坐标的边界检查。 Used for boundary checking of image pixel coordinates. 实际实现在 core/safe_math 包中。 Actual implementation is in the core/safe_math package.

    参数 Parameters:
    • v - 坐标值 Coordinate value
    • max_val - 最大值(上限为 max_val-1)Maximum value (upper bound is max_val-1)

    返回 Return:
    • 钳制后的坐标 Clamped coordinate

    clamp_double

    fn clamp_double(Double, Double, Double) -> Double

    双精度浮点钳制:将 Double 值 v 限制在 [lo, hi] 范围内。 Double clamp: constrains Double value v to [lo, hi] range.

    用于高精度图像处理(HDR/频域)的范围约束。 Used for range constraints in high-precision image processing (HDR/frequency domain). 实际实现在 core/safe_math 包中。 Actual implementation is in the core/safe_math package.

    参数 Parameters:
    • v - 输入值 Input value
    • lo - 下界 Lower bound
    • hi - 上界 Upper bound

    返回 Return:
    • 钳制后的值 Clamped value

    clamp_float

    fn clamp_float(Float, Float, Float) -> Float

    浮点钳制:将 Float 值 v 限制在 [lo, hi] 范围内。 Float clamp: constrains Float value v to [lo, hi] range.

    用于 16-bit/float 图像处理的范围约束。 Used for range constraints in 16-bit/float image processing. 实际实现在 core/safe_math 包中。 Actual implementation is in the core/safe_math package.

    参数 Parameters:
    • v - 输入值 Input value
    • lo - 下界 Lower bound
    • hi - 上界 Upper bound

    返回 Return:
    • 钳制后的值 Clamped value

    clamp_int

    fn clamp_int(Int, Int, Int) -> Int

    通用整数钳制:将 v 限制在 [lo, hi] 范围内。 General integer clamp: constrains v to [lo, hi] range.

    实际实现在 core/safe_math 包中。 Actual implementation is in the core/safe_math package.

    参数 Parameters:
    • v - 输入值 Input value
    • lo - 下界 Lower bound
    • hi - 上界 Upper bound

    返回 Return:
    • 钳制后的值 Clamped value

    clamp_pixel_value

    fn clamp_pixel_value(Int) -> Int

    像素值钳制:将 value 限制在 [0, 255] 范围内。 Pixel value clamp: constrains value to [0, 255] range.

    实际实现和形式化证明在 core/safe_math 包中。 Actual implementation and formal proof are in the core/safe_math package.

    参数 Parameters:
    • value - 输入像素值 Input pixel value

    返回 Return:
    • 钳制后的像素值(0-255)Clamped pixel value (0-255)

    dims_valid_check

    fn dims_valid_check(Int, Int, Int) -> Bool

    参数 Parameters:
    • w - 宽度 Width
    • h - 高度 Height
    • c - 通道数 Channels

    返回 Return:
    • 维度是否合法 Whether dimensions are valid

    hdr_from_u8

    fn hdr_from_u8(img : Image) -> ImageF

    将 8-bit Image 转换为 ImageF(归一化到 [0,1])

    image16_to_any

    fn image16_to_any(img : Image16) -> AnyImage

    将 Image16 升级为 AnyImage::U16

    image_error_from_load

    fn image_error_from_load(e : LoadError) -> ImageError

    把旧 LoadError 投影成 ImageError(按消息特征归类到稳定码)。 Project legacy LoadError into ImageError, classifying by message traits.

    image_error_hint

    fn image_error_hint(code : String) -> String

    建议动作:给下游/agent 的处置建议(稳定文本,便于直接回给调用方)。 Suggested action for callers/agents; stable text suitable to return as-is.

    image_to_any

    fn image_to_any(img : Image) -> AnyImage

    将 Image 升级为 AnyImage::U8

    imagef_to_any

    fn imagef_to_any(img : ImageF) -> AnyImage

    将 ImageF 升级为 AnyImage::F32

    int_max

    fn int_max(Int, Int) -> Int

    整数最大值:返回 a 和 b 中较大的那个。 Integer maximum: returns the larger of a and b.

    实际实现在 core/safe_math 包中。 Actual implementation is in the core/safe_math package.

    参数 Parameters:
    • a - 第一个值 First value
    • b - 第二个值 Second value

    返回 Return:
    • 较大值 The larger value

    int_min

    fn int_min(Int, Int) -> Int

    整数最小值:返回 a 和 b 中较小的那个。 Integer minimum: returns the smaller of a and b.

    实际实现在 core/safe_math 包中。 Actual implementation is in the core/safe_math package.

    参数 Parameters:
    • a - 第一个值 First value
    • b - 第二个值 Second value

    返回 Return:
    • 较小值 The smaller value

    safe_mul

    fn safe_mul(Int, Int) -> Int?

    安全乘法:返回 a * b,溢出时返回 None。 Safe multiplication: returns a * b, or None on overflow.

    用于在分配大数组前检查是否会溢出。 Used to check for overflow before allocating large arrays. 实际实现和形式化证明在 core/safe_math 包中。 Actual implementation and formal proof are in the core/safe_math package.

    参数 Parameters:
    • a - 乘数 Multiplicand
    • b - 乘数 Multiplier

    返回 Return:
    • Some(result) - 乘积 The product
    • None - 溢出 Overflow occurred

    safe_mul3

    fn safe_mul3(Int, Int, Int) -> Int?

    安全三参数乘法:返回 a * b * c,溢出时返回 None。 Safe three-argument multiplication: returns a * b * c, or None on overflow.

    常用于计算 w * h * channels 的数组大小。 Commonly used to compute array size as w * h * channels. 实际实现和形式化证明在 core/safe_math 包中。 Actual implementation and formal proof are in the core/safe_math package.

    参数 Parameters:
    • a - 第一乘数 First multiplicand
    • b - 第二乘数 Second multiplicand
    • c - 第三乘数 Third multiplicand

    返回 Return:
    • Some(result) - 乘积 The product
    • None - 溢出 Overflow occurred