public byte[] count(double rate) {// sigma each pixel in _data (rate*pixel) byte[] output = new byte[3]; double[] temp = new double[3]; foreach (double[] pixel in _data) { if (pixel != null) { temp[0] += pixel[0]; temp[1] += pixel[1]; temp[2] += pixel[2]; } } temp[0] *= rate; temp[1] *= rate; temp[2] *= rate; output = MyFilterData.boundPixel(temp); return(output); }
public static Bitmap decode(Bitmap baseImg, MyMotionTiff motion) { MyFilter filter = new MyFilter(MyCompresser.compressKernelSize); filter.setData(1); Bitmap newImg = new Bitmap(baseImg.Width, baseImg.Height); BitmapData baseData = baseImg.LockBits(MyDeal.boundB(baseImg), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); BitmapData newData = newImg.LockBits(MyDeal.boundB(newImg), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb); MyFilterData srcFilterData = new MyFilterData(); for (int y = 0 + MyCompresser.compressKernelSize / 2; y < motion.Height; y += MyCompresser.compressKernelSize) { for (int x = 0 + MyCompresser.compressKernelSize / 2; x < motion.Width; x += MyCompresser.compressKernelSize) { srcFilterData.fill(baseData, motion[x, y][0], motion[x, y][1], MyFilter.BorderMethod.ZERO, filter); Debug.Print("the " + x + " , " + y + " from " + motion[x, y][0] + " , " + motion[x, y][1]); unsafe { byte *dstPtr = (byte *)newData.Scan0; int skipByte = newData.Stride - 3 * MyCompresser.compressKernelSize; dstPtr += (y - MyCompresser.compressKernelSize / 2) * newData.Stride + (x - MyCompresser.compressKernelSize / 2) * 3; for (int j = 0; j < MyCompresser.compressKernelSize; j++) { for (int i = 0; i < MyCompresser.compressKernelSize; i++) { byte[] result = MyFilterData.boundPixel(srcFilterData[i, j]); //Debug.Print("Data get " + result[0] + " , " + result[1] + " , " + result[2]); dstPtr[0] = result[0]; dstPtr[1] = result[1]; dstPtr[2] = result[2]; dstPtr += 3; } dstPtr += skipByte; } } } } baseImg.UnlockBits(baseData); newImg.UnlockBits(newData); return(newImg); }