private void listViewCustom1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listViewCustom1.SelectedItems.Count == 1)
            {
                SelectedIndex = listViewCustom1.SelectedIndices[0];

                SelectedTexSettings         = settings[listViewCustom1.SelectedIndices[0]];
                formatComboBox.SelectedItem = SelectedTexSettings.Format;

                SetupSettings(SelectedTexSettings);

                MipmapNum.Maximum = STGenericTexture.GenerateTotalMipCount(
                    SelectedTexSettings.TexWidth, SelectedTexSettings.TexHeight) + 1;

                //Force the mip counter to be the selected mip counter
                //Some textures like bflim (used for UI) only have 1
                if (OverrideMipCounter)
                {
                    MipmapNum.Maximum = SelectedTexSettings.MipCount;
                    MipmapNum.Minimum = SelectedTexSettings.MipCount;
                }

                MipmapNum.Value  = SelectedTexSettings.MipCount;
                SwizzleNum.Value = SelectedTexSettings.SwizzlePattern;
            }
        }
예제 #2
0
        public void LoadSettings(GTXImporterSettings setting)
        {
            settings.Add(setting);

            listViewCustom1.Items.Add(setting.TexName).SubItems.Add(setting.Format.ToString());
            listViewCustom1.Items[0].Selected = true;
            listViewCustom1.Select();
        }
        public void SetupSettings(GTXImporterSettings setting)
        {
            if (setting.Format == GX2.GX2SurfaceFormat.INVALID || SelectedIndex == -1)
            {
                return;
            }

            if (Thread != null && Thread.IsAlive)
            {
                Thread.Abort();
            }

            if (formatComboBox.SelectedItem is GX2.GX2SurfaceFormat)
            {
                setting.Format = (GX2.GX2SurfaceFormat)formatComboBox.SelectedItem;

                listViewCustom1.Items[SelectedIndex].SubItems[1].Text = setting.Format.ToString();
            }
            HeightLabel.Text = $"Height: {setting.TexHeight}";
            WidthLabel.Text  = $"Width: {setting.TexWidth}";

            Bitmap bitmap = Toolbox.Library.Imaging.GetLoadingImage();

            pictureBox1.Image = bitmap;

            Thread = new Thread((ThreadStart)(() =>
            {
                setting.IsFinishedCompressing = false;
                ToggleOkButton(false);

                var mips = setting.GenerateMipList();
                setting.DataBlockOutput.Clear();
                setting.DataBlockOutput.Add(Utils.CombineByteArray(mips.ToArray()));

                ToggleOkButton(true);

                setting.Compress();

                bitmap = FTEX.DecodeBlockGetBitmap(mips[0], setting.
                                                   TexWidth, setting.TexHeight, FTEX.ConvertFromGx2Format(
                                                       (Syroot.NintenTools.Bfres.GX2.GX2SurfaceFormat)setting.Format), new byte[0]);

                if (pictureBox1.InvokeRequired)
                {
                    pictureBox1.Invoke((MethodInvoker) delegate {
                        pictureBox1.Image = bitmap;
                        pictureBox1.Refresh();

                        int size = Utils.GetSizeInBytes(mips);
                        dataSizeLbl.Text = $"Data Size: {STMath.GetFileSize(size, 5)}";
                    });
                }

                mips.Clear();
            }));
            Thread.Start();
        }
예제 #4
0
        private void listViewCustom1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listViewCustom1.SelectedItems.Count > 0)
            {
                SelectedTexSettings         = settings[listViewCustom1.SelectedIndices[0]];
                formatComboBox.SelectedItem = SelectedTexSettings.Format;

                SetupSettings();

                MipmapNum.Maximum = SelectedTexSettings.GetTotalMipCount() + 1;
                MipmapNum.Value   = SelectedTexSettings.MipCount;
            }
        }
예제 #5
0
        public void LoadSetting(GTXImporterSettings setting)
        {
            settings.Add(setting);

            if (setting.UseBc4Alpha)
            {
                chkBc4Alpha.Checked = true;
            }

            listViewCustom1.Items.Add(setting.TexName).SubItems.Add(setting.Format.ToString());
            listViewCustom1.Items[0].Selected = true;
            listViewCustom1.Select();
        }
예제 #6
0
 public static GX2.GX2Surface CreateGx2Texture(byte[] imageData, GTXImporterSettings setting)
 {
     return(GX2.CreateGx2Texture(imageData,
                                 setting.TexName,
                                 setting.tileMode,
                                 (uint)setting.AAMode,
                                 setting.TexWidth,
                                 setting.TexHeight,
                                 setting.Depth,
                                 (uint)setting.Format,
                                 setting.Swizzle,
                                 (uint)setting.SurfaceDim,
                                 setting.MipCount));
 }
예제 #7
0
            public static GTXImporterSettings SetImporterSettings(string name)
            {
                var    importer = new GTXImporterSettings();
                string ext      = System.IO.Path.GetExtension(name);

                ext = ext.ToLower();

                switch (ext)
                {
                case ".dds":
                    importer.LoadDDS(name);
                    break;

                default:
                    importer.LoadBitMap(name);
                    break;
                }

                return(importer);
            }
예제 #8
0
        public static GTX.GX2Surface CreateGx2Texture(byte[] imageData, GTXImporterSettings setting, uint tileMode, uint AAMode)
        {
            var Format = (GTX.GX2SurfaceFormat)setting.Format;

            Console.WriteLine("Format " + Format + " " + setting.TexName);

            var  surfOut   = GTX.getSurfaceInfo(Format, setting.TexWidth, setting.TexHeight, 1, 1, tileMode, 0, 0);
            uint imageSize = (uint)surfOut.surfSize;
            uint alignment = surfOut.baseAlign;
            uint pitch     = surfOut.pitch;
            uint mipSize   = 0;
            uint dataSize  = (uint)imageData.Length;
            uint bpp       = GTX.surfaceGetBitsPerPixel((uint)setting.Format) >> 3;

            if (dataSize <= 0)
            {
                throw new Exception($"Image is empty!!");
            }

            if (surfOut.depth != 1)
            {
                throw new Exception($"Unsupported Depth {surfOut.depth}!");
            }

            uint s = 0;

            switch (tileMode)
            {
            case 1:
            case 2:
            case 3:
            case 16:
                s = 0;
                break;

            default:
                s = 0xd0000 | setting.swizzle << 8;
                break;
            }
            uint blkWidth, blkHeight;

            if (GTX.IsFormatBCN(Format))
            {
                blkWidth  = 4;
                blkHeight = 4;
            }
            else
            {
                blkWidth  = 1;
                blkHeight = 1;
            }
            List <uint>   mipOffsets = new List <uint>();
            List <byte[]> Swizzled   = new List <byte[]>();

            for (int mipLevel = 0; mipLevel < setting.MipCount; mipLevel++)
            {
                var result = TextureHelper.GetCurrentMipSize(setting.TexWidth, setting.TexHeight, blkWidth, blkHeight, bpp, mipLevel);

                uint offset = result.Item1;
                uint size   = result.Item2;

                Console.WriteLine("Swizzle Size " + size);
                Console.WriteLine("Swizzle offset " + offset);
                Console.WriteLine("bpp " + bpp);
                Console.WriteLine("TexWidth " + setting.TexWidth);
                Console.WriteLine("TexHeight " + setting.TexHeight);
                Console.WriteLine("blkWidth " + blkWidth);
                Console.WriteLine("blkHeight " + blkHeight);
                Console.WriteLine("mipLevel " + mipLevel);

                byte[] data_ = new byte[size];
                Array.Copy(imageData, offset, data_, 0, size);

                uint width_  = Math.Max(1, setting.TexWidth >> mipLevel);
                uint height_ = Math.Max(1, setting.TexHeight >> mipLevel);

                if (mipLevel != 0)
                {
                    surfOut = GTX.getSurfaceInfo(Format, setting.TexWidth, setting.TexHeight, 1, 1, tileMode, 0, mipLevel);

                    if (mipLevel == 1)
                    {
                        mipOffsets.Add(imageSize);
                    }
                    else
                    {
                        mipOffsets.Add(mipSize);
                    }
                }

                data_ = Utils.CombineByteArray(data_, new byte[surfOut.surfSize - size]);
                byte[] dataAlignBytes = new byte[RoundUp(mipSize, surfOut.baseAlign) - mipSize];

                if (mipLevel != 0)
                {
                    mipSize += (uint)(surfOut.surfSize + dataAlignBytes.Length);
                }

                byte[] SwizzledData = GTX.swizzle(width_, height_, surfOut.height, (uint)Format, surfOut.tileMode, s,
                                                  surfOut.pitch, surfOut.bpp, data_);

                Swizzled.Add(dataAlignBytes.Concat(SwizzledData).ToArray());
            }

            GTX.GX2Surface surf = new GTX.GX2Surface();
            surf.depth         = setting.Depth;
            surf.width         = setting.TexWidth;
            surf.height        = setting.TexHeight;
            surf.depth         = 1;
            surf.use           = 1;
            surf.dim           = (uint)setting.SurfaceDim;
            surf.tileMode      = tileMode;
            surf.swizzle       = s;
            surf.resourceFlags = 0;
            surf.pitch         = pitch;
            surf.bpp           = bpp;
            surf.format        = (uint)setting.Format;
            surf.numMips       = setting.MipCount;
            surf.aa            = AAMode;
            surf.mipOffset     = mipOffsets.ToArray();
            surf.numMips       = (uint)Swizzled.Count;
            surf.alignment     = alignment;
            surf.mipSize       = mipSize;
            surf.imageSize     = imageSize;
            surf.data          = Swizzled[0];

            List <byte[]> mips = new List <byte[]>();

            for (int mipLevel = 1; mipLevel < Swizzled.Count; mipLevel++)
            {
                mips.Add(Swizzled[mipLevel]);
                Console.WriteLine(Swizzled[mipLevel].Length);
            }
            surf.mipData = Utils.CombineByteArray(mips.ToArray());
            mips.Clear();


            Console.WriteLine("");
            Console.WriteLine("// ----- GX2Surface Swizzled Info ----- ");
            Console.WriteLine("  dim             = 1");
            Console.WriteLine("  width           = " + surf.width);
            Console.WriteLine("  height          = " + surf.height);
            Console.WriteLine("  depth           = 1");
            Console.WriteLine("  numMips         = " + surf.numMips);
            Console.WriteLine("  format          = " + surf.format);
            Console.WriteLine("  aa              = 0");
            Console.WriteLine("  use             = 1");
            Console.WriteLine("  imageSize       = " + surf.imageSize);
            Console.WriteLine("  mipSize         = " + surf.mipSize);
            Console.WriteLine("  tileMode        = " + surf.tileMode);
            Console.WriteLine("  swizzle         = " + surf.swizzle);
            Console.WriteLine("  alignment       = " + surf.alignment);
            Console.WriteLine("  pitch           = " + surf.pitch);
            Console.WriteLine("  data            = " + surf.data.Length);
            Console.WriteLine("  mipData         = " + surf.mipData.Length);
            Console.WriteLine("");
            Console.WriteLine("  GX2 Component Selector:");
            Console.WriteLine("");
            Console.WriteLine("  bits per pixel  = " + (surf.bpp << 3));
            Console.WriteLine("  bytes per pixel = " + surf.bpp);
            Console.WriteLine("  realSize        = " + imageData.Length);

            return(surf);
        }
예제 #9
0
        public void SetupSettings(GTXImporterSettings setting, bool setFormat = true)
        {
            if (setting.Format == GX2.GX2SurfaceFormat.INVALID || SelectedIndex == -1)
            {
                return;
            }

            if (Thread != null && Thread.IsAlive)
            {
                Thread.Abort();
            }

            if (formatComboBox.SelectedItem is GX2.GX2SurfaceFormat && setFormat)
            {
                setting.Format = (GX2.GX2SurfaceFormat)formatComboBox.SelectedItem;

                if (setting.Format == GX2.GX2SurfaceFormat.T_BC4_UNORM && DisplayBC4Alpha ||
                    setting.Format == GX2.GX2SurfaceFormat.T_BC4_SNORM && DisplayBC4Alpha)
                {
                    chkBc4Alpha.Visible = true;
                }
                else
                {
                    chkBc4Alpha.Visible = false;
                }

                listViewCustom1.Items[SelectedIndex].SubItems[1].Text = setting.Format.ToString();
            }

            if (setting.MipCountOriginal >= 0)
            {
                chkOriginalMipCount.Enabled = true;
            }
            else
            {
                chkOriginalMipCount.Enabled = false;
            }

            HeightLabel.Text = $"Height: {setting.TexHeight}";
            WidthLabel.Text  = $"Width: {setting.TexWidth}";

            Bitmap bitmap = Toolbox.Library.Imaging.GetLoadingImage();

            pictureBox1.Image = bitmap;

            Thread = new Thread((ThreadStart)(() =>
            {
                setting.IsFinishedCompressing = false;
                ToggleOkButton(false);

                var mips = setting.GenerateMipList();
                setting.DataBlockOutput.Clear();
                setting.DataBlockOutput.Add(Utils.CombineByteArray(mips.ToArray()));

                ToggleOkButton(true);
                setting.IsFinishedCompressing = true;

                bitmap = FTEX.DecodeBlockGetBitmap(mips[0], setting.
                                                   TexWidth, setting.TexHeight, FTEX.ConvertFromGx2Format(
                                                       (Syroot.NintenTools.Bfres.GX2.GX2SurfaceFormat)setting.Format), new byte[0]);


                if (setting.FlipY)
                {
                    bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
                }
                if (setting.UseBc4Alpha)
                {
                    bitmap = BitmapExtension.SetChannel(bitmap,
                                                        STChannelType.Red, STChannelType.Red, STChannelType.Red, STChannelType.Red);
                }

                if (pictureBox1.InvokeRequired)
                {
                    pictureBox1.Invoke((MethodInvoker) delegate {
                        pictureBox1.Image = bitmap;
                        pictureBox1.Refresh();

                        int size = Utils.GetSizeInBytes(mips);
                        dataSizeLbl.Text = $"Data Size: {STMath.GetFileSize(size, 5)}";
                    });
                }

                mips.Clear();
            }));
            Thread.Start();
        }