Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

separate read/display png functions #850

Closed
okyeron opened this issue Jun 28, 2019 · 1 comment
Closed

separate read/display png functions #850

okyeron opened this issue Jun 28, 2019 · 1 comment

Comments

@okyeron
Copy link
Contributor

@okyeron okyeron commented Jun 28, 2019

While looking at the png functions today I wanted to revisit the idea of separating read and display functions for pngs.

Am I on the right track with something like the following?

void screen_read_png(const char *filename){
	image = cairo_image_surface_create_from_png (filename);
	if(cairo_surface_status (image)) { 
		fprintf(stderr, "display_png: %s\n", cairo_status_to_string (cairo_surface_status(image))); 
		return; 
	} 
}
		
void screen_show_png(double x, double y){
	int img_w, img_h;
	img_w = cairo_image_surface_get_width (image);
	img_h = cairo_image_surface_get_height (image);

	cairo_set_source_surface (cr, image, x, y);
	cairo_rectangle (cr, x, y, img_w, img_h);
	cairo_fill (cr);
	cairo_surface_destroy (image);
}

void screen_display_png(const char *filename, double x, double y){
	screen_read_png(filename);
	screen_show_png(x, y);
}
@artfwo
Copy link
Member

@artfwo artfwo commented Jun 28, 2019

@okyeron the code above will destroy the image after you first display it. it would be better to return an image object from screen_read_png (with a finalizer that will call cairo_surface_destroy in C). screen_show_png can then accept the image object as first parameter, so you can load and display images separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants