From 2bae74e706fc90f5eb00744f475bc30ffa75e711 Mon Sep 17 00:00:00 2001 From: Constantin Kaplinsky Date: Wed, 11 Apr 2007 09:07:11 +0000 Subject: [PATCH] A fix to handle line endings properly. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2255 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- common/rfb/ScaleFilters.cxx | 254 ++++++++++++++++++------------------ common/rfb/ScaleFilters.h | 152 ++++++++++----------- 2 files changed, 203 insertions(+), 203 deletions(-) diff --git a/common/rfb/ScaleFilters.cxx b/common/rfb/ScaleFilters.cxx index 97adbc0d..54da5849 100644 --- a/common/rfb/ScaleFilters.cxx +++ b/common/rfb/ScaleFilters.cxx @@ -1,127 +1,127 @@ -/* 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 -#include -#include - -#include -#include - -#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. + * + * 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 +#include +#include + +#include +#include + +#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); + } + } +} diff --git a/common/rfb/ScaleFilters.h b/common/rfb/ScaleFilters.h index d59cc37d..770ee760 100644 --- a/common/rfb/ScaleFilters.h +++ b/common/rfb/ScaleFilters.h @@ -1,76 +1,76 @@ -/* 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]; - }; - -}; +/* 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]; + }; + +}; -- 2.39.5