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};
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    host_capacity_bytes, try_host_vec_filled, try_host_vec_from_slice, try_host_vec_resize,
100    try_host_vec_with_capacity, HostAllocationBudget, HostAllocationError,
101    HostAllocationLimitError,
102};
103pub use passthrough::{
104    CompressedPayloadKind, CompressedTransferSyntax, PassthroughCandidate, PassthroughDecision,
105    PassthroughRejectReason, PassthroughRequirements,
106};
107pub use pixel::{PixelFormat, PixelLayout};
108pub use row_sink::RowSink;
109pub use sample::{Sample, SampleType};
110pub use scale::Downscale;
111pub use scratch::ScratchPool;
112pub use traits::{
113    submit_ready_device, CpuBackedImageDecode, DecodeRowsError, DeviceSubmission,
114    DeviceSubmitSession, DeviceSurface, ImageCodec, ImageDecode, ImageDecodeDevice,
115    ImageDecodeRows, ImageDecodeSubmit, ReadySubmission, TileBatchDecode, TileBatchDecodeDevice,
116    TileBatchDecodeManyDevice, TileBatchDecodeSubmit, TileDecompress,
117};
118pub use types::{CodedUnitLayout, Colorspace, DecodeOutcome, Info, Rect, TileLayout};