28#include "hdrl_frameiter.h"
33#define ARRAY_LEN(a) sizeof((a))/sizeof((a)[0])
42static void check_strides(cpl_frameset * frames, intptr_t naxes,
43 intptr_t offsets[], intptr_t strides[],
44 intptr_t dims[], intptr_t values[], intptr_t len,
48 char * soffset = cpl_sprintf(
"%s",
"(");
49 char * sstride = cpl_sprintf(
"%s",
"(");
50 char * sdim = cpl_sprintf(
"%s",
"(");
51 for (intptr_t i = 0; i < naxes; i++) {
52 char * t = cpl_sprintf(
"%s%zd%s", soffset, offsets[i],
53 i == naxes - 1 ?
")" :
",");
56 t = cpl_sprintf(
"%s%zd%s", sstride, strides ? strides[i] : 0,
57 i == naxes - 1 ?
")" :
",");
60 t = cpl_sprintf(
"%s%zd%s", sdim, dims ? dims[i] : -1,
61 i == naxes - 1 ?
")" :
",");
65 cpl_msg_info(cpl_func,
"testing offset %s, stride %s, dim %s, len %zd, "
66 "swap %d", soffset, sstride, sdim, len, swap);
71 intptr_t axes[] = {HDRL_FRAMEITER_AXIS_FRAME, HDRL_FRAMEITER_AXIS_EXT};
79 cpl_test_eq(hdrl_iter_length(it), len);
82 for (hdrl_frameiter_data * h = hdrl_iter_next(it); h != NULL; h = hdrl_iter_next(it)) {
83 cpl_test_eq(cpl_image_get(h->image, 1, 1, &d), values[cnt]);
84 cpl_image_delete(h->image);
85 cpl_propertylist_delete(h->plist);
88 cpl_test_eq(hdrl_iter_length(it), cnt);
92static void test_basic(
void)
96 cpl_frameset * frames = cpl_frameset_new();
97 for (
size_t i = 0; i < nframes; i++) {
98 char * fn = cpl_sprintf(
"hdrl_frameiter-test_%zu_%zd.fits", i, (intptr_t)getpid());
99 cpl_propertylist * plist = cpl_propertylist_new();
100 cpl_propertylist_update_string(plist,
"TAG", fn);
101 cpl_propertylist_save(plist, fn, CPL_IO_CREATE);
102 cpl_propertylist_delete(plist);
103 for (
size_t j = 1; j < next + 1; j++) {
104 cpl_image * img = cpl_image_new(50, 70, CPL_TYPE_INT);
105 cpl_image_add_scalar(img, i * next + j);
106 cpl_image_save(img, fn, CPL_TYPE_INT, NULL, CPL_IO_EXTEND);
107 cpl_image_delete(img);
109 cpl_frame * frm = cpl_frame_new();
110 cpl_frame_set_filename(frm, fn);
111 cpl_frame_set_tag(frm,
"RAW");
112 cpl_frameset_insert(frames, frm);
118 cpl_frameset * empty = cpl_frameset_new();
122 cpl_test_eq(hdrl_iter_length(it), 0);
123 cpl_test_null(hdrl_iter_next(it));
124 cpl_test_null(hdrl_iter_next(it));
125 cpl_test_null(hdrl_iter_next(it));
126 cpl_frameset_delete(empty);
127 hdrl_iter_delete(it);
131 intptr_t values[next];
132 for (
size_t i = 0; i < ARRAY_LEN(values); i++) {
135 intptr_t offsets[] = {1};
136 check_strides(frames, 1, offsets, NULL, NULL, values, ARRAY_LEN(values), 1);
140 intptr_t values[nframes * next];
141 for (
size_t i = 0; i < ARRAY_LEN(values); i++) {
144 intptr_t offsets[] = {0, 1};
145 intptr_t strides[] = {1, 1};
146 check_strides(frames, 2, offsets, strides, NULL, values,
147 ARRAY_LEN(values), 0);
151 intptr_t values[(nframes - 1) * next];
152 for (
size_t i = 0; i < ARRAY_LEN(values); i++) {
153 values[i] = i + 1 + next;
155 intptr_t offsets[] = {1, 1};
156 intptr_t strides[] = {1, 1};
157 check_strides(frames, 2, offsets, strides, NULL, values,
158 ARRAY_LEN(values), 0);
162 intptr_t values[nframes * (next / 2 + next % 2)];
164 for (
size_t i = 0; i < nframes; i++) {
165 for (
size_t j = 1; j < next + 1; j+=2) {
166 values[c++] = i * next + j;
169 cpl_test_eq(ARRAY_LEN(values), c);
170 intptr_t offsets[] = {0, 1};
171 intptr_t strides[] = {1, 2};
172 check_strides(frames, 2, offsets, strides, NULL, values,
173 ARRAY_LEN(values), 0);
177 intptr_t values[(nframes / 2 + nframes % 2) * (next)];
179 for (
size_t i = 0; i < nframes; i+=2) {
180 for (
size_t j = 1; j < next + 1; j++) {
181 values[c++] = i * next + j;
184 cpl_test_eq(ARRAY_LEN(values), c);
185 intptr_t offsets[] = {0, 1};
186 intptr_t strides[] = {2, 1};
187 check_strides(frames, 2, offsets, strides, NULL, values,
188 ARRAY_LEN(values), 0);
192 intptr_t values[(nframes / 2 + nframes % 2) * (next / 2 + next % 2)];
194 for (
size_t i = 0; i < nframes; i+=2) {
195 for (
size_t j = 1; j < next + 1; j+=2) {
196 values[c++] = i * next + j;
199 cpl_test_eq(ARRAY_LEN(values), c);
200 intptr_t offsets[] = {0, 1};
201 intptr_t strides[] = {2, 2};
202 check_strides(frames, 2, offsets, strides, NULL, values,
203 ARRAY_LEN(values), 0);
207 intptr_t values[nframes * next];
208 for (
size_t i = 0; i < ARRAY_LEN(values); i++) {
209 values[i] = (i / next) * next + 1;
211 intptr_t offsets[] = {0, 1};
212 intptr_t strides[] = {1, 0};
213 check_strides(frames, 2, offsets, strides, NULL, values,
214 ARRAY_LEN(values), 0);
218 intptr_t values[nframes * next];
219 for (
size_t i = 0; i < ARRAY_LEN(values); i++) {
220 values[i] = (i % next) + 1;
222 intptr_t offsets[] = {0, 1};
223 intptr_t strides[] = {0, 1};
224 check_strides(frames, 2, offsets, strides, NULL, values,
225 ARRAY_LEN(values), 0);
229 intptr_t values[nframes * next];
230 for (
size_t i = 0; i < ARRAY_LEN(values); i++) {
233 intptr_t offsets[] = {0, 1};
234 intptr_t strides[] = {0, 0};
235 check_strides(frames, 2, offsets, strides, NULL, values,
236 ARRAY_LEN(values), 0);
240 intptr_t values[nframes * next];
242 for (
size_t j = 1; j < next + 1; j++) {
243 for (
size_t i = 0; i < nframes; i++) {
244 values[c++] = i * next + j;
247 cpl_test_eq(ARRAY_LEN(values), c);
248 intptr_t offsets[] = {1, 0};
249 check_strides(frames, 2, offsets, NULL, NULL, values,
250 ARRAY_LEN(values), 1);
254 intptr_t values[nframes * next];
255 cpl_msg_debug(cpl_func,
"The related valgrind error present if compiled"
256 " with O3 optimisation is most probably a false "
257 "positive - adding this message suppresses the error.");
258 for (
size_t i = 0; i < ARRAY_LEN(values); i++) {
261 intptr_t offsets[] = {0, 1};
262 intptr_t dims[] = {-1, -1};
263 check_strides(frames, 2, offsets, NULL, dims, values,
264 ARRAY_LEN(values), 0);
268 intptr_t values[nframes * 3];
270 for (
size_t i = 0; i < nframes; i++) {
271 for (
size_t j = 1; j < 3 + 1; j++) {
272 values[c++] = i * next + j;
275 cpl_test_eq(ARRAY_LEN(values), c);
276 intptr_t offsets[] = {0, 1};
277 intptr_t dims[] = {-1, 3};
278 check_strides(frames, 2, offsets, NULL, dims, values,
279 ARRAY_LEN(values), 0);
283 intptr_t values[4 * next];
285 for (
size_t i = 0; i < 4; i++) {
286 for (
size_t j = 1; j < next + 1; j++) {
287 values[c++] = i * next + j;
290 cpl_test_eq(ARRAY_LEN(values), c);
291 intptr_t offsets[] = {0, 1};
292 intptr_t dims[] = {4, -1};
293 check_strides(frames, 2, offsets, NULL, dims, values,
294 ARRAY_LEN(values), 0);
297 cpl_frameset_delete(frames);
298 cpl_test_zero(system(
"rm -f hdrl_frameiter-test_*fits"));
308 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
312 return cpl_test_end(0);
hdrl_iter * hdrl_frameiter_new(const cpl_frameset *frames, hdrl_iter_flags flags, intptr_t naxes, intptr_t *axes, intptr_t *offsets, intptr_t *strides, intptr_t *dims)
create iterator over cpl_frameset