From 06ee4c12b1fad1ce872f3db1dc478d07a51a1028 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Wed, 29 Sep 2010 20:23:47 +0300 Subject: [PATCH] Add target witdth to parameters for linear separable resizers --- streamtools/resize-linear-separable.cpp | 41 +++++++++++++++++---------------- streamtools/resize-linear-separable.hpp | 18 +++++++-------- streamtools/resizer-bilinear.cpp | 2 +- streamtools/resizer-lanczos.cpp | 4 ++-- 4 files changed, 33 insertions(+), 32 deletions(-) diff --git a/streamtools/resize-linear-separable.cpp b/streamtools/resize-linear-separable.cpp index 4596d65..98effbc 100644 --- a/streamtools/resize-linear-separable.cpp +++ b/streamtools/resize-linear-separable.cpp @@ -15,7 +15,7 @@ void resizer_linear_separable::operator()(uint8_t* target, uint32_t twidth, uint for(unsigned x = 0; x < twidth; x++) { count = 0xDEADBEEF; base = 0xDEADBEEF; - compute_coeffs(coeffs, (position_t)x * swidth, twidth, swidth, count, base); + compute_coeffs(coeffs, (position_t)x * swidth, twidth, swidth, twidth, count, base); /* Normalize the coefficients. */ float sum = 0; for(unsigned i = 0; i < count; i++) @@ -39,7 +39,7 @@ void resizer_linear_separable::operator()(uint8_t* target, uint32_t twidth, uint for(unsigned y = 0; y < theight; y++) { count = 0; base = 0; - compute_coeffs(coeffs, (position_t)y * sheight, theight, sheight, count, base); + compute_coeffs(coeffs, (position_t)y * sheight, theight, sheight, theight, count, base); /* Normalize the coefficients. */ float sum = 0; for(unsigned i = 0; i < count; i++) @@ -75,49 +75,50 @@ namespace class simple_resizer_linear_separable_c : public resizer_linear_separable { public: - simple_resizer_linear_separable_c(void(*_coeffs_fn)(float* coeffs, position_t newsize, position_t oldsize, - position_t position, unsigned& base, unsigned& coeffcount)) + simple_resizer_linear_separable_c(void(*_coeffs_fn)(float* coeffs, position_t num, + position_t denum, position_t osize, position_t nsize, unsigned& base, unsigned& coeffcount)) { coeffs_fn = _coeffs_fn; } - void compute_coeffs(float* coeffs, position_t newsize, position_t oldsize, position_t position, - unsigned& base, unsigned& coeffcount) + void compute_coeffs(float* coeffs, position_t num, position_t denum, position_t osize, + position_t nsize, unsigned& base, unsigned& coeffcount) { - coeffs_fn(coeffs, newsize, oldsize, position, base, coeffcount); + coeffs_fn(coeffs, num, denum, osize, nsize, base, coeffcount); } private: - void(*coeffs_fn)(float* coeffs, position_t newsize, position_t oldsize, - position_t position, unsigned& base, unsigned& coeffcount); + void(*coeffs_fn)(float* coeffs, position_t num, position_t denum, position_t osize, + position_t nsize, unsigned& base, unsigned& coeffcount); }; class simple_resizer_linear_separable_c2 : public resizer_linear_separable { public: - simple_resizer_linear_separable_c2(void(*_coeffs_fn)(float* coeffs, position_t newsize, position_t oldsize, - position_t position, unsigned& base, unsigned& coeffcount, int algo), int _algo) + simple_resizer_linear_separable_c2(void(*_coeffs_fn)(float* coeffs, position_t num, + position_t denum, position_t osize, position_t nsize, unsigned& base, unsigned& coeffcount, + int algo), int _algo) { coeffs_fn = _coeffs_fn; algo = _algo; } - void compute_coeffs(float* coeffs, position_t newsize, position_t oldsize, position_t position, - unsigned& base, unsigned& coeffcount) + void compute_coeffs(float* coeffs, position_t num, position_t denum, position_t osize, + position_t nsize, unsigned& base, unsigned& coeffcount) { - coeffs_fn(coeffs, newsize, oldsize, position, base, coeffcount, algo); + coeffs_fn(coeffs, num, denum, osize, nsize, base, coeffcount, algo); } private: - void(*coeffs_fn)(float* coeffs, position_t newsize, position_t oldsize, - position_t position, unsigned& base, unsigned& coeffcount, int algo); + void(*coeffs_fn)(float* coeffs, position_t num, position_t denum, position_t osize, + position_t nsize, unsigned& base, unsigned& coeffcount, int algo); int algo; }; } simple_resizer_linear_separable::simple_resizer_linear_separable(const std::string& type, - void(*_coeffs_fn)(float* coeffs, position_t newsize, position_t oldsize, position_t position, unsigned& base, - unsigned& coeffcount)) + void(*_coeffs_fn)(float* coeffs, position_t num, position_t denum, position_t osize, + position_t nsize, unsigned& base, unsigned& coeffcount)) : resizer_factory(type) { coeffs_fn = _coeffs_fn; @@ -126,8 +127,8 @@ simple_resizer_linear_separable::simple_resizer_linear_separable(const std::stri } simple_resizer_linear_separable::simple_resizer_linear_separable(const std::string& type, - void(*_coeffs_fn)(float* coeffs, position_t newsize, position_t oldsize, position_t position, unsigned& base, - unsigned& coeffcount, int algo), int _algo) + void(*_coeffs_fn)(float* coeffs, position_t num, position_t denum, position_t osize, + position_t nsize, unsigned& base, unsigned& coeffcount, int algo), int _algo) : resizer_factory(type) { coeffs_fn = NULL; diff --git a/streamtools/resize-linear-separable.hpp b/streamtools/resize-linear-separable.hpp index 04d19b3..8c3144c 100644 --- a/streamtools/resize-linear-separable.hpp +++ b/streamtools/resize-linear-separable.hpp @@ -17,27 +17,27 @@ public: protected: //Fill coeffs, base and coeffcount. Coeffs is set of floating-point coefficients for pixels //starting from pixel number base (zero-based) and numbering coeffcount. Take care not to refer - //to pixel outside range [0,width). + //to pixel outside range [0,width). Twidth is target width. //num / denum gives position of pixel being approximated. The coordinate range is [0, width), //width giving the width of original data. virtual void compute_coeffs(float* coeffs, position_t num, position_t denum, position_t width, - unsigned& base, unsigned& coeffcount) = 0; + position_t twidth, unsigned& base, unsigned& coeffcount) = 0; }; class simple_resizer_linear_separable : public resizer_factory { public: simple_resizer_linear_separable(const std::string& type, void(*coeffs_fn)(float* coeffs, position_t num, - position_t denum, position_t width, unsigned& base, unsigned& coeffcount)); + position_t denum, position_t width, position_t twidth, unsigned& base, unsigned& coeffcount)); simple_resizer_linear_separable(const std::string& type, void(*coeffs_fn)(float* coeffs, position_t num, - position_t denum, position_t width, unsigned& base, unsigned& coeffcount, int algo), - int algo); + position_t denum, position_t width, position_t twidth, unsigned& base, unsigned& coeffcount, + int algo), int algo); resizer& make(const std::string& type); private: - void(*coeffs_fn)(float* coeffs, position_t newsize, position_t oldsize, position_t width, unsigned& base, - unsigned& coeffcount); - void(*coeffs_fn2)(float* coeffs, position_t newsize, position_t oldsize, position_t width, unsigned& base, - unsigned& coeffcount, int algo); + void(*coeffs_fn)(float* coeffs, position_t newsize, position_t oldsize, position_t width, position_t twidth, + unsigned& base, unsigned& coeffcount); + void(*coeffs_fn2)(float* coeffs, position_t newsize, position_t oldsize, position_t width, + position_t twidth, unsigned& base, unsigned& coeffcount, int algo); int algo; }; diff --git a/streamtools/resizer-bilinear.cpp b/streamtools/resizer-bilinear.cpp index 293b7fe..ef4ac92 100644 --- a/streamtools/resizer-bilinear.cpp +++ b/streamtools/resizer-bilinear.cpp @@ -6,7 +6,7 @@ namespace { void compute_coefficients_bilinear(float* coeffs, position_t num, position_t denum, position_t width, - unsigned& count, unsigned& base) + position_t twidth, unsigned& count, unsigned& base) { base = num / denum; if(base < width - 1) { diff --git a/streamtools/resizer-lanczos.cpp b/streamtools/resizer-lanczos.cpp index 07a2a9a..9a57f50 100644 --- a/streamtools/resizer-lanczos.cpp +++ b/streamtools/resizer-lanczos.cpp @@ -12,7 +12,7 @@ namespace // twdith = n * swidth => x / n void compute_coefficients_lanczos(float* coeffs, position_t num, position_t denum, position_t width, - unsigned& count, unsigned& base, int a) + position_t twidth, unsigned& count, unsigned& base, int a) { if(a == 0) throw std::runtime_error("Parameter alpha must be positive in lanczos resizer"); @@ -47,7 +47,7 @@ namespace } void compute_coefficients_average(float* coeffs, position_t num, position_t denum, position_t width, - unsigned& count, unsigned& base) + position_t twidth, unsigned& count, unsigned& base) { signed lowbound, highbound, scan; -- 2.11.4.GIT