Esempio n. 1
0
        public static DirectBitmap ETCTextureToBitmap(Texture2D texture, byte[] data)
        {
            int          width  = texture.Width;
            int          height = texture.Height;
            DirectBitmap bitmap = new DirectBitmap(width, height);

            try
            {
                switch (texture.TextureFormat)
                {
                case TextureFormat.ETC_RGB4:
                case TextureFormat.ETC_RGB4_3DS:
                case TextureFormat.ETC_RGB4Crunched:
                    EtcDecoder.DecompressETC(data, width, height, bitmap.Bits);
                    break;

                case TextureFormat.EAC_R:
                    EtcDecoder.DecompressEACRUnsigned(data, width, height, bitmap.Bits);
                    break;

                case TextureFormat.EAC_R_SIGNED:
                    EtcDecoder.DecompressEACRSigned(data, width, height, bitmap.Bits);
                    break;

                case TextureFormat.EAC_RG:
                    EtcDecoder.DecompressEACRGUnsigned(data, width, height, bitmap.Bits);
                    break;

                case TextureFormat.EAC_RG_SIGNED:
                    EtcDecoder.DecompressEACRGSigned(data, width, height, bitmap.Bits);
                    break;

                case TextureFormat.ETC2_RGB:
                    EtcDecoder.DecompressETC2(data, width, height, bitmap.Bits);
                    break;

                case TextureFormat.ETC2_RGBA1:
                    EtcDecoder.DecompressETC2A1(data, width, height, bitmap.Bits);
                    break;

                case TextureFormat.ETC2_RGBA8:
                case TextureFormat.ETC_RGBA8_3DS:
                case TextureFormat.ETC2_RGBA8Crunched:
                    EtcDecoder.DecompressETC2A8(data, width, height, bitmap.Bits);
                    break;

                default:
                    throw new Exception(texture.TextureFormat.ToString());
                }
                bitmap.FlipY();
                return(bitmap);
            }
            catch
            {
                bitmap.Dispose();
                throw;
            }
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            if (args.Length < 4)
            {
                Console.WriteLine("Format: {fileName} {width} {height} {mode}");
                Console.WriteLine("mode: 0 - ETC; 1 - ETC2; 2 - ETC2a1; 3 - ETC2a8; 4 - EAC R; 5 - EAC signed R; 6 - EAC RG; 7 - EAC signed RG;");
                Console.ReadKey();
                return;
            }

            string path   = args[0];
            int    width  = int.Parse(args[1]);
            int    height = int.Parse(args[2]);
            int    mode   = int.Parse(args[3]);

            using (DirectBitmap bitmap = new DirectBitmap(width, height))
            {
                ConsoleKeyInfo key;
                byte[]         data      = File.ReadAllBytes(path);
                EtcDecoder     decoder   = new EtcDecoder();
                Stopwatch      stopwatch = new Stopwatch();
                do
                {
                    stopwatch.Start();
                    switch (mode)
                    {
                    case 0:
                        decoder.DecompressETC(data, width, height, bitmap.Bits);
                        break;

                    case 1:
                        decoder.DecompressETC2(data, width, height, bitmap.Bits);
                        break;

                    case 2:
                        decoder.DecompressETC2A1(data, width, height, bitmap.Bits);
                        break;

                    case 3:
                        decoder.DecompressETC2A8(data, width, height, bitmap.Bits);
                        break;

                    case 4:
                        decoder.DecompressEACRUnsigned(data, width, height, bitmap.Bits);
                        break;

                    case 5:
                        decoder.DecompressEACRSigned(data, width, height, bitmap.Bits);
                        break;

                    case 6:
                        decoder.DecompressEACRGUnsigned(data, width, height, bitmap.Bits);
                        break;

                    case 7:
                        decoder.DecompressEACRGSigned(data, width, height, bitmap.Bits);
                        break;

                    default:
                        throw new Exception(mode.ToString());
                    }
                    stopwatch.Stop();

                    Console.WriteLine("Processed " + stopwatch.ElapsedMilliseconds);
                    stopwatch.Reset();
                    key = Console.ReadKey();
                }while (key.Key == ConsoleKey.Spacebar);

                string dirPath  = Path.GetDirectoryName(path);
                string fileName = Path.GetFileNameWithoutExtension(path);
                string outPath  = Path.Combine(dirPath, fileName + ".png");
                bitmap.Bitmap.Save(outPath, ImageFormat.Png);
            }

            Console.WriteLine("Finished!");
        }