示例#1
0
        // Exile ~Blood Royal 2~      : flipped == true
        // Gakuen ~Nerawareta Chitai~ : flipped == false
        private ImageData ReadV3(bool flipped)
        {
            using (var lzs = new LzssStream(m_input, LzssMode.Decompress, true))
            {
                if (8 == m_info.BPP)
                {
                    var palette_data = new byte[0x400];
                    if (palette_data.Length != lzs.Read(palette_data, 0, palette_data.Length))
                    {
                        throw new InvalidFormatException("Unexpected end of file");
                    }
                    SetPalette(palette_data);
                }
                m_image_data = new byte[m_stride * (int)m_info.Height];
                if (m_image_data.Length != lzs.Read(m_image_data, 0, m_image_data.Length))
                {
                    throw new InvalidFormatException();
                }

                if (flipped)
                {
                    return(ImageData.CreateFlipped(m_info, Format, Palette, m_image_data, m_stride));
                }
                else
                {
                    return(ImageData.Create(m_info, Format, Palette, m_image_data, m_stride));
                }
            }
        }
示例#2
0
        public ImageData Unpack()
        {
            Stream input = new StreamRegion(m_input.AsStream, 0x18, m_info.PackedLength, true);

            if (m_info.IsEncrypted)
            {
                input = new InputCryptoStream(input, new SjTransform(m_info.Key));
            }
            using (input = new LzssStream(input))
            {
                var header = new byte[0x28];
                input.Read(header, 0, header.Length);
                if (8 == m_info.BPP)
                {
                    Palette = ImageFormat.ReadPalette(input);
                }
                input.Read(m_output, 0, m_output.Length);
            }
            if (m_info.AlphaLength > 0 && m_info.BPP == 8)
            {
                m_input.Position = 0x18 + m_info.PackedLength;
                var alpha = new byte[m_info.AlphaLength];
                using (var lzss = new LzssStream(m_input.AsStream, LzssMode.Decompress, true))
                    lzss.Read(alpha, 0, alpha.Length);
                return(ApplyAlpha(alpha));
            }
            return(ImageData.CreateFlipped(m_info, Format, Palette, m_output, Stride));
        }
示例#3
0
        public override ImageData Read(IBinaryStream file, ImageMetaData info)
        {
            file.Position = 0x1B;
            int plane_size = info.iWidth * info.iHeight;
            var pixels     = new byte[plane_size * 4];

            using (var input = new LzssStream(file.AsStream, LzssMode.Decompress, true))
            {
                var plane = new byte[plane_size];
                int dst;
                for (int c = 0; c < 3; ++c)
                {
                    input.Read(plane, 0, plane_size);
                    dst = c;
                    for (int src = 0; src < plane_size; ++src)
                    {
                        pixels[dst] = plane[src];
                        dst        += 4;
                    }
                }
                // alpha channel is inverted
                input.Read(plane, 0, plane_size);
                dst = 3;
                for (int src = 0; src < plane_size; ++src)
                {
                    pixels[dst] = (byte)(0xFF - plane[src]);
                    dst        += 4;
                }
            }
            return(ImageData.CreateFlipped(info, PixelFormats.Bgra32, null, pixels, info.iWidth * 4));
        }
示例#4
0
文件: ArcGM.cs 项目: zxc120/GARbro
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            var header = arc.File.View.ReadBytes(entry.Offset, 25);

            if (header[0] < 'B' || header[0] > 'E' || header[1] != '1')
            {
                return(arc.File.CreateStream(entry.Offset, entry.Size));
            }
            if ('E' == header[0])
            {
                byte t = header[17];
                header[17] = header[23];
                header[23] = t;
                t          = header[19];
                header[19] = header[24];
                header[24] = t;
            }
            int    unpacked_size = header.ToInt32(6);
            var    data          = new byte[unpacked_size];
            Stream input         = arc.File.CreateStream(entry.Offset + header.Length, entry.Size - (uint)header.Length);

            input          = new PrefixStream(header, input);
            input.Position = 10;
            using (input = new LzssStream(input))
                input.Read(data, 0, unpacked_size);
            if (data.AsciiEqual("BPR01"))
            {
                return(new PackedStream <BprDecompressor> (Stream.Null, new BprDecompressor(data)));
            }
            else
            {
                return(new BinMemoryStream(data, entry.Name));
            }
        }
示例#5
0
        private ImageData ReadV1()
        {
            if (8 == m_info.BPP)
            {
                Palette = ImageFormat.ReadPalette(m_input);
            }

            var packed = new byte[m_info.PackedSize];

            if (packed.Length != m_input.Read(packed, 0, packed.Length))
            {
                throw new InvalidFormatException("Unexpected end of file");
            }
            for (int i = 0; i < packed.Length; ++i)
            {
                packed[i] ^= (byte)i;
            }

            using (var input = new MemoryStream(packed))
                using (var lzs = new LzssStream(input))
                {
                    m_image_data = new byte[m_info.UnpackedSize];
                    // flip pixels vertically
                    for (int dst = m_stride * (m_info.iHeight - 1); dst >= 0; dst -= m_stride)
                    {
                        lzs.Read(m_image_data, dst, m_stride);
                    }
                }
            return(ImageData.Create(m_info, Format, Palette, m_image_data, m_stride));
        }
示例#6
0
        public override ImageData Read(IBinaryStream stream, ImageMetaData info)
        {
            var meta = (HizMetaData)info;

            var pixels = new byte[meta.UnpackedSize];

            stream.Position = meta.DataOffset;
            using (var lzss = new LzssStream(stream.AsStream, LzssMode.Decompress, true))
            {
                var channel = new byte[info.Width * info.Height];
                for (int p = 0; p < 4; ++p)
                {
                    if (channel.Length != lzss.Read(channel, 0, channel.Length))
                    {
                        throw new InvalidFormatException("Unexpected end of file");
                    }
                    int src = 0;
                    for (int i = p; i < pixels.Length; i += 4)
                    {
                        pixels[i] = channel[src++];
                    }
                }
                return(ImageData.Create(info, PixelFormats.Bgra32, null, pixels));
            }
        }
示例#7
0
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            var pent = entry as PackedEntry;

            if (null == pent)
            {
                return(base.OpenEntry(arc, entry));
            }
            if (!pent.IsPacked)
            {
                if (!arc.File.View.AsciiEqual(entry.Offset, "LZS\0"))
                {
                    return(base.OpenEntry(arc, entry));
                }
                pent.IsPacked     = true;
                pent.UnpackedSize = arc.File.View.ReadUInt32(entry.Offset + 4);
            }
            var  input        = arc.File.CreateStream(entry.Offset + 8, entry.Size - 8);
            bool embedded_lzs = (input.Signature & ~0xF0u) == 0x535A4C0F; // 'LZS'
            var  lzs          = new LzssStream(input);

            if (embedded_lzs)
            {
                var header = new byte[8];
                lzs.Read(header, 0, 8);
                pent.UnpackedSize = header.ToUInt32(4);
                lzs = new LzssStream(lzs);
            }
            return(lzs);
        }
示例#8
0
 public override ImageMetaData ReadMetaData(IBinaryStream file)
 {
     using (var lzs = new LzssStream(file.AsStream, LzssMode.Decompress, true))
     {
         if (lzs.ReadByte() != 'B' || lzs.ReadByte() != 'M')
         {
             return(null);
         }
         var bmp = new byte[0x26];
         if (0x24 != lzs.Read(bmp, 2, 0x24))
         {
             return(null);
         }
         int file_size  = LittleEndian.ToInt32(bmp, 2);
         int width      = LittleEndian.ToInt32(bmp, 0x12);
         int height     = LittleEndian.ToInt32(bmp, 0x16);
         int bpp        = LittleEndian.ToInt16(bmp, 0x1C);
         int image_size = LittleEndian.ToInt32(bmp, 0x22);
         if (0 == image_size)
         {
             image_size = width * height * (bpp / 8);
         }
         return(new GrMetaData
         {
             Width = (uint)width,
             Height = (uint)height,
             BPP = bpp,
             UnpackedSize = 24 == bpp ? file_size : (image_size + 0x36),
         });
     }
 }
示例#9
0
        public override ImageData Read(IBinaryStream stream, ImageMetaData info)
        {
            int stride = (int)info.Width * 3;
            var pixels = new byte[stride * (int)info.Height];

            stream.Position = 0x24;
            using (var lz = new LzssStream(stream.AsStream, LzssMode.Decompress, true))
            {
                if (pixels.Length != lz.Read(pixels, 0, pixels.Length))
                {
                    throw new InvalidFormatException();
                }
            }
            int src = 0;

            for (int i = 3; i < stride; ++i)
            {
                pixels[i] += pixels[src++];
            }
            src = 0;
            for (int i = stride; i < pixels.Length; ++i)
            {
                pixels[i] += pixels[src++];
            }
            var meta = (MagMetaData)info;

            if (0 == meta.AlphaOffset)
            {
                return(ImageData.CreateFlipped(info, PixelFormats.Bgr24, null, pixels, stride));
            }

            stream.Position = 0x24 + meta.AlphaOffset;
            var alpha = new byte[meta.BackWidth * meta.BackHeight];

            using (var lz = new LzssStream(stream.AsStream, LzssMode.Decompress, true))
            {
                if (alpha.Length != lz.Read(alpha, 0, alpha.Length))
                {
                    throw new InvalidFormatException();
                }
            }
            int img_stride = (int)info.Width * 4;
            var img        = new byte[img_stride * (int)info.Height];
            int dst        = 0;
            int alpha_y    = meta.BackHeight - (meta.OffsetY + (int)meta.Height);

            for (int y = (int)meta.Height - 1; y >= 0; --y)
            {
                src = stride * y;
                int src_alpha = meta.BackWidth * (alpha_y + y) + meta.OffsetX;
                for (int i = 0; i < img_stride; i += 4)
                {
                    img[dst++] = pixels[src++];
                    img[dst++] = pixels[src++];
                    img[dst++] = pixels[src++];
                    img[dst++] = alpha[src_alpha++];
                }
            }
            return(ImageData.Create(info, PixelFormats.Bgra32, null, img, img_stride));
        }
示例#10
0
            bool ReadV1(Stream input)
            {
                // NOTE CryptoStream will close an input stream
                using (var xored = new CryptoStream(input, new NotTransform(), CryptoStreamMode.Read))
                    using (var lzss = new LzssStream(xored))
                        lzss.Read(m_index, 0, m_index.Length);

                int index_offset = Array.IndexOf(m_index, (byte)0);

                if (-1 == index_offset || 0 == index_offset)
                {
                    return(false);
                }
                Password = m_index.Take(index_offset++).ToArray();
                long base_offset = 0x20 + m_packed_size;

                for (int i = 0; i < m_count; ++i)
                {
                    var entry = new PackedEntry();
                    entry.Offset       = LittleEndian.ToUInt32(m_index, index_offset) + base_offset;
                    entry.Size         = LittleEndian.ToUInt32(m_index, index_offset + 4);
                    entry.UnpackedSize = LittleEndian.ToUInt32(m_index, index_offset + 8);
                    entry.IsPacked     = entry.UnpackedSize != 0;
                    if (!entry.CheckPlacement(m_file.MaxOffset))
                    {
                        return(false);
                    }
                    int name_len = LittleEndian.ToInt32(m_index, index_offset + 0xC);
                    entry.Name = Encodings.cp932.GetString(m_index, index_offset + 0x18, name_len);
                    entry.Type = FormatCatalog.Instance.GetTypeFromName(entry.Name);
                    m_dir.Value.Add(entry);
                    index_offset += 0x18 + name_len;
                }
                return(true);
            }
示例#11
0
文件: ImageCBF.cs 项目: zxc120/GARbro
        void UnpackV1()
        {
            m_input.Position = 0x18;
            using (var lzss = new LzssStream(m_input.AsStream, LzssMode.Decompress, true))
                lzss.Read(m_output, 0, m_output.Length);
            for (int i = 3; i < m_output.Length; ++i)
            {
                m_output[i] += m_output[i - 3];
            }
            var pixels  = new byte[m_output.Length];
            int src     = 0;
            var z_order = GetZigzagBlock();

            for (int y = 0; y < m_height; y += 8)
            {
                for (int x = 0; x < m_stride; x += 24)
                {
                    int dst = x + y * m_stride;
                    for (int i = 0; i < 64; ++i)
                    {
                        int pos = z_order[i];
                        pixels[dst + pos++] = m_output[src++];
                        pixels[dst + pos++] = m_output[src++];
                        pixels[dst + pos++] = m_output[src++];
                    }
                }
            }
            m_output = pixels;
        }
示例#12
0
文件: ImageAKB.cs 项目: zxc120/GARbro
        public byte[] Unpack(byte[] background = null)
        {
            if (0 == m_info.InnerWidth || 0 == m_info.InnerHeight)
            {
                return(background ?? CreateBackground());
            }

            m_input.Position = m_info.DataOffset;
            int inner_stride = m_info.InnerWidth * m_pixel_size;
            var pixels       = new byte[m_info.InnerHeight * inner_stride];

            using (var lz = new LzssStream(m_input, LzssMode.Decompress, true))
            {
                for (int pos = pixels.Length - inner_stride; pos >= 0; pos -= inner_stride)
                {
                    if (inner_stride != lz.Read(pixels, pos, inner_stride))
                    {
                        throw new InvalidFormatException();
                    }
                }
            }
            RestoreDelta(pixels, inner_stride);
            if (null == background && m_info.InnerWidth == m_info.Width && m_info.InnerHeight == m_info.Height)
            {
                return(pixels);
            }

            var    image = background ?? CreateBackground();
            int    src   = 0;
            int    dst   = m_info.OffsetY * Stride + m_info.OffsetX * m_pixel_size;
            Action blend_row;

            if (null == background)
            {
                blend_row = () => Buffer.BlockCopy(pixels, src, image, dst, inner_stride);
            }
            else
            {
                blend_row = () => {
                    for (int x = 0; x < inner_stride; x += m_pixel_size)
                    {
                        if (0x00 != pixels[src + x] || 0xFF != pixels[src + x + 1] || 0x00 != pixels[src + x + 2])
                        {
                            for (int i = 0; i < m_pixel_size; ++i)
                            {
                                image[dst + x + i] = pixels[src + x + i];
                            }
                        }
                    }
                };
            }
            for (int y = 0; y < m_info.InnerHeight; ++y)
            {
                blend_row();
                dst += Stride;
                src += inner_stride;
            }
            return(image);
        }
示例#13
0
            bool ReadV0(Stream input)
            {
                long current_offset    = 0x20 + m_packed_size;
                uint offset_table_size = (uint)m_count * 0x10;

                if (offset_table_size > m_file.View.Reserve(current_offset, offset_table_size))
                {
                    return(false);
                }

                using (var lzss = new LzssStream(input, LzssMode.Decompress, true))
                    if (m_index.Length != lzss.Read(m_index, 0, m_index.Length))
                    {
                        return(false);
                    }

                for (int i = 0; i < m_index.Length; ++i)
                {
                    m_index[i] = (byte)(~m_index[i] - 5);
                }
                int index_offset = Array.IndexOf <byte> (m_index, 0);

                if (-1 == index_offset || 0 == index_offset)
                {
                    return(false);
                }
                index_offset++;
//                Password = m_index.Take (index_offset++).ToArray();

                for (int i = 0; i < m_count && index_offset < m_index.Length; ++i)
                {
                    int name_end = Array.IndexOf <byte> (m_index, 0, index_offset);
                    if (-1 == name_end)
                    {
                        name_end = m_index.Length;
                    }
                    if (index_offset == name_end)
                    {
                        return(false);
                    }
                    var entry = new PackedEntry();
                    entry.Offset       = m_file.View.ReadUInt32(current_offset);
                    entry.Size         = m_file.View.ReadUInt32(current_offset + 4);
                    entry.UnpackedSize = m_file.View.ReadUInt32(current_offset + 8);
                    entry.IsPacked     = entry.UnpackedSize != 0;
                    if (!entry.CheckPlacement(m_file.MaxOffset))
                    {
                        return(false);
                    }
                    entry.Name = Encodings.cp932.GetString(m_index, index_offset, name_end - index_offset);
                    entry.Type = FormatCatalog.Instance.GetTypeFromName(entry.Name);
                    m_dir.Value.Add(entry);
                    index_offset    = name_end + 1;
                    current_offset += 0x10;
                }
                return(true);
            }
示例#14
0
 void UnpackLzss(byte[] packed)
 {
     using (var mem = new MemoryStream(packed))
         using (var lz = new LzssStream(mem))
             if (m_output.Length != lz.Read(m_output, 0, m_output.Length))
             {
                 throw new EndOfStreamException();
             }
 }
示例#15
0
 public override ImageData Read(IBinaryStream file, ImageMetaData info)
 {
     file.Position = 0x10;
     using (var lzss = new LzssStream(file.AsStream, LzssMode.Decompress, true))
     {
         var pixels = new byte[info.Width * info.Height];
         lzss.Read(pixels, 0, pixels.Length);
         return(ImageData.CreateFlipped(info, PixelFormats.Gray8, null, pixels, (int)info.Width));
     }
 }
示例#16
0
 public override ImageData Read(IBinaryStream file, ImageMetaData info)
 {
     file.Position = 0xE;
     using (var lz = new LzssStream(file.AsStream, LzssMode.Decompress, true))
     {
         lz.Config.FrameSize    = 0x1000;
         lz.Config.FrameFill    = 0x20;
         lz.Config.FrameInitPos = 0x1000 - 0x10;
         var meta   = (CrzMetaData)info;
         var header = new byte[meta.HeaderSize];
         lz.Read(header, 0, header.Length);
         int stride = (int)info.Width * 2;
         var pixels = new byte[stride * (int)info.Height];
         if (pixels.Length != lz.Read(pixels, 0, pixels.Length))
         {
             throw new InvalidFormatException();
         }
         return(ImageData.Create(info, PixelFormats.Bgr555, null, pixels, stride));
     }
 }
示例#17
0
文件: ArcUCG.cs 项目: ziyuejun/GARbro
 protected override ImageData GetImageData()
 {
     m_input.Position = 0x1C;
     using (var lz = new LzssStream(m_input.AsStream, LzssMode.Decompress, true))
     {
         int stride = Info.iWidth * 4;
         var pixels = new byte[stride * Info.iHeight];
         lz.Read(pixels, 0, pixels.Length);
         return(ImageData.CreateFlipped(Info, PixelFormats.Bgra32, null, pixels, stride));
     }
 }
示例#18
0
文件: ArcCG2.cs 项目: ziyuejun/GARbro
 protected override ImageData GetImageData()
 {
     using (var input = new LzssStream(m_input.AsStream, LzssMode.Decompress, true))
     {
         int stride  = (Info.iWidth + 3) & ~3;
         var palette = ImageFormat.ReadPalette(input, 0x100);
         var pixels  = new byte[stride * Info.iHeight];
         input.Read(pixels, 0, pixels.Length);
         return(ImageData.CreateFlipped(Info, PixelFormats.Indexed8, palette, pixels, stride));
     }
 }
示例#19
0
        public override ImageData Read(Stream stream, ImageMetaData info)
        {
            var meta = (EmMetaData)info;

            stream.Position = meta.DataOffset;
            BitmapPalette palette = null;

            if (meta.Colors != 0)
            {
                palette = ReadPalette(stream, Math.Max(meta.Colors, 3));
            }
            var pixels = new byte[meta.Stride * (int)info.Height];

            if (meta.LzssFrameSize != 0)
            {
                using (var lzss = new LzssStream(stream, LzssMode.Decompress, true))
                {
                    lzss.Config.FrameSize    = meta.LzssFrameSize;
                    lzss.Config.FrameInitPos = meta.LzssInitPos;
                    if (pixels.Length != lzss.Read(pixels, 0, pixels.Length))
                    {
                        throw new EndOfStreamException();
                    }
                }
            }
            else
            {
                if (pixels.Length != stream.Read(pixels, 0, pixels.Length))
                {
                    throw new EndOfStreamException();
                }
            }
            if (7 == meta.BPP)
            {
                return(ImageData.Create(info, PixelFormats.Gray8, palette, pixels, meta.Stride));
            }

            PixelFormat format;

            if (32 == meta.BPP)
            {
                format = PixelFormats.Bgr32;
            }
            else if (24 == meta.BPP)
            {
                format = PixelFormats.Bgr24;
            }
            else
            {
                format = PixelFormats.Indexed8;
            }
            return(ImageData.CreateFlipped(info, format, palette, pixels, meta.Stride));
        }
示例#20
0
        public override ImageData Read(IBinaryStream file, ImageMetaData info)
        {
            file.Position = 0x24;
            int stride = (int)info.Width * 2;
            var pixels = new byte[stride * (int)info.Height];

            using (var input = new LzssStream(file.AsStream, LzssMode.Decompress, true))
            {
                input.Read(pixels, 0, pixels.Length);
            }
            return(ImageData.CreateFlipped(info, PixelFormats.Bgr555, null, pixels, stride));
        }
示例#21
0
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            ushort signature = arc.File.View.ReadUInt16(entry.Offset);

            // C1/D1/E1/F1
            if (0x3146 != signature && 0x3143 != signature && 0x3144 != signature && 0x3145 != signature)
            {
                return(base.OpenEntry(arc, entry));
            }
            var            mkarc  = arc as MkArchive;
            ScrambleScheme scheme = mkarc != null ? mkarc.Scheme : DefaultScheme;

            uint packed_size = arc.File.View.ReadUInt32(entry.Offset + 2);

            if (packed_size < scheme.ScrambledSize || packed_size > entry.Size - 10)
            {
                return(base.OpenEntry(arc, entry));
            }

            Stream input;

            // XXX scrambling might be applicable for 'E1' signatures only
            if (scheme.ScrambledSize > 0)
            {
                var prefix = arc.File.View.ReadBytes(entry.Offset + 10, scheme.ScrambledSize);
                foreach (var pair in scheme.ScrambleMap)
                {
                    byte t = prefix[pair.Item1];
                    prefix[pair.Item1] = prefix[pair.Item2];
                    prefix[pair.Item2] = t;
                }
                input = arc.File.CreateStream(entry.Offset + 10 + scheme.ScrambledSize, packed_size - scheme.ScrambledSize);
                input = new PrefixStream(prefix, input);
            }
            else
            {
                input = arc.File.CreateStream(entry.Offset + 10, packed_size);
            }
            input = new LzssStream(input);

            var header = new byte[5];

            input.Read(header, 0, 5);
            if (Binary.AsciiEqual(header, "BPR02"))
            {
                return(new PackedStream <Bpr02Decompressor> (input));
            }
            if (Binary.AsciiEqual(header, "BPR01"))
            {
                return(new PackedStream <Bpr01Decompressor> (input));
            }
            return(new PrefixStream(header, input));
        }
示例#22
0
文件: ImageYGA.cs 项目: uboaa/GARbro
        public override ImageData Read(IBinaryStream file, ImageMetaData info)
        {
            var meta = (YgaMetaData)info;

            file.Position = 0x18;
            using (var input = new LzssStream(file.AsStream, LzssMode.Decompress, true))
            {
                var pixels = new byte[meta.UnpackedSize];
                input.Read(pixels, 0, meta.UnpackedSize);
                return(ImageData.Create(info, PixelFormats.Bgra32, null, pixels));
            }
        }
示例#23
0
 byte[] UnpackAt(long offset)
 {
     using (var toc_s = m_file.CreateStream(offset, PackedSize))
         using (var lzss = new LzssStream(toc_s))
         {
             var toc = new byte[UnpackedSize];
             if (toc.Length != lzss.Read(toc, 0, toc.Length))
             {
                 return(null);
             }
             return(toc);
         }
 }
示例#24
0
        }                                                                 // 'SZDD'

        public override ImageMetaData ReadMetaData(IBinaryStream file)
        {
            file.Position = 0xE;
            using (var lz = new LzssStream(file.AsStream, LzssMode.Decompress, true))
            {
                lz.Config.FrameSize    = 0x1000;
                lz.Config.FrameFill    = 0x20;
                lz.Config.FrameInitPos = 0x1000 - 0x10;
                var header = new byte[0x24];
                if (0x11 != lz.Read(header, 0, 0x11))
                {
                    return(null);
                }
                var key = KnownKeys.Where(x => header.AsciiEqual(x.Key)).Select(x => x.Value).FirstOrDefault();
                if (null == key)
                {
                    return(null);
                }
                var seed = new byte[0x10];
                lz.Read(seed, 0, 0x10);
                lz.Read(header, 0, 0x24);

                for (int i = 0; i < 0x24; ++i)
                {
                    header[i] ^= key[i];
                }
                for (int i = 0; i < 0x24; ++i)
                {
                    header[i] ^= seed[i & 0xF];
                }

                return(new CrzMetaData {
                    Width = header.ToUInt32(4),
                    Height = header.ToUInt32(0x10),
                    BPP = 16,
                    HeaderSize = header.ToInt32(0x18) + 0x45
                });
            }
        }
示例#25
0
        public override ImageData Read(IBinaryStream file, ImageMetaData info)
        {
            var meta   = (GpdMetaData)info;
            int stride = (int)info.Width * 3;

            file.Position = meta.HeaderSize;
            using (var lzss = new LzssStream(file.AsStream, LzssMode.Decompress, true))
            {
                var pixels = new byte[stride * (int)info.Height];
                lzss.Read(pixels, 0, pixels.Length);
                return(ImageData.CreateFlipped(info, PixelFormats.Bgr24, null, pixels, stride));
            }
        }
示例#26
0
        public override ImageData Read(IBinaryStream stream, ImageMetaData info)
        {
            stream.Position = 8;
            var pixels = new byte[info.Width * info.Height];

            using (var reader = new LzssStream(stream.AsStream, LzssMode.Decompress, true))
            {
                if (pixels.Length != reader.Read(pixels, 0, pixels.Length))
                {
                    throw new InvalidFormatException();
                }
                return(ImageData.CreateFlipped(info, PixelFormats.Gray8, null, pixels, (int)info.Width));
            }
        }
示例#27
0
 private void Unpack()
 {
     m_input.Position = 0;
     if (m_colors > 0)
     {
         Palette = ImageFormat.ReadPalette(m_input.AsStream, m_colors);
     }
     if (m_extra > 0)
     {
         m_input.Seek(10 * m_extra + 2, SeekOrigin.Current);
     }
     using (var lzss = new LzssStream(m_input.AsStream, LzssMode.Decompress, true))
         lzss.Read(m_output, 0, m_output.Length);
 }
示例#28
0
文件: ImageBIZ.cs 项目: zxc120/GARbro
 public override ImageData Read(IBinaryStream file, ImageMetaData info)
 {
     file.Position = 8;
     using (var input = new LzssStream(file.AsStream, LzssMode.Decompress, true))
     {
         int stride = (int)info.Width * 3;
         var pixels = new byte[stride * (int)info.Height];
         if (pixels.Length != input.Read(pixels, 0, pixels.Length))
         {
             throw new InvalidFormatException();
         }
         return(ImageData.CreateFlipped(info, PixelFormats.Bgr24, null, pixels, stride));
     }
 }
示例#29
0
        public override ImageData Read(IBinaryStream stream, ImageMetaData info)
        {
            var          meta = (DifMetaData)info;
            BitmapSource base_bitmap;

            using (var input = VFS.OpenBinaryStream(meta.BaseEntry))
            {
                var image = meta.BaseFormat.Read(input, meta.BaseInfo);
                base_bitmap = image.Bitmap;
            }
            stream.Position = 0x7C;
            var index = new byte[meta.IndexSize];

            using (var input = new LzssStream(stream.AsStream, LzssMode.Decompress, true))
                if (index.Length != input.Read(index, 0, index.Length))
                {
                    throw new EndOfStreamException();
                }

            if (base_bitmap.Format.BitsPerPixel != 24)
            {
                base_bitmap = new FormatConvertedBitmap(base_bitmap, PixelFormats.Bgr24, null, 0);
            }

            int src_stride = base_bitmap.PixelWidth * 3; // XXX
            int dst_stride = (src_stride + 3) & ~3;
            var pixels     = new byte[dst_stride * base_bitmap.PixelHeight];
            int row_offset = 0;
            var rect       = new Int32Rect(0, base_bitmap.PixelHeight, base_bitmap.PixelWidth, 1);

            for (rect.Y = base_bitmap.PixelHeight - 1; rect.Y >= 0; --rect.Y)
            {
                base_bitmap.CopyPixels(rect, pixels, src_stride, row_offset);
                row_offset += dst_stride;
            }

            stream.Position = 0x7C + meta.PackedIndexSize;
            using (var diff = new LzssStream(stream.AsStream, LzssMode.Decompress, true))
            {
                int index_src = 0;
                for (int i = 0; i < meta.DiffCount; ++i)
                {
                    int offset = LittleEndian.ToInt32(index, index_src);
                    int size   = LittleEndian.ToInt32(index, index_src + 4);
                    index_src += 8;
                    diff.Read(pixels, offset, size);
                }
                return(ImageData.CreateFlipped(info, PixelFormats.Bgr24, null, pixels, dst_stride));
            }
        }
示例#30
0
 protected override ImageData GetImageData()
 {
     m_input.Position = 0x10;
     using (var lz = new LzssStream(m_input.AsStream, LzssMode.Decompress, true))
     {
         int stride = (int)Info.Width * 2;
         var pixels = new byte[stride * (int)Info.Height];
         if (pixels.Length != lz.Read(pixels, 0, pixels.Length))
         {
             throw new InvalidFormatException();
         }
         return(ImageData.Create(Info, PixelFormats.Bgr565, null, pixels, stride));
     }
 }