#[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
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.columns: u32Tiles across.
rows: u32Tiles down.
tile_width: u32The width of a tile before the cut to the image area (XTsiz).
tile_height: u32The height of a tile before the cut to the image area (YTsiz).
x_offset: u32The 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: u32The 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
impl TileGrid
Sourcepub fn tile(&self, index: u32) -> Option<Window>
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).