[Piglit] [PATCH 1/2] Add utility functions to convert a color value to srgb or linear color space
Anuj Phogat
anuj.phogat at gmail.com
Tue Aug 20 16:04:04 PDT 2013
Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
---
tests/util/piglit-util-gl-common.h | 2 ++
tests/util/piglit-util-gl.c | 28 ++++++++++++++++++++++++++++
2 files changed, 30 insertions(+)
diff --git a/tests/util/piglit-util-gl-common.h b/tests/util/piglit-util-gl-common.h
index e2df89d..0078041 100644
--- a/tests/util/piglit-util-gl-common.h
+++ b/tests/util/piglit-util-gl-common.h
@@ -208,6 +208,8 @@ piglit_visualize_image(float *img, GLenum base_internal_format,
int image_width, int image_height,
int image_count, bool rhs);
+float piglit_srgb_to_linear(float x);
+float piglit_linear_to_srgb(float x);
extern GLfloat cube_face_texcoords[6][4][3];
extern const char *cube_face_names[6];
diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c
index 7805498..3dbeec8 100644
--- a/tests/util/piglit-util-gl.c
+++ b/tests/util/piglit-util-gl.c
@@ -1507,3 +1507,31 @@ piglit_visualize_image(float *img, GLenum base_internal_format,
visualization);
free(visualization);
}
+
+/**
+ * Convert from sRGB color space to linear color space, using the
+ * formula from the GL 3.0 spec, section 4.1.8 (sRGB Texture Color
+ * Conversion).
+ */
+float
+piglit_srgb_to_linear(float x)
+{
+ if (x <= 0.0405)
+ return x / 12.92;
+ else
+ return pow((x + 0.055) / 1.055, 2.4);
+}
+
+/* Convert from linear color space to sRGB color space. */
+float
+piglit_linear_to_srgb(float x)
+{
+ if (x < 0.0f)
+ return 0.0f;
+ else if (x < 0.0031308f)
+ return 12.92f * x;
+ else if (x < 1.0f)
+ return 1.055f * powf(x, 0.41666f) - 0.055f;
+ else
+ return 1.0f;
+}
--
1.8.1.4
More information about the Piglit
mailing list