36#include "hdrl_imagelist.h"
37#include "hdrl_imagelist_defs.h"
38#include "hdrl_imagelist_view.h"
39#include "hdrl_image_defs.h"
40#include "hdrl_image.h"
55static void hdrl_image_view_delete(hdrl_image * view)
58 hdrl_image * himg = (hdrl_image*)view;
63 hdrl_image_unwrap(himg);
68static void hdrl_image_imgview_delete(hdrl_image * view)
71 hdrl_image * himg = (hdrl_image*)view;
75 hdrl_image_unwrap(himg);
97hdrl_image_row_view_create(hdrl_image * himg,
103 const size_t dsz = cpl_type_get_sizeof(cpl_image_get_type(oimg));
104 const size_t esz = cpl_type_get_sizeof(cpl_image_get_type(oerr));
106 char * d = cpl_image_get_data(oimg);
107 char * e = cpl_image_get_data(oerr);
108 size_t offset = (ly - 1) * nx;
109 cpl_size nny = uy - ly + 1;
110 cpl_image * img = cpl_image_wrap(nx, nny, cpl_image_get_type(oimg),
112 cpl_image * err = cpl_image_wrap(nx, nny, cpl_image_get_type(oerr),
117 cpl_mask * mask = cpl_mask_wrap(nx, nny, cpl_mask_get_data(omask) + offset);
118 cpl_mask_delete(hcpl_image_set_bpm(img, mask));
119 omask = cpl_image_get_bpm(himg->error);
120 mask = cpl_mask_wrap(nx, nny, cpl_mask_get_data(omask) + offset);
121 cpl_mask_delete(hcpl_image_set_bpm(err, mask));
123 return hdrl_image_wrap(img, err, (hdrl_free*)&hdrl_image_view_delete,
145static const hdrl_image *
146hdrl_image_const_row_view_create(
const hdrl_image * himg,
149 hdrl_free * destructor)
153 const size_t dsz = cpl_type_get_sizeof(cpl_image_get_type(oimg));
154 const size_t esz = cpl_type_get_sizeof(cpl_image_get_type(oerr));
156 const char * d = cpl_image_get_data_const(oimg);
157 const char * e = cpl_image_get_data_const(oerr);
158 size_t offset = (ly - 1) * nx;
159 cpl_size nny = uy - ly + 1;
161 CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual);
163 cpl_image * img = cpl_image_wrap(nx, nny, cpl_image_get_type(oimg),
164 (
char*)d + offset * dsz);
165 cpl_image * err = cpl_image_wrap(nx, nny, cpl_image_get_type(oerr),
166 (
char *)e + offset * esz);
171 cpl_mask * mask = cpl_mask_wrap(nx, nny,
172 (cpl_binary*)cpl_mask_get_data_const(omask) + offset);
173 cpl_mask_delete(hcpl_image_set_bpm(img, mask));
176 if (cpl_image_get_bpm_const(himg->error) != NULL) {
177 cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
178 "Inconsistent HDRL image, data image has no"
179 " BPM but error image does");
180 cpl_image_unwrap(img);
181 cpl_image_unwrap(err);
185 omask = cpl_image_get_bpm_const(himg->error);
187 cpl_mask * mask = cpl_mask_wrap(nx, nny,
188 (cpl_binary*)cpl_mask_get_data_const(omask) + offset);
189 cpl_mask_delete(hcpl_image_set_bpm(err, mask));
194 return hdrl_image_wrap(img, err, destructor, CPL_FALSE);
215hdrl_imagelist * hdrl_imagelist_row_view(
220 cpl_ensure(hl, CPL_ERROR_NULL_INPUT, NULL);
221 cpl_ensure(uy >= ly, CPL_ERROR_ILLEGAL_INPUT, NULL);
222 cpl_ensure(ly > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
224 cpl_ensure(n > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
226 CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
229 for (
size_t i = 0; i < n; i++) {
231 hdrl_image * view = hdrl_image_row_view_create(img, ly, uy);
262const hdrl_imagelist * hdrl_imagelist_const_row_view(
263 const hdrl_imagelist * hl,
267 cpl_ensure(hl, CPL_ERROR_NULL_INPUT, NULL);
268 cpl_ensure(uy >= ly, CPL_ERROR_ILLEGAL_INPUT, NULL);
269 cpl_ensure(ly > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
271 cpl_ensure(n > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
273 CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
276 for (
size_t i = 0; i < n; i++) {
278 const hdrl_image * view = hdrl_image_const_row_view_create(img, ly, uy,
279 (hdrl_free*)&hdrl_image_view_delete);
284 CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual);
309hdrl_imagelist * hdrl_imagelist_image_view(
314 cpl_ensure(hl, CPL_ERROR_NULL_INPUT, NULL);
315 cpl_ensure(uz > lz, CPL_ERROR_ILLEGAL_INPUT, NULL);
317 cpl_ensure(lz >= 0, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
318 cpl_ensure(uz <= (cpl_size)n, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
321 for (
size_t i = lz; i < (size_t)uz; i++) {
324 hdrl_image * view = hdrl_image_row_view_create(img, 1, ny);
354const hdrl_imagelist * hdrl_imagelist_const_cpl_row_view(
355 const cpl_imagelist * imglist,
356 const cpl_imagelist * errlist,
360 cpl_ensure(imglist, CPL_ERROR_NULL_INPUT, NULL);
361 cpl_ensure(uy >= ly, CPL_ERROR_ILLEGAL_INPUT, NULL);
362 cpl_ensure(ly > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
363 size_t n = cpl_imagelist_get_size(imglist);
364 cpl_ensure(n > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
365 cpl_ensure(uy <= cpl_image_get_size_y(cpl_imagelist_get_const(imglist, 0)),
366 CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
367 cpl_ensure(errlist == NULL || n <= (
size_t)cpl_imagelist_get_size(errlist),
368 CPL_ERROR_INCOMPATIBLE_INPUT, NULL);
372 const cpl_image * img = cpl_imagelist_get_const(imglist, 0);
373 const cpl_image * err = cpl_imagelist_get_const(errlist, 0);
375 if (cpl_image_get_type(img) != HDRL_TYPE_DATA ||
376 cpl_image_get_type(err) != HDRL_TYPE_ERROR) {
378 cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT,
379 "Can only view image pairs with type "
380 "HDRL_TYPE_DATA and HDRL_TYPE_ERROR");
383 if (cpl_image_get_size_x(img) != cpl_image_get_size_x(err) ||
384 cpl_image_get_size_y(img) != cpl_image_get_size_y(err)) {
386 cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT,
387 "Image and Error not consistent");
390 for (
size_t i = 0; i < n; i++) {
391 img = cpl_imagelist_get_const(imglist, i);
392 err = cpl_imagelist_get_const(errlist, i);
393 if ((cpl_image_get_bpm_const(img) && !cpl_image_get_bpm_const(err)) ||
394 (!cpl_image_get_bpm_const(img) && cpl_image_get_bpm_const(err))) {
396 cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT,
397 "Image and error bad pixel mask "
401 if (cpl_image_get_bpm_const(img) && cpl_image_get_bpm_const(err)) {
402 const cpl_binary * dibpm =
403 cpl_mask_get_data_const(cpl_image_get_bpm_const(img));
404 const cpl_binary * debpm =
405 cpl_mask_get_data_const(cpl_image_get_bpm_const(err));
406 if (memcmp(dibpm, debpm, hdrl_get_image_npix(img)) != 0) {
408 cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT,
409 "Image and error bad pixel mask "
415 CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual);
416 hdrl_image * himg = hdrl_image_wrap((cpl_image*)img, (cpl_image*)err,
417 (hdrl_free*)&hdrl_image_view_delete,
419 const hdrl_image * view =
420 hdrl_image_const_row_view_create(himg, ly, uy,
421 (hdrl_free*)&hdrl_image_view_delete);
426 hdrl_image_unwrap(himg);
432 const cpl_image * img = cpl_imagelist_get_const(imglist, 0);
433 if (cpl_image_get_type(img) != HDRL_TYPE_DATA) {
435 cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT,
436 "Can only view images with type "
440 for (
size_t i = 0; i < n; i++) {
441 img = cpl_imagelist_get_const(imglist, i);
444 cpl_image * err = cpl_image_new(cpl_image_get_size_x(img),
445 cpl_image_get_size_y(img),
447 if (cpl_image_get_bpm_const(img)) {
448 cpl_image_reject_from_mask(err, cpl_image_get_bpm_const(img));
451 CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual);
452 hdrl_image * himg = hdrl_image_wrap((cpl_image*)img, err,
453 (hdrl_free*)&hdrl_image_imgview_delete,
455 const hdrl_image * view = hdrl_image_const_row_view_create(himg, ly, uy,
456 (hdrl_free*)&hdrl_image_imgview_delete);
461 hdrl_image_unwrap(himg);
462 cpl_mask_unwrap(cpl_image_unset_bpm(err));
463 cpl_image_unwrap(err);
cpl_mask * hdrl_image_get_mask(hdrl_image *himg)
get cpl bad pixel mask from image
cpl_image * hdrl_image_get_error(hdrl_image *himg)
get error as cpl image
cpl_size hdrl_image_get_size_y(const hdrl_image *self)
return size of Y dimension of image
const cpl_mask * hdrl_image_get_mask_const(const hdrl_image *himg)
get cpl bad pixel mask from image
cpl_size hdrl_image_get_size_x(const hdrl_image *self)
return size of X dimension of image
const cpl_image * hdrl_image_get_error_const(const hdrl_image *himg)
get error as cpl image
cpl_image * hdrl_image_get_image(hdrl_image *himg)
get data as cpl image
const cpl_image * hdrl_image_get_image_const(const hdrl_image *himg)
get data as cpl image
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.
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.
hdrl_image * hdrl_imagelist_get(const hdrl_imagelist *himlist, cpl_size inum)
Get an image from a list of images.