ifw-odp  2.0.0-alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
clipm_priv_checks.c File Reference
#include "clipm_priv_checks.h"
#include "clipm_priv_error.h"
#include "clipm_priv_math.h"
#define _POSIX_C_SOURCE   200112L
 
#define max(a, b)   ((a) > (b) ? (a) : (b))
 
#define min(a, b)   ((a) < (b) ? (a) : (b))
 
int clipm_priv_checks_is_window_full_image (const cpl_size window_xxyy[4], const cpl_image *image)
 Check if window coordinates represent the whole image. More...
 
cpl_error_code clipm_priv_checks_window_image (const cpl_size window_xxyy[4], const cpl_image *image, int allow_window_NULL, cpl_size *img_size_xy, cpl_size *window_size_xy, cpl_size *buffer_start_xy)
 Check window coordinates with the corresponding image. More...
 
cpl_error_code clipm_priv_checks_window_minmax (const int window_xxyy[4], int ndims, int allow_window_NULL)
 Check coordinates for min/max condition. More...
 
cpl_error_code clipm_priv_checks_window_guarantee (cpl_size window_xxyy[4], cpl_size xsize, cpl_size ysize, cpl_size min_windowsize)
 Cut window coordinates to a FITS image range if outside, expand if necessary. More...
 
cpl_error_code clipm_priv_checks_window_guarantee_image (cpl_size window_xxyy[4], const cpl_image *image, cpl_size min_windowsize)
 Cut window coordinates to a FITS image range if outside, expand if necessary. More...
 
cpl_error_code clipm_priv_checks_window_guarantee_window (cpl_size window_xxyy[4], const cpl_size *ref_window, cpl_size min_windowsize)
 Cut window coordinates to an existing reference window range, expand if necessary. More...
 
cpl_error_code clipm_priv_checks_images_match (const cpl_image *img1, const cpl_image *img2, cpl_type *type, cpl_size *xsize, cpl_size *ysize)
 Check whether two images match in the requested features. More...
 
cpl_error_code clipm_priv_checks_imtype_any (const cpl_image *image, cpl_type *out_type)
 Check whether an image is of an allowed type. More...
 
cpl_error_code clipm_priv_checks_imtype_float (const cpl_image *image, cpl_type *out_type)
 Check whether an image is of a floating-point type. More...
 

Macro Definition Documentation

#define _POSIX_C_SOURCE   200112L
#define max (   a,
 
)    ((a) > (b) ? (a) : (b))
#define min (   a,
 
)    ((a) < (b) ? (a) : (b))

Function Documentation

cpl_error_code clipm_priv_checks_images_match ( const cpl_image *  img1,
const cpl_image *  img2,
cpl_type *  type,
cpl_size *  xsize,
cpl_size *  ysize 
)

Check whether two images match in the requested features.

Parameters
img1Image 1
img2Image 2
type(output) CPL type, can be NULL
xsize(output) Horizontal size, can be NULL
ysize(output) Vertical size, can be NULL
Returns
CPL error code
Error Handling:
The following error codes can be set:
  • CPL_ERROR_NULL_INPUT: img1 or img2 is NULL
  • CPL_ERROR_TYPE_MISMATCH: type != NULL and img1 and img2 don't have the same type
  • CPL_ERROR_INCOMPATIBLE_INPUT:
    • xsize != NULL and img1 and img2 differ in their horizontal size, or
    • ysize != NULL and img1 and img2 differ in their vertical size
cpl_error_code clipm_priv_checks_imtype_any ( const cpl_image *  image,
cpl_type *  out_type 
)

Check whether an image is of an allowed type.

Parameters
imageInput image
out_type(Optional output) image type
Returns
CPL error code
Error Handling:
The following error codes can be returned:
  • CPL_ERROR_NULL_INPUT: image is NULL
  • CPL_ERROR_INVALID_TYPE: image is neither of type CPL_TYPE_INT, CPL_TYPE_FLOAT, nor CPL_TYPE_DOUBLE
cpl_error_code clipm_priv_checks_imtype_float ( const cpl_image *  image,
cpl_type *  out_type 
)

Check whether an image is of a floating-point type.

Parameters
imageInput image
out_type(Optional output) image type
Returns
CPL error code
Error Handling:
The following error codes can be returned:
  • CPL_ERROR_NULL_INPUT: image is NULL
  • CPL_ERROR_INVALID_TYPE: image is neither of type CPL_TYPE_FLOAT nor CPL_TYPE_DOUBLE
int clipm_priv_checks_is_window_full_image ( const cpl_size  window_xxyy[4],
const cpl_image *  image 
)

Check if window coordinates represent the whole image.

Parameters
window_xxyyCoordinate buffer of the form {x1a, x1b, y1a, y1b}, minimum/maximum order is irrelevant
imageImage (FITS convention)
Returns
CPL error code
Principle:
If window_xxyy is != NULL and the coordinates in window_xxyy represent exactly the whole image plane, then 1 is returned. Otherwise 0 is returned.
Error Handling:
The following codes are set, if the check fails:
  • CPL_ERROR_NULL_INPUT: image is NULL
No error is set if window_xxyy is NULL or if the coordinates in window_xxyy are outside the image range.
cpl_error_code clipm_priv_checks_window_guarantee ( cpl_size  window_xxyy[4],
cpl_size  xsize,
cpl_size  ysize,
cpl_size  min_windowsize 
)

Cut window coordinates to a FITS image range if outside, expand if necessary.

Parameters
window_xxyyCoordinate buffer of the form {x1a, x1b, y1a, y1b} in FITS convention, minimum/maximum order is irrelevant
xsizeHorizontal image size
ysizeVertical image size
min_windowsizeMinimum window size
Returns
CPL error code
Principle:
This function cuts window coordinates so that they fit into a FITS image range:
  1. The window entries are ordered to {x_min, y_min, x_max, y_max}.
  2. If window is already smaller than min_windowsize, then it is expanded in the respective dimension.
  3. If window exceeds the FITS image range, it is cut.
  4. If, by the cutting, window gets smaller than min_windowsize in x or y, it is expanded into the opposite direction. This is to ensure a minimum window size for certain purposes, e.g. like gaussian fitting etc.
Error Handling:
The following error codes can be set and returned:
  • CPL_ERROR_NULL_INPUT: window is NULL
  • CPL_ERROR_ACCESS_OUT_OF_RANGE: min_windowsize > xsize or ysize
  • CPL_ERROR_ILLEGAL_INPUT: min_windowsize < 1
In the case of error, window is not modified.
cpl_error_code clipm_priv_checks_window_guarantee_image ( cpl_size  window_xxyy[4],
const cpl_image *  image,
cpl_size  min_windowsize 
)

Cut window coordinates to a FITS image range if outside, expand if necessary.

Parameters
window_xxyyCoordinate buffer of the form {x1a, x1b, y1a, y1b} in FITS convention, minimum/maximum order is irrelevant
imageThe reference image
min_windowsizeMinimum window size
Returns
CPL error code
See Also
For the complete documentation, please refer to clipm_priv_checks_window_guarantee(). If image is NULL, then also CPL_ERROR_NULL_INPUT is set and returned.
cpl_error_code clipm_priv_checks_window_guarantee_window ( cpl_size  window_xxyy[4],
const cpl_size *  ref_window,
cpl_size  min_windowsize 
)

Cut window coordinates to an existing reference window range, expand if necessary.

Parameters
window_xxyyCoordinate buffer of the form {x1a, x1b, y1a, y1b} in FITS convention, minimum/maximum order is irrelevant
ref_windowCoordinate buffer of the form {x1a, x1b, y1a, y1b} in FITS convention, minimum/maximum order is irrelevant
min_windowsizeMinimum window size
Returns
CPL error code
See Also
For the complete documentation, please refer to clipm_priv_checks_window_guarantee(). If image is NULL, then also CPL_ERROR_NULL_INPUT is set and returned.
cpl_error_code clipm_priv_checks_window_image ( const cpl_size  window_xxyy[4],
const cpl_image *  image,
int  allow_window_NULL,
cpl_size *  img_size_xy,
cpl_size *  window_size_xy,
cpl_size *  buffer_start_xy 
)

Check window coordinates with the corresponding image.

Parameters
window_xxyyCoordinate buffer of the form {x1a, x1b, y1a, y1b}, minimum/maximum order is irrelevant
imageImage (FITS convention)
allow_window_NULLIf !0, then no error is set if (window==NULL)
img_size_xyBuffer of size 2, to which the image size [x, y] is put out, can be NULL
window_size_xyBuffer of size 2, to which the window size is determined and written, can be NULL
buffer_start_xyBuffer of size 2, to which the lower left window indices are written, starting at 0 (not FITS), can be NULL
Returns
CPL error code
Overview:
  • The window coordinates are checked for being inside the image range.
  • If an input is NULL, or if the coordinates are out of range, then the appropriate CPL error is set and returned.
  • If out_window_size != NULL, then the window size is calculated and written to this buffer. If window_xxyy == NULL, then out_window_size is set to the image size!
Error Handling:
The following codes are set, if the check fails:
  • CPL_ERROR_NULL_INPUT: image and/or window_xxyy is NULL
  • CPL_ERROR_ACCESS_OUT_OF_RANGE: window coordinates are outside the image In the case of error, the output parameter values are undefined.
Note
  • This function does not check min/max conditions. Use clipm_priv_checks_window_minmax() for this purpose.
  • Specifying buffers of too small size (sizeof(window) < 4 || sizeof(out_img_size) < 2 || sizeof(out_window_size) < 2 || sizeof(out_buffer_start_xy) < 2) will crash the application!
cpl_error_code clipm_priv_checks_window_minmax ( const int  window_xxyy[4],
int  ndims,
int  allow_window_NULL 
)

Check coordinates for min/max condition.

Parameters
window_xxyyCoordinate buffer containing [xmin, xmax, ymin, ymax, zmin, zmax,...], its size must be 2*ndims
ndimsNumber of dimensions
allow_window_NULLIf > 0, then no error is set if (window==NULL)
Returns
CPL error code
Overview:
The min coordinates are checked for being <= the max coordinates. If they violate this, then CPL_ERROR_ACCESS_OUT_OF_RANGE is set and returned.
Error Handling:
The following codes are set, if the check fails:
  • CPL_ERROR_NULL_INPUT: image is NULL
Note
Specifying a buffer of too small size (sizeof(window) < 4) will crash the application!