Modified resampler.cpp to use enums for filter types rather than char* 61/135961/1
authorKimmo Hoikka <kimmo.hoikka@samsung.com>
Tue, 27 Jun 2017 13:15:24 +0000 (14:15 +0100)
committerKimmo Hoikka <kimmo.hoikka@samsung.com>
Tue, 27 Jun 2017 13:16:11 +0000 (14:16 +0100)
- removed ununsed filter name getter

Change-Id: Ifbede1d64e9bcf9c49086a64c5a8de3195b85ff2

platform-abstractions/portable/image-operations.cpp
third-party/image-resampler/resampler.cpp
third-party/image-resampler/resampler.h

index c301fcc0db8ac027b4931887318f2da3f437167d..f9856cf04c5d41d9c3be2fd6f2713336b3ae9749 100644 (file)
@@ -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;
index 045549c2493822695d5e88825d8551b8823ce73d..c602466da64fbf00113e1a69882ccb019459a455 100644 (file)
@@ -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
index c28daaf085cba57380e5c9c9e111ece28cc5f548..4cc78a5cbf810eae18f043c6375ec3ebdbed1549 100644 (file)
@@ -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);