Esempio n. 1
0
                public static void TransferYUV420 <TDstPixel>(Span <TDstPixel> dst0, Span <TDstPixel> dst1, ReadOnlySpan <Byte> srcY0, ReadOnlySpan <Byte> srcY1, ReadOnlySpan <ushort> srcU, ReadOnlySpan <ushort> srcV)
                    where TDstPixel : unmanaged
                {
                    KernelRGB yuv = default;

                    if (typeof(TDstPixel) == typeof(BGR24))
                    {
                        var dst00 = System.Runtime.InteropServices.MemoryMarshal.Cast <TDstPixel, BGR24>(dst0);
                        var dst11 = System.Runtime.InteropServices.MemoryMarshal.Cast <TDstPixel, BGR24>(dst1);

                        for (int x = 0; x < dst0.Length - 1; x += 2)
                        {
                            yuv.SetUV(srcU[x / 2] >> 8, srcV[x / 2] >> 8);

                            yuv.CopyTo(ref dst00[x + 0], srcY0[x + 0]);
                            yuv.CopyTo(ref dst00[x + 1], srcY0[x + 1]);
                            yuv.CopyTo(ref dst11[x + 0], srcY1[x + 0]);
                            yuv.CopyTo(ref dst11[x + 1], srcY1[x + 1]);
                        }

                        return;
                    }

                    if (typeof(TDstPixel) == typeof(RGB24))
                    {
                        var dst00 = System.Runtime.InteropServices.MemoryMarshal.Cast <TDstPixel, RGB24>(dst0);
                        var dst11 = System.Runtime.InteropServices.MemoryMarshal.Cast <TDstPixel, RGB24>(dst1);

                        for (int x = 0; x < dst0.Length - 1; x += 2)
                        {
                            yuv.SetUV(srcU[x / 2] >> 8, srcV[x / 2] >> 8);

                            yuv.CopyTo(ref dst00[x + 0], srcY0[x + 0]);
                            yuv.CopyTo(ref dst00[x + 1], srcY0[x + 1]);
                            yuv.CopyTo(ref dst11[x + 0], srcY1[x + 0]);
                            yuv.CopyTo(ref dst11[x + 1], srcY1[x + 1]);
                        }

                        return;
                    }

                    throw new NotImplementedException();
                }
Esempio n. 2
0
                public static void TransferYUY2 <TDstPixel>(Span <TDstPixel> dst, ReadOnlySpan <ushort> src)
                    where TDstPixel : unmanaged
                {
                    KernelRGB yuv = default;

                    var len = Math.Min(dst.Length, src.Length) - 1;

                    var srcb = System.Runtime.InteropServices.MemoryMarshal.Cast <ushort, byte>(src);

                    if (typeof(TDstPixel) == typeof(BGR24))
                    {
                        var dstb = System.Runtime.InteropServices.MemoryMarshal.Cast <TDstPixel, BGR24>(dst);

                        for (int x = 0; x < len; x += 2)
                        {
                            var xx = x * 2;
                            yuv.SetUV(srcb[xx + 1], srcb[xx + 3]);
                            yuv.CopyTo(ref dstb[x + 0], srcb[xx + 0]);
                            yuv.CopyTo(ref dstb[x + 1], srcb[xx + 2]);
                        }

                        return;
                    }

                    if (typeof(TDstPixel) == typeof(RGB24))
                    {
                        var dstb = System.Runtime.InteropServices.MemoryMarshal.Cast <TDstPixel, RGB24>(dst);

                        for (int x = 0; x < len; x += 2)
                        {
                            var xx = x * 2;
                            yuv.SetUV(srcb[xx + 1], srcb[xx + 3]);
                            yuv.CopyTo(ref dstb[x + 0], srcb[xx + 0]);
                            yuv.CopyTo(ref dstb[x + 1], srcb[xx + 2]);
                        }

                        return;
                    }

                    throw new NotImplementedException();
                }