User avatar
hanzelpeter
Posts: 70
Joined: Mon Jul 09, 2012 11:56 am

dispmanx manual

Wed Feb 13, 2013 7:24 pm

Hello.

I just started to use dispmanx to draw content on screen. I followed hello_pi/hello_dispmanx.c
So I've got my picture on screen and now I need to update that picture.
I have used vc_dispmanx_resource_write_data to write picture to element. But how I can i update the element to show next frame of my pictures?

Is there any manual about dispmanx programming or should I study the source code for dispmanx?

Thansk.

-rst-
Posts: 1316
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland

Re: dispmanx manual

Thu Feb 14, 2013 4:18 pm

There is no manual, so the only way would be to look at the header file (/opt/vc/include/interface/vmcs_host/vc_dispmanx.h), try decipher the function names and to experiment...

What you are looking for is this bit:

Code: Select all

vc_dispmanx_element_change_source( update_handle, element, resource );		

I was planning to continue my blog with dispmanx stuff, but here's a sneak peak ;)

Code: Select all

...

// create two resources for 'page flipping'
static DISPMANX_RESOURCE_HANDLE_T	resource0;
static DISPMANX_RESOURCE_HANDLE_T	resource1;

// these are used for switching between the buffers
static DISPMANX_RESOURCE_HANDLE_T cur_res;
static DISPMANX_RESOURCE_HANDLE_T prev_res;
static DISPMANX_RESOURCE_HANDLE_T tmp_res;

...

// in the init function

	// create the 'window' element - based on the first buffer resource (resource0)
	element = vc_dispmanx_element_add(  update_handle,
										display,
										2000,
										&dst_rect_elem,
										resource0,
										&src_rect,
										DISPMANX_PROTECTION_NONE,
										&alpha,
										0,
										VC_IMAGE_ROT0 );
...

	// setup swapping of double buffers
	cur_res = resource1;
	prev_res = resource0;
...

// screen update func
int update_graphics(unsigned char* image_data) {

	int ret;
	
	// blit image to the current resource
	ret = vc_dispmanx_resource_write_data(	cur_res,
									image_type,
									pitch,
									(void *)image_data,
									&dst_rect_res );
	if (ret != 0) {
		return LLGRLIB_ERROR;
	}

	// begin display update
	update_handle = vc_dispmanx_update_start( 10 );
	if (update_handle == 0) {
		return LLGRLIB_ERROR;
	}

	// change element source to be the current resource
	int chg_ret;
	chg_ret = vc_dispmanx_element_change_source( update_handle, element, cur_res );		
	
	// finish display update
	ret = vc_dispmanx_update_submit_sync( update_handle );
	if (ret != 0) {
		return LLGRLIB_ERROR;
	}
	
	// swap current resource
	tmp_res = cur_res;
	cur_res = prev_res;
	prev_res = tmp_res;

	if (chg_ret != 0) {
		return LLGRLIB_ERROR;
	}
	
	return LLGRLIB_OK;
}

http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'

GrandAdmiral
Posts: 21
Joined: Thu Apr 18, 2013 2:34 pm

Re: dispmanx manual

Wed Apr 24, 2013 6:41 pm

I was planning to continue my blog with dispmanx stuff, but here's a sneak peak ;)
I'll second that plan! I wrote a program using the code from the dispmanx example to draw test patterns on the display, but most of the time it felt like I was just making magical incantations and hoping they would work. :)

timmehboy
Posts: 22
Joined: Tue Apr 09, 2013 10:47 am

Re: dispmanx manual

Fri Apr 26, 2013 4:58 pm

@-rst-
Thanks for the code examples!
I am having a problem: the second or third time I want to update the image data, vc_dispmanx_resource_write_data returns -1, and the following calls predictably fail.
What could be the source of the problem? I am aligning the width to a multiple of 16, and using an RGBA32 type.

ben.ezazi
Posts: 3
Joined: Wed Aug 22, 2018 9:55 am

Re: dispmanx manual

Wed Aug 22, 2018 10:04 am

can you please elaborate on how to display an image file (in example *.png) on the screen using dispmanx.c program?

I am trying to use OpenCV to pass the data of a picture file to vars->image (inside dispmanx.c) but it doesn't work. :roll:

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 11013
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: dispmanx manual

Wed Aug 22, 2018 10:39 am

This thread was 5 years old, re-opening it serves no purpose, please start a new thread.

Return to “Graphics programming”