diff --git a/tests/conform/test-cogl-texture-get-set-data.c b/tests/conform/test-cogl-texture-get-set-data.c index 84206ff67..26ba05858 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); }