diff --git a/src/header.rs b/src/header.rs index b51a7fa00a..29e9600e06 100644 --- a/src/header.rs +++ b/src/header.rs @@ -856,8 +856,8 @@ impl UncompressedHeader for BitWriter { // when we add support for it. let width = fi.width - 1; let height = fi.height - 1; - let width_bits = 32 - (width as u32).leading_zeros(); - let height_bits = 32 - (height as u32).leading_zeros(); + let width_bits = log_in_base_2(fi.width as u32) as u32 + 1; + let height_bits = log_in_base_2(fi.height as u32) as u32 + 1; assert!(width_bits <= 16); assert!(height_bits <= 16); self.write(4, width_bits - 1)?; @@ -875,8 +875,8 @@ impl UncompressedHeader for BitWriter { if fi.frame_size_override_flag { let width = fi.width - 1; let height = fi.height - 1; - let width_bits = 32 - (width as u32).leading_zeros(); - let height_bits = 32 - (height as u32).leading_zeros(); + let width_bits = log_in_base_2(fi.width as u32) as u32 + 1; + let height_bits = log_in_base_2(fi.height as u32) as u32 + 1; assert!(width_bits <= 16); assert!(height_bits <= 16); self.write(width_bits, width as u16)?; diff --git a/src/test_encode_decode/mod.rs b/src/test_encode_decode/mod.rs index 3d8b848c34..928017e15a 100644 --- a/src/test_encode_decode/mod.rs +++ b/src/test_encode_decode/mod.rs @@ -286,6 +286,10 @@ mod small_dimension { mod tiny_dimension { test_dimensions! { + (1, 1), + (2, 2), + (4, 4), + (8, 8), (16, 16), (32, 32), (64, 64), @@ -297,6 +301,7 @@ fn dimension(w: usize, h: usize, decoder: &str) { let quantizer = 100; let limit = 1; let speed = 10; + let still_picture = w < 16 || h < 16; let mut dec = get_decoder::(decoder, w as usize, h as usize); dec.encode_decode( @@ -315,7 +320,7 @@ fn dimension(w: usize, h: usize, decoder: &str) { 0, 0, 0, - false, + still_picture, ); }