Пример #1
0
        Stream BlendEntry(ArcFile arc, VirtualCharEntry entry)
        {
            using (var base_png = OpenEntry(arc, arc.Dir.First()))
                using (var overlay_png = OpenEntry(arc, entry.Source))
                {
                    var decoder    = new PngBitmapDecoder(base_png, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                    var base_frame = decoder.Frames[0];
                    decoder = new PngBitmapDecoder(overlay_png, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                    var overlay_frame = decoder.Frames[0];
                    int overlay_x     = entry.Source.OffsetX;
                    int overlay_y     = entry.Source.OffsetY;
                    var visual        = new DrawingVisual();
                    using (var context = visual.RenderOpen())
                    {
                        context.DrawImage(base_frame, new Rect(0, 0, base_frame.PixelWidth, base_frame.PixelHeight));
                        context.DrawImage(overlay_frame, new Rect(overlay_x, overlay_y, overlay_frame.PixelWidth, overlay_frame.PixelHeight));
                    }
                    var bmp = new RenderTargetBitmap(base_frame.PixelWidth, base_frame.PixelHeight,
                                                     base_frame.DpiX, base_frame.DpiY, PixelFormats.Pbgra32);
                    bmp.Render(visual);

                    var encoder = new PngBitmapEncoder();
                    encoder.Frames.Add(BitmapFrame.Create(bmp));

                    var mem = new MemoryStream();
                    encoder.Save(mem);
                    mem.Position = 0;
                    return(mem);
                }
        }
Пример #2
0
        public override ArcFile TryOpen(ArcView file)
        {
            uint index_offset = file.View.ReadUInt32(4);
            int  count        = file.View.ReadInt32(index_offset) + 1;

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

            string base_name = Path.GetFileNameWithoutExtension(file.Name);

            var dir = new List <Entry> (count);

            dir.Add(new Entry {
                Name = string.Format("{0}#0.png", base_name),
                Type = "image", Offset = 8, Size = index_offset - 8
            });
            index_offset += 4;
            for (int i = 1; i < count; ++i)
            {
                uint name_length = file.View.ReadByte(index_offset++);
                var  name        = file.View.ReadString(index_offset, name_length);
                uint size        = file.View.ReadUInt32(index_offset + name_length);
                index_offset += name_length + 4;
                if (size > 8)
                {
                    var entry = new CharEntry
                    {
                        Name    = string.Format("{0}#{1}.png", base_name, name),
                        Type    = "image",
                        Offset  = index_offset + 8,
                        Size    = size - 8,
                        OffsetX = file.View.ReadInt16(index_offset),
                        OffsetY = file.View.ReadInt16(index_offset + 2),
                        //Width  = file.View.ReadUInt16 (index_offset+4),
                        //Height = file.View.ReadUInt16 (index_offset+6),
                    };
                    dir.Add(entry);
                    var virt_entry = new VirtualCharEntry {
                        Name   = string.Format("{0}#blend#{1}.png", base_name, name),
                        Type   = "image",
                        Source = entry,
                        Offset = 0,
                    };
                    dir.Add(virt_entry);
                }
                index_offset += size;
            }
            return(new ArcFile(file, this, dir));
        }