Skip to main content

j2k_core/
lib.rs

1//! Shared traits and value types for the `j2k` workspace.
2//!
3//! Codec crates use this crate to expose common pixel formats, decode
4//! outcomes, row sinks, caller-owned scratch pools, and CPU/GPU backend
5//! selection contracts without depending on each other.
6
7#![no_std]
8#![warn(unreachable_pub)]
9
10extern crate alloc;
11
12#[doc(hidden)]
13#[macro_export]
14macro_rules! __j2k_fnv1a64_init {
15    () => {
16        0xcbf2_9ce4_8422_2325_u64
17    };
18}
19
20#[doc(hidden)]
21#[macro_export]
22macro_rules! __j2k_fnv1a64_update {
23    ($hash:ident, $byte:expr) => {{
24        $hash ^= u64::from($byte);
25        $hash = $hash.wrapping_mul(0x0000_0100_0000_01B3_u64);
26    }};
27}
28
29#[doc(hidden)]
30#[macro_export]
31macro_rules! __j2k_fnv1a64_bytes {
32    ($bytes:expr) => {{
33        let mut hash = $crate::__j2k_fnv1a64_init!();
34        for &byte in $bytes {
35            $crate::__j2k_fnv1a64_update!(hash, byte);
36        }
37        hash
38    }};
39}
40
41/// Shared accelerator runtime contracts.
42pub mod accelerator;
43/// Backend selection and capability discovery.
44mod backend;
45/// Shared helpers for ordered tile-batch work.
46mod batch;
47mod buffer;
48/// Reusable codec context wrappers.
49mod context;
50/// Shared device-output request policies.
51mod device;
52/// Common error classifications and helper error types.
53mod error;
54mod host_allocation;
55mod passthrough;
56/// Pixel layout and format descriptors.
57mod pixel;
58mod row_sink;
59/// Integer sample type descriptors.
60mod sample;
61/// Decode downscale options.
62mod scale;
63mod scratch;
64/// Facade traits implemented by codec crates.
65mod traits;
66/// Shared metadata and geometry types.
67mod types;
68
69pub use accelerator::{
70    AcceleratorSession, DeviceMemoryRange, ExecutionStats, SurfaceMetadata, SurfaceResidency,
71};
72pub use backend::{BackendCapabilities, BackendKind, BackendRequest, CpuFeatures};
73pub use batch::{
74    checked_batch_count_product, checked_batch_count_sum, tile_batch_worker_count,
75    try_batch_reserve_for_push, try_batch_reserve_to, try_collect_indexed_batch_results,
76    try_collect_ordered_batch_results, try_collect_ordered_batch_results_with_limits,
77    BatchAllocationBudget, BatchAllocationRequest, BatchDecodeError, BatchInfrastructureError,
78    BatchResultSlot, IndexedBatchResult, TileBatchError, TileBatchOptions, TileDecodeJob,
79    TileRegionDecodeJob, TileRegionScaledDecodeJob, TileRegionScaledDeviceDecodeRequest,
80    TileScaledDecodeJob,
81};
82pub use buffer::{
83    checked_surface_len, copy_tight_pixels_to_strided_output, ensure_allocation_within_cap,
84    strided_output_len, strided_output_len_capped, validate_strided_output_buffer,
85    DEFAULT_MAX_HOST_ALLOCATION_BYTES,
86};
87pub use context::{CacheStats, CodecContext, DecoderContext};
88pub use device::validate_cuda_surface_backend_request;
89pub use error::{
90    adapter_error_is_buffer_error, adapter_error_is_not_implemented, adapter_error_is_truncated,
91    adapter_error_is_unsupported, AdapterErrorKind, AdapterErrorParts, BufferError, CodecError,
92    InputError, NotImplemented, Unsupported,
93};
94#[doc(hidden)]
95pub use host_allocation::{
96    host_capacity_bytes, try_host_vec_filled, try_host_vec_from_slice, try_host_vec_resize,
97    try_host_vec_with_capacity, HostAllocationBudget, HostAllocationError,
98    HostAllocationLimitError,
99};
100pub use passthrough::{
101    CompressedPayloadKind, CompressedTransferSyntax, PassthroughCandidate, PassthroughDecision,
102    PassthroughRejectReason, PassthroughRequirements,
103};
104pub use pixel::{PixelFormat, PixelLayout};
105pub use row_sink::RowSink;
106pub use sample::{Sample, SampleType};
107pub use scale::Downscale;
108pub use scratch::ScratchPool;
109pub use traits::{
110    submit_ready_device, CpuBackedImageDecode, DecodeRowsError, DeviceSubmission,
111    DeviceSubmitSession, DeviceSurface, ImageCodec, ImageDecode, ImageDecodeDevice,
112    ImageDecodeRows, ImageDecodeSubmit, ReadySubmission, TileBatchDecode, TileBatchDecodeDevice,
113    TileBatchDecodeManyDevice, TileBatchDecodeSubmit, TileDecompress,
114};
115pub use types::{CodedUnitLayout, Colorspace, DecodeOutcome, Info, Rect, TileLayout};