From 22f23ef7889eec27a5bed3eaa49f52c9416ea01e Mon Sep 17 00:00:00 2001 From: Jonathan Behrens Date: Thu, 1 Aug 2024 20:38:06 -0700 Subject: [PATCH] Special case RLE codes (#87) --- src/lossless.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/lossless.rs b/src/lossless.rs index 4ba4aa6..36b5357 100644 --- a/src/lossless.rs +++ b/src/lossless.rs @@ -548,8 +548,15 @@ impl LosslessDecoder { return Err(DecodingError::BitStreamError); } - for i in 0..length * 4 { - data[index * 4 + i] = data[index * 4 + i - dist * 4]; + if dist == 1 { + let value: [u8; 4] = data[(index - dist) * 4..][..4].try_into().unwrap(); + for i in 0..length { + data[index * 4 + i * 4..][..4].copy_from_slice(&value); + } + } else { + for i in 0..length * 4 { + data[index * 4 + i] = data[index * 4 + i - dist * 4]; + } } index += length; } else {