Beispiel #1
0
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            var ani = (AniEntry)entry;

            byte[] key_frame = null;
            if (ani.KeyFrame != ani.FrameIndex)
            {
                var dir = (List <Entry>)arc.Dir;
                for (int i = ani.KeyFrame; i < ani.FrameIndex; ++i)
                {
                    var frame = dir[i];
                    using (var s = arc.File.CreateStream(frame.Offset, frame.Size))
                    {
                        var frame_info = Cg.ReadMetaData(s) as CgMetaData;
                        if (null == frame_info)
                        {
                            break;
                        }
                        using (var reader = new CgFormat.Reader(s, frame_info, key_frame))
                        {
                            reader.Unpack();
                            key_frame = reader.Data;
                        }
                    }
                }
            }
            var        input = arc.File.CreateStream(entry.Offset, entry.Size);
            CgMetaData info  = null;

            try
            {
                info = Cg.ReadMetaData(input) as CgMetaData;
            }
            catch
            {
                input.Dispose();
                throw;
            }
            if (null == info)
            {
                input.Position = 0;
                return(input);
            }
            using (input)
                using (var reader = new CgFormat.Reader(input, info, key_frame))
                {
                    reader.Unpack();
                    return(TgaStream.Create(info, reader.Data));
                }
        }
Beispiel #2
0
            public Reader(Stream file, CgMetaData info, byte[] base_image = null)
            {
                m_type     = info.Type;
                m_width    = (int)info.Width;
                m_height   = (int)info.Height;
                m_left     = info.OffsetX;
                m_top      = info.OffsetY;
                m_right    = info.Right == 0 ? m_width : info.Right;
                m_bottom   = info.Bottom == 0 ? m_height : info.Bottom;
                m_output   = base_image ?? new byte[3 * m_width * m_height];
                m_input    = new BinaryReader(file, Encoding.ASCII, true);
                ShiftTable = InitShiftTable();

                if (0 != (info.Type & 7))
                {
                    file.Position = 13;
                }
                else
                {
                    file.Position = 5;
                }
            }
Beispiel #3
0
        public override ImageMetaData ReadMetaData(Stream stream)
        {
            int sig = stream.ReadByte();

            if (sig >= 0x20)
            {
                return(null);
            }
            using (var input = new ArcView.Reader(stream))
            {
                int width  = input.ReadInt16();
                int height = input.ReadInt16();
                if (width <= 0 || height <= 0 || width > 4096 || height > 4096)
                {
                    return(null);
                }
                var meta = new CgMetaData
                {
                    Width  = (uint)width,
                    Height = (uint)height,
                    BPP    = 24,
                    Type   = sig,
                };
                if (0 != (sig & 7))
                {
                    meta.OffsetX = input.ReadInt16();
                    meta.OffsetY = input.ReadInt16();
                    meta.Right   = input.ReadInt16();
                    meta.Bottom  = input.ReadInt16();
                    if (meta.OffsetX > meta.Right || meta.OffsetY > meta.Bottom ||
                        meta.Right > width || meta.Bottom > height ||
                        meta.OffsetX < 0 || meta.OffsetY < 0)
                    {
                        return(null);
                    }
                }
                return(meta);
            }
        }
Beispiel #4
0
        public override ImageMetaData ReadMetaData(IBinaryStream file)
        {
            int sig = file.ReadByte();

            if (sig >= 0x20)
            {
                return(null);
            }
            int width  = file.ReadInt16();
            int height = file.ReadInt16();

            if (width <= 0 || height <= 0 || width > 4096 || height > 4096)
            {
                return(null);
            }
            var meta = new CgMetaData
            {
                Width  = (uint)width,
                Height = (uint)height,
                BPP    = 24,
                Type   = sig,
            };

            if (0 != (sig & 7))
            {
                meta.OffsetX = file.ReadInt16();
                meta.OffsetY = file.ReadInt16();
                meta.Right   = file.ReadInt16();
                meta.Bottom  = file.ReadInt16();
                if (meta.OffsetX > meta.Right || meta.OffsetY > meta.Bottom ||
                    meta.Right > width || meta.Bottom > height ||
                    meta.OffsetX < 0 || meta.OffsetY < 0)
                {
                    return(null);
                }
            }
            return(meta);
        }
Beispiel #5
0
            public Reader(IBinaryStream file, CgMetaData info, byte[] base_image, bool leave_open = false)
            {
                m_type     = info.Type;
                m_width    = (int)info.Width;
                m_height   = (int)info.Height;
                m_left     = info.OffsetX;
                m_top      = info.OffsetY;
                m_right    = info.Right == 0 ? m_width : info.Right;
                m_bottom   = info.Bottom == 0 ? m_height : info.Bottom;
                m_output   = base_image ?? CreateBackground();
                m_input    = file;
                Info       = info;
                ShiftTable = InitShiftTable();

                if (0 != (info.Type & 7))
                {
                    m_input.Position = 13;
                }
                else
                {
                    m_input.Position = 5;
                }
                m_should_dispose = !leave_open;
            }
Beispiel #6
0
 public Reader(IBinaryStream file, CgMetaData info) : this(file, info, null, true)
 {
 }
Beispiel #7
0
            public Reader(Stream file, CgMetaData info, byte[] base_image = null)
            {
                m_type = info.Type;
                m_width = (int)info.Width;
                m_height = (int)info.Height;
                m_left = info.OffsetX;
                m_top = info.OffsetY;
                m_right = info.Right == 0 ? m_width : info.Right;
                m_bottom = info.Bottom == 0 ? m_height : info.Bottom;
                m_output = base_image ?? new byte[3*m_width*m_height];
                m_input = new BinaryReader (file, Encoding.ASCII, true);
                ShiftTable = InitShiftTable();

                if (0 != (info.Type & 7))
                    file.Position = 13;
                else
                    file.Position = 5;
            }
Beispiel #8
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     int sig = stream.ReadByte();
     if (sig >= 0x20)
         return null;
     using (var input = new ArcView.Reader (stream))
     {
         int width  = input.ReadInt16();
         int height = input.ReadInt16();
         if (width <= 0 || height <= 0 || width > 4096 || height > 4096)
             return null;
         var meta = new CgMetaData
         {
             Width = (uint)width,
             Height = (uint)height,
             BPP = 24,
             Type = sig,
         };
         if (0 != (sig & 7))
         {
             meta.OffsetX = input.ReadInt16();
             meta.OffsetY = input.ReadInt16();
             meta.Right   = input.ReadInt16();
             meta.Bottom  = input.ReadInt16();
             if (meta.OffsetX > meta.Right || meta.OffsetY > meta.Bottom ||
                 meta.Right > width || meta.Bottom > height ||
                 meta.OffsetX < 0 || meta.OffsetY < 0)
                 return null;
         }
         return meta;
     }
 }