Example #1
0
        public void LoadDDS(string FileName, byte[] FileData = null, TextureData tree = 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;

            var surfaces = DDS.GetArrayFaces(dds, dds.ArrayCount);

            RedComp   = dds.RedChannel;
            GreenComp = dds.GreenChannel;
            BlueComp  = dds.BlueChannel;
            AlphaComp = dds.AlphaChannel;

            foreach (var surface in surfaces)
            {
                DataBlockOutput.Add(Utils.CombineByteArray(surface.mipmaps.ToArray()));
            }

            Format = TextureData.GenericToBntxSurfaceFormat(dds.Format);
        }
Example #2
0
        public void LoadBitMap(Image Image, string Name)
        {
            DecompressedData.Clear();

            TexName = Path.GetFileNameWithoutExtension(Name);
            Format  = TextureData.GenericToBntxSurfaceFormat(Runtime.PreferredTexFormat);

            GenerateMipmaps = true;
            LoadImage(new Bitmap(Image));
        }
Example #3
0
        public void LoadBitMap(Image Image, string Name)
        {
            DecompressedData.Clear();

            TexName = STGenericTexture.SetNameFromPath(Name);
            Format  = TextureData.GenericToBntxSurfaceFormat(Runtime.PreferredTexFormat);

            GenerateMipmaps = true;
            LoadImage(new Bitmap(Image));
        }
Example #4
0
        public override void SetImageData(Bitmap bitmap, int ArrayLevel)
        {
            if (!Runtime.NUTEXBSettings.IsSwizzled)
            {
                MipCount  = GenerateMipCount(bitmap.Width, bitmap.Height);
                ImageData = GenerateMipsAndCompress(bitmap, MipCount, Format);
                return;
            }

            if (!Runtime.NUTEXBSettings.LimitFileSize)
            {
                MipCount = GenerateMipCount(bitmap.Width, bitmap.Height);
            }

            Texture tex = new Texture();

            tex.Height      = (uint)bitmap.Height;
            tex.Width       = (uint)bitmap.Width;
            tex.Format      = TextureData.GenericToBntxSurfaceFormat(Format);
            tex.Name        = Text;
            tex.Path        = "";
            tex.TextureData = new List <List <byte[]> >();

            STChannelType[] channels = SetChannelsByFormat(Format);
            tex.sparseBinding   = 0; //false
            tex.sparseResidency = 0; //false
            tex.Flags           = 0;
            tex.Swizzle         = 0;
            tex.textureLayout   = 0;
            tex.Regs            = new uint[0];
            tex.AccessFlags     = AccessFlags.Texture;
            tex.ArrayLength     = (uint)ArrayLevel;
            tex.MipCount        = MipCount;
            tex.Depth           = Depth;
            tex.Dim             = Dim.Dim2D;
            tex.TileMode        = TileMode.Default;
            tex.textureLayout2  = 0x010007;
            tex.SurfaceDim      = SurfaceDim.Dim2D;
            tex.SampleCount     = 1;
            tex.Pitch           = 32;

            tex.MipOffsets = new long[tex.MipCount];

            var mipmaps = TextureImporterSettings.SwizzleSurfaceMipMaps(tex,
                                                                        GenerateMipsAndCompress(bitmap, MipCount, Format), MipCount);

            byte[] output = Utils.CombineByteArray(mipmaps.ToArray());
            if (Runtime.NUTEXBSettings.LimitFileSize && output.Length > ImageData.Length)
            {
                throw new Exception("Image must be the same size or smaller!");
            }

            ImageData = SetImageData(output);
        }
Example #5
0
        public override void SetImageData(Bitmap bitmap, int ArrayLevel)
        {
            if (!IsSwizzled)
            {
                //   MipCount = GenerateMipCount(bitmap.Width, bitmap.Height);

                //  ImageData = GenerateMipsAndCompress(bitmap, Format);
                return;
            }

            Texture tex = new Texture();

            tex.Height      = (uint)bitmap.Height;
            tex.Width       = (uint)bitmap.Width;
            tex.Format      = TextureData.GenericToBntxSurfaceFormat(Format);
            tex.Name        = Text;
            tex.Path        = "";
            tex.TextureData = new List <List <byte[]> >();

            STChannelType[] channels = SetChannelsByFormat(Format);
            tex.sparseBinding   = 0; //false
            tex.sparseResidency = 0; //false
            tex.Flags           = 0;
            tex.Swizzle         = 0;
            tex.textureLayout   = 0;
            tex.Regs            = new uint[0];
            tex.AccessFlags     = 0x20;
            tex.ArrayLength     = (uint)ArrayLevel;
            tex.MipCount        = MipCount;
            tex.Depth           = Depth;
            tex.Dim             = Dim.Dim2D;
            tex.TileMode        = TileMode.Default;
            tex.textureLayout2  = 0x010007;
            tex.SurfaceDim      = SurfaceDim.Dim2D;
            tex.SampleCount     = 1;
            tex.Pitch           = 32;
            tex.MipOffsets      = new long[tex.MipCount];

            MipCount = GenerateMipCount(bitmap.Width, bitmap.Height);

            var mipmaps = TextureImporterSettings.SwizzleSurfaceMipMaps(tex,
                                                                        GenerateMipsAndCompress(bitmap, Format), MipCount);

            ImageData = Utils.CombineByteArray(mipmaps.ToArray());
        }
Example #6
0
        public void LoadASTC(string FileName)
        {
            DecompressedData.Clear();
            TexName = STGenericTexture.SetNameFromPath(FileName);

            ASTC astc = new ASTC();

            astc.Load(new FileStream(FileName, FileMode.Open));

            MipCount = 0;

            TexWidth  = (uint)astc.Width;
            TexHeight = (uint)astc.Height;

            DataBlockOutput.Add(astc.DataBlock);

            Format = TextureData.GenericToBntxSurfaceFormat(astc.Format);
        }
Example #7
0
            public override void SetImageData(Bitmap bitmap, int ArrayLevel)
            {
                if (bitmap == null)
                {
                    return; //Image is likely disposed and not needed to be applied
                }
                MipCount = GenerateMipCount(bitmap.Width, bitmap.Height);

                XTXFormat = ConvertFromGenericFormat(Format);

                var tex = new Syroot.NintenTools.NSW.Bntx.Texture();

                tex.Height      = (uint)bitmap.Height;
                tex.Width       = (uint)bitmap.Width;
                tex.Format      = TextureData.GenericToBntxSurfaceFormat(Format);
                tex.Name        = Text;
                tex.Path        = "";
                tex.TextureData = new List <List <byte[]> >();

                STChannelType[] channels = SetChannelsByFormat(Format);
                tex.sparseBinding   = 0; //false
                tex.sparseResidency = 0; //false
                tex.Flags           = 0;
                tex.Swizzle         = 0;
                tex.textureLayout   = 0;
                tex.Regs            = new uint[0];
                tex.AccessFlags     = AccessFlags.Texture;
                tex.ArrayLength     = (uint)ArrayLevel;
                tex.MipCount        = MipCount;
                tex.Depth           = Depth;
                tex.Dim             = Syroot.NintenTools.NSW.Bntx.GFX.Dim.Dim2D;
                tex.TileMode        = Syroot.NintenTools.NSW.Bntx.GFX.TileMode.Default;
                tex.textureLayout2  = 0x010007;
                tex.SurfaceDim      = Syroot.NintenTools.NSW.Bntx.GFX.SurfaceDim.Dim2D;
                tex.SampleCount     = 1;
                tex.Pitch           = 32;

                tex.MipOffsets = new long[tex.MipCount];

                var mipmaps = TextureImporterSettings.SwizzleSurfaceMipMaps(tex,
                                                                            GenerateMipsAndCompress(bitmap, MipCount, Format), MipCount);

                ImageData = Utils.CombineByteArray(mipmaps.ToArray());
            }
Example #8
0
        public void LoadBitMap(string FileName)
        {
            DecompressedData.Clear();

            TexName = STGenericTexture.SetNameFromPath(FileName);
            Format  = TextureData.GenericToBntxSurfaceFormat(DefaultFormat);

            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);
        }