From 2c2f2230cdb49c0901331f179773263c6a64527a Mon Sep 17 00:00:00 2001 From: Kimmo Hoikka Date: Tue, 27 Jun 2017 14:15:24 +0100 Subject: [PATCH] Modified resampler.cpp to use enums for filter types rather than char* - removed ununsed filter name getter Change-Id: Ifbede1d64e9bcf9c49086a64c5a8de3195b85ff2 --- .../portable/image-operations.cpp | 2 +- third-party/image-resampler/resampler.cpp | 57 ++++++++-------------- third-party/image-resampler/resampler.h | 33 ++++++++++--- 3 files changed, 47 insertions(+), 45 deletions(-) diff --git a/platform-abstractions/portable/image-operations.cpp b/platform-abstractions/portable/image-operations.cpp index c301fcc..f9856cf 100644 --- a/platform-abstractions/portable/image-operations.cpp +++ b/platform-abstractions/portable/image-operations.cpp @@ -49,7 +49,7 @@ const unsigned int MAXIMUM_TARGET_BITMAP_SIZE( ( 1u << 16 ) - 1 ); // Constants used by the ImageResampler. const float DEFAULT_SOURCE_GAMMA = 1.75f; ///< Default source gamma value used in the Resampler() function. Partial gamma correction looks better on mips. Set to 1.0 to disable gamma correction. const float FILTER_SCALE = 1.f; ///< Default filter scale value used in the Resampler() function. Filter scale - values < 1.0 cause aliasing, but create sharper looking mips. -const char* const FILTER_TYPE = "lanczos4"; ///< Default filter used in the Resampler() function. Possible Lanczos filters are: lanczos3, lanczos4, lanczos6, lanczos12 +const Resampler::Filter FILTER_TYPE = Resampler::LANCZOS4; ///< Default filter used in the Resampler() function. Possible Lanczos filters are: lanczos3, lanczos4, lanczos6, lanczos12 using Integration::Bitmap; using Integration::BitmapPtr; diff --git a/third-party/image-resampler/resampler.cpp b/third-party/image-resampler/resampler.cpp index 045549c..c602466 100644 --- a/third-party/image-resampler/resampler.cpp +++ b/third-party/image-resampler/resampler.cpp @@ -362,27 +362,27 @@ static Resample_Real kaiser_filter(Resample_Real t) // filters[] is a list of all the available filter functions. static struct { - char name[32]; + Resampler::Filter name; Resample_Real (*func)(Resample_Real t); Resample_Real support; } g_filters[] = { - { "box", box_filter, BOX_FILTER_SUPPORT }, - { "tent", tent_filter, TENT_FILTER_SUPPORT }, - { "bell", bell_filter, BELL_SUPPORT }, - { "b-spline", B_spline_filter, B_SPLINE_SUPPORT }, - { "mitchell", mitchell_filter, MITCHELL_SUPPORT }, - { "lanczos3", lanczos3_filter, LANCZOS3_SUPPORT }, - { "blackman", blackman_filter, BLACKMAN_SUPPORT }, - { "lanczos4", lanczos4_filter, LANCZOS4_SUPPORT }, - { "lanczos6", lanczos6_filter, LANCZOS6_SUPPORT }, - { "lanczos12", lanczos12_filter, LANCZOS12_SUPPORT }, - { "kaiser", kaiser_filter, KAISER_SUPPORT }, - { "gaussian", gaussian_filter, GAUSSIAN_SUPPORT }, - { "catmullrom", catmull_rom_filter, CATMULL_ROM_SUPPORT }, - { "quadratic_interp", quadratic_interp_filter, QUADRATIC_SUPPORT }, - { "quadratic_approx", quadratic_approx_filter, QUADRATIC_SUPPORT }, - { "quadratic_mix", quadratic_mix_filter, QUADRATIC_SUPPORT }, + { Resampler::BOX, box_filter, BOX_FILTER_SUPPORT }, + { Resampler::TENT, tent_filter, TENT_FILTER_SUPPORT }, + { Resampler::BELL, bell_filter, BELL_SUPPORT }, + { Resampler::B_SPLINE, B_spline_filter, B_SPLINE_SUPPORT }, + { Resampler::MITCHELL, mitchell_filter, MITCHELL_SUPPORT }, + { Resampler::LANCZOS3, lanczos3_filter, LANCZOS3_SUPPORT }, + { Resampler::BLACKMAN, blackman_filter, BLACKMAN_SUPPORT }, + { Resampler::LANCZOS4, lanczos4_filter, LANCZOS4_SUPPORT }, + { Resampler::LANCZOS6, lanczos6_filter, LANCZOS6_SUPPORT }, + { Resampler::LANCZOS12, lanczos12_filter, LANCZOS12_SUPPORT }, + { Resampler::KAISER, kaiser_filter, KAISER_SUPPORT }, + { Resampler::GAUSSIAN, gaussian_filter, GAUSSIAN_SUPPORT }, + { Resampler::CATMULLROM, catmull_rom_filter, CATMULL_ROM_SUPPORT }, + { Resampler::QUADRATIC_INTERPOLATION, quadratic_interp_filter, QUADRATIC_SUPPORT }, + { Resampler::QUADRATIC_APPROXIMATION, quadratic_approx_filter, QUADRATIC_SUPPORT }, + { Resampler::QUADRATIC_MIX, quadratic_mix_filter, QUADRATIC_SUPPORT }, }; static const int NUM_FILTERS = sizeof(g_filters) / sizeof(g_filters[0]); @@ -1012,7 +1012,7 @@ Resampler::Resampler(int src_x, int src_y, int dst_x, int dst_y, Boundary_Op boundary_op, Resample_Real sample_low, Resample_Real sample_high, - const char* Pfilter_name, + Resampler::Filter filter, Contrib_List* Pclist_x, Contrib_List* Pclist_y, Resample_Real filter_x_scale, @@ -1062,17 +1062,13 @@ Resampler::Resampler(int src_x, int src_y, } // Find the specified filter. - - if (Pfilter_name == NULL) - Pfilter_name = RESAMPLER_DEFAULT_FILTER; - for (i = 0; i < NUM_FILTERS; i++) - if (strcmp(Pfilter_name, g_filters[i].name) == 0) + if ( filter == g_filters[i].name ) break; if (i == NUM_FILTERS) { - m_status = STATUS_BAD_FILTER_NAME; + m_status = STATUS_BAD_FILTER_TYPE; return; } @@ -1205,17 +1201,4 @@ void Resampler::get_clists(Contrib_List** ptr_clist_x, Contrib_List** ptr_clist_ *ptr_clist_y = m_Pclist_y; } -int Resampler::get_filter_num() -{ - return NUM_FILTERS; -} - -char* Resampler::get_filter_name(int filter_num) -{ - if ((filter_num < 0) || (filter_num >= NUM_FILTERS)) - return NULL; - else - return g_filters[filter_num].name; -} - #pragma GCC diagnostic pop diff --git a/third-party/image-resampler/resampler.h b/third-party/image-resampler/resampler.h index c28daaf..4cc78a5 100644 --- a/third-party/image-resampler/resampler.h +++ b/third-party/image-resampler/resampler.h @@ -1,10 +1,10 @@ // resampler.h, Separable filtering image rescaler v2.21, Rich Geldreich - richgel99@gmail.com // See unlicense.org text at the bottom of this file. +// Modified to specify filters as enum rather than char * #ifndef __RESAMPLER_H__ #define __RESAMPLER_H__ #define RESAMPLER_DEBUG_OPS 0 -#define RESAMPLER_DEFAULT_FILTER "lanczos4" #define RESAMPLER_MAX_DIMENSION 16384 @@ -16,6 +16,29 @@ class Resampler public: typedef Resample_Real Sample; + /** + * Supported filter types + */ + enum Filter + { + BOX, + TENT, + BELL, + B_SPLINE, + MITCHELL, + LANCZOS3, + BLACKMAN, + LANCZOS4, + LANCZOS6, + LANCZOS12, + KAISER, + GAUSSIAN, + CATMULLROM, + QUADRATIC_INTERPOLATION, + QUADRATIC_APPROXIMATION, + QUADRATIC_MIX, + }; + struct Contrib { Resample_Real weight; @@ -39,7 +62,7 @@ public: { STATUS_OKAY = 0, STATUS_OUT_OF_MEMORY = 1, - STATUS_BAD_FILTER_NAME = 2, + STATUS_BAD_FILTER_TYPE = 2, STATUS_SCAN_BUFFER_FULL = 3 }; @@ -54,7 +77,7 @@ public: int dst_x, int dst_y, Boundary_Op boundary_op = BOUNDARY_CLAMP, Resample_Real sample_low = 0.0f, Resample_Real sample_high = 0.0f, - const char* Pfilter_name = RESAMPLER_DEFAULT_FILTER, + Resampler::Filter = Resampler::LANCZOS3, Contrib_List* Pclist_x = NULL, Contrib_List* Pclist_y = NULL, Resample_Real filter_x_scale = 1.0f, @@ -80,10 +103,6 @@ public: Contrib_List* get_clist_x() const { return m_Pclist_x; } Contrib_List* get_clist_y() const { return m_Pclist_y; } - // Filter accessors. - static int get_filter_num(); - static char* get_filter_name(int filter_num); - private: Resampler(); Resampler(const Resampler& o); -- 2.7.4