From 288a6293116d50ee2acbed1e0592bf7427f53bc5 Mon Sep 17 00:00:00 2001 From: Brandon Wright Date: Sun, 23 Jan 2011 16:25:46 -0600 Subject: [PATCH 1/2] Add high-resolution blending option to GTK+ port. --- gtk/src/gtk_config.cpp | 11 +- gtk/src/gtk_config.h | 6 +- gtk/src/gtk_display.cpp | 45 ++++- gtk/src/gtk_display_driver.h | 2 +- gtk/src/gtk_preferences.cpp | 14 +- gtk/src/gtk_preferences.h | 2 - gtk/src/snes9x.ui | 325 +++++++++++++++++++---------------- 7 files changed, 239 insertions(+), 166 deletions(-) diff --git a/gtk/src/gtk_config.cpp b/gtk/src/gtk_config.cpp index cb3f6cd9..167e07d2 100644 --- a/gtk/src/gtk_config.cpp +++ b/gtk/src/gtk_config.cpp @@ -135,7 +135,7 @@ Snes9xConfig::load_defaults (void) allow_xv = 0; allow_xrandr = 0; force_inverted_byte_order = FALSE; - force_hires = 0; + hires_effect = HIRES_MERGE; pause_emulation_on_switch = 0; num_threads = 2; mute_sound = FALSE; @@ -283,7 +283,7 @@ Snes9xConfig::save_config_file (void) xml_out_int (xml, "aspect_ratio", aspect_ratio); xml_out_int (xml, "scale_method", scale_method); xml_out_int (xml, "overscan", overscan); - xml_out_int (xml, "force_hires", force_hires); + xml_out_int (xml, "hires_effect", hires_effect); xml_out_int (xml, "force_inverted_byte_order", force_inverted_byte_order); xml_out_int (xml, "multithreading", multithreading); xml_out_string (xml, "last_directory", last_directory); @@ -467,7 +467,12 @@ Snes9xConfig::set_option (const char *name, const char *value) } else if (!strcasecmp (name, "force_hires")) { - force_hires = atoi (value); + /* Deprecated */ + } + else if (!strcasecmp (name, "hires_effect")) + { + hires_effect = atoi (value); + hires_effect = CLAMP (hires_effect, 0, 2); } else if (!strcasecmp (name, "scale_method")) { diff --git a/gtk/src/gtk_config.h b/gtk/src/gtk_config.h index 9cee7c30..9e8ec7c0 100644 --- a/gtk/src/gtk_config.h +++ b/gtk/src/gtk_config.h @@ -15,6 +15,10 @@ #define HWA_OPENGL 1 #define HWA_XV 2 +#define HIRES_MERGE 0 +#define HIRES_NORMAL 1 +#define HIRES_SCALE 2 + #define ESC_TOGGLE_MENUBAR 0 #define ESC_EXIT_FULLSCREEN 1 #define ESC_EXIT_SNES9X 2 @@ -63,7 +67,7 @@ class Snes9xConfig unsigned int scale_method; unsigned char overscan; unsigned char multithreading; - unsigned char force_hires; + int hires_effect; unsigned char force_inverted_byte_order; snes_ntsc_setup_t ntsc_setup; diff --git a/gtk/src/gtk_display.cpp b/gtk/src/gtk_display.cpp index 0adfd405..332e7175 100644 --- a/gtk/src/gtk_display.cpp +++ b/gtk/src/gtk_display.cpp @@ -688,6 +688,39 @@ S9xForceHires (void *buffer, return; } +#undef AVERAGE_1555 +#define AVERAGE_1555(el0, el1) (((el0) & (el1)) + ((((el0) ^ (el1)) & 0x7BDE) >> 1)) +static void +S9xMergeHires (void *buffer, + int pitch, + int &width, + int &height) +{ + if (width <= 256) + return; + + for (register int y = 0; y < height; y++) + { + register uint16 *input = (uint16 *) ((uint8 *) buffer + y * pitch); + register uint16 *output = input; + register uint16 l, r; + + l = 0; + for (register int x = 0; x < (width >> 1); x++) + { + r = *input++; + *output++ = AVERAGE_1555 (l, r); + l = r; + + r = *input++; + *output++ = AVERAGE_1555 (l, r); + l = r; + } + } + + return; +} + void filter_2x (void *src, int src_pitch, @@ -1603,11 +1636,19 @@ S9xDeinitUpdate (int width, int height) else height = 224; - if (gui_config->force_hires) + if (gui_config->hires_effect == HIRES_SCALE) { S9xForceHires (GFX.Screen, S9xDisplayDriver::image_width * - S9xDisplayDriver::image_bpp, + S9xDisplayDriver::image_bpp, + width, + height); + } + else if (gui_config->hires_effect == HIRES_MERGE) + { + S9xMergeHires (GFX.Screen, + S9xDisplayDriver::image_width * + S9xDisplayDriver::image_bpp, width, height); } diff --git a/gtk/src/gtk_display_driver.h b/gtk/src/gtk_display_driver.h index a3d9f11c..3aa11742 100644 --- a/gtk/src/gtk_display_driver.h +++ b/gtk/src/gtk_display_driver.h @@ -17,7 +17,7 @@ class S9xDisplayDriver virtual void reconfigure (int width, int height) = 0; /* Namespaced sizing constants */ - static const int image_width = 512; + static const int image_width = 1024; static const int image_height = 478; static const int image_bpp = 2; static const int scaled_max_width = 1024; diff --git a/gtk/src/gtk_preferences.cpp b/gtk/src/gtk_preferences.cpp index f5745938..b2bcb738 100644 --- a/gtk/src/gtk_preferences.cpp +++ b/gtk/src/gtk_preferences.cpp @@ -545,13 +545,6 @@ Snes9xPreferences::Snes9xPreferences (Snes9xConfig *config) : last_toggled = NULL; this->config = config; - size_group[0] = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); - gtk_size_group_add_widget (size_group[0], get_widget ("resolution_combo")); - gtk_size_group_add_widget (size_group[0], get_widget ("scale_method_combo")); - size_group[1] = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); - gtk_size_group_add_widget (size_group[1], get_widget ("change_display_resolution")); - gtk_size_group_add_widget (size_group[1], get_widget ("scale_method_label")); - fix_style (); gtk_widget_realize (window); @@ -563,9 +556,6 @@ Snes9xPreferences::Snes9xPreferences (Snes9xConfig *config) : Snes9xPreferences::~Snes9xPreferences (void) { - g_object_unref (size_group[0]); - g_object_unref (size_group[1]); - return; } @@ -630,7 +620,7 @@ Snes9xPreferences::move_settings_to_dialog (void) set_check ("scale_to_fit", config->scale_to_fit); set_check ("overscan", config->overscan); set_check ("multithreading", config->multithreading); - set_check ("force_hires", config->force_hires); + set_combo ("hires_effect", config->hires_effect); set_check ("maintain_aspect_ratio", config->maintain_aspect_ratio); set_combo ("aspect_ratio", config->aspect_ratio); if (config->sram_directory[0] == '\0') @@ -808,7 +798,7 @@ Snes9xPreferences::get_settings_from_dialog (void) config->maintain_aspect_ratio = get_check ("maintain_aspect_ratio"); config->aspect_ratio = get_combo ("aspect_ratio"); config->scale_method = get_combo ("scale_method_combo"); - config->force_hires = get_check ("force_hires"); + config->hires_effect = get_combo ("hires_effect"); config->force_inverted_byte_order = get_check ("force_inverted_byte_order"); Settings.AutoSaveDelay = get_entry_value ("save_sram_after_sec"); config->multithreading = get_check ("multithreading"); diff --git a/gtk/src/gtk_preferences.h b/gtk/src/gtk_preferences.h index 8e071508..377ba58b 100644 --- a/gtk/src/gtk_preferences.h +++ b/gtk/src/gtk_preferences.h @@ -41,8 +41,6 @@ class Snes9xPreferences : public GtkBuilderWindow private: void get_settings_from_dialog (void); void move_settings_to_dialog (void); - - GtkSizeGroup *size_group[2]; }; #endif /* __GTK_PREFERENCES_H */ diff --git a/gtk/src/snes9x.ui b/gtk/src/snes9x.ui index 8ad3b41e..08882952 100644 --- a/gtk/src/snes9x.ui +++ b/gtk/src/snes9x.ui @@ -1,16 +1,16 @@ - + GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_FOCUS_CHANGE_MASK | GDK_STRUCTURE_MASK | GDK_SUBSTRUCTURE_MASK Snes9x - - - - - - + + + + + + True @@ -32,7 +32,7 @@ True image2 False - + @@ -56,7 +56,7 @@ True image3 False - + @@ -64,7 +64,7 @@ True Open _MultiCart... True - + @@ -77,7 +77,7 @@ True _Load State True - + @@ -85,7 +85,7 @@ True Slot _0 True - + @@ -93,7 +93,7 @@ True Slot _1 True - + @@ -101,7 +101,7 @@ True Slot _2 True - + @@ -109,7 +109,7 @@ True Slot _3 True - + @@ -117,7 +117,7 @@ True Slot _4 True - + @@ -125,7 +125,7 @@ True Slot _5 True - + @@ -133,7 +133,7 @@ True Slot _6 True - + @@ -141,7 +141,7 @@ True Slot _7 True - + @@ -149,7 +149,7 @@ True Slot _8 True - + @@ -162,7 +162,7 @@ True From _File... True - + @@ -174,7 +174,7 @@ True _Save State True - + @@ -182,7 +182,7 @@ True Slot _0 True - + @@ -190,7 +190,7 @@ True Slot _1 True - + @@ -198,7 +198,7 @@ True Slot _2 True - + @@ -206,7 +206,7 @@ True Slot _3 True - + @@ -214,7 +214,7 @@ True Slot _4 True - + @@ -222,7 +222,7 @@ True Slot _5 True - + @@ -230,7 +230,7 @@ True Slot _6 True - + @@ -238,7 +238,7 @@ True Slot _7 True - + @@ -246,7 +246,7 @@ True Slot _8 True - + @@ -259,7 +259,7 @@ True To _File... True - + @@ -278,7 +278,7 @@ True image4 False - + @@ -293,7 +293,7 @@ True image5 False - + @@ -308,7 +308,7 @@ True image18 False - + @@ -329,7 +329,7 @@ True image6 False - + @@ -339,7 +339,7 @@ True image7 False - + @@ -356,7 +356,7 @@ True image8 False - + @@ -367,7 +367,7 @@ True image19 False - + @@ -378,7 +378,7 @@ True image9 False - + @@ -389,7 +389,7 @@ True image10 False - + @@ -404,7 +404,7 @@ True image11 False - + @@ -420,7 +420,7 @@ True image12 False - + @@ -430,7 +430,7 @@ True image13 False - + @@ -442,7 +442,7 @@ True _View True - + @@ -452,7 +452,7 @@ True image14 False - + @@ -460,7 +460,7 @@ True _Status Bar True - + @@ -491,7 +491,7 @@ True _1x True - + @@ -499,7 +499,7 @@ True _2x True - + @@ -507,7 +507,7 @@ True _3x True - + @@ -515,7 +515,7 @@ True _4x True - + @@ -523,7 +523,7 @@ True _5x True - + @@ -544,7 +544,7 @@ True 1x True - + @@ -552,7 +552,7 @@ True 2x True - + @@ -560,7 +560,7 @@ True 3x True - + @@ -568,7 +568,7 @@ True 4x True - + @@ -576,7 +576,7 @@ True 5x True - + @@ -595,7 +595,7 @@ True image15 False - + @@ -621,7 +621,7 @@ True SNES Port 1 True - + @@ -629,7 +629,7 @@ True Joypad True - + @@ -638,7 +638,7 @@ Mouse True joypad1 - + @@ -648,7 +648,7 @@ True True joypad1 - + @@ -660,7 +660,7 @@ True SNES Port 2 True - + @@ -668,7 +668,7 @@ True Joypad True - + @@ -677,7 +677,7 @@ Mouse True joypad2 - + @@ -686,7 +686,7 @@ Multitap True joypad2 - + @@ -696,7 +696,7 @@ True True joypad2 - + @@ -718,7 +718,7 @@ GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK _Cheats... True - + @@ -734,7 +734,7 @@ True image16 False - + @@ -754,11 +754,11 @@ True True GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_STRUCTURE_MASK | GDK_SUBSTRUCTURE_MASK - - - - - + + + + + 1 @@ -783,8 +783,8 @@ 480 dialog True - - + + True @@ -800,7 +800,7 @@ 0 1 0 - + True @@ -1011,20 +1011,6 @@ 1 - - - Force SNES-hires output - True - True - False - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Detects frames that are not output by Snes9x in hires, and scales them - True - - - 2 - - True @@ -1069,6 +1055,41 @@ + + 2 + + + + + True + 12 + + + True + High-resolution effect: + + + False + 0 + + + + + True + liststore15 + + + + 0 + + + + + False + 1 + + + 3 @@ -1092,7 +1113,7 @@ True liststore12 - + @@ -1101,6 +1122,7 @@ + False 1 @@ -1170,7 +1192,7 @@ True True True - + False @@ -1183,7 +1205,7 @@ True True True - + False @@ -1196,7 +1218,7 @@ True True True - + False @@ -1209,7 +1231,7 @@ True True True - + False @@ -1701,7 +1723,7 @@ True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK liststore9 - + @@ -1754,7 +1776,6 @@ True False Use glFinish to reduce latency by one frame. May cause 100% CPU usage in faulty graphics drivers - False True @@ -1844,7 +1865,6 @@ True True False - False 0 True @@ -1857,7 +1877,7 @@ True True - + True @@ -1870,7 +1890,7 @@ True True True - + False @@ -2552,10 +2572,10 @@ True True False - + gtk-clear - - + + 1 @@ -2567,10 +2587,10 @@ True True False - + gtk-clear - - + + 1 @@ -2584,10 +2604,10 @@ True True False - + gtk-clear - - + + 1 @@ -2601,10 +2621,10 @@ True True False - + gtk-clear - - + + 1 @@ -2618,10 +2638,10 @@ True True False - + gtk-clear - - + + 1 @@ -2636,7 +2656,7 @@ True True True - + 2 @@ -2651,7 +2671,7 @@ True True True - + 2 @@ -2668,7 +2688,7 @@ True True True - + 2 @@ -2685,7 +2705,7 @@ True True True - + 2 @@ -2702,7 +2722,7 @@ True True True - + 2 @@ -2823,7 +2843,7 @@ True True Automatically save the game's SRAM at this interval. Setting this to 0 will only save when quitting or changing ROMs - + 5 1 @@ -2920,7 +2940,7 @@ True liststore3 - + @@ -2949,7 +2969,7 @@ True True True - + False @@ -2999,7 +3019,7 @@ True True True - + False @@ -3032,7 +3052,7 @@ True True - + True @@ -3931,7 +3951,7 @@ True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK True - + False @@ -4069,7 +4089,7 @@ True True - + True @@ -5789,7 +5809,7 @@ True False True - + False @@ -5818,9 +5838,8 @@ True True True - False True - + False @@ -6280,6 +6299,23 @@ + + + + + + + + Blend at pixel boundaries + + + Output directly + + + Scale low-resolution screens + + + 512 350 @@ -6379,7 +6415,7 @@ True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK True - + False @@ -6395,7 +6431,7 @@ True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK True - + False @@ -6493,7 +6529,7 @@ True True True - + False @@ -6505,7 +6541,7 @@ True True True - + True @@ -6628,7 +6664,7 @@ True True connect_radio - + 2 @@ -7051,44 +7087,44 @@ 1 + 1 1 60 - 1 1 1 + 6096 1 9999 - 6096 1 1 + 6096 1 9999 - 6096 1 1 + 50 1 100 - 50 1 10 + 31990 31500 32500 - 31990 1 10 + 2 2 256 - 2 1 1 @@ -7123,9 +7159,9 @@ 0.10000000000000001 + 1.0408340855860843e-17 -1 1 - 1.0408340855860843e-17 0.01 0.10000000000000001 @@ -7154,9 +7190,9 @@ 0.10000000000000001 + 2 2 8 - 2 1 1 @@ -7421,7 +7457,6 @@ True True True - False True From 7c6a0f58d1b45870a414fbbaba4d9d1cc6674318 Mon Sep 17 00:00:00 2001 From: Brandon Wright Date: Sun, 23 Jan 2011 17:07:22 -0600 Subject: [PATCH 2/2] Choose a sane default for filter mode. --- gtk/src/gtk_config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gtk/src/gtk_config.cpp b/gtk/src/gtk_config.cpp index 167e07d2..c0f3bde5 100644 --- a/gtk/src/gtk_config.cpp +++ b/gtk/src/gtk_config.cpp @@ -135,7 +135,7 @@ Snes9xConfig::load_defaults (void) allow_xv = 0; allow_xrandr = 0; force_inverted_byte_order = FALSE; - hires_effect = HIRES_MERGE; + hires_effect = HIRES_NORMAL; pause_emulation_on_switch = 0; num_threads = 2; mute_sound = FALSE;