#include <windows.h>
int gaussBlur(int *data, int width, int height, double sigma, int radius)
{
double *gaussMatrix, gaussSum = 0.0, _2sigma2 = 2 * sigma * sigma;
int x, y, xx, yy, xxx, yyy;
double *pdbl, a, r, g, b, d;
unsigned char *bbb, *pout, *poutb;
pout = poutb = (unsigned char *)LocalAlloc(LMEM_FIXED, width * height * 4);
if (!pout) return 0;
gaussMatrix = pdbl = (double *)LocalAlloc(LMEM_FIXED, (radius * 2 + 1) * (radius * 2 + 1) * sizeof(double));
if (!gaussMatrix) {
LocalFree(pout);
return 0;
}
for (y = -radius; y <= radius; y++) {
for (x = -radius; x <= radius; x++) {
a = exp(-(double)(x * x + y * y) / _2sigma2);
*pdbl++ = a;
gaussSum += a;
}
}
pdbl = gaussMatrix;
for (y = -radius; y <= radius; y++) {
for (x = -radius; x <= radius; x++) {
*pdbl++ /= gaussSum;
}
}
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {
a = r = g = b = 0.0;
pdbl = gaussMatrix;
for (yy = -radius; yy <= radius; yy++) {
yyy = y + yy;
if (yyy >= 0 && yyy < height) {
for (xx = -radius; xx <= radius; xx++) {
xxx = x + xx;
if (xxx >= 0 && xxx < width) {
bbb = (unsigned char *)&data[xxx + yyy * width];
d = *pdbl;
b += d * bbb[0];
g += d * bbb[1];
r += d * bbb[2];
a += d * bbb[3];
}
pdbl++;
}
} else {
pdbl += (radius * 2 + 1);
}
}
*pout++ = (unsigned char)b;
*pout++ = (unsigned char)g;
*pout++ = (unsigned char)r;
*pout++ = (unsigned char)a;
}
}
RtlMoveMemory(data, poutb, width * height * 4);
LocalFree(gaussMatrix);
LocalFree(poutb);
return 1;
}
int gaussBlur(int *data, int width, int height, double sigma, int radius)
{
double *gaussMatrix, gaussSum = 0.0, _2sigma2 = 2 * sigma * sigma;
int x, y, xx, yy, xxx, yyy;
double *pdbl, a, r, g, b, d;
unsigned char *bbb, *pout, *poutb;
pout = poutb = (unsigned char *)LocalAlloc(LMEM_FIXED, width * height * 4);
if (!pout) return 0;
gaussMatrix = pdbl = (double *)LocalAlloc(LMEM_FIXED, (radius * 2 + 1) * (radius * 2 + 1) * sizeof(double));
if (!gaussMatrix) {
LocalFree(pout);
return 0;
}
for (y = -radius; y <= radius; y++) {
for (x = -radius; x <= radius; x++) {
a = exp(-(double)(x * x + y * y) / _2sigma2);
*pdbl++ = a;
gaussSum += a;
}
}
pdbl = gaussMatrix;
for (y = -radius; y <= radius; y++) {
for (x = -radius; x <= radius; x++) {
*pdbl++ /= gaussSum;
}
}
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {
a = r = g = b = 0.0;
pdbl = gaussMatrix;
for (yy = -radius; yy <= radius; yy++) {
yyy = y + yy;
if (yyy >= 0 && yyy < height) {
for (xx = -radius; xx <= radius; xx++) {
xxx = x + xx;
if (xxx >= 0 && xxx < width) {
bbb = (unsigned char *)&data[xxx + yyy * width];
d = *pdbl;
b += d * bbb[0];
g += d * bbb[1];
r += d * bbb[2];
a += d * bbb[3];
}
pdbl++;
}
} else {
pdbl += (radius * 2 + 1);
}
}
*pout++ = (unsigned char)b;
*pout++ = (unsigned char)g;
*pout++ = (unsigned char)r;
*pout++ = (unsigned char)a;
}
}
RtlMoveMemory(data, poutb, width * height * 4);
LocalFree(gaussMatrix);
LocalFree(poutb);
return 1;
}
Public Function gaussBlur(ByVal data As Integer,
ByVal width As Integer,
ByVal height As Integer,
ByVal sigma As Integer,
ByVal radius As Integer) As Integer
Dim gaussMatrix As Double
Dim gaussSum As Double = 0.0
Dim _2sigma2 As Double = 2 * sigma * sigma
Dim x, y, xx, yy, xxx, yyy As Integer
Dim pdbl, a, r, g, b, d As Double
Dim bbb, pout, poutb As Char End Function后面的自己搞吧。
ByVal width As Integer,
ByVal height As Integer,
ByVal sigma As Integer,
ByVal radius As Integer) As Integer
Dim gaussMatrix As Double
Dim gaussSum As Double = 0.0
Dim _2sigma2 As Double = 2 * sigma * sigma
Dim x, y, xx, yy, xxx, yyy As Integer
Dim pdbl, a, r, g, b, d As Double
Dim bbb, pout, poutb As Char End Function
http://blog.csdn.net/downmoon/archive/2005/08/09/448863.aspx
硬要转还不如重写,
还有个办法,
编译C代码,在VB中调用
LocalAlloc RtlMoveMemory LocalFree
你用VB API声明一下 然后剩下的全是加减乘除 你用VB来做就好了
还好没什么特有的函数或是类什么的 可以转换 楼主研究下