Exemplo n.º 1
0
        IImageDecoder BlendAImage(BellArchive arc, Entry entry, AImageReader overlay)
        {
            var header = overlay.ReadHeader();

            if (header[0] != 1)
            {
                return(overlay);
            }
            var scheme = arc.Scheme;
            var dir    = (List <Entry>)arc.Dir;
            int i      = dir.IndexOf(entry);

            while (--i >= 0 && "image" == dir[i].Type)
            {
                using (var input = OpenEntry(arc, dir[i]))
                {
                    int type = input.ReadByte();
                    if (type != 'a')
                    {
                        break;
                    }
                    int id = input.ReadByte();
                    if (id != scheme.Value2)
                    {
                        break;
                    }
                    using (var bin = new BinaryStream(input, dir[i].Name))
                        using (var base_image = new AImageReader(bin, scheme))
                        {
                            var base_header = base_image.ReadHeader();
                            if (1 == base_header[0])
                            {
                                continue;
                            }
                            // check if image width/height are the same
                            if (base_header[3] == header[3] && base_header[4] == header[4])
                            {
                                base_image.Unpack();
                                overlay.Baseline = base_image.Data;
                            }
                            break;
                        }
                }
            }
            return(overlay);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Search archive <paramref name="arc"/> for baseline image.
        /// </summary>
        internal void ReadBaseline(BellArchive arc, Entry entry)
        {
            var header = ReadHeader();

            if (!((header[0] & 1) == 1 && 'd' == this.Type ||
                  header[0] == 1 && 'a' == this.Type))
            {
                return;
            }
            var scheme = arc.Scheme;
            var dir    = (List <Entry>)arc.Dir;
            int i      = dir.IndexOf(entry);

            while (--i >= 0 && "image" == dir[i].Type)
            {
                using (var input = arc.OpenEntry(dir[i]))
                {
                    int type = input.ReadByte();
                    if ('d' == type)
                    {
                        continue;
                    }
                    if ('a' == type)
                    {
                        int id = input.ReadByte();
                        if (id != scheme.Value2)
                        {
                            break;
                        }
                        using (var bin = new BinaryStream(input, dir[i].Name))
                            using (var base_image = new AImageReader(bin, scheme))
                            {
                                var base_header = base_image.ReadHeader();
                                if (1 == base_header[0])
                                {
                                    continue;
                                }
                                // check if image width/height are the same
                                if (base_header[3] == header[3] && base_header[4] == header[4])
                                {
                                    base_image.Unpack();
                                    Baseline = base_image.Data;
                                }
                            }
                    }
                    else if ('b' == type || 'c' == type)
                    {
                        var size_buf = new byte[4];
                        input.Read(size_buf, 0, 4);
                        var decoder = new PngBitmapDecoder(input, BitmapCreateOptions.None,
                                                           BitmapCacheOption.OnLoad);
                        BitmapSource frame = decoder.Frames[0];
                        Info.Width  = (uint)frame.PixelWidth;
                        Info.Height = (uint)frame.PixelHeight;
                        if (frame.Format.BitsPerPixel != 32)
                        {
                            frame = new FormatConvertedBitmap(frame, PixelFormats.Bgra32, null, 0);
                        }
                        int stride = frame.PixelWidth * 4;
                        var pixels = new byte[stride * frame.PixelHeight];
                        frame.CopyPixels(pixels, stride, 0);
                        Baseline = pixels;
                    }
                    break;
                }
            }
        }