libyuv 再次封装打包与测试
目录
一、接口函数
二、编译封装
三、测试
四、参考文献
上篇文章中进行了libyuv在HI3516平台上的编译和测试。libyuv所处理的数据类型一般都是NV21 YUV420格式。需求端客户要对8位的灰度图像进行放缩处理,同时对外发布版本的时候不能直接告诉客户我们用的是libyuv,所以需要对libyuv进行一次函数接口重新封装,打包成一个我们自己的库对外发布。
一、接口函数
函数目的是对把输入的Y8数据转换成I420送入yuvlib,同时将放缩后的result中的y8抠出来,送出,代码如下:
#include <iostream>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "libyuv.h"
#include "y8_resize.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.67kFilterLinear = 1, // Filter horizontally only.kFilterBilinear = 2, // Faster than box, but lower quality scaling down.kFilterBox = 3 // Highest quality.
} FilterModeEnum;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 ydst->stride[1] = dst->width >> 1; //stride for udst->stride[2] = dst->width >> 1; //stride for vuint32_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{printf("Mode error \n");}}int guide_y8_resize(unsigned char *srcImg, int width, int height,unsigned char *dstImg, float scale, int mode)
{int i,j,k;int len = width*height;int len_i420 = width*height + width*height/2;//yyyy u vint width_scale = scale * width;int height_scale = scale * height;int len_scale = width_scale*height_scale;unsigned char *image_uv=(unsigned char*)malloc(len/2*sizeof(unsigned char));unsigned char *result_uv = (unsigned char*)malloc(len_scale/2*sizeof(unsigned char));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 = len;uint32_t src_u_size = srcBuf.stride[1] * (srcBuf.height >> 1);srcBuf.data[0] = srcImg;//image_y8;srcBuf.data[1] = image_uv;//srcBuf.data[0] + src_y_size;srcBuf.data[2] = srcBuf.data[1] + src_u_size;dstBuf.width = width_scale;dstBuf.height = height_scale;uint32_t dst_u_size = width_scale / 2 * height_scale / 2;dstBuf.data[0] = dstImg;//result_y8;dstBuf.data[1] = result_uv;dstBuf.data[2] = dstBuf.data[1] + dst_u_size;LibyuvResize_I420(&srcBuf, &dstBuf, mode);free(image_uv);free(result_uv);return 1;
}
二、编译封装
这里分别把编译动态库和静态库的makefile贴出来
#########################################
############ make xx.so
#########################################CHIP = arm-himix200-linux-
#CHIP = arm-linux-gnueabihf-
#CHIP = arm-fsl-linux-gnueabi-CC = $(CHIP)gcc
CXX= $(CHIP)g++objects = y8_resize.o libyuv.aCFLAGS = -O3 -mfpu=neon -mthumb -march=armv7-a -funsafe-math-optimizations -mfloat-abi=softfp
CFLAGS += -fPIC -shared
CFLAGS += -std=c++11 -Wno-narrowingTOPDIR=.
CFLAGS += -I$(TOPDIR)/include
.PHONY:allall:libImage.so libImage.so: $(objects)@echo ------------linking...$(CC) $(CFLAGS) -o $@ $^ -lc -lpthread -ldl@echo ------------ libImage.so over !!!.c.o:@echo ------------gcc .c $(CC) $(CFLAGS) -c $^ .cpp.o:@echo ------------g++ .cpp$(CXX) $(CFLAGS) -c -fPIC $^clean:rm -f libImage.so *.o; pwd;
###############################
############### make xx.a
################################CHIP = arm-himix200-linux-
#CHIP = arm-linux-gnueabihf-
#CHIP = arm-fsl-linux-gnueabi-CC = $(CHIP)gcc
CXX= $(CHIP)g++
AR = $(CHIP)ar
AS = $(CHIP)asobjects = y8_resize.o libyuv.aCFLAGS = -O3 -mfpu=neon -mthumb -march=armv7-a -funsafe-math-optimizations -mfloat-abi=softfp
CFLAGS += -fPIC -shared
CFLAGS += -std=c++11 -Wno-narrowingTOPDIR=.
CFLAGS += -I$(TOPDIR)/include
.PHONY:allall: libImage.alibImage.a: $(objects)@echo ------------linking...
# $(AR) -o $@ $^ -lc -lpthread -ldl$(AR) -crv libyuv.a y8_resize.o@echo ------------libImage.a over !!!.c.o:@echo ------------gcc .c $(CC) $(CFLAGS) -c $^ .cpp.o:@echo ------------g++ .cpp$(CXX) $(CFLAGS) -c -fPIC $^clean:rm -f libImage.a *.o; pwd;
这里需要说明的是,$(AR) -crv libyuv.a y8_resize.o 是把y8_resize.o打包到了libyuv.a中,此时的libyuv.a已经不再是原始的libyuv库中编译出来的libyuv.a。
三、测试
测试代码如下:
#include <iostream>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "time.h"
#include "bmp.h"
#include <sys/time.h>
#include "y8_resize.h" int main(void)
{int i,j,k;int width = 384;//256;//384;int height = 288;//192;//288;int len = width*height;int len_i420 = width*height + width*height/2;//yyyy u vfloat 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/256_192.raw", "rb");//y16if (!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<height;i++){for(j=0;j<width;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);for(k=0;k<5;k++){gettimeofday(&start_time,NULL);guide_y8_resize(image_y8, width, height, result_y8, scale, k);gettimeofday(&end_time,NULL);time_use = (end_time.tv_sec-start_time.tv_sec)*1000000 + (end_time.tv_usec-start_time.tv_usec);//usprintf("---- guide_y8_resize mode %d cost %8.2f ms \n", k, time_use/1000);}for(i=0;i<height_scale;i++){for(j=0;j<width_scale;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;
}
app的makefile
objects = test.o bmp.o
CFLAGS = -O3 -mfpu=neon -mthumb -march=armv7-a -funsafe-math-optimizations -mfloat-abi=softfp
CFLAGS += -std=c++11 -Wno-narrowing
TOPDIR=.
CFLAGS += -I$(TOPDIR)/include
.PHONY:allall:demodemo: $(objects)@echo ------------linking...
# arm-himix200-linux-g++ $(CFLAGS) -o $@ $^ -lc -lgomp -lpthread -ldl -L./ -lImagearm-himix200-linux-g++ $(CFLAGS) -o $@ $^ -lc -lgomp -lpthread -ldl -L./ -lyuv@echo ------------over !!!
# cp demo ./bin; mv *.o ./bin.c.o:@echo ------------gcc .c arm-himix200-linux-gcc $(CFLAGS) -c $^ .cpp.o:@echo ------------g++ .cpparm-himix200-linux-g++ $(CFLAGS) -c $^clean:rm -f demo *.o; pwd;
测试结果:(测试前请删除前面生成的libImage.so以便验证静态库的有效性)
/mnt/alg_test/libyuv/diy_lib_test/test_lib # ./demo
---- guide_y8_resize mode 0 cost 3.75 ms
---- guide_y8_resize mode 1 cost 4.78 ms
---- guide_y8_resize mode 2 cost 9.17 ms
---- guide_y8_resize mode 3 cost 9.13 ms
Mode error
---- guide_y8_resize mode 4 cost 0.06 ms
四、参考文献
Linux 静态库 编译和使用
C++静态库与动态库
libyuv 再次封装打包与测试相关推荐
- NSIS使用教程(安装包制作安装文件教程,如何封装打包文件) 中文版
NSIS使用教程(安装包制作安装文件教程,如何封装打包文件) 中文版 原文:NSIS使用教程(安装包制作安装文件教程,如何封装打包文件) 中文版 nsis中文版(Nullsoft Scriptable ...
- Python 程序封装-打包成exe程序
Python 程序封装-打包成exe程序 前言 一. Python 打包工具-Pyinstaller 二.打包具体过程 1. 打包成仅包含一个独立的exe程序 2. 打包成包含文件夹的程序,内有相关的 ...
- python怎么封装方法然后调用_Python实现封装打包自己写的代码,被python import
1.新建一个文件夹example,里面放入要打包的.py文件,以及必需的_init_.py. 代码如下: # -*- coding: utf-8 -*- """ Crea ...
- app应用分发平台|苹果ios超级签名|APP封装打包|应用内测托管平台|iOS应用企业签名|Android应用上传内测-虾分发
CDN分发平台-注册免审核-虾分发 https://xiafenfa.com/ app应用分发平台|苹果ios超级签名|APP封装打包|应用内测托管平台|iOS应用企业签名|Android应用上传内测 ...
- linux整盘封装生成iso,一键自安装ISO封装打包脚本 | 聂扬帆博客
对于经常打包ISO的来说,每次都要运行那几行命令很没效率.于是就整理了一个自动封装打包ISO的脚本.#!/bin/sh workpath="/CentOS/7" pack_dir= ...
- PHP安卓苹果APP在线封装打包制作源码 H5手机网站转APP 免签封装绿标
简介: PHP安卓苹果APP在线封装打包制作源码 H5手机网站转APP 免签封装绿标 更新记录: 1.解决ios无法下载的问题 2.优化打包流程 修复原先各种问题 3.可自行上传安卓证书 4.可自行上 ...
- MATLAB如何进行封装打包成独立可执行exe.
写作时间:2021年12月31日起,2022年1月4日止. MATLAB进行封装打包, 首先说明这是两件事情,第一是封装:第二是打包(打包并非一键即可完成). 怎样服用本文?→见本文解决的问题,若认为 ...
- | 应用打包还是测试团队老大难问题?
如果接口测试仅仅只是掌握一些requests或者其他一些功能强大的库的用法,是远远不够的,还需要具有根据公司的业务以及需求去定制化一个接口自动化测试框架能力.所以在这个部分,会主要介绍接口测试用例分析 ...
- vue项目构建实战基础知识:SPA理解/RESTful接口介绍/static目录配置/axios封装/打包时map文件去除...
一.SPA 不是指水疗.是 single page web application 的缩写.中文翻译为 单页应用程序 或 单页Web应用,更多解释请自行搜索. 所有的前端人员都应该明白我们的页面的 u ...
- h5是可以一键打包小程序的_H5手机网站封装打包微信小程序并实现分享及微信支付...
手机网站打包小程序教程,生成小程序,网页版小程序 打包微信小程序,H5封装成微信小程序. 微信小程序开发一般分为2种方式,一种就是原生开发小程序,一种是将手机网站打包成小程序. 原生开发小程序成本较 ...
最新文章
- php token的生成和使用
- C++/C++11中头文件numeric的使用
- ndarray保存成文本
- 【深度学习】NetAug(网络增强)—Dropout的反面
- 我妈要把闺蜜介绍给我当女朋友......
- 按规律插入一个数字到数组中
- 团伙(信息学奥赛一本通-T1385)
- 华为服务器存储系列,华为 服务器 存储相关资料(示例代码)
- 库克用iPhone12 Pro Max发中秋祝福 网友调侃:库克也没抢到iPhone13?
- 什么是ie浏览器_关于几款电脑浏览器的使用感受,你用过吗?
- python项目依赖库打包发布方法
- Linux之centos7 VMware安装教程
- UE4 C++:Interface接口
- MeGUI中文版x64版本使用说明
- CM源码(CyanogenMod)源码编译
- 温一壶月光下的酒——林清玄
- Kali Linux蓝牙连接问题解决
- 做门户网站 个人站长的新好出路
- APP推广案例之星巴克APP营销方式
- 数字化转型微漫画丨商品、渠道、供应同质化严重,企业如何在竞争中取胜
热门文章
- ab 压力测试及结果分析
- java从本地下载pdf文件_java下载PDF文件
- csdn广告过滤油猴子(Greasemonkey)脚本(同样适用于暴力猴 tampermonkey/Violentmonkey 在浏览器Firefox/chrome都可以用,全部复制粘贴即可)
- 北斗导航 | 两个地面站之间的多跳卫星通信链路(附matlab代码)
- android 如何把.swf作为开机动画,win10系统将PPT幻灯片转为SWF动画的操作方法
- Python实现千图成像:从图片爬取到图片合成
- 超图神经网络 Hypergraph Neural Networks
- 基于openoffice+pdfobject.js实现文档上传以及在线预览功能
- 计算机无法访问iTunes,PC端itunes识别不了iphone怎么办 itunes无法识别插入iPhone解决方法...
- 数学建模计算机模拟实验答案,数学建模与数学实验课后习题答案.doc