| 1 |
//! Development-time-only helper module for exporting private APIs so that they can be benchmarked. |
| 2 |
//! This module is gated behind the "benchmarks" feature. |
| 3 |
|
| 4 |
use crate::adam7::{expand_pass, Adam7Iterator}; |
| 5 |
use crate::common::BytesPerPixel; |
| 6 |
use crate::filter::{Filter, RowFilter}; |
| 7 |
use crate::{BitDepth, ColorType, Info}; |
| 8 |
|
| 9 |
/// Re-exporting `unfilter` to make it easier to benchmark, despite some items being only |
| 10 |
/// `pub(crate)`: `fn unfilter`, `enum BytesPerPixel`. |
| 11 |
pub fn unfilter(filter: Filter, tbpp: u8, previous: &[u8], current: &mut [u8]) { |
| 12 |
let filter = RowFilter::from_method(filter).unwrap(); // RowFilter type is private |
| 13 |
let tbpp = BytesPerPixel::from_usize(tbpp as usize); |
| 14 |
crate::filter::unfilter(filter, tbpp, previous, current) |
| 15 |
} |
| 16 |
|
| 17 |
pub fn adam7(img: &mut [u8], buffer: &[u8], width: u32, height: u32, bpp: u8) { |
| 18 |
fn bytes_of_width(width: u32, bpp: u8) -> usize { |
| 19 |
let total = (u64::from(width) * u64::from(bpp)).div_ceil(8); |
| 20 |
usize::try_from(total).unwrap() |
| 21 |
} |
| 22 |
|
| 23 |
let img_row_stride = bytes_of_width(width, bpp); |
| 24 |
for adam7 in Adam7Iterator::new(width as u32, height as u32).into_iter() { |
| 25 |
// We use the same buffer for all interlace passes, to avoid counting the creation time in |
| 26 |
// the benchmark here. But the expansion expects us to pass a slice so make sure we use the |
| 27 |
// correct one. As of writing the implementation is not sensitive to this but it may become |
| 28 |
// so. |
| 29 |
let used_bytes = bytes_of_width(adam7.width, bpp); |
| 30 |
expand_pass(img, img_row_stride, &buffer[..used_bytes], &adam7, bpp); |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
pub use crate::decoder::transform::{create_transform_fn, TransformFn}; |
| 35 |
|
| 36 |
pub fn create_info_from_plte_trns_bitdepth<'a>( |
| 37 |
plte: &'a [u8], |
| 38 |
trns: Option<&'a [u8]>, |
| 39 |
bit_depth: u8, |
| 40 |
) -> Info<'a> { |
| 41 |
Info { |
| 42 |
color_type: ColorType::Indexed, |
| 43 |
bit_depth: BitDepth::from_u8(bit_depth).unwrap(), |
| 44 |
palette: Some(plte.into()), |
| 45 |
trns: trns.map(Into::into), |
| 46 |
..Info::default() |
| 47 |
} |
| 48 |
} |