[cairo] [Not for upstream PATCH 5/5] boilerplate: Add support for new float formats.

Maarten Lankhorst maarten.lankhorst at linux.intel.com
Mon Dec 3 14:13:43 UTC 2018


This will make it possible to actually test floating point support works.

Tested with CAIRO_TEST_TARGET=imagefloat.

All tests fail, because the comparison function is broken, but at least
it shows the code works.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst at linux.intel.com>
---
 boilerplate/cairo-boilerplate.c | 154 ++++++++++++++++++++++++++------
 1 file changed, 129 insertions(+), 25 deletions(-)

diff --git a/boilerplate/cairo-boilerplate.c b/boilerplate/cairo-boilerplate.c
index 4804deaffcb5..080b5c3006b3 100644
--- a/boilerplate/cairo-boilerplate.c
+++ b/boilerplate/cairo-boilerplate.c
@@ -241,6 +241,56 @@ _cairo_boilerplate_image16_create_similar (cairo_surface_t *other,
     return surface;
 }
 
+static cairo_surface_t *
+_cairo_boilerplate_imagefloat_create_surface (const char	     *name,
+					      cairo_content_t	      content,
+					      double		      width,
+					      double		      height,
+					      double		      max_width,
+					      double		      max_height,
+					      cairo_boilerplate_mode_t   mode,
+					      void		    **closure)
+{
+    *closure = NULL;
+
+    /* XXX force CAIRO_CONTENT_COLOR */
+    return cairo_image_surface_create (CAIRO_FORMAT_RGB96F, ceil (width), ceil (height));
+}
+
+static cairo_surface_t *
+_cairo_boilerplate_imagefloat_create_similar (cairo_surface_t *other,
+					   cairo_content_t content,
+					   int width, int height)
+{
+    cairo_format_t format;
+    cairo_surface_t *surface;
+    int stride;
+    void *ptr;
+
+    switch (content) {
+    case CAIRO_CONTENT_ALPHA:
+        format = CAIRO_FORMAT_A8;
+        break;
+    case CAIRO_CONTENT_COLOR:
+        format = CAIRO_FORMAT_RGB96F;
+        break;
+    case CAIRO_CONTENT_COLOR_ALPHA:
+    default:
+        format = CAIRO_FORMAT_RGBA128F;
+        break;
+    }
+
+    stride = cairo_format_stride_for_width(format, width);
+    ptr = malloc (stride* height);
+
+    surface = cairo_image_surface_create_for_data (ptr, format,
+						   width, height, stride);
+    cairo_surface_set_user_data (surface, &key, ptr, free);
+
+    return surface;
+}
+
+
 static char *
 _cairo_boilerplate_image_describe (void *closure)
 {
@@ -281,36 +331,16 @@ _cairo_boilerplate_recording_surface_cleanup (void *closure)
 
 const cairo_user_data_key_t cairo_boilerplate_output_basename_key;
 
-cairo_surface_t *
-_cairo_boilerplate_get_image_surface (cairo_surface_t *src,
-				      int	       page,
-				      int	       width,
-				      int	       height)
+static cairo_surface_t *
+_cairo_boilerplate_get_image_surface_for_format(cairo_surface_t *src,
+						cairo_format_t	 format,
+						int		 width,
+						int		 height)
 {
     cairo_surface_t *surface, *image;
     cairo_t *cr;
     cairo_status_t status;
-    cairo_format_t format;
-
-    if (cairo_surface_status (src))
-	return cairo_surface_reference (src);
 
-    if (page != 0)
-	return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
-
-    /* extract sub-surface */
-    switch (cairo_surface_get_content (src)) {
-    case CAIRO_CONTENT_ALPHA:
-	format = CAIRO_FORMAT_A8;
-	break;
-    case CAIRO_CONTENT_COLOR:
-	format = CAIRO_FORMAT_RGB24;
-	break;
-    default:
-    case CAIRO_CONTENT_COLOR_ALPHA:
-	format = CAIRO_FORMAT_ARGB32;
-	break;
-    }
     surface = cairo_image_surface_create (format, width, height);
     assert (cairo_surface_get_content (surface) == cairo_surface_get_content (src));
     image = cairo_surface_reference (surface);
@@ -352,6 +382,67 @@ _cairo_boilerplate_get_image_surface (cairo_surface_t *src,
     return image;
 }
 
+cairo_surface_t *
+_cairo_boilerplate_get_image_surface (cairo_surface_t *src,
+				      int	       page,
+				      int	       width,
+				      int	       height)
+{
+    cairo_format_t format;
+
+    if (cairo_surface_status (src))
+	return cairo_surface_reference (src);
+
+    if (page != 0)
+	return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
+
+    /* extract sub-surface */
+    switch (cairo_surface_get_content (src)) {
+    case CAIRO_CONTENT_ALPHA:
+	format = CAIRO_FORMAT_A8;
+	break;
+    case CAIRO_CONTENT_COLOR:
+	format = CAIRO_FORMAT_RGB24;
+	break;
+    default:
+    case CAIRO_CONTENT_COLOR_ALPHA:
+	format = CAIRO_FORMAT_ARGB32;
+	break;
+    }
+    return _cairo_boilerplate_get_image_surface_for_format(src, format, width, height);
+}
+
+static cairo_surface_t *
+_cairo_boilerplate_get_image_surface_float (cairo_surface_t *src,
+					    int	       page,
+					    int	       width,
+					    int	       height)
+{
+    cairo_format_t format;
+
+    if (cairo_surface_status (src))
+	return cairo_surface_reference (src);
+
+    if (page != 0)
+	return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
+
+    /* extract sub-surface */
+    switch (cairo_surface_get_content (src)) {
+    case CAIRO_CONTENT_ALPHA:
+	format = CAIRO_FORMAT_A8;
+	break;
+    case CAIRO_CONTENT_COLOR:
+	format = CAIRO_FORMAT_RGB96F;
+	break;
+    default:
+    case CAIRO_CONTENT_COLOR_ALPHA:
+	format = CAIRO_FORMAT_RGBA128F;
+	break;
+    }
+
+    return _cairo_boilerplate_get_image_surface_for_format(src, format, width, height);
+}
+
 cairo_surface_t *
 cairo_boilerplate_get_image_surface_from_png (const char   *filename,
 					      int	    width,
@@ -454,6 +545,19 @@ static const cairo_boilerplate_target_t builtin_targets[] = {
         _cairo_boilerplate_image_describe,
 	TRUE, FALSE, FALSE
     },
+    {
+	"imagefloat", "image", NULL, NULL,
+	CAIRO_SURFACE_TYPE_IMAGE, CAIRO_CONTENT_COLOR, 0,
+	NULL,
+	_cairo_boilerplate_imagefloat_create_surface,
+	_cairo_boilerplate_imagefloat_create_similar,
+	NULL, NULL,
+	_cairo_boilerplate_get_image_surface_float,
+	cairo_surface_write_to_png,
+	NULL, NULL,
+        _cairo_boilerplate_image_describe,
+	TRUE, FALSE, FALSE
+    },
 #if CAIRO_HAS_RECORDING_SURFACE
     {
 	"recording", "image", NULL, NULL,
-- 
2.19.2



More information about the cairo mailing list