public byte[] GenerateMips(int SurfaceLevel = 0)
        {
            Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight);

            if (FlipY)
            {
                Image.RotateFlip(RotateFlipType.RotateNoneFlipY);
            }

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

            for (int mipLevel = 0; mipLevel < MipCount; mipLevel++)
            {
                int MipWidth  = Math.Max(1, (int)TexWidth >> mipLevel);
                int MipHeight = Math.Max(1, (int)TexHeight >> mipLevel);

                if (mipLevel != 0)
                {
                    Image = BitmapExtension.Resize(Image, MipWidth, MipHeight);
                }

                mipmaps.Add(STGenericTexture.CompressBlock(BitmapExtension.ImageToByte(Image),
                                                           Image.Width, Image.Height, FTEX.ConvertFromGx2Format((GX2SurfaceFormat)Format), alphaRef));
            }
            Image.Dispose();

            return(Utils.CombineByteArray(mipmaps.ToArray()));
        }
        public byte[] GenerateMips(int SurfaceLevel = 0)
        {
            Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight);

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

            mipmaps.Add(FTEX.CompressBlock(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight, Format));

            //while (Image.Width / 2 > 0 && Image.Height / 2 > 0)
            //      for (int mipLevel = 0; mipLevel < MipCount; mipLevel++)
            int width  = Image.Width;
            int height = Image.Height;

            for (int mipLevel = 0; mipLevel < MipCount; mipLevel++)
            {
                if (Image.Width != 1)
                {
                    width = Image.Width / 2;
                }
                if (Image.Height != 1)
                {
                    height = Image.Height / 2;
                }

                Image = BitmapExtension.Resize(Image, width, height);
                mipmaps.Add(FTEX.CompressBlock(BitmapExtension.ImageToByte(Image), Image.Width, Image.Height, Format));
            }
            Image.Dispose();

            return(Utils.CombineByteArray(mipmaps.ToArray()));
        }
Example #3
0
        public byte[] GenerateMips(STCompressionMode CompressionMode, int SurfaceLevel = 0)
        {
            Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight);

            if (GammaFix)
            {
                Image = BitmapExtension.AdjustGamma(Image, 2.2f);
            }

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

            for (int mipLevel = 0; mipLevel < MipCount; mipLevel++)
            {
                int MipWidth  = Math.Max(1, (int)TexWidth >> mipLevel);
                int MipHeight = Math.Max(1, (int)TexHeight >> mipLevel);

                if (mipLevel != 0)
                {
                    Image = BitmapExtension.Resize(Image, MipWidth, MipHeight);
                }

                mipmaps.Add(STGenericTexture.CompressBlock(BitmapExtension.ImageToByte(Image),
                                                           Image.Width, Image.Height, TextureData.ConvertFormat(Format), alphaRef, CompressionMode));
            }
            Image.Dispose();

            return(Utils.CombineByteArray(mipmaps.ToArray()));
        }
        public List <byte[]> GenerateMipList(int SurfaceLevel = 0)
        {
            Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight);

            if (FlipY)
            {
                Image.RotateFlip(RotateFlipType.RotateNoneFlipY);
            }
            if (UseBc4Alpha && (Format == GX2.GX2SurfaceFormat.T_BC4_UNORM || Format == GX2.GX2SurfaceFormat.T_BC4_SNORM))
            {
                Image = BitmapExtension.SetChannel(Image, STChannelType.Alpha, STChannelType.Alpha, STChannelType.Alpha, STChannelType.One);
            }

            Console.WriteLine($"FlipY {FlipY}");

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

            for (int mipLevel = 0; mipLevel < MipCount; mipLevel++)
            {
                int MipWidth  = Math.Max(1, (int)TexWidth >> mipLevel);
                int MipHeight = Math.Max(1, (int)TexHeight >> mipLevel);

                if (mipLevel != 0)
                {
                    Image = BitmapExtension.Resize(Image, MipWidth, MipHeight);
                }

                mipmaps.Add(STGenericTexture.CompressBlock(BitmapExtension.ImageToByte(Image),
                                                           Image.Width, Image.Height, FTEX.ConvertFromGx2Format((GX2SurfaceFormat)Format), alphaRef));
            }
            Image.Dispose();

            return(mipmaps);
        }
        public void LoadBitMap(string FileName, BntxFile bntxFile)
        {
            DecompressedData.Clear();

            TexName         = Path.GetFileNameWithoutExtension(FileName);
            bntx            = bntxFile;
            Format          = SurfaceFormat.BC1_SRGB;
            GenerateMipmaps = true;

            Bitmap Image = new Bitmap(FileName);

            Image = TextureData.SwapBlueRedChannels(Image);

            TexWidth  = (uint)Image.Width;
            TexHeight = (uint)Image.Height;
            MipCount  = (uint)GetTotalMipCount();

            DecompressedData.Add(BitmapExtension.ImageToByte(Image));

            Image.Dispose();
            if (DecompressedData.Count == 0)
            {
                throw new Exception("Failed to load " + Format);
            }
        }
Example #6
0
        public Tuple <List <byte[]>, ushort[]> GenerateMipList(int SurfaceLevel = 0)
        {
            Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight);

            ushort[] paletteData = new ushort[0];

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

            for (int mipLevel = 0; mipLevel < MipCount; mipLevel++)
            {
                int MipWidth  = Math.Max(1, (int)TexWidth >> mipLevel);
                int MipHeight = Math.Max(1, (int)TexHeight >> mipLevel);

                if (mipLevel != 0)
                {
                    Image = BitmapExtension.Resize(Image, MipWidth, MipHeight);
                }

                var EncodedData = Decode_Gamecube.EncodeData(BitmapExtension.ImageToByte(Image), Format, PaletteFormat, MipWidth, MipHeight);

                mipmaps.Add(EncodedData.Item1);

                if (mipLevel == 0) //Set palette data once
                {
                    paletteData = EncodedData.Item2;
                }
            }
            Image.Dispose();

            return(Tuple.Create(mipmaps, paletteData));
        }
Example #7
0
        public byte[] GenerateMips(int SurfaceLevel = 0)
        {
            Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight);

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

            mipmaps.Add(STGenericTexture.CompressBlock(DecompressedData[SurfaceLevel],
                                                       (int)TexWidth, (int)TexHeight, TextureData.ConvertFormat(Format), alphaRef));

            //while (Image.Width / 2 > 0 && Image.Height / 2 > 0)
            //      for (int mipLevel = 0; mipLevel < MipCount; mipLevel++)
            for (int mipLevel = 0; mipLevel < MipCount; mipLevel++)
            {
                int width  = Image.Width / 2;
                int height = Image.Height / 2;
                if (width <= 0)
                {
                    width = 1;
                }
                if (height <= 0)
                {
                    height = 1;
                }

                Image = BitmapExtension.Resize(Image, width, height);
                mipmaps.Add(STGenericTexture.CompressBlock(BitmapExtension.ImageToByte(Image),
                                                           Image.Width, Image.Height, TextureData.ConvertFormat(Format), alphaRef));
            }
            Image.Dispose();

            return(Utils.CombineByteArray(mipmaps.ToArray()));
        }
Example #8
0
        public List <byte[]> GenerateMipList(STCompressionMode CompressionMode, bool multiThread, bool bc4Alpha, int SurfaceLevel = 0)
        {
            Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight);

            if (GammaFix)
            {
                Image = BitmapExtension.AdjustGamma(Image, 2.2f);
            }
            if (bc4Alpha)
            {
                Image = BitmapExtension.SetChannel(Image, STChannelType.Alpha, STChannelType.Alpha, STChannelType.Alpha, STChannelType.Alpha);
            }

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

            for (int mipLevel = 0; mipLevel < MipCount; mipLevel++)
            {
                int MipWidth  = Math.Max(1, (int)TexWidth >> mipLevel);
                int MipHeight = Math.Max(1, (int)TexHeight >> mipLevel);

                if (mipLevel != 0)
                {
                    Image = BitmapExtension.Resize(Image, MipWidth, MipHeight);
                }

                mipmaps.Add(STGenericTexture.CompressBlock(BitmapExtension.ImageToByte(Image),
                                                           Image.Width, Image.Height, TextureData.ConvertFormat(Format), alphaRef, multiThread, CompressionMode));
            }
            Image.Dispose();

            return(mipmaps);
        }
Example #9
0
        public void LoadTGA(string FileName, BntxFile bntxFile)
        {
            DecompressedData.Clear();

            TexName    = Path.GetFileNameWithoutExtension(FileName);
            bntx       = bntxFile;
            Format     = TEX_FORMAT.BC1;
            FormatType = TEX_FORMAT_TYPE.SRGB;

            GenerateMipmaps = true;

            Bitmap Image = Paloma.TargaImage.LoadTargaImage(FileName);

            Image = STGenericTexture.SwapBlueRedChannels(Image);

            TexWidth  = (uint)Image.Width;
            TexHeight = (uint)Image.Height;
            MipCount  = (uint)GetTotalMipCount();

            DecompressedData.Add(BitmapExtension.ImageToByte(Image));

            Image.Dispose();
            if (DecompressedData.Count == 0)
            {
                throw new Exception("Failed to load " + Format);
            }
        }
Example #10
0
        private void LoadImage(Bitmap Image)
        {
            TexWidth  = (uint)Image.Width;
            TexHeight = (uint)Image.Height;
            MipCount  = (uint)STGenericTexture.GenerateTotalMipCount(TexWidth, TexHeight);

            DecompressedData.Add(BitmapExtension.ImageToByte(Image));

            Image.Dispose();
            if (DecompressedData.Count == 0)
            {
                throw new Exception("Failed to load " + Format);
            }
        }
        private void LoadImage(Bitmap Image)
        {
            Image = BitmapExtension.SwapBlueRedChannels(Image);

            TexWidth  = (uint)Image.Width;
            TexHeight = (uint)Image.Height;
            MipCount  = (uint)GetTotalMipCount();

            DecompressedData.Add(BitmapExtension.ImageToByte(Image));

            Image.Dispose();
            if (DecompressedData.Count == 0)
            {
                throw new Exception("Failed to load " + Format);
            }
        }
Example #12
0
        public ImportedTexture(string fileName)
        {
            Name           = Path.GetFileNameWithoutExtension(fileName);
            SourceFilePath = fileName;
            TargetOutput   = TexFormat.RGBA8_UNORM;

            var bitmap = new Bitmap(SourceFilePath);

            Width  = bitmap.Width;
            Height = bitmap.Height;

            var rgbaImage = BitmapExtension.SwapBlueRedChannels(bitmap);

            rgba = BitmapExtension.ImageToByte(rgbaImage);

            bitmap.Dispose();
        }
Example #13
0
        public List <byte[]> GenerateMipList(int SurfaceLevel = 0)
        {
            Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight);

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

            mipmaps.Add(CTR_3DS.EncodeBlock(DecompressedData[SurfaceLevel],
                                            (int)TexWidth, (int)TexHeight, Format));

            for (int mipLevel = 0; mipLevel < MipCount; mipLevel++)
            {
                int width  = Image.Width / 2;
                int height = Image.Width / 2;
                if (Format == CTR_3DS.PICASurfaceFormat.ETC1 || Format == CTR_3DS.PICASurfaceFormat.ETC1A4)
                {
                    if (width < 16)
                    {
                        break;
                    }
                    if (height < 16)
                    {
                        break;
                    }
                }
                else
                {
                    if (width < 8)
                    {
                        break;
                    }
                    if (height < 8)
                    {
                        break;
                    }
                }

                Image = BitmapExtension.Resize(Image, width, height);
                mipmaps.Add(CTR_3DS.EncodeBlock(BitmapExtension.ImageToByte(Image),
                                                Image.Width, Image.Height, Format));
            }
            Image.Dispose();

            return(mipmaps);
        }
        private void LoadBitmap(Bitmap bitmap, bool swapBlueRed = true)
        {
            if (bitmap.PixelFormat != System.Drawing.Imaging.PixelFormat.Format32bppArgb)
            {
                bitmap = BitmapExtension.ToArgb32(bitmap);
            }

            Name      = FileInfo != null ? FileInfo.FileName : "bitmap";
            ImageData = BitmapExtension.ImageToByte(bitmap);
            if (swapBlueRed)
            {
                ImageData = ImageUtility.ConvertBgraToRgba(ImageData);
            }
            Width  = (uint)bitmap.Width;
            Height = (uint)bitmap.Height;
            Platform.OutputFormat = TexFormat.RGBA8_UNORM;
            MipCount = 1;
            CanEdit  = true;
        }
        public byte[] GenerateMips(int SurfaceLevel = 0)
        {
            Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight);

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

            mipmaps.Add(STGenericTexture.CompressBlock(DecompressedData[SurfaceLevel],
                                                       (int)TexWidth, (int)TexHeight, FTEX.ConvertFromGx2Format((GX2SurfaceFormat)Format), alphaRef));

            //while (Image.Width / 2 > 0 && Image.Height / 2 > 0)
            //      for (int mipLevel = 0; mipLevel < MipCount; mipLevel++)
            for (int mipLevel = 0; mipLevel < MipCount; mipLevel++)
            {
                Image = BitmapExtension.Resize(Image, Image.Width / 2, Image.Height / 2);
                mipmaps.Add(STGenericTexture.CompressBlock(BitmapExtension.ImageToByte(Image),
                                                           Image.Width, Image.Height, FTEX.ConvertFromGx2Format((GX2SurfaceFormat)Format), alphaRef));
            }
            Image.Dispose();

            return(Utils.CombineByteArray(mipmaps.ToArray()));
        }
Example #16
0
        private void LoadImage(Bitmap Image)
        {
            Image = BitmapExtension.SwapBlueRedChannels(Image);

            TexWidth  = (uint)Image.Width;
            TexHeight = (uint)Image.Height;
            MipCount  = (uint)GetTotalMipCount();

            if (TexWidth != Image.Width || TexHeight != Image.Height)
            {
                Image = BitmapExtension.Resize(Image, TexWidth, TexHeight);
            }

            DecompressedData.Add(STGenericTexture.ConvertBgraToRgba(BitmapExtension.ImageToByte(Image)));

            Image.Dispose();
            if (DecompressedData.Count == 0)
            {
                throw new Exception("Failed to load " + Format);
            }
        }
        public void LoadBitMap(string FileName, BntxFile bntxFile, TextureData tree = null)
        {
            TexName     = Path.GetFileNameWithoutExtension(FileName);
            bntx        = bntxFile;
            textureData = tree;
            Format      = SurfaceFormat.R8_G8_B8_A8_SRGB;

            Bitmap Image = new Bitmap(FileName);

            TexWidth  = (uint)Image.Width;
            TexHeight = (uint)Image.Height;
            MipCount  = 1;

            DataBlockOutput = BitmapExtension.ImageToByte(Image);

            Image.Dispose();

            if (DataBlockOutput.Length == 0)
            {
                throw new Exception("Failed to load " + Format);
            }
        }
        public List <byte[]> GenerateMipList(STCompressionMode CompressionMode, bool multiThread, int SurfaceLevel = 0)
        {
            Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight);

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

            for (int mipLevel = 0; mipLevel < MipCount; mipLevel++)
            {
                int MipWidth  = Math.Max(1, (int)TexWidth >> mipLevel);
                int MipHeight = Math.Max(1, (int)TexHeight >> mipLevel);

                if (mipLevel != 0)
                {
                    Image = BitmapExtension.Resize(Image, MipWidth, MipHeight);
                }

                mipmaps.Add(STGenericTexture.CompressBlock(BitmapExtension.ImageToByte(Image),
                                                           Image.Width, Image.Height, Format, alphaRef, multiThread, CompressionMode));
            }
            Image.Dispose();

            return(mipmaps);
        }
        public List <byte[]> GenerateMipList(int SurfaceLevel = 0)
        {
            MipCount = 1;

            Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight);

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

            mipmaps.Add(CTR_3DS.EncodeBlock(DecompressedData[SurfaceLevel],
                                            (int)TexWidth, (int)TexHeight, Format));

            //while (Image.Width / 2 > 0 && Image.Height / 2 > 0)
            //      for (int mipLevel = 0; mipLevel < MipCount; mipLevel++)
            for (int mipLevel = 0; mipLevel < MipCount; mipLevel++)
            {
                Image = BitmapExtension.Resize(Image, Image.Width / 2, Image.Height / 2);
                mipmaps.Add(CTR_3DS.EncodeBlock(BitmapExtension.ImageToByte(Image),
                                                Image.Width, Image.Height, Format));
            }
            Image.Dispose();

            return(mipmaps);
        }
Example #20
0
        private void UpdateImage()
        {
            if (activeTexture == null)
            {
                return;
            }

            Thread = new Thread((ThreadStart)(() =>
            {
                pictureBoxCustom1.Image = Imaging.GetLoadingImage();
                var image = activeTexture.GetBitmap(0, 0);

                var mipmaps = STGenericTexture.CompressBlock(BitmapExtension.ImageToByte(activeImage),
                                                             activeImage.Width, activeImage.Height, Format, 0.5f);

                newImage = BitmapExtension.SwapBlueRedChannels(STGenericTexture.DecodeBlockGetBitmap(mipmaps, (uint)image.Width, (uint)image.Height, Format));

                pictureBoxCustom1.Image = newImage;
            }));
            Thread.Start();


            pictureBoxCustom1.Image = newImage;
        }
 public static unsafe uint GetChecksum(Bitmap image)
 {
     return(GetChecksum(BitmapExtension.ImageToByte(image)));
 }