pixman: Branch 'master' - 3 commits
Søren Sandmann Pedersen
sandmann at kemper.freedesktop.org
Tue Apr 3 22:17:56 PDT 2012
demos/Makefile.am | 6 +++---
demos/gtk-utils.c | 46 +++++++++-------------------------------------
test/utils.c | 22 +++++++++++-----------
test/utils.h | 9 +++++++++
4 files changed, 32 insertions(+), 51 deletions(-)
New commits:
commit 87ecec8d72be4106358e843a1e7a907b0e814f7f
Author: Søren Sandmann Pedersen <ssp at redhat.com>
Date: Mon Apr 2 15:16:18 2012 -0400
gtk-utils.c: In pixbuf_from_argb32() use a8r8g8b8_to_rgba_np()
Instead of inlining a copy of that functionality.
diff --git a/demos/Makefile.am b/demos/Makefile.am
index 6049090..a664d93 100644
--- a/demos/Makefile.am
+++ b/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/demos/gtk-utils.c b/demos/gtk-utils.c
index b321989..1ff89eb 100644
--- a/demos/gtk-utils.c
+++ b/demos/gtk-utils.c
@@ -1,5 +1,6 @@
#include <gtk/gtk.h>
#include <config.h>
+#include "../test/utils.h"
#include "gtk-utils.h"
GdkPixbuf *
@@ -13,45 +14,19 @@ pixbuf_from_argb32 (uint32_t *bits,
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;
+ int i;
- if (a)
- {
- r = (r * 255) / a;
- g = (g * 255) / a;
- b = (b * 255) / a;
- }
+ for (i = 0; i < height; ++i)
+ {
+ uint32_t *src_row = &bits[i * (stride / 4)];
+ uint32_t *dst_row = p_bits + i * (p_stride / 4);
- 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;
- }
+ a8r8g8b8_to_rgba_np (dst_row, src_row, width);
}
-
+
return pixbuf;
}
-
static gboolean
on_expose (GtkWidget *widget, GdkEventExpose *expose, gpointer data)
{
commit d1ec1467f607c21a4d8b445eab5465ca60a12a97
Author: Søren Sandmann Pedersen <ssp at redhat.com>
Date: Mon Apr 2 15:09:16 2012 -0400
test/utils.c: Rename and export the pngify_pixels() function.
This function converts from a8r8g8b8 to non-premultiplied RGBA (the
PNG or GdkPixbuf format that has the channels in this order: R, G, B,
A in memory regardless of the computer's endianness). The function's
new name is a8r8g8b8_to_rgba_np().
diff --git a/test/utils.c b/test/utils.c
index 379bd71..cc0365a 100644
--- a/test/utils.c
+++ b/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/test/utils.h b/test/utils.h
index 3c0647b..01af316 100644
--- a/test/utils.h
+++ b/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);
commit b16ddf17829633ec6eb54656924b7e841c6c69a4
Author: Søren Sandmann Pedersen <ssp at redhat.com>
Date: Mon Apr 2 14:59:02 2012 -0400
gtk-utils.c: Don't include pixman-private.h
Use pixman_image_get_format() instead of image->bits.format.
diff --git a/demos/gtk-utils.c b/demos/gtk-utils.c
index 0e7cb5c..b321989 100644
--- a/demos/gtk-utils.c
+++ b/demos/gtk-utils.c
@@ -1,8 +1,5 @@
#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 *
@@ -94,7 +91,7 @@ show_image (pixman_image_t *image)
gtk_window_set_default_size (GTK_WINDOW (window), width, height);
- format = image->bits.format;
+ format = pixman_image_get_format (image);
if (format == PIXMAN_a8r8g8b8)
has_alpha = TRUE;
More information about the xorg-commit
mailing list