⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_ipipe.c

📁 德州仪器新推出的达芬奇技术dm355的源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
        if (ret < 0) {
                printf("IPIPE_SET_PARAM fail\n");
                goto free;
        }

        ret = ioctl(fd, IPIPE_GET_PARAM,g_param);
        if (ret < 0) {
                printf("IPIPE_SET_PARAM fail\n");
                goto free;
        }

        g_param->ipipeif_param.source = SDRAM_YUV;
        g_param->ipipeif_param.glob_hor_size = 328;
        g_param->ipipeif_param.glob_ver_size = 250;
        g_param->ipipeif_param.hnum = 320;
        g_param->ipipeif_param.vnum = 240;
        g_param->ipipeif_param.adofs = 640;
        g_param->ipipe_dpaths_fmt = YUV2YUV;
        g_param->ipipe_vsz = 239;
        g_param->ipipe_hsz = 319;
        g_param->rsz_rsc_param[1].rsz_o_vsz = 239;
        g_param->rsz_rsc_param[1].rsz_o_hsz = 319;
        g_param->rsz_rsc_param[1].rsz_v_dif = 128;
        g_param->rsz_rsc_param[1].rsz_h_dif = 128;
        g_param->ext_mem_param[1].rsz_sdr_oft = 320 * 2;
        g_param->rsz_en[0] = DISABLE;
        g_param->rsz_en[1] = ENABLE;
        //g_param->rsz_en[0] = ENABLE;
        ret = ioctl(fd, IPIPE_SET_PARAM,g_param);
        if (ret < 0) {
                printf("IPIPE_SET_PARAM fail\n");
                goto free;
        }
#endif

        /* request for 1 input buffer */
        reqbufs.buf_type = IPIPE_BUF_IN;
        reqbufs.size = 2* 320 * 240;
        reqbufs.count = 1;
        if ((ret = ioctl(fd, IPIPE_REQBUF, &reqbufs)) < 0){
                printf("IPIPE_REQBUF fail\n");
                goto free;

        }
         /* request for 1 output buffer */
        reqbufs.buf_type = IPIPE_BUF_OUT;
        /*resize ratio will be 1*/
        reqbufs.size =  2 * 320 * 240;
        reqbufs.count = 1;

        if ((ret = ioctl(fd, IPIPE_REQBUF, &reqbufs)) < 0){
                printf("IPIPE_REQBUF fail\n");
                goto free;
        }

        temp_buff.index = 0;
        temp_buff.buf_type = IPIPE_BUF_IN;
        /*query buffer for input buffer*/
        if ((ret = ioctl(fd,IPIPE_QUERYBUF,&temp_buff)) < 0){
                printf("IPIPE_QUERYBUF fail\n");
                goto free;

        }
        in_buff.index = 0;
        in_buff.offset = temp_buff.offset;

        buff[0].length = temp_buff.size;

        buff[0].addr = mmap(NULL, temp_buff.size, PROT_READ | PROT_WRITE, MAP_SHARED,
				 fd,(temp_buff.offset ));

        if (buff[0].addr == MAP_FAILED) {
                printf("\ncannot mmap buffer\n");
                goto free;
        }

        temp_buff.index = 0;
        temp_buff.buf_type = IPIPE_BUF_OUT;
        /*query buffer for output buffer*/

        if ((ret = ioctl(fd,IPIPE_QUERYBUF,&temp_buff)) < 0){
                printf("IPIPE_QUERYBUF fail\n");
        }
        printf("add_app = %x\n",temp_buff.offset);

        out_buff.index = 0;
        out_buff.offset = temp_buff.offset;

        buff[1].length = temp_buff.size;
        buff[1].addr = mmap(NULL, temp_buff.size, PROT_READ | PROT_WRITE, MAP_SHARED,
                                        fd, temp_buff.offset );
         if (buff[1].addr == MAP_FAILED) {
                printf("\ncannot mmap buffer\n");
                munmap(buff[0].addr, buff[0].length);
                goto free;
        }
        /*copy the image to mapped virtual address */

        fread(buff[0].addr,1,320 * 240 * 2, fccdc);
        fclose(fccdc);
        /*inaddr/SE and outaddr contains the mapped addresses */
        inadr = buff[0].addr;
        outadr = buff[1].addr;

        convert.in_buff.index = convert.out_buff.index = 0;
        printf("ipipe_start\n");

        if ((ret = ioctl(fd, IPIPE_START, &convert)) < 0){

                printf("IPIPE_START fail\n");
		 goto out;
        }

        fc = fopen("out_yuv16.yuv", "w");

        if (fc == NULL)
        {
                printf("error in file out_yuv16.yuv\n");
                goto out;
        }
        fwrite(buff[1].addr,1, 320 * 240* 2,fc);
	fclose(fc);

out:
        munmap(buff[0].addr, buff[0].length);
        munmap(buff[1].addr, buff[1].length);
free:
        close(fd);
        free(g_param);
        printf("file closed");
        return ret;
}

/* 9 */
int ipipe_8raw2yuv_downscale(struct ipipe_params* g_param)
{
	 //struct ipipe_cropsize crop;
        char *inadr, *outadr;
        int fd;
        int *addr = NULL;
        FILE *fp,*fc;
        int cy = 0, ccb = 0, ccr = 0,i,j;
        struct ipipe_reqbufs reqbufs;
        struct ipipe_buffer temp_buff,in_buff, out_buff;
        struct buffer buff[2];
        struct ipipe_convert convert;
        int ret = 0;

        /*** Output Device name ***/
        if ((fd = open(DR_NAME, O_RDWR)) < 0)
        {
                printf("\nError opening ipipe device;");
                free(g_param);
                return -1;
        }
        printf("device opened\n");
#if 1
        ret = ioctl(fd, IPIPE_SET_PARAM,NULL);
        if (ret < 0) {
                printf("IPIPE_SET_PARAM fail\n");
                goto free;
        }
        ret = ioctl(fd, IPIPE_GET_PARAM,g_param);
        if (ret < 0) {
                printf("IPIPE_GET_PARAM fail\n");
                goto free;
        }
        g_param->ipipeif_param.source = SDRAM_RAW;
        g_param->ipipeif_param.glob_ver_size = 490;
        g_param->ipipeif_param.glob_hor_size = 648;
        g_param->ipipeif_param.ialaw = ALAW_ON;
        g_param->ipipeif_param.pack_mode = EIGHT_BIT;
        g_param->ipipeif_param.hnum = 640;
        g_param->ipipeif_param.vnum = 480;
        g_param->ipipeif_param.adofs = 640;
        g_param->ipipe_dpaths_fmt = RAW2YUV;
        g_param->ipipe_vsz = 480 - 1;
        g_param->ipipe_hsz = 640 - 1;
	 g_param->rsz_rsc_param[0].rsz_o_vsz = 240 - 1;
        g_param->rsz_rsc_param[0].rsz_o_hsz =  320 - 1;
        g_param->rsz_rsc_param[0].rsz_v_dif = 512;
        g_param->rsz_rsc_param[0].rsz_h_dif = 512;
        g_param->ext_mem_param[0].rsz_sdr_oft = 320 * 2;
        g_param->ext_mem_param[0].rsz_sdr_ptr_e = 240;

        ret = ioctl(fd, IPIPE_SET_PARAM,g_param);
        if (ret < 0) {
                printf("IPIPE_SET_PARAM fail\n");
                goto free;
        }
#endif
        /* request for 1 input buffer */
        reqbufs.buf_type = IPIPE_BUF_IN;
        reqbufs.size = 640 * 480;
        reqbufs.count = 1;
        if ((ret = ioctl(fd, IPIPE_REQBUF, &reqbufs)) < 0){
                printf("IPIPE_REQBUF fail\n");
                goto free;

        }
         /* request for 1 output buffer */
        reqbufs.buf_type = IPIPE_BUF_OUT;
        /*resize ratio will be 1*/
        reqbufs.size = 320 * 240 * 2;
        reqbufs.count = 1;

        if ((ret = ioctl(fd, IPIPE_REQBUF, &reqbufs)) < 0){
                printf("IPIPE_REQBUF fail\n");
                goto free;
        }

        temp_buff.index = 0;
	 temp_buff.buf_type = IPIPE_BUF_IN;
        /*query buffer for input buffer*/
        if ((ret = ioctl(fd,IPIPE_QUERYBUF,&temp_buff)) < 0){
                printf("IPIPE_QUERYBUF fail\n");
                goto free;

        }
        in_buff.index = 0;
        in_buff.offset = temp_buff.offset;

        buff[0].length = temp_buff.size;

        buff[0].addr = mmap(NULL, temp_buff.size, PROT_READ | PROT_WRITE, MAP_SHARED,
                                fd,(temp_buff.offset ));

        if (buff[0].addr == MAP_FAILED) {
                printf("\ncannot mmap buffer\n");
                goto free;
        }

        temp_buff.index = 0;
        temp_buff.buf_type = IPIPE_BUF_OUT;
        /*query buffer for output buffer*/

        if ((ret = ioctl(fd,IPIPE_QUERYBUF,&temp_buff)) < 0){
                printf("IPIPE_QUERYBUF fail\n");
        }
        printf("add_app = %x\n",temp_buff.offset);

        out_buff.index = 0;
        out_buff.offset = temp_buff.offset;

        buff[1].length = temp_buff.size;
        buff[1].addr = mmap(NULL, temp_buff.size, PROT_READ | PROT_WRITE, MAP_SHARED,
                                        fd, temp_buff.offset );
         if (buff[1].addr == MAP_FAILED) {
                printf("\ncannot mmap buffer\n");
                munmap(buff[0].addr, buff[0].length);
                goto free;
        }
        /*copy the image to mapped virtual address */

        memcpy(buff[0].addr,bayerimage,640 * 480);
	inadr = buff[0].addr;
        outadr = buff[1].addr;

        convert.in_buff.index = convert.out_buff.index = 0;
        printf("ipipe_start\n");

        if ((ret = ioctl(fd, IPIPE_START, &convert)) < 0){

                printf("IPIPE_START fail\n");
                goto out;
        }

        fc = fopen("yuv16.yuv", "w");

        if (fc == NULL)
        {
                printf("error in file yuv16.yuv\n");
                goto out;
        }
        fwrite(buff[1].addr,1, 320 * 240 * 2 ,fc);
	fclose(fc);

out:
        munmap(buff[0].addr, buff[0].length);
        munmap(buff[1].addr, buff[1].length);
free:
        close(fd);
        free(g_param);
        printf("file closed");
        return ret;
}
/* 10 */
int ipipe_16raw2yuv_up_rsz1(struct ipipe_params* g_param)
{

}
/* 11 */
int ipipe_16raw2yuv_down_rsz1(struct ipipe_params* g_param)
{
	//struct ipipe_cropsize crop;
        char *inadr, *outadr;
        int fd;
        int *addr = NULL;
        FILE *fp,*fc;
        int cy = 0, ccb = 0, ccr = 0,i,j;
        struct ipipe_reqbufs reqbufs;
        struct ipipe_buffer temp_buff,in_buff, out_buff;
        struct buffer buff[2];
        struct ipipe_convert convert;
        FILE *fccdc ;
        int ret = 0;

        /*** Output Device name ***/
        if ((fd = open(DR_NAME, O_RDWR)) < 0)
        {
                printf("\nError opening ipipe device;");
                free(g_param);
                return -1;
        }
        printf("device opened\n");
        fccdc = fopen("raw16.bin","r+b");
        if (fccdc == NULL)
        {
                printf("error in cup.bin\n");
                goto free;
                return -1;
        }
#if 1
        ret = ioctl(fd, IPIPE_SET_PARAM,NULL);
        if (ret < 0) {
                printf("IPIPE_SET_PARAM fail\n");
                goto free;
        }
        ret = ioctl(fd, IPIPE_GET_PARAM,g_param);
        if (ret < 0) {
                printf("IPIPE_SET_PARAM fail\n");
                goto free;
        }
        g_param->ipipeif_param.glob_hor_size = 624 + 8;
        g_param->ipipeif_param.glob_ver_size = 456 + 10;
	g_param->ipipeif_param.hnum = 624;
        g_param->ipipeif_param.vnum = 456;
        g_param->ipipeif_param.adofs = 624 * 2;
        g_param->ipipe_vsz = 456 - 1;
        g_param->ipipe_hsz = 624 - 1;
        g_param->rsz_rsc_param[1].rsz_o_vsz = 239;
        g_param->rsz_rsc_param[1].rsz_o_hsz = 319;
        g_param->rsz_rsc_param[1].rsz_v_dif = 486;
        g_param->rsz_rsc_param[1].rsz_h_dif = 480;
        g_param->ext_mem_param[1].rsz_sdr_ptr_e = 480;
        g_param->ext_mem_param[1].rsz_sdr_oft = 640;
        g_param->rsz_en[0] = DISABLE;
        g_param->rsz_en[1] = ENABLE;

        ret = ioctl(fd, IPIPE_SET_PARAM,g_param);
        if (ret < 0) {
                printf("IPIPE_SET_PARAM fail\n");
                goto free;
        }
#endif

        /* request for 1 input buffer */
        reqbufs.buf_type = IPIPE_BUF_IN;
        reqbufs.size = 2* 624 * 456;
        reqbufs.count = 1;
        if ((ret = ioctl(fd, IPIPE_REQBUF, &reqbufs)) < 0){
                printf("IPIPE_REQBUF fail\n");
                goto free;

        }
         /* request for 1 output buffer */
        reqbufs.buf_type = IPIPE_BUF_OUT;
        /*resize ratio will be 1*/
        reqbufs.size =  2 * 320 * 240;
        reqbufs.count = 1;
	if ((ret = ioctl(fd, IPIPE_REQBUF, &reqbufs)) < 0){
                printf("IPIPE_REQBUF fail\n");
                goto free;
        }

        temp_buff.index = 0;
        temp_buff.buf_type = IPIPE_BUF_IN;
        /*query buffer for input buffer*/
        if ((ret = ioctl(fd,IPIPE_QUERYBUF,&temp_buff)) < 0){
                printf("IPIPE_QUERYBUF fail\n");
                goto free;

        }
        in_buff.index = 0;
        in_buff.offset = temp_buff.offset;

        buff[0].length = temp_buff.size;

        buff[0].addr = mmap(NULL, temp_buff.size, PROT_READ | PROT_WRITE, MAP_SHARED,
                                fd,(temp_buff.offset ));

        if (buff[0].addr == MAP_FAILED) {
                printf("\ncannot mmap buffer\n");
                goto free;
        }

        temp_buff.index = 0;
        temp_buff.buf_type = IPIPE_BUF_OUT;
        /*query buffer for output buffer*/

        if ((ret = ioctl(fd,IPIPE_QUERYBUF,&temp_buff)) < 0){
                printf("IPIPE_QUERYBUF fail\n");
        }

        out_buff.index = 0;
        out_buff.offset = temp_buff.offset;

        buff[1].length = temp_buff.size;
	 buff[1].addr = mmap(NULL, temp_buff.size, PROT_READ | PROT_WRITE, MAP_SHARED,
                                        fd, temp_buff.offset );
         if (buff[1].addr == MAP_FAILED) {
                printf("\ncannot mmap buffer\n");
                munmap(buff[0].addr, buff[0].length);
                goto free;
        }
        /*copy the image to mapped virtual address */

        fread(buff[0].addr,1,456 * 624 * 2, fccdc);
        fclose(fccdc);
        /*inaddr/SE and outaddr contains the mapped addresses */
        inadr = buff[0].addr;
        outadr = buff[1].addr;

        convert.in_buff.index = convert.out_buff.index = 0;
        printf("ipipe_start\n");

        if ((ret = ioctl(fd, IPIPE_START, &convert)) < 0){

                printf("IPIPE_START fail\n");
                goto out;
        }
        fc = fopen("yuv16.yuv", "w");

        if (fc == NULL)
        {
                printf("error in file fc\n");
		ret = -1;
                goto out;
        }
        fwrite(buff[1].addr,1, 320 * 240 * 2,fc);
	fclose(fc);	

out:
        munmap(buff[0].addr, buff[0].length);
        munmap(buff[1].addr, buff[1].length);
free:
        close(fd);
        free(g_param);
	printf("file closed");
        return ret;
}
usage(char* abc)
{
	printf( "Usage: Command Line Arg No.\n"
                        " 0    | -- ioctl_test\n"
                        " 1    | -- converts 8bit raw to yuv(upscale)RZA \n"
                        " 2    | -- converts 16bit raw to yuv(upscale)RZA \n"
                        " 3    | -- converts 16 bit yuv to yuv,  RZA\n"
                        " 4    | -- converts 16bit raw to yuv(downscale),RZA \n"
                        " 5    | -- converts 16bit yuv to yuv(downscale),RZA \n"
                        " 6    | -- converts 16bit yuv to yuv(upscale),RZA\n"
                        " 7    | -- converts 16bit yuv to yuv(downscale)RZB\n"
                        " 8    | -- converts 16bit yuv to yuv(upscale)RZB\n"
                        " 9    | -- converts 8bit raw to yuv(downscale)RZA\n"
                        " 10   | -- converts 16bit raw to yuv(upscale)RZB\n"
                        " 11   | -- converts 16bit raw to yuv(downscale)RZB\n");
        exit(0);

		
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -