Skip to content

Commit 9ca3982

Browse files
committed
core: divUp function
1 parent 2e608b1 commit 9ca3982

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

modules/core/include/opencv2/core/utility.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,23 @@ static inline size_t alignSize(size_t sz, int n)
444444
return (sz + n-1) & -n;
445445
}
446446

447+
/** @brief Integer division with result round up.
448+
449+
Use this function instead of `ceil((float)a / b)` expressions.
450+
451+
@sa alignSize
452+
*/
453+
static inline int divUp(int a, unsigned int b)
454+
{
455+
CV_DbgAssert(a >= 0);
456+
return (a + b - 1) / b;
457+
}
458+
/** @overload */
459+
static inline size_t divUp(size_t a, unsigned int b)
460+
{
461+
return (a + b - 1) / b;
462+
}
463+
447464
/** @brief Enables or disables the optimized code.
448465
449466
The function can be used to dynamically turn on and off optimized code (code that uses SSE2, AVX,

modules/core/src/matrix.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3406,11 +3406,6 @@ static TransposeInplaceFunc transposeInplaceTab[] =
34063406

34073407
#ifdef HAVE_OPENCL
34083408

3409-
static inline int divUp(int a, int b)
3410-
{
3411-
return (a + b - 1) / b;
3412-
}
3413-
34143409
static bool ocl_transpose( InputArray _src, OutputArray _dst )
34153410
{
34163411
const ocl::Device & dev = ocl::Device::getDefault();

modules/photo/src/fast_nlmeans_denoising_opencl.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ enum
2323
CTA_SIZE_DEFAULT = 256
2424
};
2525

26-
static int divUp(int a, int b)
27-
{
28-
return (a + b - 1) / b;
29-
}
30-
3126
template <typename FT, typename ST, typename WT>
3227
static bool ocl_calcAlmostDist2Weight(UMat & almostDist2Weight,
3328
int searchWindowSize, int templateWindowSize,

0 commit comments

Comments
 (0)