[Pixman] [PATCH 2/2] utils.[ch]: Add new format_name() function
Søren Sandmann
sandmann at cs.au.dk
Sat Jan 19 07:44:59 PST 2013
From: Søren Sandmann Pedersen <ssp at redhat.com>
This function returns the name of the given format code, which is
useful for printing out debug information. The function is written as
a switch without a default value so that the compiler will warn if new
formats are added in the future. The fake formats used in the fast
path tables are also recognized.
The function is used in alpha_map.c, where it replaces an existing
format_name() function, and in blitters-test.c, affine-test.c, and
scaling-test.c.
---
test/affine-test.c | 2 +-
test/alphamap.c | 19 ----------
test/blitters-test.c | 6 ++-
test/scaling-test.c | 3 +-
test/utils.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++
test/utils.h | 3 ++
6 files changed, 103 insertions(+), 23 deletions(-)
diff --git a/test/affine-test.c b/test/affine-test.c
index 477c1e1..678fbe8 100644
--- a/test/affine-test.c
+++ b/test/affine-test.c
@@ -200,7 +200,7 @@ test_composite (int testnum,
#define M(r,c) \
transform.matrix[r][c]
- printf ("src_fmt=%08X, dst_fmt=%08X\n", src_fmt, dst_fmt);
+ printf ("src_fmt=%s, dst_fmt=%s\n", format_name (src_fmt), format_name (dst_fmt));
printf ("op=%s, repeat=%d, transform=\n",
operator_name (op), repeat);
printf (" { { { 0x%08x, 0x%08x, 0x%08x },\n"
diff --git a/test/alphamap.c b/test/alphamap.c
index 1a6fca5..4d09076 100644
--- a/test/alphamap.c
+++ b/test/alphamap.c
@@ -26,25 +26,6 @@ static const int origins[] =
0, 10, -100
};
-static const char *
-format_name (pixman_format_code_t format)
-{
- if (format == PIXMAN_a8)
- return "a8";
- else if (format == PIXMAN_a2r10g10b10)
- return "a2r10g10b10";
- else if (format == PIXMAN_a8r8g8b8)
- return "a8r8g8b8";
- else if (format == PIXMAN_a4r4g4b4)
- return "a4r4g4b4";
- else if (format == PIXMAN_null)
- return "none";
- else
- assert (0);
-
- return "<unknown - bug in alphamap.c>";
-}
-
static void
on_destroy (pixman_image_t *image, void *data)
{
diff --git a/test/blitters-test.c b/test/blitters-test.c
index c5b452c..8766fa8 100644
--- a/test/blitters-test.c
+++ b/test/blitters-test.c
@@ -329,8 +329,10 @@ test_composite (int testnum, int verbose)
if (verbose)
{
- printf ("op=%s, src_fmt=%08X, dst_fmt=%08X, mask_fmt=%08X\n",
- operator_name (op), src_fmt, dst_fmt, mask_fmt);
+ printf ("op=%s\n", operator_name (op));
+ printf ("src_fmt=%s, dst_fmt=%s, mask_fmt=%s\n",
+ format_name (src_fmt), format_name (dst_fmt),
+ format_name (mask_fmt));
printf ("src_width=%d, src_height=%d, dst_width=%d, dst_height=%d\n",
src_width, src_height, dst_width, dst_height);
printf ("src_x=%d, src_y=%d, dst_x=%d, dst_y=%d\n",
diff --git a/test/scaling-test.c b/test/scaling-test.c
index 173179c..a8cb4c4 100644
--- a/test/scaling-test.c
+++ b/test/scaling-test.c
@@ -239,7 +239,8 @@ test_composite (int testnum,
if (verbose)
{
- printf ("src_fmt=%08X, dst_fmt=%08X\n", src_fmt, dst_fmt);
+ printf ("src_fmt=%s, dst_fmt=%s\n",
+ format_name (src_fmt), format_name (dst_fmt));
printf ("op=%s, scale_x=%d, scale_y=%d, repeat=%d\n",
operator_name (op), scale_x, scale_y, repeat);
printf ("translate_x=%d, translate_y=%d\n",
diff --git a/test/utils.c b/test/utils.c
index 480129b..ba7e353 100644
--- a/test/utils.c
+++ b/test/utils.c
@@ -939,6 +939,99 @@ operator_name (pixman_op_t op)
return "<unknown operator>";
}
+const char *
+format_name (pixman_format_code_t format)
+{
+ switch (format)
+ {
+/* 32bpp formats */
+ case PIXMAN_a8r8g8b8: return "a8r8g8b8";
+ case PIXMAN_x8r8g8b8: return "x8r8g8b8";
+ case PIXMAN_a8b8g8r8: return "a8b8g8r8";
+ case PIXMAN_x8b8g8r8: return "x8b8g8r8";
+ case PIXMAN_b8g8r8a8: return "b8g8r8a8";
+ case PIXMAN_b8g8r8x8: return "b8g8r8x8";
+ case PIXMAN_r8g8b8a8: return "r8g8b8a8";
+ case PIXMAN_r8g8b8x8: return "r8g8b8x8";
+ case PIXMAN_x14r6g6b6: return "x14r6g6b6";
+ case PIXMAN_x2r10g10b10: return "x2r10g10b10";
+ case PIXMAN_a2r10g10b10: return "a2r10g10b10";
+ case PIXMAN_x2b10g10r10: return "x2b10g10r10";
+ case PIXMAN_a2b10g10r10: return "a2b10g10r10";
+
+/* sRGB formats */
+ case PIXMAN_a8r8g8b8_sRGB: return "a8r8g8b8_sRGB";
+
+/* 24bpp formats */
+ case PIXMAN_r8g8b8: return "r8g8b8";
+ case PIXMAN_b8g8r8: return "b8g8r8";
+
+/* 16bpp formats */
+ case PIXMAN_r5g6b5: return "r5g6b5";
+ case PIXMAN_b5g6r5: return "b5g6r5";
+
+ case PIXMAN_a1r5g5b5: return "a1r5g5b5";
+ case PIXMAN_x1r5g5b5: return "x1r5g5b5";
+ case PIXMAN_a1b5g5r5: return "a1b5g5r5";
+ case PIXMAN_x1b5g5r5: return "x1b5g5r5";
+ case PIXMAN_a4r4g4b4: return "a4r4g4b4";
+ case PIXMAN_x4r4g4b4: return "x4r4g4b4";
+ case PIXMAN_a4b4g4r4: return "a4b4g4r4";
+ case PIXMAN_x4b4g4r4: return "x4b4g4r4";
+
+/* 8bpp formats */
+ case PIXMAN_a8: return "a8";
+ case PIXMAN_r3g3b2: return "r3g3b2";
+ case PIXMAN_b2g3r3: return "b2g3r3";
+ case PIXMAN_a2r2g2b2: return "a2r2g2b2";
+ case PIXMAN_a2b2g2r2: return "a2b2g2r2";
+
+#if 0
+ case PIXMAN_x4c4: return "x4c4";
+ case PIXMAN_g8: return "g8";
+#endif
+ case PIXMAN_c8: return "x4c4 / c8";
+ case PIXMAN_x4g4: return "x4g4 / g8";
+
+ case PIXMAN_x4a4: return "x4a4";
+
+/* 4bpp formats */
+ case PIXMAN_a4: return "a4";
+ case PIXMAN_r1g2b1: return "r1g2b1";
+ case PIXMAN_b1g2r1: return "b1g2r1";
+ case PIXMAN_a1r1g1b1: return "a1r1g1b1";
+ case PIXMAN_a1b1g1r1: return "a1b1g1r1";
+
+ case PIXMAN_c4: return "c4";
+ case PIXMAN_g4: return "g4";
+
+/* 1bpp formats */
+ case PIXMAN_a1: return "a1";
+
+ case PIXMAN_g1: return "g1";
+
+/* YUV formats */
+ case PIXMAN_yuy2: return "yuy2";
+ case PIXMAN_yv12: return "yv12";
+ };
+
+ /* Fake formats.
+ *
+ * This is separate switch to prevent GCC from complaining
+ * that the values are not in the pixman_format_code_t enum.
+ */
+ switch ((uint32_t)format)
+ {
+ case PIXMAN_null: return "null";
+ case PIXMAN_solid: return "solid";
+ case PIXMAN_pixbuf: return "pixbuf";
+ case PIXMAN_rpixbuf: return "rpixbuf";
+ case PIXMAN_unknown: return "unknown";
+ };
+
+ return "<unknown format>";
+};
+
static double
round_channel (double p, int m)
{
diff --git a/test/utils.h b/test/utils.h
index e984210..4988314 100644
--- a/test/utils.h
+++ b/test/utils.h
@@ -180,6 +180,9 @@ initialize_palette (pixman_indexed_t *palette, uint32_t depth, int is_rgb);
const char *
operator_name (pixman_op_t op);
+const char *
+format_name (pixman_format_code_t format);
+
typedef struct
{
double r, g, b, a;
--
1.7.4
More information about the Pixman
mailing list