add temporary (and wasteful) methods to load gif/iff/pcx to RgbaBitmaps

temporary measure until i feel like making the existing loading process
for all of these able to handle variable pixel bit-depth destinations.
not super high on my priority list so this may not happen for a while.
This commit is contained in:
Gered 2023-03-13 13:03:55 -04:00
parent bc59442311
commit 6de4bf3ef0
3 changed files with 60 additions and 0 deletions

View file

@ -6,6 +6,7 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use thiserror::Error; use thiserror::Error;
use crate::graphics::bitmap::indexed::IndexedBitmap; use crate::graphics::bitmap::indexed::IndexedBitmap;
use crate::graphics::bitmap::rgb::RgbaBitmap;
use crate::graphics::palette::{Palette, PaletteError, PaletteFormat}; use crate::graphics::palette::{Palette, PaletteError, PaletteFormat};
use crate::utils::lzwgif::{lzw_decode, lzw_encode, LzwError}; use crate::utils::lzwgif::{lzw_decode, lzw_encode, LzwError};
@ -551,6 +552,25 @@ impl IndexedBitmap {
} }
} }
// wasteful temporary measures until i feel like re-working the above loading process with some kind of
// multi-pixel-depth support.
impl RgbaBitmap {
pub fn load_gif_bytes<T: ReadBytesExt>(
reader: &mut T,
) -> Result<(RgbaBitmap, Palette), GifError> {
let (temp_bitmap, palette) = IndexedBitmap::load_gif_bytes(reader)?;
let output = temp_bitmap.to_rgba(&palette);
Ok((output, palette))
}
pub fn load_gif_file(path: &Path) -> Result<(RgbaBitmap, Palette), GifError> {
let (temp_bitmap, palette) = IndexedBitmap::load_gif_file(path)?;
let output = temp_bitmap.to_rgba(&palette);
Ok((output, palette))
}
}
#[cfg(test)] #[cfg(test)]
pub mod tests { pub mod tests {
use tempfile::TempDir; use tempfile::TempDir;

View file

@ -7,6 +7,7 @@ use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use thiserror::Error; use thiserror::Error;
use crate::graphics::bitmap::indexed::IndexedBitmap; use crate::graphics::bitmap::indexed::IndexedBitmap;
use crate::graphics::bitmap::rgb::RgbaBitmap;
use crate::graphics::palette::{Palette, PaletteError, PaletteFormat}; use crate::graphics::palette::{Palette, PaletteError, PaletteFormat};
use crate::utils::packbits::{pack_bits, PackBitsError, unpack_bits}; use crate::utils::packbits::{pack_bits, PackBitsError, unpack_bits};
@ -559,6 +560,25 @@ impl IndexedBitmap {
} }
} }
// wasteful temporary measures until i feel like re-working the above loading process with some kind of
// multi-pixel-depth support.
impl RgbaBitmap {
pub fn load_iff_bytes<T: ReadBytesExt + Seek>(
reader: &mut T,
) -> Result<(RgbaBitmap, Palette), IffError> {
let (temp_bitmap, palette) = IndexedBitmap::load_iff_bytes(reader)?;
let output = temp_bitmap.to_rgba(&palette);
Ok((output, palette))
}
pub fn load_iff_file(path: &Path) -> Result<(RgbaBitmap, Palette), IffError> {
let (temp_bitmap, palette) = IndexedBitmap::load_iff_file(path)?;
let output = temp_bitmap.to_rgba(&palette);
Ok((output, palette))
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use tempfile::TempDir; use tempfile::TempDir;

View file

@ -6,6 +6,7 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use thiserror::Error; use thiserror::Error;
use crate::graphics::bitmap::indexed::IndexedBitmap; use crate::graphics::bitmap::indexed::IndexedBitmap;
use crate::graphics::bitmap::rgb::RgbaBitmap;
use crate::graphics::color::from_rgb32; use crate::graphics::color::from_rgb32;
use crate::graphics::palette::{Palette, PaletteError, PaletteFormat}; use crate::graphics::palette::{Palette, PaletteError, PaletteFormat};
use crate::utils::bytes::ReadFixedLengthByteArray; use crate::utils::bytes::ReadFixedLengthByteArray;
@ -280,6 +281,25 @@ impl IndexedBitmap {
} }
} }
// wasteful temporary measures until i feel like re-working the above loading process with some kind of
// multi-pixel-depth support.
impl RgbaBitmap {
pub fn load_pcx_bytes<T: ReadBytesExt + Seek>(
reader: &mut T,
) -> Result<(RgbaBitmap, Palette), PcxError> {
let (temp_bitmap, palette) = IndexedBitmap::load_pcx_bytes(reader)?;
let output = temp_bitmap.to_rgba(&palette);
Ok((output, palette))
}
pub fn load_pcx_file(path: &Path) -> Result<(RgbaBitmap, Palette), PcxError> {
let (temp_bitmap, palette) = IndexedBitmap::load_pcx_file(path)?;
let output = temp_bitmap.to_rgba(&palette);
Ok((output, palette))
}
}
#[cfg(test)] #[cfg(test)]
pub mod tests { pub mod tests {
use tempfile::TempDir; use tempfile::TempDir;