-/* 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/Rect.h>\r
-#include <rfb/ScaleFilters.h>\r
-\r
-#ifdef _WIN32\r
-#define strcasecmp _stricmp\r
-#endif\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
-int ScaleFilters::getFilterIdByName(char *filterName) {\r
- for (unsigned int i = 0; i <= scaleFilterMaxNumber; i++) {\r
- if (strcasecmp(filters[i].name, filterName) == 0) return i;\r
- }\r
- return -1;\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
-}\r
-\r
-void ScaleFilters::makeWeightTabs(int filter_id, int src_x, int dst_x, SFilterWeightTab **pWeightTabs) {\r
- double sxc;\r
- double offset = 0.5;\r
- double ratio = (double)dst_x / src_x;\r
-\r
- SFilter sFilter = filters[filter_id];\r
- \r
- *pWeightTabs = new SFilterWeightTab[dst_x];\r
- SFilterWeightTab *weightTabs = *pWeightTabs;\r
-\r
- // Make the weight tab for the each dest x position\r
- for (int x = 0; x < dst_x; x++) {\r
- sxc = (double(x)+offset) / ratio;\r
-\r
- // Calculate the scale filter interval, [i0, i1)\r
- int i0 = int(__rfbmax(sxc-sFilter.radius+0.5, 0));\r
- int i1 = int(__rfbmin(sxc+sFilter.radius+0.5, src_x));\r
-\r
- weightTabs[x].i0 = i0; weightTabs[x].i1 = i1;\r
- weightTabs[x].weight = new double[i1-i0];\r
-\r
- // Calculate the weight coeffs on the scale filter interval\r
- for (int ci = 0, i = i0; i < i1; i++) {\r
- weightTabs[x].weight[ci++] = (double)sFilter.func(double(i)-sxc+0.5);\r
- }\r
- }\r
-}\r
+/* Copyright (C) 2006 TightVNC Team. All Rights Reserved.
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this software; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ * USA.
+ */
+
+#include <string.h>
+#include <assert.h>
+#include <math.h>
+
+#include <rfb/Rect.h>
+#include <rfb/ScaleFilters.h>
+
+#ifdef _WIN32
+#define strcasecmp _stricmp
+#endif
+
+using namespace rfb;
+
+//
+// -=- 1-D filters functions
+//
+
+// Nearest neighbor filter function
+double nearest_neighbor(double x) {
+ if (x < -0.5) return 0.0;
+ if (x < 0.5) return 1.0;
+ return 0.0;
+}
+
+// Linear filter function
+double linear(double x) {
+ if (x < -1.0) return 0.0;
+ if (x < 0.0) return 1.0+x;
+ if (x < 1.0) return 1.0-x;
+ return 0.0;
+}
+
+// Cubic filter functions
+double cubic(double x) {
+ double t;
+ if (x < -2.0) return 0.0;
+ if (x < -1.0) {t = 2.0+x; return t*t*t/6.0;}
+ if (x < 0.0) return (4.0+x*x*(-6.0+x*-3.0))/6.0;
+ if (x < 1.0) return (4.0+x*x*(-6.0+x*3.0))/6.0;
+ if (x < 2.0) {t = 2.0-x; return t*t*t/6.0;}
+ return 0.0;
+}
+
+// Sinc filter function
+double sinc(double x) {
+ if (x == 0.0) return 1.0;
+ else return sin(pi*x)/(pi*x);
+}
+
+
+//
+// -=- ScaleFilters class
+//
+
+SFilter &ScaleFilters::operator[](unsigned int filter_id) {
+ assert(filter_id <= scaleFilterMaxNumber);
+ return filters[filter_id];
+}
+
+int ScaleFilters::getFilterIdByName(char *filterName) {
+ for (unsigned int i = 0; i <= scaleFilterMaxNumber; i++) {
+ if (strcasecmp(filters[i].name, filterName) == 0) return i;
+ }
+ return -1;
+}
+
+void ScaleFilters::initFilters() {
+ filters[scaleFilterNearestNeighbor] = create("Nearest neighbor", 0.5, nearest_neighbor);
+ filters[scaleFilterBilinear] = create("Bilinear", 1, linear);
+ filters[scaleFilterBicubic] = create("Bicubic", 2, cubic);
+ filters[scaleFilterSinc] = create("Sinc", 4, sinc);
+}
+
+SFilter ScaleFilters::create(char *name_, double radius_, filter_func func_) {
+ SFilter filter;
+ strncpy(filter.name, name_, sizeof(filter.name)-1);
+ filter.name[sizeof(filter.name)-1] = '\0';
+ filter.radius = radius_;
+ filter.func = func_;
+ return filter;
+}
+
+void ScaleFilters::makeWeightTabs(int filter_id, int src_x, int dst_x, SFilterWeightTab **pWeightTabs) {
+ double sxc;
+ double offset = 0.5;
+ double ratio = (double)dst_x / src_x;
+
+ SFilter sFilter = filters[filter_id];
+
+ *pWeightTabs = new SFilterWeightTab[dst_x];
+ SFilterWeightTab *weightTabs = *pWeightTabs;
+
+ // Make the weight tab for the each dest x position
+ for (int x = 0; x < dst_x; x++) {
+ sxc = (double(x)+offset) / ratio;
+
+ // Calculate the scale filter interval, [i0, i1)
+ int i0 = int(__rfbmax(sxc-sFilter.radius+0.5, 0));
+ int i1 = int(__rfbmin(sxc+sFilter.radius+0.5, src_x));
+
+ weightTabs[x].i0 = i0; weightTabs[x].i1 = i1;
+ weightTabs[x].weight = new double[i1-i0];
+
+ // Calculate the weight coeffs on the scale filter interval
+ for (int ci = 0, i = i0; i < i1; i++) {
+ weightTabs[x].weight[ci++] = (double)sFilter.func(double(i)-sxc+0.5);
+ }
+ }
+}
-/* 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
-// -=- ScaleFilters.h\r
-//\r
-// Definitions of the 1-D filters and routines using for the image scaling.\r
-// \r
-// \r
-\r
-namespace rfb {\r
-\r
- typedef double (*filter_func)(double x);\r
-\r
- const double pi = 3.14159265358979;\r
-\r
- const unsigned int scaleFilterNearestNeighbor = 0;\r
- const unsigned int scaleFilterBilinear = 1;\r
- const unsigned int scaleFilterBicubic = 2;\r
- const unsigned int scaleFilterSinc = 3;\r
-\r
- const unsigned int scaleFilterMaxNumber = 3;\r
- const unsigned int defaultScaleFilter = scaleFilterBilinear;\r
-\r
- //\r
- // -=- Scale filters structures and routines\r
- //\r
-\r
- // Scale filter stuct\r
- typedef struct {\r
- char name[30]; // Filter name\r
- double radius; // Radius where filter function is nonzero\r
- filter_func func; // Pointer to filter function\r
- } SFilter;\r
-\r
- // Scale filter weight table\r
- typedef struct {\r
- short int i0, i1; // Filter function interval, [i0..i1)\r
- double *weight; // Weight coefficients on the filter function interval\r
- } SFilterWeightTab;\r
-\r
-\r
- // ScaleFilters class helps us using a set of 1-d scale filters.\r
- class ScaleFilters {\r
- public:\r
- ScaleFilters() { initFilters(); };\r
-\r
- SFilter &operator[](unsigned int filter_id);\r
-\r
- int getFilterIdByName(char *filterName);\r
-\r
- void makeWeightTabs(int filter, int src_x, int dst_x, SFilterWeightTab **weightTabs);\r
-\r
- protected:\r
- void initFilters();\r
-\r
- SFilter create(char *name_, double radius_, filter_func func_);\r
-\r
- SFilter filters[scaleFilterMaxNumber+1];\r
- };\r
-\r
-};\r
+/* Copyright (C) 2006 TightVNC Team. All Rights Reserved.
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this software; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ * USA.
+ */
+
+// -=- ScaleFilters.h
+//
+// Definitions of the 1-D filters and routines using for the image scaling.
+//
+//
+
+namespace rfb {
+
+ typedef double (*filter_func)(double x);
+
+ const double pi = 3.14159265358979;
+
+ const unsigned int scaleFilterNearestNeighbor = 0;
+ const unsigned int scaleFilterBilinear = 1;
+ const unsigned int scaleFilterBicubic = 2;
+ const unsigned int scaleFilterSinc = 3;
+
+ const unsigned int scaleFilterMaxNumber = 3;
+ const unsigned int defaultScaleFilter = scaleFilterBilinear;
+
+ //
+ // -=- Scale filters structures and routines
+ //
+
+ // Scale filter stuct
+ typedef struct {
+ char name[30]; // Filter name
+ double radius; // Radius where filter function is nonzero
+ filter_func func; // Pointer to filter function
+ } SFilter;
+
+ // Scale filter weight table
+ typedef struct {
+ short int i0, i1; // Filter function interval, [i0..i1)
+ double *weight; // Weight coefficients on the filter function interval
+ } SFilterWeightTab;
+
+
+ // ScaleFilters class helps us using a set of 1-d scale filters.
+ class ScaleFilters {
+ public:
+ ScaleFilters() { initFilters(); };
+
+ SFilter &operator[](unsigned int filter_id);
+
+ int getFilterIdByName(char *filterName);
+
+ void makeWeightTabs(int filter, int src_x, int dst_x, SFilterWeightTab **weightTabs);
+
+ protected:
+ void initFilters();
+
+ SFilter create(char *name_, double radius_, filter_func func_);
+
+ SFilter filters[scaleFilterMaxNumber+1];
+ };
+
+};