Exemplo n.º 1
0
        public void StrideTest1()
        {
            var strides = new VideoFormatInfo(PixelFormat.Rgba32, 800, 600).GetStrides(1);

            Assert.Single(strides);
            Assert.Equal(3200, strides[0]);
        }
Exemplo n.º 2
0
        public unsafe void Scale()
        {
            var sourceFormat = new VideoFormatInfo(PixelFormat.Bgra32, 1000, 1000);
            var targetFormat = new VideoFormatInfo(PixelFormat.Rgb24, 100, 100);

            using (var source = new VideoFrame(sourceFormat))
                using (var target = new VideoFrame(targetFormat))
                    using (var resampler = new VideoResampler(sourceFormat, targetFormat, SwsFlags.Lanczos))
                    {
                        Assert.Equal(300, target.Strides[0]);

                        var pixels = MemoryMarshal.Cast <byte, Bgra32>(source.Memory.Span);

                        pixels.Fill(new Bgra32(new Rgba32(1, 2, 3, 4)));

                        Assert.Equal(1000 * 1000 * 4, source.Memory.Length);
                        Assert.Equal(100 * 100 * 3, target.Memory.Length);

                        resampler.Resample(source, target);

                        int i = 0;

                        foreach (Rgb24 pixel in MemoryMarshal.Cast <byte, Rgb24>(target.Memory.Span))
                        {
                            if (!pixel.Equals(new Rgb24(1, 2, 3)))
                            {
                                throw new Exception($"{i} | {pixel.R},{pixel.B},{pixel.G})");
                            }

                            Assert.Equal(new Rgb24(1, 2, 3), pixel);

                            i++;
                        }
                    }
        }
Exemplo n.º 3
0
        public unsafe void ChangePixelFormat()
        {
            var sourceFormat = new VideoFormatInfo(PixelFormat.Bgra32, 100, 100);
            var targetFormat = new VideoFormatInfo(PixelFormat.Rgb24, 100, 100);

            using (var source = new VideoFrame(sourceFormat))
                using (var target = new VideoFrame(targetFormat))
                    using (var resampler = new VideoResampler(sourceFormat, targetFormat))
                    {
                        Assert.Equal(300, target.Strides[0]);

                        var pixels = MemoryMarshal.Cast <byte, Bgra32>(source.Memory.Span);

                        pixels.Fill(new Bgra32(new Rgba32(1, 2, 3, 4)));

                        Assert.Equal(100 * 100 * 4, source.Memory.Length);
                        Assert.Equal(100 * 100 * 3, target.Memory.Length);

                        resampler.Resample(source, target);

                        foreach (Rgb24 pixel in MemoryMarshal.Cast <byte, Rgb24>(target.Memory.Span))
                        {
                            Assert.Equal(new Rgb24(1, 2, 3), pixel);
                        }
                    }
        }
Exemplo n.º 4
0
        public void StrideTest3()
        {
            var strides = new VideoFormatInfo(PixelFormat.Yuv410p, 800, 600).GetStrides(1);

            Assert.Collection(strides,
                              a => Assert.Equal(800, a),
                              b => Assert.Equal(200, b),
                              c => Assert.Equal(200, c)
                              );
        }
Exemplo n.º 5
0
        public static int GetVideoFormatList(ref string CameraName, out VideoFormatInfo[] VideoFormatList, out int VideoFormatCount)
        {
            IntPtr pVideoFormatList = IntPtr.Zero;

            VideoFormatCount = 0;
            int res = FSDK_GetVideoFormatList_Old(CameraName, ref pVideoFormatList, out VideoFormatCount);

            VideoFormatList = new VideoFormatInfo[VideoFormatCount];
            for (int i = 0; i < VideoFormatCount; ++i)
            {
                VideoFormatList[i] = ((VideoFormatInfo *)pVideoFormatList)[i];
            }
            FSDK_FreeVideoFormatList(pVideoFormatList);
            return(res);
        }
Exemplo n.º 6
0
 private static extern int FSDK_SetVideoFormat_Old([In, MarshalAs(UnmanagedType.LPWStr)]string CameraName, VideoFormatInfo VideoFormat);
Exemplo n.º 7
0
 public static int SetVideoFormat(ref string CameraName, VideoFormatInfo VideoFormat)
 {
     return FSDK_SetVideoFormat_Old(CameraName, VideoFormat);
 }
Exemplo n.º 8
0
 public static int GetVideoFormatList(ref string CameraName, out VideoFormatInfo[] VideoFormatList, out int VideoFormatCount)
 {
     IntPtr pVideoFormatList = IntPtr.Zero;
     VideoFormatCount = 0;
     int res = FSDK_GetVideoFormatList_Old(CameraName, ref pVideoFormatList, out VideoFormatCount);
     VideoFormatList = new VideoFormatInfo[VideoFormatCount];
     for (int i = 0; i < VideoFormatCount; ++i){
         VideoFormatList[i] = ((VideoFormatInfo*)pVideoFormatList)[i];
     }
     FSDK_FreeVideoFormatList(pVideoFormatList);
     return res;
 }
Exemplo n.º 9
0
 public static int SetVideoFormat(ref string CameraName, VideoFormatInfo VideoFormat)
 {
     return(FSDK_SetVideoFormat_Old(CameraName, VideoFormat));
 }
Exemplo n.º 10
0
 private static extern int FSDK_SetVideoFormat_Old([In, MarshalAs(UnmanagedType.LPWStr)] string CameraName, VideoFormatInfo VideoFormat);