pub struct Channel {
pub hshift: u32,
pub vshift: u32,
pub component: i32,
/* private fields */
}Expand description
A single channel in a modular image.
Channels store i32 values, which can represent:
- Raw pixel values (0-255 for 8-bit, 0-65535 for 16-bit)
- Prediction residuals (can be negative)
- Transformed values (after RCT, Squeeze, etc.)
Fields§
§hshift: u32Horizontal subsampling shift (0 = no subsampling).
vshift: u32Vertical subsampling shift (0 = no subsampling).
component: i32Original color component index (-1 = unset). Used to look up per-component quantization tables in lossy modular encoding. Set by LfFrame: Y=0, X=1, B-Y=2. Propagated through Squeeze transforms.
Implementations§
Source§impl Channel
impl Channel
Sourcepub fn new(width: usize, height: usize) -> Result<Self>
pub fn new(width: usize, height: usize) -> Result<Self>
Creates a new channel filled with zeros.
Sourcepub fn from_vec(data: Vec<i32>, width: usize, height: usize) -> Result<Self>
pub fn from_vec(data: Vec<i32>, width: usize, height: usize) -> Result<Self>
Creates a channel from existing data.
Sourcepub fn get_clamped(&self, x: isize, y: isize) -> i32
pub fn get_clamped(&self, x: isize, y: isize) -> i32
Gets a pixel with boundary handling (returns 0 outside bounds).
Sourcepub fn extract_shifted_region(
&self,
rect_x0: usize,
rect_y0: usize,
rect_xsize: usize,
rect_ysize: usize,
) -> Option<Channel>
pub fn extract_shifted_region( &self, rect_x0: usize, rect_y0: usize, rect_xsize: usize, rect_ysize: usize, ) -> Option<Channel>
Extracts a region from this channel, accounting for hshift/vshift.
The rect is specified in full-resolution image coordinates. It is
downshifted by hshift/vshift and clamped to channel bounds.
Returns None if the shifted region has zero area.
Sourcepub fn extract_grid_cell(
&self,
gx: usize,
gy: usize,
group_dim: usize,
) -> Option<Channel>
pub fn extract_grid_cell( &self, gx: usize, gy: usize, group_dim: usize, ) -> Option<Channel>
Extracts a grid cell region matching the decoder’s get_grid_rect logic.
Given a group position (gx, gy) and group_dim (the image-level group size, typically 256), computes the channel-space sub-region for this group.
This matches jxl-rs ModularChannel::get_grid_rect:
grid_dim = (group_dim >> hshift, group_dim >> vshift)
bx = gx * grid_dim.0, by = gy * grid_dim.1
size = (min(chan_w - bx, grid_dim.0), min(chan_h - by, grid_dim.1))
Returns None if the sub-region has zero area.
Sourcepub fn get_clamped_to_edge(&self, x: isize, y: isize) -> i32
pub fn get_clamped_to_edge(&self, x: isize, y: isize) -> i32
Gets a pixel, clamping coordinates to valid range.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Channel
impl RefUnwindSafe for Channel
impl Send for Channel
impl Sync for Channel
impl Unpin for Channel
impl UnsafeUnpin for Channel
impl UnwindSafe for Channel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more