[Piglit] [PATCH 01/16] util: Make a separate function to compare in-memory images.

Anuj Phogat anuj.phogat at gmail.com
Thu Jun 21 14:41:24 PDT 2012


On Fri, Jun 15, 2012 at 8:32 AM, Paul Berry <stereotype441 at gmail.com> wrote:
> This patch splits off a new piglit-util function,
> piglit_compare_images_color(), from the existing
> piglit_probe_image_color() function.  The new function compares two
> images in memory, so that the caller can take responsibility for
> calling glReadPixels().
>
> In addition, this patch creates a function
> piglit_compute_probe_tolerance(), which detemines the correct
> tolerance thresholds to use when comparing images.
>
> These functions will be needed in order to test proper behaviour of
> MSAA with different buffer formats, since the MSAA format test needs
> to be able to read the rendered image using glReadPixels, make
> adjustments to it in memory, and then compare the results.
> ---
>  tests/util/piglit-util-gl.c |   90 ++++++++++++++++++++++++++++++-------------
>  tests/util/piglit-util.h    |    5 ++
>  2 files changed, 68 insertions(+), 27 deletions(-)
>
> diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c
> index 4b6f3fd..6cdded5 100644
> --- a/tests/util/piglit-util-gl.c
> +++ b/tests/util/piglit-util-gl.c
> @@ -240,21 +240,14 @@ print_pixel(const float *pixel, unsigned components)
>                printf(" %f", pixel[p]);
>  }
>
> -int
> -piglit_probe_image_color(int x, int y, int w, int h, GLenum format,
> -                        const float *image)
> +/**
> + * Compute the appropriate tolerance for comparing images of the given
> + * base format.
> + */
> +void
> +piglit_compute_probe_tolerance(GLenum format, float *tolerance)
>  {
> -       int i, j, p;
> -       int c = piglit_num_components(format);
> -       GLfloat *probe;
> -       GLfloat *pixels = malloc(w*h*c*sizeof(float));
> -       float tolerance[4];
> -       if (format == GL_INTENSITY) {
> -               /* GL_INTENSITY is not allowed for ReadPixels so
> -                * substitute GL_LUMINANCE.
> -                */
> -               format = GL_LUMINANCE;
> -       }
> +       int num_components, component;
>        switch (format) {
>        case GL_LUMINANCE_ALPHA:
>                tolerance[0] = piglit_tolerance[0];
> @@ -264,37 +257,80 @@ piglit_probe_image_color(int x, int y, int w, int h, GLenum format,
>                tolerance[0] = piglit_tolerance[3];
>                break;
>        default:
> -               for (p = 0; p < c; ++p)
> -                       tolerance[p] = piglit_tolerance[p];
> +               num_components = piglit_num_components(format);
> +               for (component = 0; component < num_components; ++component)
> +                       tolerance[component] = piglit_tolerance[component];
> +               break;
>        }
> +}
>
> -       glReadPixels(x, y, w, h, format, GL_FLOAT, pixels);
> -
> +/**
> + * 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 = &image[(j*w+i)*c];
> -                       probe = &pixels[(j*w+i)*c];
> -
> -                       for (p = 0; p < c; ++p) {
> -                               if (fabs(probe[p] - expected[p]) >= tolerance[p]) {
> +                       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, c);
> +                                       print_pixel(expected, num_components);
>                                        printf("\n  Observed:");
> -                                       print_pixel(probe, c);
> +                                       print_pixel(probe, num_components);
>                                        printf("\n");
>
> -                                       free(pixels);
>                                        return 0;
>                                }
>                        }
>                }
>        }
>
> -       free(pixels);
>        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;
> +}
> +
>  int
>  piglit_probe_image_rgb(int x, int y, int w, int h, const float *image)
>  {
> diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
> index 2d89775..8461e53 100755
> --- a/tests/util/piglit-util.h
> +++ b/tests/util/piglit-util.h
> @@ -217,6 +217,11 @@ int piglit_probe_rect_rgb_silent(int x, int y, int w, int h, const float *expect
>  int piglit_probe_rect_rgba(int x, int y, int w, int h, const float* expected);
>  int piglit_probe_rect_rgba_int(int x, int y, int w, int h, const int* expected);
>  int piglit_probe_rect_rgba_uint(int x, int y, int w, int h, const unsigned int* expected);
> +void piglit_compute_probe_tolerance(GLenum format, float *tolerance);
> +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 piglit_probe_image_color(int x, int y, int w, int h, GLenum format, const float *image);
>  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);
> --
> 1.7.7.6
>
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit

Reviewed-by: Anuj Phogat <anuj.phogat at gmail.com>


More information about the Piglit mailing list