Skip to content

Commit 15d0bef

Browse files
committed
feat: use solid fills with rle compressed images
1 parent d61a220 commit 15d0bef

2 files changed

Lines changed: 290 additions & 153 deletions

File tree

src/lib.rs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ where
266266
D: DrawTarget<Color = C>,
267267
{
268268
let area = self.bounding_box();
269-
let slice_size = Size::new(area.size.width, 1);
270269

271270
match self.raw_bmp.color_type {
272271
ColorType::Index1 => {
@@ -300,13 +299,25 @@ where
300299
.map(Into::into)
301300
.unwrap_or(fallback_color)
302301
};
302+
303303
// RLE produces pixels in bottom-up order, so we draw them line by line rather than the entire bitmap at once.
304304
for y in (0..area.size.height).rev() {
305305
colors.start_row();
306306

307-
let row = Rectangle::new(Point::new(0, y as i32), slice_size);
308-
let colors = colors.by_ref().map(map_color);
309-
target.fill_contiguous(&row, colors.take(area.size.width as usize))?;
307+
let mut point = Point::new(0, y as i32);
308+
loop {
309+
if point.x >= area.size.width as i32 {
310+
break;
311+
}
312+
let Some((raw_color, count)) = colors.next_solid_chunk() else {
313+
break;
314+
};
315+
316+
let size = Size::new(count as u32, 1);
317+
let color = map_color(raw_color);
318+
target.fill_solid(&Rectangle::new(point, size), color)?;
319+
point.x += count as i32;
320+
}
310321
}
311322
Ok(())
312323
} else {
@@ -335,13 +346,25 @@ where
335346
.map(Into::into)
336347
.unwrap_or(fallback_color)
337348
};
349+
338350
// RLE produces pixels in bottom-up order, so we draw them line by line rather than the entire bitmap at once.
339351
for y in (0..area.size.height).rev() {
340352
colors.start_row();
341353

342-
let row = Rectangle::new(Point::new(0, y as i32), slice_size);
343-
let colors = colors.by_ref().map(map_color);
344-
target.fill_contiguous(&row, colors.take(area.size.width as usize))?;
354+
let mut point = Point::new(0, y as i32);
355+
loop {
356+
if point.x >= area.size.width as i32 {
357+
break;
358+
}
359+
let Some((raw_color, count)) = colors.next_solid_chunk() else {
360+
break;
361+
};
362+
363+
let size = Size::new(count as u32, 1);
364+
let color = map_color(raw_color);
365+
target.fill_solid(&Rectangle::new(point, size), color)?;
366+
point.x += count as i32;
367+
}
345368
}
346369
Ok(())
347370
} else {

0 commit comments

Comments
 (0)