public static void AttachToCurrentTestAll(this SpanBitmap bmp, string filePath) { var mem = bmp.ToMemoryBitmap(); TestContext.WriteLine($"{filePath} {bmp.Info.ToDebuggerDisplayString()}"); if (bmp.PixelFormat == Pixel.BGR96F.Format || bmp.PixelFormat == Pixel.RGB96F.Format) { var tmp = new MemoryBitmap(bmp.Width, bmp.Height, Pixel.BGR24.Format); SpanBitmap.CopyPixels(bmp.OfType <System.Numerics.Vector3>(), tmp, (0, 1), (0, 255)); bmp = tmp; } AttachmentInfo _injectExt(string fp, string extPrefix) { var ext = System.IO.Path.GetExtension(fp); fp = fp.Substring(0, fp.Length - ext.Length); return(new AttachmentInfo($"{fp}.{extPrefix}{ext}")); } var f1 = _injectExt(filePath, "WPF"); mem.Save(f1, WPFCodec.Default); var f2 = _injectExt(filePath, "GDI"); mem.Save(f2, GDICodec.Default); var f3 = _injectExt(filePath, "ImageSharp"); mem.Save(f3, ImageSharpCodec.Default); var f4 = _injectExt(filePath, "SkiaSharp"); mem.Save(f4, SkiaCodec.Default); var f5 = _injectExt(filePath, "OpenCvSharp"); mem.Save(f5, OpenCvCodec.Default); var f6 = _injectExt(filePath, "STB"); mem.Save(f6, STBCodec.WithQuality(80)); // TODO: it should compare saved files against bmp }
public void CopyGreyPixels() { var src = new MemoryBitmap <float>(177, 177).Slice((10, 10, 150, 150)); var dst = new MemoryBitmap <Byte>(177, 177).Slice((10, 10, 150, 150)); src.SetPixels(1); var(min, max) = SpanBitmap.MinMax(src); Assert.AreEqual(min, 1); Assert.AreEqual(max, 1); SpanBitmap.CopyPixels(src, dst, (0, 128), (0, 255)); Assert.IsTrue(dst.EnumeratePixels().All(p => p.Pixel == 128)); SpanBitmap.CopyPixels(src, dst, (0, 1), (10, 255)); Assert.IsTrue(dst.EnumeratePixels().All(p => p.Pixel == 10)); SpanBitmap.CopyPixels(src, dst, (0, 1), (2, 3)); Assert.IsTrue(dst.EnumeratePixels().All(p => p.Pixel == 2)); }
public void CopyRGBPixels() { var src = new MemoryBitmap <Vector3>(177, 177).Slice((10, 10, 150, 150)); var dst = new MemoryBitmap <PixelBGR>(177, 177).Slice((10, 10, 150, 150)); src.SetPixels(Vector3.One); Assert.IsTrue(SpanBitmap.ArePixelsEqual(src, src)); SpanBitmap.CopyPixels(src, dst, (0, 128), (0, 255)); Assert.IsTrue(dst.EnumeratePixels().All(p => p.Pixel.Equals(new PixelBGR(128)))); SpanBitmap.CopyPixels(src, dst, (0, 1), (10, 255)); Assert.IsTrue(dst.EnumeratePixels().All(p => p.Pixel.Equals(new PixelBGR(10)))); SpanBitmap.CopyPixels(src, dst, (0, 1), (2, 3)); Assert.IsTrue(dst.EnumeratePixels().All(p => p.Pixel.Equals(new PixelBGR(2)))); Assert.IsTrue(SpanBitmap.ArePixelsEqual(dst, dst)); }