public void LoadDDS(string FileName, byte[] FileData = null)
        {
            TexName = STGenericTexture.SetNameFromPath(FileName);

            DDS dds = new DDS();

            if (FileData != null)
            {
                dds.Load(new FileReader(new MemoryStream(FileData)));
            }
            else
            {
                dds.Load(new FileReader(FileName));
            }
            MipCount    = dds.header.mipmapCount;
            TexWidth    = dds.header.width;
            TexHeight   = dds.header.height;
            arrayLength = 1;
            if (dds.header.caps2 == (uint)DDS.DDSCAPS2.CUBEMAP_ALLFACES)
            {
                arrayLength = 6;
            }
            DataBlockOutput.Add(dds.bdata);

            Format = (CTR_3DS.PICASurfaceFormat)CTR_3DS.ConvertToPICAFormat(dds.Format);
        }
Exemplo n.º 2
0
        public override void Replace(string FileName)
        {
            CTR_3DSTextureImporter  importer = new CTR_3DSTextureImporter();
            CTR_3DSImporterSettings settings = new CTR_3DSImporterSettings();

            settings.LoadBitMap(FileName);
            importer.LoadSettings(new List <CTR_3DSImporterSettings>()
            {
                settings,
            });
            settings.MipCount = 1;
            settings.Format   = CTR_3DS.ConvertToPICAFormat(Format);

            if (importer.ShowDialog() == DialogResult.OK)
            {
                if (settings.GenerateMipmaps && !settings.IsFinishedCompressing)
                {
                    settings.DataBlockOutput.Clear();
                    settings.DataBlockOutput.Add(settings.GenerateMips());
                }

                ApplySettings(settings);
                UpdateEditor();
            }
        }
        public void LoadBitMap(Image Image, string FileName)
        {
            DecompressedData.Clear();

            TexName = STGenericTexture.SetNameFromPath(FileName);

            Format = CTR_3DS.ConvertToPICAFormat(Runtime.PreferredTexFormat);

            GenerateMipmaps = true;
            LoadImage(new Bitmap(Image));
        }
Exemplo n.º 4
0
        public void Save(System.IO.Stream stream)
        {
            using (var writer = new FileWriter(stream, true))
            {
                writer.Write(Width);
                writer.Write(Height);
                writer.Write((byte)CTR_3DS.ConvertToPICAFormat(Format));
                writer.Write((byte)MipCount);
                writer.Write((ushort)0); //Padding
                writer.WriteString(Text);

                writer.Position = 0x80;
                writer.Write(ImageData);
            }
        }
        public void LoadSupportedFormats(TEX_FORMAT[] Formats)
        {
            formatComboBox.Items.Clear();
            foreach (TEX_FORMAT format in Formats)
            {
                var CtrFormat = CTR_3DS.ConvertToPICAFormat(format);
                formatComboBox.Items.Add(CtrFormat);
            }

            var CtrDefaultFormat = CTR_3DS.ConvertToPICAFormat(Runtime.PreferredTexFormat);

            if (formatComboBox.Items.Contains(CtrDefaultFormat))
            {
                formatComboBox.SelectedItem = CtrDefaultFormat;
            }
        }
Exemplo n.º 6
0
        public override void SetImageData(System.Drawing.Bitmap bitmap, int ArrayLevel)
        {
            if (bitmap == null || image == null)
            {
                return; //Image is likely disposed and not needed to be applied
            }
            MipCount = 1;
            var CtrFormat = CTR_3DS.ConvertToPICAFormat(Format);

            try
            {
                //Create image block from bitmap first
                var data = GenerateMipsAndCompress(bitmap, MipCount, Format);

                //Swizzle and create surface

                /*    var surface = GX2.CreateGx2Texture(data, Text,
                 *      (uint)image.TileMode,
                 *      (uint)0,
                 *      (uint)image.Width,
                 *      (uint)image.Height,
                 *      (uint)1,
                 *      (uint)Gx2Format,
                 *      (uint)0,
                 *      (uint)1,
                 *      (uint)MipCount
                 *      );
                 *
                 *  image.Swizzle = (byte)surface.swizzle;
                 *  image.BCLIMFormat = ConvertFormatGenericToBflim(Format);
                 *  image.Height = (ushort)surface.height;
                 *  image.Width = (ushort)surface.width;*/

                Width  = image.Width;
                Height = image.Height;

                // ImageData = surface.data;

                IsEdited = true;
                LoadOpenGLTexture();
                LibraryGUI.UpdateViewport();
            }
            catch (Exception ex)
            {
                STErrorDialog.Show("Failed to swizzle and compress image " + Text, "Error", ex.ToString());
            }
        }
Exemplo n.º 7
0
            public override void Replace(string FileName)
            {
                CTR_3DSTextureImporter  importer = new CTR_3DSTextureImporter();
                CTR_3DSImporterSettings settings = new CTR_3DSImporterSettings();

                if (Utils.GetExtension(FileName) == ".dds" ||
                    Utils.GetExtension(FileName) == ".dds2")
                {
                    settings.LoadDDS(FileName);
                    importer.LoadSettings(new List <CTR_3DSImporterSettings>()
                    {
                        settings,
                    });

                    ApplySettings(settings);
                    UpdateEditor();
                }
                else
                {
                    settings.LoadBitMap(FileName);
                    settings.Format = CTR_3DS.ConvertToPICAFormat(Format);
                    if (MipCount == 1)
                    {
                        settings.MipCount = 1;
                    }
                    importer.LoadSettings(new List <CTR_3DSImporterSettings>()
                    {
                        settings,
                    });

                    if (importer.ShowDialog() == DialogResult.OK)
                    {
                        if (settings.GenerateMipmaps && !settings.IsFinishedCompressing)
                        {
                            settings.DataBlockOutput.Clear();
                            settings.DataBlockOutput.Add(settings.GenerateMips());
                        }

                        Console.WriteLine($"ImageSize {this.ImageData.Length} {settings.DataBlockOutput[0]}");

                        ApplySettings(settings);
                        UpdateEditor();
                    }
                }
            }
Exemplo n.º 8
0
        private void ApplySettings(CTR_3DSImporterSettings settings)
        {
            if (this.Width != settings.TexWidth)
            {
                throw new Exception("The image should be the same width as the original!");
            }
            if (this.Height != settings.TexHeight)
            {
                throw new Exception("The image should be the same height as the original!");
            }

            this.TextureTGLP.SheetDataList[SheetIndex] = settings.DataBlockOutput[0];
            this.TextureTGLP.Format = (ushort)CTR_3DS.ConvertToPICAFormat(settings.GenericFormat);
            this.Format             = settings.GenericFormat;
            this.MipCount           = settings.MipCount;
            this.Depth      = settings.Depth;
            this.ArrayCount = (uint)settings.DataBlockOutput.Count;
        }
Exemplo n.º 9
0
        public byte[] Save()
        {
            MemoryStream mem = new MemoryStream();

            using (var writer = new FileWriter(mem))
            {
                writer.Write(Width);
                writer.Write(Height);
                writer.Write((byte)CTR_3DS.ConvertToPICAFormat(Format));
                writer.Write((byte)MipCount);
                writer.Write((ushort)0); //Padding
                writer.WriteString(Text);

                writer.Position = 0x80;
                writer.Write(ImageData);
            }


            return(mem.ToArray());
        }
        public void LoadBitMap(string FileName)
        {
            DecompressedData.Clear();

            TexName = STGenericTexture.SetNameFromPath(FileName);

            Format          = CTR_3DS.ConvertToPICAFormat(Runtime.PreferredTexFormat);
            GenerateMipmaps = true;

            //If a texture is .tga, we need to convert it
            Bitmap Image = null;

            if (Utils.GetExtension(FileName) == ".tga")
            {
                Image = Paloma.TargaImage.LoadTargaImage(FileName);
            }
            else
            {
                Image = new Bitmap(FileName);
            }

            LoadImage(Image);
        }