全志V85x內(nèi)G2D模塊實(shí)現(xiàn)圖片格式步驟方法_第1頁(yè)
全志V85x內(nèi)G2D模塊實(shí)現(xiàn)圖片格式步驟方法_第2頁(yè)
全志V85x內(nèi)G2D模塊實(shí)現(xiàn)圖片格式步驟方法_第3頁(yè)
全志V85x內(nèi)G2D模塊實(shí)現(xiàn)圖片格式步驟方法_第4頁(yè)
全志V85x內(nèi)G2D模塊實(shí)現(xiàn)圖片格式步驟方法_第5頁(yè)
已閱讀5頁(yè),還剩8頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

第第頁(yè)全志V85x內(nèi)G2D模塊實(shí)現(xiàn)圖片格式步驟方法G2D主要功能:

1)旋轉(zhuǎn):支持90、180、270旋轉(zhuǎn);

2)scale:放縮;

3)鏡像反轉(zhuǎn):H/V;

4)透明疊加:實(shí)現(xiàn)兩個(gè)rgb圖片疊加;

5)格式轉(zhuǎn)換:yuv轉(zhuǎn)rgb等多種格式相互間轉(zhuǎn)換;

6)矩形填充,等諸多功能;

G2D配置

源碼目錄

(ti)na-v853-docker/kernel/(linux)-4.9/drivers/char/sunxi_g2d

makekernel_menuconfig配置

DeviceDrivers>Characterdevices>sunxig2ddriver

DeviceTree設(shè)備樹(shù)配置

sun8iw21p1.dtsi路徑:

tina-v853-docker/kernel/linux-4.9/arch/(arm)/boot/dts/sun8iw21p1.dtsi

g2d:g2d@05410000{compatible="allwinner,sunxi-g2d";reg=;interrupts=;clocks=

注:status要設(shè)定為“okay”狀態(tài)。

重新編譯內(nèi)核

使用燒錄工具PhoenixSuit將編譯打包好的img鏡像燒錄到開(kāi)發(fā)板。

(ad)bshell打開(kāi)控制終端查看設(shè)備節(jié)點(diǎn)G2D:

通過(guò)G2D設(shè)備節(jié)點(diǎn)進(jìn)行操作

staticintSampleG2d_G2dOpen(SAMPLE_G2D_CTX*p_g2d_ctx){intret=0;p_g2d_ctx->mG2dFd=open("/dev/g2d",O_RDWR,0);if(p_g2d_ctx->mG2dFd

G2Dsample具體應(yīng)用

G2Dsample目錄

進(jìn)行rotation,scale,格式轉(zhuǎn)換

具體實(shí)現(xiàn):將nv21格式的1920x1080圖轉(zhuǎn)換成rgb888格式并放縮為640x360大小。具體用到兩個(gè)功能,格式轉(zhuǎn)換和放縮。

首先根據(jù)1920x1080nv21格式以及640x360rgb888格式申請(qǐng)?zhí)摂M地址空間以及轉(zhuǎn)換成物理地址(注意:g2d轉(zhuǎn)換是在物理地址中完成的)

1920x1080nv21格式空間大?。ㄝ斎胛募?/p>

Y占19202380=2073600字節(jié)

UV占19202380/2=1036800字節(jié)

640x360rgb888格式空間大小(輸出文件):

RGB占6403603=691200字節(jié)

另外:虛擬地址轉(zhuǎn)換成物理地址使用如下函數(shù):

g2d_getPhyAddrByVirAddr()

申請(qǐng)?zhí)摂M空間并轉(zhuǎn)換成物理空間完整函數(shù)如下:

staticintPrepareFrmBuff(SAMPLE_G2D_CTX*p_g2d_ctx){SampleG2(dC)onfig*pConfig=NULL;unsignedintsize=0;pConfig=p_g2d_ctx->src_frm_info.frm_width=pConfig->mSrcWidth;p_g2d_ctx->src_frm_info.frm_height=pConfig->mSrcHeight;p_g2d_ctx->dst_frm_info.frm_width=pConfig->mDstWidth;p_g2d_ctx->dst_frm_info.frm_height=pConfig->mDstHeight;size=ALIGN(p_g2d_ctx->src_frm_info.frm_width,16)*ALIGN(p_g2d_ctx->src_frm_info.frm_height,16);if(pConfig->mPicFormat==MM_(PI)XEL_FORMAT_YVU_SEMIPLANAR_420||pConfig->mPicFormat==MM_PIXEL_FORMAT_YUV_SEMIPLANAR_420){p_g2d_ctx->src_frm_info.p_vir_addr[0]=(void*)g2d_allocMem(size);if(NULL==p_g2d_ctx->src_frm_info.p_vir_addr[0]){aloge("malloc_src_frm_y_mem_failed");return-1;}p_g2d_ctx->src_frm_info.p_vir_addr[1]=(void*)g2d_allocMem(size/2);if(NULL==p_g2d_ctx->src_frm_info.p_vir_addr[1]){g2d_freeMem(p_g2d_ctx->src_frm_info.p_vir_addr[0]);aloge("malloc_src_frm_c_mem_failed");return-1;}p_g2d_ctx->src_frm_info.p_phy_addr[0]=(void*)g2d_getPhyAddrByVirAddr(p_g2d_ctx->src_frm_info.p_vir_addr[0]);p_g2d_ctx->src_frm_info.p_phy_addr[1]=(void*)g2d_getPhyAddrByVirAddr(p_g2d_ctx->src_frm_info.p_vir_addr[1]);}if(pConfig->mDstPicFormat==MM_PIXEL_FORMAT_RGB_888){size=p_g2d_ctx->dst_frm_info.frm_width*p_g2d_ctx->dst_frm_info.frm_height*3;p_g2d_ctx->dst_frm_info.p_vir_addr[0]=(void*)g2d_allocMem(size);if(NULL==p_g2d_ctx->dst_frm_info.p_vir_addr[0]){if(p_g2d_ctx->src_frm_info.p_vir_addr[0]!=NULL){g2d_freeMem(p_g2d_ctx->src_frm_info.p_vir_addr[0]);}if(p_g2d_ctx->src_frm_info.p_vir_addr[1]!=NULL){g2d_freeMem(p_g2d_ctx->src_frm_info.p_vir_addr[1]);}aloge("malloc_dst_frm_y_mem_failed");return-1;}p_g2d_ctx->dst_frm_info.p_phy_addr[0]=(void*)g2d_getPhyAddrByVirAddr(p_g2d_ctx->dst_frm_info.p_vir_addr[0]);}return0;}

通過(guò)fopen傳菜間兩個(gè)文件句柄,fd_infd_out用來(lái)操作輸入輸出兩個(gè)文件資源。

p_g2d_ctx->fd_in=fopen(p_g2d_ctx->mConfigPara.SrcFile,"r");if(NULL==p_g2d_ctx->fd_in){aloge("opensrcfilefailed");ret=-1;goto_err2;}fseek(p_g2d_ctx->fd_in,0,SEEK_SET);p_g2d_ctx->fd_out=fopen(p_g2d_ctx->mConfigPara.DstFile,"wb");if(NULL==p_g2d_ctx->fd_out){aloge("openoutfilefailed");ret=-1;goto_err2;}fseek(p_g2d_ctx->fd_out,0,SEEK_SET);

讀出1920x1080nv21圖資放入虛擬空間

read_len=p_g2d_ctx->src_frm_info.frm_width*p_g2d_ctx->src_frm_info.frm_height;if(pConfig->mPicFormat==MM_PIXEL_FORMAT_YVU_SEMIPLANAR_420||pConfig->mPicFormat==MM_PIXEL_FORMAT_YUV_SEMIPLANAR_420){size1=fread(p_g2d_ctx->src_frm_info.p_vir_addr[0],1,read_len,p_g2d_ctx->fd_in);if(size1!=read_len){aloge("read_y_data_frm_src_file_invalid");}size2=fread(p_g2d_ctx->src_frm_info.p_vir_addr[1],1,read_len/2,p_g2d_ctx->fd_in);if(size2!=read_len/2){aloge("read_c_data_frm_src_file_invalid");}fclose(p_g2d_ctx->fd_in);g2d_flushCache((void*)p_g2d_ctx->src_frm_info.p_vir_addr[0],read_len);g2d_flushCache((void*)p_g2d_ctx->src_frm_info.p_vir_addr[1],read_len/2);}

打開(kāi)g2d初始化,并開(kāi)始轉(zhuǎn)換

ret=SampleG2d_G2dOpen(p_g2d_ctx);if(retmPicFormat,if(ret!=SUCCESS){aloge("fatalerror!srcpixelformat[0x%x]isinvalid!",pConfig->mPicFormat);return-1;}ret=convert_PIXEL_FORMAT_E_to_g2d_fmt_enh(pConfig->mDstPicFormat,if(ret!=SUCCESS){aloge("fatalerror!dstpixelformat[0x%x]isinvalid!",pConfig->mPicFormat);return-1;}//configblit(mems)et(if(0!=pConfig->mDstRotate){aloge("fatal_err:rotation(can)'tbepe(rf)ormedwhendoscaling");}blit.flag_h=G2D_BLT_NONE_H;//anglerotationused//switch(pConfig->mDstRotate)//{//case0://blit.flag_h=G2D_BLT_NONE_H;//G2D_ROT_0,G2D_BLT_NONE_H//break;//case90://blit.flag_h=G2D_ROT_90;//break;//case180://blit.flag_h=G2D_ROT_180;//break;//case270://blit.flag_h=G2D_ROT_270;//break;//default://aloge("fatalerror!rotation[%d]isinvalid!",pConfig->mDstRotate);//blit.flag_h=G2D_BLT_NONE_H;//break;//}//blit.src_image_h.bbuff=1;//blit.src_image_h.color=0xff;blit.src_image_h.format=eSrcFormat;blit.src_image_h.laddr[0]=(unsignedint)p_g2d_ctx->src_frm_info.p_phy_addr[0];blit.src_image_h.laddr[1]=(unsignedint)p_g2d_ctx->src_frm_info.p_phy_addr[1];blit.src_image_h.laddr[2]=(unsignedint)p_g2d_ctx->src_frm_info.p_phy_addr[2];//blit.src_image_h.haddr[]=blit.src_image_h.width=p_g2d_ctx->src_frm_info.frm_width;blit.src_image_h.height=p_g2d_ctx->src_frm_info.frm_height;blit.src_image_h.align[0]=0;blit.src_image_h.align[1]=0;blit.src_image_h.align[2]=0;blit.src_image_h.clip_rect.x=pConfig->mSrcRectX;blit.src_image_h.clip_rect.y=pConfig->mSrcRectY;blit.src_image_h.clip_rect.w=pConfig->mSrcRectW;blit.src_image_h.clip_rect.h=pConfig->mSrcRectH;blit.src_image_h.gamut=G2D_BT601;blit.src_image_h.bpremul=0;//blit.src_image_h.alpha=0xff;blit.src_image_h.mode=G2D_PIXEL_ALPHA;//G2D_PIXEL_ALPHA,G2D_GLOBAL_ALPHAblit.src_image_h.fd=-1;blit.src_image_h.use_phy_addr=1;//blit.dst_image_h.bbuff=1;//blit.dst_image_h.color=0xff;blit.dst_image_h.format=eDstFormat;blit.dst_image_h.laddr[0]=(unsignedint)p_g2d_ctx->dst_frm_info.p_phy_addr[0];blit.dst_image_h.laddr[1]=(unsignedint)p_g2d_ctx->dst_frm_info.p_phy_addr[1];blit.dst_image_h.laddr[2]=(unsignedint)p_g2d_ctx->dst_frm_info.p_phy_addr[2];//blit.dst_image_h.haddr[]=blit.dst_image_h.width=p_g2d_ctx->dst_frm_info.frm_width;blit.dst_image_h.height=p_g2d_ctx->dst_frm_info.frm_height;blit.dst_image_h.align[0]=0;blit.dst_image_h.align[1]=0;blit.dst_image_h.align[2]=0;blit.dst_image_h.clip_rect.x=pConfig->mDstRectX;blit.dst_image_h.clip_rect.y=pConfig->mDstRectY;blit.dst_image_h.clip_rect.w=pConfig->mDstRectW;blit.dst_image_h.clip_rect.h=pConfig->mDstRectH;blit.dst_image_h.gamut=G2D_BT601;blit.dst_image_h.bpremul=0;//blit

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論