From bc5944231193c5ef95d3d38d8f779c4de0b4bb59 Mon Sep 17 00:00:00 2001 From: gered Date: Mon, 13 Mar 2023 13:02:21 -0400 Subject: [PATCH] add method to convert an IndexedBitmap to an RgbaBitmap doing the reverse is a fair bit more complicated, so we'll leave that alone for now! --- ggdt/src/graphics/bitmap/indexed/mod.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ggdt/src/graphics/bitmap/indexed/mod.rs b/ggdt/src/graphics/bitmap/indexed/mod.rs index 0d12b44..7dd60fc 100644 --- a/ggdt/src/graphics/bitmap/indexed/mod.rs +++ b/ggdt/src/graphics/bitmap/indexed/mod.rs @@ -1,6 +1,7 @@ use std::path::Path; use crate::graphics::bitmap::{Bitmap, BitmapError}; +use crate::graphics::bitmap::rgb::RgbaBitmap; use crate::graphics::palette::Palette; pub mod blit; @@ -54,4 +55,18 @@ impl IndexedBitmap { *dest = palette[*src]; } } + + /// Makes a [`RgbaBitmap`] copy of this bitmap, using the specified 256 colour palette during + /// the pixel format conversion. + /// + /// # Arguments + /// + /// * `palette`: the 256 colour palette to use during pixel conversion + /// + /// returns: `RgbaBitmap` + pub fn to_rgba(&self, palette: &Palette) -> RgbaBitmap { + let mut output = RgbaBitmap::new(self.width, self.height).unwrap(); + self.copy_as_argb_to(output.pixels_mut(), palette); + output + } } \ No newline at end of file