public void TestHashCodes() { var gray = new MemoryBitmap <Byte>(256, 256, Pixel.Luminance8.Format); Assert.AreEqual(256, gray.Info.StepByteSize); var grayWithStride = new MemoryBitmap <Byte>(256, 256, Pixel.Luminance8.Format, 320); Assert.AreEqual(320, grayWithStride.Info.StepByteSize); var rnd = new Random(117); for (int i = 0; i < 256 * 256; ++i) { gray.SetPixel(i & 255, i / 256, (Byte)rnd.Next()); } grayWithStride.SetPixels(0, 0, gray); Assert.AreEqual(gray.GetHashCode(), grayWithStride.GetHashCode()); var span = gray.AsSpanBitmap(); var less = span.AsTypeless(); var hash = gray.GetHashCode(); Assert.AreEqual(1953103375, hash); Assert.AreEqual(hash, gray.AsTypeless().GetHashCode()); Assert.AreEqual(hash, span.GetHashCode()); Assert.AreEqual(hash, less.GetHashCode()); }
public void TestPointerBitmapSlice() { void _testSlice(PointerBitmap ptr) { ptr = ptr.Slice((1, 1, 2, 2)); Assert.AreEqual(true, ptr.IsReadOnly); Assert.AreEqual(2, ptr.Width); Assert.AreEqual(2, ptr.Height); Assert.AreEqual(16, ptr.StepByteSize); var ptrSpan = ptr.AsSpanBitmapOfType <int>(); Assert.AreEqual(0, ptrSpan.GetPixel(0, 0)); Assert.AreEqual(0, ptrSpan.GetPixel(1, 0)); Assert.AreEqual(0, ptrSpan.GetPixel(0, 1)); Assert.AreEqual(0, ptrSpan.GetPixel(1, 1)); } var bmp = new MemoryBitmap <int>(4, 4, Pixel.ARGB32.Format); bmp.SetPixels(int.MaxValue); bmp.Slice((1, 1, 2, 2)).SetPixels(0); bmp.AsSpanBitmap().PinReadablePointer(_testSlice); }
public void LoadKinect2ColorFrame() { TestContext.CurrentContext.AttachFolderBrowserShortcut(); var src = MemoryBitmap <ushort> .Load(ResourceInfo.From("Kinect2Color.InteropBmp")); var dst = new MemoryBitmap <Pixel.BGR24>(src.Width, src.Height); dst.AsSpanBitmap().SetPixelsFromYUY2(src); dst.Save(AttachmentInfo.From("kinect2color.jpg")); }
public void TestTransformWithConversion() { var src = LoadShannonImage().OfType <Pixel.BGR24>(); src.Save(new AttachmentInfo("input.png")); var dst = new MemoryBitmap <Pixel.RGB96F>(512, 512); dst.AsSpanBitmap().SetPixels(Matrix3x2.CreateScale(0.7f), src.AsSpanBitmap(), true, 1); dst.Save(new AttachmentInfo("transformed.png")); }
public void TestTransform(bool useBilinear) { var src = LoadShannonImage().OfType <Pixel.BGR24>(); src.Save(new AttachmentInfo("input.png")); var filePath = System.IO.Path.Combine(TestContext.CurrentContext.TestDirectory, "Resources\\cat.png"); var cat00 = MemoryBitmap .Load(filePath, Codecs.GDICodec.Default) .OfType <Pixel.BGRA32>(); filePath = System.IO.Path.Combine(TestContext.CurrentContext.TestDirectory, "Resources\\QRCode.png"); var qrcode = MemoryBitmap .Load(filePath, Codecs.GDICodec.Default) .OfType <Pixel.BGRA32>(); var x = Matrix3x2.CreateScale(0.75f, 0.75f) * Matrix3x2.CreateRotation(0.25f); x.Translation = new Vector2(20, 20); Matrix3x2.Invert(x, out var xx); var dst = new MemoryBitmap <Pixel.BGR24>(512, 512); using (PerformanceBenchmark.Run(t => TestContext.WriteLine($"Transform {(int)t.TotalMilliseconds}ms"))) { dst.AsSpanBitmap().SetPixels(xx, src.AsSpanBitmap(), useBilinear); } for (float r = 0.1f; r < 1; r += 0.2f) { // 1st API var xform = Matrix3x2.CreateRotation(r) * Matrix3x2.CreateTranslation(50, 15); xform = Matrix3x2.CreateTranslation(-50, -50) * xform * Matrix3x2.CreateTranslation(50, 50); xform = xform * Matrix3x2.CreateScale(3, 3); dst.AsSpanBitmap().SetPixels(xform, cat00.AsSpanBitmap(), useBilinear, r); DrawBounds(dst, cat00.Bounds, xform, Colors.Red); // 2nd API xform *= Matrix3x2.CreateTranslation(0, 150); dst.AsSpanBitmap().SetPixels(xform, cat00.AsSpanBitmap(), useBilinear, r); DrawBounds(dst, cat00.Bounds, xform, Colors.Red); } dst.AsSpanBitmap().SetPixels(Matrix3x2.CreateScale(3), cat00.AsSpanBitmap(), useBilinear); dst.AsSpanBitmap().SetPixels(Matrix3x2.CreateScale(-.6f) * Matrix3x2.CreateTranslation(40, 200), cat00.AsSpanBitmap(), useBilinear); dst.AsSpanBitmap().SetPixels(Matrix3x2.CreateScale(.3f) * Matrix3x2.CreateRotation(1) * Matrix3x2.CreateTranslation(150, 300), qrcode.AsSpanBitmap(), useBilinear); dst.Save(new AttachmentInfo("transformed.png")); }
public void TestReinterpretBitmaps() { var src = new MemoryBitmap<Pixel.BGRA32>(16, 16); src.SetPixel(0, 0, (255, 0, 0, 255)); var dst = src.AsSpanBitmap().ReinterpretAs<Pixel.RGBA32>(); var p = dst.GetPixel(0, 0); Assert.AreEqual(0, p.R); Assert.AreEqual(0, p.G); Assert.AreEqual(255, p.B); // formerly R Assert.AreEqual(255, p.A); // float RGB to Vector3 var bgr = new MemoryBitmap<Pixel.BGR96F>(16, 16); var xyz = bgr.AsSpanBitmap().ReinterpretAs<System.Numerics.Vector3>(); }