sunlinyi 2013-01-15

 代码如下:
var pyrDown = function(__src, __dst){ 
__src || error(arguments.callee, IS_UNDEFINED_OR_NULL/* {line} */); 
if(__src.type && __src.type == "CV_RGBA"){ 
var width = __src.col, 
height = __src.row, 
dWidth = ((width & 1) + width) / 2, 
dHeight = ((height & 1) + height) / 2, 
sData = __src.data, 
dst = __dst || new Mat(dHeight, dWidth, CV_RGBA), 
dstData = dst.data; 
var withBorderMat = copyMakeBorder(__src, 2, 2, 0, 0), 
mData = withBorderMat.data, 
mWidth = withBorderMat.col; 
var newValue, nowX, offsetY, offsetI, dOffsetI, i, j; 
var kernel = [1, 4, 6, 4, 1, 
, 16, 24, 16, 4, 
, 24, 36, 24, 6, 
, 16, 24, 16, 4, 
, 4, 6, 4, 1 
]; 
for(i = dHeight; i--;){ 
dOffsetI = i * dWidth; 
for(j = dWidth; j--;){ 
for(c = 3; c--;){ 
newValue = 0; 
for(y = 5; y--;){ 
offsetY = (y + i * 2) * mWidth * 4; 
for(x = 5; x--;){ 
nowX = (x + j * 2) * 4 + c; 
newValue += (mData[offsetY + nowX] * kernel[y * 5 + x]); 
} 
} 
dstData[(j + dOffsetI) * 4 + c] = newValue / 256; 
} 
dstData[(j + dOffsetI) * 4 + 3] = mData[offsetY + 2 * mWidth * 4 + (j * 2 + 2) * 4 + 3]; 
} 
} 
}else{ 
error(arguments.callee, UNSPPORT_DATA_TYPE/* {line} */); 
} 
return dst; 
}; 代码如下:
var pyrUp = function(__src, __dst){ 
__src || error(arguments.callee, IS_UNDEFINED_OR_NULL/* {line} */); 
if(__src.type && __src.type == "CV_RGBA"){ 
var width = __src.col, 
height = __src.row, 
dWidth = width * 2, 
dHeight = height * 2, 
sData = __src.data, 
dst = __dst || new Mat(dHeight, dWidth, CV_RGBA), 
dstData = dst.data; 
var withBorderMat = copyMakeBorder(__src, 2, 2, 0, 0), 
mData = withBorderMat.data, 
mWidth = withBorderMat.col; 
var newValue, nowX, offsetY, offsetI, dOffsetI, i, j; 
var kernel = [1, 4, 6, 4, 1, 
, 16, 24, 16, 4, 
, 24, 36, 24, 6, 
, 16, 24, 16, 4, 
, 4, 6, 4, 1 
]; 
for(i = dHeight; i--;){ 
dOffsetI = i * dWidth; 
for(j = dWidth; j--;){ 
for(c = 3; c--;){ 
newValue = 0; 
for(y = 2 + (i & 1); y--;){ 
offsetY = (y + ((i + 1) >> 1)) * mWidth * 4; 
for(x = 2 + (j & 1); x--;){ 
nowX = (x + ((j + 1) >> 1)) * 4 + c; 
newValue += (mData[offsetY + nowX] * kernel[(y * 2 + (i & 1 ^ 1)) * 5 + (x * 2 + (j & 1 ^ 1))]); 
} 
} 
dstData[(j + dOffsetI) * 4 + c] = newValue / 64; 
} 
dstData[(j + dOffsetI) * 4 + 3] = mData[offsetY + 2 * mWidth * 4 + (((j + 1) >> 1) + 2) * 4 + 3]; 
} 
} 
}else{ 
error(arguments.callee, UNSPPORT_DATA_TYPE/* {line} */); 
} 
return dst; 
}; 