guvcview-源码记录
guvcview源码记录
- 一、概述
- 二、项目结构
- 1. guvcview
- 2. gview_audio
- 3. gview_encoder
- 4. gview_render
- 1. render.c
- 2. render_sdl2.c
- 3. render_osd_crosshair.c
- 4. render_osd_vu_meter.c
- 5. render_fx.c
- 3. gview_v4l2core
- 三、
- 四、
- 五、
- 六、
一、概述
项目地址:guvcview http://guvcview.sourceforge.net
git clone https://git.code.sf.net/p/guvcview/git-master guvcview-git-master
二、项目结构
项目主要有以下五个模块构成,其目录结构如下:
guvcview模块为完整的应用,包括主窗口的显示,参数配置窗口。
1. guvcview
2. gview_audio
3. gview_encoder
4. gview_render
这里记录一下渲染模块的逻辑
1. render.c
对外提供的渲染接口,具体实现接口可以选择SDL或者是SFML实现,这里优先记录SDL的内容
2. render_sdl2.c
使用SDL实现rander.c中的函数
3. render_osd_crosshair.c
这个函数是界面中OSD配置的功能
就是相机中的这个十字准星
函数解读:
render_osd_crosshair 调用 plot_crosshair_yu12函数,通过对传入的YUV图像进行绘制。
render_osd_crosshair 函数主要是处理一下十字准星的颜色,将RGB转为YUV格式,具体实现在plot_crosshair_yu12。
/** 渲染十字准星* args:* frame - 传入 yuyv 数据的指针* width - 图像宽度* height - 图像高度** asserts:* none** returns: none*/
void render_osd_crosshair(uint8_t *frame, int width, int height)
{yuv_color_t color;color.y = 0;color.u = 0;color.v = 0;uint32_t rgb_color = render_get_crosshair_color();int size = render_get_crosshair_size();uint8_t r = (uint8_t) ((rgb_color & 0x00FF0000) >> 16);uint8_t g = (uint8_t) ((rgb_color & 0x0000FF00) >> 8);uint8_t b = (uint8_t) (rgb_color & 0x000000FF);color.y = CLIP(0.299*(r-128) + 0.587*(g-128) + 0.114*(b-128) + 128) ;color.u = CLIP(-0.147*(r-128) - 0.289*(g-128) + 0.436*(b-128) + 128);color.v = CLIP(0.615*(r-128) - 0.515*(g-128) - 0.100*(b-128) + 128);plot_crosshair_yu12(frame, size, width, height, &color);
}
准星由四条线构成,需要对Y和UV分量单独覆盖
/** plot a crosshair in a yu12 frame (planar)* args:* frame - pointer to yu12 frame data* size - frame line size in pixels (width)十字准星短线的长度* width - width,图像宽度* height - height,图像高度* color - line color** asserts:* none** returns: none*/
static void plot_crosshair_yu12(uint8_t *frame, int size, int width, int height, yuv_color_t *color)
{//找到YUV数据的地址uint8_t *py = frame;uint8_t *pu = frame + (width * height);uint8_t *pv = pu + ((width * height) / 4); /*y - 1st vertical line*/int h = (height-size)/2;for(h = (height-size)/2; h < height/2 - 2; h++){py = frame + (h * width) + width/2;*py = color->y;}/*y - 1st horizontal line*/int w = (width-size)/2;for(w = (width-size)/2; w < width/2 - 2; w++){py = frame + ((height/2) * width) + w;*py = color->y;}/*y - 2nd horizontal line*/for(w = width/2 + 2; w < (width+size)/2; w++){py = frame + ((height/2) * width) + w;*py = color->y;}/*y - 2nd vertical line*/for(h = height/2 + 2; h < (height+size)/2; h++){py = frame + (h * width) + width/2;*py = color->y;}/*u v - 1st vertical line*/for(h = (height-size)/4; h < height/4 - 1; h++) /*every two rows*/{pu = frame + (width * height) + (h * width/2) + width/4;*pu = color->u;pv = pu + (width * height)/4;*pv = color->v;}/*u v - 1st horizontal line*/for(w = (width-size)/4; w < width/4 - 1; w++) /*every two rows*/{pu = frame + (width * height) + ((height/4) * width/2) + w;*pu = color->u;pv = pu + (width * height)/4;*pv = color->v;}/*u v - 2nd horizontal line*/for(w = width/4 + 1; w < (width+size)/4; w++) /*every two rows*/{pu = frame + (width * height) + ((height/4) * width/2) + w;*pu = color->u;pv = pu + (width * height)/4;*pv = color->v;}/*u v - 2nd vertical line*/for(h = height/4 + 1; h < (height+size)/4; h++) /*every two rows*/{pu = frame + (width * height) + (h * width/2) + width/4;*pu = color->u;pv = pu + (width * height)/4;*pv = color->v;}
}
4. render_osd_vu_meter.c
这个文件是绘制音量键区域
激活就在录制视频时候激活
这个文件有三个函数
- plot_box_yu12:音量块儿
- plot_line_yu12:短线
- render_osd_vu_meter:组合上述音量块和短线组成的控件
5. render_fx.c
这个文件中是特殊的滤镜特效实现,具体内容比较多,
实现的函数具体如下