示例#1
0
文件: ImageGDT.cs 项目: zxc120/GARbro
 BitmapSource ReadBitmapSource(IBinaryStream file, GdtMetaData info)
 {
     using (var bmp = new StreamRegion(file.AsStream, info.BitmapOffset, true))
     {
         var decoder = new BmpBitmapDecoder(bmp,
                                            BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
         return(decoder.Frames[0]);
     }
 }
示例#2
0
        BitmapSource BlendBaseLine(BitmapSource overlay, GdtMetaData meta)
        {
            string base_name = VFS.ChangeFileName(meta.FileName, meta.BaseLine);

            if (!VFS.FileExists(base_name))
            {
                base_name += ".gdt";
                if (!VFS.FileExists(base_name))
                {
                    return(overlay);
                }
            }
            using (var base_file = VFS.OpenBinaryStream(base_name))
            {
                var base_info = ReadMetaData(base_file) as GdtMetaData;
                if (null == base_info)
                {
                    return(overlay);
                }
                var base_image = ReadBitmapSource(base_file, base_info);
                if (base_image.Format.BitsPerPixel < 24)
                {
                    base_image = new FormatConvertedBitmap(base_image, PixelFormats.Bgr32, null, 0);
                }
                var canvas     = new WriteableBitmap(base_image);
                int canvas_bpp = canvas.Format.BitsPerPixel;
                if (canvas_bpp != overlay.Format.BitsPerPixel)
                {
                    overlay = new FormatConvertedBitmap(overlay, canvas.Format, null, 0);
                }
                canvas.Lock();
                unsafe
                {
                    byte *buffer         = (byte *)canvas.BackBuffer;
                    int   canvas_stride  = canvas.BackBufferStride;
                    int   canvas_size    = canvas_stride * canvas.PixelHeight;
                    int   overlay_stride = (overlay.PixelWidth * canvas_bpp + 7) / 8;
                    int   overlay_size   = overlay_stride * overlay.PixelHeight;
                    int   pos            = meta.OffsetY * canvas_stride + meta.OffsetX * canvas_bpp / 8;
                    overlay.CopyPixels(Int32Rect.Empty, (IntPtr)(buffer + pos), canvas_size - pos, canvas_stride);
                }
                var rect = new Int32Rect(meta.OffsetX, meta.OffsetY, overlay.PixelWidth, overlay.PixelHeight);
                canvas.AddDirtyRect(rect);
                canvas.Unlock();
                return(canvas);
            }
        }