Skip to main content

TileGrid

Struct TileGrid 

Source
#[non_exhaustive]
pub struct TileGrid { pub columns: u32, pub rows: u32, pub tile_width: u32, pub tile_height: u32, pub x_offset: u32, pub y_offset: u32, /* private fields */ }
Expand description

How an image is cut into tiles: the grid that the SIZ marker declares on the reference grid, the coordinate space of the whole codestream.

Every tile is tile_width by tile_height, and the grid starts at (x_offset, y_offset). Tiles at the edges are cut to the image area, so they can be smaller. They are numbered in raster order from 0, as Region::Tile numbers them: tile n is in column n % columns and row n / columns. An image of one tile has a grid of 1 by 1.

The grid follows ISO/IEC 15444-1 B.3: columns is ceil((Xsiz - XTOsiz) / XTsiz) (Eq. B-5), rows the same down, and tile gives each tile’s rectangle (Eq. B-7). On ordinary files the values match what opj_dump prints as tw, th, tdx, tdy, tx0 and ty0.

use rust_j2k::{DecodeOptions, Region, decode_with, read_header};

let bytes = std::fs::read("image.j2k")?;
let tiles = read_header(&bytes)?.tiles;
for index in 0..tiles.count() {
    let area = tiles.tile(index).expect("the index is below the count");
    let options = DecodeOptions::default().with_region(Region::Tile(index));
    let tile = decode_with(&bytes, &options)?;
    assert_eq!((tile.width, tile.height), (area.x1 - area.x0, area.y1 - area.y0));
    println!("tile {index} at ({}, {}): {}x{}", area.x0, area.y0, tile.width, tile.height);
}

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§columns: u32

Tiles across.

§rows: u32

Tiles down.

§tile_width: u32

The width of a tile before the cut to the image area (XTsiz).

§tile_height: u32

The height of a tile before the cut to the image area (YTsiz).

§x_offset: u32

The left edge of the first column of tiles on the reference grid (XTOsiz). It is at or left of the image area’s left edge.

§y_offset: u32

The top edge of the first row of tiles on the reference grid (YTOsiz). It is at or above the image area’s top edge.

Implementations§

Source§

impl TileGrid

Source

pub const fn count(&self) -> u32

How many tiles the image has: columns * rows, at most 65535.

Source

pub fn tile(&self, index: u32) -> Option<Window>

Tile index’s rectangle on the reference grid, cut to the image area: the area Region::Tile(index) decodes. None when index is at or past count.

Column p = index % columns and row q = index / columns span max(x_offset + p * tile_width, x0)..min(x_offset + (p + 1) * tile_width, x1) across, for the image area x0..x1, and the same down (ISO/IEC 15444-1 Eq. B-7).

Trait Implementations§

Source§

impl Clone for TileGrid

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for TileGrid

Source§

impl Debug for TileGrid

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for TileGrid

Source§

impl Hash for TileGrid

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for TileGrid

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for TileGrid

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.