Пример #1
0
        unsafe void IConversionProcessor.ConvertLine(byte *istart, byte *ostart, int cb)
        {
            ushort *ip = (ushort *)istart, ipe = (ushort *)(istart + cb);
            byte *  op = ostart;

#if HWINTRINSICS
            if (HWIntrinsics.IsSupported && cb >= HWIntrinsics.VectorCount <byte>() * 2)
            {
                convertIntrinsic(ip, ipe, op);
            }
            else
#endif
            convertScalar(ip, ipe, op);
        }
        public PlanarConversionTransform(PixelSource srcY, PixelSource srcCb, PixelSource srcCr, Matrix4x4 matrix, bool videoLevels) : base(srcY)
        {
            if (srcCb.Width != srcY.Width || srcCb.Height != srcY.Height)
            {
                throw new ArgumentException("Chroma plane incorrect size", nameof(srcCb));
            }
            if (srcCr.Width != srcY.Width || srcCr.Height != srcY.Height)
            {
                throw new ArgumentException("Chroma plane incorrect size", nameof(srcCr));
            }
            if (srcCb.Format.BitsPerPixel != srcY.Format.BitsPerPixel)
            {
                throw new ArgumentException("Chroma plane incorrect format", nameof(srcCb));
            }
            if (srcCr.Format.BitsPerPixel != srcY.Format.BitsPerPixel)
            {
                throw new ArgumentException("Chroma plane incorrect format", nameof(srcCr));
            }

            matrix = matrix.InvertPrecise();
            if (matrix.IsNaN())
            {
                throw new ArgumentException("Invalid YCC matrix", nameof(matrix));
            }

            sourceCb = srcCb;
            sourceCr = srcCr;

            if (videoLevels)
            {
                matrix *= byte.MaxValue / videoChromaScale;
            }

            coeffCb0 = matrix.M23;
            coeffCb1 = matrix.M22;
            coeffCr0 = matrix.M32;
            coeffCr1 = matrix.M31;

            Format = srcY.Format == PixelFormat.Y8Bpp ? PixelFormat.Bgr24Bpp : PixelFormat.Bgrx128BppFloat;

            int bufferStride = BufferStride;

            if (HWIntrinsics.IsAvxSupported)
            {
                bufferStride = PowerOfTwoCeiling(bufferStride, HWIntrinsics.VectorCount <byte>());
            }

            lineBuff = BufferPool.Rent(bufferStride * 3, true);
        }
        public PlanarConversionTransform(PixelSource srcY, PixelSource srcCb, PixelSource srcCr, Matrix4x4 matrix, bool videoLevels) : base(srcY)
        {
            if (srcCb.Width != srcY.Width || srcCb.Height != srcY.Height)
            {
                throw new ArgumentException("Chroma plane incorrect size", nameof(srcCb));
            }
            if (srcCr.Width != srcY.Width || srcCr.Height != srcY.Height)
            {
                throw new ArgumentException("Chroma plane incorrect size", nameof(srcCr));
            }
            if (srcCb.Format.BitsPerPixel != srcY.Format.BitsPerPixel)
            {
                throw new ArgumentException("Chroma plane incorrect format", nameof(srcCb));
            }
            if (srcCr.Format.BitsPerPixel != srcY.Format.BitsPerPixel)
            {
                throw new ArgumentException("Chroma plane incorrect format", nameof(srcCr));
            }

            matrix = matrix.InvertPrecise();
            if (matrix.IsNaN())
            {
                throw new ArgumentException("Invalid YCC matrix", nameof(matrix));
            }

            sourceCb = srcCb;
            sourceCr = srcCr;

            if (videoLevels)
            {
                matrix.M22 *= byte.MaxValue / videoChromaScale;
                matrix.M23 *= byte.MaxValue / videoChromaScale;
                matrix.M31 *= byte.MaxValue / videoChromaScale;
                matrix.M32 *= byte.MaxValue / videoChromaScale;
            }

            vec0 = new Vector4(matrix.M13, matrix.M23, matrix.M33, 0f);
            vec1 = new Vector4(matrix.M12, matrix.M22, matrix.M32, 0f);
            vec2 = new Vector4(matrix.M11, matrix.M21, matrix.M31, 0f);

            Format = srcY.Format.FormatGuid == Consts.GUID_WICPixelFormat8bppY ? PixelFormat.FromGuid(Consts.GUID_WICPixelFormat24bppBGR) : PixelFormat.Bgrx128BppFloat;
            if (HWIntrinsics.IsAvxSupported)
            {
                BufferStride = PowerOfTwoCeiling(BufferStride, HWIntrinsics.VectorCount <byte>());
            }

            lineBuff = BufferPool.Rent(BufferStride * 3, true);
        }