3 * Pixel conversions tests.
5 * Copyright (C) 2009-2014 Cyril Hrubis <metan@ucw.cz>
8 #include <core/GP_Convert.h>
13 * Returns black color for particular pixel type.
15 static GP_Pixel get_black(GP_PixelType pixel_type)
18 @ for pt in pixeltypes:
22 /* Black in CMYK is full K rest zero */
23 return {{ K.C_mask }};
26 /* Black with Alpha channel is full A rest zero */
27 return {{ A.C_mask }};
32 tst_msg("Invalid pixel type %i", pixel_type);
38 * Returns white color for particular pixel type.
40 static GP_Pixel get_white(GP_PixelType pixel_type)
43 @ for pt in pixeltypes:
46 /* White in CMYK is zero */
55 return {{ A.C_mask }} | {{ R.C_mask }} | {{ G.C_mask }} | {{ B.C_mask }};
58 return {{ R.C_mask }} | {{ G.C_mask }} | {{ B.C_mask }};
64 /* Grayscale with Alpha */
65 return {{ V.C_mask }} | {{ A.C_mask }};
68 return {{ V.C_mask }};
71 tst_msg("FIXME: Unsupported conversion to %s",
72 GP_PixelTypeName(pixel_type));
76 tst_msg("Invalid pixel type %i", pixel_type);
82 * Returns red color for particular pixel type.
84 static GP_Pixel get_red(GP_PixelType pixel_type)
87 @ for pt in pixeltypes:
92 /* Red in CMYK is full M and Y rest zero */
93 return {{ M.C_mask }} | {{ Y.C_mask }};
98 /* Red with Alpha channel is full Alpha and R rest zero */
99 return {{ A.C_mask }} | {{ R.C_mask }};
102 return {{ R.C_mask }};
108 /* Grayscale with Alpha channel is full Alpha + 1/3 Gray */
109 return ({{ hex(V.max // 3)}}{{ V.C_shift }}) | {{ A.C_mask }};
111 /* Grayscale is 1/3 Gray */
112 return {{ hex(V.max // 3) }}{{ V.C_shift }};
115 tst_msg("FIXME: Unsupported conversion to %s",
116 GP_PixelTypeName(pixel_type));
120 tst_msg("Invalid pixel type %i", pixel_type);
125 @ def gen_convert_and_check(test_name, in_name, out_name):
126 static int convert_and_check_{{ test_name }}_{{ in_name }}_to_{{ out_name }}(void)
129 GP_Pixel in = get_{{ test_name }}(GP_PIXEL_{{ in_name }});
130 GP_Pixel out_exp = get_{{ test_name }}(GP_PIXEL_{{ out_name }});
132 tst_msg("{{ in_name }} %08x -> {{ out_name }} %08x", in, out_exp);
134 GP_Pixel_{{ in_name }}_TO_{{ out_name }}(in, out);
136 if (out_exp != out) {
137 tst_msg("Pixels are different have %08x, expected %08x",
147 @ def gen_converts():
148 @ for pt1 in pixeltypes:
149 @ if not pt1.is_unknown() and not pt1.is_palette():
150 @ if pt1.name not in ['RGB888', 'RGBA8888']:
152 {@ gen_convert_and_check('white', pt1.name, 'RGB888') @}
153 {@ gen_convert_and_check('white', pt1.name, 'RGBA8888') @}
154 {@ gen_convert_and_check('white', 'RGB888', pt1.name) @}
155 {@ gen_convert_and_check('white', 'RGBA8888', pt1.name) @}
157 {@ gen_convert_and_check('black', pt1.name, 'RGB888') @}
158 {@ gen_convert_and_check('black', pt1.name, 'RGBA8888') @}
159 {@ gen_convert_and_check('black', 'RGB888', pt1.name) @}
160 {@ gen_convert_and_check('black', 'RGBA8888', pt1.name) @}
162 @ if not pt1.is_gray():
163 {@ gen_convert_and_check('red', pt1.name, 'RGB888') @}
164 {@ gen_convert_and_check('red', pt1.name, 'RGBA8888') @}
166 {@ gen_convert_and_check('red', 'RGB888', pt1.name) @}
167 {@ gen_convert_and_check('red', 'RGBA8888', pt1.name) @}
172 @ def gen_suite_entry(name, p_from, p_to):
173 {.name = "Convert {{ name }} {{ p_from }} -> {{ p_to }}",
174 .tst_fn = convert_and_check_{{ name }}_{{ p_from }}_to_{{ p_to }}},
177 const struct tst_suite tst_suite = {
178 .suite_name = "Pixel Conversions Testsuite",
180 @ for pt1 in pixeltypes:
181 @ if not pt1.is_unknown() and not pt1.is_palette():
182 @ if pt1.name not in ['RGB888', 'RGBA8888']:
184 {@ gen_suite_entry('white', pt1.name, 'RGB888') @}
185 {@ gen_suite_entry('white', pt1.name, 'RGBA8888') @}
186 {@ gen_suite_entry('white', 'RGB888', pt1.name) @}
187 {@ gen_suite_entry('white', 'RGBA8888', pt1.name) @}
189 {@ gen_suite_entry('black', pt1.name, 'RGB888') @}
190 {@ gen_suite_entry('black', pt1.name, 'RGBA8888') @}
191 {@ gen_suite_entry('black', 'RGB888', pt1.name) @}
192 {@ gen_suite_entry('black', 'RGBA8888', pt1.name) @}
194 @ if not pt1.is_gray():
195 {@ gen_suite_entry('red', pt1.name, 'RGB888') @}
196 {@ gen_suite_entry('red', pt1.name, 'RGBA8888') @}
198 {@ gen_suite_entry('red', 'RGB888', pt1.name) @}
199 {@ gen_suite_entry('red', 'RGBA8888', pt1.name) @}