Ejemplo 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);
                }
            }
Ejemplo n.º 2
0
            public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
            {
                if (Gx2HeaderData != null)
                {
                    var surfaces = GX2.Decode(Gx2HeaderData);
                    return(surfaces[ArrayLevel][MipLevel]);
                }
                else
                {
                    uint DataOffset = 0;
                    for (byte arrayLevel = 0; arrayLevel < ArrayCount; ++arrayLevel)
                    {
                        for (byte mipLevel = 0; mipLevel < MipCount; ++mipLevel)
                        {
                            if (ArrayLevel == arrayLevel && MipLevel == mipLevel)
                            {
                                return(Utils.SubArray(Data, DataOffset, ImageSizes[mipLevel]));
                            }
                            else
                            {
                                DataOffset += ImageSizes[mipLevel];
                            }
                        }
                    }

                    return(null);
                }
            }
Ejemplo n.º 3
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]);
        }
Ejemplo n.º 4
0
            public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
            {
                RedChannel   = SetChannel(surface.compSel[0]);
                GreenChannel = SetChannel(surface.compSel[1]);
                BlueChannel  = SetChannel(surface.compSel[2]);
                AlphaChannel = SetChannel(surface.compSel[3]);


                Console.WriteLine("");
                Console.WriteLine("// ----- GX2Surface Info ----- ");
                Console.WriteLine("  dim             = " + surface.dim);
                Console.WriteLine("  width           = " + surface.width);
                Console.WriteLine("  height          = " + surface.height);
                Console.WriteLine("  depth           = " + surface.depth);
                Console.WriteLine("  numMips         = " + surface.numMips);
                Console.WriteLine("  format          = " + surface.format);
                Console.WriteLine("  aa              = " + surface.aa);
                Console.WriteLine("  use             = " + surface.use);
                Console.WriteLine("  imageSize       = " + surface.imageSize);
                Console.WriteLine("  mipSize         = " + surface.mipSize);
                Console.WriteLine("  tileMode        = " + surface.tileMode);
                Console.WriteLine("  swizzle         = " + surface.swizzle);
                Console.WriteLine("  alignment       = " + surface.alignment);
                Console.WriteLine("  pitch           = " + surface.pitch);
                Console.WriteLine("  bits per pixel  = " + (surface.bpp << 3));
                Console.WriteLine("  bytes per pixel = " + surface.bpp);
                Console.WriteLine("  data size       = " + surface.data.Length);
                Console.WriteLine("  mip size        = " + surface.mipData.Length);
                Console.WriteLine("  realSize        = " + surface.imageSize);

                return(GX2.Decode(surface, ArrayLevel, MipLevel));
            }
Ejemplo 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));
            }
Ejemplo 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));
        }
Ejemplo n.º 7
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));
            }
        }
Ejemplo n.º 8
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]);
        }
Ejemplo n.º 9
0
        public override void SetImageData(Bitmap bitmap, int ArrayLevel)
        {
            if (bitmap == null)
            {
                return; //Image is likely disposed and not needed to be applied
            }
            texture.Format = ConvertToGx2Format(Format);
            texture.Width  = (uint)bitmap.Width;
            texture.Height = (uint)bitmap.Height;
            uint swizzle = (texture.Swizzle >> 8) & 7;

            if (MipCount != 1)
            {
                MipCount = GenerateMipCount(bitmap.Width, bitmap.Height);
                if (MipCount == 0)
                {
                    MipCount = 1;
                }
            }

            texture.MipCount   = MipCount;
            texture.MipOffsets = new uint[MipCount];

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

                bitmap.Dispose();

                //Swizzle and create surface
                var surface = GX2.CreateGx2Texture(data, Text,
                                                   (uint)texture.TileMode,
                                                   (uint)texture.AAMode,
                                                   (uint)texture.Width,
                                                   (uint)texture.Height,
                                                   (uint)texture.Depth,
                                                   (uint)texture.Format,
                                                   (uint)swizzle,
                                                   (uint)texture.Dim,
                                                   (uint)texture.MipCount
                                                   );

                var tex = FromGx2Surface(surface, texture.Name);
                UpdateTex(tex);

                IsEdited = true;
                Read(texture);
                LoadOpenGLTexture();
                LibraryGUI.UpdateViewport();
            }
            catch (Exception ex)
            {
                STErrorDialog.Show("Failed to swizzle and compress image " + Text, "Error", ex.ToString());
            }
        }
Ejemplo n.º 10
0
            public override void SetImageData(Bitmap bitmap, int ArrayLevel)
            {
                if (bitmap == null)
                {
                    return; //Image is likely disposed and not needed to be applied
                }
                RedChannel   = SetChannel(surface.compSel[0]);
                GreenChannel = SetChannel(surface.compSel[1]);
                BlueChannel  = SetChannel(surface.compSel[2]);
                AlphaChannel = SetChannel(surface.compSel[3]);

                surface.format = (uint)FTEX.ConvertToGx2Format(Format);
                surface.width  = (uint)bitmap.Width;
                surface.height = (uint)bitmap.Height;

                if (MipCount != 1)
                {
                    MipCount = GenerateMipCount(bitmap.Width, bitmap.Height);
                    if (MipCount == 0)
                    {
                        MipCount = 1;
                    }
                }

                surface.numMips   = MipCount;
                surface.mipOffset = new uint[MipCount];

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

                    //Swizzle and create surface
                    var NewSurface = GX2.CreateGx2Texture(data, Text,
                                                          (uint)surface.tileMode,
                                                          (uint)surface.aa,
                                                          (uint)surface.width,
                                                          (uint)surface.height,
                                                          (uint)surface.depth,
                                                          (uint)surface.format,
                                                          (uint)surface.swizzle,
                                                          (uint)surface.dim,
                                                          (uint)surface.numMips
                                                          );

                    ApplySurface(NewSurface);
                    IsEdited = true;
                    LoadOpenGLTexture();
                    LibraryGUI.Instance.UpdateViewport();
                }
                catch (Exception ex)
                {
                    STErrorDialog.Show("Failed to swizzle and compress image " + Text, "Error", ex.ToString());
                }
            }
Ejemplo n.º 11
0
 /// <inheritdoc />
 public override int GetHashCode()
 {
     unchecked {
         int hashCode = ParticipantId.GetHashCode();
         hashCode = (hashCode * 397) ^ GX1.GetHashCode();
         hashCode = (hashCode * 397) ^ X1V.GetHashCode();
         hashCode = (hashCode * 397) ^ X1R.GetHashCode();
         hashCode = (hashCode * 397) ^ GX2.GetHashCode();
         hashCode = (hashCode * 397) ^ X2V.GetHashCode();
         hashCode = (hashCode * 397) ^ X2R.GetHashCode();
         return(hashCode);
     }
 }
Ejemplo n.º 12
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));
 }
Ejemplo n.º 13
0
            public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
            {
                if (GX2Surface != null)
                {
                    GX2Surface.data    = ImageData;
                    GX2Surface.mipData = ImageData;

                    return(GX2.Decode(GX2Surface, ArrayLevel, MipLevel));
                }
                else
                {
                    return(ImageData);
                }
            }
Ejemplo n.º 14
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 Gx2Format = FTEX.ConvertToGx2Format(Format);

            uint swizzle = (image.Swizzle >> 8) & 7;

            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)swizzle,
                                                   (uint)1,
                                                   (uint)MipCount
                                                   );

                image.Swizzle     = surface.swizzle;
                image.BflimFormat = FormatsWiiU.FirstOrDefault(x => x.Value == Format).Key;
                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());
            }
        }
Ejemplo n.º 15
0
            public override void Replace(string FileName)
            {
                FTEX ftex = new FTEX();

                ftex.ReplaceTexture(FileName, Format);
                if (ftex.texture != null)
                {
                    surface.swizzle    = ftex.texture.Swizzle;
                    surface.tileMode   = (uint)ftex.texture.TileMode;
                    surface.format     = (uint)ftex.texture.Format;
                    surface.aa         = (uint)ftex.texture.AAMode;
                    surface.use        = (uint)ftex.texture.Use;
                    surface.alignment  = (uint)ftex.texture.Alignment;
                    surface.dim        = (uint)ftex.texture.Dim;
                    surface.width      = (uint)ftex.texture.Width;
                    surface.height     = (uint)ftex.texture.Height;
                    surface.depth      = (uint)ftex.texture.Depth;
                    surface.numMips    = (uint)ftex.texture.MipCount;
                    surface.imageSize  = (uint)ftex.texture.Data.Length;
                    surface.mipSize    = (uint)ftex.texture.MipData.Length;
                    surface.data       = ftex.texture.Data;
                    surface.mipData    = ftex.texture.MipData;
                    surface.mipOffset  = ftex.texture.MipOffsets;
                    surface.firstMip   = ftex.texture.ViewMipFirst;
                    surface.firstSlice = 0;
                    surface.numSlices  = ftex.texture.ArrayLength;
                    surface.imageCount = ftex.texture.MipCount;
                    surface.pitch      = ftex.texture.Pitch;
                    surface.texRegs    = GX2.CreateRegisters(surface);

                    SetChannelComponents();

                    Format     = FTEX.ConvertFromGx2Format((Syroot.NintenTools.Bfres.GX2.GX2SurfaceFormat)surface.format);
                    Width      = surface.width;
                    Height     = surface.height;
                    MipCount   = surface.numMips;
                    ArrayCount = surface.depth;

                    ImageEditorBase editor = (ImageEditorBase)LibraryGUI.GetActiveContent(typeof(ImageEditorBase));

                    if (editor != null)
                    {
                        UpdateEditor();
                    }
                }
            }
Ejemplo n.º 16
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));
        }
Ejemplo n.º 17
0
 /// <inheritdoc />
 public bool Equals(ECJpakeRound1 other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return
         (String.Equals(ParticipantId, other.ParticipantId, StringComparison.Ordinal) &&
          GX1.SequenceEqualShortCircuiting(other.GX1) && X1V.SequenceEqualShortCircuiting(other.X1V) &&
          X1R.SequenceEqualShortCircuiting(other.X1R) &&
          GX2.SequenceEqualShortCircuiting(other.GX2) && X2V.SequenceEqualShortCircuiting(other.X2V) &&
          X2R.SequenceEqualShortCircuiting(other.X2R));
 }
Ejemplo n.º 18
0
        public override void SetImageData(Bitmap bitmap, int ArrayLevel)
        {
            if (bitmap == null)
            {
                return; //Image is likely disposed and not needed to be applied
            }
            uint Gx2Format = (uint)Bfres.Structs.FTEX.ConvertToGx2Format(Format);

            Width  = (uint)bitmap.Width;
            Height = (uint)bitmap.Height;

            MipCount = 1;
            uint[] MipOffsets = new uint[MipCount];

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

                //Swizzle and create surface
                var surface = GX2.CreateGx2Texture(data, Text,
                                                   (uint)2,
                                                   (uint)0,
                                                   (uint)Width,
                                                   (uint)Height,
                                                   (uint)1,
                                                   (uint)Gx2Format,
                                                   (uint)Swizzle,
                                                   (uint)1,
                                                   (uint)MipCount
                                                   );

                TextureTGLP.Format      = (ushort)ConvertToGx2(Format);
                TextureTGLP.SheetHeight = (ushort)surface.height;
                TextureTGLP.SheetWidth  = (ushort)surface.width;
                TextureTGLP.SheetDataList[SheetIndex] = surface.data;

                IsEdited = true;
                UpdateEditor();
            }
            catch (Exception ex)
            {
                STErrorDialog.Show("Failed to swizzle and compress image " + Text, "Error", ex.ToString());
            }
        }
Ejemplo n.º 19
0
        public byte[] EncodeImage(STGenericTexture texture, byte[] data, uint width, uint height, int array, int mip)
        {
            //Swizzle and create surface
            var NewSurface = GX2.CreateGx2Texture(data, "",
                                                  (uint)TileMode,
                                                  (uint)AAMode,
                                                  (uint)width,
                                                  (uint)height,
                                                  (uint)1,
                                                  (uint)Format,
                                                  (uint)0,
                                                  (uint)SurfaceDimension,
                                                  (uint)texture.MipCount
                                                  );

            MipData = NewSurface.mipData;
            return(NewSurface.data);
        }
Ejemplo n.º 20
0
        public static Texture AddTexture(string name, List <byte[]> images, int width, int height, int mipCount, GX2SurfaceFormat format)
        {
            Texture tex = null;

            //Go through each texture as an array or depth surface
            List <byte[]> imageData = new List <byte[]>();
            List <byte[]> mipData   = new List <byte[]>();

            for (int i = 0; i < images.Count; i++)
            {
                //Swizzle and create surface
                var surface = GX2.CreateGx2Texture(images[i], name,
                                                   (uint)GX2TileMode.Mode2dTiledThin1,
                                                   (uint)GX2AAMode.Mode1X,
                                                   (uint)width,
                                                   (uint)height,
                                                   (uint)1,
                                                   (uint)format,
                                                   (uint)0,
                                                   (uint)GX2SurfaceDim.Dim2D,
                                                   (uint)mipCount
                                                   );

                //Apply first surface
                if (i == 0)
                {
                    tex = FromGx2Surface(surface, name);
                }

                imageData.Add(surface.data);
                mipData.Add(surface.mipData);
            }

            tex.Data        = Utils.CombineByteArray(imageData.ToArray());
            tex.MipData     = Utils.CombineByteArray(mipData.ToArray());
            tex.ArrayLength = (uint)images.Count;
            imageData.Clear();
            mipData.Clear();
            return(tex);
        }
Ejemplo n.º 21
0
        //For tex2
        public static void GenerateMipmaps(uint mipCount, TEX_FORMAT Format, Bitmap bitmap, Texture texture)
        {
            if (bitmap == null)
            {
                return; //Image is likely disposed and not needed to be applied
            }
            Console.WriteLine(texture.Name + " mipCount " + mipCount);
            texture.MipCount   = mipCount;
            texture.MipOffsets = new uint[mipCount];

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

                bitmap.Dispose();

                //Swizzle and create surface
                var surface = GX2.CreateGx2Texture(data, texture.Name,
                                                   (uint)texture.TileMode,
                                                   (uint)texture.AAMode,
                                                   (uint)texture.Width,
                                                   (uint)texture.Height,
                                                   (uint)texture.Depth,
                                                   (uint)texture.Format,
                                                   (uint)texture.Swizzle,
                                                   (uint)texture.Dim,
                                                   (uint)texture.MipCount
                                                   );

                var tex = FromGx2Surface(surface, texture.Name);
                texture.MipData    = tex.MipData;
                texture.MipOffsets = tex.MipOffsets;
                texture.MipCount   = tex.MipCount;
            }
            catch (Exception ex)
            {
                STErrorDialog.Show("Failed to swizzle and compress image " + texture.Name, "Error", ex.ToString());
            }
        }
Ejemplo n.º 22
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]);
            }
Ejemplo n.º 23
0
        private void ReadGx2(FileReader reader)
        {
            reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;

            header = new GTXHeader();
            header.Read(reader);

            Console.WriteLine("header size " + header.HeaderSize);

            uint surfBlockType;
            uint dataBlockType;
            uint mipBlockType;
            uint vertexShaderHeader    = 0x03;
            uint vertexShaderProgram   = 0x05;
            uint pixelShaderHeader     = 0x06;
            uint pixelShaderProgram    = 0x07;
            uint geometryShaderHeader  = 0x08;
            uint geometryShaderProgram = 0x09;
            uint userDataBlock         = 0x10;

            if (header.MajorVersion == 6 && header.MinorVersion == 0)
            {
                surfBlockType = 0x0A;
                dataBlockType = 0x0B;
                mipBlockType  = 0x0C;
            }
            else if (header.MajorVersion == 6 || header.MajorVersion == 7)
            {
                surfBlockType = 0x0B;
                dataBlockType = 0x0C;
                mipBlockType  = 0x0D;
            }
            else
            {
                throw new Exception($"Unsupported GTX version {header.MajorVersion}");
            }

            if (header.GpuVersion != 2)
            {
                throw new Exception($"Unsupported GPU version {header.GpuVersion}");
            }

            reader.Position = header.HeaderSize;

            bool blockB = false;
            bool blockC = false;

            uint ImageInfo = 0;
            uint images    = 0;

            while (reader.Position < reader.BaseStream.Length)
            {
                Console.WriteLine("BLOCK POS " + reader.Position + " " + reader.BaseStream.Length);
                GTXDataBlock block = new GTXDataBlock();
                block.Read(reader);
                blocks.Add(block);

                bool BlockIsEmpty = block.BlockType == BlockType.AlignData ||
                                    block.BlockType == BlockType.EndOfFile;

                //Here we use "if" instead of "case" statements as types vary between versions
                if ((uint)block.BlockType == surfBlockType)
                {
                    ImageInfo += 1;
                    blockB     = true;

                    var surface = new SurfaceInfoParse();
                    surface.Read(new FileReader(block.data));

                    if (surface.tileMode == 0 || surface.tileMode > 16)
                    {
                        throw new Exception($"Invalid tileMode {surface.tileMode}!");
                    }

                    if (surface.numMips > 14)
                    {
                        throw new Exception($"Invalid number of mip maps {surface.numMips}!");
                    }

                    TextureData textureData = new TextureData();
                    textureData.surface    = surface;
                    textureData.MipCount   = surface.numMips;
                    textureData.ArrayCount = surface.depth;
                    textureData.Text       = "Texture" + ImageInfo;
                    Nodes.Add(textureData);
                    textures.Add(textureData);
                }
                else if ((uint)block.BlockType == dataBlockType)
                {
                    images += 1;
                    blockC  = true;

                    data.Add(block.data);
                }
                else if ((uint)block.BlockType == mipBlockType)
                {
                    mipMaps.Add(block.data);
                }
                else if ((uint)block.BlockType == vertexShaderHeader)
                {
                    Nodes.Add(new BlockDisplay(block.data)
                    {
                        Text = "Vertex Shader Header"
                    });
                }
                else if ((uint)block.BlockType == vertexShaderProgram)
                {
                    Nodes.Add(new BlockDisplay(block.data)
                    {
                        Text = "Vertex Shader Program"
                    });
                }
                else if ((uint)block.BlockType == pixelShaderHeader)
                {
                    Nodes.Add(new BlockDisplay(block.data)
                    {
                        Text = "Pixel Shader Header"
                    });
                }
                else if ((uint)block.BlockType == pixelShaderProgram)
                {
                    Nodes.Add(new BlockDisplay(block.data)
                    {
                        Text = "Pixel Shader Program"
                    });
                }
                else if ((uint)block.BlockType == geometryShaderHeader)
                {
                    Nodes.Add(new BlockDisplay(block.data)
                    {
                        Text = "Geometry Shader Header"
                    });
                }
                else if ((uint)block.BlockType == geometryShaderProgram)
                {
                    Nodes.Add(new BlockDisplay(block.data)
                    {
                        Text = "Geometry Shader Program"
                    });
                }
                else if (!BlockIsEmpty)
                {
                    Nodes.Add(new BlockDisplay(block.data)
                    {
                        Text = $"Block Type {block.BlockType.ToString("X")}"
                    });
                }
            }
            if (textures.Count != data.Count)
            {
                throw new Exception($"Bad size! {textures.Count} {data.Count}");
            }

            int curTex = 0;
            int curMip = 0;

            foreach (var node in Nodes)
            {
                if (node is TextureData)
                {
                    TextureData tex = (TextureData)node;

                    tex.surface.data = data[curTex];
                    tex.surface.bpp  = GX2.surfaceGetBitsPerPixel(tex.surface.format) >> 3;
                    tex.Format       = FTEX.ConvertFromGx2Format((Syroot.NintenTools.Bfres.GX2.GX2SurfaceFormat)tex.surface.format);
                    tex.Width        = tex.surface.width;
                    tex.Height       = tex.surface.height;

                    if (tex.surface.numMips > 1)
                    {
                        tex.surface.mipData = mipMaps[curMip++];
                    }
                    else
                    {
                        tex.surface.mipData = new byte[0];
                    }

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

                    curTex++;
                }
            }
        }
Ejemplo n.º 24
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]);
            }