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)]
9extern crate alloc;
10
11#[doc(hidden)]
12#[macro_export]
13macro_rules! __j2k_fnv1a64_init {
14    () => {
15        0xcbf2_9ce4_8422_2325_u64
16    };
17}
18
19#[doc(hidden)]
20#[macro_export]
21macro_rules! __j2k_fnv1a64_update {
22    ($hash:ident, $byte:expr) => {{
23        $hash ^= u64::from($byte);
24        $hash = $hash.wrapping_mul(0x0000_0100_0000_01B3_u64);
25    }};
26}
27
28#[doc(hidden)]
29#[macro_export]
30macro_rules! __j2k_fnv1a64_bytes {
31    ($bytes:expr) => {{
32        let mut hash = $crate::__j2k_fnv1a64_init!();
33        for &byte in $bytes {
34            $crate::__j2k_fnv1a64_update!(hash, byte);
35        }
36        hash
37    }};
38}
39
40/// Shared accelerator runtime contracts.
41pub mod accelerator;
42/// Backend selection and capability discovery.
43mod backend;
44/// Shared helpers for ordered tile-batch work.
45mod batch;
46mod buffer;
47/// Reusable codec context wrappers.
48mod context;
49/// Shared device-output request policies.
50mod device;
51/// Common error classifications and helper error types.
52mod error;
53mod host_allocation;
54mod passthrough;
55/// Pixel layout and format descriptors.
56mod pixel;
57mod rejection;
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};
73#[doc(hidden)]
74pub use batch::plan_ht_gpu_job_chunks;
75pub use batch::{
76    checked_batch_count_product, checked_batch_count_sum, tile_batch_worker_count,
77    try_batch_reserve_for_push, try_batch_reserve_to, try_collect_indexed_batch_results,
78    try_collect_ordered_batch_results_with_limits, BatchAllocationBudget, BatchAllocationRequest,
79    BatchDecodeError, BatchInfrastructureError, BatchResultSlot, HtGpuJobChunk, HtGpuJobChunkEntry,
80    HtGpuJobChunkLimit, HtGpuJobChunkLimits, HtGpuJobChunkPlan, HtGpuJobChunkPlanError,
81    HtGpuJobChunkRequest, HtGpuJobPassBucket, IndexedBatchResult, TileBatchError, TileBatchOptions,
82    TileDecodeJob, TileRegionDecodeJob, TileRegionScaledDecodeJob,
83    TileRegionScaledDeviceDecodeRequest, TileScaledDecodeJob,
84};
85pub use buffer::{
86    checked_surface_len, copy_tight_pixels_to_strided_output, ensure_allocation_within_cap,
87    strided_output_len, strided_output_len_capped, validate_strided_output_buffer,
88    DEFAULT_MAX_HOST_ALLOCATION_BYTES,
89};
90pub use context::{CacheStats, CodecContext};
91pub use device::validate_cuda_surface_backend_request;
92pub use error::{
93    adapter_error_is_buffer_error, adapter_error_is_not_implemented, adapter_error_is_truncated,
94    adapter_error_is_unsupported, AdapterErrorKind, AdapterErrorParts, BufferError, CodecError,
95    InputError, NotImplemented, Unsupported,
96};
97#[doc(hidden)]
98pub use host_allocation::{
99    checked_host_phase_product, checked_host_phase_sum, host_capacity_bytes, try_host_vec_filled,
100    try_host_vec_from_slice, try_host_vec_resize, try_host_vec_with_capacity, HostAllocationBudget,
101    HostAllocationError, HostAllocationLimitError, HostPhaseBudget, HostPhaseError,
102};
103pub use passthrough::{
104    CompressedPayloadKind, CompressedTransferSyntax, PassthroughCandidate, PassthroughDecision,
105    PassthroughRejectReason, PassthroughRequirements,
106};
107pub use pixel::{PixelFormat, PixelLayout};
108pub use rejection::{CapabilityRejection, CapabilityRejectionKind};
109pub use row_sink::RowSink;
110pub use sample::{Sample, SampleType};
111pub use scale::Downscale;
112pub use scratch::ScratchPool;
113pub use traits::{
114    submit_ready_device, CpuBackedImageDecode, DecodeRowsError, DeviceCodestream, DeviceSubmission,
115    DeviceSubmitSession, DeviceSurface, ImageCodec, ImageDecode, ImageDecodeDevice,
116    ImageDecodeRows, ImageDecodeSubmit, ReadySubmission, TileBatchDecode, TileBatchDecodeDevice,
117    TileBatchDecodeManyDevice, TileBatchDecodeSubmit, TileDecompress,
118};
119pub use types::{CodedUnitLayout, Colorspace, DecodeOutcome, Info, Rect, TileLayout};