diff options
author | Marek Olšák <maraeo@gmail.com> | 2011-03-11 04:26:14 +0100 |
---|---|---|
committer | Marek Olšák <maraeo@gmail.com> | 2011-03-11 04:26:14 +0100 |
commit | 2feecc80a00a378f3bc695752c4024058a8c0032 (patch) | |
tree | 560bb20de97581af0bd4374d9e4c54175eac3823 | |
parent | 119a037d827352d1741aa0bf87ba2e080dbee615 (diff) |
util: add piglit_probe_image_rgb* functions
-rw-r--r-- | tests/util/piglit-util-gl.c | 66 | ||||
-rw-r--r-- | tests/util/piglit-util.h | 2 |
2 files changed, 68 insertions, 0 deletions
diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c index 0aa8c4435..ed849ab72 100644 --- a/tests/util/piglit-util-gl.c +++ b/tests/util/piglit-util-gl.c @@ -138,6 +138,72 @@ piglit_probe_rect_rgba(int x, int y, int w, int h, const float *expected) return 1; } +int +piglit_probe_image_rgb(int x, int y, int w, int h, const float *image) +{ + int i, j, p; + GLfloat *probe; + GLfloat *pixels = malloc(w*h*3*sizeof(float)); + + glReadPixels(x, y, w, h, GL_RGB, GL_FLOAT, pixels); + + for (j = 0; j < h; j++) { + for (i = 0; i < w; i++) { + const float *expected = &image[(j*w+i)*3]; + probe = &pixels[(j*w+i)*3]; + + for (p = 0; p < 3; ++p) { + if (fabs(probe[p] - expected[p]) >= tolerance[p]) { + printf("Probe at (%i,%i)\n", x+i, y+j); + printf(" Expected: %f %f %f\n", + expected[0], expected[1], expected[2]); + printf(" Observed: %f %f %f\n", + probe[0], probe[1], probe[2]); + + free(pixels); + return 0; + } + } + } + } + + free(pixels); + return 1; +} + +int +piglit_probe_image_rgba(int x, int y, int w, int h, const float *image) +{ + int i, j, p; + GLfloat *probe; + GLfloat *pixels = malloc(w*h*4*sizeof(float)); + + glReadPixels(x, y, w, h, GL_RGBA, GL_FLOAT, pixels); + + for (j = 0; j < h; j++) { + for (i = 0; i < w; i++) { + const float *expected = &image[(j*w+i)*4]; + probe = &pixels[(j*w+i)*4]; + + for (p = 0; p < 4; ++p) { + if (fabs(probe[p] - expected[p]) >= tolerance[p]) { + printf("Probe at (%i,%i)\n", x+i, y+j); + printf(" Expected: %f %f %f %f\n", + expected[0], expected[1], expected[2], expected[3]); + printf(" Observed: %f %f %f %f\n", + probe[0], probe[1], probe[2], probe[3]); + + free(pixels); + return 0; + } + } + } + } + + free(pixels); + return 1; +} + /** * Read a pixel from the given location and compare its RGB value to the * given expected values. diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h index ee13afedb..c8938c967 100644 --- a/tests/util/piglit-util.h +++ b/tests/util/piglit-util.h @@ -103,6 +103,8 @@ int piglit_probe_pixel_rgb(int x, int y, const float* expected); int piglit_probe_pixel_rgba(int x, int y, const float* expected); int piglit_probe_rect_rgb(int x, int y, int w, int h, const float* expected); int piglit_probe_rect_rgba(int x, int y, int w, int h, const float* expected); +int piglit_probe_image_rgb(int x, int y, int w, int h, const float *image); +int piglit_probe_image_rgba(int x, int y, int w, int h, const float *image); int piglit_probe_texel_rgb(int target, int level, int x, int y, const float* expected); int piglit_probe_texel_rgba(int target, int level, int x, int y, |