use super::*; use crate::ser::*; impl Serialize for Tex2d { fn serialize(&self, s: SE) -> Result { ASSERT!(self.param.l == 1, "MIPS NOT IMPL"); Image::::from(self).serialize(s) } } impl<'de, S: TexSize, F: TexFmt> Deserialize<'de> for Tex2d { fn deserialize>(d: D) -> Result { Ok(Image::::deserialize(d)?.into()) } } impl Serialize for Image { fn serialize(&self, s: SE) -> Result { self.to_bytes().serialize(s) } } impl<'de, S: TexSize, F: TexFmt> Deserialize<'de> for Image { fn deserialize>(d: D) -> Result { Ok(Self::from_bytes(<&[u8]>::deserialize(d)?)) } } impl Image { pub fn to_bytes(&self) -> Box<[u8]> { let Self { w, h, data, .. } = self; let w: [_; 4] = w.to_le_bytes(); let h: [_; 4] = h.to_le_bytes(); let (_, d, _) = unsafe { data.align_to() }; [&w, &h, d].concat().into() } pub fn from_bytes(v: &[u8]) -> Self { let w = u32::from_le_bytes(v[0..4].try_into().valid()); let h = u32::from_le_bytes(v[4..8].try_into().valid()); let data = unsafe { v[8..].align_to() }.1.into(); Self { w, h, data, s: Dummy } } }