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 row_sink;
58/// Integer sample type descriptors.
59mod sample;
60/// Decode downscale options.
61mod scale;
62mod scratch;
63/// Facade traits implemented by codec crates.
64mod traits;
65/// Shared metadata and geometry types.
66mod types;
67
68pub use accelerator::{
69    AcceleratorSession, DeviceMemoryRange, ExecutionStats, SurfaceMetadata, SurfaceResidency,
70};
71pub use backend::{BackendCapabilities, BackendKind, BackendRequest, CpuFeatures};
72#[doc(hidden)]
73pub use batch::plan_ht_gpu_job_chunks;
74pub use batch::{
75    checked_batch_count_product, checked_batch_count_sum, tile_batch_worker_count,
76    try_batch_reserve_for_push, try_batch_reserve_to, try_collect_indexed_batch_results,
77    try_collect_ordered_batch_results_with_limits, BatchAllocationBudget, BatchAllocationRequest,
78    BatchDecodeError, BatchInfrastructureError, BatchResultSlot, HtGpuJobChunk, HtGpuJobChunkEntry,
79    HtGpuJobChunkLimit, HtGpuJobChunkLimits, HtGpuJobChunkPlan, HtGpuJobChunkPlanError,
80    HtGpuJobChunkRequest, HtGpuJobPassBucket, IndexedBatchResult, TileBatchError, TileBatchOptions,
81    TileDecodeJob, TileRegionDecodeJob, TileRegionScaledDecodeJob,
82    TileRegionScaledDeviceDecodeRequest, TileScaledDecodeJob,
83};
84pub use buffer::{
85    checked_surface_len, copy_tight_pixels_to_strided_output, ensure_allocation_within_cap,
86    strided_output_len, strided_output_len_capped, validate_strided_output_buffer,
87    DEFAULT_MAX_HOST_ALLOCATION_BYTES,
88};
89pub use context::{CacheStats, CodecContext};
90pub use device::validate_cuda_surface_backend_request;
91pub use error::{
92    adapter_error_is_buffer_error, adapter_error_is_not_implemented, adapter_error_is_truncated,
93    adapter_error_is_unsupported, AdapterErrorKind, AdapterErrorParts, BufferError, CodecError,
94    InputError, NotImplemented, Unsupported,
95};
96#[doc(hidden)]
97pub use host_allocation::{
98    host_capacity_bytes, try_host_vec_filled, try_host_vec_from_slice, try_host_vec_resize,
99    try_host_vec_with_capacity, HostAllocationBudget, HostAllocationError,
100    HostAllocationLimitError,
101};
102pub use passthrough::{
103    CompressedPayloadKind, CompressedTransferSyntax, PassthroughCandidate, PassthroughDecision,
104    PassthroughRejectReason, PassthroughRequirements,
105};
106pub use pixel::{PixelFormat, PixelLayout};
107pub use row_sink::RowSink;
108pub use sample::{Sample, SampleType};
109pub use scale::Downscale;
110pub use scratch::ScratchPool;
111pub use traits::{
112    submit_ready_device, CpuBackedImageDecode, DecodeRowsError, DeviceSubmission,
113    DeviceSubmitSession, DeviceSurface, ImageCodec, ImageDecode, ImageDecodeDevice,
114    ImageDecodeRows, ImageDecodeSubmit, ReadySubmission, TileBatchDecode, TileBatchDecodeDevice,
115    TileBatchDecodeManyDevice, TileBatchDecodeSubmit, TileDecompress,
116};
117pub use types::{CodedUnitLayout, Colorspace, DecodeOutcome, Info, Rect, TileLayout};