Function png::expand_interlaced_row

source ยท
pub fn expand_interlaced_row(
    img: &mut [u8],
    img_row_stride: usize,
    interlaced_row: &[u8],
    interlace_info: &Adam7Info,
    bits_per_pixel: u8,
)
Expand description

Copies pixels from interlaced_row into the right location in img.

First bytes of img should belong to the top-left corner of the currently decoded frame.

img_row_stride specifies an offset in bytes between subsequent rows of img. This can be the width of the current frame being decoded, but this is not required - a bigger stride may be useful if the frame being decoded is a sub-region of img.

interlaced_row and interlace_info typically come from crate::decoder::Reader::next_interlaced_row, but this is not required. In particular, before calling expand_interlaced_row one may need to expand the decoded row, so that its format and bits_per_pixel matches that of img. Note that in initial Adam7 passes the interlaced_row may contain less pixels that the width of the frame being decoded (e.g. it contains only 1/8th of pixels in the initial pass).

Example:

use png::{expand_interlaced_row, Adam7Info};
let info = Adam7Info::new(5, 0, 4);  // 1st line of 5th pass has 4 pixels.
let mut img = vec![0; 8 * 8];
let row = vec![1, 2, 3, 4];
expand_interlaced_row(&mut img, 8, &row, &info, 8);
assert_eq!(&img, &[
    0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0,
    1, 0, 2, 0, 3, 0, 4, 0,  // <= this is where the 1st line of 5s appears
    0, 0, 0, 0, 0, 0, 0, 0,  //    in the schematic drawing of the passes at
    0, 0, 0, 0, 0, 0, 0, 0,  //    https://en.wikipedia.org/wiki/Adam7_algorithm
    0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0,
]);