Ejemplo n.º 1
0
        }                                                               // 'YGP'

        public override ImageMetaData ReadMetaData(IBinaryStream stream)
        {
            stream.Position = 4;
            int  mask_pos = stream.ReadUInt16();        // 04
            byte type     = stream.ReadUInt8();         // 06

            if (type != 1 && type != 2)
            {
                return(null);
            }
            var info = new YgpMetaData {
                Type = type, BPP = 32
            };

            info.Flags = stream.ReadUInt8();            // 07
            int header_size = stream.ReadInt32();       // 08

            stream.Position = header_size;
            info.DataSize   = stream.ReadInt32();       // XX+00
            info.Width      = stream.ReadUInt16();      // XX+04
            info.Height     = stream.ReadUInt16();      // XX+06
            info.DataOffset = header_size + 8;
            if (0 != (info.Flags & 4))
            {
                stream.Position = 0x14;
                info.OffsetX    = stream.ReadInt16();
                info.OffsetY    = stream.ReadInt16();
            }
            return(info);
        }
Ejemplo n.º 2
0
            void UpdateRepeatCount(Dictionary <uint, int> rows_count)
            {
                m_input.Position = 4;
                int count  = m_input.ReadInt32();
                var frames = new List <uint> (count);

                for (int i = 0; i < count; ++i)
                {
                    var offset = m_input.ReadUInt32();
                    if (0 != offset)
                    {
                        frames.Add(offset);
                    }
                }
                foreach (var offset in frames)
                {
                    if (offset + 0x14 == m_origin)
                    {
                        continue;
                    }
                    m_input.Position = offset + 4;
                    int height = m_input.ReadInt32();
                    m_input.Position = offset + 0x14;
                    for (int i = 0; i < height; ++i)
                    {
                        var row_offset = m_input.ReadUInt32();
                        if (rows_count.ContainsKey(row_offset))
                        {
                            ++rows_count[row_offset];
                        }
                    }
                }
            }
Ejemplo n.º 3
0
        void UnpackRle(int dst, int pixel_size)
        {
            int remaining = m_input.ReadInt32();

            while (remaining > 0)
            {
                int count = m_input.ReadInt8();
                --remaining;
                if (count >= 0)
                {
                    for (int i = 0; i <= count; ++i)
                    {
                        m_output[dst] = m_input.ReadUInt8();
                        --remaining;
                        dst += pixel_size;
                    }
                }
                else
                {
                    count = 1 - count;
                    byte repeat = m_input.ReadUInt8();
                    --remaining;
                    for (int i = 0; i < count; ++i)
                    {
                        m_output[dst] = repeat;
                        dst          += pixel_size;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public override ImageMetaData ReadMetaData(IBinaryStream file)
        {
            var header = file.ReadHeader(16);
            var info   = new EpaMetaData {
                Width     = header.ToUInt32(8),
                Height    = header.ToUInt32(12),
                Mode      = header[3],
                ColorType = header[4],
            };

            switch (info.ColorType)
            {
            case 0: info.BPP = 8; break;

            case 1: info.BPP = 24; break;

            case 2: info.BPP = 32; break;

            case 3: info.BPP = 16; break;

            case 4: info.BPP = 8; break;

            default: return(null);
            }
            if (2 == info.Mode)
            {
                info.OffsetX = file.ReadInt32();
                info.OffsetY = file.ReadInt32();
            }
            return(info);
        }
Ejemplo n.º 5
0
        }                                                                 // 'amp_'

        public override ImageMetaData ReadMetaData(IBinaryStream stream)
        {
            stream.Position = 4;
            int version = stream.ReadInt16();

            if (version != 1)
            {
                return(null);
            }
            int unpacked_size = stream.ReadInt32();
            int data_offset   = stream.ReadInt32();

            if (unpacked_size < 0x36 || data_offset < stream.Position)
            {
                return(null);
            }
            var header = new byte[0x20];

            stream.Position = data_offset;
            Unpack(stream.AsStream, header);
            Decrypt(header);
            if ('B' != header[0] || 'M' != header[1])
            {
                return(null);
            }
            return(new ZbmMetaData
            {
                Width = LittleEndian.ToUInt32(header, 0x12),
                Height = LittleEndian.ToUInt32(header, 0x16),
                BPP = LittleEndian.ToInt16(header, 0x1C),
                UnpackedSize = unpacked_size,
                DataOffset = data_offset,
            });
        }
Ejemplo n.º 6
0
        void ParseEncryptedIndex(int count)
        {
            int header_length = m_index.ReadUInt8();

            if (0 != header_length)
            {
                m_info.Prefix = m_index.ReadBytes(header_length);
            }
            m_wide_offset = m_index.ReadByte() != 0;
            int name_tree_length   = m_index.ReadInt32();
            var entry_table_offset = m_index.Position + name_tree_length;

            m_name_buf = new byte[0x110];
            TraverseIndex(m_index.Position, 0);
            if (m_dir.Count != count)
            {
                throw new InvalidFormatException();
            }

            foreach (EpkEntry entry in m_dir)
            {
                m_index.Position = entry_table_offset + entry.DirIndex * 12;
                ReadEntry(entry);
            }
        }
Ejemplo n.º 7
0
        }                                                                 // 'METAL'

        public override ImageMetaData ReadMetaData(IBinaryStream file)
        {
            var header = file.ReadHeader(0x2C);

            if (!header.AsciiEqual("METAL") || header.ToInt32(0x10) != 0x28 || header[0x15] == 0)
            {
                return(null);
            }
            int name_length = header.ToInt32(0x28);

            if (name_length <= 0)
            {
                return(null);
            }
            var name = file.ReadCString(name_length);

            if (file.ReadInt32() != 0xC)
            {
                return(null);
            }
            int frame_count = file.ReadInt32();

            if (!ArchiveFormat.IsSaneCount(frame_count))
            {
                return(null);
            }
            var data_pos = file.Position + frame_count * 0x18;

            return(new MtlMetaData {
                Width = header.ToUInt32(0x20),
                Height = header.ToUInt32(0x24),
                BPP = 32,
                DataOffset = data_pos,
            });
        }
Ejemplo n.º 8
0
        public void Parse(IBinaryStream index)
        {
            index.Position = 16;
            int segment_count = Binary.BigEndian(index.ReadInt32());

            m_segments = new List <BundleSegment> (segment_count);
            long packed_offset   = m_data_offset;
            long unpacked_offset = 0;

            for (int i = 0; i < segment_count; ++i)
            {
                var segment = new BundleSegment();
                segment.Offset         = packed_offset;
                segment.UnpackedOffset = unpacked_offset;
                segment.UnpackedSize   = Binary.BigEndian(index.ReadUInt32());
                segment.PackedSize     = Binary.BigEndian(index.ReadUInt32());
                segment.Compression    = Binary.BigEndian(index.ReadUInt16());
                m_segments.Add(segment);
                packed_offset   += segment.PackedSize;
                unpacked_offset += segment.UnpackedSize;
            }
            int count = Binary.BigEndian(index.ReadInt32());

            m_bundles = new List <BundleEntry> (count);
            for (int i = 0; i < count; ++i)
            {
                var entry = new BundleEntry();
                entry.Offset = Binary.BigEndian(index.ReadInt64());
                entry.Size   = (uint)Binary.BigEndian(index.ReadInt64());
                entry.Flags  = Binary.BigEndian(index.ReadUInt32());
                entry.Name   = index.ReadCString(Encoding.UTF8);
                m_bundles.Add(entry);
            }
        }
Ejemplo n.º 9
0
        }                                                                 // 'hiz'

        public override ImageMetaData ReadMetaData(IBinaryStream file)
        {
            file.Position = 4;
            int n = file.ReadInt32();

            if (100 != n)
            {
                return(null);
            }
            uint right    = file.ReadUInt32() ^ 0xAA5A5A5A;
            uint bottom   = file.ReadUInt32() ^ 0xAC9326AF;
            int  unknown1 = file.ReadInt32(); // @0x10

            if (unknown1 == 0x375A8436)
            {
                return(null);
            }
            uint unpacked_size = file.ReadUInt32() ^ 0x19739D6A; // @0x14

            if (unpacked_size != right * bottom * 4)
            {
                return(null);
            }
            return(new HizMetaData
            {
                Width = right,
                Height = bottom,
                BPP = 32,
                IsPacked = true,
                DataOffset = 0x4c,
                UnpackedSize = unpacked_size,
            });
        }
Ejemplo n.º 10
0
        public override ImageData Read(IBinaryStream stream, ImageMetaData info)
        {
            var meta = (FcbMetaData)info;

            byte[] input;
            if (1 == meta.Method)
            {
                stream.Position = 0x14;
                int unpacked_size = Binary.BigEndian(stream.ReadInt32());
                stream.ReadInt32(); // packed_size
                input = new byte[unpacked_size];
                using (var z = new ZLibStream(stream.AsStream, CompressionMode.Decompress, true))
                    if (unpacked_size != z.Read(input, 0, unpacked_size))
                    {
                        throw new EndOfStreamException();
                    }
            }
            else if (0 == meta.Method)
            {
                stream.Position = 0x10;
                using (var tz = new TzCompression(stream.AsStream))
                    input = tz.Unpack();
            }
            else
            {
                throw new InvalidFormatException();
            }
            var pixels = Unpack(input, info);

            return(ImageData.Create(info, PixelFormats.Bgra32, null, pixels));
        }
Ejemplo n.º 11
0
        public override ImageMetaData ReadMetaData(IBinaryStream file)
        {
            var  info           = new AkbMetaData();
            bool is_incremental = '+' == (file.ReadUInt32() >> 24);

            info.Width       = file.ReadUInt16();
            info.Height      = file.ReadUInt16();
            info.Flags       = file.ReadUInt32();
            info.BPP         = 0 == (info.Flags & 0x40000000) ? 32 : 24;
            info.Background  = file.ReadBytes(4);
            info.OffsetX     = file.ReadInt32();
            info.OffsetY     = file.ReadInt32();
            info.InnerWidth  = file.ReadInt32() - info.OffsetX;
            info.InnerHeight = file.ReadInt32() - info.OffsetY;
            if (info.InnerWidth > info.Width || info.InnerHeight > info.Height)
            {
                return(null);
            }
            if (is_incremental)
            {
                info.BaseFileName = file.ReadCString(0x20);
            }
            info.DataOffset = (uint)file.Position;
            return(info);
        }
Ejemplo n.º 12
0
        public override ImageMetaData ReadMetaData(IBinaryStream file)
        {
            var header  = file.ReadHeader(0x14);
            int version = header.ToUInt16(4);

            if (version != 101 && version != 102)
            {
                return(null);
            }
            var info = new PrtMetaData {
                Width         = header.ToUInt16(0xC),
                Height        = header.ToUInt16(0xE),
                BPP           = header.ToUInt16(6),
                Version       = version,
                PaletteOffset = header.ToUInt16(8),
                DataOffset    = header.ToUInt16(0xA),
                HasAlpha      = header.ToInt32(0x10) != 0,
            };

            if (102 == version)
            {
                info.OffsetX = file.ReadInt32();
                info.OffsetY = file.ReadInt32();
            }
            return(info);
        }
Ejemplo n.º 13
0
        public void Unpack()
        {
            m_input.Position = 0x11;
            int ctl_length = (m_input.ReadInt32() + 7) / 8;
            var ctl_bytes  = m_input.ReadBytes(ctl_length);

            m_input.ReadInt32();
            using (var ctl_mem = new MemoryStream(ctl_bytes))
                using (var bits = new LsbBitStream(ctl_mem))
                {
                    int dst = 0;
                    while (dst < m_output.Length)
                    {
                        int bit = bits.GetNextBit();
                        if (-1 == bit)
                        {
                            break;
                        }
                        if (0 == bit)
                        {
                            m_output[dst++] = m_input.ReadUInt8();
                        }
                        else
                        {
                            int offset = m_input.ReadUInt16();
                            int count  = (offset & 7) + 1;
                            offset = (offset >> 3) + 1;
                            Binary.CopyOverlapped(m_output, dst - offset, dst, count);
                            dst += count;
                        }
                    }
                }
        }
Ejemplo n.º 14
0
        public override uint     Signature { get { return 0; } } // 'RIFF'

        public override ImageMetaData ReadMetaData (IBinaryStream file)
        {
            // 'RIFF' isn't included into signature to avoid auto-detection of the WAV files as IPH images.
            if (0x46464952 != file.Signature) // 'RIFF'
                return null;
            var header = file.ReadHeader (0x10);
            if (0x38 != header.ToInt32 (4))
                return null;
            var signature = header.ToInt32 (8);
            if (signature != 0x20485049 && signature != 0x00485049) // 'IPH'
                return null;
            if (0x20746D66 != header.ToInt32 (12)) // 'fmt '
                return null;
            file.Position = 0x38;
            if (0x20706D62 != file.ReadInt32()) // 'bmp '
                return null;
            var info = new IphMetaData();
            info.PackedSize = file.ReadInt32();
            info.Width  = file.ReadUInt16();
            info.Height = file.ReadUInt16();
            file.Position = 0x50;
            info.BPP = file.ReadUInt16();
            info.IsCompressed = 0 != file.ReadInt16();
            // XXX int16@[0x54] is a transparency color or 0xFFFF if image is not transparent
            return info;
        }
Ejemplo n.º 15
0
        internal static CgdMetaData FromStream(IBinaryStream file, uint offset)
        {
            file.Position = offset;
            int unpacked_size = file.ReadInt32();

            file.ReadInt32();
            byte compression = (byte)file.ReadUInt16();
            uint header_size = file.ReadUInt16();
            uint id          = file.ReadUInt32();

            if (header_size < 0x10 || (id != 0x973768 && id != 0xB29EA4))
            {
                return(null);
            }
            ushort width  = file.ReadUInt16();
            ushort height = file.ReadUInt16();
            ushort bpp    = file.ReadUInt16();

            return(new CgdMetaData {
                Width = width,
                Height = height,
                BPP = bpp,
                DataOffset = offset + 0x10 + header_size,
                UnpackedSize = unpacked_size,
                Compression = compression,
            });
        }
Ejemplo n.º 16
0
        }                                                               // 'CHD'

        public override ImageMetaData ReadMetaData(IBinaryStream file)
        {
            file.Position = 4;
            int count = file.ReadInt32();

            if (count < 0 || count > 0xFFFFF)
            {
                return(null);
            }
            file.ReadInt32();
            uint first_offset = 0;

            for (int i = 0; i < count && 0 == first_offset; ++i)
            {
                first_offset = file.ReadUInt32();
            }
            if (0 == first_offset)
            {
                return(null);
            }
            file.Position = first_offset;
            var info = new ChdMetaData();

            info.Width       = file.ReadUInt32();
            info.Height      = file.ReadUInt32();
            info.OffsetX     = file.ReadInt32();
            info.OffsetY     = file.ReadInt32();
            info.FirstOffset = first_offset + 0x10;
            info.BPP         = 32;
            return(info);
        }
Ejemplo n.º 17
0
        public override ImageMetaData ReadMetaData(IBinaryStream file)
        {
            var info = new EpaMetaData();

            info.Mode      = file.ReadInt32() >> 24;
            info.ColorType = file.ReadInt32() & 0xff;
            switch (info.ColorType)
            {
            case 0: info.BPP = 8; break;

            case 1: info.BPP = 24; break;

            case 2: info.BPP = 32; break;

            case 3: info.BPP = 15; break;

            case 4: info.BPP = 8; break;

            default: return(null);
            }
            info.Width  = file.ReadUInt32();
            info.Height = file.ReadUInt32();
            if (2 == info.Mode)
            {
                info.OffsetX = file.ReadInt32();
                info.OffsetY = file.ReadInt32();
            }
            return(info);
        }
Ejemplo n.º 18
0
        public override ImageMetaData ReadMetaData(IBinaryStream file)
        {
            file.Position = 4;
            int  frames = file.ReadUInt16();
            int  bpp    = file.ReadUInt16();
            uint width  = file.ReadUInt32();
            uint height = file.ReadUInt32();
            int  x      = file.ReadInt32();
            int  y      = file.ReadInt32();

            file.ReadInt32(); // 0
            uint frame_size = file.ReadUInt32();

            if (24 != bpp && 8 != bpp)
            {
                Trace.WriteLine("unsupported bpp", "WipFormat");
                return(null);
            }
            return(new WipMetaData
            {
                Width = width,
                Height = height,
                OffsetX = x,
                OffsetY = y,
                BPP = bpp,
                FrameCount = frames,
                FrameSize = frame_size,
            });
        }
Ejemplo n.º 19
0
        }                                                                 // 'dcf '

        public override ImageMetaData ReadMetaData(IBinaryStream stream)
        {
            stream.Seek(4, SeekOrigin.Current);
            uint header_size = stream.ReadUInt32();
            long data_pos    = stream.Position + header_size;

            if (stream.ReadInt32() != 1)
            {
                return(null);
            }
            uint width       = stream.ReadUInt32();
            uint height      = stream.ReadUInt32();
            int  bpp         = stream.ReadInt32();
            int  name_length = stream.ReadInt32();

            if (name_length <= 0)
            {
                return(null);
            }
            int shift     = (name_length % 7) + 1;
            var name_bits = stream.ReadBytes(name_length);

            for (int i = 0; i < name_length; ++i)
            {
                name_bits[i] = Binary.RotByteL(name_bits[i], shift);
            }
            return(new DcfMetaData
            {
                Width = width,
                Height = height,
                BPP = bpp,
                BaseName = Encodings.cp932.GetString(name_bits),
                DataOffset = data_pos,
            });
        }
Ejemplo n.º 20
0
        byte[] UnpackCfp0(IBinaryStream input)
        {
            input.Position = 8;
            int unpacked_size = input.ReadInt32();
            var output        = new byte[unpacked_size];
            int dst           = 0;

            while (dst < output.Length)
            {
                int cmd   = input.ReadByte();
                int count = 0;
                switch (cmd)
                {
                case 0:
                    count = input.ReadUInt8();
                    input.Read(output, dst, count);
                    break;

                case 1:
                    count = input.ReadInt32();
                    input.Read(output, dst, count);
                    break;

                case 2:
                {
                    count = input.ReadUInt8();
                    byte v = input.ReadUInt8();
                    for (int i = 0; i < count; ++i)
                    {
                        output[dst + i] = v;
                    }
                    break;
                }

                case 3:
                {
                    count = input.ReadInt32();
                    byte v = input.ReadUInt8();
                    for (int i = 0; i < count; ++i)
                    {
                        output[dst + i] = v;
                    }
                    break;
                }

                case 6:
                    int offset = input.ReadUInt16();
                    count = input.ReadUInt16();
                    Binary.CopyOverlapped(output, dst - offset, dst, count);
                    break;

                case 15:
                case -1:
                    return(output);
                }
                dst += count;
            }
            return(output);
        }
Ejemplo n.º 21
0
        public override ImageMetaData ReadMetaData(IBinaryStream file)
        {
            file.ReadUInt32();
            if (file.ReadUInt32() != 0x0a1a0a0d)
            {
                return(null);
            }
            uint chunk_size = Binary.BigEndian(file.ReadUInt32());

            byte[] chunk_type = file.ReadBytes(4);
            if (!Binary.AsciiEqual(chunk_type, "IHDR"))
            {
                return(null);
            }

            var meta = new ImageMetaData();

            meta.Width  = Binary.BigEndian(file.ReadUInt32());
            meta.Height = Binary.BigEndian(file.ReadUInt32());
            int bpp        = file.ReadByte();
            int color_type = file.ReadByte();

            switch (color_type)
            {
            case 2: meta.BPP = bpp * 3; break;

            case 3: meta.BPP = 24; break;

            case 4: meta.BPP = bpp * 2; break;

            case 6: meta.BPP = bpp * 4; break;

            default: meta.BPP = bpp; break;
            }
            SkipBytes(file, 7);

            for (;;)
            {
                chunk_size = Binary.BigEndian(file.ReadUInt32());
                file.Read(chunk_type, 0, 4);
                if (Binary.AsciiEqual(chunk_type, "IDAT") || Binary.AsciiEqual(chunk_type, "IEND"))
                {
                    break;
                }
                if (Binary.AsciiEqual(chunk_type, "oFFs"))
                {
                    int x = Binary.BigEndian(file.ReadInt32());
                    int y = Binary.BigEndian(file.ReadInt32());
                    if (0 == file.ReadByte())
                    {
                        meta.OffsetX = x;
                        meta.OffsetY = y;
                    }
                    break;
                }
                SkipBytes(file, chunk_size + 4);
            }
            return(meta);
        }
Ejemplo n.º 22
0
        public void Unpack()
        {
            m_input.Position = m_info.DataOffset;
            uint name_length = m_input.ReadUInt32();

            m_input.Seek(name_length, SeekOrigin.Current);
            uint mask = m_input.ReadUInt32();

            m_input.Seek(9, SeekOrigin.Current);
            int layer_count = m_input.ReadInt32();

            if (layer_count < 1)
            {
                throw new InvalidFormatException();
            }

            // XXX only first frame is interpreted.

            var frame = new Frame(layer_count);

            frame.Width  = m_input.ReadInt32();
            frame.Height = m_input.ReadInt32();
            frame.BPP    = m_input.ReadInt32();
            if (frame.BPP <= 0)
            {
                throw new InvalidFormatException();
            }
            if (frame.BPP <= 8)
            {
                frame.Palette = ImageFormat.ReadColorMap(m_input.AsStream, 1 << frame.BPP);
            }
            frame.SetStride();
            m_frames.Add(frame);
            for (int i = 0; i < layer_count; ++i)
            {
                m_input.ReadInt32();    // left
                m_input.ReadInt32();    // top
                m_input.ReadByte();     // visibility
                m_input.ReadInt32();    // (-1) TransColor
                m_input.ReadInt32();    // (0xFF) alpha
                m_input.ReadByte();     // AlphaOn
                name_length = m_input.ReadUInt32();
                m_input.Seek(name_length, SeekOrigin.Current);
                if (m_info.Version >= 107)
                {
                    m_input.ReadByte(); // lock
                }
                var layer      = new Layer();
                int layer_size = m_input.ReadInt32();
                layer.Pixels = UnpackLayer(frame, layer_size);
                int alpha_size = m_input.ReadInt32();
                if (alpha_size != 0)
                {
                    layer.Alpha = UnpackLayer(frame, alpha_size, true);
                }
                frame.Layers.Add(layer);
            }
            Flatten(0);
        }
Ejemplo n.º 23
0
        public PgdReader(IBinaryStream input, int position)
        {
            m_input          = input;
            m_input.Position = position;
            int unpacked_size = m_input.ReadInt32();

            m_input.ReadInt32(); // packed_size
            m_output = new byte[unpacked_size];
        }
Ejemplo n.º 24
0
        public void Unpack()
        {
            int alpha_size = m_input.ReadInt32();

            UnpackAlpha(alpha_size);
            int rgb_size = m_input.ReadInt32();

            UnpackColor(rgb_size);
        }
Ejemplo n.º 25
0
        public void Unpack()
        {
            m_input.Position = 0x1A;
            int  color_data_length = Binary.BigEndian(m_input.ReadInt32());
            long next_pos          = m_input.Position + color_data_length;

            if (0 != color_data_length)
            {
                if (8 == m_info.BPP)
                {
                    ReadPalette(color_data_length);
                }
                m_input.Position = next_pos;
            }
            next_pos        += 4 + Binary.BigEndian(m_input.ReadInt32());
            m_input.Position = next_pos; // skip Image Resources
            next_pos        += 4 + Binary.BigEndian(m_input.ReadInt32());
            m_input.Position = next_pos; // skip Layer and Mask Information

            int compression = Binary.BigEndian(m_input.ReadInt16());
            int remaining   = checked ((int)(m_input.Length - m_input.Position));

            byte[] pixels;
            if (0 == compression)
            {
                pixels = m_input.ReadBytes(remaining);
            }
            else if (1 == compression)
            {
                pixels = UnpackRLE();
            }
            else
            {
                throw new NotSupportedException("PSD files with ZIP compression not supported");
            }

            if (1 == m_info.Channels)
            {
                m_output = pixels;
                return;
            }
            int channels = Math.Min(4, m_info.Channels);

            m_output = new byte[channels * m_channel_size];
            int src = 0;

            for (int ch = 0; ch < channels; ++ch)
            {
                int dst = ChannelMap[ch];
                for (int i = 0; i < m_channel_size; ++i)
                {
                    m_output[dst] = pixels[src++];
                    dst          += channels;
                }
            }
        }
Ejemplo n.º 26
0
        bool TestAlign(IBinaryStream index, int align)
        {
            int first_offset  = index.ReadInt32();
            int size          = index.ReadInt32();
            int second_offset = (first_offset + size + 7) & -8;
            int name_length   = index.ReadUInt8();

            index.Position = ((align + 1 + name_length) & -align) + 8;
            return(second_offset == index.ReadInt32());
        }
Ejemplo n.º 27
0
        public override ImageMetaData ReadMetaData(IBinaryStream stream)
        {
            int count = stream.ReadInt16();

            if (count <= 0 || count >= 0x100)
            {
                return(null);
            }
            int offset;

            if (count > 1)
            {
                offset = stream.ReadInt32();
                if (offset != 2 + count * 4)
                {
                    return(null);
                }
            }
            else
            {
                offset = 2;
            }
            stream.Position = offset;
            int unpacked_size = stream.ReadInt32();
            int packed_size   = stream.ReadInt32();

            offset += 8;
            if (offset + packed_size > stream.Length)
            {
                return(null);
            }
            byte[] header = new byte[0x36];
            if (0x36 != MgrOpener.Decompress(stream.AsStream, header) ||
                header[0] != 'B' || header[1] != 'M')
            {
                return(null);
            }
            using (var bmp = new BinMemoryStream(header, stream.Name))
            {
                var info = Bmp.ReadMetaData(bmp);
                if (null == info)
                {
                    return(null);
                }
                return(new MgrMetaData
                {
                    Width = info.Width,
                    Height = info.Height,
                    BPP = info.BPP,
                    Offset = offset,
                    PackedSize = packed_size,
                    UnpackedSize = unpacked_size,
                });
            }
        }
Ejemplo n.º 28
0
        public BmrDecoder(IBinaryStream input)
        {
            input.Position = 3;
            m_step         = input.ReadUInt8();
            m_final_size   = input.ReadInt32();
            m_key          = input.ReadInt32();
            int unpacked_size = input.ReadInt32();

            m_output = new byte[unpacked_size];
            m_input  = new MsbBitStream(input.AsStream, true);
        }
Ejemplo n.º 29
0
        private void Decode3(IBinaryStream input, Stream output, int step)
        {
            input.ReadInt32(); // unpacked_size
            int count = input.ReadInt32();

            using (var buffer = new BinaryWriter(output, Encoding.ASCII, true))
            {
                short sample = input.ReadInt16();
                buffer.Write(sample);
                for (int i = 0; i < count; ++i)
                {
                    if (count - 300 == i)
                    {
                        sample = 0;
                    }
                    ushort v = input.ReadUInt8();
                    if (0 != (v & 1))
                    {
                        ushort v14 = (ushort)((v >> 1) & 0x7F);
                        if (0 != (v14 & 0x40))
                        {
                            sample = (short)(v14 << 10);
                        }
                        else
                        {
                            sample += (short)SampleTable2[v14];
                        }
                        buffer.Write(sample);
                        if (step != 0)
                        {
                            buffer.BaseStream.Seek(step, SeekOrigin.Current);
                        }
                    }
                    else
                    {
                        v |= (ushort)(input.ReadUInt8() << 8);
                        int    repeat = SizeTable[(v >> 1) & 7];
                        short  end    = (short)(v & 0xFFF0);
                        double inc    = (end - sample) / (double)repeat;
                        double v8     = sample;
                        for (int j = 0; j < repeat; ++j)
                        {
                            v8 += inc;
                            buffer.Write((short)v8);
                            if (step != 0)
                            {
                                buffer.BaseStream.Seek(step, SeekOrigin.Current);
                            }
                        }
                        sample = end;
                    }
                }
            }
        }
Ejemplo n.º 30
0
 internal virtual ImageMetaData GetBaseInfo(IBinaryStream input)
 {
     input.Position = 4;
     return(new ImageMetaData
     {
         OffsetX = input.ReadInt32(),
         OffsetY = input.ReadInt32(),
         Width = input.ReadUInt32(),
         Height = input.ReadUInt32(),
         BPP = 32,
     });
 }