📄 cvpyramids.c
字号:
row[1] = PD_SINGULAR( src[1], src[4] ); \
row[2] = PD_SINGULAR( src[2], src[5] ); \
} \
} \
} \
\
/* second pass. Do vertical conv and write results do destination image */ \
if( y > 0 ) \
{ \
if( y < size.height - PD_SZ/2 ) \
{ \
for( x = 0; x < Wdn; x++, x1++ ) \
{ \
dst[x] = (type)_pd_scale_( PD_FILTER( row01[x], row01[x1], \
row23[x], row23[x1], row4[x] )); \
} \
top_row += 2*buffer_step; \
top_row &= top_row < pd_sz ? -1 : 0; \
} \
else /* bottom */ \
for( x = 0; x < Wdn; x++, x1++ ) \
dst[x] = (type)_pd_scale_( PD_RB( row01[x], row01[x1], \
row23[x], row23[x1])); \
} \
else \
{ \
if( size.height > PD_SZ/2 ) /* top */ \
{ \
for( x = 0; x < Wdn; x++, x1++ ) \
dst[x] = (type)_pd_scale_( PD_LT( row01[x], row01[x1], row23[x] )); \
} \
else /* size.height <= PD_SZ/2 */ \
{ \
for( x = 0; x < Wdn; x++, x1++ ) \
dst[x] = (type)_pd_scale_( PD_SINGULAR( row01[x], row01[x1] )); \
} \
fst = PD_SZ - 2; \
} \
\
lst = y + 2 + PD_SZ/2 < size.height ? PD_SZ : size.height - y; \
} \
\
return CV_OK; \
}
ICV_DEF_PYR_DOWN_FUNC( 8u, uchar, int, PD_SCALE_INT )
ICV_DEF_PYR_DOWN_FUNC( 16s, short, int, PD_SCALE_INT )
ICV_DEF_PYR_DOWN_FUNC( 16u, ushort, int, PD_SCALE_INT )
ICV_DEF_PYR_DOWN_FUNC( 32f, float, float, PD_SCALE_FLT )
ICV_DEF_PYR_DOWN_FUNC( 64f, double, double, PD_SCALE_FLT )
/****************************************************************************************\
Up-sampling pyramids core functions
\****************************************************************************************/
/////////// filtering macros //////////////
/* COMMON CASE: NON ZERO */
/* 1/16[1 4 6 4 1] */
/* ...| x0 | 0 | x1 | 0 | x2 |... */
#define PU_FILTER( x0, x1, x2 ) ((x1)*6 + (x0) + (x2))
/* ZERO POINT AT CENTER */
/* 1/16[1 4 6 4 1] */
/* ...| 0 | x0 | 0 | x1 | 0 |... */
#define PU_FILTER_ZI( x0, x1 ) (((x0) + (x1))*4)
/* MACROS FOR BORDERS */
/* | b I a | b | reflection */
/* LEFT/TOP */
/* 1/16[1 4 6 4 1] */
/* | x1 | 0 I x0 | 0 | x1 |... */
#define PU_LT( x0, x1 ) ((x0)*6 + (x1)*2)
/* 1/16[1 4 6 4 1] */
/* | 0 I x0 | 0 | x1 | 0 |... */
#define PU_LT_ZI( x0, x1 ) PU_FILTER_ZI((x0),(x1))
/* RIGHT/BOTTOM: NON ZERO */
/* 1/16[1 4 6 4 1] */
/* ...| x0 | 0 | x1 | 0 I x1 | */
#define PU_RB( x0, x1 ) ((x0) + (x1)*7)
/* RIGHT/BOTTOM: ZERO POINT AT CENTER */
/* 1/16[1 4 6 4 1] */
/* ...| 0 | x0 | 0 I x0 | 0 | */
#define PU_RB_ZI( x0 ) ((x0)*8)
/* SINGULAR CASE */
/* 1/16[1 4 6 4 1] */
/* | x0 | 0 I x0 | 0 I x0 | */
#define PU_SINGULAR( x0 ) PU_RB_ZI((x0)) /* <--| the same formulas */
#define PU_SINGULAR_ZI( x0 ) PU_RB_ZI((x0)) /* <--| */
/* x/64 - scaling in up-sampling functions */
#define PU_SCALE_INT(x) (((x) + (1<<5)) >> 6)
#define PU_SCALE_FLT(x) ((x)*0.015625f)
#define PU_SZ 3
//////////// generic macro /////////////
#define ICV_DEF_PYR_UP_FUNC( flavor, type, worktype, _pu_scale_ ) \
static CvStatus CV_STDCALL \
icvPyrUpG5x5_##flavor##_CnR( const type* src, int srcstep, type* dst, \
int dststep, CvSize size, void *buf, int Cs ) \
{ \
worktype *buffer = (worktype*)buf; \
worktype *rows[PU_SZ]; \
int y, top_row = 0; \
int Wd = size.width * 2, Wdn = Wd * Cs, Wn = size.width * Cs; \
int buffer_step = Wdn; \
int pu_sz = PU_SZ*buffer_step; \
int fst = 0, lst = size.height <= PU_SZ/2 ? size.height : PU_SZ/2 + 1; \
\
assert( Cs == 1 || Cs == 3 ); \
srcstep /= sizeof(src[0]); dststep /= sizeof(dst[0]); \
\
/* main loop */ \
for( y = 0; y < size.height; y++, dst += 2 * dststep ) \
{ \
int x, y1, k = top_row; \
worktype *row0, *row1, *row2; \
type *dst1; \
\
/* assign rows pointers */ \
for( y1 = 0; y1 < PU_SZ; y1++ ) \
{ \
rows[y1] = buffer + k; \
k += buffer_step; \
k &= k < pu_sz ? -1 : 0; \
} \
\
row0 = rows[0]; \
row1 = rows[1]; \
row2 = rows[2]; \
dst1 = dst + dststep; \
\
/* fill new buffer rows with filtered source (horizontal conv) */ \
if( Cs == 1 ) \
if( size.width > PU_SZ / 2 ) \
for( y1 = fst; y1 < lst; y1++, src += srcstep ) \
{ \
worktype *row = rows[y1]; \
\
/* process left & right bounds */ \
row[0] = PU_LT( src[0], src[1] ); \
row[1] = PU_LT_ZI( src[0], src[1] ); \
row[size.width * 2 - 2] = PU_RB( src[size.width - 2], \
src[size.width - 1] ); \
row[size.width * 2 - 1] = PU_RB_ZI( src[size.width - 1] ); \
/* other points */ \
for( x = 1; x < size.width - 1; x++ ) \
{ \
row[2 * x] = PU_FILTER( src[x - 1], src[x], src[x + 1] ); \
row[2 * x + 1] = PU_FILTER_ZI( src[x], src[x + 1] ); \
} \
} \
else /* size.width <= PU_SZ/2 */ \
for( y1 = fst; y1 < lst; y1++, src += srcstep ) \
{ \
worktype *row = rows[y1]; \
worktype val = src[0]; \
\
row[0] = PU_SINGULAR( val ); \
row[1] = PU_SINGULAR_ZI( val ); \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -