Repository: opencv/opencv
File: modules/features2d/src/hal_replacement.hpp (C++)

Code before:
/**
   @brief Non-maximum suppression for FAST_9_16.
   @param src_data,src_step Source mask
   @param dst_data,dst_step Destination mask after NMS
   @param width,height Source mask dimensions
*/
inline int hal_ni_FAST_NMS(const uchar* src_data, size_t src_step, uchar* dst_data, size_t dst_step, int width, int height) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }

//! @cond IGNORED
#define cv_hal_FAST_NMS hal_ni_FAST_NMS
//! @endcond

/**
   @brief Detects corners using the FAST algorithm.
   @param src_data Source image data
   @param src_step Source image step
   @param width Source image width
   @param height Source image height
   @param keypoints_data Pointer to keypoints
   @param keypoints_count Count of keypoints
   @param threshold Threshold for keypoint
   @param nonmax_suppression Indicates if make nonmaxima suppression or not.
   @param type FAST type
   @param realloc_func function for reallocation
*/
inline int hal_ni_FAST(const uchar* src_data, size_t src_step, int width, int height, void** keypoints_data, size_t* keypoints_count, int threshold, bool nonmax_suppression, int /*cv::FastFeatureDetector::DetectorType*/ type, void* (*realloc_func)(void*, size_t)) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }

//! @cond IGNORED
#define cv_hal_FAST hal_ni_FAST
//! @endcond

//! @}


#if defined(__clang__)
#pragma clang diagnostic pop
#elif defined(_MSC_VER)
#pragma warning(pop)
#elif defined(__GNUC__)
#pragma GCC diagnostic pop
#endif

#include "custom_hal.hpp"

//! @cond IGNORED
#define CALL_HAL_RET(name, fun, retval, ...) \
    int res = __CV_EXPAND(fun(__VA_ARGS__, &retval)); \
    if (res == CV_HAL_ERROR_OK) \
        return retval; \
    else if (res != CV_HAL_ERROR_NOT_IMPLEMENTED) \
        CV_Error_(cv::Error::StsInternal, \

Review comment (suggestion):
We usually presume backward compatibility in HAL. I propose to presume the original API and add new entrypoint with realloc, e.g. `hal_ni_FAST_withRealloc`.
On caller side you need to try the new one, then the old one and then default impl.

Code after:
/**
   @brief Non-maximum suppression for FAST_9_16.
   @param src_data,src_step Source mask
   @param dst_data,dst_step Destination mask after NMS
   @param width,height Source mask dimensions
*/
inline int hal_ni_FAST_NMS(const uchar* src_data, size_t src_step, uchar* dst_data, size_t dst_step, int width, int height) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }

//! @cond IGNORED
#define cv_hal_FAST_NMS hal_ni_FAST_NMS
//! @endcond

/**
   @brief Detects corners using the FAST algorithm.
   @param src_data Source image data
   @param src_step Source image step
   @param width Source image width
   @param height Source image height
   @param keypoints_data Pointer to keypoints
   @param keypoints_count Count of keypoints
   @param threshold Threshold for keypoint
   @param nonmax_suppression Indicates if make nonmaxima suppression or not.
   @param type FAST type
*/
inline int hal_ni_FAST(const uchar* src_data, size_t src_step, int width, int height, uchar* keypoints_data, size_t* keypoints_count, int threshold, bool nonmax_suppression, int /*cv::FastFeatureDetector::DetectorType*/ type) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }

/**
   @brief Detects corners using the FAST algorithm.
   @param src_data Source image data
   @param src_step Source image step
   @param width Source image width
   @param height Source image height
   @param keypoints_data Pointer to keypoints
   @param keypoints_count Count of keypoints
   @param threshold Threshold for keypoint
   @param nonmax_suppression Indicates if make nonmaxima suppression or not.
   @param type FAST type
   @param realloc_func function for reallocation
*/
inline int hal_ni_FASTv2(const uchar* src_data, size_t src_step, int width, int height, void** keypoints_data, size_t* keypoints_count, int threshold, bool nonmax_suppression, int /*cv::FastFeatureDetector::DetectorType*/ type, void* (*realloc_func)(void*, size_t)) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }

//! @cond IGNORED
#define cv_hal_FAST hal_ni_FAST
#define cv_hal_FASTv2 hal_ni_FASTv2
//! @endcond

//! @}


#if defined(__clang__)
#pragma clang diagnostic pop