public void Can_Create_Color_Image() { var bitmap = new Bitmap(20, 10); var imageFactory = new RgbBitmapFactory(); var pointerFactory = new ArrayToPointerFactory(); var data = new ushort[20 * 10 * 2]; for (int index = data.Length / 2; index < data.Length; index++) { data[index] = ushort.MaxValue; } var pointer = pointerFactory.CreatePointer(data); try { imageFactory.CreateImage(bitmap, pointer); } finally { pointerFactory.Destroy(pointer); } var color = bitmap.GetPixel(0, 0); var color2 = bitmap.GetPixel(10, 9); Assert.AreEqual(0, color.R); Assert.AreEqual(0, color.G); Assert.AreEqual(0, color.B); Assert.AreEqual(255, color2.R); Assert.AreEqual(255, color2.G); Assert.AreEqual(255, color2.B); }
public void Can_Create_DepthFrame_From_Pointer() { var generatorStub = new DepthGeneratorStub(); var datasource = new DepthDataFrameSource(generatorStub); var pointerFactory = new ArrayToPointerFactory(); var data = new List <ushort>(); for (int index = 0; index < generatorStub.Width * generatorStub.Height; index++) { data.Add((ushort)index); } var pointer = pointerFactory.CreatePointer(data.ToArray()); generatorStub.ImagePointer = pointer; datasource.ForceRun(); pointerFactory.Destroy(pointer); var frame = datasource.CurrentValue; Assert.AreEqual(20, frame.Width); Assert.AreEqual(10, frame.Height); Assert.AreEqual(frame.Data[1], 1); Assert.AreEqual(frame.Data[66], 66); Assert.AreEqual(frame.Data[199], 199); }
public void Filters_Depth_Data_Correctly() { var data = PrepareDepthData(); var pointerFactory = new ArrayToPointerFactory(); var pointer = pointerFactory.CreatePointer(data.ToArray()); var result = this.filter.Filter(pointer); pointerFactory.Destroy(pointer); Assert.AreEqual(2, result.Count); Assert.IsTrue(result.Contains(new Point(2, 2, 700))); Assert.IsTrue(result.Contains(new Point(15, 8, 700))); }
public unsafe void Does_Create_Correct_Pointer() { var factory = new ArrayToPointerFactory(); var data = new ushort[] { 0, 0, 700, 700, 0, 0 }; var pointer = factory.CreatePointer(data); ushort *pDepth = (ushort *)pointer; for (int index = 0; index < data.Length; index++) { Assert.AreEqual(data[index], *pDepth); pDepth++; } factory.Destroy(pointer); }
public void Can_Create_Color_Image() { var imageFactory = new RgbImageSourceFactory(); var pointerFactory = new ArrayToPointerFactory(); var data = new ushort[20 * 10 * 2]; for (int index = data.Length / 2; index < data.Length; index++) { data[index] = ushort.MaxValue; } var bitmap = new WriteableBitmap(20, 10, 96, 96, PixelFormats.Bgr24, null); var pointer = pointerFactory.CreatePointer(data); try { imageFactory.CreateImage(bitmap, pointer); } finally { pointerFactory.Destroy(pointer); } int height = bitmap.PixelHeight; int width = bitmap.PixelWidth; int stride = bitmap.PixelWidth * 3; byte[] pixelByteArray = new byte[bitmap.PixelHeight * stride]; bitmap.CopyPixels(pixelByteArray, stride, 0); Assert.AreEqual(0, pixelByteArray[0]); Assert.AreEqual(0, pixelByteArray[1]); Assert.AreEqual(0, pixelByteArray[2]); Assert.AreEqual(255, pixelByteArray[10 * 3 + 9 * stride]); Assert.AreEqual(255, pixelByteArray[10 * 3 + 9 * stride + 1]); Assert.AreEqual(255, pixelByteArray[10 * 3 + 9 * stride + 2]); }
public void DepthImage_Colors_Fade_With_Distance() { var bitmap = new Bitmap(20, 10); var factory = new DepthBitmapFactory(200); var frame = new DepthDataFrame(20, 10); for (int index = 0; index < frame.Data.Length; index++) { frame.Data[index] = (ushort)index; } var pointerFactory = new ArrayToPointerFactory(); var pointer = pointerFactory.CreatePointer(frame.Data); try { factory.CreateImage(bitmap, pointer); AssertColorsFade(bitmap); } finally { pointerFactory.Destroy(pointer); } }