Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ impl<W: JfifWrite> Encoder<W> {
const MARKER: &[u8; 12] = b"ICC_PROFILE\0";
const MAX_CHUNK_LENGTH: usize = 65535 - 2 - 12 - 2;

let num_chunks = ceil_div(data.len(), MAX_CHUNK_LENGTH);
let num_chunks = data.len().div_ceil(MAX_CHUNK_LENGTH);

// Sequence number is stored as a byte and starts with 1
if num_chunks >= 255 {
Expand Down Expand Up @@ -692,8 +692,8 @@ impl<W: JfifWrite> Encoder<W> {
let width = image.width();
let height = image.height();

let num_cols = ceil_div(usize::from(width), 8 * max_h_sampling);
let num_rows = ceil_div(usize::from(height), 8 * max_v_sampling);
let num_cols = usize::from(width).div_ceil(8 * max_h_sampling);
let num_rows = usize::from(height).div_ceil(8 * max_v_sampling);

let buffer_width = num_cols * 8 * max_h_sampling;
let buffer_size = buffer_width * 8 * max_v_sampling;
Expand Down Expand Up @@ -966,8 +966,8 @@ impl<W: JfifWrite> Encoder<W> {

let (max_h_sampling, max_v_sampling) = self.get_max_sampling_size();

let num_cols = ceil_div(usize::from(width), 8 * max_h_sampling) * max_h_sampling;
let num_rows = ceil_div(usize::from(height), 8 * max_v_sampling) * max_v_sampling;
let num_cols = usize::from(width).div_ceil(8 * max_h_sampling) * max_h_sampling;
let num_rows = usize::from(height).div_ceil(8 * max_v_sampling) * max_v_sampling;

debug_assert!(num_cols > 0);
debug_assert!(num_rows > 0);
Expand All @@ -991,8 +991,8 @@ impl<W: JfifWrite> Encoder<W> {
}
}

let num_cols = ceil_div(usize::from(width), 8);
let num_rows = ceil_div(usize::from(height), 8);
let num_cols = usize::from(width).div_ceil(8);
let num_rows = usize::from(height).div_ceil(8);

debug_assert!(num_cols > 0);
debug_assert!(num_rows > 0);
Expand All @@ -1003,8 +1003,8 @@ impl<W: JfifWrite> Encoder<W> {
let h_scale = max_h_sampling / component.horizontal_sampling_factor as usize;
let v_scale = max_v_sampling / component.vertical_sampling_factor as usize;

let cols = ceil_div(num_cols, h_scale);
let rows = ceil_div(num_rows, v_scale);
let cols = num_cols.div_ceil(h_scale);
let rows = num_rows.div_ceil(v_scale);

debug_assert!(cols > 0);
debug_assert!(rows > 0);
Expand Down Expand Up @@ -1223,10 +1223,6 @@ fn get_block(
block
}

fn ceil_div(value: usize, div: usize) -> usize {
value / div + usize::from(value % div != 0)
}

fn get_num_bits(mut value: i16) -> u8 {
if value < 0 {
value = -value;
Expand Down
Loading