/// <summary>
        /// Gets a <see cref="Bitmap"/> given an array and mip index.
        /// </summary>
        /// <param name="ArrayIndex">The index of the surface/array. Cubemaps will have 6</param>
        /// <param name="MipLevel">The index of the mip level.</param>
        /// <returns></returns>
        public Bitmap GetBitmap(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
        {
            uint width  = Math.Max(1, Width >> MipLevel);
            uint height = Math.Max(1, Height >> MipLevel);

            byte[] data = GetImageData(ArrayLevel, MipLevel, DepthLevel);

            data = Platform.DecodeImage(this, data, width, height, ArrayLevel, MipLevel);

            if (Platform.OutputFormat != TexFormat.RGBA8_UNORM)
            {
                data = DecodeBlock(data, width, height, Platform.OutputFormat);
            }
            else if (Platform is DefaultSwizzle || Platform is SwitchSwizzle || Platform is WiiUSwizzle)
            {
                data = ImageUtility.ConvertBgraToRgba(data);
            }

            if (data.Length == 0)
            {
                LoadOpenGLTexture();
                return(RenderableTex.ToBitmap());
            }

            if (IsBCNCompressed())
            {
                width  = ((width + 3) / 4) * 4;
                height = ((height + 3) / 4) * 4;
            }

            return(BitmapExtension.CreateBitmap(data, (int)width, (int)height));
        }
 public static byte[] DecodeBlock(byte[] data, uint width, uint height, TexFormat format)
 {
     byte[] output = new byte[0];
     foreach (var decoder in FileManager.GetTextureDecoders())
     {
         bool isDecoded = decoder.Decode(format, data, (int)width, (int)height, out output);
         if (isDecoded)
         {
             return(output != null?ImageUtility.ConvertBgraToRgba(output) : new byte[0]);
         }
     }
     return(output != null?ImageUtility.ConvertBgraToRgba(output) : new byte[0]);
 }
        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;
        }
        /// <summary>
        /// Gets a <see cref="Bitmap"/> given an array and mip index.
        /// </summary>
        /// <param name="ArrayIndex">The index of the surface/array. Cubemaps will have 6</param>
        /// <param name="MipLevel">The index of the mip level.</param>
        /// <returns></returns>
        public Bitmap GetBitmap(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
        {
            uint width  = Math.Max(1, Width >> MipLevel);
            uint height = Math.Max(1, Height >> MipLevel);

            byte[] data = GetImageData(ArrayLevel, MipLevel, DepthLevel);

            Console.WriteLine($"data {data.Length}");
            data = Platform.DecodeImage(this, data, width, height, ArrayLevel, MipLevel);
            Console.WriteLine($"data2 {data.Length}");

            Console.WriteLine($"OutputFormat {Platform.OutputFormat}");

            if (Platform.OutputFormat != TexFormat.RGBA8_UNORM)
            {
                data = DecodeBlock(data, width, height, Platform.OutputFormat);
            }
            else if (Platform is DefaultSwizzle || Platform is TegraX1Swizzle || Platform is WiiUSwizzle)
            {
                data = ImageUtility.ConvertBgraToRgba(data);
            }

            return(BitmapExtension.CreateBitmap(data, (int)width, (int)height));
        }
示例#5
0
 public static System.Drawing.Bitmap DecodeBlockToBitmap(byte[] Input, int Width, int Height, PICASurfaceFormat picaFormat)
 {
     return(BitmapExtension.CreateBitmap(ImageUtility.ConvertBgraToRgba(DecodeBlock(Input, Width, Height, picaFormat)),
                                         Width, Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb));
 }