void CWin32Font::ApplyGaussianBlurToTexture(int rgbaX, int rgbaY, int rgbaWide, int rgbaTall, unsigned char *rgba) { if (!m_pGaussianDistribution) return; unsigned char *src = (unsigned char *)_alloca(rgbaWide * rgbaTall * 4); memcpy(src, rgba, rgbaWide * rgbaTall * 4); unsigned char *dest = rgba; for (int y = 0; y < rgbaTall; y++) { for (int x = 0; x < rgbaWide; x++) { GetBlurValueForPixel(src, m_iBlur, m_pGaussianDistribution, x, y, rgbaWide, rgbaTall, dest); dest += 4; } } }
//----------------------------------------------------------------------------- // Purpose: blurs the texture //----------------------------------------------------------------------------- void ApplyGaussianBlurToTexture( int rgbaWide, int rgbaTall, unsigned char *rgba, int iBlur ) { float *pGaussianDistribution; if ( !iBlur ) return; // generate the gaussian field pGaussianDistribution = (float*)_alloca( (iBlur*2+1) * sizeof(float) ); double sigma = 0.683 * iBlur; for (int x = 0; x <= (iBlur * 2); x++) { int val = x - iBlur; pGaussianDistribution[x] = (float)(1.0f / sqrt(2 * 3.14 * sigma * sigma)) * pow(2.7, -1 * (val * val) / (2 * sigma * sigma)); } // alloc a new buffer unsigned char *src = new unsigned char[rgbaWide * rgbaTall * 4]; // copy in memcpy(src, rgba, rgbaWide * rgbaTall * 4); // incrementing destination pointer unsigned char *dest = rgba; for (int y = 0; y < rgbaTall; y++) { for (int x = 0; x < rgbaWide; x++) { // scan the source pixel GetBlurValueForPixel(src, iBlur, pGaussianDistribution, x, y, rgbaWide, rgbaTall, dest); // move to the next dest += 4; } } delete[] src; }