Ejemplo n.º 1
0
        private void Parse(BinaryReader reader)
        {
            DDSStruct header = new DDSStruct();

            Utils.PixelFormat pixelFormat = Utils.PixelFormat.UNKNOWN;
            byte[]            data        = null;

            if (ReadHeader(reader, ref header))
            {
                _isValid = true;
                // patches for stuff
                if (header.depth == 0)
                {
                    header.depth = 1;
                }

                uint blocksize = 0;
                pixelFormat = GetFormat(header, ref blocksize);
                if (pixelFormat == Utils.PixelFormat.UNKNOWN)
                {
                    throw new InvalidFileHeaderException();
                }

                data = ReadData(reader, header);
                if (data != null)
                {
                    byte[] rawData = Decompressor.Expand(header, data, pixelFormat);
                    _bitmap = CreateBitmap((int)header.width, (int)header.height, rawData);
                }
            }
        }
Ejemplo n.º 2
0
        private DDSResult CreateBitmap(int width, int height, byte[] rawData)
        {
            var result = new DDSResult
            {
                Width  = width,
                Height = height,
                Data   = new Color[width * height]
            };

            for (int i = 0; i < result.Data.Length; i++)
            {
                // iterate through bytes.
                result.Data[i].R = rawData[i * 4 + 0];
                result.Data[i].G = rawData[i * 4 + 1];
                result.Data[i].B = rawData[i * 4 + 2];
                result.Data[i].A = rawData[i * 4 + 3];

                if (result.Data[i].R == 255 &&
                    result.Data[i].G == 0 &&
                    result.Data[i].B == 0 &&
                    result.Data[i].A == 255)
                {
                    result.Data[i] = Color.Transparent;
                }
            }

            return(result);
        }