• libyuv 海思平台编译测试


    一、下载代码

    二、编译安装

            首先,新建install文件夹用于存放生成的安装文件

            然后,cmake编译

    1. mike@ubuntu:/home/guide/hisi/project/alg_test/libyuv/libyuv-main$
    2. cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_C_COMPILER=arm-himix200-linux-gcc -DCMAKE_CXX_COMPILER=arm-himix200-linux-g++ -DCMAKE_INSTALL_PREFIX=./install
    3. mike@ubuntu:/home/guide/hisi/project/alg_test/libyuv/libyuv-main$ make -j8
    4. mike@ubuntu:/home/guide/hisi/project/alg_test/libyuv/libyuv-main$ make install

            此时,可以看到在install文件夹下出现了编译后生成的bin include lib

    使用如下指令查看静态库文件的属性

    readelf -a libyuv.a 
    

     机器属性是ARM,说明确实是海思编译器编译生成的

    三、测试

    3.1测试代码

    1. #include
    2. #include
    3. #include
    4. #include
    5. #include
    6. #include "time.h"
    7. #include
    8. #include "libyuv.h"
    9. #include "bmp.h"
    10. enum ColorFormat {
    11. YUV_I420 = 0,
    12. YUV_NV21,
    13. YUV_NV12,
    14. BGR ,
    15. RGB ,
    16. BGRA,
    17. RGBA,
    18. ABGR,
    19. ARGB,
    20. };
    21. struct Buffer {
    22. uint32_t width, height;
    23. uint8_t *data[3];
    24. uint32_t stride[3];
    25. ColorFormat color;
    26. };
    27. typedef enum FilterMode {
    28. kFilterNone = 0, // Point sample; Fastest. 640*480--3.67
    29. kFilterLinear = 1, // Filter horizontally only.
    30. kFilterBilinear = 2, // Faster than box, but lower quality scaling down.
    31. kFilterBox = 3 // Highest quality.
    32. } FilterModeEnum;
    33. // void LibyuvResize_NV21(const Buffer *src, Buffer *dst);
    34. // void LibyuvResize_I420(const Buffer *src, Buffer *dst);
    35. void LibyuvResize_I420(const Buffer *src, Buffer *dst, int mode)
    36. {
    37. // you should make complete info of buffer src, stride data width height
    38. dst->stride[0] = dst->width; //stride for y
    39. dst->stride[1] = dst->width >> 1; //stride for u
    40. dst->stride[2] = dst->width >> 1; //stride for v
    41. uint32_t dst_y_size = dst->width * dst->height;
    42. uint32_t dst_u_size = dst->stride[1] * (dst->height >> 1);
    43. //uint32_t dst_v_size = dst->stride[2] * (dst->height >> 1);
    44. dst->data[1] = dst->data[0] + dst_y_size;
    45. dst->data[2] = dst->data[1] + dst_u_size;
    46. dst->color = ColorFormat::YUV_I420;
    47. if(mode==0)
    48. {
    49. libyuv::I420Scale(src->data[0], src->stride[0],
    50. src->data[1], src->stride[1],
    51. src->data[2], src->stride[2],
    52. src->width, src->height,
    53. dst->data[0], dst->stride[0],
    54. dst->data[1],dst->stride[1],
    55. dst->data[2],dst->stride[2],
    56. dst->width, dst->height,
    57. libyuv::FilterMode::kFilterNone);//
    58. }else if(mode==1)
    59. {
    60. libyuv::I420Scale(src->data[0], src->stride[0],
    61. src->data[1], src->stride[1],
    62. src->data[2], src->stride[2],
    63. src->width, src->height,
    64. dst->data[0], dst->stride[0],
    65. dst->data[1],dst->stride[1],
    66. dst->data[2],dst->stride[2],
    67. dst->width, dst->height,
    68. libyuv::FilterMode::kFilterLinear);//
    69. }else if(mode==2)
    70. {
    71. libyuv::I420Scale(src->data[0], src->stride[0],
    72. src->data[1], src->stride[1],
    73. src->data[2], src->stride[2],
    74. src->width, src->height,
    75. dst->data[0], dst->stride[0],
    76. dst->data[1],dst->stride[1],
    77. dst->data[2],dst->stride[2],
    78. dst->width, dst->height,
    79. libyuv::FilterMode::kFilterBilinear);//
    80. }else if(mode == 3)
    81. {
    82. libyuv::I420Scale(src->data[0], src->stride[0],
    83. src->data[1], src->stride[1],
    84. src->data[2], src->stride[2],
    85. src->width, src->height,
    86. dst->data[0], dst->stride[0],
    87. dst->data[1],dst->stride[1],
    88. dst->data[2],dst->stride[2],
    89. dst->width, dst->height,
    90. libyuv::FilterMode::kFilterBox);//
    91. }else{}
    92. }
    93. int main(void)
    94. {
    95. int i,j,k;
    96. int width = 256;//384;
    97. int height = 192;//288;
    98. int len = width*height;
    99. int len_i420 = width*height + width*height/2;//yyyy u v
    100. float time_use=0;
    101. struct timeval start_time;
    102. struct timeval end_time;
    103. struct timeval temp_time;
    104. FILE* fp = fopen("../../../append_file/car_384288.yuv", "rb");
    105. // FILE* fp = fopen("../../../append_file/256x16pic.raw", "rb");
    106. if (!fp)
    107. return -1;
    108. unsigned char *image_y8=(unsigned char*)malloc(len*3/2*sizeof(unsigned char));
    109. unsigned char *image_rgb888=(unsigned char*)malloc(len*3*sizeof(unsigned char));
    110. // unsigned char *image_i420=(unsigned char*)malloc(len_i420*sizeof(unsigned char));
    111. float scale = 1.5;
    112. int width_scale = scale * width;
    113. int height_scale = scale * height;
    114. int len_scale = width_scale*height_scale;
    115. unsigned char *result_y8 = (unsigned char*)malloc(len_scale*3/2*sizeof(unsigned char));
    116. unsigned char *result_rgb888 = (unsigned char*)malloc(len_scale*3*sizeof(unsigned char));
    117. fread(image_y8, 1, len, fp);
    118. for(i=0;i
    119. {
    120. for(j=0;j
    121. {
    122. image_rgb888[i*3*width + j*3] = image_y8[i*width+j];
    123. image_rgb888[i*3*width + j*3 + 1] = image_y8[i*width+j];
    124. image_rgb888[i*3*width + j*3 + 2] = image_y8[i*width+j];
    125. }
    126. }
    127. bmp_creator("123.bmp", image_rgb888, height, width);
    128. struct Buffer srcBuf, dstBuf;
    129. srcBuf.color = YUV_I420;
    130. srcBuf.width = width;
    131. srcBuf.height = height;
    132. srcBuf.stride[0] = width;
    133. srcBuf.stride[1] = width >> 1;
    134. srcBuf.stride[2] = width >> 1;
    135. uint32_t src_y_size = width * height;
    136. uint32_t src_u_size = srcBuf.stride[1] * (srcBuf.height >> 1);
    137. srcBuf.data[0] = image_y8;
    138. srcBuf.data[1] = srcBuf.data[0] + src_y_size;
    139. srcBuf.data[2] = srcBuf.data[1] + src_u_size;
    140. dstBuf.width = width_scale;
    141. dstBuf.height = height_scale;
    142. dstBuf.data[0] = result_y8;
    143. for(k=0;k<4;k++)
    144. {
    145. gettimeofday(&start_time,NULL);
    146. LibyuvResize_I420(&srcBuf, &dstBuf, k);
    147. gettimeofday(&end_time,NULL);
    148. time_use = (end_time.tv_sec-start_time.tv_sec)*1000000 + (end_time.tv_usec-start_time.tv_usec);//us
    149. printf("---- mode %d cost %8.2f ms \n", k, time_use/1000);
    150. }
    151. for(i=0;i
    152. {
    153. for(j=0;j
    154. {
    155. result_rgb888[i*3*width_scale + j*3] = result_y8[i*width_scale+j];
    156. result_rgb888[i*3*width_scale + j*3 + 1] = result_y8[i*width_scale+j];
    157. result_rgb888[i*3*width_scale + j*3 + 2] = result_y8[i*width_scale+j];
    158. }
    159. }
    160. bmp_creator("234.bmp", result_rgb888, height_scale, width_scale);
    161. fclose(fp);
    162. free(image_y8);
    163. free(image_rgb888);
    164. free(result_y8);
    165. free(result_rgb888);
    166. return 1;
    167. }

    3.2测试结果

    I420格式640*480放大1.5倍

    1. /mnt/alg_test/libyuv/test_app # ./demo
    2. ---- mode 0 cost 3.66 ms
    3. ---- mode 1 cost 4.76 ms
    4. ---- mode 2 cost 9.12 ms
    5. ---- mode 3 cost 9.13 ms

    I420格式256*192放大1.5倍

    1. ---- mode 0 cost 1.68 ms
    2. ---- mode 1 cost 2.12 ms
    3. ---- mode 2 cost 4.16 ms
    4. ---- 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