--- /dev/null
+/* Copyright (C) 2006 TightVNC Team. All Rights Reserved.\r
+ * \r
+ * This is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ * \r
+ * This software is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this software; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,\r
+ * USA.\r
+ */\r
+\r
+#include <string.h>\r
+#include <assert.h>\r
+#include <math.h>\r
+\r
+#include <rfb/ScaleFilters.h>\r
+\r
+using namespace rfb;\r
+\r
+//\r
+// -=- 1-D filters functions\r
+//\r
+\r
+// Nearest neighbor filter function\r
+double nearest_neighbor(double x) {\r
+ if (x < -0.5) return 0.0;\r
+ if (x < 0.5) return 1.0;\r
+ return 0.0;\r
+}\r
+\r
+// Linear filter function\r
+double linear(double x) {\r
+ if (x < -1.0) return 0.0;\r
+ if (x < 0.0) return 1.0+x;\r
+ if (x < 1.0) return 1.0-x;\r
+ return 0.0;\r
+}\r
+\r
+// Cubic filter functions\r
+double cubic(double x) {\r
+ double t;\r
+ if (x < -2.0) return 0.0;\r
+ if (x < -1.0) {t = 2.0+x; return t*t*t/6.0;}\r
+ if (x < 0.0) return (4.0+x*x*(-6.0+x*-3.0))/6.0;\r
+ if (x < 1.0) return (4.0+x*x*(-6.0+x*3.0))/6.0;\r
+ if (x < 2.0) {t = 2.0-x; return t*t*t/6.0;}\r
+ return 0.0;\r
+}\r
+\r
+// Sinc filter function\r
+double sinc(double x) {\r
+ if (x == 0.0) return 1.0;\r
+ else return sin(pi*x)/(pi*x);\r
+}\r
+\r
+\r
+//\r
+// -=- ScaleFilters class\r
+//\r
+\r
+SFilter &ScaleFilters::operator[](unsigned int filter_id) {\r
+ assert(filter_id < scaleFilterMaxNumber);\r
+ return filters[filter_id];\r
+}\r
+\r
+void ScaleFilters::initFilters() {\r
+ filters[scaleFilterNearestNeighbor] = create("Nearest neighbor", 0.5, nearest_neighbor);\r
+ filters[scaleFilterBilinear] = create("Bilinear", 1, linear);\r
+ filters[scaleFilterBicubic] = create("Bicubic", 2, cubic);\r
+ filters[scaleFilterSinc] = create("Sinc", 4, sinc);\r
+}\r
+\r
+SFilter ScaleFilters::create(char *name_, double radius_, filter_func func_) {\r
+ SFilter filter;\r
+ strncpy(filter.name, name_, sizeof(filter.name)-1); \r
+ filter.name[sizeof(filter.name)-1] = '\0';\r
+ filter.radius = radius_;\r
+ filter.func = func_;\r
+ return filter;\r
+}
\ No newline at end of file
// \r
// \r
\r
-#include <assert.h>\r
-#include <math.h>\r
-\r
namespace rfb {\r
\r
typedef double (*filter_func)(double x);\r
\r
const unsigned int scaleFilterMaxNumber = 3;\r
\r
- //\r
- // -=- 1-D filters functions\r
- //\r
-\r
- // Nearest neighbor filter function\r
- double nearest_neighbor(double x) {\r
- if (x < -0.5) return 0.0;\r
- if (x < 0.5) return 1.0;\r
- return 0.0;\r
- }\r
-\r
- // Linear filter function\r
- double linear(double x) {\r
- if (x < -1.0) return 0.0;\r
- if (x < 0.0) return 1.0+x;\r
- if (x < 1.0) return 1.0-x;\r
- return 0.0;\r
- }\r
-\r
- // Cubic filter functions\r
- double cubic(double x) {\r
- double t;\r
- if (x < -2.0) return 0.0;\r
- if (x < -1.0) {t = 2.0+x; return t*t*t/6.0;}\r
- if (x < 0.0) return (4.0+x*x*(-6.0+x*-3.0))/6.0;\r
- if (x < 1.0) return (4.0+x*x*(-6.0+x*3.0))/6.0;\r
- if (x < 2.0) {t = 2.0-x; return t*t*t/6.0;}\r
- return 0.0;\r
- }\r
-\r
- // Sinc filter function\r
- double sinc(double x) {\r
- if (x == 0.0) return 1.0;\r
- else return sin(pi*x)/(pi*x);\r
- }\r
-\r
//\r
// -=- Scale filters structures and routines\r
//\r
public:\r
ScaleFilters() { initFilters(); };\r
\r
- SFilter &operator[](unsigned int filter_id) {\r
- assert(filter_id < scaleFilterMaxNumber);\r
- return filters[filter_id];\r
- }\r
+ SFilter &operator[](unsigned int filter_id);\r
\r
protected:\r
- void initFilters() {\r
- filters[scaleFilterNearestNeighbor] = create("Nearest neighbor", 0.5, nearest_neighbor);\r
- filters[scaleFilterBilinear] = create("Bilinear", 1, linear);\r
- filters[scaleFilterBicubic] = create("Bicubic", 2, cubic);\r
- filters[scaleFilterSinc] = create("Sinc", 4, sinc);\r
- }\r
-\r
- SFilter create(char *name_, double radius_, filter_func func_) {\r
- SFilter filter;\r
- strncpy(filter.name, name_, sizeof(filter.name)-1); \r
- filter.name[sizeof(filter.name)-1] = '\0';\r
- filter.radius = radius_;\r
- filter.func = func_;\r
- return filter;\r
- }\r
+ void initFilters();\r
+\r
+ SFilter create(char *name_, double radius_, filter_func func_);\r
\r
SFilter filters[scaleFilterMaxNumber+1];\r
};\r