IPU direct display bitmap BMP

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

IPU direct display bitmap BMP

1,324 Views
cachegxp
Contributor I

I hope imx-lib the IPU direct display bitmap BMP, in accordance with the following code, the resultsSegmegtation fault.I estimate the parameters fill in error, may I ask how to fill it?

 

int read_bmp_file(char* filename, unsigned char * const buffer, unsigned char** data, int* width, int* height, int* depth)
{
FILE* fd;
int rt;
int channel;
unsigned char* bits;

BITMAPFILEHEADER bmfh;
BITMAPINFOHEADER bmih;
fd = fopen(filename, "rb");
if(fd == NULL) {
printf("NO such file %s. ", filename);
return -1;
}
rt = fread(buffer, 1, 10*1024*1024, fd);
printf("read image ->%d. ", rt);
fclose(fd);
printf("sizeof(bmfh)->%d. ", sizeof(bmfh));
printf("sizeof(bmih)->%d. ", sizeof(bmih));
memcpy(&bmfh, buffer, sizeof(bmfh));
memcpy(&bmih, buffer + sizeof(bmfh), sizeof(bmih));
if(bmfh.bfType != 19778) {
return -1;
}
bits = (unsigned char*) (buffer+bmfh.bfOffBits);
channel = bmih.biBitCount/8;
*depth = bmih.biBitCount;
*width = bmih.biWidth;
*height = bmih.biHeight;
*data = bits;
printf(" size(%dx%d) channel:%d --- ", *width, *height, channel);
return 0;
}

int main(int argc, char *argv[])
{
int ret, test, i;
unsigned char *ptr;
ipu_lib_handle_t handle;
ipu_lib_input_param_t input;
ipu_lib_output_param_t output;
unsigned int w = 1440, h = 900;

char filename[256] = "\0";
unsigned char* data;
unsigned char* buffer;
int width, height, depth;

printf("IPU Test\n" );

strcpy(filename, "24.bmp");
buffer = (unsigned char*) malloc(10*1024*1024);
if(buffer == NULL) {
printf("malloc buuf fail\n");
return -1;
}
data = NULL;
read_bmp_file(filename, buffer, &data, &width, &height, &depth);
if(data == NULL) {
free(buffer);
return -1;
}
printf("Need DisPlay int date:width:%d,height:%d,depth:%d\n",width,height,depth);

memset(&input, 0x00, sizeof(input));
input.width = w;
input.height = h;
input.fmt = v4l2_fourcc('B', 'G', 'R', '3');
input.motion_sel = HIGH_MOTION;
input.input_crop_win.pos.x = 0;
input.input_crop_win.pos.y = 0;
input.input_crop_win.win_w = w;
input.input_crop_win.win_h = h;
input.user_def_paddr[0] = data;// NULL means that a buffer will be allocated

memset(&output, 0x00, sizeof(output));
output.width = w;
output.height = h;
output.fmt = v4l2_fourcc('B', 'G', 'R', '3');// IPU_PIX_FMT_RGB24;
output.rot = IPU_ROTATE_NONE;
output.show_to_fb = 1;
output.fb_disp.pos.x = 0;
output.fb_disp.pos.y = 0;
output.fb_disp.fb_num = 0;
output.output_win.pos.x = 0;
output.output_win.pos.y = 0;
output.output_win.win_w = w;
output.output_win.win_h = h;
output.user_def_paddr[0] = NULL;// NULL means that a buffer will be allocated

memset(&handle, 0x00, sizeof(handle));

ret = mxc_ipu_lib_task_init(&input, NULL, &output, OP_NORMAL_MODE,&handle);

printf("mxc_ipu_lib_task_init ret:%d"
" inbuf_start: 0x%X outbuf_start: 0x%X\n"
" ifr_size: %d ofr_size: %d\n",
ret,
(unsigned int)handle.inbuf_start[0], (unsigned int)handle.outbuf_start[0],
handle.ifr_size, handle.ofr_size);

if (ret == 0) // zero means the init worked
{
printf("DOING IPU TASK\n");
ret = mxc_ipu_lib_task_buf_update(&handle, NULL, 0, 0, NULL, NULL);
//ret = mxc_ipu_lib_task_buf_update(&handle, f->fb()->YCrCb.physical_base(),0,0, NULL, NULL);
printf("mxc_ipu_lib_task_buf_update returned:%d\n", ret);

// now print some outbuf contents after the task
ptr = (unsigned char *)handle.outbuf_start[0];
if (*ptr)// check for any non-zero value in output
printf("************* IPU DID CONVERT *************\n");// very rarely prints this!
printf("outbuf after: ");
for (i = 0; i < 10; i++, ptr++)printf("%02X ", *ptr);
printf("\n");

}
else
{
printf("mxc_ipu_lib_task_init FAILED:%d\n", ret);
return(0);
}

mxc_ipu_lib_task_uninit(&handle);
free(buffer);
return 0;

}

dbmp.c

Tags (2)
0 Kudos
Reply
1 Reply

591 Views
qiang_li-mpu_se
NXP Employee
NXP Employee

In ipu unit test code, there is a similar test case "Copy test", maybe you can reference to it. (imx-test-11.09.01\test\mxc_ipudev_test\test_pattern.c)

 

int copy_test(ipu_test_handle_t * test_handle)
{
 int ret = 0, fd_fb = 0, screen_size;
 struct fb_var_screeninfo fb_var;
 struct fb_fix_screeninfo fb_fix;
 void * fake_fb[1];
 int fake_fb_paddr[1], done_cnt = 0;

 if ((fd_fb = open("/dev/fb0", O_RDWR, 0)) < 0) {
  printf("Unable to open /dev/fb0\n");
  ret = -1;
  goto done;
 }

 if ( ioctl(fd_fb, FBIOGET_VSCREENINFO, &fb_var) < 0) {
  printf("Get FB var info failed!\n");
  ret = -1;
  goto done;
 }
 if ( ioctl(fd_fb, FBIOGET_FSCREENINFO, &fb_fix) < 0) {
  printf("Get FB fix info failed!\n");
  ret = -1;
  goto done;
 }
 screen_size = fb_var.yres * fb_fix.line_length;
 ret = dma_memory_alloc(screen_size, 1, fake_fb_paddr, fake_fb);
 if ( ret < 0) {
  printf("dma_memory_alloc failed\n");
  goto done;
 }

 test_handle->mode = OP_NORMAL_MODE | TASK_PP_MODE;
 test_handle->fcount = 10;
 test_handle->input.width = fb_var.xres;
 test_handle->input.height = fb_var.yres;
 test_handle->output.width = fb_var.xres;
 test_handle->output.height = fb_var.yres;
 if (fb_var.bits_per_pixel == 24) {
  test_handle->output.fmt = v4l2_fourcc('B', 'G', 'R', '3');
  test_handle->input.fmt = v4l2_fourcc('B', 'G', 'R', '3');
 } else {
  test_handle->output.fmt = v4l2_fourcc('R', 'G', 'B', 'P');
  test_handle->input.fmt = v4l2_fourcc('R', 'G', 'B', 'P');
 }
 test_handle->input.user_def_paddr[0] = fake_fb_paddr[0];
 test_handle->output.user_def_paddr[0] = fb_fix.smem_start;

 ret = mxc_ipu_lib_task_init(&(test_handle->input), NULL, &(test_handle->output),
    test_handle->mode, test_handle->ipu_handle);
 if (ret < 0) {
  printf("mxc_ipu_lib_task_init failed!\n");
  goto err;
 }

 while((done_cnt < test_handle->fcount) && (ctrl_c_rev == 0)) {
  static int j = 0;
  if ((j % 3) == 0)
   memset(fake_fb[0], 0, screen_size);
  if ((j % 3) == 1)
   memset(fake_fb[0], 0x80, screen_size);
  if ((j % 3) == 2)
   memset(fake_fb[0], 0xff, screen_size);
  j++;
  if (mxc_ipu_lib_task_buf_update(test_handle->ipu_handle, 0, 0, 0, NULL, NULL) < 0)
   break;
  done_cnt++;
  sleep(1);
 }

 mxc_ipu_lib_task_uninit(test_handle->ipu_handle);

err:
 dma_memory_free(screen_size, 1, fake_fb_paddr, fake_fb);
done:
 return ret;
}

0 Kudos
Reply