示例#1
0
        public override ImageData Read(IBinaryStream stream, ImageMetaData info)
        {
            if (stream.Length > int.MaxValue)
            {
                throw new FileSizeException();
            }
            var header       = stream.ReadHeader(14);
            int data_length  = header.ToInt32(10);
            int input_length = (int)(stream.Length - stream.Position);

            using (var lz = new LzssReader(stream.AsStream, input_length, data_length))
            {
                lz.FrameSize    = 0x1000;
                lz.FrameFill    = 0x20;
                lz.FrameInitPos = 0x1000 - 0x10;
                lz.Unpack();
                var data  = lz.Data;
                int count = Math.Min(100, data.Length);
                for (int i = 0; i < count; ++i)
                {
                    data[i] ^= 0xff;
                }
                using (var bmp = new BinMemoryStream(data, stream.Name))
                    return(Bmp.Read(bmp, info));
            }
        }
示例#2
0
文件: ImageLZS.cs 项目: zxc120/GARbro
        public override ImageData Read(IBinaryStream file, ImageMetaData info)
        {
            var meta = (LzsMetaData)info;

            using (var input = OpenLzss(file, meta.UnpackedSize, meta.IsCompressed))
                return(Bmp.Read(input, info));
        }
示例#3
0
        public override ImageData Read(IBinaryStream stream, ImageMetaData info)
        {
            var meta = (YkgMetaData)info;

            switch (meta.Format)
            {
            case YkgImage.Bmp:
                using (var reg = new StreamRegion(stream.AsStream, meta.DataOffset, meta.DataSize, true))
                    using (var bmp = new BinaryStream(reg, stream.Name))
                        return(Bmp.Read(bmp, info));

            case YkgImage.Png:
                using (var reg = new StreamRegion(stream.AsStream, meta.DataOffset, meta.DataSize, true))
                    using (var png = new BinaryStream(reg, stream.Name))
                        return(Png.Read(png, info));

            case YkgImage.Gnp:
                using (var body = new StreamRegion(stream.AsStream, meta.DataOffset + 4, meta.DataSize - 4, true))
                    using (var pre = new PrefixStream(PngPrefix, body))
                        using (var png = new BinaryStream(pre, stream.Name))
                            return(Png.Read(png, info));

            default:
                throw new InvalidFormatException();
            }
        }
示例#4
0
        public override ImageData Read(Stream stream, ImageMetaData info)
        {
            var meta = info as YkgMetaData;

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

            switch (meta.Format)
            {
            case YkgImage.Bmp:
                using (var bmp = new StreamRegion(stream, meta.DataOffset, meta.DataSize, true))
                    return(Bmp.Read(bmp, info));

            case YkgImage.Png:
                using (var png = new StreamRegion(stream, meta.DataOffset, meta.DataSize, true))
                    return(Png.Read(png, info));

            case YkgImage.Gnp:
                using (var body = new StreamRegion(stream, meta.DataOffset + 4, meta.DataSize - 4, true))
                    using (var png = new PrefixStream(PngPrefix, body))
                        return(Png.Read(png, info));

            default:
                throw new InvalidFormatException();
            }
        }
示例#5
0
        public override ImageData Read(IBinaryStream file, ImageMetaData info)
        {
            var meta = (IkeMetaData)info;

            using (var bmp = IkeReader.CreateStream(file, meta.UnpackedSize))
                return(Bmp.Read(bmp, info));
        }
示例#6
0
文件: ImageMGR.cs 项目: zxc120/GARbro
        public override ImageData Read(IBinaryStream stream, ImageMetaData info)
        {
            var meta = (MgrMetaData)info;

            stream.Position = meta.Offset;
            var data = new byte[meta.UnpackedSize];

            if (data.Length != MgrOpener.Decompress(stream.AsStream, data))
            {
                throw new InvalidFormatException();
            }
            if (meta.BPP != 32)
            {
                using (var bmp = new BinMemoryStream(data, stream.Name))
                    return(Bmp.Read(bmp, info));
            }
            // special case for 32bpp bitmaps with alpha-channel
            int stride = (int)meta.Width * 4;
            var pixels = new byte[stride * (int)meta.Height];
            int src    = LittleEndian.ToInt32(data, 0xA);

            for (int dst = stride * ((int)meta.Height - 1); dst >= 0; dst -= stride)
            {
                Buffer.BlockCopy(data, src, pixels, dst, stride);
                src += stride;
            }
            return(ImageData.Create(info, PixelFormats.Bgra32, null, pixels));
        }
示例#7
0
文件: ImagePMP.cs 项目: zxc120/GARbro
 public override ImageData Read(IBinaryStream stream, ImageMetaData info)
 {
     using (var input = new XoredStream(stream.AsStream, 0x21, true))
         using (var zstream = new ZLibStream(input, CompressionMode.Decompress))
             using (var bmp = new BinaryStream(zstream, stream.Name))
                 return(Bmp.Read(bmp, info));
 }
示例#8
0
文件: ImageK2.cs 项目: zxc120/GARbro
        public override ImageData Read(IBinaryStream file, ImageMetaData info)
        {
            var bmp_data = Decompress(file);

            using (var bmp = new BinMemoryStream(bmp_data))
                return(Bmp.Read(bmp, info));
        }
示例#9
0
 public override ImageData Read(IBinaryStream file, ImageMetaData info)
 {
     file.Seek(8, SeekOrigin.Current);
     using (var zstream = new ZLibStream(file.AsStream, CompressionMode.Decompress, true))
         using (var input = new SeekableStream(zstream))
             using (var bmp = new BinaryStream(input, file.Name))
                 return(Bmp.Read(bmp, info));
 }
示例#10
0
        public override ImageData Read(IBinaryStream stream, ImageMetaData info)
        {
            var meta = (NNNNMetaData)info;

            using (var lzss = meta.Input.UnpackStream())
                using (var bmp = new BinaryStream(lzss, stream.Name))
                    return(Bmp.Read(bmp, meta.BmpInfo));
        }
示例#11
0
        public override ImageData Read(IBinaryStream file, ImageMetaData info)
        {
            var gps = (GpsMetaData)info;

            file.Position = gps.HeaderSize;
            using (var stream = OpenGpsStream(file, gps.Compression, gps.UnpackedSize))
                using (var input = BinaryStream.FromStream(stream, file.Name))
                    return(Bmp.Read(input, info));
        }
示例#12
0
        public override ImageData Read(IBinaryStream file, ImageMetaData info)
        {
            int unpacked_size = (int)file.Signature;

            file.Position = 4;
            var unpacked = Decompress(file, unpacked_size);

            using (var bmp = new BinMemoryStream(unpacked, file.Name))
                return(Bmp.Read(bmp, info));
        }
示例#13
0
        public override ImageData Read(IBinaryStream file, ImageMetaData info)
        {
            var meta = (BmpMetaData)info;
            var data = new byte[meta.ImageLength];

            file.Position = 8;
            Unpack(file, data);
            using (var bmp = new BinMemoryStream(data))
                return(Bmp.Read(bmp, info));
        }
示例#14
0
        public override ImageData Read(IBinaryStream file, ImageMetaData info)
        {
            var meta = (YpMetaData)info;

            file.Position = 8;
            var data = LzUnpack(file, meta.UnpackedSize);

            using (var bmp = new BinMemoryStream(data, file.Name))
                return(Bmp.Read(bmp, info));
        }
示例#15
0
文件: ImageDAT.cs 项目: zxc120/GARbro
        public override ImageData Read(IBinaryStream file, ImageMetaData info)
        {
            var meta = (MinkMetaData)info;

            file.Position = 9;
            var pixels = new byte[meta.UnpackedSize];

            Unpack(file, pixels);
            using (var bmp = new BinMemoryStream(pixels, file.Name))
                return(Bmp.Read(bmp, info));
        }
示例#16
0
        public override ImageData Read(IBinaryStream stream, ImageMetaData info)
        {
            var meta = (ZbmMetaData)info;
            var data = new byte[meta.UnpackedSize];

            stream.Position = meta.DataOffset;
            Unpack(stream.AsStream, data);
            Decrypt(data);
            using (var bmp = new BinMemoryStream(data, stream.Name))
                return(Bmp.Read(bmp, info));
        }
示例#17
0
        public override ImageData Read(IBinaryStream file, ImageMetaData info)
        {
            var meta = (ExpMetaData)info;

            file.Position = 0x28;
            var reader   = new ExpReader(file, meta.BitmapFileName);
            var bmp_data = reader.Unpack(meta.BitmapSize);

            using (var mem_bmp = new BinMemoryStream(bmp_data, file.Name))
                return(Bmp.Read(mem_bmp, info));
        }
示例#18
0
        public override ImageData Read(IBinaryStream stream, ImageMetaData info)
        {
            var meta = (EgnMetaData)info;

            stream.Position = meta.DataOffset;
            var reader = new Reader(stream, meta.UnpackedSize, meta.Mode, meta.Flag);

            reader.Unpack();
            using (var bmp = new BinMemoryStream(reader.Data, stream.Name))
                return(Bmp.Read(bmp, info));
        }
示例#19
0
 public override ImageData Read(IBinaryStream stream, ImageMetaData info)
 {
     stream.Position = 0x0e;
     using (var lz = new LzssStream(stream.AsStream, LzssMode.Decompress, true))
     {
         lz.Config.FrameSize    = 0x1000;
         lz.Config.FrameFill    = 0x20;
         lz.Config.FrameInitPos = 0x1000 - 0x10;
         using (var bmp = new BinaryStream(lz, stream.Name))
             return(Bmp.Read(bmp, info));
     }
 }
示例#20
0
        public override ImageData Read(IBinaryStream stream, ImageMetaData info)
        {
            uint length = (uint)(stream.Length - 0x38);
            var  image  = new byte[length + 0x38];

            stream.Read(image, 0, 0x10);
            stream.Read(image, 0xE, (int)length + 0x28);
            if (24 == info.BPP && length + 2 == info.Width * info.Height * 3)
            {
                image[image.Length - 2] = 0xFF;
                image[image.Length - 1] = 0xFF;
                length += 2;
            }
            LittleEndian.Pack(length + 0x36, image, 2);
            using (var bmp = new BinMemoryStream(image, stream.Name))
                return(Bmp.Read(bmp, info));
        }
示例#21
0
文件: ImageNCL.cs 项目: zxc120/GARbro
        public override ImageData Read(IBinaryStream file, ImageMetaData info)
        {
            ImageData base_img;

            using (var input = new StreamRegion(file.AsStream, 0x24, true))
                using (var bmp = new BinaryStream(input, file.Name))
                {
                    var bmp_info = Bmp.ReadMetaData(bmp) as BmpMetaData;
                    if (null == bmp_info)
                    {
                        throw new InvalidFormatException();
                    }
                    bmp.Position  = 0;
                    base_img      = Bmp.Read(bmp, bmp_info);
                    file.Position = 0x24 + bmp_info.ImageLength;
                    if (file.PeekByte() == -1)
                    {
                        return(base_img);
                    }
                }
            using (var input = new StreamRegion(file.AsStream, file.Position, true))
                using (var bmp = new BinaryStream(input, file.Name))
                {
                    var bmp_info = Bmp.ReadMetaData(bmp) as BmpMetaData;
                    if (null == bmp_info)
                    {
                        return(base_img);
                    }
                    bmp.Position = 0;
                    var alpha_img = Bmp.Read(bmp, bmp_info);
                    var alpha_bmp = new FormatConvertedBitmap(alpha_img.Bitmap, PixelFormats.Gray8, null, 0);
                    var alpha     = new byte[alpha_bmp.PixelWidth * alpha_bmp.PixelHeight];
                    alpha_bmp.CopyPixels(alpha, alpha_bmp.PixelWidth, 0);

                    var base_bmp = new FormatConvertedBitmap(base_img.Bitmap, PixelFormats.Bgr32, null, 0);
                    int stride   = base_bmp.PixelWidth * 4;
                    var pixels   = new byte[stride * base_bmp.PixelHeight];
                    base_bmp.CopyPixels(pixels, stride, 0);
                    int asrc = 0;
                    for (int dst = 3; dst < pixels.Length; dst += 4)
                    {
                        pixels[dst] = alpha[asrc++];
                    }
                    return(ImageData.Create(info, PixelFormats.Bgra32, null, pixels, stride));
                }
        }
示例#22
0
        public override ImageData Read(IBinaryStream file, ImageMetaData info)
        {
            var meta = (FgMetaData)info;

            using (var input = new StreamRegion(file.AsStream, meta.DataOffset, meta.DataLength, true))
                using (var bmp = new BinaryStream(input, file.Name))
                {
                    var bmp_info = Bmp.ReadMetaData(bmp);
                    if (null == bmp_info)
                    {
                        throw new InvalidFormatException();
                    }
                    bmp.Position     = 0;
                    bmp_info.OffsetX = meta.OffsetX;
                    bmp_info.OffsetY = meta.OffsetY;
                    return(Bmp.Read(bmp, bmp_info));
                }
        }
示例#23
0
文件: ImageIAF.cs 项目: zxc120/GARbro
        public override ImageData Read(IBinaryStream stream, ImageMetaData info)
        {
            var meta = (IafMetaData)info;

            stream.Position = meta.DataOffset;
            var bitmap = UnpackBitmap(stream.AsStream, meta.PackType, meta.PackedSize, meta.UnpackedSize);

            if ('C' == bitmap[0])
            {
                bitmap[0] = (byte)'B';
                if (info.BPP > 8)
                {
                    bitmap = ConvertCM(bitmap, (int)info.Width, (int)info.Height, info.BPP);
                }
            }
            if (info.BPP >= 24) // currently alpha channel could be applied to 24+bpp bitmaps only
            {
                try
                {
                    int bmp_size = LittleEndian.ToInt32(bitmap, 2);
                    if (bitmap.Length - bmp_size > 0x36) // size of bmp header
                    {
                        if ('B' == bitmap[bmp_size] && 'M' == bitmap[bmp_size + 1] &&
                            8 == bitmap[bmp_size + 0x1c]) // 8bpp
                        {
                            uint alpha_width  = LittleEndian.ToUInt32(bitmap, bmp_size + 0x12);
                            uint alpha_height = LittleEndian.ToUInt32(bitmap, bmp_size + 0x16);
                            if (info.Width == alpha_width && info.Height == alpha_height)
                            {
                                return(BitmapWithAlphaChannel(info, bitmap, bmp_size));
                            }
                        }
                    }
                }
                catch
                {
                    // ignore any errors occured during alpha-channel read attempt,
                    // fallback to a plain bitmap
                }
            }
            using (var bmp = new BinMemoryStream(bitmap, stream.Name))
                return(Bmp.Read(bmp, info));
        }
示例#24
0
文件: ImageGR.cs 项目: zxc120/GARbro
        public override ImageData Read(IBinaryStream file, ImageMetaData info)
        {
            var meta = (GrMetaData)info;

            using (var lzs = new LzssStream(file.AsStream, LzssMode.Decompress, true))
                using (var bmp = new BinaryStream(lzs, file.Name))
                {
                    if (32 != info.BPP)
                    {
                        return(Bmp.Read(bmp, info));
                    }
                    int stride = (int)info.Width * 4;
                    var pixels = new byte[Math.Max(0x36, stride * info.Height)];
                    bmp.Read(pixels, 0, 0x36); // skip header
                    for (int y = (int)info.Height - 1; y >= 0; --y)
                    {
                        int dst = y * stride;
                        bmp.Read(pixels, dst, stride);
                    }
                    return(ImageData.Create(info, PixelFormats.Bgra32, null, pixels));
                }
        }
示例#25
0
文件: ImagePBM.cs 项目: uboaa/GARbro
 public override ImageData Read(IBinaryStream file, ImageMetaData info)
 {
     using (var bmp = OpenBitmapStream(file, file.Signature))
         return(Bmp.Read(bmp, info));
 }
示例#26
0
文件: ImageGRD.cs 项目: zxc120/GARbro
 public override ImageData Read(IBinaryStream stream, ImageMetaData info)
 {
     using (var bmp = DecompressStream(stream))
         return(Bmp.Read(bmp, info));
 }
示例#27
0
 public override ImageData Read(IBinaryStream file, ImageMetaData info)
 {
     using (var input = OpenGamStream(file))
         return(Bmp.Read(input, info));
 }
示例#28
0
文件: ImageMB.cs 项目: zxc120/GARbro
 public override ImageData Read(IBinaryStream stream, ImageMetaData info)
 {
     using (var bmp = OpenAsBitmap(stream))
         return(Bmp.Read(bmp, info));
 }
示例#29
0
 public override ImageData Read(IBinaryStream file, ImageMetaData info)
 {
     using (var bmp = DeobfuscateStream(file))
         return(Bmp.Read(bmp, info));
 }
示例#30
0
文件: ImageGRA.cs 项目: zxc120/GARbro
 public override ImageData Read(IBinaryStream file, ImageMetaData info)
 {
     file.Position = 0x20;
     using (var bmp = UnpackStream(file))
         return(Bmp.Read(bmp, info));
 }