Esempio n. 1
0
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            var abm   = arc as AbmArchive;
            var frame = entry as AbmEntry;

            if (null == abm || null == frame)
            {
                return(arc.File.CreateStream(entry.Offset, entry.Size));
            }

            var frame_info = abm.FrameInfo;

            if (frame.Index != 0)
            {
                frame_info             = frame_info.Clone();
                frame_info.FrameOffset = (uint)frame.Offset;
            }
            using (var input = arc.File.CreateStream(0, (uint)arc.File.MaxOffset))
                using (var reader = new AbmReader(input, frame_info))
                {
                    // emulate TGA image
                    var header = new byte[0x12];
                    header[2] = 2;
                    LittleEndian.Pack((ushort)frame_info.Width, header, 0xC);
                    LittleEndian.Pack((ushort)frame_info.Height, header, 0xE);
                    header[0x10] = (byte)reader.BPP;
                    header[0x11] = 0x20;
                    var pixels = reader.Unpack();
                    return(new PrefixStream(header, new MemoryStream(pixels)));
                }
        }
Esempio n. 2
0
        public override ImageData Read(Stream stream, ImageMetaData info)
        {
            var meta = info as AbmImageData;

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

            using (var reader = new AbmReader(stream, meta))
            {
                var         pixels = reader.Unpack();
                PixelFormat format = 32 == reader.BPP ? PixelFormats.Bgra32 : PixelFormats.Bgr24;
                return(ImageData.Create(info, format, null, pixels));
            }
        }
Esempio n. 3
0
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            var abm = arc as AbmArchive;
            var frame = entry as AbmEntry;
            if (null == abm || null == frame)
                return arc.File.CreateStream (entry.Offset, entry.Size);

            var frame_info = abm.FrameInfo;
            if (frame.Index != 0)
            {
                frame_info = frame_info.Clone();
                frame_info.FrameOffset = (uint)frame.Offset;
            }
            using (var input = arc.File.CreateStream (0, (uint)arc.File.MaxOffset))
            using (var reader = new AbmReader (input, frame_info))
            {
                // emulate TGA image
                var header = new byte[0x12];
                header[2] = 2;
                LittleEndian.Pack ((ushort)frame_info.Width,  header, 0xC);
                LittleEndian.Pack ((ushort)frame_info.Height, header, 0xE);
                header[0x10] = (byte)reader.BPP;
                header[0x11] = 0x20;
                var pixels = reader.Unpack();
                return new PrefixStream (header, new MemoryStream (pixels));
            }
        }