aboutsummaryrefslogtreecommitdiff
path: root/pixman/test
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2011-09-12 09:07:21 +0200
committermarha <marha@users.sourceforge.net>2011-09-12 09:07:21 +0200
commit0b40f5f4b54453a77f4b09c431f8efc6875da61f (patch)
treec1f08e0dd75a6ed7876c24c7219f93f01cab3605 /pixman/test
parent75530c6eb2feebe234f7cb078c4caaf70c64981a (diff)
parent24a692ce832161d3b794110dd82b1508d38a0887 (diff)
downloadvcxsrv-0b40f5f4b54453a77f4b09c431f8efc6875da61f.tar.gz
vcxsrv-0b40f5f4b54453a77f4b09c431f8efc6875da61f.tar.bz2
vcxsrv-0b40f5f4b54453a77f4b09c431f8efc6875da61f.zip
Merge remote-tracking branch 'origin/released'
Conflicts: mesalib/src/glsl/ast_to_hir.cpp mesalib/src/glsl/glcpp/glcpp.c mesalib/src/mesa/drivers/dri/common/dri_util.c mesalib/src/mesa/drivers/dri/common/spantmp2.h mesalib/src/mesa/drivers/dri/common/utils.c mesalib/src/mesa/drivers/dri/swrast/swrast.c mesalib/src/mesa/program/ir_to_mesa.cpp mesalib/src/mesa/state_tracker/st_extensions.c mesalib/src/mesa/state_tracker/st_mesa_to_tgsi.c pixman/configure.ac pixman/pixman/pixman-arm-neon-asm.S pixman/test/Makefile.am pixman/test/utils.c pixman/test/utils.h
Diffstat (limited to 'pixman/test')
-rw-r--r--pixman/test/Makefile.am2
-rw-r--r--pixman/test/utils.c112
-rw-r--r--pixman/test/utils.h3
3 files changed, 116 insertions, 1 deletions
diff --git a/pixman/test/Makefile.am b/pixman/test/Makefile.am
index eca692236..56d56aeb1 100644
--- a/pixman/test/Makefile.am
+++ b/pixman/test/Makefile.am
@@ -1,6 +1,6 @@
AM_CFLAGS = @OPENMP_CFLAGS@
AM_LDFLAGS = @OPENMP_CFLAGS@ @TESTPROGS_EXTRA_LDFLAGS@
-LDADD = $(top_builddir)/pixman/libpixman-1.la -lm
+LDADD = $(top_builddir)/pixman/libpixman-1.la -lm -lpng
INCLUDES = -I$(top_srcdir)/pixman -I$(top_builddir)/pixman
TESTPROGRAMS = \
diff --git a/pixman/test/utils.c b/pixman/test/utils.c
index da494cf59..46b48415f 100644
--- a/pixman/test/utils.c
+++ b/pixman/test/utils.c
@@ -21,6 +21,10 @@
#include <fenv.h>
#endif
+#ifdef HAVE_LIBPNG
+#include <png.h>
+#endif
+
/* Random number seed
*/
@@ -335,6 +339,114 @@ make_random_bytes (int n_bytes)
return bytes;
}
+#ifdef HAVE_LIBPNG
+
+static void
+pngify_pixels (uint32_t *pixels, int n_pixels)
+{
+ int i;
+
+ for (i = 0; i < n_pixels; ++i)
+ {
+ uint32_t p = pixels[i];
+ uint8_t *out = (uint8_t *)&(pixels[i]);
+ uint8_t a, r, g, b;
+
+ a = (p & 0xff000000) >> 24;
+ r = (p & 0x00ff0000) >> 16;
+ g = (p & 0x0000ff00) >> 8;
+ b = (p & 0x000000ff) >> 0;
+
+ if (a != 0)
+ {
+ r = (r * 255) / a;
+ g = (g * 255) / a;
+ b = (b * 255) / a;
+ }
+
+ *out++ = r;
+ *out++ = g;
+ *out++ = b;
+ *out++ = a;
+ }
+}
+
+pixman_bool_t
+write_png (pixman_image_t *image, const char *filename)
+{
+ int width = pixman_image_get_width (image);
+ int height = pixman_image_get_height (image);
+ int stride = width * 4;
+ uint32_t *data = malloc (height * stride);
+ pixman_image_t *copy;
+ png_struct *write_struct;
+ png_info *info_struct;
+ pixman_bool_t result = FALSE;
+ FILE *f = fopen (filename, "wb");
+ png_bytep *row_pointers;
+ int i;
+
+ if (!f)
+ return FALSE;
+
+ row_pointers = malloc (height * sizeof (png_bytep));
+
+ copy = pixman_image_create_bits (
+ PIXMAN_a8r8g8b8, width, height, data, stride);
+
+ pixman_image_composite32 (
+ PIXMAN_OP_SRC, image, NULL, copy, 0, 0, 0, 0, 0, 0, width, height);
+
+ pngify_pixels (data, height * width);
+
+ for (i = 0; i < height; ++i)
+ row_pointers[i] = (png_bytep)(data + i * width);
+
+ if (!(write_struct = png_create_write_struct (
+ PNG_LIBPNG_VER_STRING, NULL, NULL, NULL)))
+ goto out1;
+
+ if (!(info_struct = png_create_info_struct (write_struct)))
+ goto out2;
+
+ png_init_io (write_struct, f);
+
+ png_set_IHDR (write_struct, info_struct, width, height,
+ 8, PNG_COLOR_TYPE_RGB_ALPHA,
+ PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE,
+ PNG_FILTER_TYPE_BASE);
+
+ png_write_info (write_struct, info_struct);
+
+ png_write_image (write_struct, row_pointers);
+
+ png_write_end (write_struct, NULL);
+
+ result = TRUE;
+
+out2:
+ png_destroy_write_struct (&write_struct, &info_struct);
+
+out1:
+ if (fclose (f) != 0)
+ result = FALSE;
+
+ pixman_image_unref (copy);
+ free (row_pointers);
+ free (data);
+ return result;
+}
+
+#else /* no libpng */
+
+pixman_bool_t
+write_png (pixman_image_t *image, const char *filename)
+{
+ return FALSE;
+}
+
+#endif
+
/*
* A function, which can be used as a core part of the test programs,
* intended to detect various problems with the help of fuzzing input
diff --git a/pixman/test/utils.h b/pixman/test/utils.h
index 9b4d984f7..cd9a3c263 100644
--- a/pixman/test/utils.h
+++ b/pixman/test/utils.h
@@ -105,6 +105,9 @@ fail_after (int seconds, const char *msg);
/* If possible, enable traps for floating point exceptions */
void enable_fp_exceptions(void);
+pixman_bool_t
+write_png (pixman_image_t *image, const char *filename);
+
/* A pair of macros which can help to detect corruption of
* floating point registers after a function call. This may
* happen if _mm_empty() call is forgotten in MMX/SSE2 fast