[Piglit] [PATCH] Move visualize_image function to util/piglit-util-gl.c

Anuj Phogat anuj.phogat at gmail.com
Tue Aug 20 15:16:23 PDT 2013


This function might be useful to develop new piglit test cases.

Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
---
 tests/spec/ext_framebuffer_multisample/common.cpp  | 82 ---------------------
 tests/spec/ext_framebuffer_multisample/common.h    |  5 --
 .../draw-buffers-common.cpp                        | 10 +--
 tests/spec/ext_framebuffer_multisample/formats.cpp | 16 ++---
 tests/util/piglit-util-gl-common.h                 |  4 ++
 tests/util/piglit-util-gl.c                        | 84 ++++++++++++++++++++++
 6 files changed, 101 insertions(+), 100 deletions(-)

diff --git a/tests/spec/ext_framebuffer_multisample/common.cpp b/tests/spec/ext_framebuffer_multisample/common.cpp
index 3fc236b..c96a935 100644
--- a/tests/spec/ext_framebuffer_multisample/common.cpp
+++ b/tests/spec/ext_framebuffer_multisample/common.cpp
@@ -629,85 +629,3 @@ create_test(test_type_enum test_type, int n_samples, bool small,
 		   pattern_height, supersample_factor);
 	return test;
 }
-
-/**
- * Convert the image into a format that can be easily understood by
- * visual inspection, and display it on the screen.
- *
- * Luminance and intensity values are converted to a grayscale value.
- * Alpha values are visualized by blending the image with a grayscale
- * checkerboard.
- *
- * Pass image_count = 0 to disable drawing multiple images to window
- * system framebuffer.
- */
-void
-visualize_image(float *img, GLenum base_internal_format,
-		int image_width, int image_height,
-		int image_count, bool rhs)
-{
-	unsigned components = piglit_num_components(base_internal_format);
-	float *visualization =
-		(float *) malloc(sizeof(float)*3*image_width*image_height);
-	for (int y = 0; y < image_height; ++y) {
-		for (int x = 0; x < image_width; ++x) {
-			float r = 0, g = 0, b = 0, a = 1;
-			float *pixel =
-				&img[(y * image_width + x) * components];
-			switch (base_internal_format) {
-			case GL_ALPHA:
-				a = pixel[0];
-				break;
-			case GL_RGBA:
-				a = pixel[3];
-				/* Fall through */
-			case GL_RGB:
-				b = pixel[2];
-				/* Fall through */
-			case GL_RG:
-				g = pixel[1];
-				/* Fall through */
-			case GL_RED:
-				r = pixel[0];
-				break;
-			case GL_LUMINANCE_ALPHA:
-				a = pixel[1];
-				/* Fall through */
-			case GL_INTENSITY:
-			case GL_LUMINANCE:
-				r = pixel[0];
-				g = pixel[0];
-				b = pixel[0];
-				break;
-			}
-			float checker = ((x ^ y) & 0x10) ? 0.75 : 0.25;
-			r = r * a + checker * (1 - a);
-			g = g * a + checker * (1 - a);
-			b = b * a + checker * (1 - a);
-			visualization[(y * image_width + x) * 3] = r;
-			visualization[(y * image_width + x) * 3 + 1] = g;
-			visualization[(y * image_width + x) * 3 + 2] = b;
-		}
-	}
-	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
-	glUseProgram(0);
-
-	/* To simultaneously display multiple images on window system
-	 * framebuffer.
-	 */
-	if(image_count) {
-		/* Use glWindowPos to directly update x, y coordinates of
-		 * current raster position without getting transformed by
-		 * modelview projection matrix and viewport-to-window
-		 * transform.
-		 */
-		glWindowPos2f(rhs ? image_width : 0,
-			      (image_count - 1) * image_height);
-	}
-	else {
-		glRasterPos2f(rhs ? 0 : -1, -1);
-	}
-	glDrawPixels(image_width, image_height, GL_RGB, GL_FLOAT,
-		     visualization);
-	free(visualization);
-}
diff --git a/tests/spec/ext_framebuffer_multisample/common.h b/tests/spec/ext_framebuffer_multisample/common.h
index 5b9f8a0..7e26a45 100644
--- a/tests/spec/ext_framebuffer_multisample/common.h
+++ b/tests/spec/ext_framebuffer_multisample/common.h
@@ -179,8 +179,3 @@ Test *
 create_test(test_type_enum test_type, int n_samples, bool small,
 	    bool combine_depth_stencil, int pattern_width,
 	    int pattern_height, int supersample_factor);
-
-void
-visualize_image(float *img, GLenum base_internal_format,
-		int image_width, int image_height,
-		int draw_buffer_count, bool rhs);
diff --git a/tests/spec/ext_framebuffer_multisample/draw-buffers-common.cpp b/tests/spec/ext_framebuffer_multisample/draw-buffers-common.cpp
index ef1fa3f..6d8634b 100644
--- a/tests/spec/ext_framebuffer_multisample/draw-buffers-common.cpp
+++ b/tests/spec/ext_framebuffer_multisample/draw-buffers-common.cpp
@@ -722,15 +722,15 @@ draw_image_to_window_system_fb(int draw_buffer_count, bool rhs)
 	}
 
 	/* Rendering using gldrawPixels() with dual source blending enabled
-	 * produces undefined results. So, disable blending in visualize_image
-	 * function to avoid undefined behavior.
+	 * produces undefined results. So, disable blending in
+	 * piglit_visualize_image function to avoid undefined behavior.
 	 */
 	GLboolean isBlending;
         glGetBooleanv(GL_BLEND, &isBlending);
 	glDisable(GL_BLEND);
-	visualize_image(image, GL_RGBA,
-			pattern_width, pattern_height,
-			draw_buffer_count + 1, rhs);
+	piglit_visualize_image(image, GL_RGBA,
+			       pattern_width, pattern_height,
+			       draw_buffer_count + 1, rhs);
 	if(isBlending)
 		glEnable(GL_BLEND);
 	free(image);
diff --git a/tests/spec/ext_framebuffer_multisample/formats.cpp b/tests/spec/ext_framebuffer_multisample/formats.cpp
index 9e251ac..3694302 100644
--- a/tests/spec/ext_framebuffer_multisample/formats.cpp
+++ b/tests/spec/ext_framebuffer_multisample/formats.cpp
@@ -538,14 +538,14 @@ test_format(const struct format_desc *format)
 	 * display image without any offset applied to raster position.
 	 */
 	glViewport(0, 0, piglit_width, piglit_height);
-	visualize_image(test_image, format->base_internal_format,
-			pattern_width, pattern_height,
-			0 /* image_count */,
-			false /* rhs */);
-	visualize_image(expected_image, format->base_internal_format,
-			pattern_width, pattern_height,
-			0 /* image_count */,
-			true /* rhs */);
+	piglit_visualize_image(test_image, format->base_internal_format,
+			       pattern_width, pattern_height,
+			       0 /* image_count */,
+			       false /* rhs */);
+	piglit_visualize_image(expected_image, format->base_internal_format,
+			       pattern_width, pattern_height,
+			       0 /* image_count */,
+			       true /* rhs */);
 
 	/* Finally, if any error occurred, count that as a failure. */
 	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
diff --git a/tests/util/piglit-util-gl-common.h b/tests/util/piglit-util-gl-common.h
index 41f110a..e2df89d 100644
--- a/tests/util/piglit-util-gl-common.h
+++ b/tests/util/piglit-util-gl-common.h
@@ -203,6 +203,10 @@ unsigned
 piglit_compressed_pixel_offset(GLenum format, unsigned width,
 			       unsigned x, unsigned y);
 
+void
+piglit_visualize_image(float *img, GLenum base_internal_format,
+		       int image_width, int image_height,
+		       int image_count, bool rhs);
 
 
 extern GLfloat cube_face_texcoords[6][4][3];
diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c
index 98d7a80..7805498 100644
--- a/tests/util/piglit-util-gl.c
+++ b/tests/util/piglit-util-gl.c
@@ -1423,3 +1423,87 @@ piglit_require_transform_feedback(void)
 		piglit_report_result(PIGLIT_SKIP);
 	}
 }
+
+/**
+ * Convert the image into a format that can be easily understood by
+ * visual inspection, and display it on the screen.
+ *
+ * Luminance and intensity values are converted to a grayscale value.
+ * Alpha values are visualized by blending the image with a grayscale
+ * checkerboard.
+ *
+ * Pass image_count = 0 to disable drawing multiple images to window
+ * system framebuffer.
+ */
+void
+piglit_visualize_image(float *img, GLenum base_internal_format,
+		       int image_width, int image_height,
+		       int image_count, bool rhs)
+{
+	int x, y;
+	float checker;
+	unsigned components = piglit_num_components(base_internal_format);
+	float *visualization =
+		(float *) malloc(sizeof(float)*3*image_width*image_height);
+	for (y = 0; y < image_height; ++y) {
+		for ( x = 0; x < image_width; ++x) {
+			float r = 0, g = 0, b = 0, a = 1;
+			float *pixel =
+				&img[(y * image_width + x) * components];
+			switch (base_internal_format) {
+			case GL_ALPHA:
+				a = pixel[0];
+				break;
+			case GL_RGBA:
+				a = pixel[3];
+				/* Fall through */
+			case GL_RGB:
+				b = pixel[2];
+				/* Fall through */
+			case GL_RG:
+				g = pixel[1];
+				/* Fall through */
+			case GL_RED:
+				r = pixel[0];
+				break;
+			case GL_LUMINANCE_ALPHA:
+				a = pixel[1];
+				/* Fall through */
+			case GL_INTENSITY:
+			case GL_LUMINANCE:
+				r = pixel[0];
+				g = pixel[0];
+				b = pixel[0];
+				break;
+			}
+			checker = ((x ^ y) & 0x10) ? 0.75 : 0.25;
+			r = r * a + checker * (1 - a);
+			g = g * a + checker * (1 - a);
+			b = b * a + checker * (1 - a);
+			visualization[(y * image_width + x) * 3] = r;
+			visualization[(y * image_width + x) * 3 + 1] = g;
+			visualization[(y * image_width + x) * 3 + 2] = b;
+		}
+	}
+	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
+	glUseProgram(0);
+
+	/* To simultaneously display multiple images on window system
+	 * framebuffer.
+	 */
+	if(image_count) {
+		/* Use glWindowPos to directly update x, y coordinates of
+		 * current raster position without getting transformed by
+		 * modelview projection matrix and viewport-to-window
+		 * transform.
+		 */
+		glWindowPos2f(rhs ? image_width : 0,
+			      (image_count - 1) * image_height);
+	}
+	else {
+		glRasterPos2f(rhs ? 0 : -1, -1);
+	}
+	glDrawPixels(image_width, image_height, GL_RGB, GL_FLOAT,
+		     visualization);
+	free(visualization);
+}
-- 
1.8.1.4



More information about the Piglit mailing list