diff options
author | Eric Engestrom <[email protected]> | 2019-11-07 17:33:19 +0000 |
---|---|---|
committer | Eric Engestrom <[email protected]> | 2019-12-27 21:04:43 +0000 |
commit | da9937d09b2f3dc883ae8ad315ae9e5bfdecb1fd (patch) | |
tree | c615179dc63a69e4bd84da45ef37639124857d9d /src | |
parent | 8f4d4c808b6ed0b15b7a0cb0154a4cc3e8e7d907 (diff) |
util/format: add trivial srgb<->linear conversion test
This would've caught 8829f9ccb0267d113283 ("u_format: add ETC2 to
util_format_srgb/util_format_linear").
Suggested-by: Eric Anholt <[email protected]>
Signed-off-by: Eric Engestrom <[email protected]>
Reviewed-by: Eric Anholt <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/util/meson.build | 1 | ||||
-rw-r--r-- | src/util/tests/format/meson.build | 12 | ||||
-rw-r--r-- | src/util/tests/format/srgb.c | 40 |
3 files changed, 53 insertions, 0 deletions
diff --git a/src/util/meson.build b/src/util/meson.build index 88c6ab2d2a8..3d9cb1bc7bd 100644 --- a/src/util/meson.build +++ b/src/util/meson.build @@ -287,4 +287,5 @@ if with_tests subdir('tests/vma') subdir('tests/set') subdir('tests/sparse_array') + subdir('tests/format') endif diff --git a/src/util/tests/format/meson.build b/src/util/tests/format/meson.build new file mode 100644 index 00000000000..663bf691d1f --- /dev/null +++ b/src/util/tests/format/meson.build @@ -0,0 +1,12 @@ +foreach t : ['srgb'] + test(t, + executable( + t, + '@[email protected]'.format(t), + include_directories : inc_common, + dependencies : idep_mesautil, + ), + suite : 'format', + should_fail : meson.get_cross_property('xfail', '').contains(t), + ) +endforeach diff --git a/src/util/tests/format/srgb.c b/src/util/tests/format/srgb.c new file mode 100644 index 00000000000..9b3c15e65ce --- /dev/null +++ b/src/util/tests/format/srgb.c @@ -0,0 +1,40 @@ +#include <stdio.h> +#include <stdlib.h> + +#include "util/macros.h" +#include "util/format/u_format.h" +#include "pipe/p_format.h" + +int main(void) +{ + for (enum pipe_format format = 0; format < PIPE_FORMAT_COUNT; format++) + { + if (!util_format_is_srgb(format)) { + const enum pipe_format linear = util_format_linear(format); + if (format != linear) { + fprintf(stderr, "%s converted to linear is %s\n", + util_format_name(format), + util_format_name(linear)); + return EXIT_FAILURE; + } + continue; + } + + const enum pipe_format linear = util_format_linear(format); + if (format == linear) { + fprintf(stderr, "%s can't be converted to a linear equivalent\n", + util_format_name(format)); + return EXIT_FAILURE; + } + + const enum pipe_format srgb = util_format_srgb(linear); + if (format != srgb) { + fprintf(stderr, "%s converted to linear and back to srgb becomes %s\n", + util_format_name(format), + util_format_name(srgb)); + return EXIT_FAILURE; + } + } + + return EXIT_SUCCESS; +} |