use crate::extensions::graphic_control_extension::GraphicControlExtension;
use crate::table_based_image::TableBasedImage;
use crate::color_table::ColorTable;
pub struct Frame {
pub delay_time: u16,
pub bytes: Vec<u8>,
}
impl Frame {
pub fn new(
screen_width: u16,
screen_height: u16,
color_table: &ColorTable,
ctrl: Option<GraphicControlExtension>,
img: &TableBasedImage,
) -> Self {
let (delay_time, transparent_index) = if let Some(control) = ctrl {
let tc_index = if control.transparent_color_flag() == 1 {
Some(control.transparent_color_index)
} else {
None
};
(control.delay_time, tc_index)
} else {
(0, None)
};
let bytes = img.convert_to_frame(
screen_width,
screen_height,
color_table,
transparent_index,
);
Self {
delay_time,
bytes,
}
}
}
impl Default for Frame {
fn default() -> Frame {
Frame {
delay_time: 0,
bytes: Vec::new(),
}
}
}