Debugger: Use Format32bppPArgb pixel format for better draw performance

This commit is contained in:
Sour 2019-06-24 11:45:40 -04:00
parent fc5005e857
commit 237718c6b8
8 changed files with 21 additions and 17 deletions

View file

@ -11,6 +11,7 @@ using System.Runtime.InteropServices;
using Mesen.GUI.Controls;
using Mesen.GUI.Forms;
using Mesen.GUI.Config;
using System.Drawing.Imaging;
namespace Mesen.GUI.Debugger
{
@ -114,14 +115,14 @@ namespace Mesen.GUI.Debugger
int picHeight = _baseHeight;
if(_screenBitmap == null || _screenBitmap.Height != picHeight) {
_screenBitmap = new Bitmap(_baseWidth, picHeight);
_overlayBitmap = new Bitmap(_baseWidth, picHeight);
_displayBitmap = new Bitmap(_baseWidth, picHeight);
_screenBitmap = new Bitmap(_baseWidth, picHeight, PixelFormat.Format32bppPArgb);
_overlayBitmap = new Bitmap(_baseWidth, picHeight, PixelFormat.Format32bppPArgb);
_displayBitmap = new Bitmap(_baseWidth, picHeight, PixelFormat.Format32bppPArgb);
}
GCHandle handle = GCHandle.Alloc(this._pictureData, GCHandleType.Pinned);
try {
Bitmap source = new Bitmap(_baseWidth, _baseHeight, _baseWidth*4, System.Drawing.Imaging.PixelFormat.Format32bppArgb, handle.AddrOfPinnedObject());
Bitmap source = new Bitmap(_baseWidth, _baseHeight, _baseWidth*4, PixelFormat.Format32bppPArgb, handle.AddrOfPinnedObject());
using(Graphics g = Graphics.FromImage(_screenBitmap)) {
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;

View file

@ -8,6 +8,7 @@ using System.Windows.Forms.VisualStyles;
using System.Text;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Drawing.Imaging;
namespace Be.Windows.Forms
{
@ -2837,7 +2838,7 @@ namespace Be.Windows.Forms
Point dimensions = new Point(rec.Width, rec.Height);
Bitmap bitmap;
if(!_shadowSelectionCache.TryGetValue(dimensions, out bitmap)) {
bitmap = new Bitmap(rec.Width, rec.Height);
bitmap = new Bitmap(rec.Width, rec.Height, PixelFormat.Format32bppPArgb);
using(Graphics bitmapGraphics = Graphics.FromImage(bitmap)) {
using(SolidBrush shadowSelectionBrush = new SolidBrush(_shadowSelectionColor)) {
bitmapGraphics.FillRectangle(shadowSelectionBrush, 0, 0, rec.Width, rec.Height);

View file

@ -37,7 +37,7 @@ namespace Mesen.GUI.Debugger
set
{
_paletteScale = value;
_paletteImage = new Bitmap(PaletteScale * 16, PaletteScale * 16, PixelFormat.Format32bppArgb);
_paletteImage = new Bitmap(PaletteScale * 16, PaletteScale * 16, PixelFormat.Format32bppPArgb);
}
}
@ -140,7 +140,7 @@ namespace Mesen.GUI.Debugger
using(Graphics g = Graphics.FromImage(_paletteImage)) {
GCHandle handle = GCHandle.Alloc(argbPalette, GCHandleType.Pinned);
Bitmap source = new Bitmap(16, 16, 16 * 4, PixelFormat.Format32bppArgb, handle.AddrOfPinnedObject());
Bitmap source = new Bitmap(16, 16, 16 * 4, PixelFormat.Format32bppPArgb, handle.AddrOfPinnedObject());
try {
g.InterpolationMode = InterpolationMode.NearestNeighbor;
g.SmoothingMode = SmoothingMode.None;

View file

@ -44,7 +44,7 @@ namespace Mesen.GUI.Debugger
_notifListener.OnNotification += OnNotificationReceived;
_previewData = new byte[256 * 240 * 4];
_previewImage = new Bitmap(256, 240, PixelFormat.Format32bppArgb);
_previewImage = new Bitmap(256, 240, PixelFormat.Format32bppPArgb);
ctrlImagePanel.ImageSize = new Size(256, 240);
ctrlImagePanel.Image = _previewImage;
@ -142,7 +142,7 @@ namespace Mesen.GUI.Debugger
using(Graphics g = Graphics.FromImage(_previewImage)) {
GCHandle handle = GCHandle.Alloc(_previewData, GCHandleType.Pinned);
Bitmap source = new Bitmap(256, 240, 4 * 256, PixelFormat.Format32bppArgb, handle.AddrOfPinnedObject());
Bitmap source = new Bitmap(256, 240, 4 * 256, PixelFormat.Format32bppPArgb, handle.AddrOfPinnedObject());
g.DrawImage(source, 0, 0);
handle.Free();
}

View file

@ -47,7 +47,7 @@ namespace Mesen.GUI.Debugger
_notifListener.OnNotification += OnNotificationReceived;
_tileData = new byte[512 * 512 * 4];
_tileImage = new Bitmap(512, 512, PixelFormat.Format32bppArgb);
_tileImage = new Bitmap(512, 512, PixelFormat.Format32bppPArgb);
ctrlImagePanel.Image = _tileImage;
BaseConfigForm.InitializeComboBox(cboFormat, typeof(TileFormat));
@ -216,13 +216,13 @@ namespace Mesen.GUI.Debugger
int mapHeight = tileCount / _options.Width * 8;
if(_tileImage.Width != mapWidth || _tileImage.Height != mapHeight) {
_tileImage = new Bitmap(mapWidth, mapHeight, PixelFormat.Format32bppArgb);
_tileImage = new Bitmap(mapWidth, mapHeight, PixelFormat.Format32bppPArgb);
ctrlImagePanel.Image = _tileImage;
}
using(Graphics g = Graphics.FromImage(_tileImage)) {
GCHandle handle = GCHandle.Alloc(_tileData, GCHandleType.Pinned);
Bitmap source = new Bitmap(mapWidth, mapHeight, 4 * mapWidth, PixelFormat.Format32bppArgb, handle.AddrOfPinnedObject());
Bitmap source = new Bitmap(mapWidth, mapHeight, 4 * mapWidth, PixelFormat.Format32bppPArgb, handle.AddrOfPinnedObject());
try {
g.DrawImage(source, 0, 0);
} finally {

View file

@ -46,7 +46,7 @@ namespace Mesen.GUI.Debugger
_notifListener.OnNotification += OnNotificationReceived;
_tilemapData = new byte[1024 * 1024 * 4];
_tilemapImage = new Bitmap(1024, 1024, PixelFormat.Format32bppArgb);
_tilemapImage = new Bitmap(1024, 1024, PixelFormat.Format32bppPArgb);
ctrlImagePanel.Image = _tilemapImage;
InitShortcuts();
@ -197,12 +197,12 @@ namespace Mesen.GUI.Debugger
int mapWidth = GetWidth();
int mapHeight = GetHeight();
if(_tilemapImage.Width != mapWidth || _tilemapImage.Height != mapHeight) {
_tilemapImage = new Bitmap(mapWidth, mapHeight, PixelFormat.Format32bppArgb);
_tilemapImage = new Bitmap(mapWidth, mapHeight, PixelFormat.Format32bppPArgb);
ctrlImagePanel.Image = _tilemapImage;
}
using(Graphics g = Graphics.FromImage(_tilemapImage)) {
GCHandle handle = GCHandle.Alloc(_tilemapData, GCHandleType.Pinned);
Bitmap source = new Bitmap(mapWidth, mapHeight, 4 * 1024, PixelFormat.Format32bppArgb, handle.AddrOfPinnedObject());
Bitmap source = new Bitmap(mapWidth, mapHeight, 4 * 1024, PixelFormat.Format32bppPArgb, handle.AddrOfPinnedObject());
g.DrawImage(source, 0, 0);
handle.Free();
}

View file

@ -9,6 +9,7 @@ using System.Threading.Tasks;
using System.Windows.Forms;
using Mesen.GUI.Config;
using Mesen.GUI.Controls;
using System.Drawing.Imaging;
namespace Mesen.GUI.Forms.Config
{
@ -35,7 +36,7 @@ namespace Mesen.GUI.Forms.Config
{
float xFactor = picBackground.Width / 585f;
float yFactor = picBackground.Height / 253f;
Bitmap bitmap = new Bitmap(picBackground.Width, picBackground.Height);
Bitmap bitmap = new Bitmap(picBackground.Width, picBackground.Height, PixelFormat.Format32bppPArgb);
using(Graphics g = Graphics.FromImage(bitmap)) {
g.ScaleTransform(xFactor, yFactor);
using(Pen pen = new Pen(Color.LightGray, 2f)) {

View file

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -139,7 +140,7 @@ namespace Mesen.GUI.Forms.Config
private void UpdateOverscanImage(PictureBox picture, int top, int bottom, int left, int right)
{
Bitmap overscan = new Bitmap(picture.Width - 2, picture.Height - 2);
Bitmap overscan = new Bitmap(picture.Width - 2, picture.Height - 2, PixelFormat.Format32bppPArgb);
using(Graphics g = Graphics.FromImage(overscan)) {
g.Clear(Color.DarkGray);