diff options
Diffstat (limited to 'pixman')
-rw-r--r-- | pixman/demos/Makefile.am | 6 | ||||
-rw-r--r-- | pixman/demos/gtk-utils.c | 202 | ||||
-rw-r--r-- | pixman/pixman/pixman-mmx.c | 5 | ||||
-rw-r--r-- | pixman/test/utils.c | 22 | ||||
-rw-r--r-- | pixman/test/utils.h | 9 |
5 files changed, 113 insertions, 131 deletions
diff --git a/pixman/demos/Makefile.am b/pixman/demos/Makefile.am index 6049090ea..a664d939e 100644 --- a/pixman/demos/Makefile.am +++ b/pixman/demos/Makefile.am @@ -6,7 +6,7 @@ AM_LDFLAGS = $(OPENMP_CFLAGS) LDADD = $(top_builddir)/pixman/libpixman-1.la -lm $(GTK_LIBS) $(PNG_LIBS) INCLUDES = -I$(top_srcdir)/pixman -I$(top_builddir)/pixman $(GTK_CFLAGS) $(PNG_CFLAGS) -GTK_UTILS = gtk-utils.c gtk-utils.h +GTK_UTILS = gtk-utils.c gtk-utils.h ../test/utils.c ../test/utils.h DEMOS = \ clip-test \ @@ -30,8 +30,8 @@ clip_in_SOURCES = clip-in.c $(GTK_UTILS) trap_test_SOURCES = trap-test.c $(GTK_UTILS) screen_test_SOURCES = screen-test.c $(GTK_UTILS) convolution_test_SOURCES = convolution-test.c $(GTK_UTILS) -radial_test_SOURCES = radial-test.c ../test/utils.c ../test/utils.h $(GTK_UTILS) -tri_test_SOURCES = tri-test.c ../test/utils.c ../test/utils.h $(GTK_UTILS) +radial_test_SOURCES = radial-test.c $(GTK_UTILS) +tri_test_SOURCES = tri-test.c $(GTK_UTILS) checkerboard_SOURCES = checkerboard.c $(GTK_UTILS) noinst_PROGRAMS = $(DEMOS) diff --git a/pixman/demos/gtk-utils.c b/pixman/demos/gtk-utils.c index f45cdc912..1ff89ebd3 100644 --- a/pixman/demos/gtk-utils.c +++ b/pixman/demos/gtk-utils.c @@ -1,115 +1,87 @@ -#include <gtk/gtk.h>
-#include <config.h>
-#include "pixman-private.h" /* For image->bits.format
- * FIXME: there should probably be public API for this
- */
-#include "gtk-utils.h"
-
-GdkPixbuf *
-pixbuf_from_argb32 (uint32_t *bits,
- gboolean has_alpha,
- int width,
- int height,
- int stride)
-{
- GdkPixbuf *pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE,
- 8, width, height);
- int p_stride = gdk_pixbuf_get_rowstride (pixbuf);
- guint32 *p_bits = (guint32 *)gdk_pixbuf_get_pixels (pixbuf);
- int w, h;
-
- for (h = 0; h < height; ++h)
- {
- for (w = 0; w < width; ++w)
- {
- uint32_t argb = bits[h * (stride / 4) + w];
- guint r, g, b, a;
- char *pb = (char *)p_bits;
-
- pb += h * p_stride + w * 4;
-
- r = (argb & 0x00ff0000) >> 16;
- g = (argb & 0x0000ff00) >> 8;
- b = (argb & 0x000000ff) >> 0;
- a = has_alpha? (argb & 0xff000000) >> 24 : 0xff;
-
- if (a)
- {
- r = (r * 255) / a;
- g = (g * 255) / a;
- b = (b * 255) / a;
- }
-
- if (r > 255) r = 255;
- if (g > 255) g = 255;
- if (b > 255) b = 255;
-
- pb[0] = r;
- pb[1] = g;
- pb[2] = b;
- pb[3] = a;
- }
- }
-
- return pixbuf;
-}
-
-
-static gboolean
-on_expose (GtkWidget *widget, GdkEventExpose *expose, gpointer data)
-{
- GdkPixbuf *pixbuf = data;
-
- gdk_draw_pixbuf (widget->window, NULL,
- pixbuf, 0, 0, 0, 0,
- gdk_pixbuf_get_width (pixbuf),
- gdk_pixbuf_get_height (pixbuf),
- GDK_RGB_DITHER_NONE,
- 0, 0);
-
- return TRUE;
-}
-
-void
-show_image (pixman_image_t *image)
-{
- GtkWidget *window;
- GdkPixbuf *pixbuf;
- int width, height, stride;
- int argc;
- char **argv;
- char *arg0 = g_strdup ("pixman-test-program");
- gboolean has_alpha;
- pixman_format_code_t format;
-
- argc = 1;
- argv = (char **)&arg0;
-
- gtk_init (&argc, &argv);
-
- window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- width = pixman_image_get_width (image);
- height = pixman_image_get_height (image);
- stride = pixman_image_get_stride (image);
-
- gtk_window_set_default_size (GTK_WINDOW (window), width, height);
-
- format = image->bits.format;
-
- if (format == PIXMAN_a8r8g8b8)
- has_alpha = TRUE;
- else if (format == PIXMAN_x8r8g8b8)
- has_alpha = FALSE;
- else
- g_error ("Can't deal with this format: %x\n", format);
-
- pixbuf = pixbuf_from_argb32 (pixman_image_get_data (image), has_alpha,
- width, height, stride);
-
- g_signal_connect (window, "expose_event", G_CALLBACK (on_expose), pixbuf);
- g_signal_connect (window, "delete_event", G_CALLBACK (gtk_main_quit), NULL);
-
- gtk_widget_show (window);
-
- gtk_main ();
-}
+#include <gtk/gtk.h> +#include <config.h> +#include "../test/utils.h" +#include "gtk-utils.h" + +GdkPixbuf * +pixbuf_from_argb32 (uint32_t *bits, + gboolean has_alpha, + int width, + int height, + int stride) +{ + GdkPixbuf *pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, + 8, width, height); + int p_stride = gdk_pixbuf_get_rowstride (pixbuf); + guint32 *p_bits = (guint32 *)gdk_pixbuf_get_pixels (pixbuf); + int i; + + for (i = 0; i < height; ++i) + { + uint32_t *src_row = &bits[i * (stride / 4)]; + uint32_t *dst_row = p_bits + i * (p_stride / 4); + + a8r8g8b8_to_rgba_np (dst_row, src_row, width); + } + + return pixbuf; +} + +static gboolean +on_expose (GtkWidget *widget, GdkEventExpose *expose, gpointer data) +{ + GdkPixbuf *pixbuf = data; + + gdk_draw_pixbuf (widget->window, NULL, + pixbuf, 0, 0, 0, 0, + gdk_pixbuf_get_width (pixbuf), + gdk_pixbuf_get_height (pixbuf), + GDK_RGB_DITHER_NONE, + 0, 0); + + return TRUE; +} + +void +show_image (pixman_image_t *image) +{ + GtkWidget *window; + GdkPixbuf *pixbuf; + int width, height, stride; + int argc; + char **argv; + char *arg0 = g_strdup ("pixman-test-program"); + gboolean has_alpha; + pixman_format_code_t format; + + argc = 1; + argv = (char **)&arg0; + + gtk_init (&argc, &argv); + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + width = pixman_image_get_width (image); + height = pixman_image_get_height (image); + stride = pixman_image_get_stride (image); + + gtk_window_set_default_size (GTK_WINDOW (window), width, height); + + format = pixman_image_get_format (image); + + if (format == PIXMAN_a8r8g8b8) + has_alpha = TRUE; + else if (format == PIXMAN_x8r8g8b8) + has_alpha = FALSE; + else + g_error ("Can't deal with this format: %x\n", format); + + pixbuf = pixbuf_from_argb32 (pixman_image_get_data (image), has_alpha, + width, height, stride); + + g_signal_connect (window, "expose_event", G_CALLBACK (on_expose), pixbuf); + g_signal_connect (window, "delete_event", G_CALLBACK (gtk_main_quit), NULL); + + gtk_widget_show (window); + + gtk_main (); +} diff --git a/pixman/pixman/pixman-mmx.c b/pixman/pixman/pixman-mmx.c index 9d1f6afd4..3b4625ccf 100644 --- a/pixman/pixman/pixman-mmx.c +++ b/pixman/pixman/pixman-mmx.c @@ -319,7 +319,7 @@ in_over (__m64 src, __m64 srca, __m64 mask, __m64 dest) /* Elemental unaligned loads */ -static __inline__ __m64 ldq_u(uint64_t *p) +static force_inline __m64 ldq_u(uint64_t *p) { #ifdef USE_X86_MMX /* x86's alignment restrictions are very relaxed. */ @@ -338,7 +338,7 @@ static __inline__ __m64 ldq_u(uint64_t *p) #endif } -static __inline__ uint32_t ldl_u(const uint32_t *p) +static force_inline uint32_t ldl_u(const uint32_t *p) { #ifdef USE_X86_MMX /* x86's alignment restrictions are very relaxed. */ @@ -3139,6 +3139,7 @@ static const pixman_fast_path_t mmx_fast_paths[] = PIXMAN_STD_FAST_PATH (OVER, solid, null, a8r8g8b8, mmx_composite_over_n_8888 ), PIXMAN_STD_FAST_PATH (OVER, solid, null, x8r8g8b8, mmx_composite_over_n_8888 ), PIXMAN_STD_FAST_PATH (OVER, solid, null, r5g6b5, mmx_composite_over_n_0565 ), + PIXMAN_STD_FAST_PATH (OVER, solid, null, b5g6r5, mmx_composite_over_n_0565 ), PIXMAN_STD_FAST_PATH (OVER, x8r8g8b8, null, x8r8g8b8, mmx_composite_copy_area ), PIXMAN_STD_FAST_PATH (OVER, x8b8g8r8, null, x8b8g8r8, mmx_composite_copy_area ), diff --git a/pixman/test/utils.c b/pixman/test/utils.c index 379bd71a8..cc0365aa2 100644 --- a/pixman/test/utils.c +++ b/pixman/test/utils.c @@ -340,17 +340,15 @@ make_random_bytes (int n_bytes) return bytes; } -#ifdef HAVE_LIBPNG - -static void -pngify_pixels (uint32_t *pixels, int n_pixels) +void +a8r8g8b8_to_rgba_np (uint32_t *dst, uint32_t *src, int n_pixels) { + uint8_t *dst8 = (uint8_t *)dst; int i; for (i = 0; i < n_pixels; ++i) { - uint32_t p = pixels[i]; - uint8_t *out = (uint8_t *)&(pixels[i]); + uint32_t p = src[i]; uint8_t a, r, g, b; a = (p & 0xff000000) >> 24; @@ -365,13 +363,15 @@ pngify_pixels (uint32_t *pixels, int n_pixels) b = (b * 255) / a; } - *out++ = r; - *out++ = g; - *out++ = b; - *out++ = a; + *dst8++ = r; + *dst8++ = g; + *dst8++ = b; + *dst8++ = a; } } +#ifdef HAVE_LIBPNG + pixman_bool_t write_png (pixman_image_t *image, const char *filename) { @@ -398,7 +398,7 @@ write_png (pixman_image_t *image, const char *filename) pixman_image_composite32 ( PIXMAN_OP_SRC, image, NULL, copy, 0, 0, 0, 0, 0, 0, width, height); - pngify_pixels (data, height * width); + a8r8g8b8_to_rgba_np (data, data, height * width); for (i = 0; i < height; ++i) row_pointers[i] = (png_bytep)(data + i * width); diff --git a/pixman/test/utils.h b/pixman/test/utils.h index 3c0647bc6..01af316d2 100644 --- a/pixman/test/utils.h +++ b/pixman/test/utils.h @@ -107,6 +107,15 @@ fail_after (int seconds, const char *msg); /* If possible, enable traps for floating point exceptions */ void enable_fp_exceptions(void); +/* Converts a8r8g8b8 pixels to pixels that + * - are not premultiplied, + * - are stored in this order in memory: R, G, B, A, regardless of + * the endianness of the computer. + * It is allowed for @src and @dst to point to the same memory buffer. + */ +void +a8r8g8b8_to_rgba_np (uint32_t *dst, uint32_t *src, int n_pixels); + pixman_bool_t write_png (pixman_image_t *image, const char *filename); |