Signed-off-by: Josh Triplett <j...@joshtriplett.org> --- tests/util/piglit-util-gl-common.c | 210 +++++++++++++++++++++++++++++++++++++ tests/util/piglit-util-gl.c | 166 ----------------------------- tests/util/piglit-util-gles.c | 44 -------- 3 files changed, 210 insertions(+), 210 deletions(-)
diff --git a/tests/util/piglit-util-gl-common.c b/tests/util/piglit-util-gl-common.c index 6764d96..9f778c5 100644 --- a/tests/util/piglit-util-gl-common.c +++ b/tests/util/piglit-util-gl-common.c @@ -1273,3 +1273,213 @@ piglit_probe_rect_rgba_uint(int x, int y, int w, int h, free(pixels); return 1; } + +static void +print_pixel_ubyte(const GLubyte *pixel, unsigned components) +{ + int p; + for (p = 0; p < components; ++p) + printf(" %u", pixel[p]); +} + +static void +print_pixel_float(const float *pixel, unsigned components) +{ + int p; + for (p = 0; p < components; ++p) + printf(" %f", pixel[p]); +} + +/** + * Compute the appropriate tolerance for comparing images of the given + * base format. + */ +void +piglit_compute_probe_tolerance(GLenum format, float *tolerance) +{ + int num_components, component; + switch (format) { + case GL_LUMINANCE_ALPHA: + tolerance[0] = piglit_tolerance[0]; + tolerance[1] = piglit_tolerance[3]; + break; + case GL_ALPHA: + tolerance[0] = piglit_tolerance[3]; + break; + default: + num_components = piglit_num_components(format); + for (component = 0; component < num_components; ++component) + tolerance[component] = piglit_tolerance[component]; + break; + } +} + +/** + * Compare two in-memory floating-point images. + */ +int +piglit_compare_images_color(int x, int y, int w, int h, int num_components, + const float *tolerance, + const float *expected_image, + const float *observed_image) +{ + int i, j, p; + for (j = 0; j < h; j++) { + for (i = 0; i < w; i++) { + const float *expected = + &expected_image[(j*w+i)*num_components]; + const float *probe = + &observed_image[(j*w+i)*num_components]; + + for (p = 0; p < num_components; ++p) { + if (fabs(probe[p] - expected[p]) + >= tolerance[p]) { + printf("Probe at (%i,%i)\n", x+i, y+j); + printf(" Expected:"); + print_pixel_float(expected, num_components); + printf("\n Observed:"); + print_pixel_float(probe, num_components); + printf("\n"); + + return 0; + } + } + } + } + + return 1; +} + +/** + * Compare the contents of the current read framebuffer with the given + * in-memory floating-point image. + */ +int +piglit_probe_image_color(int x, int y, int w, int h, GLenum format, + const float *image) +{ + int c = piglit_num_components(format); + GLfloat *pixels; + float tolerance[4]; + int result; + + piglit_compute_probe_tolerance(format, tolerance); + + if (format == GL_INTENSITY) { + /* GL_INTENSITY is not allowed for ReadPixels so + * substitute GL_LUMINANCE. + */ + format = GL_LUMINANCE; + } + + pixels = piglit_read_pixels_float(x, y, w, h, format, NULL); + + result = piglit_compare_images_color(x, y, w, h, c, tolerance, image, + pixels); + + free(pixels); + return result; +} + +int +piglit_probe_image_rgb(int x, int y, int w, int h, const float *image) +{ + return piglit_probe_image_color(x, y, w, h, GL_RGB, image); +} + +int +piglit_probe_image_rgba(int x, int y, int w, int h, const float *image) +{ + return piglit_probe_image_color(x, y, w, h, GL_RGBA, image); +} + +/** + * Compare two in-memory unsigned-byte images. + */ +int +piglit_compare_images_ubyte(int x, int y, int w, int h, + const GLubyte *expected_image, + const GLubyte *observed_image) +{ + int i, j; + for (j = 0; j < h; j++) { + for (i = 0; i < w; i++) { + const GLubyte expected = expected_image[j*w+i]; + const GLubyte probe = observed_image[j*w+i]; + + if (probe != expected) { + printf("Probe at (%i,%i)\n", x+i, y+j); + printf(" Expected: %d\n", expected); + printf(" Observed: %d\n", probe); + + return 0; + } + } + } + + return 1; +} + +/** + * Compare the contents of the current read framebuffer's stencil + * buffer with the given in-memory byte image. + */ +int +piglit_probe_image_stencil(int x, int y, int w, int h, + const GLubyte *image) +{ + GLubyte *pixels = malloc(w*h*sizeof(GLubyte)); + int result; + GLint old_pack_alignment; + + /* Temporarily set pack alignment to 1 so that glReadPixels + * won't put any padding at the end of the row. + */ + glGetIntegerv(GL_PACK_ALIGNMENT, &old_pack_alignment); + glPixelStorei(GL_PACK_ALIGNMENT, 1); + + glReadPixels(x, y, w, h, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, pixels); + + glPixelStorei(GL_PACK_ALIGNMENT, old_pack_alignment); + + result = piglit_compare_images_ubyte(x, y, w, h, image, pixels); + + free(pixels); + return result; +} + +int +piglit_probe_image_ubyte(int x, int y, int w, int h, GLenum format, + const GLubyte *image) +{ + const int c = piglit_num_components(format); + GLubyte *pixels = malloc(w * h * 4 * sizeof(GLubyte)); + int i, j, p; + + glReadPixels(x, y, w, h, format, GL_UNSIGNED_BYTE, pixels); + + for (j = 0; j < h; j++) { + for (i = 0; i < w; i++) { + const GLubyte *expected = &image[(j * w + i) * c]; + const GLubyte *probe = &pixels[(j * w + i) * c]; + + for (p = 0; p < c; ++p) { + if (probe[p] == expected[p]) + continue; + + printf("Probe at (%i,%i)\n", x + i, y + j); + printf(" Expected:"); + print_pixel_ubyte(expected, c); + printf("\n Observed:"); + print_pixel_ubyte(probe, c); + printf("\n"); + + free(pixels); + return 0; + } + } + } + + free(pixels); + return 1; +} diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c index 4c019da..7c3414c 100644 --- a/tests/util/piglit-util-gl.c +++ b/tests/util/piglit-util-gl.c @@ -38,172 +38,6 @@ GLint piglit_ARBfp_pass_through = 0; -static void -print_pixel(const float *pixel, unsigned components) -{ - int p; - for (p = 0; p < components; ++p) - printf(" %f", pixel[p]); -} - -/** - * Compute the appropriate tolerance for comparing images of the given - * base format. - */ -void -piglit_compute_probe_tolerance(GLenum format, float *tolerance) -{ - int num_components, component; - switch (format) { - case GL_LUMINANCE_ALPHA: - tolerance[0] = piglit_tolerance[0]; - tolerance[1] = piglit_tolerance[3]; - break; - case GL_ALPHA: - tolerance[0] = piglit_tolerance[3]; - break; - default: - num_components = piglit_num_components(format); - for (component = 0; component < num_components; ++component) - tolerance[component] = piglit_tolerance[component]; - break; - } -} - -/** - * Compare two in-memory floating-point images. - */ -int -piglit_compare_images_color(int x, int y, int w, int h, int num_components, - const float *tolerance, - const float *expected_image, - const float *observed_image) -{ - int i, j, p; - for (j = 0; j < h; j++) { - for (i = 0; i < w; i++) { - const float *expected = - &expected_image[(j*w+i)*num_components]; - const float *probe = - &observed_image[(j*w+i)*num_components]; - - for (p = 0; p < num_components; ++p) { - if (fabs(probe[p] - expected[p]) - >= tolerance[p]) { - printf("Probe at (%i,%i)\n", x+i, y+j); - printf(" Expected:"); - print_pixel(expected, num_components); - printf("\n Observed:"); - print_pixel(probe, num_components); - printf("\n"); - - return 0; - } - } - } - } - - return 1; -} - -/** - * Compare two in-memory unsigned-byte images. - */ -int -piglit_compare_images_ubyte(int x, int y, int w, int h, - const GLubyte *expected_image, - const GLubyte *observed_image) -{ - int i, j; - for (j = 0; j < h; j++) { - for (i = 0; i < w; i++) { - const GLubyte expected = expected_image[j*w+i]; - const GLubyte probe = observed_image[j*w+i]; - - if (probe != expected) { - printf("Probe at (%i,%i)\n", x+i, y+j); - printf(" Expected: %d\n", expected); - printf(" Observed: %d\n", probe); - - return 0; - } - } - } - - return 1; -} - -/** - * Compare the contents of the current read framebuffer with the given - * in-memory floating-point image. - */ -int -piglit_probe_image_color(int x, int y, int w, int h, GLenum format, - const float *image) -{ - int c = piglit_num_components(format); - GLfloat *pixels = malloc(w*h*c*sizeof(float)); - float tolerance[4]; - int result; - - piglit_compute_probe_tolerance(format, tolerance); - - if (format == GL_INTENSITY) { - /* GL_INTENSITY is not allowed for ReadPixels so - * substitute GL_LUMINANCE. - */ - format = GL_LUMINANCE; - } - - glReadPixels(x, y, w, h, format, GL_FLOAT, pixels); - - result = piglit_compare_images_color(x, y, w, h, c, tolerance, image, - pixels); - - free(pixels); - return result; -} - -/** - * Compare the contents of the current read framebuffer's stencil - * buffer with the given in-memory byte image. - */ -int -piglit_probe_image_stencil(int x, int y, int w, int h, - const GLubyte *image) -{ - GLubyte *pixels = malloc(w*h*sizeof(GLubyte)); - int result; - GLint old_pack_alignment; - - /* Temporarily set pack alignment to 1 so that glReadPixels - * won't put any padding at the end of the row. - */ - glGetIntegerv(GL_PACK_ALIGNMENT, &old_pack_alignment); - glPixelStorei(GL_PACK_ALIGNMENT, 1); - - glReadPixels(x, y, w, h, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, pixels); - - glPixelStorei(GL_PACK_ALIGNMENT, old_pack_alignment); - - result = piglit_compare_images_ubyte(x, y, w, h, image, pixels); - - free(pixels); - return result; -} - -int -piglit_probe_image_rgb(int x, int y, int w, int h, const float *image) -{ - return piglit_probe_image_color(x, y, w, h, GL_RGB, image); -} - -int -piglit_probe_image_rgba(int x, int y, int w, int h, const float *image) -{ - return piglit_probe_image_color(x, y, w, h, GL_RGBA, image); -} - /** * Read a pixel from the given location and compare its depth value to the * given expected value. diff --git a/tests/util/piglit-util-gles.c b/tests/util/piglit-util-gles.c index e1cdae5..7eef8e2 100644 --- a/tests/util/piglit-util-gles.c +++ b/tests/util/piglit-util-gles.c @@ -35,50 +35,6 @@ #include "piglit-util-gl-common.h" -static void -print_pixel(const GLubyte *pixel, unsigned components) -{ - int p; - for (p = 0; p < components; ++p) - printf(" %u", pixel[p]); -} - -int -piglit_probe_image_ubyte(int x, int y, int w, int h, GLenum format, - const GLubyte *image) -{ - const int c = piglit_num_components(format); - GLubyte *pixels = malloc(w * h * 4 * sizeof(GLubyte)); - int i, j, p; - - glReadPixels(x, y, w, h, format, GL_UNSIGNED_BYTE, pixels); - - for (j = 0; j < h; j++) { - for (i = 0; i < w; i++) { - const GLubyte *expected = &image[(j * w + i) * c]; - const GLubyte *probe = &pixels[(j * w + i) * c]; - - for (p = 0; p < c; ++p) { - if (probe[p] == expected[p]) - continue; - - printf("Probe at (%i,%i)\n", x + i, y + j); - printf(" Expected:"); - print_pixel(expected, c); - printf("\n Observed:"); - print_pixel(probe, c); - printf("\n"); - - free(pixels); - return 0; - } - } - } - - free(pixels); - return 1; -} - void piglit_escape_exit_key(unsigned char key, int x, int y) { -- 2.0.1 _______________________________________________ Piglit mailing list Piglit@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/piglit