public static RawTextureInfo Read(byte[] data) { using (var ms = new MemoryStream(data)) { using (var br = new BinaryReader(ms)) { CRNHeaderStruct header = CRNHeaderStruct.Read(br); uint sig = header.m_sig.Value; if (sig != CRNHeaderStruct.CRN_SIG_VALUE) { return(null); } var info = new RawTextureInfo(); info.Width = (int)header.m_width.Value; info.Height = (int)header.m_height.Value; info.HasMips = header.m_levels.Value > 1; uint format = header.m_format.Value; if (format == cCRNFmtDXT1) { info.Format = TextureFormat.DXT1Crunched; } else if (format == cCRNFmtDXT5) { info.Format = TextureFormat.DXT5Crunched; } else { Debug.LogError("Unknown crn format = " + header.m_format.Value); } info.RawData = data; return(info); } } }
public static CRNHeaderStruct Read(BinaryReader br) { CRNHeaderStruct header = new CRNHeaderStruct(); header.m_sig = new crn_packed_uint2(br); header.m_header_size = new crn_packed_uint2(br); header.m_header_crc16 = new crn_packed_uint2(br); header.m_data_size = new crn_packed_uint4(br); header.m_data_crc16 = new crn_packed_uint2(br); header.m_width = new crn_packed_uint2(br); header.m_height = new crn_packed_uint2(br); header.m_levels = new crn_packed_uint1(br); header.m_faces = new crn_packed_uint1(br); header.m_format = new crn_packed_uint1(br); header.m_flags = new crn_packed_uint2(br); header.m_reserved = new crn_packed_uint4(br); header.m_userdata0 = new crn_packed_uint4(br); header.m_userdata1 = new crn_packed_uint4(br); header.m_color_endpoints = new crn_palette(br); header.m_color_selectors = new crn_palette(br); header.m_alpha_endpoints = new crn_palette(br); header.m_alpha_selectors = new crn_palette(br); header.m_tables_size = new crn_packed_uint2(br); header.m_tables_ofs = new crn_packed_uint3(br); header.m_level_ofs = new crn_packed_uint4(br); return(header); }