summaryrefslogtreecommitdiff
blob: c57996844a1629460b24e8e7933467b59456bdf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
From 13e13619f96b8840c24fe349799aaf8d87b065f5 Mon Sep 17 00:00:00 2001
From: Neil Roberts <neil@linux.intel.com>
Date: Wed, 17 Nov 2010 17:31:23 +0000
Subject: [PATCH] test-cogl-texture-get-set-data: Test the alpha component

Previously the alpha component of the test texture data was always set
to 255 and the data was read back as RGB so that the alpha component
is ignored. Now the alpha component is set to a generated value and
the data is read back a second time as RGBA to verify that Cogl is not
doing any premult conversions when the internal texture and target
data is the same.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2414
---
 tests/conform/test-cogl-texture-get-set-data.c |   39 ++++++++++++++++++++++--
 1 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/tests/conform/test-cogl-texture-get-set-data.c b/tests/conform/test-cogl-texture-get-set-data.c
index 84206ff..26ba058 100644
--- a/tests/conform/test-cogl-texture-get-set-data.c
+++ b/tests/conform/test-cogl-texture-get-set-data.c
@@ -18,7 +18,7 @@ check_texture (int width, int height, CoglTextureFlags flags)
         *(p++) = x;
         *(p++) = y;
         *(p++) = 128;
-        *(p++) = 255;
+        *(p++) = (x ^ y);
       }
 
   tex = cogl_texture_new_from_data (width, height,
@@ -38,6 +38,7 @@ check_texture (int width, int height, CoglTextureFlags flags)
           p[0] = ~p[0];
           p[1] = ~p[1];
           p[2] = ~p[2];
+          p[3] = ~p[3];
           p += 4;
         }
       p += width * 2;
@@ -55,14 +56,16 @@ check_texture (int width, int height, CoglTextureFlags flags)
                            width * 4, /* rowstride */
                            data);
 
-  memset (data, 0, width * height * 4);
-
   /* Check passing a NULL pointer and a zero rowstride. The texture
      should calculate the needed data size and return it */
   g_assert_cmpint (cogl_texture_get_data (tex, COGL_PIXEL_FORMAT_ANY, 0, NULL),
                    ==,
                    width * height * 4);
 
+  /* Try first receiving the data as RGB. This should cause a
+   * conversion */
+  memset (data, 0, width * height * 4);
+
   cogl_texture_get_data (tex, COGL_PIXEL_FORMAT_RGB_888,
                          width * 3, data);
 
@@ -86,6 +89,36 @@ check_texture (int width, int height, CoglTextureFlags flags)
         p += 3;
       }
 
+  /* Now try receiving the data as RGBA. This should not cause a
+   * conversion and no unpremultiplication because we explicitly set
+   * the internal format when we created the texture */
+  memset (data, 0, width * height * 4);
+
+  cogl_texture_get_data (tex, COGL_PIXEL_FORMAT_RGBA_8888,
+                         width * 4, data);
+
+  p = data;
+
+  for (y = 0; y < height; y++)
+    for (x = 0; x < width; x++)
+      {
+        if (x >= width / 2 && y >= height / 2)
+          {
+            g_assert_cmpint (p[0], ==, ~x & 0xff);
+            g_assert_cmpint (p[1], ==, ~y & 0xff);
+            g_assert_cmpint (p[2], ==, ~128 & 0xff);
+            g_assert_cmpint (p[3], ==, ~(x ^ y) & 0xff);
+          }
+        else
+          {
+            g_assert_cmpint (p[0], ==, x & 0xff);
+            g_assert_cmpint (p[1], ==, y & 0xff);
+            g_assert_cmpint (p[2], ==, 128);
+            g_assert_cmpint (p[3], ==, (x ^ y) & 0xff);
+          }
+        p += 4;
+      }
+
   cogl_handle_unref (tex);
   g_free (data);
 }
-- 
1.7.3.16.g9464b