QNX 图片渲染

qnx系统如果想展示本地图片,需要用到特定的图片解析API,通过screen模块进行创建场景展示。有问题欢迎留言啊

//图片解析窗口
static int decode_setup(uintptr_t data, img_t *img, unsigned flags)
{
   screen_window_t screen_win = (screen_window_t)data;
   screen_buffer_t screen_buf;
   int size[2];

   size[0] = img->w;
   size[1] = img->h;
   screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size);
   screen_create_window_buffers(screen_win, 1);

   screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)&screen_buf);
   screen_get_buffer_property_pv(screen_buf, SCREEN_PROPERTY_POINTER, (void **)&img->access.direct.data);
   screen_get_buffer_property_iv(screen_buf, SCREEN_PROPERTY_STRIDE, (int *)&img->access.direct.stride);

   img->flags |= IMG_DIRECT;
   return IMG_ERR_OK;
}

//解析完对窗口进行释放
static void decode_abort(uintptr_t data, img_t *img)
{
    screen_window_t screen_win = (screen_window_t)data;
       screen_destroy_window_buffers(screen_win);
}

//通过img_decode_callouts_t 结构解析图片数据到screen到screen win 中
static int load_image(screen_window_t screen_win, const char *path)
{
    img_decode_callouts_t callouts;
    img_lib_t ilib = NULL;
    img_t img;
    int rc;
 
    rc = img_lib_attach(&ilib);
    if (rc != IMG_ERR_OK) {
        printf("Failed to load lib rc=%d \n",rc);
		printf("IMG_ERR_OK=%d \n",IMG_ERR_OK);
		printf("IMG_ERR_MEM=%d \n",IMG_ERR_MEM);
		printf("IMG_ERR_CFG=%d \n",IMG_ERR_CFG);
        return -1;
    }
 
    memset(&img, 0, sizeof(img));
    img.flags |= IMG_FORMAT;
    img.format = IMG_FMT_PKLE_XRGB8888;
 
    memset(&callouts, 0, sizeof(callouts));
    callouts.setup_f = decode_setup;
    callouts.abort_f = decode_abort;
    callouts.data = (uintptr_t)screen_win;
 
    rc = img_load_file(ilib, path, &callouts, &img);
    img_lib_detach(ilib);
 
    return rc == IMG_ERR_OK ? 0 : -1;
}

//创建screen 和 buf用于存放图片imge数据 file为绝对路径
int show_image(int zorder,const char* file){

	printf("show path=%s\n",file);
    screen_context_t screen_ctx;
    screen_window_t screen_win;
    int viewport_size[2] = { 0, 0 };
	int usage = SCREEN_USAGE_WRITE;
    screen_buffer_t screen_buf = NULL;
    int rect[4] = { 0, 0, 0, 0 };
   
    /* Setup the window */
    screen_create_context(&screen_ctx, 0);
    screen_create_window(&screen_win, screen_ctx);
    screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage);

 	int count = 0;
 	screen_get_context_property_iv(screen_ctx, SCREEN_PROPERTY_DISPLAY_COUNT, &count);
 	printf("start demo count=%d  \n",count);
 	screen_display_t *screen_disps = (screen_display_t *)calloc(count, sizeof(screen_display_t));
 	screen_get_context_property_pv(screen_ctx, SCREEN_PROPERTY_DISPLAYS, (void **)screen_disps);
 	screen_display_t screen_disp = screen_disps[1];
    //由于可以显示的screen有差别  这部需要注意 你的机器是否为screen_disps[1]
	screen_set_window_property_pv(screen_win,SCREEN_PROPERTY_DISPLAY,(void**)&screen_disps[1]);
   
    int rc=load_image(screen_win, file);
	printf("###rc=%d\n",rc);
   
    screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)&screen_buf);
    screen_get_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, rect+2);
    viewport_size[0] = rect[2];
    viewport_size[1] = rect[3];
    screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_SOURCE_SIZE , viewport_size);
	
   //展示的层级 数字越高 越优先展示
	int zder = zorder;
	screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ZORDER, &zder);
    //show 
    screen_post_window(screen_win, screen_buf, 1, rect, 0);

	return 0;

}

你可能感兴趣的:(QNX,qnx,c++,嵌入式)