diff --git a/src/encoder.rs b/src/encoder.rs index 778fe69..e908ea4 100644 --- a/src/encoder.rs +++ b/src/encoder.rs @@ -378,7 +378,7 @@ impl Encoder { 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 { @@ -692,8 +692,8 @@ impl Encoder { 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; @@ -966,8 +966,8 @@ impl Encoder { 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); @@ -991,8 +991,8 @@ impl Encoder { } } - 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); @@ -1003,8 +1003,8 @@ impl Encoder { 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); @@ -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;