j2k-metal 0.10.0

Metal decoder and encode-stage adapter for j2k
Documentation
// SPDX-License-Identifier: MIT OR Apache-2.0
// @generated by `cargo xtask promotion-codegen`; do not edit by hand.

#[cfg(any(test, target_os = "macos"))]
use j2k_core::{CompressedPayloadKind as Payload, CompressedTransferSyntax as Syntax, PixelFormat};

#[cfg(any(test, target_os = "macos"))]
use crate::routing::promotion::{PromotionCell, PromotionOperation as Operation};

const METAL_PART1: &str = "162a47f7a96b2be88abebc100aab672513af04895532863fa1a293660546f879";
const METAL_PART15: &str = "cfa66686d053bb3e2d4c8756abaf84aab65d8505a635795cefd38de53573c1f5";
const METAL_HOST_OUTPUT: &str = "c98f11c0b2a2a96853953ceee7ea672e0e5044bdb8abbd397c8c36eb82fe53b8";

pub(crate) const SOURCE_EVIDENCE: &[&str] = &[METAL_PART1, METAL_PART15, METAL_HOST_OUTPUT];

#[cfg(any(test, target_os = "macos"))]
const fn decode_cell(
    format: PixelFormat,
    transfer_syntax: Syntax,
    payload_kind: Payload,
    operation: Operation,
    boundary: (u32, u32, u64, usize),
    source_evidence: &'static str,
) -> PromotionCell {
    PromotionCell {
        format,
        transfer_syntax,
        payload_kind,
        operation,
        minimum_width: boundary.0,
        minimum_height: boundary.1,
        minimum_pixels: boundary.2,
        minimum_count: boundary.3,
        source_evidence,
    }
}

#[cfg(any(test, target_os = "macos"))]
pub(crate) const PROMOTION_CELLS: &[PromotionCell] = &[
    decode_cell(
        PixelFormat::Gray8,
        Syntax::Jpeg2000Lossy,
        Payload::Jpeg2000Codestream,
        Operation::Repeated,
        (0, 0, 2_960_793, 16),
        METAL_PART1,
    ),
    decode_cell(
        PixelFormat::Rgb8,
        Syntax::Jpeg2000Lossy,
        Payload::Jpeg2000Codestream,
        Operation::Repeated,
        (0, 0, 307_200, 16),
        METAL_PART1,
    ),
    decode_cell(
        PixelFormat::Rgb8,
        Syntax::Jpeg2000Lossless,
        Payload::Jpeg2000Codestream,
        Operation::Repeated,
        (0, 0, 5_038_848, 16),
        METAL_PART1,
    ),
    decode_cell(
        PixelFormat::Rgb8,
        Syntax::HtJpeg2000Lossy,
        Payload::Jpeg2000Codestream,
        Operation::Repeated,
        (640, 480, 0, 16),
        METAL_PART15,
    ),
    decode_cell(
        PixelFormat::Rgb8,
        Syntax::HtJpeg2000Lossless,
        Payload::JphFile,
        Operation::Repeated,
        (768, 512, 0, 16),
        METAL_PART15,
    ),
    decode_cell(
        PixelFormat::Rgb8,
        Syntax::HtJpeg2000Lossy,
        Payload::Jpeg2000Codestream,
        Operation::ScaledHalf,
        (320, 240, 0, 1),
        METAL_PART15,
    ),
];

#[cfg(target_os = "macos")]
const HOST_OUTPUT_CELLS: &[(u16, u32, u32, &str)] = &[
    (3, 1024, 1024, METAL_HOST_OUTPUT),
    (1, 2048, 2048, METAL_HOST_OUTPUT),
    (3, 2048, 2048, METAL_HOST_OUTPUT),
];

#[cfg(target_os = "macos")]
pub(crate) fn auto_host_output_encode_qualifies(components: u16, width: u32, height: u32) -> bool {
    HOST_OUTPUT_CELLS.iter().any(|cell| {
        cell.0 == components
            && cell.1 == width
            && cell.2 == height
            && SOURCE_EVIDENCE.contains(&cell.3)
    })
}

pub(crate) fn auto_lossy_rgb8_encode_qualifies(pixels: usize) -> bool {
    pixels >= 5_038_848 && SOURCE_EVIDENCE.contains(&METAL_PART1)
}