コード例 #1
0
        public List <Bitmap> GetBitmaps()
        {
            List <Bitmap> list = new List <Bitmap>();

            for (uint depth = 0; depth < TXM.Depth; ++depth)
            {
                Data.Position = 0;
                Stream plane = TXM.GetSinglePlane(Data, depth);
                switch (TXM.Format)
                {
                case TextureFormat.DXT1a:
                case TextureFormat.DXT1b:
                case TextureFormat.DXT5a:
                case TextureFormat.DXT5b: {
                    plane.Position = 0;
                    DDSHeader header = DDSHeader.Generate(TXM.Width, TXM.Height, TXM.Mipmaps, (TXM.Format == TextureFormat.DXT1a || TXM.Format == TextureFormat.DXT1b) ? Textures.TextureFormat.DXT1a : Textures.TextureFormat.DXT5);
                    list.Add(new DDS(header, plane).ConvertToBitmap());
                }
                break;

                default:
                    for (uint mip = 0; mip < TXM.Mipmaps; ++mip)
                    {
                        (uint width, uint height, IPixelOrderIterator pxit, IColorFetchingIterator colit) = GenerateIterators(plane, mip);
                        var bmp = colit.ConvertToBitmap(pxit, width, height);
                        list.Add(bmp);
                    }
                    break;
                }
            }

            return(list);
        }
コード例 #2
0
        // TODO: Duplicated code between GetBitmaps() and GetDiskWritableStreams()..
        public List <Bitmap> GetBitmaps()
        {
            List <Bitmap> list = new List <Bitmap>();

            for (uint depth = 0; depth < TXM.Depth; ++depth)
            {
                Data.Position = 0;
                Stream plane = TXM.GetSinglePlane(Data, depth);
                switch (TXM.Format)
                {
                case TextureFormat.DXT1a:
                case TextureFormat.DXT1b:
                case TextureFormat.DXT5a:
                case TextureFormat.DXT5b: {
                    plane.Position = 0;
                    DDSHeader header = DDSHeader.Generate(TXM.Width, TXM.Height, TXM.Mipmaps, (TXM.Format == TextureFormat.DXT1a || TXM.Format == TextureFormat.DXT1b) ? Textures.TextureFormat.DXT1 : Textures.TextureFormat.DXT5);
                    list.Add(new DDS(header, plane).ConvertToBitmap());
                }
                break;

                case TextureFormat.ARGBa:
                case TextureFormat.ARGBb:
                    for (uint mip = 0; mip < TXM.Mipmaps; ++mip)
                    {
                        var dims = TXM.GetDimensions((int)mip);
                        IPixelOrderIterator pxit;
                        if (TXM.Format == TextureFormat.ARGBa)
                        {
                            pxit = new ARGBaPixelOrderIterator((int)dims.width, (int)dims.height);
                        }
                        else
                        {
                            pxit = new LinearPixelOrderIterator((int)dims.width, (int)dims.height);
                        }
                        var bmp = new ColorFetcherARGB8888(plane, dims.width, dims.height).ConvertToBitmap(pxit, dims.width, dims.height);
                        list.Add(bmp);
                    }
                    break;

                default:
                    throw new Exception("Unhandled texture format " + TXM.Format);
                }
            }

            return(list);
        }
コード例 #3
0
        public List <(string name, Stream data)> Decode()
        {
            List <(string name, Stream data)> list = new List <(string name, Stream data)>();

            if (TXM is TXMSingleCubemap)
            {
                Console.WriteLine();
            }

            for (uint depth = 0; depth < TXM.Depth; ++depth)
            {
                Data.Position = 0;
                Stream plane = TXM.GetSinglePlane(Data, depth);
                switch (TXM.Format)
                {
                case TextureFormat.DXT1a:
                case TextureFormat.DXT1b:
                case TextureFormat.DXT5a:
                case TextureFormat.DXT5b: {
                    plane.Position = 0;
                    Stream stream = new MemoryStream((int)(plane.Length + 0x80));
                    stream.Write(Textures.DDSHeader.Generate(TXM.Width, TXM.Height, TXM.Mipmaps, (TXM.Format == TextureFormat.DXT1a || TXM.Format == TextureFormat.DXT1b) ? Textures.TextureFormat.DXT1 : Textures.TextureFormat.DXT5));
                    Util.CopyStream(plane, stream, plane.Length);
                    string name = TXM.Name + (TXM.Depth > 1 ? ("_Plane" + depth) : "") + ".dds";
                    list.Add((name, stream));
                }
                break;

                case TextureFormat.ARGBb:
                    for (uint mip = 0; mip < TXM.Mipmaps; ++mip)
                    {
                        var    dims   = TXM.GetDimensions((int)mip);
                        Stream stream = new ColorFetcherARGB8888(plane, dims.width, dims.height).WriteSingleImageToPngStream(new LinearPixelOrderIterator((int)dims.width, (int)dims.height), dims.width, dims.height);
                        string name   = TXM.Name + (TXM.Depth > 1 ? ("_Plane" + depth) : "") + (TXM.Mipmaps > 1 ? ("_Mip" + mip) : "") + ".png";
                        list.Add((name, stream));
                    }
                    break;

                default:
                    throw new Exception("Unhandled texture format " + TXM.Format);
                }
            }

            return(list);
        }