Beispiel #1
0
        public AbmReader(Stream file, AbmImageData info)
        {
            m_info = info;
            if (2 == m_info.Mode)
            {
                m_bpp         = 32;
                file.Position = m_info.BaseOffset;
                using (var base_frame = new ArcView.Reader(file))
                    m_output = UnpackV2(base_frame);
            }
            else if (1 == m_info.Mode || 32 == m_info.Mode || 24 == m_info.Mode)
            {
                if (1 == m_info.Mode)
                {
                    m_bpp = 24;
                }
                else
                {
                    m_bpp = m_info.Mode;
                }

                int total_length = (int)(m_info.Width * m_info.Height * m_bpp / 8);
                m_output      = new byte[total_length];
                file.Position = m_info.BaseOffset;
                if (1 == m_info.Mode)
                {
                    if (total_length != file.Read(m_output, 0, (total_length)))
                    {
                        throw new EndOfStreamException();
                    }
                }
                else
                {
                    using (var base_frame = new ArcView.Reader(file))
                    {
                        if (24 == m_bpp)
                        {
                            UnpackStream24(base_frame, m_output, total_length);
                        }
                        else
                        {
                            UnpackStream32(base_frame, m_output, total_length);
                        }
                    }
                }
            }
            else
            {
                throw new NotImplementedException();
            }
            if (0 != m_info.FrameOffset)
            {
                m_input = new ArcView.Reader(file);
            }
        }
Beispiel #2
0
        public override ArcFile TryOpen(ArcView file)
        {
            if ('B' != file.View.ReadByte(0) || 'M' != file.View.ReadByte(1))
            {
                return(null);
            }
            int type = file.View.ReadSByte(0x1C);

            if (type != 1 && type != 2)
            {
                return(null);
            }

            int count = file.View.ReadInt16(0x3A);

            if (!IsSaneCount(count))
            {
                return(null);
            }

            uint width            = file.View.ReadUInt32(0x12);
            uint height           = file.View.ReadUInt32(0x16);
            int  pixel_size       = 2 == type ? 4 : 3;
            uint bitmap_data_size = width * height * (uint)pixel_size;

            var    dir            = new List <Entry> (count);
            long   next_offset    = file.View.ReadUInt32(0x42);
            uint   current_offset = 0x46;
            string base_name      = Path.GetFileNameWithoutExtension(file.Name);

            for (int i = 0; i < count; ++i)
            {
                var entry = new AbmEntry {
                    Name   = string.Format("{0}#{1:D4}", base_name, i),
                    Type   = "image",
                    Offset = next_offset,
                    Index  = i,
                };
                if (i + 1 != count)
                {
                    next_offset     = file.View.ReadUInt32(current_offset);
                    current_offset += 4;
                }
                else
                {
                    next_offset = file.MaxOffset;
                }
                if (next_offset <= entry.Offset)
                {
                    return(null);
                }
                entry.Size = (uint)(next_offset - entry.Offset);
                if (!entry.CheckPlacement(file.MaxOffset))
                {
                    return(null);
                }
                entry.UnpackedSize = 0x12 + bitmap_data_size;
                dir.Add(entry);
            }
            var image_info = new AbmImageData
            {
                Width      = (uint)width,
                Height     = (uint)height,
                BPP        = pixel_size * 8,
                Mode       = type,
                BaseOffset = (uint)dir[0].Offset,
            };

            return(new AbmArchive(file, this, dir, image_info));
        }
Beispiel #3
0
 public AbmArchive(ArcView arc, ArchiveFormat impl, ICollection <Entry> dir, AbmImageData info)
     : base(arc, impl, dir)
 {
     FrameInfo = info;
 }
Beispiel #4
0
 public AbmReader(IBinaryStream file, AbmImageData info) : base(file, info)
 {
     m_info = info;
 }
Beispiel #5
0
        public AbmReader(Stream file, AbmImageData info)
        {
            m_info = info;
            if (2 == m_info.Mode)
            {
                m_bpp = 32;
                file.Position = m_info.BaseOffset;
                using (var base_frame = new ArcView.Reader (file))
                    m_output = UnpackV2 (base_frame);
            }
            else if (1 == m_info.Mode || 32 == m_info.Mode || 24 == m_info.Mode)
            {
                if (1 == m_info.Mode)
                    m_bpp = 24;
                else
                    m_bpp = m_info.Mode;

                int total_length = (int)(m_info.Width * m_info.Height * m_bpp / 8);
                m_output = new byte[total_length];
                file.Position = m_info.BaseOffset;
                if (1 == m_info.Mode)
                {
                    if (total_length != file.Read (m_output, 0, (total_length)))
                        throw new EndOfStreamException();
                }
                else
                {
                    using (var base_frame = new ArcView.Reader (file))
                    {
                        if (24 == m_bpp)
                            UnpackStream24 (base_frame, m_output, total_length);
                        else
                            UnpackStream32 (base_frame, m_output, total_length);
                    }
                }
            }
            else
                throw new NotImplementedException();
            if (0 != m_info.FrameOffset)
            {
                m_input = new ArcView.Reader (file);
            }
        }
Beispiel #6
0
 public AbmArchive(ArcView arc, ArchiveFormat impl, ICollection<Entry> dir, AbmImageData info)
     : base(arc, impl, dir)
 {
     FrameInfo = info;
 }
Beispiel #7
0
        public override ArcFile TryOpen(ArcView file)
        {
            if ('B' != file.View.ReadByte (0) || 'M' != file.View.ReadByte (1))
                return null;
            int type = file.View.ReadSByte (0x1C);
            if (type != 1 && type != 2)
                return null;

            int count = file.View.ReadInt16 (0x3A);
            if (!IsSaneCount (count))
                return null;

            uint width = file.View.ReadUInt32 (0x12);
            uint height = file.View.ReadUInt32 (0x16);
            int pixel_size = 2 == type ? 4 : 3;
            uint bitmap_data_size = width*height*(uint)pixel_size;

            var dir = new List<Entry> (count);
            long next_offset = file.View.ReadUInt32 (0x42);
            uint current_offset = 0x46;
            string base_name = Path.GetFileNameWithoutExtension (file.Name);
            for (int i = 0; i < count; ++i)
            {
                var entry = new AbmEntry {
                    Name = string.Format ("{0}#{1:D4}.tga", base_name, i),
                    Type = "image",
                    Offset = next_offset,
                    Index = i,
                };
                if (i + 1 != count)
                {
                    next_offset = file.View.ReadUInt32 (current_offset);
                    current_offset += 4;
                }
                else
                    next_offset = file.MaxOffset;
                if (next_offset <= entry.Offset)
                    return null;
                entry.Size = (uint)(next_offset - entry.Offset);
                if (!entry.CheckPlacement (file.MaxOffset))
                    return null;
                entry.UnpackedSize = 0x12 + bitmap_data_size;
                dir.Add (entry);
            }
            var image_info = new AbmImageData
            {
                Width = (uint)width,
                Height = (uint)height,
                BPP = pixel_size * 8,
                Mode = type,
                BaseOffset = (uint)dir[0].Offset,
            };
            return new AbmArchive (file, this, dir, image_info);
        }