视频图像处理系列索引 || Arcgis/Engine/Server开发索引 || Web Map Gis开发索引 || jquery表格组件 JQGrid索引
WPF MVVM模式开发实现简明教程索引 || ArcGIS Runtime WPF(.net C#)开发简明教程索引

直接操作 SDL_Overlay YUV叠加上的像素

根据这篇解码出yuv数据后

海思h264解码库

y,u,v数据全部存进数组内,      
 
 IntPtr y = _decodeFrame.pY;
                IntPtr v = _decodeFrame.pV;
                IntPtr u = _decodeFrame.pU;
                byte[] ys = new byte[yLength];
                Marshal.Copy(y, ys, 0, yLength);
                byte[] vs = new byte[uLength];
                Marshal.Copy(v, vs, 0, uLength);
                byte[] us = new byte[uLength];
                Marshal.Copy(u, us, 0, uLength);
 
rgb转yuv转换矩阵C++,网上其他的不能用
//转换矩阵
#define MY(a,b,c) (( a*  0.2989  + b*  0.5866  + c*  0.1145))
#define MU(a,b,c) (( a*(-0.1688) + b*(-0.3312) + c*  0.5000 + 128))
#define MV(a,b,c) (( a*  0.5000  + b*(-0.4184) + c*(-0.0816) + 128))
 
 简单写个画线的函数以说明,遍历像素修改效率很低      1920为视频宽  1080p        
 
private void drawLineYUV(Point pnt1, Point pnt2, ref byte[] ys, ref byte[] vs, ref byte[] us, byte R, byte G, byte B)
        {
            //y1 = k x1 + b  b = y1 - k x1  
            //    y2 = k x2 + b k = (y2 - b)/ x2      k = (y2 - y1 - k x1)/ x2
            //(x-x1)/(x2-x1)=(y-y1)/(y2-y1)
            int x1 = pnt1.X;
            int x2 = pnt2.X;
            int y1 = pnt1.Y;
            int y2 = pnt2.Y;
            double k = 1;
            double b = 0;
            if (x1 == x2)
            {
                int ymin = y1, ymax = y2;
                if (y1 > y2)
                {
                    ymin = y2;
                    ymax = y1;
                }
                for (int h = ymin; h <= ymin; h++)
                {
                    int Y = (int)(0.299 * R + 0.587 * G + 0.114 * B);
                    ys[h * 1920 + x1] = (byte)Y;
                    vs[(int)((h * 1920 + x1 * 2) / 4)] = (byte)(int)(R * 0.5000 + G * (-0.4184) + B * (-0.0816) + 128);
                    us[(int)((h * 1920 + x1 * 2) / 4)] = (byte)(int)(R * (-0.1688) + G * (-0.3312) + B * 0.5000 + 128);
                }
            }
            else
            {
                int ymin = y1, ymax = y2;
                if (y1 > y2)
                {
                    ymin = y2;
                    ymax = y1;
                }
                int xmin = x1, xmax = x2;
                if (y1 > y2)
                {
                    xmin = x2;
                    xmax = x1;
                }
 
                k = (double)(ymax - ymin) / (double)(xmax - xmin);
                b = ymin - k * xmin;
 
                for (int w = xmin; w < xmax; w++)
                {
                    for (int h = ymin; h < ymax; h++)
                    {
                        if (Math.Abs(h - k * w - b) < 2)
                        {
                            int Y = (int)(0.299 * R + 0.587 * G + 0.114 * B);
                            ys[h * 1920 + w] = (byte)Y;
 
                            vs[(int)((h * 1920 + w * 2) / 4)] = (byte)(int)(R * 0.5000 + G * (-0.4184) + B * (-0.0816) + 128);
 
                            us[(int)((h * 1920 + w * 2) / 4)] = (byte)(int)(R * (-0.1688) + G * (-0.3312) + B * 0.5000 + 128);
                        }
                    }
                }
            }
        }
 
posted @ 2016-04-26 09:51  jhlong  阅读(1291)  评论(0编辑  收藏  举报
海龙的博客 jhlong@cnblogs 版权所有© 转载请注明链接.有用请推荐一下
代码全部经过本人测试,但不保证复制粘贴就正常运行,更不保证能解决你的问题,请结合前后代码及描述理解后修改和使用