28#include "hdrl_elemop.h"
29#include "hdrl_image.h"
30#include "hdrl_image_defs.h"
31#include "hdrl_utils.h"
32#include "hdrl_buffer.h"
54static void _hdrl_image_delete(hdrl_image * himg);
55static void _hdrl_image_delete_buffer(hdrl_image * himg);
56static void _hdrl_image_sync_mask(hdrl_image * himg);
66hdrl_image_check_consistent(
const cpl_image * image,
67 const cpl_image * error)
69 cpl_ensure_code(image, CPL_ERROR_NULL_INPUT);
71 cpl_size inx = cpl_image_get_size_x(image);
72 cpl_size iny = cpl_image_get_size_y(image);
73 cpl_size enx = cpl_image_get_size_x(error);
74 cpl_size eny = cpl_image_get_size_y(error);
75 const cpl_mask * ibpm = cpl_image_get_bpm_const(image);
76 const cpl_mask * ebpm = cpl_image_get_bpm_const(error);
77 cpl_ensure_code(inx == enx, CPL_ERROR_INCOMPATIBLE_INPUT);
78 cpl_ensure_code(iny == eny, CPL_ERROR_INCOMPATIBLE_INPUT);
81 const cpl_binary * dibpm = cpl_mask_get_data_const(ibpm);
82 const cpl_binary * debpm = cpl_mask_get_data_const(ebpm);
83 if (memcmp(dibpm, debpm, inx * iny) != 0) {
84 cpl_msg_warning(cpl_func,
"Image and error bad pixel mask "
85 "not equal, ignoring mask of error image");
88 else if (ibpm == NULL && ebpm) {
89 cpl_msg_warning(cpl_func,
"Image and error bad pixel mask "
90 "not equal, ignoring mask of error image");
94 return CPL_ERROR_NONE;
107 cpl_ensure(himg, CPL_ERROR_NULL_INPUT, NULL);
120 cpl_ensure(himg, CPL_ERROR_NULL_INPUT, NULL);
133 cpl_ensure(himg, CPL_ERROR_NULL_INPUT, NULL);
146 cpl_ensure(himg, CPL_ERROR_NULL_INPUT, NULL);
159 cpl_ensure(himg, CPL_ERROR_NULL_INPUT, NULL);
177 cpl_ensure(himg, CPL_ERROR_NULL_INPUT, NULL);
192hdrl_image_wrap(cpl_image * img, cpl_image * err, hdrl_free * destructor,
193 cpl_boolean sync_mask)
196 cpl_ensure(img, CPL_ERROR_NULL_INPUT, NULL);
197 cpl_ensure(err, CPL_ERROR_NULL_INPUT, NULL);
198 cpl_ensure(cpl_image_get_type(img) == HDRL_TYPE_DATA,
199 CPL_ERROR_INCOMPATIBLE_INPUT, NULL);
200 cpl_ensure(cpl_image_get_type(err) == HDRL_TYPE_ERROR,
201 CPL_ERROR_INCOMPATIBLE_INPUT, NULL);
203 himg = cpl_malloc(
sizeof(*himg));
208 himg->fp_free = destructor;
211 himg->fp_free = (hdrl_free*)_hdrl_image_delete;
215 _hdrl_image_sync_mask(himg);
228void hdrl_image_unwrap(hdrl_image * himg)
247static hdrl_image * _hdrl_image_create(
const cpl_image * image,
248 const cpl_image * error,
249 cpl_boolean check_consistent)
251 cpl_image * himage = NULL, * herror = NULL;
253 if (check_consistent && hdrl_image_check_consistent(image, error)) {
257 himage = cpl_image_cast(image, HDRL_TYPE_DATA);
259 herror = cpl_image_cast(error, HDRL_TYPE_ERROR);
263 herror = cpl_image_new(cpl_image_get_size_x(image),
264 cpl_image_get_size_y(image),
269 if (cpl_image_get_bpm_const(image)) {
270 cpl_image_reject_from_mask(herror,
271 cpl_image_get_bpm_const(image));
274 cpl_image_accept_all(herror);
277 return hdrl_image_wrap(himage, herror, NULL, CPL_FALSE);
296 const cpl_image * error)
298 return _hdrl_image_create(image, error, CPL_TRUE);
313 cpl_image * himage = cpl_image_new(nx, ny, HDRL_TYPE_DATA);
314 cpl_image * herror = cpl_image_new(nx, ny, HDRL_TYPE_ERROR);
316 if (cpl_error_get_code()) {
317 cpl_image_delete(himage);
318 cpl_image_delete(herror);
322 return hdrl_image_wrap(himage, herror, NULL, CPL_FALSE);
326hdrl_image_new_from_buffer(cpl_size nx, cpl_size ny, hdrl_buffer * buf)
328 char * p = hdrl_buffer_allocate(buf, nx * ny * (
sizeof(hdrl_data_t) +
329 sizeof(hdrl_error_t)));
330 cpl_image * himage = cpl_image_wrap(nx, ny, HDRL_TYPE_DATA, p);
331 cpl_image * herror = cpl_image_wrap(nx, ny, HDRL_TYPE_ERROR,
332 p + nx * ny *
sizeof(hdrl_data_t));
334 if (cpl_error_get_code()) {
335 cpl_image_delete(himage);
336 cpl_image_delete(herror);
340 return hdrl_image_wrap(himage, herror,
341 (hdrl_free*)&_hdrl_image_delete_buffer,
350static void _hdrl_image_delete(hdrl_image * himg)
353 cpl_image_delete(himg->image);
354 cpl_image_delete(himg->error);
364static void _hdrl_image_delete_buffer(hdrl_image * himg)
367 cpl_image_unwrap(himg->image);
368 cpl_image_unwrap(himg->error);
408 const cpl_mask * map)
428 cpl_size xpos, cpl_size ypos)
447 cpl_ensure(self, CPL_ERROR_NULL_INPUT, -1);
463 cpl_ensure(self, CPL_ERROR_NULL_INPUT, -1);
494 cpl_size xpos, cpl_size ypos)
512 return cpl_error_get_code();
560 cpl_size xpos, cpl_size ypos,
595 cpl_size xpos, cpl_size ypos,
599 cpl_ensure_code(value.error >= 0 || isnan(value.error), CPL_ERROR_ILLEGAL_INPUT);
602 return cpl_error_get_code();
626 const hdrl_image * self,
634 if (llx < 1) llx += nx;
635 if (lly < 1) lly += ny;
636 if (urx < 1) urx += nx;
637 if (ury < 1) ury += ny;
644 if (cpl_error_get_code()) {
645 cpl_image_delete(img);
646 cpl_image_delete(err);
650 return hdrl_image_wrap(img, err, NULL, CPL_FALSE);
665 cpl_ensure_code(self, CPL_ERROR_NULL_INPUT);
668 return cpl_error_get_code();
687 cpl_size xpos, cpl_size ypos)
689 cpl_ensure_code(dst, CPL_ERROR_NULL_INPUT);
690 cpl_ensure_code(src, CPL_ERROR_NULL_INPUT);
696 return cpl_error_get_code();
716 const cpl_image * image,
717 const cpl_image * error,
718 cpl_size xpos, cpl_size ypos)
720 cpl_ensure_code(self, CPL_ERROR_NULL_INPUT);
721 cpl_ensure_code(image, CPL_ERROR_NULL_INPUT);
727 if (cpl_image_get_bpm_const(image)) {
728 const cpl_mask * msrc = cpl_image_get_bpm_const(image);
730 cpl_mask_copy(mdst, msrc, xpos, ypos);
733 return cpl_error_get_code();
743static void _hdrl_image_sync_mask(hdrl_image * himg)
768 const hdrl_image * himg,
794 const hdrl_image * himg,
802 llx, lly, urx, ury, stream);
hdrl_value hdrl_image_get_pixel(const hdrl_image *self, cpl_size xpos, cpl_size ypos, int *pis_rejected)
get pixel values of hdrl_image
int hdrl_image_is_rejected(hdrl_image *self, cpl_size xpos, cpl_size ypos)
return if pixel is marked bad
cpl_error_code hdrl_image_set_pixel(hdrl_image *self, cpl_size xpos, cpl_size ypos, hdrl_value value)
set pixel values of hdrl_image
cpl_error_code hdrl_image_reject_value(hdrl_image *self, cpl_value mode)
Reject pixels with the specified special value(s)
cpl_error_code hdrl_image_reject_from_mask(hdrl_image *self, const cpl_mask *map)
set bpm of hdrl_image
cpl_error_code hdrl_image_turn(hdrl_image *self, int rot)
Rotate an image by a multiple of 90 degrees clockwise.
hdrl_image * hdrl_image_duplicate(const hdrl_image *himg)
copy hdrl_image
cpl_error_code hdrl_image_copy(hdrl_image *dst, const hdrl_image *src, cpl_size xpos, cpl_size ypos)
Copy one image into another.
cpl_mask * hdrl_image_get_mask(hdrl_image *himg)
get cpl bad pixel mask from image
hdrl_image * hdrl_image_extract(const hdrl_image *self, cpl_size llx, cpl_size lly, cpl_size urx, cpl_size ury)
extract copy of window from 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_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_error_code hdrl_image_insert(hdrl_image *self, const cpl_image *image, const cpl_image *error, cpl_size xpos, cpl_size ypos)
Copy cpl images into an hdrl image.
cpl_size hdrl_image_count_rejected(const hdrl_image *self)
return number of rejected pixels
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_image * hdrl_image_get_image(hdrl_image *himg)
get data as cpl image
cpl_error_code hdrl_image_reject(hdrl_image *self, cpl_size xpos, cpl_size ypos)
mark pixel as bad
const cpl_image * hdrl_image_get_image_const(const hdrl_image *himg)
get data as cpl image
hdrl_image * hdrl_image_new(cpl_size nx, cpl_size ny)
create new zero filled hdrl image
cpl_error_code hdrl_image_dump_structure(const hdrl_image *himg, FILE *stream)
Dump structural information of a HDRL image.
cpl_error_code hdrl_image_accept(hdrl_image *self, cpl_size xpos, cpl_size ypos)
mark pixel as good
void hdrl_image_delete(hdrl_image *himg)
delete hdrl_image
cpl_error_code hdrl_image_accept_all(hdrl_image *self)
Accept all pixels in an image.