36#include "hdrl_imagelist.h"
38#include "hdrl_imagelist_view.h"
43 cpl_image_get_data(hdrl_image_get_image(a))
45 cpl_image_get_data(hdrl_image_get_image(a))
47 cpl_mask_get_data(hdrl_image_get_mask(a))
49 cpl_image_get_data_const(hdrl_image_get_image_const(a))
51 cpl_image_get_data_const(hdrl_image_get_image_const(a))
53 cpl_mask_get_data_const(hdrl_image_get_mask_const(a))
65cpl_error_code test_row_view(
void)
67 hdrl_imagelist * hlist;
73 cpl_size nimages = 20;
74 hdrl_imagelist * view;
75 const hdrl_imagelist * cview;
76 cpl_imagelist * clist;
80 clist = cpl_imagelist_new() ;
81 for (cpl_size i = 0 ; i < nimages ; i++) {
83 cpl_image *ima = cpl_image_new(XSIZE, YSIZE, HDRL_TYPE_DATA);
84 cpl_image *ima_err = cpl_image_new(XSIZE, YSIZE, HDRL_TYPE_ERROR);
86 cpl_image_add_scalar(ima_err, 1.);
87 cpl_image_reject(ima, 1, 5);
89 cpl_image_reject(ima, 2, 5);
92 cpl_image_delete(ima_err);
94 cpl_imagelist_set(clist, ima, i);
97 view = hdrl_imagelist_row_view(NULL, 10, 20);
99 cpl_test_error(CPL_ERROR_NULL_INPUT);
100 view = hdrl_imagelist_row_view(hlist, 20, 10);
102 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
103 view = hdrl_imagelist_row_view(hlist, 0, 10);
105 cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
106 view = hdrl_imagelist_row_view(hlist, 1, YSIZE + 11);
108 cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
111 cview = hdrl_imagelist_const_row_view(NULL, 10, 20);
112 cpl_test_null(cview);
113 cpl_test_error(CPL_ERROR_NULL_INPUT);
114 cview = hdrl_imagelist_const_row_view(hlist, 20, 10);
115 cpl_test_null(cview);
116 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
117 cview = hdrl_imagelist_const_row_view(hlist, 0, 10);
118 cpl_test_null(cview);
119 cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
120 cview = hdrl_imagelist_const_row_view(hlist, 1, YSIZE + 11);
121 cpl_test_null(cview);
122 cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
127 view = hdrl_imagelist_row_view(hlist, 1, YSIZE);
130 hdrl_test_image_abs(himg, himg2, 0);
131 cpl_test_image_abs(contrib, contrib2, 0);
132 cpl_image * ccontrib = cpl_image_new_from_accepted(clist);
133 cpl_test_image_abs(ccontrib, contrib2, 0);
134 cpl_image * cerror = cpl_image_cast(ccontrib, HDRL_TYPE_ERROR);
135 cpl_image_power(cerror, -0.5);
137 cpl_image_delete(contrib2);
139 cpl_image_delete(cerror);
142 cview = hdrl_imagelist_const_row_view(hlist, 1, YSIZE);
145 hdrl_test_image_abs(himg, himg2, 0);
146 cpl_test_image_abs(contrib, contrib2, 0);
147 cpl_test_image_abs(ccontrib, contrib2, 0);
148 cerror = cpl_image_cast(ccontrib, HDRL_TYPE_ERROR);
149 cpl_image_power(cerror, -0.5);
152 cpl_image_delete(contrib2);
154 cpl_image_delete(ccontrib);
155 cpl_image_delete(cerror);
156 cpl_image_delete(contrib);
161 cpl_test_eq_ptr(IMG_PTR(iorig), IMG_PTR(iview));
162 cpl_test_eq_ptr(ERR_PTR(iorig), ERR_PTR(iview));
163 cpl_test_eq_ptr(MSK_PTR(iorig), MSK_PTR(iview));
166 cpl_test_eq_ptr(IMG_PTR(iorig), CIMG_PTR(ciview));
167 cpl_test_eq_ptr(ERR_PTR(iorig), CERR_PTR(ciview));
168 cpl_test_eq_ptr(MSK_PTR(iorig), CMSK_PTR(ciview));
173 cpl_test_eq_ptr(IMG_PTR(iorig), IMG_PTR(iview));
174 cpl_test_eq_ptr(ERR_PTR(iorig), ERR_PTR(iview));
175 cpl_test_eq_ptr(MSK_PTR(iorig), MSK_PTR(iview));
178 cpl_test_eq_ptr(IMG_PTR(iorig), CIMG_PTR(ciview));
179 cpl_test_eq_ptr(ERR_PTR(iorig), CERR_PTR(ciview));
180 cpl_test_eq_ptr(MSK_PTR(iorig), CMSK_PTR(ciview));
184 cpl_test_noneq_ptr(IMG_PTR(icopy), IMG_PTR(iview));
185 cpl_test_noneq_ptr(ERR_PTR(icopy), ERR_PTR(iview));
186 cpl_test_noneq_ptr(MSK_PTR(icopy), MSK_PTR(iview));
195 cpl_size nsizey = YSIZE - 17 - 5 + 1;
196 view = hdrl_imagelist_row_view(hlist, 5, YSIZE - 17);
209 HDRL_EPS_DATA * XSIZE * YSIZE);
213 CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual);
218 cpl_imagelist_delete(clist);
220 return cpl_error_get_code();
223cpl_error_code test_cpl_row_view_invalid(
void)
225 cpl_imagelist * imglist = cpl_imagelist_new();
226 cpl_imagelist * errlist = cpl_imagelist_new();
227 const hdrl_imagelist * view;
229 view = hdrl_imagelist_const_cpl_row_view(NULL, errlist, 1, 2);
231 cpl_test_error(CPL_ERROR_NULL_INPUT);
233 view = hdrl_imagelist_const_cpl_row_view(imglist, errlist, 1, 0);
235 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
237 view = hdrl_imagelist_const_cpl_row_view(imglist, errlist, 1, 2);
239 cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
241 cpl_image * img = cpl_image_new(5, 5, HDRL_TYPE_DATA);
242 cpl_imagelist_set(imglist, img, 0);
243 cpl_image * err = cpl_image_new(6, 5, HDRL_TYPE_ERROR);
244 cpl_imagelist_set(errlist, err, 0);
246 view = hdrl_imagelist_const_cpl_row_view(imglist, errlist, 1, 2);
248 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
250 cpl_image_delete(cpl_imagelist_unset(imglist, 0));
251 cpl_image_delete(cpl_imagelist_unset(errlist, 0));
253 img = cpl_image_new(5, 5, CPL_TYPE_INT);
254 cpl_imagelist_set(imglist, img, 0);
255 err = cpl_image_new(5, 5, CPL_TYPE_INT);
256 cpl_imagelist_set(errlist, err, 0);
258 view = hdrl_imagelist_const_cpl_row_view(imglist, errlist, 1, 2);
260 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
262 cpl_image_delete(cpl_imagelist_unset(imglist, 0));
263 cpl_image_delete(cpl_imagelist_unset(errlist, 0));
265 img = cpl_image_new(5, 5, HDRL_TYPE_DATA);
266 cpl_imagelist_set(imglist, img, 0);
267 err = cpl_image_new(5, 5, HDRL_TYPE_ERROR);
268 cpl_imagelist_set(errlist, err, 0);
269 cpl_image_reject(img, 1, 1);
271 view = hdrl_imagelist_const_cpl_row_view(imglist, errlist, 1, 2);
273 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
275 cpl_image_reject(img, 1, 1);
276 cpl_image_reject(err, 1, 2);
278 view = hdrl_imagelist_const_cpl_row_view(imglist, errlist, 1, 2);
280 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
282 cpl_image_accept_all(img);
284 view = hdrl_imagelist_const_cpl_row_view(imglist, errlist, 1, 2);
286 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
288 cpl_imagelist_delete(imglist);
289 cpl_imagelist_delete(errlist);
291 return cpl_error_get_code();
294cpl_error_code test_cpl_row_view(
void)
296 hdrl_imagelist * hlist;
297 hdrl_imagelist * hlist_noerr;
301 cpl_image * vcontrib;
303 cpl_size nimages = 20;
304 const hdrl_imagelist * cview;
305 cpl_imagelist * cimglist, * cerrlist;
310 cimglist = cpl_imagelist_new() ;
311 cerrlist = cpl_imagelist_new() ;
312 for (cpl_size i = 0 ; i < nimages ; i++) {
314 cpl_image *ima = cpl_image_new(XSIZE, YSIZE, HDRL_TYPE_DATA);
315 cpl_image *ima_err = cpl_image_new(XSIZE, YSIZE, HDRL_TYPE_ERROR);
317 cpl_image_add_scalar(ima_err, 1.);
318 cpl_image_reject(ima, 1, 5);
319 cpl_image_reject(ima_err, 1, 5);
321 cpl_image_reject(ima, 2, 5);
322 cpl_image_reject(ima_err, 2, 5);
327 cpl_imagelist_set(cimglist, ima, i);
328 cpl_imagelist_set(cerrlist, ima_err, i);
331 cview = hdrl_imagelist_const_cpl_row_view(cimglist, cerrlist, 1, YSIZE);
332 cpl_test_nonnull(cview);
333 cpl_test_error(CPL_ERROR_NONE);
336 hdrl_test_image_abs(himg, vhimg, 0);
337 cpl_test_image_abs(contrib, vcontrib, 0);
340 cpl_image_delete(contrib);
341 cpl_image_delete(vcontrib);
345 hdrl_test_image_abs(himg, vhimg, 0);
346 cpl_test_image_abs(contrib, vcontrib, 0);
349 cpl_image_delete(contrib);
350 cpl_image_delete(vcontrib);
351 CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual);
356 cview = hdrl_imagelist_const_cpl_row_view(cimglist, NULL, 1, YSIZE);
359 hdrl_test_image_abs(himg, vhimg, 0);
360 cpl_test_image_abs(contrib, vcontrib, 0);
363 cpl_image_delete(contrib);
364 cpl_image_delete(vcontrib);
368 hdrl_test_image_abs(himg, vhimg, 0);
369 cpl_test_image_abs(contrib, vcontrib, 0);
372 cpl_image_delete(contrib);
373 cpl_image_delete(vcontrib);
379 hdrl_test_image_abs(himg, vhimg, 0);
380 cpl_test_image_abs(contrib, vcontrib, 0);
383 cpl_image_delete(contrib);
384 cpl_image_delete(vcontrib);
390 hdrl_test_image_abs(himg, vhimg, 0);
391 cpl_test_image_abs(contrib, vcontrib, 0);
394 cpl_image_delete(contrib);
395 cpl_image_delete(vcontrib);
397 CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual);
403 cpl_imagelist_delete(cimglist);
404 cpl_imagelist_delete(cerrlist);
406 return cpl_error_get_code();
410cpl_error_code test_image_view(
void)
413 hdrl_imagelist * view;
415 view = hdrl_imagelist_image_view(hl, 5, 1);
416 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
419 view = hdrl_imagelist_image_view(hl, 1, 1);
420 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
423 view = hdrl_imagelist_image_view(hl, 0, 1);
424 cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
429 view = hdrl_imagelist_image_view(hl, 1, 2);
430 cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
433 view = hdrl_imagelist_image_view(hl, -1, 1);
434 cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
437 view = hdrl_imagelist_image_view(hl, 0, 1);
438 cpl_test_error(CPL_ERROR_NONE);
439 cpl_test_nonnull(view);
459 view = hdrl_imagelist_image_view(hl, 1, 2);
460 cpl_test_error(CPL_ERROR_NONE);
470 view = hdrl_imagelist_image_view(hl, 1, 3);
486 hdrl_imagelist * rview = hdrl_imagelist_row_view(view, 2, 7);
496 return cpl_error_get_code();
506 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
510 test_cpl_row_view_invalid();
513 return cpl_test_end(0);
hdrl_image * hdrl_image_duplicate(const hdrl_image *himg)
copy hdrl_image
cpl_error_code hdrl_image_add_scalar(hdrl_image *self, hdrl_value value)
Elementwise addition of a scalar to an image.
cpl_image * hdrl_image_get_error(hdrl_image *himg)
get error as cpl image
hdrl_value hdrl_image_get_mean(const hdrl_image *self)
computes mean pixel value and associated error of an image.
cpl_size hdrl_image_get_size_y(const hdrl_image *self)
return size of Y dimension of image
cpl_size hdrl_image_get_size_x(const hdrl_image *self)
return size of X dimension of image
hdrl_image * hdrl_image_create(const cpl_image *image, const cpl_image *error)
create a new hdrl_image from to existing images by copying them
hdrl_image * hdrl_image_new(cpl_size nx, cpl_size ny)
create new zero filled hdrl image
void hdrl_image_delete(hdrl_image *himg)
delete hdrl_image
cpl_error_code hdrl_imagelist_collapse_sigclip(const hdrl_imagelist *himlist, double kappa_low, double kappa_high, int niter, hdrl_image **out, cpl_image **contrib, cpl_image **reject_low, cpl_image **reject_high)
Sigma-clipped collapsing of image list.
cpl_error_code hdrl_imagelist_add_scalar(hdrl_imagelist *himlist, hdrl_value value)
Elementwise addition of a scalar to each image in the himlist.
cpl_error_code hdrl_imagelist_collapse_mean(const hdrl_imagelist *himlist, hdrl_image **out, cpl_image **contrib)
Mean collapsing of image list.
cpl_error_code hdrl_imagelist_set(hdrl_imagelist *himlist, hdrl_image *himg, cpl_size pos)
Insert an image into an imagelist.
void hdrl_imagelist_delete(hdrl_imagelist *himlist)
Free all memory used by a hdrl_imagelist object including the images.
cpl_size hdrl_imagelist_get_size(const hdrl_imagelist *himlist)
Get the number of images in the imagelist.
hdrl_imagelist * hdrl_imagelist_new(void)
Create an empty imagelist.
cpl_error_code hdrl_imagelist_collapse_median(const hdrl_imagelist *himlist, hdrl_image **out, cpl_image **contrib)
Median collapsing of image list.
hdrl_imagelist * hdrl_imagelist_duplicate(const hdrl_imagelist *himlist)
Duplicate an image list.
cpl_error_code hdrl_imagelist_collapse_minmax(const hdrl_imagelist *himlist, double nlow, double nhigh, hdrl_image **out, cpl_image **contrib, cpl_image **reject_low, cpl_image **reject_high)
Minmax-clipped collapsing of image list.
cpl_error_code hdrl_imagelist_collapse_weighted_mean(const hdrl_imagelist *himlist, hdrl_image **out, cpl_image **contrib)
Weighted Mean collapsing of image list.
hdrl_image * hdrl_imagelist_get(const hdrl_imagelist *himlist, cpl_size inum)
Get an image from a list of images.