Пример #1
0
        /// <summary>
        /// Passes bitstream to the decoder.
        /// </summary>
        /// <param name="inbuf">Bitstream buffer to pass</param>
        /// <param name="offset">Index into inbuf</param>
        /// <param name="length">Number of bytes to use from inbuf</param>
        void PutBitstream(byte[] inbuf, int offset, int length)
        {
            FastMemcpyMemmove.memmove(bitstream.Data, bitstream.Data + (int)bitstream.DataOffset, (int)bitstream.DataLength);
            bitstream.DataOffset = 0;

            int free = (int)(bitstream.MaxLength - bitstream.DataLength);

            Trace.Assert(length <= free);

            Marshal.Copy(inbuf, offset, bitstream.Data + (int)bitstream.DataLength, length);

            bitstream.DataLength += (uint)length;
        }
Пример #2
0
        /// <summary>
        /// Puts the bitstream.
        /// </summary>
        /// <param name="inbuf">The inbuf.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="length">The length.</param>
        /// <exception cref="QuickSyncException">insufficient space in buffer</exception>
        public void PutBitstream(byte[] inbuf, int offset, int length)
        {
            FastMemcpyMemmove.memmove(bitstream.Data, bitstream.Data + (int)bitstream.DataOffset, (int)bitstream.DataLength);
            bitstream.DataOffset = 0;

            int free = (int)(bitstream.MaxLength - bitstream.DataLength);

            //Trace.Assert(length <= free);
            if (free < length)
            {
                throw new QuickSyncException("insufficient space in buffer");
            }

            Marshal.Copy(inbuf, offset, bitstream.Data + (int)bitstream.DataLength, length);

            bitstream.DataLength += (uint)length;
        }
Пример #3
0
      unsafe  static public Bitmap GetBitmap(this ILowLevelDecoder decoder, mfxFrameSurface1 surface)

        {
#if false
            //   if ( this.Data.MemId == IntPtr.Zero)
            {
                Trace.Assert(this.Info.FourCC == FourCC.NV12, "AsBitmap only works on NV12 currently");

                Bitmap bmp = new Bitmap(this.Info.CropW, this.Info.CropH, PixelFormat.Format32bppArgb);

                Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);

                //  var a = new FrameFormatConverterFromNV12(FourCC.BGR4,bmp.Width, bmp.Height);
                var a = new NV12ToXXXXLowLevelConverter();

                BitmapData bmpData = bmp.LockBits(rect, ImageLockMode.ReadWrite, bmp.PixelFormat);

                // Get the address of the first line.
                IntPtr ptr = bmpData.Scan0;

                a.ConvertFromNV12FrameSurface(FourCC.BGR4, this.Data.Y_ptr, this.Data.UV_ptr, (byte*)bmpData.Scan0, bmp.Width, bmp.Height,
                    bmpData.Stride * bmpData.Height, this.Info.CropW, bmpData.Stride);

                return bmp;
#else
            Trace.Assert(surface.Info.FourCC == FourCC.RGB4, "For vidmem, AsBitmap only works on RGB4 currently");

            Bitmap bmp = new Bitmap(surface.Info.CropW, surface.Info.CropH, PixelFormat.Format32bppArgb);

            Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);


            BitmapData bmpData;

            bmpData = bmp.LockBits(rect, ImageLockMode.ReadWrite, bmp.PixelFormat);
            // Get the address of the first line.
            IntPtr ptr = bmpData.Scan0;

            mfxFrameData fd = new mfxFrameData();

          
            decoder.LockFrame((IntPtr)(&surface));

            Console.WriteLine(fd.B);
            int pitch = fd.PitchHigh << 16 | fd.PitchLow;


            var zm = new byte[pitch * surface.Info.CropH];
            //for (int i = 0; i < zm.Length; i++)
            //{
            //    zm[i] = 1;
            //}
            //  Marshal.Copy(fd.B, zm, 0, zm.Length);
            //  Console.WriteLine(zm.Sum(z => (long)z));


            if (pitch == bmpData.Stride)
            {
                FastMemcpyMemmove.memcpy(ptr, fd.B, pitch * surface.Info.CropH);
            }
            else
            {
                int minpitch = Math.Min(pitch, bmpData.Stride);
                for (int i = 0; i < surface.Info.CropH; i++)
                {
                    FastMemcpyMemmove.memcpy(ptr + bmpData.Stride * i, fd.B + pitch * i, minpitch);
                }
            }
            decoder.UnlockFrame((IntPtr)(&surface));
            bmp.UnlockBits(bmpData);
            return bmp;

        }
#endif
    }