[gdk-pixbuf] tests: Move pixbuf creation helpers to test-common.[ch]



commit 5f232dc86d5da47b2c722136117f31d807313491
Author: Bastien Nocera <hadess hadess net>
Date:   Fri Jan 6 17:05:35 2017 +0100

    tests: Move pixbuf creation helpers to test-common.[ch]
    
    Those will be used in the 2-step scaler tests.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=80925

 tests/pixbuf-scale.c |   58 --------------------------------------------------
 tests/test-common.c  |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/test-common.h  |    2 +
 3 files changed, 60 insertions(+), 58 deletions(-)
---
diff --git a/tests/pixbuf-scale.c b/tests/pixbuf-scale.c
index 9fb9be6..d655ad7 100644
--- a/tests/pixbuf-scale.c
+++ b/tests/pixbuf-scale.c
@@ -171,64 +171,6 @@ test_rotate (gconstpointer data)
 
 /* Test images creation functions */
 
-/* Checkerboard of black and white pxels (actually (1,1,1) and (255,255,255)
- * so they average to (128,128,128)) */
-static GdkPixbuf *
-make_checkerboard (int width, int height)
-{
-  GdkPixbuf *checkerboard;
-  guint x, y;
-  guchar *row;   /* Pointer to start of row of pixels within the image */
-  guchar *pixel; /* Pointer to current pixel data in row */
-
-  checkerboard = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, width, height);
-  g_assert_nonnull (checkerboard);
-
-  for (y = 0, row = gdk_pixbuf_get_pixels (checkerboard);
-       y < height;
-       y++, row += gdk_pixbuf_get_rowstride (checkerboard))
-    {
-      for (x = 0, pixel = row;
-           x < width;
-           x++, pixel += gdk_pixbuf_get_n_channels (checkerboard))
-        {
-          pixel[0] = pixel[1] = pixel[2] = (x ^ y) & 1 ? 1 : 255;
-        }
-    }
-
-  return checkerboard;
-}
-
-/* Image where all the pixels have different colours */
-static GdkPixbuf *
-make_rg (int width, int height)
-{
-  GdkPixbuf *pixbuf;
-  guint x, y;
-  guchar *row;   /* Pointer to start of row of pixels within the image */
-  guchar *pixel; /* Pointer to current pixel data in row */
-
-  /* Make a source image whose pixels are all of different colors */
-  pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, width, height);
-  g_assert_nonnull (pixbuf);
-
-  for (y = 0, row = gdk_pixbuf_get_pixels (pixbuf);
-       y < height;
-       y++, row += gdk_pixbuf_get_rowstride (pixbuf))
-    {
-      for (x = 0, pixel = row;
-           x < width;
-           x++, pixel += gdk_pixbuf_get_n_channels (pixbuf))
-        {
-          pixel[0] = x & 255; pixel[1] = y & 255;
-          /* If image > 256 pixels wide/high put the extra bits in the last pixel */
-          pixel[2] = ((x >> 8) & 15) | ((( y >> 8) & 15) << 4);
-        }
-    }
-
-  return pixbuf;
-}
-
 /* Create a 256x256 checkerboard of (1,1,1) and (255,255,255) pixels,
  * scale it to exactly half size and check that all pixels are (128,128,128). */
 static void
diff --git a/tests/test-common.c b/tests/test-common.c
index cda9988..a75655f 100644
--- a/tests/test-common.c
+++ b/tests/test-common.c
@@ -26,6 +26,64 @@
 
 #include <string.h>
 
+/* Checkerboard of black and white pxels (actually (1,1,1) and (255,255,255)
+ * so they average to (128,128,128)) */
+GdkPixbuf *
+make_checkerboard (int width, int height)
+{
+  GdkPixbuf *checkerboard;
+  guint x, y;
+  guchar *row;   /* Pointer to start of row of pixels within the image */
+  guchar *pixel; /* Pointer to current pixel data in row */
+
+  checkerboard = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, width, height);
+  g_assert_nonnull (checkerboard);
+
+  for (y = 0, row = gdk_pixbuf_get_pixels (checkerboard);
+       y < height;
+       y++, row += gdk_pixbuf_get_rowstride (checkerboard))
+    {
+      for (x = 0, pixel = row;
+           x < width;
+           x++, pixel += gdk_pixbuf_get_n_channels (checkerboard))
+        {
+          pixel[0] = pixel[1] = pixel[2] = (x ^ y) & 1 ? 1 : 255;
+        }
+    }
+
+  return checkerboard;
+}
+
+/* Image where all the pixels have different colours */
+GdkPixbuf *
+make_rg (int width, int height)
+{
+  GdkPixbuf *pixbuf;
+  guint x, y;
+  guchar *row;   /* Pointer to start of row of pixels within the image */
+  guchar *pixel; /* Pointer to current pixel data in row */
+
+  /* Make a source image whose pixels are all of different colors */
+  pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, width, height);
+  g_assert_nonnull (pixbuf);
+
+  for (y = 0, row = gdk_pixbuf_get_pixels (pixbuf);
+       y < height;
+       y++, row += gdk_pixbuf_get_rowstride (pixbuf))
+    {
+      for (x = 0, pixel = row;
+           x < width;
+           x++, pixel += gdk_pixbuf_get_n_channels (pixbuf))
+        {
+          pixel[0] = x & 255; pixel[1] = y & 255;
+          /* If image > 256 pixels wide/high put the extra bits in the last pixel */
+          pixel[2] = ((x >> 8) & 15) | ((( y >> 8) & 15) << 4);
+        }
+    }
+
+  return pixbuf;
+}
+
 gboolean
 format_supported (const gchar *filename)
 {
diff --git a/tests/test-common.h b/tests/test-common.h
index 8da8f96..8e7f676 100644
--- a/tests/test-common.h
+++ b/tests/test-common.h
@@ -33,6 +33,8 @@ gboolean format_supported (const gchar *filename);
 gboolean file_supported (GFile *file);
 gboolean skip_if_insufficient_memory (GError **err);
 gboolean pixdata_equal (GdkPixbuf *test, GdkPixbuf *ref, GError **error);
+GdkPixbuf *make_checkerboard (int width, int height);
+GdkPixbuf *make_rg (int width, int height);
 void add_test_for_all_images (const gchar   *prefix,
                               GFile         *base,
                               GFile         *file,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]