李国帅 写于2010
Rgb的surface可以使用getdc得到,并把图形绘制在dc上,但是yuv不可以,需要使用直接写内存的方式。
http://www.fourcc.org/yuv.php
在维基 On wiki http://en.wikipedia.org/wiki/YUV,
while on fourcc.org http://www.fourcc.org/fccyvrgb.php。
yuv的前面是亮度数据一个点对应一个byte,后面的u变量4个点对应一个数据,v变量和u变量一样。
int src_off = 4 * sizeof(int); //skip first 16 bytes,define by onself: size per line = 16BYTE int src_lineSize = *(int *)pOutData; int dst_off = 0; for (int i = 0; i < VideoHeight; i++)//亮度数据 { memcpy(pBuffer + dst_off, pOutData + src_off, src_lineSize); dst_off += lPitch; src_off += src_lineSize; } YUV_drawLine(pBuffer, VideoWidth, VideoHeight, lPitch, 100, 100, 200, 200, 200); for (int i = 0; i < VideoHeight; i++)//v变量和u变量 { memcpy(pBuffer + dst_off, pOutData + src_off, src_lineSize / 2); dst_off += lPitch / 2; src_off += src_lineSize / 2; } void YUV_drawLine(unsigned char *dst_buf, int w, int h, int lpitch, int x0, int y0, int x1, int y1, unsigned char color) { unsigned char *xoff; unsigned char *yoff; int rect_width = x1 - x0; int rect_height = y1 - y0; xoff = dst_buf + y0*lpitch + x0; memset(xoff, color, rect_width); xoff = dst_buf + y1*lpitch + x0; memset(xoff, color, rect_width); for (int i = 0; i < rect_height; i++) { yoff = dst_buf + (i + y0)*lpitch + x0; *yoff = color; yoff = dst_buf + (i + y0)*lpitch + x1; *yoff = color; } }