示例#1
0
文件: ImageGCP.cs 项目: zxc120/GARbro
        public override ImageData Read(IBinaryStream stream, ImageMetaData info)
        {
            var meta = (GcpMetaData)info;

            stream.Position = 12;
            var reader = new CmpReader(stream.AsStream, meta.PackedSize, meta.DataSize);

            reader.Unpack();
            // 24bpp bitmaps have non-standard stride
            if (24 == meta.BPP && 0 != (meta.Width & 3) &&
                (meta.Height * meta.Width * 3 + 54) == meta.DataSize)
            {
                int stride = (int)meta.Width * 3;
                var pixels = new byte[stride * (int)meta.Height];
                Buffer.BlockCopy(reader.Data, 54, pixels, 0, pixels.Length);
                return(ImageData.CreateFlipped(meta, PixelFormats.Bgr24, null, pixels, stride));
            }
            using (var bmp = new MemoryStream(reader.Data))
            {
                var decoder = new BmpBitmapDecoder(bmp,
                                                   BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                BitmapSource frame = decoder.Frames[0];
                frame.Freeze();
                return(new ImageData(frame, info));
            }
        }
示例#2
0
文件: ImageGCP.cs 项目: zxc120/GARbro
        public override ImageMetaData ReadMetaData(IBinaryStream stream)
        {
            var header    = stream.ReadHeader(12);
            int data_size = header.ToInt32(4);
            int pack_size = header.ToInt32(8);

            if (data_size < 54)
            {
                return(null);
            }
            var reader = new CmpReader(stream.AsStream, pack_size, 0x22);  // BMP header

            reader.Unpack();
            var bmp = reader.Data;

            if (bmp[0] != 'B' || bmp[1] != 'M')
            {
                return(null);
            }
            int width  = LittleEndian.ToInt32(bmp, 0x12);
            int height = LittleEndian.ToInt32(bmp, 0x16);
            int bpp    = LittleEndian.ToInt16(bmp, 0x1c);

            return(new GcpMetaData
            {
                Width = (uint)width,
                Height = (uint)height,
                BPP = bpp,
                DataSize = data_size,
                PackedSize = pack_size,
            });
        }
示例#3
0
        public override ImageData Read(IBinaryStream stream, ImageMetaData info)
        {
            var meta = (GcpMetaData)info;

            stream.Position = 12;
            var reader = new CmpReader(stream.AsStream, meta.PackedSize, meta.DataSize);

            reader.Unpack();
            using (var bmp = new MemoryStream(reader.Data))
            {
                var decoder = new BmpBitmapDecoder(bmp,
                                                   BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                BitmapSource frame = decoder.Frames[0];
                frame.Freeze();
                return(new ImageData(frame, info));
            }
        }
示例#4
0
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            var pentry = entry as PackedEntry;

            if (null == pentry || !pentry.IsPacked ||
                !arc.File.View.AsciiEqual(entry.Offset, "CMP1"))
            {
                return(arc.File.CreateStream(entry.Offset, entry.Size));
            }
            int unpacked_size = arc.File.View.ReadInt32(entry.Offset + 4);

            using (var input = arc.File.CreateStream(entry.Offset + 12, entry.Size - 12))
            {
                var reader = new CmpReader(input, (int)entry.Size, unpacked_size);
                reader.Unpack();
                return(new BinMemoryStream(reader.Data, entry.Name));
            }
        }
示例#5
0
        public override ImageData Read(Stream stream, ImageMetaData info)
        {
            var meta = info as GcpMetaData;

            if (null == meta)
            {
                throw new ArgumentException("GcpFormat.Read should be supplied with GcpMetaData", "info");
            }

            stream.Position = 12;
            var reader = new CmpReader(stream, meta.PackedSize, meta.DataSize);

            reader.Unpack();
            using (var bmp = new MemoryStream(reader.Data, false))
            {
                var decoder = new BmpBitmapDecoder(bmp,
                                                   BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                BitmapSource frame = decoder.Frames[0];
                frame.Freeze();
                return(new ImageData(frame, info));
            }
        }