summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2010-02-19 18:20:41 +0100
committerBenjamin Otte <otte@redhat.com>2010-04-23 23:30:29 +0200
commit412b233dd1587251032e3b9a5e99dcaaa96e1660 (patch)
treed23582cedd90c365e2e5fc122d9985bed8b4c129
parente749462f1f9c5c5c5bd15b0da48ac86b5f632520 (diff)
test: Add a test for all the different color space / format combinations
-rw-r--r--test/Makefile.sources1
-rw-r--r--test/image-formats.c152
-rw-r--r--test/image-formats.ref.pngbin0 -> 224 bytes
3 files changed, 153 insertions, 0 deletions
diff --git a/test/Makefile.sources b/test/Makefile.sources
index 1062e253..1f136055 100644
--- a/test/Makefile.sources
+++ b/test/Makefile.sources
@@ -115,6 +115,7 @@ test_sources = \
group-unaligned.c \
huge-linear.c \
huge-radial.c \
+ image-formats.c \
image-surface-source.c \
implicit-close.c \
infinite-join.c \
diff --git a/test/image-formats.c b/test/image-formats.c
new file mode 100644
index 00000000..6abe0750
--- /dev/null
+++ b/test/image-formats.c
@@ -0,0 +1,152 @@
+/*
+ * Copyright 2010 Red Hat Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Benjamin Otte not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Benjamin Otte makes no representations about the
+ * suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * BENJAMIN OTTE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL BENJAMIN OTTE BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+ * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Benjamin Otte <otte@redhat.com>
+ */
+
+#include "cairo-test.h"
+#include <pthread.h>
+#include <stdlib.h>
+
+#define SPACE 5
+#define BLOCK SPACE
+#define IMAGE (2 * BLOCK)
+
+#define N_FORMATS (CAIRO_FORMAT_PLANAR_420 + 1)
+#define N_COLOR_SPACES (CAIRO_COLOR_SPACE_YCBCR_JPEG + 1)
+
+#define WIDTH (SPACE + IMAGE) * N_FORMATS + SPACE
+#define HEIGHT (SPACE + IMAGE) * N_COLOR_SPACES + SPACE
+
+static void
+draw_surface (cairo_t *cr)
+{
+ cairo_set_source_rgb (cr, 0.75, 0, 0);
+ cairo_rectangle (cr, 0, 0, BLOCK, BLOCK);
+ cairo_fill (cr);
+
+ cairo_set_source_rgb (cr, 0, 0.75, 0);
+ cairo_rectangle (cr, 0, BLOCK, BLOCK, BLOCK);
+ cairo_fill (cr);
+
+ cairo_set_source_rgb (cr, 0, 0, 0.75);
+ cairo_rectangle (cr, BLOCK, 0, BLOCK, BLOCK);
+ cairo_fill (cr);
+
+ cairo_set_source_rgb (cr, 0.75, 0.75, 0.75);
+ cairo_rectangle (cr, BLOCK, BLOCK, BLOCK, BLOCK);
+ cairo_fill (cr);
+}
+
+static int
+get_planes_for_format (cairo_format_t format)
+{
+ switch (format) {
+ case CAIRO_FORMAT_PLANAR_444:
+ case CAIRO_FORMAT_PLANAR_422:
+ case CAIRO_FORMAT_PLANAR_420:
+ return 3;
+ case CAIRO_FORMAT_ARGB32:
+ case CAIRO_FORMAT_RGB24:
+ case CAIRO_FORMAT_A8:
+ case CAIRO_FORMAT_A1:
+ case CAIRO_FORMAT_RGB16_565:
+ case CAIRO_FORMAT_RGBA32:
+ case CAIRO_FORMAT_ABGR32:
+ case CAIRO_FORMAT_BGRA32:
+ case CAIRO_FORMAT_PACKED_YUYV:
+ case CAIRO_FORMAT_PACKED_YVYU:
+ case CAIRO_FORMAT_PACKED_UYVY:
+ case CAIRO_FORMAT_PACKED_VYUY:
+ case CAIRO_FORMAT_INVALID:
+ default:
+ return 1;
+ }
+}
+
+static cairo_surface_t *
+create_surface (cairo_format_t format, cairo_color_space_t color_space)
+{
+ cairo_surface_t *surface;
+ static const cairo_user_data_key_t key;
+ char *planes[4];
+ int strides[4];
+ int i;
+
+ planes[0] = calloc (4, IMAGE * IMAGE * 4);
+ strides[0] = IMAGE * 4;
+ if (planes[0] == NULL)
+ return NULL;
+
+ for (i = 1; i < 4; i++) {
+ planes[i] = planes[i - 1] + IMAGE * IMAGE * 4;
+ strides[i] = strides[i - 1];
+ }
+
+ surface = cairo_image_surface_create_planar (format,
+ color_space,
+ IMAGE,
+ IMAGE,
+ get_planes_for_format (format),
+ planes,
+ strides);
+ cairo_surface_set_user_data (surface, &key, planes[0], free);
+
+ return surface;
+}
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+ int format, color_space;
+ cairo_surface_t *surface;
+ cairo_t *cr2;
+
+ cairo_set_source_rgb (cr, 0.25, 0.25, 0.25);
+ cairo_paint (cr);
+
+ for (format = 0; format < N_FORMATS; format++) {
+ for (color_space = 0; color_space < N_COLOR_SPACES; color_space++) {
+ surface = create_surface (format, color_space);
+ if (surface == NULL)
+ return CAIRO_TEST_NO_MEMORY;
+
+ cr2 = cairo_create (surface);
+ draw_surface (cr2);
+ cairo_destroy (cr2);
+
+ cairo_set_source_surface (cr, surface, (IMAGE + SPACE) * format + SPACE, (IMAGE + SPACE) * color_space + SPACE);
+ cairo_paint (cr);
+
+ cairo_surface_destroy (surface);
+ }
+ }
+
+ return CAIRO_TEST_SUCCESS;
+}
+
+CAIRO_TEST (image_formats,
+ "Draw lots of 1x1 rectangles on similar surfaces in lots of threads",
+ "", /* keywords */
+ NULL, /* requirements */
+ WIDTH, HEIGHT,
+ NULL, draw)
diff --git a/test/image-formats.ref.png b/test/image-formats.ref.png
new file mode 100644
index 00000000..9dfa8098
--- /dev/null
+++ b/test/image-formats.ref.png
Binary files differ