[cairo-commit] 2 commits - src/cairo-gstate.c src/cairo.h src/cairo-image-surface.c src/cairo-rectangle.c src/Makefile.am

Carl Worth cworth at kemper.freedesktop.org
Mon Jun 5 14:36:16 PDT 2006


 src/Makefile.am           |    1 
 src/cairo-gstate.c        |   46 ------------------------
 src/cairo-image-surface.c |   69 +++++++++++++++++++++++++++++++++++++
 src/cairo-rectangle.c     |   85 ++++++++++++++++++++++++++++++++++++++++++++++
 src/cairo.h               |    9 ++++
 5 files changed, 164 insertions(+), 46 deletions(-)

New commits:
diff-tree 28d47d332aafa81bcbc669603357298cb0a14322 (from 3d9dc96d186c9093da24c7bbf36614f3d8df1758)
Author: Carl Worth <cworth at cworth.org>
Date:   Mon Jun 5 14:25:13 2006 -0700

    Move rectangle functions to new cairo-rectangle.c

diff --git a/src/Makefile.am b/src/Makefile.am
index 42ae71f..06bce46 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -161,6 +161,7 @@ libcairo_la_SOURCES =				\
 	cairo-path-stroke.c			\
 	cairo-pen.c				\
 	cairo-polygon.c				\
+	cairo-rectangle.c			\
 	cairo-region.c				\
 	cairo-scaled-font.c			\
 	cairo-slope.c				\
diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c
index df9e9f5..2d4c79f 100644
--- a/src/cairo-gstate.c
+++ b/src/cairo-gstate.c
@@ -959,52 +959,6 @@ BAIL:
     return status;
 }
 
-/* XXX We currently have a confusing mix of boxes and rectangles as
- * exemplified by this function.  A cairo_box_t is a rectangular area
- * represented by the coordinates of the upper left and lower right
- * corners, expressed in fixed point numbers.  A cairo_rectangle_fixed_t is
- * also a rectangular area, but represented by the upper left corner
- * and the width and the height, as integer numbers.
- *
- * This function converts a cairo_box_t to a cairo_rectangle_fixed_t by
- * increasing the area to the nearest integer coordinates.  We should
- * standardize on cairo_rectangle_fixed_t and cairo_rectangle_fixed_t, and
- * this function could be renamed to the more reasonable
- * _cairo_rectangle_fixed_round.
- */
-
-void
-_cairo_box_round_to_rectangle (cairo_box_t *box, cairo_rectangle_fixed_t *rectangle)
-{
-    rectangle->x = _cairo_fixed_integer_floor (box->p1.x);
-    rectangle->y = _cairo_fixed_integer_floor (box->p1.y);
-    rectangle->width = _cairo_fixed_integer_ceil (box->p2.x) - rectangle->x;
-    rectangle->height = _cairo_fixed_integer_ceil (box->p2.y) - rectangle->y;
-}
-
-void
-_cairo_rectangle_intersect (cairo_rectangle_fixed_t *dest, cairo_rectangle_fixed_t *src)
-{
-    int x1, y1, x2, y2;
-
-    x1 = MAX (dest->x, src->x);
-    y1 = MAX (dest->y, src->y);
-    x2 = MIN (dest->x + dest->width, src->x + src->width);
-    y2 = MIN (dest->y + dest->height, src->y + src->height);
-
-    if (x1 >= x2 || y1 >= y2) {
-	dest->x = 0;
-	dest->y = 0;
-	dest->width = 0;
-	dest->height = 0;
-    } else {
-	dest->x = x1;
-	dest->y = y1;
-	dest->width = x2 - x1;
-	dest->height = y2 - y1;
-    }	
-}
-
 cairo_status_t
 _cairo_gstate_fill (cairo_gstate_t *gstate, cairo_path_fixed_t *path)
 {
diff --git a/src/cairo-rectangle.c b/src/cairo-rectangle.c
new file mode 100644
index 0000000..2f30e92
--- /dev/null
+++ b/src/cairo-rectangle.c
@@ -0,0 +1,85 @@
+/* cairo - a vector graphics library with display and print output
+ *
+ * Copyright © 2002 University of Southern California
+ * Copyright © 2005 Red Hat, Inc.
+ * Copyright © 2006 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it either under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation
+ * (the "LGPL") or, at your option, under the terms of the Mozilla
+ * Public License Version 1.1 (the "MPL"). If you do not alter this
+ * notice, a recipient may use your version of this file under either
+ * the MPL or the LGPL.
+ *
+ * You should have received a copy of the LGPL along with this library
+ * in the file COPYING-LGPL-2.1; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * You should have received a copy of the MPL along with this library
+ * in the file COPYING-MPL-1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
+ * OF ANY KIND, either express or implied. See the LGPL or the MPL for
+ * the specific language governing rights and limitations.
+ *
+ * The Original Code is the cairo graphics library.
+ *
+ * The Initial Developer of the Original Code is University of Southern
+ * California.
+ *
+ * Contributor(s):
+ *	Carl D. Worth <cworth at cworth.org>
+ */
+
+#include "cairoint.h"
+
+/* XXX We currently have a confusing mix of boxes and rectangles as
+ * exemplified by this function.  A cairo_box_t is a rectangular area
+ * represented by the coordinates of the upper left and lower right
+ * corners, expressed in fixed point numbers.  A cairo_rectangle_fixed_t is
+ * also a rectangular area, but represented by the upper left corner
+ * and the width and the height, as integer numbers.
+ *
+ * This function converts a cairo_box_t to a cairo_rectangle_fixed_t by
+ * increasing the area to the nearest integer coordinates.  We should
+ * standardize on cairo_rectangle_fixed_t and cairo_rectangle_fixed_t, and
+ * this function could be renamed to the more reasonable
+ * _cairo_rectangle_fixed_round.
+ */
+
+void
+_cairo_box_round_to_rectangle (cairo_box_t *box, cairo_rectangle_fixed_t *rectangle)
+{
+    rectangle->x = _cairo_fixed_integer_floor (box->p1.x);
+    rectangle->y = _cairo_fixed_integer_floor (box->p1.y);
+    rectangle->width = _cairo_fixed_integer_ceil (box->p2.x) - rectangle->x;
+    rectangle->height = _cairo_fixed_integer_ceil (box->p2.y) - rectangle->y;
+}
+
+void
+_cairo_rectangle_intersect (cairo_rectangle_fixed_t *dest, cairo_rectangle_fixed_t *src)
+{
+    int x1, y1, x2, y2;
+
+    x1 = MAX (dest->x, src->x);
+    y1 = MAX (dest->y, src->y);
+    x2 = MIN (dest->x + dest->width, src->x + src->width);
+    y2 = MIN (dest->y + dest->height, src->y + src->height);
+
+    if (x1 >= x2 || y1 >= y2) {
+	dest->x = 0;
+	dest->y = 0;
+	dest->width = 0;
+	dest->height = 0;
+    } else {
+	dest->x = x1;
+	dest->y = y1;
+	dest->width = x2 - x1;
+	dest->height = y2 - y1;
+    }	
+}
diff-tree 3d9dc96d186c9093da24c7bbf36614f3d8df1758 (from 0c49666231e42a3f968ad46a0aa58fc7b854b258)
Author: Carl Worth <cworth at cworth.org>
Date:   Thu May 25 02:28:09 2006 -0700

    New API: Add cairo_image_surface_get_{data,format,stride}

diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index 72c593f..b5010c5 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -329,6 +329,50 @@ _cairo_image_surface_create_for_data_wit
 }
 
 /**
+ * cairo_image_surface_get_data:
+ * @surface: a #cairo_image_surface_t
+ * 
+ * Get a pointer to the data of the image surface, for direct
+ * inspection or modification.
+ * 
+ * Return value: a pointer to the image data of this surface or NULL
+ * if @surface is not an image surface.
+ **/
+unsigned char *
+cairo_image_surface_get_data (cairo_surface_t *surface)
+{
+    cairo_image_surface_t *image_surface = (cairo_image_surface_t *) surface;
+
+    if (!_cairo_surface_is_image (surface)) {
+	_cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
+	return NULL;
+    }
+
+    return image_surface->data;
+}
+
+/**
+ * cairo_image_surface_get_format:
+ * @surface: a #cairo_image_surface_t
+ * 
+ * Get the format of the surface.
+ * 
+ * Return value: the format of the surface
+ **/
+cairo_format_t
+cairo_image_surface_get_format (cairo_surface_t *surface)
+{
+    cairo_image_surface_t *image_surface = (cairo_image_surface_t *) surface;
+
+    if (!_cairo_surface_is_image (surface)) {
+	_cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
+	return 0;
+    }
+
+    return image_surface->format;
+}
+
+/**
  * cairo_image_surface_get_width:
  * @surface: a #cairo_image_surface_t
  * 
@@ -370,6 +414,31 @@ cairo_image_surface_get_height (cairo_su
     return image_surface->height;
 }
 
+/**
+ * cairo_image_surface_get_stride:
+ * @surface: a #cairo_image_surface_t
+ * 
+ * Get the stride of the image surface in bytes
+ * 
+ * Return value: the stride of the image surface in bytes (or 0 if
+ * @surface is not an image surface). The stride is the distance in
+ * bytes from the beginning of one row of the image data to the
+ * beginning of the next row.
+ **/
+int
+cairo_image_surface_get_stride (cairo_surface_t *surface)
+{
+
+    cairo_image_surface_t *image_surface = (cairo_image_surface_t *) surface;
+
+    if (!_cairo_surface_is_image (surface)) {
+	_cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
+	return 0;
+    }
+
+    return image_surface->stride;
+}
+
 cairo_format_t
 _cairo_format_from_content (cairo_content_t content)
 {
diff --git a/src/cairo.h b/src/cairo.h
index 980ecc0..387501c 100644
--- a/src/cairo.h
+++ b/src/cairo.h
@@ -1362,12 +1362,21 @@ cairo_image_surface_create_for_data (uns
 				     int			height,
 				     int			stride);
 
+cairo_public unsigned char *
+cairo_image_surface_get_data (cairo_surface_t *surface);
+
+cairo_public cairo_format_t
+cairo_image_surface_get_format (cairo_surface_t *surface);
+
 cairo_public int
 cairo_image_surface_get_width (cairo_surface_t *surface);
 
 cairo_public int
 cairo_image_surface_get_height (cairo_surface_t *surface);
 
+int
+cairo_image_surface_get_stride (cairo_surface_t *surface);
+
 #if CAIRO_HAS_PNG_FUNCTIONS
 
 cairo_public cairo_surface_t *


More information about the cairo-commit mailing list