set alpha component consistently with other colours during palette read

when reading palette files/streams, we set up the colour entries
using helper functions that automatically set an alpha component of 255.
however, we were first initializing the palette with 0 (alpha component
of 0 too).

this meant that if a palette of less than 256 colours was loaded, the
remaining entries (since Palette is always sized for 256 colours), were
black (0,0,0) with alpha components of 0.

this change makes all palette entries have a consistent alpha value
(which is never really used anyway ...) when loaded.
This commit is contained in:
Gered 2023-03-20 22:18:02 -04:00
parent 148a24ca42
commit a5c8af67ad

View file

@ -8,7 +8,7 @@ use byteorder::{ReadBytesExt, WriteBytesExt};
use thiserror::Error;
use crate::graphics::bitmap::indexed::IndexedBitmap;
use crate::graphics::color::{from_rgb32, lerp_rgb32, to_rgb32};
use crate::graphics::color::{from_rgb32, lerp_rgb32, to_argb32, to_rgb32};
use crate::NUM_COLORS;
use crate::utils::abs_diff;
@ -26,7 +26,7 @@ fn read_palette_6bit<T: ReadBytesExt>(
if num_colors > NUM_COLORS {
return Err(PaletteError::OutOfRange(num_colors));
}
let mut colors = [0u32; NUM_COLORS];
let mut colors = [to_argb32(255, 0, 0, 0); NUM_COLORS];
for i in 0..num_colors {
let r = reader.read_u8()?;
let g = reader.read_u8()?;
@ -62,7 +62,7 @@ fn read_palette_8bit<T: ReadBytesExt>(
if num_colors > NUM_COLORS {
return Err(PaletteError::OutOfRange(num_colors));
}
let mut colors = [0u32; NUM_COLORS];
let mut colors = [to_argb32(255, 0, 0, 0); NUM_COLORS];
for i in 0..num_colors {
let r = reader.read_u8()?;
let g = reader.read_u8()?;