Example #1
0
 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);
         }
     }
 }
Example #2
0
        public static RawTextureInfo Read(byte[] data)
        {
            using (var ms = new MemoryStream(data))
            {
                using (var br = new BinaryReader(ms))
                {
                    DDSHeaderStruct header = new DDSHeaderStruct();
                    if (ReadHeader(br, ref header))
                    {
                        RawTextureInfo info = new RawTextureInfo();
                        info.Width   = (int)header.width;
                        info.Height  = (int)header.height;
                        info.HasMips = header.mipmapcount > 1;
                        switch (header.pixelformat.fourcc)
                        {
                        case FOURCC_NO_COMPRESSION:
                            if (header.pixelformat.rgbbitcount == 8)
                            {
                                info.Format = TextureFormat.Alpha8;
                            }
                            else if (header.pixelformat.rgbbitcount == 32)
                            {
                                info.Format = TextureFormat.RGBA32;
                            }
                            else
                            {
                                Debug.LogError("Invalid texture format fourcc = " + header.pixelformat.fourcc + " rgbbitcount = " + header.pixelformat.rgbbitcount);
                            }
                            break;

                        case FOURCC_DXT1:
                            info.Format = TextureFormat.DXT1;
                            break;

                        case FOURCC_DXT5:
                            info.Format = TextureFormat.DXT5;
                            break;

                        default:
                            Debug.LogError("Unrecognized texture format fourcc = " + header.pixelformat.fourcc);
                            break;
                        }
                        info.RawData = new byte[ms.Length - ms.Position];
                        ms.Read(info.RawData, 0, info.RawData.Length);
                        return(info);
                    }
                }
            }
            return(null);
        }