static VALUE
cr_surface_create_similar (VALUE self, VALUE content, VALUE width, VALUE height)
{
  cairo_surface_t *surface;

  surface = cairo_surface_create_similar (RVAL2CRSURFACE (self),
                                          RVAL2CRCONTENT (content),
                                          NUM2INT (width), NUM2INT (height));
  cr_surface_check_status (surface);
  return CRSURFACE2RVAL_WITH_DESTROY (surface);
}
Beispiel #2
0
static VALUE
image_create_cairo_surface(VALUE obj)
{
    cairo_surface_t* cairo_surface;
    cairo_format_t cairo_format;
    unsigned char* data;
    VALUE surface;
    struct image_data* image = get_image_data(obj);

    data = xmalloc(sizeof(unsigned char)*RSTRING_LEN(image->buffer));
    MEMCPY(data, RSTRING_PTR(image->buffer), unsigned char, RSTRING_LEN(image->buffer));

    cairo_format = pixel_format_to_cairo_format(image->pixel_format);
    cairo_surface = cairo_image_surface_create_for_data(
	    data, cairo_format, (int)image->width, (int)image->height,
	    (int)image->stride*pixel_format_size(image->pixel_format));
    cairo_surface_set_user_data(cairo_surface, &cairo_data_key, data, image_surface_did_destroyed);
    surface = CRSURFACE2RVAL_WITH_DESTROY(cairo_surface);
    return surface;
}