28#include "hdrl_image.h"
29#include "hdrl_imagelist.h"
30#include "hdrl_imagelist_defs.h"
31#include "hdrl_imagelist_view.h"
42#define HDRL_MSG "Imagelist with %d image(s)\n"
43#define HDRL_IMSG "Image nb %d of %d in imagelist\n"
70static void hdrl_imagelist_set_capacity(hdrl_imagelist * h, cpl_size size)
72 h->capacity = CX_MAX(h->ni, CX_MAX(128, size));
73 h->images = cpl_realloc(h->images, h->capacity *
sizeof(h->images[0]));
86 hdrl_imagelist * h = cpl_calloc(1,
sizeof(hdrl_imagelist));
87 hdrl_imagelist_set_capacity(h, 128);
103 cpl_imagelist * imlist,
104 cpl_imagelist * errlist)
106 hdrl_imagelist * himlist ;
110 cpl_ensure(imlist != NULL, CPL_ERROR_NULL_INPUT, NULL);
112 cpl_ensure(cpl_imagelist_get_size(imlist) ==
113 cpl_imagelist_get_size(errlist), CPL_ERROR_ILLEGAL_INPUT, NULL);
120 for (cpl_size i = 0; i < cpl_imagelist_get_size(imlist); i++) {
124 error = cpl_imagelist_get(errlist, i) ;
150 cpl_ensure(himlist != NULL, CPL_ERROR_NULL_INPUT, -1);
151 assert( himlist->ni >= 0 );
170 cpl_ensure(himlist != NULL, CPL_ERROR_NULL_INPUT, -1);
171 cpl_ensure(himlist->ni > 0, CPL_ERROR_ILLEGAL_INPUT, -1);
190 cpl_ensure(himlist != NULL, CPL_ERROR_NULL_INPUT, -1);
191 cpl_ensure(himlist->ni > 0, CPL_ERROR_ILLEGAL_INPUT, -1);
211 const hdrl_imagelist * himlist,
214 cpl_ensure(himlist != NULL, CPL_ERROR_NULL_INPUT, NULL);
215 cpl_ensure(inum >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL);
216 cpl_ensure(inum < himlist->ni, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
217 return himlist->images[inum];
230 const hdrl_imagelist * himlist,
233 cpl_ensure(himlist != NULL, CPL_ERROR_NULL_INPUT, NULL);
234 cpl_ensure(inum >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL);
235 cpl_ensure(inum < himlist->ni, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
236 return himlist->images[inum];
275 hdrl_imagelist * himlist,
279 cpl_ensure_code(himlist, CPL_ERROR_NULL_INPUT);
280 cpl_ensure_code(himg, CPL_ERROR_NULL_INPUT);
281 cpl_ensure_code(pos >= 0, CPL_ERROR_ILLEGAL_INPUT);
282 cpl_ensure_code(pos <= himlist->ni, CPL_ERROR_ACCESS_OUT_OF_RANGE);
285 if (pos < himlist->ni && himg == himlist->images[pos])
286 return CPL_ERROR_NONE;
288 if (pos > 0 || himlist->ni > 1) {
292 CPL_ERROR_INCOMPATIBLE_INPUT);
295 CPL_ERROR_INCOMPATIBLE_INPUT);
302 if (pos == himlist->ni) {
304 if (pos >= himlist->capacity) {
305 hdrl_imagelist_set_capacity(himlist, 2 * pos);
313 for (i = 0; i < himlist->ni; i++) {
314 if (i != pos && himlist->images[i] == himlist->images[pos])
break;
316 if (i == himlist->ni) {
323 himlist->images[pos] = himg;
325 return CPL_ERROR_NONE;
348 hdrl_imagelist * himlist,
354 cpl_ensure(himlist, CPL_ERROR_NULL_INPUT, NULL);
355 cpl_ensure(pos >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL);
356 cpl_ensure(pos < himlist->ni, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
359 out = himlist->images[pos];
362 for (i=pos + 1; i < himlist->ni; i++) {
363 himlist->images[i-1] = himlist->images[i];
370 if (himlist->ni < himlist->capacity / 2) {
371 hdrl_imagelist_set_capacity(himlist, himlist->ni / 2);
386 if (himlist != NULL) {
388 hdrl_imagelist_unwrap(himlist);
405 if (himlist != NULL) {
406 while (himlist->ni > 0) {
408 cpl_size i = himlist->ni - 1;
414 if (himlist->images[i] == del) {
440 hdrl_imagelist * out;
443 cpl_ensure(himlist != NULL, CPL_ERROR_NULL_INPUT, NULL);
449 for (i=0; i<himlist->ni; i++) {
470 cpl_ensure(himlist != NULL, CPL_ERROR_NULL_INPUT, -1);
471 if (himlist->ni == 0)
return 1;
491 const hdrl_imagelist * himlist,
494 const int msgmin = (int)strlen(HDRL_MSG) - 5;
498 cpl_ensure_code(himlist != NULL, CPL_ERROR_NULL_INPUT);
499 cpl_ensure_code(stream != NULL, CPL_ERROR_NULL_INPUT);
501 cpl_ensure_code( fprintf(stream, HDRL_MSG, (
int)himlist->ni) >= msgmin,
504 for (i = 0; i < himlist -> ni; i++) {
506 const int imsgmin = (int)strlen(HDRL_IMSG) - 5;
508 cpl_ensure_code( fprintf(stream, HDRL_IMSG, i, (
int)himlist->ni) >= imsgmin,
512 cpl_error_get_code() );
515 return CPL_ERROR_NONE;
537 const hdrl_imagelist * himlist,
546 cpl_ensure_code(himlist != NULL, CPL_ERROR_NULL_INPUT);
547 cpl_ensure_code(stream != NULL, CPL_ERROR_NULL_INPUT);
549 for (i = 0; i < himlist -> ni; i++) {
551 const int imsgmin = (int)strlen(HDRL_IMSG) - 5;
553 cpl_ensure_code( fprintf(stream, HDRL_IMSG, (
int)i,
554 (
int)himlist->ni) >= imsgmin, CPL_ERROR_FILE_IO );
558 cpl_error_get_code() );
560 return CPL_ERROR_NONE;
575void hdrl_imagelist_unwrap(hdrl_imagelist * himlist)
577 if (himlist != NULL) {
578 cpl_free(himlist->images);
585 const hdrl_imagelist * hlist;
591 hdrl_imagelist * last_view;
592} hdrl_imagelist_row_slices_iter;
594static void * hdrl_imagelist_row_slices_next(hdrl_iter * it)
596 hdrl_imagelist_row_slices_iter * s = hdrl_iter_state(it);
597 if (s->pos > s->ny) {
600 cpl_size lower = CX_MAX(s->pos - s->overlap, 1);
601 cpl_size upper = CX_MIN(s->pos + s->nrows + s->overlap - 1, s->ny);
606 hdrl_imagelist * view;
608 CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual);
609 if (hdrl_iter_check(it, HDRL_ITER_CONST)) {
610 view = (hdrl_imagelist*)
611 hdrl_imagelist_const_row_view((hdrl_imagelist*)s->hlist,
615 view = hdrl_imagelist_row_view((hdrl_imagelist*)s->hlist,
620 s->prev_pos = s->pos;
621 s->pos = CX_MIN(s->pos + s->nrows - 1, s->ny) + 1;
622 if (hdrl_iter_check(it, HDRL_ITER_OWNS_DATA)) {
629hdrl_il_rowsliceiter_data
630hdrl_imagelist_iter_row_slices_get_data(
const hdrl_iter * it)
632 hdrl_imagelist_row_slices_iter * s = hdrl_iter_state(it);
634 if (s->prev_pos == 1) {
635 return (hdrl_il_rowsliceiter_data){1., CX_MIN(s->nrows, s->ny)};
638 return (hdrl_il_rowsliceiter_data){s->overlap + 1, s->overlap + s->pos - s->prev_pos};
642static cpl_size hdrl_imagelist_row_slices_length(hdrl_iter * it)
644 hdrl_imagelist_row_slices_iter * s = hdrl_iter_state(it);
645 return s->ny / s->nrows + ((s->ny % s->nrows) != 0);
648static void hdrl_imagelist_iter_delete(
void * it)
652 hdrl_imagelist_row_slices_iter * s = hdrl_iter_state(it);
658hdrl_iter * hdrl_imagelist_get_iter_row_slices(
const hdrl_imagelist * hlist,
661 hdrl_iter_flags flags)
663 cpl_ensure(hlist, CPL_ERROR_NULL_INPUT, NULL);
665 cpl_ensure(nrows >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL);
667 CPL_ERROR_ILLEGAL_INPUT, NULL);
669 hdrl_imagelist_row_slices_iter * state = cpl_malloc(
sizeof(*state));
670 state->hlist = hlist;
674 state->overlap = CX_MAX(overlap, 0);
675 state->nrows = CX_MAX(nrows, 1);
676 state->last_view = NULL;
678 return hdrl_iter_init(hdrl_imagelist_row_slices_next, NULL,
679 hdrl_imagelist_row_slices_length,
680 hdrl_imagelist_iter_delete,
681 HDRL_ITER_INPUT | HDRL_ITER_IMAGELIST | flags,
hdrl_image * hdrl_image_duplicate(const hdrl_image *himg)
copy hdrl_image
cpl_error_code hdrl_image_dump_window(const hdrl_image *himg, cpl_size llx, cpl_size lly, cpl_size urx, cpl_size ury, FILE *stream)
Dump pixel values in a HDRL 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
cpl_error_code hdrl_image_dump_structure(const hdrl_image *himg, FILE *stream)
Dump structural information of a HDRL image.
void hdrl_image_delete(hdrl_image *himg)
delete hdrl_image
hdrl_image * hdrl_imagelist_unset(hdrl_imagelist *himlist, cpl_size pos)
Remove an image from an imagelist.
cpl_error_code hdrl_imagelist_set(hdrl_imagelist *himlist, hdrl_image *himg, cpl_size pos)
Insert an image into an imagelist.
cpl_size hdrl_imagelist_get_size_y(const hdrl_imagelist *himlist)
Get number of rows of images in the imagelist.
hdrl_imagelist * hdrl_imagelist_create(cpl_imagelist *imlist, cpl_imagelist *errlist)
Create an hdrl_imagelist out of 2 cpl_imagelist.
void hdrl_imagelist_delete(hdrl_imagelist *himlist)
Free all memory used by a hdrl_imagelist object including the images.
const hdrl_image * hdrl_imagelist_get_const(const hdrl_imagelist *himlist, cpl_size inum)
Get an image from a list of images.
void hdrl_imagelist_empty(hdrl_imagelist *himlist)
Empty an imagelist and deallocate all its images.
cpl_size hdrl_imagelist_get_size(const hdrl_imagelist *himlist)
Get the number of images in the imagelist.
int hdrl_imagelist_is_consistent(const hdrl_imagelist *himlist)
Determine if an imagelist contains images of equal size and type.
cpl_error_code hdrl_imagelist_dump_window(const hdrl_imagelist *himlist, cpl_size llx, cpl_size lly, cpl_size urx, cpl_size ury, FILE *stream)
Dump pixel values of images in a imagelist.
hdrl_imagelist * hdrl_imagelist_new(void)
Create an empty imagelist.
hdrl_imagelist * hdrl_imagelist_duplicate(const hdrl_imagelist *himlist)
Duplicate an image list.
cpl_size hdrl_imagelist_get_size_x(const hdrl_imagelist *himlist)
Get number of colums of images in the imagelist.
cpl_error_code hdrl_imagelist_dump_structure(const hdrl_imagelist *himlist, FILE *stream)
Dump structural information of images in an imagelist.
hdrl_image * hdrl_imagelist_get(const hdrl_imagelist *himlist, cpl_size inum)
Get an image from a list of images.