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);
387 if (himlist != NULL) {
389 hdrl_imagelist_unwrap(himlist);
407 if (himlist != NULL) {
408 while (himlist->ni > 0) {
410 cpl_size i = himlist->ni - 1;
416 if (himlist->images[i] == del) {
442 hdrl_imagelist * out;
445 cpl_ensure(himlist != NULL, CPL_ERROR_NULL_INPUT, NULL);
451 for (i=0; i<himlist->ni; i++) {
472 cpl_ensure(himlist != NULL, CPL_ERROR_NULL_INPUT, -1);
473 if (himlist->ni == 0)
return 1;
493 const hdrl_imagelist * himlist,
496 const int msgmin = (int)strlen(HDRL_MSG) - 5;
500 cpl_ensure_code(himlist != NULL, CPL_ERROR_NULL_INPUT);
501 cpl_ensure_code(stream != NULL, CPL_ERROR_NULL_INPUT);
503 cpl_ensure_code( fprintf(stream, HDRL_MSG, (
int)himlist->ni) >= msgmin,
506 for (i = 0; i < himlist -> ni; i++) {
508 const int imsgmin = (int)strlen(HDRL_IMSG) - 5;
510 cpl_ensure_code( fprintf(stream, HDRL_IMSG, i, (
int)himlist->ni) >= imsgmin,
514 cpl_error_get_code() );
517 return CPL_ERROR_NONE;
539 const hdrl_imagelist * himlist,
548 cpl_ensure_code(himlist != NULL, CPL_ERROR_NULL_INPUT);
549 cpl_ensure_code(stream != NULL, CPL_ERROR_NULL_INPUT);
551 for (i = 0; i < himlist -> ni; i++) {
553 const int imsgmin = (int)strlen(HDRL_IMSG) - 5;
555 cpl_ensure_code( fprintf(stream, HDRL_IMSG, (
int)i,
556 (
int)himlist->ni) >= imsgmin, CPL_ERROR_FILE_IO );
560 cpl_error_get_code() );
562 return CPL_ERROR_NONE;
577void hdrl_imagelist_unwrap(hdrl_imagelist * himlist)
579 if (himlist != NULL) {
580 cpl_free(himlist->images);
587 const hdrl_imagelist * hlist;
593 hdrl_imagelist * last_view;
594} hdrl_imagelist_row_slices_iter;
596static void * hdrl_imagelist_row_slices_next(hdrl_iter * it)
598 hdrl_imagelist_row_slices_iter * s = hdrl_iter_state(it);
599 if (s->pos > s->ny) {
602 cpl_size lower = CX_MAX(s->pos - s->overlap, 1);
603 cpl_size upper = CX_MIN(s->pos + s->nrows + s->overlap - 1, s->ny);
608 hdrl_imagelist * view;
610 CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual);
611 if (hdrl_iter_check(it, HDRL_ITER_CONST)) {
612 view = (hdrl_imagelist*)
613 hdrl_imagelist_const_row_view((hdrl_imagelist*)s->hlist,
617 view = hdrl_imagelist_row_view((hdrl_imagelist*)s->hlist,
622 s->prev_pos = s->pos;
623 s->pos = CX_MIN(s->pos + s->nrows - 1, s->ny) + 1;
624 if (hdrl_iter_check(it, HDRL_ITER_OWNS_DATA)) {
631hdrl_il_rowsliceiter_data
632hdrl_imagelist_iter_row_slices_get_data(
const hdrl_iter * it)
634 hdrl_imagelist_row_slices_iter * s = hdrl_iter_state(it);
636 if (s->prev_pos == 1) {
637 return (hdrl_il_rowsliceiter_data){1., CX_MIN(s->nrows, s->ny)};
640 return (hdrl_il_rowsliceiter_data){s->overlap + 1, s->overlap + s->pos - s->prev_pos};
644static cpl_size hdrl_imagelist_row_slices_length(hdrl_iter * it)
646 hdrl_imagelist_row_slices_iter * s = hdrl_iter_state(it);
647 return s->ny / s->nrows + ((s->ny % s->nrows) != 0);
650static void hdrl_imagelist_iter_delete(
void * it)
654 hdrl_imagelist_row_slices_iter * s = hdrl_iter_state(it);
660hdrl_iter * hdrl_imagelist_get_iter_row_slices(
const hdrl_imagelist * hlist,
663 hdrl_iter_flags flags)
665 cpl_ensure(hlist, CPL_ERROR_NULL_INPUT, NULL);
667 cpl_ensure(nrows >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL);
669 CPL_ERROR_ILLEGAL_INPUT, NULL);
671 hdrl_imagelist_row_slices_iter * state = cpl_malloc(
sizeof(*state));
672 state->hlist = hlist;
676 state->overlap = CX_MAX(overlap, 0);
677 state->nrows = CX_MAX(nrows, 1);
678 state->last_view = NULL;
680 return hdrl_iter_init(hdrl_imagelist_row_slices_next, NULL,
681 hdrl_imagelist_row_slices_length,
682 hdrl_imagelist_iter_delete,
683 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.