[cairo] PNG backend

Carl Worth cworth at east.isi.edu
Tue Feb 17 06:34:13 PST 2004


On Feb 8, Olivier Andrieu wrote:
 > I wrote a simple PNG backend for cairo. Like the PS backend, it's just
 > a wrapper of "image" surfaces for format CAIRO_FORMAT_ARGB32 and
 > CAIRO_FORMAT_RGB24.

Olivier,

Thank you very much for contributing this work. I had been planning on
doing something similar for some time.

A few (fairly minor) comments:

 > | void
 > | cairo_set_target_png (cairo_t	*cr,
 > |                       FILE *file,
 > |                       cairo_format_t format,
 > |                       int width,
 > |                       int height,
 > |                       double pixels_per_inch);
 > | 
 > | cairo_surface_t *
 > | cairo_png_surface_create (FILE           *file,
 > |                           cairo_format_t format,
 > |                           int width,
 > |                           int height,
 > |                           double pixels_per_inch);

Hmm... does it make sense to require pixels_per_inch here? The current
image_surface backend doesn't take this, and these two should probably
be consistent.

My initial thought is that since we're accepting width/height in
device-space units, that we don't need the pixels per inch
parameter. I suppose we'll also have to be careful about how the
default matrix is defined, (eg. in the absence of a pixels_per_inch
parameter, it should probably be defined as the identity matrix).

Another option we might consider would be to move the pixels_per_inch
parameter to a new function such as cairo_surface_set_pixels_per_inch.

 > -Requires: fontconfig libpixman @XRENDER_REQUIRES@
 > +Requires: fontconfig libpixman @XRENDER_REQUIRES@ libpng12

This should be fixed to add the libpng12 requirement only if the png
backend is enabled.

 > +static cairo_status_t
 > +_cairo_png_surface_set_matrix (void		*abstract_surface,
 > +			       cairo_matrix_t	*matrix)
 > +{
 > +    cairo_png_surface_t *surface = abstract_surface;
 > +
 > +    return _cairo_image_surface_set_matrix (surface->image, matrix);
 > +}

It might be worth figuring out how to eliminate these several trivial
wrappers.

 > +static cairo_int_status_t
 > +_cairo_png_surface_fill_rectangles (void			*abstract_surface,
 > +				    cairo_operator_t	operator,
 > +				    const cairo_color_t	*color,
 > +				    cairo_rectangle_t	*rects,
 > +				    int			num_rects)
 > +{
 > +    return CAIRO_INT_STATUS_UNSUPPORTED;
 > +}

These too.

These look really ugly as just looking at this code makes it appear
that the png backend is missing some functionality, (whereas the
intent is to defer to the image_surface backend for this function).
And, yes, this ugliness is all mine, not Olivier's. I'm just pointing
it out here as I see my own ugly code staring back at me.

-Carl





More information about the cairo mailing list