// * // Run image manipulation // \return Pointer to image buffer which has been set in the constructor. // public override TextureBuffer process() { float[] blurKernel = { 1, 2, 3, 2, 1, 2, 4, 5, 4, 2, 3, 5, 6, 5, 3, 2, 4, 5, 4, 2, 1, 2, 3, 2, 1 }; Convolution filter = new Convolution(mBuffer); switch (mType) { default: //C++ TO C# CONVERTER TODO TASK: C# does not allow fall-through from a non-empty 'case': case BLUR_TYPE.BLUR_BOX: filter.setKernel(5, blurKernel); break; case BLUR_TYPE.BLUR_MEAN: filter.setKernel(new Matrix3(1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f)).calculateDivisor(); break; case BLUR_TYPE.BLUR_GAUSSIAN: float fSigma = 0.5f + ((3.0f - 0.5f) / 255.0f) * (float)mSigma; int r = (int)mSize / 2; double min = System.Math.Exp((float)(2 * r * r) / (-2.0f * fSigma * fSigma)) / (Math.TWO_PI * fSigma * fSigma); int[] kernel = new int[mSize * mSize]; int divisor = 0; int y = -r; int x = -r; for (int i = 0; i < mSize; i++) { for (int j = 0; j < mSize; j++) { kernel[i * mSize + j] = (int)((System.Math.Exp((float)(x * x + y * y) / (-2.0f * fSigma * fSigma)) / (Math.TWO_PI * fSigma * fSigma)) / min); divisor += kernel[i * mSize + j]; x++; } y++; } filter.setKernel(mSize, kernel).setDivisor((float)divisor); kernel = null; break; } filter.setIncludeAlphaChannel(true).process(); Utils.log("Modify texture with blur filter : " + (mType).ToString()); return mBuffer; }
// * // Run image manipulation // \return Pointer to image buffer which has been set in the constructor. // public override TextureBuffer process() { Convolution filter = new Convolution(mBuffer); switch (mType) { default: //C++ TO C# CONVERTER TODO TASK: C# does not allow fall-through from a non-empty 'case': case SHARP_TYPE.SHARP_BASIC: filter.setKernel(new Matrix3(0.0f, -1.0f, 0.0f, -1.0f, 5.0f, -1.0f, 0.0f, -1.0f, 0.0f)).calculateDivisor(); break; case SHARP_TYPE.SHARP_GAUSSIAN: float fSigma = 0.5f + ((5.0f - 0.5f) / 255.0f) * (float)mSigma; int r = (int)mSize / 2; double min = System.Math.Exp((float)(2 * r * r) / (-2.0f * fSigma * fSigma)) / (Math.TWO_PI * fSigma * fSigma); int[] kernel = new int[mSize * mSize]; int sum = 0; int y = -r; int x = -r; for (int i = 0; i < mSize; i++) { for (int j = 0; j < mSize; j++) { kernel[i * mSize + j] = (int)((System.Math.Exp((float)(x * x + y * y) / (-2.0f * fSigma * fSigma)) / (Math.TWO_PI * fSigma * fSigma)) / min); sum += kernel[i * mSize + j]; x++; } y++; } int c = (int)mSize >> 1; int divisor = 0; for (int i = 0; i < mSize; i++) { for (int j = 0; j < mSize; j++) { if ((i == c) && (j == c)) kernel[i * mSize + j] = 2 * sum - kernel[i * mSize + j]; else kernel[i * mSize + j] = -kernel[i * mSize + j]; divisor += kernel[i * mSize + j]; } } filter.setKernel(mSize, kernel).setDivisor((float)divisor); kernel = null; break; } filter.setIncludeAlphaChannel(true).process(); Utils.log("Modify texture with sharpen filter : " + (mType).ToString()); return mBuffer; }