Ejemplo n.º 1
0
 protected bool Equals(DdsPixelFormat other)
 {
     return(Size == other.Size &&
            Flags == other.Flags &&
            FourCc == other.FourCc &&
            RgbBitCount == other.RgbBitCount &&
            RBitMask == other.RBitMask &&
            GBitMask == other.GBitMask &&
            BBitMask == other.BBitMask &&
            ABitMask == other.ABitMask);
 }
Ejemplo n.º 2
0
        private static DdsPixelFormat DdsPfDx(int fourCc)
        {
            DdsPixelFormat pixelFormat = new DdsPixelFormat
            {
                Size   = DefaultSize,
                Flags  = DdsPixelFormatFlag.FourCc,
                FourCc = fourCc
            };

            return(pixelFormat);
        }
Ejemplo n.º 3
0
        public static byte[] ConvertData(byte[] sourceBuffer, int height, int width, DxgiFormat dxgiFormat)
        {
            if (sourceBuffer == null)
            {
                return(null);
            }

            var inputStream = new MemoryStream(sourceBuffer);

            byte[] targetBuffer  = new byte[sourceBuffer.Length];
            byte[] blockBuffer   = new byte[64];
            int    heightBlock   = height / 4;
            int    widthBlock    = width / 4;
            int    bytesPerPixel = DdsPixelFormat.DxgiToBytesPerPixel(dxgiFormat) * 2;

            for (int y = 0; y < heightBlock; y++)
            {
                for (int x = 0; x < widthBlock; x++)
                {
                    int mx = x;
                    int my = y;
                    if (widthBlock > 1 && heightBlock > 1)
                    {
                        MapBlockPosition(x, y, widthBlock, 2, out mx, out my);
                    }

                    if (widthBlock > 2 && heightBlock > 2)
                    {
                        MapBlockPosition(mx, my, widthBlock, 4, out mx, out my);
                    }

                    if (widthBlock > 4 && heightBlock > 4)
                    {
                        MapBlockPosition(mx, my, widthBlock, 8, out mx, out my);
                    }

                    inputStream.Read(blockBuffer, 0, bytesPerPixel);
                    int destinationIndex = bytesPerPixel * (my * widthBlock + mx);
                    Array.Copy(blockBuffer, 0, targetBuffer, destinationIndex, bytesPerPixel);
                }
            }

            return(targetBuffer);
        }