Exemplo n.º 1
0
            public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
            {
                if (ContainerParent.Platform == GT1Platform.WiiU)
                {
                    uint bpp = GetBytesPerPixel(Format);

                    GX2.GX2Surface surf = new GX2.GX2Surface();
                    surf.bpp       = bpp;
                    surf.height    = Height;
                    surf.width     = Width;
                    surf.aa        = (uint)GX2.GX2AAMode.GX2_AA_MODE_1X;
                    surf.alignment = 0;
                    surf.depth     = 1;
                    surf.dim       = (uint)GX2.GX2SurfaceDimension.DIM_2D;
                    surf.format    = (uint)Bfres.Structs.FTEX.ConvertToGx2Format(Format);
                    surf.use       = (uint)GX2.GX2SurfaceUse.USE_COLOR_BUFFER;
                    surf.pitch     = 0;
                    surf.data      = ImageData;
                    surf.numMips   = MipCount;
                    surf.mipOffset = new uint[0];
                    surf.mipData   = ImageData;
                    surf.tileMode  = (uint)GX2.GX2TileMode.MODE_2D_TILED_THIN1;

                    //  surf.tileMode = (uint)GX2.GX2TileMode.MODE_2D_TILED_THIN1;
                    surf.swizzle  = 0;
                    surf.numArray = 1;

                    return(GX2.Decode(surf, ArrayLevel, MipLevel));
                }
                else
                {
                    return(ImageData);
                }
            }
Exemplo n.º 2
0
        public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
        {
            if (image.Is3DS)
            {
                PlatformSwizzle = PlatformSwizzle.Platform_3DS;
                return(ImageData);
            }
            else
            {
                uint bpp = GetBytesPerPixel(Format);

                GX2.GX2Surface surf = new GX2.GX2Surface();
                surf.bpp       = bpp;
                surf.height    = image.Height;
                surf.width     = image.Width;
                surf.aa        = (uint)GX2.GX2AAMode.GX2_AA_MODE_1X;
                surf.alignment = image.Alignment;
                surf.depth     = 1;
                surf.dim       = (uint)GX2.GX2SurfaceDimension.DIM_2D;
                surf.format    = (uint)FTEX.ConvertToGx2Format(Format);
                surf.use       = (uint)GX2.GX2SurfaceUse.USE_COLOR_BUFFER;
                surf.pitch     = 0;
                surf.data      = ImageData;
                surf.numMips   = 1;
                surf.mipOffset = new uint[0];
                surf.mipData   = ImageData;
                surf.tileMode  = (uint)GX2.GX2TileMode.MODE_2D_TILED_THIN1;
                surf.swizzle   = image.Swizzle;
                surf.numArray  = 1;

                return(GX2.Decode(surf, ArrayLevel, MipLevel));
            }
        }
Exemplo n.º 3
0
            private void ApplySurface(GX2.GX2Surface NewSurface)
            {
                surface.aa            = NewSurface.aa;
                surface.alignment     = NewSurface.alignment;
                surface.bpp           = NewSurface.bpp;
                surface.compSel       = NewSurface.compSel;
                surface.data          = NewSurface.data;
                surface.depth         = NewSurface.depth;
                surface.dim           = NewSurface.dim;
                surface.firstMip      = NewSurface.firstMip;
                surface.firstSlice    = NewSurface.firstSlice;
                surface.format        = NewSurface.format;
                surface.height        = NewSurface.height;
                surface.imageCount    = NewSurface.imageCount;
                surface.imageSize     = NewSurface.imageSize;
                surface.mipData       = NewSurface.mipData;
                surface.mipSize       = NewSurface.mipSize;
                surface.mipOffset     = NewSurface.mipOffset;
                surface.numArray      = NewSurface.numArray;
                surface.numMips       = NewSurface.numMips;
                surface.pitch         = NewSurface.pitch;
                surface.resourceFlags = NewSurface.resourceFlags;
                surface.swizzle       = NewSurface.swizzle;
                surface.tileMode      = NewSurface.tileMode;
                surface.use           = NewSurface.use;
                surface.width         = NewSurface.width;
                surface.texRegs       = NewSurface.texRegs;

                SetChannelComponents();
            }
Exemplo n.º 4
0
        public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
        {
            uint bpp = GetBytesPerPixel(Format);

            GX2.GX2Surface surf = new GX2.GX2Surface();
            surf.bpp       = bpp;
            surf.height    = Height;
            surf.width     = Width;
            surf.aa        = (uint)GX2.GX2AAMode.GX2_AA_MODE_1X;
            surf.alignment = 0;
            surf.depth     = 1;
            surf.dim       = (uint)GX2.GX2SurfaceDimension.DIM_2D;
            surf.format    = (uint)Bfres.Structs.FTEX.ConvertToGx2Format(Format);
            surf.use       = (uint)GX2.GX2SurfaceUse.USE_COLOR_BUFFER;
            surf.pitch     = 0;
            surf.data      = TextureTGLP.SheetDataList[SheetIndex];
            surf.numMips   = 1;
            surf.mipOffset = new uint[0];
            surf.mipData   = null;
            surf.tileMode  = (uint)GX2.GX2TileMode.MODE_2D_TILED_THIN1;
            surf.swizzle   = Swizzle;
            surf.numArray  = 1;

            var surfaces = GX2.Decode(surf);

            return(surfaces[ArrayLevel][MipLevel]);
        }
Exemplo n.º 5
0
            public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
            {
                int  swizzle = (int)Swizzle;
                int  pitch   = (int)0;
                uint bpp     = GX2.surfaceGetBitsPerPixel(GX2Format) >> 3;

                GX2.GX2Surface surf = new GX2.GX2Surface();
                surf.bpp       = bpp;
                surf.height    = Height;
                surf.width     = Width;
                surf.aa        = (uint)0;
                surf.alignment = Alignment;
                surf.depth     = Depth;
                surf.dim       = 0x1;
                surf.format    = GX2Format;
                surf.use       = 0x1;
                surf.pitch     = 0;
                surf.data      = data;
                surf.mipData   = data;
                surf.numMips   = MipCount;
                surf.tileMode  = TileMode;
                surf.swizzle   = Swizzle;
                surf.imageSize = ImageSize;

                // GX2.GenerateMipSurfaceData(surf);

                return(GX2.Decode(surf, ArrayLevel, MipLevel));
            }
Exemplo n.º 6
0
        public byte[] DecodeImage(STGenericTexture texture, byte[] data, uint width, uint height, int array, int mip)
        {
            uint bpp = TextureFormatHelper.GetBytesPerPixel(OutputFormat);

            GX2.GX2Surface surf = new GX2.GX2Surface();
            surf.bpp       = bpp;
            surf.height    = texture.Height;
            surf.width     = texture.Width;
            surf.depth     = texture.ArrayCount;
            surf.alignment = Alignment;
            surf.aa        = (uint)AAMode;
            surf.dim       = (uint)SurfaceDimension;
            surf.format    = (uint)Format;
            surf.use       = (uint)SurfaceUse;
            surf.pitch     = Pitch;
            surf.data      = data;
            surf.mipData   = MipData != null ? MipData : data;
            surf.mipOffset = MipOffsets != null ? MipOffsets : new uint[0];
            surf.numMips   = texture.MipCount;
            surf.numArray  = texture.ArrayCount;
            surf.tileMode  = (uint)TileMode;
            surf.swizzle   = Swizzle;

            Console.WriteLine("WII U DECODE");

            return(GX2.Decode(surf, array, mip));
        }
Exemplo n.º 7
0
        public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
        {
            format = (int)texture.Format;
            int  swizzle = (int)texture.Swizzle;
            int  pitch   = (int)texture.Pitch;
            uint bpp     = GX2.surfaceGetBitsPerPixel((uint)format) >> 3;

            RedChannel   = GX2ChanneToGeneric(texture.CompSelR);
            GreenChannel = GX2ChanneToGeneric(texture.CompSelG);
            BlueChannel  = GX2ChanneToGeneric(texture.CompSelB);
            AlphaChannel = GX2ChanneToGeneric(texture.CompSelA);

            UpdateMipMaps();

            GX2.GX2Surface surf = new GX2.GX2Surface();
            surf.bpp       = bpp;
            surf.height    = texture.Height;
            surf.width     = texture.Width;
            surf.aa        = (uint)texture.AAMode;
            surf.alignment = texture.Alignment;
            surf.depth     = texture.Depth;
            surf.dim       = (uint)texture.Dim;
            surf.format    = (uint)texture.Format;
            surf.use       = (uint)texture.Use;
            surf.pitch     = texture.Pitch;
            surf.data      = texture.Data;
            surf.numMips   = MipCount;
            surf.mipOffset = texture.MipOffsets;
            surf.mipData   = texture.MipData;
            surf.tileMode  = (uint)texture.TileMode;
            surf.swizzle   = texture.Swizzle;
            surf.numArray  = texture.ArrayLength;



            if (Tex2Swizzle != 0)
            {
                surf.mip_swizzle = Tex2Swizzle;
            }

            if (surf.mipData == null)
            {
                surf.numMips = 1;
            }

            var surfaces = GX2.Decode(surf);

            if (ArrayLevel >= surfaces.Count)
            {
                throw new Exception("Invalid amount of surfaces decoded!");
            }
            if (surfaces.Count == 0)
            {
                throw new Exception("Surfaces came out empty!");
            }

            return(surfaces[ArrayLevel][MipLevel]);
        }
Exemplo n.º 8
0
        //We reuse GX2 data as it's the same thing
        public static Texture FromGx2Surface(GX2.GX2Surface surf, string Name)
        {
            Texture tex = new Texture();

            tex.Name           = Name;
            tex.Path           = "";
            tex.AAMode         = (GX2AAMode)surf.aa;
            tex.Alignment      = (uint)surf.alignment;
            tex.ArrayLength    = 1;
            tex.Data           = surf.data;
            tex.MipData        = surf.mipData;
            tex.Format         = (GX2SurfaceFormat)surf.format;
            tex.Dim            = (GX2SurfaceDim)surf.dim;
            tex.Use            = (GX2SurfaceUse)surf.use;
            tex.TileMode       = (GX2TileMode)surf.tileMode;
            tex.Swizzle        = surf.swizzle;
            tex.Pitch          = surf.pitch;
            tex.Depth          = surf.depth;
            tex.MipCount       = surf.numMips;
            tex.ViewMipCount   = surf.numMips;
            tex.ViewSliceCount = 1;

            tex.MipOffsets = new uint[13];
            for (int i = 0; i < 13; i++)
            {
                if (i < surf.mipOffset.Length)
                {
                    tex.MipOffsets[i] = surf.mipOffset[i];
                }
            }
            tex.Height      = surf.height;
            tex.Width       = surf.width;
            tex.ArrayLength = 1;

            tex.Regs = new uint[5];

            if (surf.compSel == null || surf.compSel.Length != 4)
            {
                surf.compSel = new byte[] { 0, 1, 2, 3 }
            }
            ;

            //Set channels for settings and format
            tex.CompSelR = (GX2CompSel)surf.compSel[0];
            tex.CompSelG = (GX2CompSel)surf.compSel[1];
            tex.CompSelB = (GX2CompSel)surf.compSel[2];
            tex.CompSelA = (GX2CompSel)surf.compSel[3];
            SetChannelsByFormat((GX2SurfaceFormat)surf.format, tex);

            tex.UserData = new ResDict <UserData>();
            return(tex);
        }
Exemplo n.º 9
0
        public byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
        {
            format = (int)texture.Format;
            int  swizzle = (int)texture.Swizzle;
            int  pitch   = (int)texture.Pitch;
            uint bpp     = GX2.surfaceGetBitsPerPixel((uint)format) >> 3;

            RedChannel   = GX2ChanneToGeneric(texture.CompSelR);
            GreenChannel = GX2ChanneToGeneric(texture.CompSelG);
            BlueChannel  = GX2ChanneToGeneric(texture.CompSelB);
            AlphaChannel = GX2ChanneToGeneric(texture.CompSelA);

            UpdateMipMaps();

            GX2.GX2Surface surf = new GX2.GX2Surface();
            surf.bpp       = bpp;
            surf.height    = texture.Height;
            surf.width     = texture.Width;
            surf.aa        = (uint)texture.AAMode;
            surf.alignment = texture.Alignment;
            surf.depth     = texture.Depth;
            surf.dim       = (uint)texture.Dim;
            surf.format    = (uint)texture.Format;
            surf.use       = (uint)texture.Use;
            surf.pitch     = texture.Pitch;
            surf.data      = texture.Data;
            surf.numMips   = MipCount;
            surf.mipOffset = texture.MipOffsets;
            surf.mipData   = texture.MipData;
            surf.tileMode  = (uint)texture.TileMode;
            surf.swizzle   = texture.Swizzle;
            surf.numArray  = texture.ArrayLength;

            if (Tex2Swizzle != 0)
            {
                surf.mip_swizzle = Tex2Swizzle;
            }

            if (surf.mipData == null)
            {
                surf.numMips = 1;
            }


            return(GX2.Decode(surf, ArrayLevel, MipLevel));
        }
Exemplo n.º 10
0
            public void ReadChunk(FileReader reader)
            {
                reader.SetByteOrder(true);

                Console.WriteLine("TEX pos " + reader.Position);
                GX2Surface            = new GX2.GX2Surface();
                GX2Surface.dim        = reader.ReadUInt32();
                GX2Surface.width      = reader.ReadUInt32();
                GX2Surface.height     = reader.ReadUInt32();
                GX2Surface.depth      = reader.ReadUInt32();
                GX2Surface.numMips    = reader.ReadUInt32();
                GX2Surface.format     = reader.ReadUInt32();
                GX2Surface.aa         = reader.ReadUInt32();
                GX2Surface.use        = reader.ReadUInt32();
                GX2Surface.imageSize  = reader.ReadUInt32();
                GX2Surface.imagePtr   = reader.ReadUInt32();
                GX2Surface.mipSize    = reader.ReadUInt32();
                GX2Surface.mipPtr     = reader.ReadUInt32();
                GX2Surface.tileMode   = reader.ReadUInt32();
                GX2Surface.swizzle    = reader.ReadUInt32();
                GX2Surface.alignment  = reader.ReadUInt32();
                GX2Surface.pitch      = reader.ReadUInt32();
                GX2Surface.mipOffset  = reader.ReadUInt32s(13);
                GX2Surface.firstMip   = reader.ReadUInt32();
                GX2Surface.imageCount = reader.ReadUInt32();
                GX2Surface.firstSlice = reader.ReadUInt32();
                GX2Surface.numSlices  = reader.ReadUInt32();
                GX2Surface.compSel    = reader.ReadBytes(4);
                GX2Surface.texRegs    = reader.ReadUInt32s(4);

                RedChannel   = GX2ChanneToGeneric((Syroot.NintenTools.Bfres.GX2.GX2CompSel)GX2Surface.compSel[0]);
                GreenChannel = GX2ChanneToGeneric((Syroot.NintenTools.Bfres.GX2.GX2CompSel)GX2Surface.compSel[1]);
                BlueChannel  = GX2ChanneToGeneric((Syroot.NintenTools.Bfres.GX2.GX2CompSel)GX2Surface.compSel[2]);
                AlphaChannel = GX2ChanneToGeneric((Syroot.NintenTools.Bfres.GX2.GX2CompSel)GX2Surface.compSel[3]);

                if (GX2Surface.numMips > 13)
                {
                    return;
                }

                Width      = GX2Surface.width;
                Height     = GX2Surface.height;
                MipCount   = GX2Surface.numMips;
                ArrayCount = GX2Surface.numArray;
                Format     = Bfres.Structs.FTEX.ConvertFromGx2Format((Syroot.NintenTools.Bfres.GX2.GX2SurfaceFormat)GX2Surface.format);
            }
Exemplo n.º 11
0
            public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
            {
                int  swizzle = (int)Swizzle;
                int  pitch   = (int)0;
                uint bpp     = GX2.surfaceGetBitsPerPixel(GX2Format) >> 3;

                GX2.GX2Surface surf = new GX2.GX2Surface();
                surf.bpp       = bpp;
                surf.height    = Height;
                surf.width     = Width;
                surf.aa        = (uint)0;
                surf.alignment = Alignment;
                surf.depth     = Depth;
                surf.dim       = 0x1;
                surf.format    = GX2Format;
                surf.use       = 0x1;
                surf.pitch     = 0;
                surf.data      = data;
                surf.numMips   = MipCount;
                surf.mipOffset = new uint[MipCount];
                surf.mipData   = null;
                surf.tileMode  = TileMode;
                surf.swizzle   = Swizzle;
                surf.imageSize = ImageSize;

                // GX2.GenerateMipSurfaceData(surf);

                foreach (var mipoffset in surf.mipOffset)
                {
                    Console.WriteLine($"mipoffset {mipoffset}");
                }

                var surfaces = GX2.Decode(surf);

                return(surfaces[ArrayLevel][MipLevel]);
            }
Exemplo n.º 12
0
            public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
            {
                uint GX2Format = (uint)GX2.GX2SurfaceFormat.T_BC5_UNORM;

                switch (SurfFormat)
                {
                case SurfaceFormat.T_BC1_UNORM:
                    GX2Format = (uint)GX2.GX2SurfaceFormat.T_BC1_UNORM;
                    Format    = TEX_FORMAT.BC1_UNORM;
                    break;

                case SurfaceFormat.T_BC1_SRGB:
                    GX2Format = (uint)GX2.GX2SurfaceFormat.T_BC1_SRGB;
                    Format    = TEX_FORMAT.BC1_UNORM_SRGB;
                    break;

                case SurfaceFormat.T_BC2_UNORM:
                    GX2Format = (uint)GX2.GX2SurfaceFormat.T_BC2_UNORM;
                    Format    = TEX_FORMAT.BC2_UNORM;
                    break;

                case SurfaceFormat.T_BC2_SRGB:
                    GX2Format = (uint)GX2.GX2SurfaceFormat.T_BC2_SRGB;
                    Format    = TEX_FORMAT.BC2_UNORM_SRGB;
                    break;

                case SurfaceFormat.T_BC3_UNORM:
                    GX2Format = (uint)GX2.GX2SurfaceFormat.T_BC3_UNORM;
                    Format    = TEX_FORMAT.BC3_UNORM;
                    break;

                case SurfaceFormat.T_BC3_SRGB:
                    GX2Format = (uint)GX2.GX2SurfaceFormat.T_BC3_SRGB;
                    Format    = TEX_FORMAT.BC3_UNORM_SRGB;
                    break;

                case SurfaceFormat.T_BC4_UNORM:
                    GX2Format = (uint)GX2.GX2SurfaceFormat.T_BC4_UNORM;
                    Format    = TEX_FORMAT.BC4_UNORM;
                    break;

                case SurfaceFormat.T_BC4_SNORM:
                    GX2Format = (uint)GX2.GX2SurfaceFormat.T_BC4_SNORM;
                    Format    = TEX_FORMAT.BC4_SNORM;
                    break;

                case SurfaceFormat.T_BC5_UNORM:
                    GX2Format = (uint)GX2.GX2SurfaceFormat.T_BC5_UNORM;
                    Format    = TEX_FORMAT.BC5_UNORM;
                    break;

                case SurfaceFormat.T_BC5_SNORM:
                    GX2Format = (uint)GX2.GX2SurfaceFormat.T_BC5_SNORM;
                    Format    = TEX_FORMAT.BC5_SNORM;
                    break;

                case SurfaceFormat.TC_R8_G8_UNORM:
                    GX2Format = (uint)GX2.GX2SurfaceFormat.TC_R8_G8_UNORM;
                    Format    = TEX_FORMAT.R8G8_UNORM;
                    break;

                case SurfaceFormat.TCS_R8_G8_B8_A8_UNORM:
                    GX2Format = (uint)GX2.GX2SurfaceFormat.TCS_R8_G8_B8_A8_UNORM;
                    Format    = TEX_FORMAT.R8G8B8A8_UNORM;
                    break;

                case SurfaceFormat.TCS_R8_G8_B8_A8:
                    GX2Format = (uint)GX2.GX2SurfaceFormat.TCS_R8_G8_B8_A8_UNORM;
                    Format    = TEX_FORMAT.R8G8B8A8_UNORM;
                    break;

                case SurfaceFormat.TC_R8_UNORM:
                    GX2Format = (uint)GX2.GX2SurfaceFormat.TC_R8_UNORM;
                    Format    = TEX_FORMAT.R8_UNORM;
                    break;

                case SurfaceFormat.TCS_R5_G6_B5_UNORM:
                    GX2Format = (uint)GX2.GX2SurfaceFormat.TCS_R5_G6_B5_UNORM;
                    Format    = TEX_FORMAT.B5G6R5_UNORM;
                    break;

                default:
                    throw new Exception("Format unsupported! " + SurfFormat);
                }


                int  swizzle = (int)Swizzle;
                int  pitch   = (int)0;
                uint bpp     = GX2.surfaceGetBitsPerPixel(GX2Format) >> 3;

                GX2.GX2Surface surf = new GX2.GX2Surface();
                surf.bpp       = bpp;
                surf.height    = Height;
                surf.width     = Width;
                surf.aa        = (uint)0;
                surf.alignment = 0;
                surf.depth     = Depth;
                surf.dim       = 0x1;
                surf.format    = GX2Format;
                surf.use       = 0x1;
                surf.pitch     = 0;
                surf.data      = data;
                surf.numMips   = 1;
                surf.mipOffset = new uint[0];
                surf.mipData   = null;
                surf.tileMode  = TileMode;
                surf.swizzle   = Swizzle;
                surf.imageSize = ImageSize;

                var surfaces = GX2.Decode(surf);

                return(surfaces[ArrayLevel][MipLevel]);
            }