use unityrs_core::files::SerializedFile;
use unityrs_texture::Format;
use super::Texture;
use crate::ngui::classify::{self, Class};
pub(in crate::ngui) fn data_format(
t: &Texture,
file: &SerializedFile,
format: Format,
data: &[u8],
) -> Result<Format, Class> {
if t.width == 0 || t.height == 0 {
return Ok(format);
}
if data.is_empty() {
return Err(classify::decode(&unityrs_texture::DecodeError::NoImageData));
}
if !format.is_crunched() {
return Ok(format);
}
let version = file
.version()
.map(|v| {
v.version
.as_tuple()
.map(|(major, minor, ..)| (major, minor))
.map_err(|e| classify::error(&unityrs_core::Error::Version(e)))
})
.transpose()?
.unwrap_or((u16::MAX, u16::MAX));
super::formats(
t,
file.target_platform()
.unwrap_or(crate::ngui::attempt::UNKNOWN_PLATFORM),
unityrs_texture::Formats::DECODED,
version,
)
}