From e507cb5713c6a16393ffd0af3fe38e99fa71acbc Mon Sep 17 00:00:00 2001 From: Jonathon Jongsma Date: Fri, 11 Apr 2008 11:06:42 -0500 Subject: Wrap cairo_format_stride_for_width() --- ChangeLog | 6 ++++++ cairomm/surface.cc | 5 +++++ cairomm/surface.h | 23 +++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/ChangeLog b/ChangeLog index 52edb87..5e9c15c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-04-11 Jonathon Jongsma + + * cairomm/surface.cc: + * cairomm/surface.h: wrap cairo_format_stride_for_width() as a static + function in Cairo::ImageSurface + 2008-04-11 Murray Cumming * Add autoheader to autogen.sh, to create cairommconfig.h.in, to fix diff --git a/cairomm/surface.cc b/cairomm/surface.cc index d3dece5..f7393ac 100644 --- a/cairomm/surface.cc +++ b/cairomm/surface.cc @@ -214,6 +214,11 @@ int ImageSurface::get_stride() const return cairo_image_surface_get_stride(m_cobject); } +int ImageSurface::format_stride_for_width (Cairo::Format format, int width) +{ + return cairo_format_stride_for_width(static_cast(format), width); +} + /******************************************************************************* * THE FOLLOWING SURFACE TYPES ARE EXPERIMENTAL AND NOT FULLY SUPPORTED diff --git a/cairomm/surface.h b/cairomm/surface.h index a6f3404..7043fc0 100644 --- a/cairomm/surface.h +++ b/cairomm/surface.h @@ -295,6 +295,29 @@ public: */ int get_stride() const; + /** + * This function provides a stride value that will respect all + * alignment requirements of the accelerated image-rendering code + * within cairo. Typical usage will be of the form: + * + * @code + * int stride; + * unsigned char *data; + * Cairo::RefPtr surface; + * + * stride = Cairo::ImageSurface::format_stride_for_width (format, width); + * data = malloc (stride * height); + * surface = Cairo::ImageSurface::create (data, format, width, height); + * @endcode + * + * @param format A Cairo::Format value + * @param width The desired width of an image surface to be created. + * @return the appropriate stride to use given the desired format and width, or + * -1 if either the format is invalid or the width too large. + * + * @since 1.6 + **/ + static int format_stride_for_width (Cairo::Format format, int width); /** Creates an image surface of the specified format and dimensions. The * initial contents of the surface is undefined; you must explicitely clear -- cgit v1.2.3