一、下载代码
二、编译安装
首先,新建install文件夹用于存放生成的安装文件
然后,cmake编译
- mike@ubuntu:/home/guide/hisi/project/alg_test/libyuv/libyuv-main$
- cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_C_COMPILER=arm-himix200-linux-gcc -DCMAKE_CXX_COMPILER=arm-himix200-linux-g++ -DCMAKE_INSTALL_PREFIX=./install
-
- mike@ubuntu:/home/guide/hisi/project/alg_test/libyuv/libyuv-main$ make -j8
-
- mike@ubuntu:/home/guide/hisi/project/alg_test/libyuv/libyuv-main$ make install
此时,可以看到在install文件夹下出现了编译后生成的bin include lib

使用如下指令查看静态库文件的属性
readelf -a libyuv.a

机器属性是ARM,说明确实是海思编译器编译生成的
三、测试
3.1测试代码
- #include
- #include
- #include
- #include
- #include
- #include "time.h"
- #include
-
- #include "libyuv.h"
- #include "bmp.h"
-
-
- enum ColorFormat {
- YUV_I420 = 0,
- YUV_NV21,
- YUV_NV12,
- BGR ,
- RGB ,
- BGRA,
- RGBA,
- ABGR,
- ARGB,
- };
-
-
- struct Buffer {
- uint32_t width, height;
- uint8_t *data[3];
- uint32_t stride[3];
- ColorFormat color;
- };
-
- typedef enum FilterMode {
- kFilterNone = 0, // Point sample; Fastest. 640*480--3.67
- kFilterLinear = 1, // Filter horizontally only.
- kFilterBilinear = 2, // Faster than box, but lower quality scaling down.
- kFilterBox = 3 // Highest quality.
- } FilterModeEnum;
-
- // void LibyuvResize_NV21(const Buffer *src, Buffer *dst);
- // void LibyuvResize_I420(const Buffer *src, Buffer *dst);
-
- void LibyuvResize_I420(const Buffer *src, Buffer *dst, int mode)
- {
- // you should make complete info of buffer src, stride data width height
- dst->stride[0] = dst->width; //stride for y
- dst->stride[1] = dst->width >> 1; //stride for u
- dst->stride[2] = dst->width >> 1; //stride for v
- uint32_t dst_y_size = dst->width * dst->height;
- uint32_t dst_u_size = dst->stride[1] * (dst->height >> 1);
- //uint32_t dst_v_size = dst->stride[2] * (dst->height >> 1);
- dst->data[1] = dst->data[0] + dst_y_size;
- dst->data[2] = dst->data[1] + dst_u_size;
- dst->color = ColorFormat::YUV_I420;
-
- if(mode==0)
- {
- libyuv::I420Scale(src->data[0], src->stride[0],
- src->data[1], src->stride[1],
- src->data[2], src->stride[2],
- src->width, src->height,
- dst->data[0], dst->stride[0],
- dst->data[1],dst->stride[1],
- dst->data[2],dst->stride[2],
- dst->width, dst->height,
- libyuv::FilterMode::kFilterNone);//
- }else if(mode==1)
- {
- libyuv::I420Scale(src->data[0], src->stride[0],
- src->data[1], src->stride[1],
- src->data[2], src->stride[2],
- src->width, src->height,
- dst->data[0], dst->stride[0],
- dst->data[1],dst->stride[1],
- dst->data[2],dst->stride[2],
- dst->width, dst->height,
- libyuv::FilterMode::kFilterLinear);//
- }else if(mode==2)
- {
- libyuv::I420Scale(src->data[0], src->stride[0],
- src->data[1], src->stride[1],
- src->data[2], src->stride[2],
- src->width, src->height,
- dst->data[0], dst->stride[0],
- dst->data[1],dst->stride[1],
- dst->data[2],dst->stride[2],
- dst->width, dst->height,
- libyuv::FilterMode::kFilterBilinear);//
- }else if(mode == 3)
- {
- libyuv::I420Scale(src->data[0], src->stride[0],
- src->data[1], src->stride[1],
- src->data[2], src->stride[2],
- src->width, src->height,
- dst->data[0], dst->stride[0],
- dst->data[1],dst->stride[1],
- dst->data[2],dst->stride[2],
- dst->width, dst->height,
- libyuv::FilterMode::kFilterBox);//
- }else{}
-
- }
-
-
- int main(void)
- {
- int i,j,k;
- int width = 256;//384;
- int height = 192;//288;
- int len = width*height;
- int len_i420 = width*height + width*height/2;//yyyy u v
-
- float time_use=0;
- struct timeval start_time;
- struct timeval end_time;
- struct timeval temp_time;
-
- FILE* fp = fopen("../../../append_file/car_384288.yuv", "rb");
- // FILE* fp = fopen("../../../append_file/256x16pic.raw", "rb");
- if (!fp)
- return -1;
-
- unsigned char *image_y8=(unsigned char*)malloc(len*3/2*sizeof(unsigned char));
- unsigned char *image_rgb888=(unsigned char*)malloc(len*3*sizeof(unsigned char));
- // unsigned char *image_i420=(unsigned char*)malloc(len_i420*sizeof(unsigned char));
-
- float scale = 1.5;
- int width_scale = scale * width;
- int height_scale = scale * height;
- int len_scale = width_scale*height_scale;
- unsigned char *result_y8 = (unsigned char*)malloc(len_scale*3/2*sizeof(unsigned char));
- unsigned char *result_rgb888 = (unsigned char*)malloc(len_scale*3*sizeof(unsigned char));
-
- fread(image_y8, 1, len, fp);
-
- for(i=0;i
- {
- for(j=0;j
- {
- image_rgb888[i*3*width + j*3] = image_y8[i*width+j];
- image_rgb888[i*3*width + j*3 + 1] = image_y8[i*width+j];
- image_rgb888[i*3*width + j*3 + 2] = image_y8[i*width+j];
- }
- }
-
- bmp_creator("123.bmp", image_rgb888, height, width);
-
- struct Buffer srcBuf, dstBuf;
- srcBuf.color = YUV_I420;
- srcBuf.width = width;
- srcBuf.height = height;
- srcBuf.stride[0] = width;
- srcBuf.stride[1] = width >> 1;
- srcBuf.stride[2] = width >> 1;
- uint32_t src_y_size = width * height;
- uint32_t src_u_size = srcBuf.stride[1] * (srcBuf.height >> 1);
- srcBuf.data[0] = image_y8;
- srcBuf.data[1] = srcBuf.data[0] + src_y_size;
- srcBuf.data[2] = srcBuf.data[1] + src_u_size;
-
- dstBuf.width = width_scale;
- dstBuf.height = height_scale;
- dstBuf.data[0] = result_y8;
-
- for(k=0;k<4;k++)
- {
- gettimeofday(&start_time,NULL);
- LibyuvResize_I420(&srcBuf, &dstBuf, k);
- gettimeofday(&end_time,NULL);
- time_use = (end_time.tv_sec-start_time.tv_sec)*1000000 + (end_time.tv_usec-start_time.tv_usec);//us
- printf("---- mode %d cost %8.2f ms \n", k, time_use/1000);
- }
-
-
-
- for(i=0;i
- {
- for(j=0;j
- {
- result_rgb888[i*3*width_scale + j*3] = result_y8[i*width_scale+j];
- result_rgb888[i*3*width_scale + j*3 + 1] = result_y8[i*width_scale+j];
- result_rgb888[i*3*width_scale + j*3 + 2] = result_y8[i*width_scale+j];
- }
- }
-
- bmp_creator("234.bmp", result_rgb888, height_scale, width_scale);
-
- fclose(fp);
- free(image_y8);
- free(image_rgb888);
-
- free(result_y8);
- free(result_rgb888);
-
- return 1;
- }
-
-
-
-
-
-
3.2测试结果
I420格式640*480放大1.5倍
- /mnt/alg_test/libyuv/test_app # ./demo
- ---- mode 0 cost 3.66 ms
- ---- mode 1 cost 4.76 ms
- ---- mode 2 cost 9.12 ms
- ---- mode 3 cost 9.13 ms
I420格式256*192放大1.5倍
- ---- mode 0 cost 1.68 ms
- ---- mode 1 cost 2.12 ms
- ---- mode 2 cost 4.16 ms
- ---- mode 3 cost 4.02 ms
-
相关阅读:
编译原理期末复习
html2canvas将html代码生成canvas转换成图片,并且保存到本地
C#界面里的winform AutoScaleMode属性
NVIDIA TX2 与 维特 IMU CAN通信
【办公类-06】python批量制作代班排班表
文本转拼音易语言代码
如何运用并行编程Parallel提升任务执行效率
SpringBoot&Vue&EmementUI前后端分离整合、统一封装axios、跨域配置
成功的程序化交易者需要具备什么技能?
ARM的工作模式
-
原文地址:https://blog.csdn.net/fuhanga123/article/details/125893935