[GRASS-SVN] r43698 - grass/branches/develbranch_6/lib/cairodriver

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Sep 27 06:13:40 EDT 2010


Author: hamish
Date: 2010-09-27 10:13:40 +0000 (Mon, 27 Sep 2010)
New Revision: 43698

Modified:
   grass/branches/develbranch_6/lib/cairodriver/Draw_bitmap.c
Log:
backport cairo driver fixes from trunk (#1152)

Modified: grass/branches/develbranch_6/lib/cairodriver/Draw_bitmap.c
===================================================================
--- grass/branches/develbranch_6/lib/cairodriver/Draw_bitmap.c	2010-09-27 05:34:36 UTC (rev 43697)
+++ grass/branches/develbranch_6/lib/cairodriver/Draw_bitmap.c	2010-09-27 10:13:40 UTC (rev 43698)
@@ -1,44 +1,53 @@
-#include "cairodriver.h"
+/*!
+  \file cairodriver/Draw_bitmap.c
 
-static cairo_surface_t *fix_surface(cairo_surface_t * src)
-{
-    int width = cairo_image_surface_get_width(src);
-    int height = cairo_image_surface_get_height(src);
-    int stride = cairo_image_surface_get_stride(src);
-    cairo_format_t format = cairo_image_surface_get_format(src);
-    unsigned char *data = cairo_image_surface_get_data(src);
-    cairo_surface_t *dst = cairo_image_surface_create(format, width, height);
-    int stride2 = cairo_image_surface_get_stride(dst);
-    unsigned char *data2 = cairo_image_surface_get_data(dst);
-    int i;
+  \brief GRASS cairo display driver - draw bitmap
 
-    for (i = 0; i < height; i++) {
-	void *p = data + i * stride;
-	void *q = data2 + i * stride2;
-	int n = stride < stride2 ? stride : stride2;
+  (C) 2007-2010 by Lars Ahlzen and the GRASS Development Team
+  
+  This program is free software under the GNU General Public License
+  (>=v2). Read the file COPYING that comes with GRASS for details.
+  
+  \author Lars Ahlzen <lars ahlzen.com> (original contibutor)
+  \author Glynn Clements  
+*/
 
-	memcpy(q, p, n);
-    }
+#include <grass/glocale.h>
 
-    cairo_surface_destroy(src);
-    return dst;
-}
+#include "cairodriver.h"
 
+/*!
+  \brief Draw bitmap
+
+  \param ncols,nrows number of columns and rows
+  \param threshold threshold value
+  \param buf data buffer
+*/
 void Cairo_draw_bitmap(int ncols, int nrows, int threshold,
 		       const unsigned char *buf)
 {
     cairo_surface_t *surf;
+    int stride;
+    unsigned char *data;
+    int i;
 
     G_debug(1, "Cairo_draw_bitmap: %d %d %d", ncols, nrows, threshold);
 
-    surf = cairo_image_surface_create_for_data((unsigned char *)buf,
-					       CAIRO_FORMAT_A8, ncols, nrows,
-					       ncols);
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1,5,8)
+    stride = cairo_format_stride_for_width(CAIRO_FORMAT_A8, ncols);
+#else
+#define MULTIPLE 4
+    stride = (ncols + (MULTIPLE - 1)) / MULTIPLE * MULTIPLE;
+#endif
+    data = malloc(stride * nrows);
+    surf = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_A8, ncols,
+					       nrows, stride);
 
     if (cairo_surface_status(surf) != CAIRO_STATUS_SUCCESS)
-	G_fatal_error("Cairo_draw_bitmap: Failed to create source");
+	G_fatal_error(_("Cairo_draw_bitmap: Failed to create source"));
 
-    surf = fix_surface(surf);
+    for (i = 0; i < nrows; i++)
+	memcpy(&data[i * stride], &buf[i * ncols], ncols);
 
     cairo_mask_surface(cairo, surf, cur_x, cur_y);
 



More information about the grass-commit mailing list