[cairo] [PATCH] add cairo_image_surface_create_with_masks to API
John K Luebs
jkluebs at luebsphoto.com
Mon Feb 9 11:09:39 PST 2004
Attached is a patch that makes cairo_image_surface_create_with_masks
part of the externally visible API. This allows one to render
directly to almost any pixman supported image format.
This function seems like a clean way to access the general RGB API of
pixman and thus has utility to application developers using cairo.
--jkl
-------------- next part --------------
? src/cairo_bdf_font.c
Index: src/cairo.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo.h,v
retrieving revision 1.43
diff -p -u -r1.43 cairo.h
--- src/cairo.h 3 Feb 2004 07:24:14 -0000 1.43
+++ src/cairo.h 9 Feb 2004 18:56:33 -0000
@@ -610,6 +610,14 @@ cairo_surface_get_filter (cairo_surface_
/* Image-surface functions */
+typedef struct cairo_format_masks {
+ int bpp;
+ unsigned long alpha_mask;
+ unsigned long red_mask;
+ unsigned long green_mask;
+ unsigned long blue_mask;
+} cairo_format_masks_t;
+
cairo_surface_t *
cairo_image_surface_create (cairo_format_t format,
int width,
@@ -622,6 +630,13 @@ cairo_image_surface_create_for_data (cha
int height,
int stride);
+cairo_surface_t *
+cairo_image_surface_create_with_masks (char *data,
+ cairo_format_masks_t *format,
+ int width,
+ int height,
+ int stride);
+
#ifdef CAIRO_HAS_PS_SURFACE
/* PS-surface functions */
Index: src/cairo_image_surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo_image_surface.c,v
retrieving revision 1.7
diff -p -u -r1.7 cairo_image_surface.c
--- src/cairo_image_surface.c 11 Dec 2003 21:04:39 -0000 1.7
+++ src/cairo_image_surface.c 9 Feb 2004 18:56:33 -0000
@@ -68,39 +68,6 @@ _cairo_image_surface_create_for_pixman_i
return surface;
}
-cairo_image_surface_t *
-_cairo_image_surface_create_with_masks (char *data,
- cairo_format_masks_t *format,
- int width,
- int height,
- int stride)
-{
- cairo_image_surface_t *surface;
- pixman_format_t *pixman_format;
- pixman_image_t *pixman_image;
-
- pixman_format = pixman_format_create_masks (format->bpp,
- format->alpha_mask,
- format->red_mask,
- format->green_mask,
- format->blue_mask);
-
- if (pixman_format == NULL)
- return NULL;
-
- pixman_image = pixman_image_create_for_data ((pixman_bits_t *) data, pixman_format,
- width, height, format->bpp, stride);
-
- pixman_format_destroy (pixman_format);
-
- if (pixman_image == NULL)
- return NULL;
-
- surface = _cairo_image_surface_create_for_pixman_image (pixman_image);
-
- return surface;
-}
-
static pixman_format_t *
_create_pixman_format (cairo_format_t format)
{
@@ -147,6 +114,39 @@ cairo_image_surface_create (cairo_format
}
cairo_surface_t *
+cairo_image_surface_create_with_masks (char *data,
+ cairo_format_masks_t *format,
+ int width,
+ int height,
+ int stride)
+{
+ cairo_image_surface_t *surface;
+ pixman_format_t *pixman_format;
+ pixman_image_t *pixman_image;
+
+ pixman_format = pixman_format_create_masks (format->bpp,
+ format->alpha_mask,
+ format->red_mask,
+ format->green_mask,
+ format->blue_mask);
+
+ if (pixman_format == NULL)
+ return NULL;
+
+ pixman_image = pixman_image_create_for_data ((pixman_bits_t *) data, pixman_format,
+ width, height, format->bpp, stride);
+
+ pixman_format_destroy (pixman_format);
+
+ if (pixman_image == NULL)
+ return NULL;
+
+ surface = _cairo_image_surface_create_for_pixman_image (pixman_image);
+
+ return &surface->base;
+}
+
+cairo_surface_t *
cairo_image_surface_create_for_data (char *data,
cairo_format_t format,
int width,
Index: src/cairo_xcb_surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo_xcb_surface.c,v
retrieving revision 1.1
diff -p -u -r1.1 cairo_xcb_surface.c
--- src/cairo_xcb_surface.c 3 Feb 2004 07:24:14 -0000 1.1
+++ src/cairo_xcb_surface.c 9 Feb 2004 18:56:33 -0000
@@ -351,11 +351,12 @@ _cairo_xcb_surface_get_image (void *abst
masks.green_mask = surface->visual->green_mask;
masks.blue_mask = surface->visual->blue_mask;
- image = _cairo_image_surface_create_with_masks (XCBGetImageData(imagerep),
- &masks,
- surface->width,
- surface->height,
- bytes_per_line(surface->dpy, surface->width, bpp));
+ image = (cairo_image_surface_t *)
+ cairo_image_surface_create_with_masks (XCBGetImageData(imagerep),
+ &masks,
+ surface->width,
+ surface->height,
+ bytes_per_line(surface->dpy, surface->width, bpp));
} else {
image = (cairo_image_surface_t *)
cairo_image_surface_create_for_data (XCBGetImageData(imagerep),
Index: src/cairo_xlib_surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo_xlib_surface.c,v
retrieving revision 1.16
diff -p -u -r1.16 cairo_xlib_surface.c
--- src/cairo_xlib_surface.c 2 Feb 2004 19:20:45 -0000 1.16
+++ src/cairo_xlib_surface.c 9 Feb 2004 18:56:33 -0000
@@ -206,11 +206,12 @@ _cairo_xlib_surface_get_image (void *abs
masks.green_mask = surface->visual->green_mask;
masks.blue_mask = surface->visual->blue_mask;
- image = _cairo_image_surface_create_with_masks (ximage->data,
- &masks,
- ximage->width,
- ximage->height,
- ximage->bytes_per_line);
+ image = (cairo_image_surface_t *)
+ cairo_image_surface_create_with_masks (ximage->data,
+ &masks,
+ ximage->width,
+ ximage->height,
+ ximage->bytes_per_line);
} else {
image = (cairo_image_surface_t *)
cairo_image_surface_create_for_data (ximage->data,
Index: src/cairoint.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairoint.h,v
retrieving revision 1.50
diff -p -u -r1.50 cairoint.h
--- src/cairoint.h 30 Jan 2004 22:44:18 -0000 1.50
+++ src/cairoint.h 9 Feb 2004 18:56:33 -0000
@@ -386,14 +386,6 @@ struct cairo_matrix {
double m[3][2];
};
-typedef struct cairo_format_masks {
- int bpp;
- unsigned long alpha_mask;
- unsigned long red_mask;
- unsigned long green_mask;
- unsigned long blue_mask;
-} cairo_format_masks_t;
-
struct cairo_surface {
const cairo_surface_backend_t *backend;
@@ -1027,13 +1019,6 @@ _cairo_surface_set_image (cairo_surface_
/* cairo_image_surface.c */
-extern cairo_image_surface_t * __internal_linkage
-_cairo_image_surface_create_with_masks (char *data,
- cairo_format_masks_t *format,
- int width,
- int height,
- int stride);
-
extern void __internal_linkage
_cairo_image_surface_assume_ownership_of_data (cairo_image_surface_t *surface);
More information about the cairo
mailing list