コード例 #1
0
        private static Texture CreateTextureFromFilePath(string filePath, TextureFormat formatHint, string texturesDirectoryPath, TextureSet textureSet)
        {
            string textureName = Path.GetFileNameWithoutExtension(filePath);

            var texture = textureSet.Textures.FirstOrDefault(x =>
                                                             x.Name.Equals(textureName, StringComparison.OrdinalIgnoreCase));

            if (texture != null)
            {
                return(texture);
            }

            string newFilePath = FindTexturePath(filePath, texturesDirectoryPath);

            if (string.IsNullOrEmpty(newFilePath))
            {
                return(null);
            }

            texture = TextureEncoder.EncodeFromFile(newFilePath, formatHint, true);

            texture.Name = textureName;
            texture.Id   = MurmurHash.Calculate(textureName);

            textureSet.Textures.Add(texture);

            return(texture);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var stgFarc = BinaryFile.Load <FarcArchive>(args[0]);

            foreach (string fileName in stgFarc)
            {
                if (fileName.EndsWith(".txd"))
                {
                    MemoryStream stream    = new MemoryStream();
                    var          oldTexSet = BinaryFile.Load <TextureSet>(stgFarc.Open(fileName, EntryStreamMode.MemoryStream));
                    var          newTexSet = new TextureSet();

                    foreach (var tex in oldTexSet.Textures)
                    {
                        Texture newTex = TextureEncoder.EncodeFromFile(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\white.dds", tex.Format, true);
                        newTex.Id   = tex.Id;
                        newTex.Name = tex.Name;
                        newTexSet.Textures.Add(newTex);
                    }
                    newTexSet.Endianness = oldTexSet.Endianness;
                    newTexSet.Format     = oldTexSet.Format;

                    newTexSet.Save(stream, true);
                    stgFarc.Add(fileName, stream, false, ConflictPolicy.Replace);
                }
            }
            stgFarc.Save(args[0]);
        }
コード例 #3
0
        protected override void InitializeCore()
        {
            RegisterExportHandler <TextureDictionary>(path => Data.Save(path));
            RegisterReplaceHandler <TextureDictionary>(Resource.Load <TextureDictionary>);

            RegisterAddHandler <Bitmap>(path => Data.Add(TextureEncoder.Encode(Path.GetFileNameWithoutExtension(path) + ".dds",
                                                                               TextureFormat.DDS, new Bitmap(path))));

            RegisterAddHandler <Stream>(path => Data.Add(new Texture(Path.GetFileNameWithoutExtension(path) + ".dds",
                                                                     TextureFormat.DDS, File.ReadAllBytes(path))));

            RegisterModelUpdateHandler(() =>
            {
                var textureDictionary = new TextureDictionary(Version);
                foreach (TextureViewNode textureAdapter in Nodes)
                {
                    textureDictionary[textureAdapter.Name] = textureAdapter.Data;
                }

                return(textureDictionary);
            });

            RegisterCustomHandler("Convert to field texture archive", () =>
            {
                using (var dialog = new SaveFileDialog())
                {
                    dialog.Filter             = "Field Texture Archive (*.bin)|*.bin";
                    dialog.AutoUpgradeEnabled = true;
                    dialog.CheckPathExists    = true;
                    dialog.FileName           = Text;
                    dialog.OverwritePrompt    = true;
                    dialog.Title         = "Select a file to export to.";
                    dialog.ValidateNames = true;
                    dialog.AddExtension  = true;

                    if (dialog.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    Replace(TextureDictionary.ConvertToFieldTextureArchive(Data, dialog.FileName));
                }
            });

            RegisterCustomHandler("Export All", () =>
            {
                using (var dialog = new VistaFolderBrowserDialog())
                {
                    if (dialog.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    foreach (TextureViewNode viewModel in Nodes)
                    {
                        File.WriteAllBytes(Path.Combine(dialog.SelectedPath, viewModel.Text), viewModel.Data.Data);
                    }
                }
            });
        }
コード例 #4
0
 /*Save to texture*/
 public static void EncodeSurfaceRegion(SurfaceBiomeDatabase.SurfaceBiome encode, Texture2D dataTexture, int index, out int nextIndex)
 {
     nextIndex = index;
     TextureEncoder.EncodeFloat(encode.Height, dataTexture, nextIndex, out nextIndex);
     TextureEncoder.EncodeFloat(encode.Floor, dataTexture, nextIndex, out nextIndex);
     TextureEncoder.EncodeFloat(encode.AdditiveHeightLimit, dataTexture, nextIndex, out nextIndex);
     GradientEncoder.EncodeGradient(encode.GroundPalette, dataTexture, nextIndex, out nextIndex);
     GradientEncoder.EncodeGradient(encode.WallPalette, dataTexture, nextIndex, out nextIndex);
 }
コード例 #5
0
        protected override void Initialize()
        {
            RegisterImportHandler <Texture>(filePath =>
            {
                var texture = TextureEncoder.Encode(filePath);
                {
                    texture.Id   = Data.Textures.Max(x => x.Id) + 1;
                    texture.Name = Path.GetFileNameWithoutExtension(filePath);
                }
                Data.Textures.Add(texture);
            });
            RegisterImportHandler <Bitmap>(filePath =>
            {
                var texture = TextureEncoder.Encode(filePath);
                {
                    texture.Id   = Data.Textures.Max(x => x.Id) + 1;
                    texture.Name = Path.GetFileNameWithoutExtension(filePath);
                }
                Data.Textures.Add(texture);
            });
            RegisterExportHandler <TextureSet>(filePath => Data.Save(filePath));
            RegisterReplaceHandler <TextureSet>(BinaryFile.Load <TextureSet>);
            RegisterCustomHandler("Export All", () =>
            {
                using (var folderBrowseDialog = new VistaFolderBrowserDialog())
                {
                    folderBrowseDialog.Description            = "Select a folder to save textures to.";
                    folderBrowseDialog.UseDescriptionForTitle = true;

                    if (folderBrowseDialog.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    foreach (var texture in Data.Textures)
                    {
                        if (!TextureFormatUtilities.IsCompressed(texture.Format) || texture.IsYCbCr)
                        {
                            TextureDecoder.DecodeToPNG(texture,
                                                       Path.Combine(folderBrowseDialog.SelectedPath, $"{texture.Name}.png"));
                        }
                        else
                        {
                            TextureDecoder.DecodeToDDS(texture,
                                                       Path.Combine(folderBrowseDialog.SelectedPath, $"{texture.Name}.dds"));
                        }
                    }
                }
            }, Keys.Control | Keys.Shift | Keys.E);

            base.Initialize();
        }
コード例 #6
0
ファイル: Texture.cs プロジェクト: q4a/SparkIV
        public void Encode(Image image)
        {
            for (int i = 0; i < Levels; i++)
            {
                TextureEncoder.Encode(this, image, i);
            }

            if (_thumbnailCache != null)
            {
                _thumbnailCache.Dispose();
                _thumbnailCache = null;
            }
        }
コード例 #7
0
 /*Save to texture*/
 public static void EncodeGradient(Gradient encode, Texture2D dataTexture, int index, out int nextIndex)
 {
     nextIndex = index;
     TextureEncoder.EncodeFloat(encode.colorKeys.Length, dataTexture, nextIndex, out nextIndex);
     TextureEncoder.EncodeVector4(0 < encode.colorKeys.Length ? new Vector4(encode.colorKeys[0].color.r, encode.colorKeys[0].color.g, encode.colorKeys[0].color.b, encode.colorKeys[0].time) : Vector4.zero, dataTexture, nextIndex, out nextIndex);
     TextureEncoder.EncodeVector4(1 < encode.colorKeys.Length ? new Vector4(encode.colorKeys[1].color.r, encode.colorKeys[1].color.g, encode.colorKeys[1].color.b, encode.colorKeys[1].time) : Vector4.zero, dataTexture, nextIndex, out nextIndex);
     TextureEncoder.EncodeVector4(2 < encode.colorKeys.Length ? new Vector4(encode.colorKeys[2].color.r, encode.colorKeys[2].color.g, encode.colorKeys[2].color.b, encode.colorKeys[2].time) : Vector4.zero, dataTexture, nextIndex, out nextIndex);
     TextureEncoder.EncodeVector4(3 < encode.colorKeys.Length ? new Vector4(encode.colorKeys[3].color.r, encode.colorKeys[3].color.g, encode.colorKeys[3].color.b, encode.colorKeys[3].time) : Vector4.zero, dataTexture, nextIndex, out nextIndex);
     TextureEncoder.EncodeVector4(4 < encode.colorKeys.Length ? new Vector4(encode.colorKeys[4].color.r, encode.colorKeys[4].color.g, encode.colorKeys[4].color.b, encode.colorKeys[4].time) : Vector4.zero, dataTexture, nextIndex, out nextIndex);
     TextureEncoder.EncodeVector4(5 < encode.colorKeys.Length ? new Vector4(encode.colorKeys[5].color.r, encode.colorKeys[5].color.g, encode.colorKeys[5].color.b, encode.colorKeys[5].time) : Vector4.zero, dataTexture, nextIndex, out nextIndex);
     TextureEncoder.EncodeVector4(6 < encode.colorKeys.Length ? new Vector4(encode.colorKeys[6].color.r, encode.colorKeys[6].color.g, encode.colorKeys[6].color.b, encode.colorKeys[6].time) : Vector4.zero, dataTexture, nextIndex, out nextIndex);
     TextureEncoder.EncodeVector4(7 < encode.colorKeys.Length ? new Vector4(encode.colorKeys[7].color.r, encode.colorKeys[7].color.g, encode.colorKeys[7].color.b, encode.colorKeys[7].time) : Vector4.zero, dataTexture, nextIndex, out nextIndex);
 }
コード例 #8
0
        protected override void InitializeCore()
        {
            RegisterExportHandler <TextureDictionary>(path => Data.Save(path));
            RegisterReplaceHandler <TextureDictionary>(Resource.Load <TextureDictionary>);

            RegisterAddHandler <Bitmap>(path => Data.Add(TextureEncoder.Encode(Path.GetFileNameWithoutExtension(path) + ".dds",
                                                                               TextureFormat.DDS, new Bitmap(path))));

            RegisterAddHandler <Stream>(path => Data.Add(new Texture(Path.GetFileNameWithoutExtension(path) + ".dds",
                                                                     TextureFormat.DDS, File.ReadAllBytes(path))));

            RegisterCustomHandler("Add", "New texture", () =>
            {
                Data.Add(Texture.CreateDefaultTexture("New texture.dds"));
                InitializeView(true);
            });

            RegisterModelUpdateHandler(() =>
            {
                var textureDictionary = new TextureDictionary(Version);
                foreach (TextureViewNode textureAdapter in Nodes)
                {
                    textureDictionary[textureAdapter.Name] = textureAdapter.Data;
                }

                return(textureDictionary);
            });

            RegisterCustomHandler("Convert to", "Field texture archive (PS3)", () => { ConvertToFieldTextureArchive(false); });
            RegisterCustomHandler("Convert to", "Field texture archive (PS4)", () => { ConvertToFieldTextureArchive(true); });

            RegisterCustomHandler("Export", "All", () =>
            {
                var dialog = new VistaFolderBrowserDialog();
                {
                    if (dialog.ShowDialog() != true)
                    {
                        return;
                    }

                    foreach (TextureViewNode viewModel in Nodes)
                    {
                        File.WriteAllBytes(Path.Combine(dialog.SelectedPath, viewModel.Text), viewModel.Data.Data);
                    }
                }
            });
        }
コード例 #9
0
        protected override void InitializeCore()
        {
            RegisterExportHandler <Bitmap>((path) => TextureDecoder.Decode(Data).Save(path));
            RegisterExportHandler <Texture>((path) => TextureDecoder.DecodeToDDS(Data, path));

            RegisterReplaceHandler <Bitmap>((path) =>
            {
                using (var bitmap = new Bitmap(path))
                {
                    if (Data.IsYCbCr)
                    {
                        var format = DDSCodec.HasTransparency(bitmap) ? TextureFormat.RGBA : TextureFormat.RGB;

                        return(TextureEncoder.Encode(bitmap, format, false));
                    }

                    return(TextureEncoder.Encode(bitmap, Data.Format, Data.MipMapCount != 0));
                }
            });
            RegisterReplaceHandler <Texture>(TextureEncoder.Encode);
        }
コード例 #10
0
        /*Save to texture*/
        public static void EncodeRegionMap(Region encode, Texture2D dataTexture, int index, out int nextIndex)
        {
            //Map out closest neighbors
            List <Site> neighborSites = encode.RegionSite.NeighborSites();

            if (neighborSites.Count > 8)
            {
                Debug.Log("Warning! Neighbor site count greater than 8! Count: " + neighborSites.Count + " @CreateRegionFragGPUs(List<Region> mapRegions)");
            }

            nextIndex = index;
            TextureEncoder.EncodeVector2(encode.RegionSite.Coord, dataTexture, nextIndex, out nextIndex);
            TextureEncoder.EncodeFloat(encode.SurfaceBiomeID, dataTexture, nextIndex, out nextIndex);
            TextureEncoder.EncodeFloat(encode.CaveBiomeID, dataTexture, nextIndex, out nextIndex);
            TextureEncoder.EncodeFloat(0 < neighborSites.Count ? neighborSites[0].SiteIndex : -1, dataTexture, nextIndex, out nextIndex);
            TextureEncoder.EncodeFloat(1 < neighborSites.Count ? neighborSites[1].SiteIndex : -1, dataTexture, nextIndex, out nextIndex);
            TextureEncoder.EncodeFloat(2 < neighborSites.Count ? neighborSites[2].SiteIndex : -1, dataTexture, nextIndex, out nextIndex);
            TextureEncoder.EncodeFloat(3 < neighborSites.Count ? neighborSites[3].SiteIndex : -1, dataTexture, nextIndex, out nextIndex);
            TextureEncoder.EncodeFloat(4 < neighborSites.Count ? neighborSites[4].SiteIndex : -1, dataTexture, nextIndex, out nextIndex);
            TextureEncoder.EncodeFloat(5 < neighborSites.Count ? neighborSites[5].SiteIndex : -1, dataTexture, nextIndex, out nextIndex);
            TextureEncoder.EncodeFloat(6 < neighborSites.Count ? neighborSites[6].SiteIndex : -1, dataTexture, nextIndex, out nextIndex);
            TextureEncoder.EncodeFloat(7 < neighborSites.Count ? neighborSites[7].SiteIndex : -1, dataTexture, nextIndex, out nextIndex);
        }
コード例 #11
0
        private static Texture ConvertTexture(string textureFilePath, TextureSet textureSet)
        {
            if (!File.Exists(textureFilePath))
            {
                return(null);
            }

            string textureName = Path.GetFileNameWithoutExtension(textureFilePath);

            Texture texture;

            if ((texture = textureSet.Textures.FirstOrDefault(x => x.Name.Equals(textureName, StringComparison.OrdinalIgnoreCase))) != null)
            {
                return(texture);
            }

            texture      = TextureEncoder.Encode(textureFilePath);
            texture.Name = textureName;
            texture.Id   = sRandom.Next(int.MinValue, int.MaxValue);
            textureSet.Textures.Add(texture);

            return(texture);
        }
コード例 #12
0
        private static TextureInfo ConvertTexture(Ai.TextureSlot aiTextureSlot, string baseDirectoryPath)
        {
            var relativeFilePath = aiTextureSlot.FilePath;
            var fullFilePath     = Path.GetFullPath(Path.Combine(baseDirectoryPath, relativeFilePath));
            var textureName      = AssimpConverterCommon.UnescapeName(Path.GetFileNameWithoutExtension(relativeFilePath) + ".dds");

            Texture texture;

            if (!File.Exists(fullFilePath))
            {
                texture = Texture.CreateDefaultTexture(textureName);
            }
            else if (relativeFilePath.EndsWith(".dds", StringComparison.InvariantCultureIgnoreCase))
            {
                texture = new Texture(textureName, TextureFormat.DDS, File.ReadAllBytes(fullFilePath));
            }
            else
            {
                var bitmap = new Bitmap(fullFilePath);
                texture = TextureEncoder.Encode(textureName, TextureFormat.DDS, bitmap);
            }

            return(TextureInfo.GetTextureInfo(texture));
        }
コード例 #13
0
 protected override Texture ImportCore(Stream source, string fileName)
 {
     return(TextureEncoder.Encode(source));
 }
コード例 #14
0
ファイル: Program.cs プロジェクト: samnyan/MikuMikuLibrary
        private static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine(Resources.HelpText);
                Console.ReadLine();
                return;
            }

            string sourceFileName      = null;
            string destinationFileName = null;

            foreach (string arg in args)
            {
                if (sourceFileName == null)
                {
                    sourceFileName = arg;
                }

                else if (destinationFileName == null)
                {
                    destinationFileName = arg;
                }
            }

            if (destinationFileName == null)
            {
                destinationFileName = sourceFileName;
            }

            if (File.GetAttributes(sourceFileName).HasFlag(FileAttributes.Directory))
            {
                destinationFileName = Path.ChangeExtension(destinationFileName, "bin");

                var textureSet = new TextureSet();
                var textures   = new SortedList <int, Texture>();
                foreach (string textureFileName in Directory.EnumerateFiles(sourceFileName))
                {
                    if (textureFileName.EndsWith(".dds", StringComparison.OrdinalIgnoreCase) ||
                        textureFileName.EndsWith(".png", StringComparison.OrdinalIgnoreCase))
                    {
                        string cleanFileName = Path.GetFileNameWithoutExtension(textureFileName);
                        if (int.TryParse(cleanFileName, out int index))
                        {
                            Texture texture;

                            if (textureFileName.EndsWith(".png", StringComparison.OrdinalIgnoreCase))
                            {
                                var bitmap = new Bitmap(textureFileName);
                                var format = TextureFormat.RGB;

                                if (DDSCodec.HasTransparency(bitmap))
                                {
                                    format = TextureFormat.RGBA;
                                }

                                texture = TextureEncoder.Encode(new Bitmap(textureFileName), format, false);
                            }

                            else
                            {
                                texture = TextureEncoder.Encode(textureFileName);
                            }

                            textures.Add(index, texture);
                        }

                        else
                        {
                            Console.WriteLine(
                                "WARNING: Skipped '{0}' because it didn't match the expected name format",
                                Path.GetFileName(textureFileName));
                        }
                    }
                }

                textureSet.Textures.Capacity = textures.Count;
                foreach (var texture in textures.Values)
                {
                    textureSet.Textures.Add(texture);
                }

                textureSet.Save(destinationFileName);
            }

            else if (sourceFileName.EndsWith(".bin", StringComparison.OrdinalIgnoreCase) ||
                     sourceFileName.EndsWith(".txd", StringComparison.OrdinalIgnoreCase))
            {
                destinationFileName = Path.ChangeExtension(destinationFileName, null);

                var textureSet = BinaryFile.Load <TextureSet>(sourceFileName);

                Directory.CreateDirectory(destinationFileName);
                for (int i = 0; i < textureSet.Textures.Count; i++)
                {
                    var    texture = textureSet.Textures[i];
                    string name    = string.IsNullOrEmpty(texture.Name) ? $"{i}" : texture.Name;

                    if (TextureFormatUtilities.IsCompressed(texture.Format))
                    {
                        TextureDecoder.DecodeToDDS(texture, Path.Combine(destinationFileName, $"{name}.dds"));
                    }

                    else
                    {
                        TextureDecoder.DecodeToPNG(texture, Path.Combine(destinationFileName, $"{name}.png"));
                    }
                }
            }
        }
コード例 #15
0
 public override Texture Import(string filePath)
 {
     return(TextureEncoder.EncodeFromFile(filePath, TextureFormat.Unknown, true));
 }
        protected override void Initialize()
        {
            AddImportHandler <Texture>(filePath =>
            {
                var texture = TextureEncoder.EncodeFromFile(filePath, TextureFormat.Unknown, Parent.FindParent <SpriteSetNode>() == null);
                {
                    texture.Name = Path.GetFileNameWithoutExtension(filePath);
                    texture.Id   = MurmurHash.Calculate(texture.Name);
                }

                Data.Textures.Add(texture);
            });
            AddExportHandler <TextureSet>(filePath => Data.Save(filePath));
            AddReplaceHandler <TextureSet>(BinaryFile.Load <TextureSet>);

            AddCustomHandler("Export All", () =>
            {
                string filePath = ModuleExportUtilities.SelectModuleExport <Texture>(
                    "Select a folder to export textures to.", "Enter into a directory and press Save");

                if (string.IsNullOrEmpty(filePath))
                {
                    return;
                }

                string directoryPath = Path.GetDirectoryName(filePath);
                string extension     = Path.GetExtension(filePath).Trim('.');

                foreach (var texture in Data.Textures)
                {
                    TextureDecoder.DecodeToFile(texture, Path.Combine(directoryPath, $"{texture.Name}.{extension}"));
                }
            }, Keys.Control | Keys.Shift | Keys.E);

            AddCustomHandler("Export All (Flipped)", () =>
            {
                string filePath = ModuleExportUtilities.SelectModuleExport <Bitmap>(
                    "Select a folder to export textures to.", "Enter into a directory and press Save");

                if (string.IsNullOrEmpty(filePath))
                {
                    return;
                }

                string directoryPath = Path.GetDirectoryName(filePath);
                string extension     = Path.GetExtension(filePath).Trim('.');

                foreach (var texture in Data.Textures)
                {
                    using (var bitmap = TextureDecoder.DecodeToBitmap(texture))
                    {
                        bitmap.RotateFlip(RotateFlipType.Rotate180FlipX);
                        bitmap.Save(Path.Combine(directoryPath, $"{texture.Name}.{extension}"));
                    }
                }
            });

            AddCustomHandlerSeparator();

            AddDirtyCustomHandler("Replace All", () =>
            {
                var fileNames = ModuleImportUtilities.SelectModuleImportMultiselect <Texture>();

                if (fileNames == null)
                {
                    return(false);
                }

                bool any = false;

                foreach (string fileName in fileNames)
                {
                    string textureName = Path.GetFileNameWithoutExtension(fileName);

                    int textureIndex = Data.Textures.FindIndex(x => x.Name.Equals(textureName, StringComparison.OrdinalIgnoreCase));

                    if (textureIndex == -1)
                    {
                        continue;
                    }

                    any = true;

                    var texture = Data.Textures[textureIndex];

                    var newTexture = TextureEncoder.EncodeFromFile(fileName,
                                                                   texture.IsYCbCr ? TextureFormat.RGBA8 : texture.Format, texture.MipMapCount != 1);

                    newTexture.Name = texture.Name;
                    newTexture.Id   = texture.Id;

                    Data.Textures[textureIndex] = newTexture;
                }

                return(any);
            }, Keys.Control | Keys.Shift | Keys.R, CustomHandlerFlags.Repopulate | CustomHandlerFlags.ClearMementos);

            AddDirtyCustomHandler("Replace All (Flipped)", () =>
            {
                var fileNames = ModuleImportUtilities.SelectModuleImportMultiselect <Bitmap>();

                if (fileNames == null)
                {
                    return(false);
                }

                bool any = false;

                foreach (string fileName in fileNames)
                {
                    // Boy do I love duplicate code C:

                    string textureName = Path.GetFileNameWithoutExtension(fileName);

                    int textureIndex = Data.Textures.FindIndex(x => x.Name.Equals(textureName, StringComparison.OrdinalIgnoreCase));

                    if (textureIndex == -1)
                    {
                        continue;
                    }

                    any = true;

                    var texture = Data.Textures[textureIndex];

                    Texture newTexture;

                    using (var bitmap = new Bitmap(fileName))
                    {
                        bitmap.RotateFlip(RotateFlipType.Rotate180FlipX);

                        newTexture = TextureEncoder.EncodeFromBitmap(bitmap,
                                                                     texture.IsYCbCr ? TextureFormat.RGBA8 : texture.Format, texture.MipMapCount != 1);
                    }

                    newTexture.Name = texture.Name;
                    newTexture.Id   = texture.Id;

                    Data.Textures[textureIndex] = newTexture;
                }

                return(any);
            }, Keys.None, CustomHandlerFlags.Repopulate | CustomHandlerFlags.ClearMementos);

            base.Initialize();
        }
コード例 #17
0
        protected override void InitializeCore()
        {
            RegisterReplaceHandler <TextureSet>(BinaryFile.Load <TextureSet>);
            RegisterExportHandler <TextureSet>((path) =>
            {
                // Assume it's being exported for F2nd PS3
                if (BinaryFormatUtilities.IsClassic(Data.Format) && path.EndsWith(".txd", StringComparison.OrdinalIgnoreCase))
                {
                    Data.Format     = BinaryFormat.F2nd;
                    Data.Endianness = Endianness.BigEndian;
                }

                // Or reverse
                else if (BinaryFormatUtilities.IsModern(Data.Format) && path.EndsWith(".bin", StringComparison.OrdinalIgnoreCase))
                {
                    Data.Format     = BinaryFormat.DT;
                    Data.Endianness = Endianness.LittleEndian;
                }

                Data.Save(path);
            });
            RegisterImportHandler <Texture>((path) =>
            {
                var texture = TextureEncoder.Encode(path);
                var node    = DataNodeFactory.Create <Texture>(Path.GetFileNameWithoutExtension(path), texture);
                Textures.Add(node);
            });
            RegisterImportHandler <Bitmap>((path) =>
            {
                var texture = TextureEncoder.Encode(path);
                var node    = DataNodeFactory.Create <Texture>(Path.GetFileNameWithoutExtension(path), texture);
                Textures.Add(node);
            });
            RegisterCustomHandler("Export All", () =>
            {
                using (var saveFileDialog = new SaveFileDialog())
                {
                    saveFileDialog.AutoUpgradeEnabled = true;
                    saveFileDialog.CheckPathExists    = true;
                    saveFileDialog.Title    = "Select a folder to export textures to.";
                    saveFileDialog.FileName = "Enter into a directory and press Save";

                    if (saveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        var outputDirectory = Path.GetDirectoryName(saveFileDialog.FileName);
                        foreach (var texture in Data.Textures)
                        {
                            if (!TextureFormatUtilities.IsCompressed(texture.Format) || texture.IsYCbCr)
                            {
                                TextureDecoder.DecodeToPNG(texture, Path.Combine(outputDirectory, texture.Name + ".png"));
                            }
                            else
                            {
                                TextureDecoder.DecodeToDDS(texture, Path.Combine(outputDirectory, texture.Name + ".dds"));
                            }
                        }
                    }
                }
            }, Keys.Control | Keys.Shift | Keys.E);
            RegisterDataUpdateHandler(() =>
            {
                var data        = new TextureSet();
                data.Format     = Format;
                data.Endianness = Endianness;
                data.Textures.AddRange(Textures.Data);
                return(data);
            });
        }