Implementing Resea GUI (Part 3): Porting libpng
I successfully enabled Cairo's built-in support for reading PNG images.
Porting libpng and zlib
Cairo's PNG support can be enabled by defining
cairo-features.h. The PNG support depends on a external library libpng, as the name suggests, it implements PNG-related features including the PNG file reader. Moreover, since a PNG file is compressed with the deflate algorithm, it internally depends on zlib.
Porting libpng and zlib is so easy: just compile them with libc.
Rendering a PNG image
cairo_image_surface_create_from_png_stream() API, you can inflate a PNG image into a Cairo surface.
// Fill the screen with a PNG image. surface = cairo_image_surface_create_from_png_stream(/* ... */); cairo_set_source_surface(cr, surface, 0, 0); cairo_rectangle(cr, 0, 0, screen_width, screen_height); cairo_fill(cr);
Finally all essential 2D graphics features are now available on Resea!