Ejemplo n.º 1
0
 public override ImageData Read(IBinaryStream stream, ImageMetaData info)
 {
     using (var reader = new SbiReader(stream, (SbiMetaData)info))
     {
         reader.Unpack();
         return(ImageData.Create(info, reader.Format, reader.Palette, reader.Data, reader.Stride));
     }
 }
Ejemplo n.º 2
0
        public override ImageData Read(IBinaryStream stream, ImageMetaData info)
        {
            var meta = (MfcMetaData)info;
            // XXX implemented like in reference code, width is expected to be even.
            var alpha = new byte[info.Width * info.Height / 2];

            stream.Position = 0x18;
            RleUnpack(stream.AsStream, meta.AlphaSize - 0x18, alpha);
            byte[] pixels;
            using (var reg = new StreamRegion(stream.AsStream, meta.AlphaSize, true))
                using (var sbi = new BinaryStream(reg, stream.Name))
                    using (var reader = new SbiReader(sbi, meta.BaseInfo))
                    {
                        reader.Unpack();
                        if (meta.BaseInfo.BPP != 32)
                        {
                            var bitmap = BitmapSource.Create((int)info.Width, (int)info.Height, ImageData.DefaultDpiX, ImageData.DefaultDpiY,
                                                             reader.Format, reader.Palette, reader.Data, reader.Stride);
                            bitmap = new FormatConvertedBitmap(bitmap, PixelFormats.Bgra32, null, 0);
                            int stride = (int)info.Width * 4;
                            pixels = new byte[stride * (int)info.Height];
                            bitmap.CopyPixels(pixels, stride, 0);
                        }
                        else
                        {
                            pixels = reader.Data;
                        }
                    }
            using (var mem = new MemoryStream(alpha))
                using (var bits = new LsbBitStream(mem))
                {
                    for (int i = 3; i < pixels.Length; i += 4)
                    {
                        pixels[i] = (byte)(bits.GetBits(4) * 0x11);
                    }
                }
            return(ImageData.Create(info, PixelFormats.Bgra32, null, pixels));
        }