From d31dc7c8d4d7c75fbf272e57cdb4dd787451d8cf Mon Sep 17 00:00:00 2001 From: bgk Date: Mon, 27 Oct 2008 20:52:37 +0000 Subject: [PATCH] GTK : Filter code cleanup --- src/gtk/displayconfig.cpp | 42 ++----------------- src/gtk/filters.cpp | 87 ++++++++++++++++++++++++++++++--------- src/gtk/filters.h | 37 +++-------------- src/gtk/screenarea.cpp | 6 +-- src/gtk/screenarea.h | 4 +- src/gtk/window.cpp | 2 +- 6 files changed, 83 insertions(+), 95 deletions(-) diff --git a/src/gtk/displayconfig.cpp b/src/gtk/displayconfig.cpp index 25216640..dab7ec20 100644 --- a/src/gtk/displayconfig.cpp +++ b/src/gtk/displayconfig.cpp @@ -33,40 +33,6 @@ DisplayConfigDialog::DisplayConfigDialog(GtkDialog* _pstDialog, const Glib::RefP Gtk::Dialog(_pstDialog), m_poConfig(0) { - //TODO Move to filters.h - struct - { - const char * m_csName; - const EFilter2x m_eFilter; - } - astFilter[] = - { - { "None", FilterNone }, - { "2xSaI", Filter2xSaI }, - { "Super 2xSaI", FilterSuper2xSaI }, - { "Super Eagle", FilterSuperEagle }, - { "Pixelate", FilterPixelate }, - { "AdvanceMAME Scale2x", FilterAdMame2x }, - { "Bilinear", FilterBilinear }, - { "Bilinear Plus", FilterBilinearPlus }, - { "Scanlines", FilterScanlines }, - { "TV Mode", FilterScanlinesTV }, - { "hq2x", FilterHq2x }, - { "lq2x", FilterLq2x } - }; - - struct - { - const char * m_csName; - const EFilterIB m_eFilterIB; - } - astFilterIB[] = - { - { "None", FilterIBNone }, - { "Smart interframe blending", FilterIBSmart }, - { "Interframe motion blur", FilterIBMotionBlur } - }; - refBuilder->get_widget("FiltersComboBox", m_poFiltersComboBox); refBuilder->get_widget("IBFiltersComboBox", m_poIBFiltersComboBox); refBuilder->get_widget("OutputOpenGL", m_poOutputOpenGLRadioButton); @@ -84,20 +50,20 @@ DisplayConfigDialog::DisplayConfigDialog(GtkDialog* _pstDialog, const Glib::RefP Glib::RefPtr poFiltersListStore; poFiltersListStore = Glib::RefPtr::cast_static(refBuilder->get_object("FiltersListStore")); - for (guint i = 0; i < G_N_ELEMENTS(astFilter); i++) + for (guint i = FirstFilter; i <= LastFilter; i++) { Gtk::TreeModel::Row row = *(poFiltersListStore->append()); - row->set_value(0, std::string(astFilter[i].m_csName)); + row->set_value(0, std::string(pcsGetFilterName((EFilter)i))); } // Populate the interframe blending filters combobox Glib::RefPtr poIBFiltersListStore; poIBFiltersListStore = Glib::RefPtr::cast_static(refBuilder->get_object("IBFiltersListStore")); - for (guint i = 0; i < G_N_ELEMENTS(astFilterIB); i++) + for (guint i = FirstFilterIB; i <= LastFilterIB; i++) { Gtk::TreeModel::Row row = *(poIBFiltersListStore->append()); - row->set_value(0, std::string(astFilterIB[i].m_csName)); + row->set_value(0, std::string(pcsGetFilterIBName((EFilterIB)i))); } } diff --git a/src/gtk/filters.cpp b/src/gtk/filters.cpp index 75e465de..d139600d 100644 --- a/src/gtk/filters.cpp +++ b/src/gtk/filters.cpp @@ -18,40 +18,87 @@ #include "filters.h" +void _2xSaI (u8 *, u32, u8 *, u8 *, u32, int, int); +void _2xSaI32 (u8 *, u32, u8 *, u8 *, u32, int, int); +void Super2xSaI (u8 *, u32, u8 *, u8 *, u32, int, int); +void Super2xSaI32 (u8 *, u32, u8 *, u8 *, u32, int, int); +void SuperEagle (u8 *, u32, u8 *, u8 *, u32, int, int); +void SuperEagle32 (u8 *, u32, u8 *, u8 *, u32, int, int); +void Pixelate (u8 *, u32, u8 *, u8 *, u32, int, int); +void Pixelate32 (u8 *, u32, u8 *, u8 *, u32, int, int); +void AdMame2x (u8 *, u32, u8 *, u8 *, u32, int, int); +void AdMame2x32 (u8 *, u32, u8 *, u8 *, u32, int, int); +void Bilinear (u8 *, u32, u8 *, u8 *, u32, int, int); +void Bilinear32 (u8 *, u32, u8 *, u8 *, u32, int, int); +void BilinearPlus (u8 *, u32, u8 *, u8 *, u32, int, int); +void BilinearPlus32(u8 *, u32, u8 *, u8 *, u32, int, int); +void Scanlines (u8 *, u32, u8 *, u8 *, u32, int, int); +void Scanlines32 (u8 *, u32, u8 *, u8 *, u32, int, int); +void ScanlinesTV (u8 *, u32, u8 *, u8 *, u32, int, int); +void ScanlinesTV32 (u8 *, u32, u8 *, u8 *, u32, int, int); +void hq2x (u8 *, u32, u8 *, u8 *, u32, int, int); +void hq2x32 (u8 *, u32, u8 *, u8 *, u32, int, int); +void lq2x (u8 *, u32, u8 *, u8 *, u32, int, int); +void lq2x32 (u8 *, u32, u8 *, u8 *, u32, int, int); + +void SmartIB (u8 *, u32, int, int); +void SmartIB32 (u8 *, u32, int, int); +void MotionBlurIB (u8 *, u32, int, int); +void MotionBlurIB32(u8 *, u32, int, int); + namespace VBA { -static const Filter2x apvFilters2x[][2] = +struct { + char m_csName[30]; + int m_iEnlargeFactor; + Filter m_apvFunc[2]; +} +static const astFilters[] = { - { NULL, NULL }, - { _2xSaI, _2xSaI32 }, - { Super2xSaI, Super2xSaI32 }, - { SuperEagle, SuperEagle32 }, - { Pixelate, Pixelate32 }, - { AdMame2x, AdMame2x32 }, - { Bilinear, Bilinear32 }, - { BilinearPlus, BilinearPlus32 }, - { Scanlines, Scanlines32 }, - { ScanlinesTV, ScanlinesTV32 }, - { hq2x, hq2x32 }, - { lq2x, lq2x32 } + { "None", 1, { NULL, NULL } }, + { "2xSaI", 2, { _2xSaI, _2xSaI32 } }, + { "Super 2xSaI", 2, { Super2xSaI, Super2xSaI32 } }, + { "Super Eagle", 2, { SuperEagle, SuperEagle32 } }, + { "Pixelate", 2, { Pixelate, Pixelate32 } }, + { "AdvanceMAME Scale2x", 2, { AdMame2x, AdMame2x32 } }, + { "Bilinear", 2, { Bilinear, Bilinear32 } }, + { "Bilinear Plus", 2, { BilinearPlus, BilinearPlus32 } }, + { "Scanlines", 2, { Scanlines, Scanlines32 } }, + { "TV Mode", 2, { ScanlinesTV, ScanlinesTV32 } }, + { "hq2x", 2, { hq2x, hq2x32 } }, + { "lq2x", 2, { lq2x, lq2x32 } } }; -static const FilterIB apvFiltersIB[][2] = +struct { + char m_csName[30]; + FilterIB m_apvFunc[2]; +} +static const astFiltersIB[] = { - { NULL, NULL }, - { SmartIB, SmartIB32 }, - { MotionBlurIB, MotionBlurIB32 } + { "None", { NULL, NULL } }, + { "Smart interframe blending", { SmartIB, SmartIB32 } }, + { "Interframe motion blur", { MotionBlurIB, MotionBlurIB32 } } }; -Filter2x pvGetFilter2x(EFilter2x _eFilter2x, EFilterDepth _eDepth) +Filter pvGetFilter(EFilter _eFilter, EFilterDepth _eDepth) { - return apvFilters2x[_eFilter2x][_eDepth]; + return astFilters[_eFilter].m_apvFunc[_eDepth]; +} + +char* pcsGetFilterName(const EFilter _eFilter) +{ + return (char*)astFilters[_eFilter].m_csName; } FilterIB pvGetFilterIB(EFilterIB _eFilterIB, EFilterDepth _eDepth) { - return apvFiltersIB[_eFilterIB][_eDepth]; + return astFiltersIB[_eFilterIB].m_apvFunc[_eDepth]; +} + +char* pcsGetFilterIBName(const EFilterIB _eFilterIB) +{ + return (char*)astFiltersIB[_eFilterIB].m_csName; } } // namespace VBA diff --git a/src/gtk/filters.h b/src/gtk/filters.h index f174e253..30ded2c9 100644 --- a/src/gtk/filters.h +++ b/src/gtk/filters.h @@ -24,41 +24,13 @@ int Init_2xSaI(u32); -void _2xSaI (u8 *, u32, u8 *, u8 *, u32, int, int); -void _2xSaI32 (u8 *, u32, u8 *, u8 *, u32, int, int); -void Super2xSaI (u8 *, u32, u8 *, u8 *, u32, int, int); -void Super2xSaI32 (u8 *, u32, u8 *, u8 *, u32, int, int); -void SuperEagle (u8 *, u32, u8 *, u8 *, u32, int, int); -void SuperEagle32 (u8 *, u32, u8 *, u8 *, u32, int, int); -void Pixelate (u8 *, u32, u8 *, u8 *, u32, int, int); -void Pixelate32 (u8 *, u32, u8 *, u8 *, u32, int, int); -void AdMame2x (u8 *, u32, u8 *, u8 *, u32, int, int); -void AdMame2x32 (u8 *, u32, u8 *, u8 *, u32, int, int); -void Bilinear (u8 *, u32, u8 *, u8 *, u32, int, int); -void Bilinear32 (u8 *, u32, u8 *, u8 *, u32, int, int); -void BilinearPlus (u8 *, u32, u8 *, u8 *, u32, int, int); -void BilinearPlus32(u8 *, u32, u8 *, u8 *, u32, int, int); -void Scanlines (u8 *, u32, u8 *, u8 *, u32, int, int); -void Scanlines32 (u8 *, u32, u8 *, u8 *, u32, int, int); -void ScanlinesTV (u8 *, u32, u8 *, u8 *, u32, int, int); -void ScanlinesTV32 (u8 *, u32, u8 *, u8 *, u32, int, int); -void hq2x (u8 *, u32, u8 *, u8 *, u32, int, int); -void hq2x32 (u8 *, u32, u8 *, u8 *, u32, int, int); -void lq2x (u8 *, u32, u8 *, u8 *, u32, int, int); -void lq2x32 (u8 *, u32, u8 *, u8 *, u32, int, int); - -void SmartIB (u8 *, u32, int, int); -void SmartIB32 (u8 *, u32, int, int); -void MotionBlurIB (u8 *, u32, int, int); -void MotionBlurIB32(u8 *, u32, int, int); - namespace VBA { -typedef void (*Filter2x)(u8 *, u32, u8 *, u8 *, u32, int, int); +typedef void (*Filter)(u8 *, u32, u8 *, u8 *, u32, int, int); typedef void (*FilterIB)(u8 *, u32, int, int); -enum EFilter2x +enum EFilter { FirstFilter, FilterNone = FirstFilter, @@ -91,8 +63,11 @@ enum EFilterDepth FilterDepth32 }; -Filter2x pvGetFilter2x(EFilter2x _eFilter2x, EFilterDepth _eDepth); +Filter pvGetFilter(EFilter _eFilter, EFilterDepth _eDepth); +char* pcsGetFilterName(const EFilter _eFilter); + FilterIB pvGetFilterIB(EFilterIB _eFilterIB, EFilterDepth _eDepth); +char* pcsGetFilterIBName(const EFilterIB _eFilterIB); } // namespace VBA diff --git a/src/gtk/screenarea.cpp b/src/gtk/screenarea.cpp index fb5ce877..04f7eb9d 100644 --- a/src/gtk/screenarea.cpp +++ b/src/gtk/screenarea.cpp @@ -92,16 +92,16 @@ void ScreenArea::vSetScale(int _iScale) if (_iScale == 1) { - vSetFilter2x(FilterNone); + vSetFilter(FilterNone); } m_iScale = _iScale; vUpdateSize(); } -void ScreenArea::vSetFilter2x(EFilter2x _eFilter2x) +void ScreenArea::vSetFilter(EFilter _eFilter) { - m_vFilter2x = pvGetFilter2x(_eFilter2x, FilterDepth32); + m_vFilter2x = pvGetFilter(_eFilter, FilterDepth32); m_iFilterScale = 1; if (m_vFilter2x != NULL) diff --git a/src/gtk/screenarea.h b/src/gtk/screenarea.h index 1bd05976..f43a6dfd 100644 --- a/src/gtk/screenarea.h +++ b/src/gtk/screenarea.h @@ -36,7 +36,7 @@ public: void vSetSize(int _iWidth, int _iHeight); void vSetScale(int _iScale); - void vSetFilter2x(EFilter2x _eFilter2x); + void vSetFilter(EFilter _eFilter); void vSetFilterIB(EFilterIB _eFilterIB); virtual void vDrawPixels(u8 * _puiData); virtual void vDrawBlackScreen() = 0; @@ -54,7 +54,7 @@ protected: int m_iFilterScale; int m_iAreaWidth; int m_iAreaHeight; - Filter2x m_vFilter2x; + Filter m_vFilter2x; FilterIB m_vFilterIB; u32 * m_puiPixels; u8 * m_puiDelta; diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index b6e77cdc..b75675a6 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -971,7 +971,7 @@ void Window::vSaveConfig(const std::string & _rsFile) void Window::vApplyConfigFilter() { int iFilter = m_poDisplayConfig->oGetKey("filter2x"); - m_poScreenArea->vSetFilter2x((EFilter2x)iFilter); + m_poScreenArea->vSetFilter((EFilter)iFilter); if (emulating) { vDrawScreen();