use super::*;
impl TryFrom<ColorTable> for SPFColorTable {
type Error = ConversionError;
fn try_from(table: ColorTable) -> Result<Self, Self::Error> {
let (colors_ptr, colors_len) = vec_to_raw_with_conversion!(table.colors, SPFColor);
Ok(SPFColorTable {
modifier_flags: table.modifier_flags.bits(),
configuration_flags: table.configuration_flags.bits(),
has_constant_alpha: table.constant_alpha.is_some() as c_uchar,
constant_alpha: table.constant_alpha.unwrap_or(0) as c_uchar,
colors: colors_ptr,
colors_length: colors_len as c_ulong,
})
}
}
impl TryInto<ColorTable> for &SPFColorTable {
type Error = ConversionError;
fn try_into(self) -> Result<ColorTable, Self::Error> {
unsafe {
let colors = vec_from_raw_with_conversion!(self.colors, self.colors_length);
let constant_alpha = ffi_to_option!(self.has_constant_alpha, self.constant_alpha);
Ok(ColorTable {
modifier_flags: ColorTableModifierFlags::from_bits_retain(self.modifier_flags),
configuration_flags: ColorTableConfigurationFlags::from_bits_retain(self.configuration_flags),
constant_alpha,
colors,
})
}
}
}