Ejemplo n.º 1
0
        public unsafe SpanPlanesXYZ(int width, int height)
        {
            var dataX = System.Runtime.InteropServices.MemoryMarshal.Cast <TComponent, byte>(new TComponent[width * height]);
            var dataY = System.Runtime.InteropServices.MemoryMarshal.Cast <TComponent, byte>(new TComponent[width * height]);
            var dataZ = System.Runtime.InteropServices.MemoryMarshal.Cast <TComponent, byte>(new TComponent[width * height]);

            X = new SpanBitmap <TComponent>(dataX, width, height);
            Y = new SpanBitmap <TComponent>(dataY, width, height);
            Z = new SpanBitmap <TComponent>(dataZ, width, height);
        }
Ejemplo n.º 2
0
        public SpanPlanesXYZ(SpanBitmap <TComponent> x, SpanBitmap <TComponent> y, SpanBitmap <TComponent> z)
        {
            if (x.Width != y.Width || x.Height != y.Height)
            {
                throw new ArgumentException(_Error_AllChannelsEqualSize, nameof(y));
            }
            if (x.Width != z.Width || x.Height != z.Height)
            {
                throw new ArgumentException(_Error_AllChannelsEqualSize, nameof(z));
            }

            X = x;
            Y = y;
            Z = z;
        }
Ejemplo n.º 3
0
        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
        }
Ejemplo n.º 4
0
        public static void CopyPixels(SpanBitmap dst, SpanBitmap src) // Copy
        {
            Guard.AreEqual(nameof(src), dst.Width, src.Width);
            Guard.AreEqual(nameof(src), dst.Height, src.Height);

            src = src.AsReadOnly();

            var rowConverter = Pixel.GetByteCopyConverter(src.PixelFormat, dst.PixelFormat);

            for (int y = 0; y < dst.Height; ++y)
            {
                var dstRow = dst.UseScanlineBytes(y);
                var srcRow = src.UseScanlineBytes(y);
                rowConverter(srcRow, dstRow);
            }
        }
Ejemplo n.º 5
0
        public static (Vector4 Min, Vector4 Max) MinMax(SpanBitmap <Vector4> src)
        {
            var min = new Vector4(float.PositiveInfinity);
            var max = new Vector4(float.NegativeInfinity);

            for (int y = 0; y < src.Height; ++y)
            {
                var srcRow = src.GetScanlinePixels(y);

                for (int x = 0; x < srcRow.Length; ++x)
                {
                    var p = srcRow[x];
                    min = Vector4.Min(min, p);
                    max = Vector4.Max(max, p);
                }
            }

            return(min, max);
        }
Ejemplo n.º 6
0
        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));
        }
Ejemplo n.º 7
0
        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));
        }
Ejemplo n.º 8
0
        public static (Single Min, Single Max) MinMax(SpanBitmap <float> src)
        {
            var min = float.PositiveInfinity;
            var max = float.NegativeInfinity;

            for (int y = 0; y < src.Height; ++y)
            {
                var srcRow = src.GetScanlinePixels(y);

                var(rMin, rMax) = Vector4Streaming.MinMax(srcRow);

                if (min > rMin)
                {
                    min = rMin;
                }
                if (max < rMax)
                {
                    max = rMax;
                }
            }

            return(min, max);
        }
Ejemplo n.º 9
0
 public static void CopyPixels(SpanBitmap <Byte> src, SpanBitmap <Single> dst, (Single offset, Single scale) transform, (Single min, Single max) range)
Ejemplo n.º 10
0
 public static void PinTransferPointers(SpanBitmap src, SpanBitmap dst, PointerBitmap.Action2 onPinned)
 {
     _SpanBitmapImpl.PinTransferPointers(src, dst, onPinned);
 }
Ejemplo n.º 11
0
 public static void SetPixels <TSrcPixel, TDstPixel>(this SpanBitmap <TDstPixel> target, SpanBitmap <TSrcPixel> source, Processing.Kernel3x3 <TDstPixel> .KernelEvaluator <TDstPixel> function)
     where TSrcPixel : unmanaged
     where TDstPixel : unmanaged
 {
     Processing.Kernel3x3 <TDstPixel> .Copy(source, target, function);
 }
Ejemplo n.º 12
0
 public static void Apply <TPixel, TKernelPixel>(this SpanBitmap <TPixel> target, Processing.Kernel3x3 <TKernelPixel> .KernelEvaluator <TPixel> function)
     where TPixel : unmanaged
     where TKernelPixel : unmanaged
 {
     Processing.Kernel3x3 <TKernelPixel> .Apply(target, function);
 }
Ejemplo n.º 13
0
 public SpanBitmap(SpanBitmap other, bool isReadOnly = false)
 {
     _Info     = other.Info;
     _Readable = other._Readable;
     _Writable = isReadOnly ? null : other._Writable;
 }