This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, master has been updated via f7cb41744ef49b26625e2c6c9e7deb64a6ba0018 (commit) via 9962b69ac47d514051afb83b0942655ff9e76991 (commit) from e596ea9912cfde653e3048e64d3a821328975f14 (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/f7cb41744ef49b26625e2c6c9e7deb64a6ba0...
commit f7cb41744ef49b26625e2c6c9e7deb64a6ba0018 Author: Cyril Hrubis metan@ucw.cz Date: Sun May 19 16:23:13 2013 +0200
tests: core: Add test for Convert_Scale operations
There are few failures that are caused by slightly incorrect rounding on upsampling but these are not fatal.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/tests/core/Convert_Scale.gen.c.t b/tests/core/Convert_Scale.gen.c.t new file mode 100644 index 0000000..a3ce1b5 --- /dev/null +++ b/tests/core/Convert_Scale.gen.c.t @@ -0,0 +1,103 @@ +/***************************************************************************** + * This file is part of gfxprim library. * + * * + * Gfxprim is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * Gfxprim is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with gfxprim; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, * + * Boston, MA 02110-1301 USA * + * * + * Copyright (C) 2009-2013 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + +%% extends "base.test.c.t" + +%% block body + +#include <stdio.h> +#include <math.h> + +#include <core/GP_Convert_Scale.gen.h> + +#include "tst_test.h" + +%% set max = 16 + +%% for i in range(1, max) +%% for j in range(1, max) +static int check_convert_{{ i }}_{{ j }}(void) +{ + unsigned int v, res, exp_res, fail = 0; + float fres; + + for (v = 0; v < {{ 2 ** i - 1 }}; v++) { + res = GP_SCALE_VAL_{{ i }}_{{ j }}(v); +%% if j > i + /* + * We have {{ 2**i }} values and we need to map them to + * subset of {{ 2**j }} values while making sure 0 -> 0 + * and {{ 2**i - 1 }} -> {{ 2**j - 1 }} and that the + * mapping is as evenly distributed as possible. + * + * So we map the input to 0-1 interval by dividing it by + * maximal input value {{ 2**i - 1 }} and then multiply + * it by output maximal value {{ 2**j - 1}}. + */ + fres = (v / {{ (2.00 ** i - 1) }}) * {{ (2.00 ** j - 1) }}; + exp_res = round(fres); +%% else + /* + * We have {{ 2**i }} values that must be mapped to {{ 2**j }} + * so we do simple division and floor() which maps the values + * evenly, 0 -> 0 and {{ 2**i - 1 }} -> {{ 2**j - 1 }}. + * + * In terms for implementation this is just bitshift. + */ + fres = v * {{ (2.00 ** j) / (2.00 ** i) }}; + exp_res = floor(fres); +%% endif + + if (res != exp_res) { + if (fail < 5) + tst_msg("GP_SCALE_{{ i }}_{{ j }}(%i) = %i, " + "expected %i %f", v, res, exp_res, fres); + fail++; + } + } + + if (fail) { + if (fail > 5) + tst_msg("+ next %u failures", fail - 5); + return TST_FAILED; + } + + return TST_SUCCESS; +} + +%% endfor +%% endfor + +const struct tst_suite tst_suite = { + .suite_name = "Pixel Conversions Testsuite", + .tests = { +%% for i in range(1, max) +%% for j in range(1, max) + {.name = "SCALE_{{ i }}_{{ j }}()", + .tst_fn = check_convert_{{ i }}_{{ j }}}, +%% endfor +%% endfor + {.name = NULL} + } +}; + +%% endblock body diff --git a/tests/core/Makefile b/tests/core/Makefile index 2c0d363..c770fc5 100644 --- a/tests/core/Makefile +++ b/tests/core/Makefile @@ -4,9 +4,11 @@ include $(TOPDIR)/pre.mk
CSOURCES=Context.c Pixel.c
-GENSOURCES+=WritePixel.gen.c GetPutPixel.gen.c Convert.gen.c BlitConv.gen.c +GENSOURCES+=WritePixel.gen.c GetPutPixel.gen.c Convert.gen.c BlitConv.gen.c + Convert_Scale.gen.c
-APPS=WritePixel.gen Pixel Context GetPutPixel.gen Convert.gen BlitConv.gen +APPS=WritePixel.gen Pixel Context GetPutPixel.gen Convert.gen BlitConv.gen + Convert_Scale.gen
include ../tests.mk
diff --git a/tests/core/test_list.txt b/tests/core/test_list.txt index 45702bb..3edab32 100644 --- a/tests/core/test_list.txt +++ b/tests/core/test_list.txt @@ -4,4 +4,5 @@ Context Pixel GetPutPixel.gen Convert.gen +Convert_Scale.gen BlitConv.gen
http://repo.or.cz/w/gfxprim.git/commit/9962b69ac47d514051afb83b0942655ff9e76...
commit 9962b69ac47d514051afb83b0942655ff9e76991 Author: Cyril Hrubis metan@ucw.cz Date: Sat May 18 12:50:15 2013 +0200
tests: core: Convert.gen.c: Add more cases.
Some of them fail, I'm not yet sure if these are wrong tests of rounding errors in the implementation.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/tests/core/Convert.gen.c.t b/tests/core/Convert.gen.c.t index 84159f1..57bc4d2 100644 --- a/tests/core/Convert.gen.c.t +++ b/tests/core/Convert.gen.c.t @@ -102,6 +102,58 @@ static GP_Pixel get_white(GP_PixelType pixel_type) }
/* + * Returns 50% gray color for particular pixel type. + */ +static GP_Pixel get_gray(GP_PixelType pixel_type) +{ + switch (pixel_type) { +%% for pt in pixeltypes + case {{ pt.C_enum }}: +%% if pt.is_cmyk() +%% set K = pt.chans['K'] + /* Gray in CMYK modifies K */ + return {{ hex(round(K.max / 2.00)) }}{{ K.C_shift }}; +%% elif pt.is_rgb() +%% set R = pt.chans['R'] +%% set G = pt.chans['G'] +%% set B = pt.chans['B'] +%% if pt.is_alpha() +%% set A = pt.chans['A'] + /* Gray in RGBA */ + return {{ A.C_mask }} | + ({{ hex(round(R.max / 2.00)) }}{{ R.C_shift }}) | + ({{ hex(round(G.max / 2.00)) }}{{ G.C_shift }}) | + ({{ hex(round(B.max / 2.00)) }}{{ B.C_shift }}); +%% else + /* Gray Plain old RGB */ + return ({{ hex(round(R.max / 2.00)) }}{{ R.C_shift }}) | + ({{ hex(round(G.max / 2.00)) }}{{ G.C_shift }}) | + ({{ hex(round(B.max / 2.00)) }}{{ B.C_shift }}); +%% endif +%% elif pt.is_gray() +%% set V = pt.chans['V'] +%% if pt.is_alpha() +%% set A = pt.chans['A'] + /* Gray in Grayscale with Alpha */ + return {{ A.C_mask }} | + ({{ hex(round(V.max / 2.00)) }}{{ V.C_shift }}); +%% else + /* Grayscale */ + return {{ hex(round(V.max / 2.00)) }}{{ V.C_shift }}; +%% endif +%% else + tst_msg("FIXME: Unsupported conversion to %s", + GP_PixelTypeName(pixel_type)); + exit(TST_INTERR); +%% endif +%% endfor + default: + tst_msg("Invalid pixel type %i", pixel_type); + exit(TST_INTERR); + } +} + +/* * Returns red color for particular pixel type. */ static GP_Pixel get_red(GP_PixelType pixel_type) @@ -171,14 +223,24 @@ static int convert_and_check_{{ test_name }}_{{ in_name }}_to_{{ out_name }}(voi %% for pt1 in pixeltypes %% if not pt1.is_unknown() and not pt1.is_palette() %% if pt1.name not in ['RGB888', 'RGBA8888'] +{#- White -#} {{ gen_convert_and_check('white', pt1.name, 'RGB888') }} {{ gen_convert_and_check('white', pt1.name, 'RGBA8888') }} {{ gen_convert_and_check('white', 'RGB888', pt1.name) }} {{ gen_convert_and_check('white', 'RGBA8888', pt1.name) }} +{#- Black -#} {{ gen_convert_and_check('black', pt1.name, 'RGB888') }} {{ gen_convert_and_check('black', pt1.name, 'RGBA8888') }} {{ gen_convert_and_check('black', 'RGB888', pt1.name) }} {{ gen_convert_and_check('black', 'RGBA8888', pt1.name) }} +{#- Grayscale -#} +%% if pt1.name not in ['G1'] +{{ gen_convert_and_check('gray', pt1.name, 'RGB888') }} +{{ gen_convert_and_check('gray', pt1.name, 'RGBA8888') }} +%% endif +{{ gen_convert_and_check('gray', 'RGB888', pt1.name) }} +{{ gen_convert_and_check('gray', 'RGBA8888', pt1.name) }} +{#- Red -#} %% if not pt1.is_gray() {{ gen_convert_and_check('red', pt1.name, 'RGB888') }} {{ gen_convert_and_check('red', pt1.name, 'RGBA8888') }} @@ -203,14 +265,24 @@ const struct tst_suite tst_suite = { %% for pt1 in pixeltypes %% if not pt1.is_unknown() and not pt1.is_palette() %% if pt1.name not in ['RGB888', 'RGBA8888'] +{#- White -#} {{ gen_suite_entry('white', pt1.name, 'RGB888') }} {{ gen_suite_entry('white', pt1.name, 'RGBA8888') }} {{ gen_suite_entry('white', 'RGB888', pt1.name) }} {{ gen_suite_entry('white', 'RGBA8888', pt1.name) }} +{#- Black -#} {{ gen_suite_entry('black', pt1.name, 'RGB888') }} {{ gen_suite_entry('black', pt1.name, 'RGBA8888') }} {{ gen_suite_entry('black', 'RGB888', pt1.name) }} {{ gen_suite_entry('black', 'RGBA8888', pt1.name) }} +{#- Gray -#} +%% if pt1.name not in ['G1'] +{{ gen_suite_entry('gray', pt1.name, 'RGB888') }} +{{ gen_suite_entry('gray', pt1.name, 'RGBA8888') }} +%% endif +{{ gen_suite_entry('gray', 'RGB888', pt1.name) }} +{{ gen_suite_entry('gray', 'RGBA8888', pt1.name) }} +{#- Red -#} %% if not pt1.is_gray() {{ gen_suite_entry('red', pt1.name, 'RGB888') }} {{ gen_suite_entry('red', pt1.name, 'RGBA8888') }}
-----------------------------------------------------------------------
Summary of changes: tests/core/Convert.gen.c.t | 72 +++++++++++++++++++ tests/core/{Pixel.c => Convert_Scale.gen.c.t} | 93 ++++++++++++++++-------- tests/core/Makefile | 6 +- tests/core/test_list.txt | 1 + 4 files changed, 139 insertions(+), 33 deletions(-) copy tests/core/{Pixel.c => Convert_Scale.gen.c.t} (51%)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.