123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- #pragma once
- #include <Mathematics/Math.h>
- namespace WwiseGTE
- {
-
-
-
-
- template <typename T>
- class FastGaussianBlur2
- {
- public:
- void Execute(int xBound, int yBound, T const* input, T* output,
- double scale, double logBase)
- {
- mXBound = xBound;
- mYBound = yBound;
- mInput = input;
- mOutput = output;
- int xBoundM1 = xBound - 1, yBoundM1 = yBound - 1;
- for (int y = 0; y < yBound; ++y)
- {
- double ryps = static_cast<double>(y) + scale;
- double ryms = static_cast<double>(y) - scale;
- int yp1 = static_cast<int>(std::floor(ryps));
- int ym1 = static_cast<int>(std::ceil(ryms));
- for (int x = 0; x < xBound; ++x)
- {
- double rxps = x + scale;
- double rxms = x - scale;
- int xp1 = static_cast<int>(std::floor(rxps));
- int xm1 = static_cast<int>(std::ceil(rxms));
- double center = Input(x, y);
- double xsum = -2.0 * center, ysum = xsum;
-
- if (xp1 >= xBoundM1)
- {
- xsum += Input(xBoundM1, y);
- }
- else
- {
- double imgXp1 = Input(xp1, y);
- double imgXp2 = Input(xp1 + 1, y);
- double delta = rxps - static_cast<double>(xp1);
- xsum += imgXp1 + delta * (imgXp2 - imgXp1);
- }
- if (xm1 <= 0)
- {
- xsum += Input(0, y);
- }
- else
- {
- double imgXm1 = Input(xm1, y);
- double imgXm2 = Input(xm1 - 1, y);
- double delta = rxms - static_cast<double>(xm1);
- xsum += imgXm1 + delta * (imgXm1 - imgXm2);
- }
-
- if (yp1 >= yBoundM1)
- {
- ysum += Input(x, yBoundM1);
- }
- else
- {
- double imgYp1 = Input(x, yp1);
- double imgYp2 = Input(x, yp1 + 1);
- double delta = ryps - static_cast<double>(yp1);
- ysum += imgYp1 + delta * (imgYp2 - imgYp1);
- }
- if (ym1 <= 0)
- {
- ysum += Input(x, 0);
- }
- else
- {
- double imgYm1 = Input(x, ym1);
- double imgYm2 = Input(x, ym1 - 1);
- double delta = ryms - static_cast<double>(ym1);
- ysum += imgYm1 + delta * (imgYm1 - imgYm2);
- }
- Output(x, y) = static_cast<T>(center + logBase * (xsum + ysum));
- }
- }
- mXBound = 0;
- mYBound = 0;
- mInput = nullptr;
- mOutput = nullptr;
- }
- private:
- inline double Input(int x, int y) const
- {
- return static_cast<double>(mInput[x + mXBound * y]);
- }
- inline T& Output(int x, int y)
- {
- return mOutput[x + mXBound * y];
- }
- int mXBound, mYBound;
- T const* mInput;
- T* mOutput;
- };
- }
|