資源簡介
libyuv庫,包含RGB和yuv之間的轉換接口,圖像縮放接口等。包含頭文件libyuv.h即可,接口在yuv_convert.cpp中,代碼量很少,一看就懂。
代碼片段和文件信息
#include?“yuv_convert.h“
#include?
#include?
#include?
#include?
#include?
#include?
#include?
//#include?“util/time_util.hpp“
//#include?“base/log_system.hpp“
#ifdef?__cplusplus
extern?“C“?{
#endif
#include?“libyuv.h“
#ifdef?__cplusplus
}
#endif
using?namespace?libyuv;
//static?LogSystem?log_(“yuv_convert“);
//#define?debug_info(fmt?args...)?log_.Dbg(“%s@%d:?“?fmt?__FUNCTION__?__LINE__?##args)
//#define?print_info(fmt?args...)?log_.Info(“%s@%d:?“?fmt?__FUNCTION__?__LINE__?##args)
//#define?error_info(fmt?args...)?log_.Err(“%s@%d:?“?fmt?__FUNCTION__?__LINE__?##args)
int?fb_index?=?-1;
unsigned?char?*rgb_buffer;
unsigned?char?*yuv_buffer;
unsigned?char?*fb_mem;
unsigned?int?w;
unsigned?int?h;
void?ConvToI420(unsigned?char?*dataIn?unsigned?char?*dataOut?int?width?int?height?enum?ConvertType?type)
{
????unsigned?int?FourCC?=?0;
????switch?(type)?{
????????case?CONV_UYVY_TO_I420:
????????????FourCC?=?FOURCC_2VUY;
????????????break;
????????case?CONV_ABGR_TO_I420:
????????????FourCC?=?FOURCC_ABGR;
????????????break;
????????default:
????????????FourCC?=?FOURCC_2VUY;
????????????break;
????}
????//unsigned?long?long?int?time1?=?GetTimeOfSysUs();
????ConvertToI420(dataIn?width?*?height?*?3?/?2
??????????????????dataOut?width?dataOut?+?(width?*?height)?width?/?2?dataOut?+?(width?*?height?*?5?/?4)?width?/?2
??????????????????0?0?width?height?width?height?kRotate0?FourCC);
????//unsigned?long?long?int?time2?=?GetTimeOfSysUs();
????//debug_info(“ConvertToI420?delay:?%lldms\n“?(time2?-?time1)?/?1000);
}
void?ConvToARGB(unsigned?char?*dataIn?unsigned?char?*dataOut?int?width?int?height?enum?ConvertType?type)
{
????unsigned?int?FourCC?=?0;
????switch?(type)?{
????????case?CONV_I420_TO_ARGB:
????????????FourCC?=?FOURCC_IYUV;
????????????break;
????????case?CONV_UYVY_TO_ARGB:
????????????FourCC?=?FOURCC_2VUY;
????????????break;
????????default:
????????????FourCC?=?FOURCC_IYUV;
????????????break;
????}
????//unsigned?long?long?int?time1?=?GetTimeOfSysUs();
????ConvertToARGB(dataIn?width?*?height?*?3?/?2?dataOut?width?*?4?0?0?width?height?width?height?kRotate0?FourCC);
????//unsigned?long?long?int?time2?=?GetTimeOfSysUs();
????//debug_info(“ConvertToARGB?delay:?%lldms\n“?(time2?-?time1)?/?1000);
}
void?YuvInit(unsigned?int?width?unsigned?int?height)
{
????w?=?width;
????h?=?height;
????printf(“YuvInit?w:%d?h:%d\n“?w?h);
????rgb_buffer?=?(unsigned?char?*)malloc(w?*?h?*?4);
????yuv_buffer?=?(unsigned?char?*)malloc(w?*?h?*?2);
????system(“sudo?service?lightdm?stop“);
????fb_index?=?open(“/dev/fb0“?O_RDWR);
????fb_mem?=?(unsigned?char?*)mmap(NULL?w?*?h?*?4?PROT_READ?|?PROT_WRITE?MAP_SHARED?fb_index?0);
}
void?YuvWriteframe(unsigned?char?*data)
{
????ConvToARGB(data?rgb_buffer?w?h?CONV_I420_TO_ARGB);
????memcpy(fb_
- 上一篇:測距雷達距離模糊的兩種快速算法
- 下一篇:Jetson_Nano開發板原理圖.pdf
評論
共有 條評論