1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
44 #define ICV_DEF_ACC_FUNC( name, srctype, dsttype, cvtmacro ) \
45 IPCVAPI_IMPL( CvStatus, \
46 name,( const srctype *src, int srcstep, dsttype *dst, \
47 int dststep, CvSize size ), (src, srcstep, dst, dststep, size )) \
50 srcstep /= sizeof(src[0]); \
51 dststep /= sizeof(dst[0]); \
53 for( ; size.height--; src += srcstep, dst += dststep ) \
56 for( x = 0; x <= size.width - 4; x += 4 ) \
58 dsttype t0 = dst[x] + cvtmacro(src[x]); \
59 dsttype t1 = dst[x + 1] + cvtmacro(src[x + 1]); \
60 dst[x] = t0; dst[x + 1] = t1; \
62 t0 = dst[x + 2] + cvtmacro(src[x + 2]); \
63 t1 = dst[x + 3] + cvtmacro(src[x + 3]); \
64 dst[x + 2] = t0; dst[x + 3] = t1; \
67 for( ; x < size.width; x++ ) \
68 dst[x] += cvtmacro(src[x]); \
75 ICV_DEF_ACC_FUNC( icvAdd_8u32f_C1IR, uchar, float, CV_8TO32F )
76 ICV_DEF_ACC_FUNC( icvAdd_32f_C1IR, float, float, CV_NOP )
77 ICV_DEF_ACC_FUNC( icvAddSquare_8u32f_C1IR, uchar, float, CV_8TO32F_SQR )
78 ICV_DEF_ACC_FUNC( icvAddSquare_32f_C1IR, float, float, CV_SQR )
81 #define ICV_DEF_ACCPROD_FUNC( flavor, srctype, dsttype, cvtmacro ) \
82 IPCVAPI_IMPL( CvStatus, icvAddProduct_##flavor##_C1IR, \
83 ( const srctype *src1, int step1, const srctype *src2, int step2, \
84 dsttype *dst, int dststep, CvSize size ), \
85 (src1, step1, src2, step2, dst, dststep, size) ) \
87 step1 /= sizeof(src1[0]); \
88 step2 /= sizeof(src2[0]); \
89 dststep /= sizeof(dst[0]); \
91 for( ; size.height--; src1 += step1, src2 += step2, dst += dststep ) \
94 for( x = 0; x <= size.width - 4; x += 4 ) \
96 dsttype t0 = dst[x] + cvtmacro(src1[x])*cvtmacro(src2[x]); \
97 dsttype t1 = dst[x+1] + cvtmacro(src1[x+1])*cvtmacro(src2[x+1]);\
98 dst[x] = t0; dst[x + 1] = t1; \
100 t0 = dst[x + 2] + cvtmacro(src1[x + 2])*cvtmacro(src2[x + 2]); \
101 t1 = dst[x + 3] + cvtmacro(src1[x + 3])*cvtmacro(src2[x + 3]); \
102 dst[x + 2] = t0; dst[x + 3] = t1; \
105 for( ; x < size.width; x++ ) \
106 dst[x] += cvtmacro(src1[x])*cvtmacro(src2[x]); \
113 ICV_DEF_ACCPROD_FUNC( 8u32f, uchar, float, CV_8TO32F )
114 ICV_DEF_ACCPROD_FUNC( 32f, float, float, CV_NOP )
117 #define ICV_DEF_ACCWEIGHT_FUNC( flavor, srctype, dsttype, cvtmacro ) \
118 IPCVAPI_IMPL( CvStatus, icvAddWeighted_##flavor##_C1IR, \
119 ( const srctype *src, int srcstep, dsttype *dst, int dststep, \
120 CvSize size, dsttype alpha ), (src, srcstep, dst, dststep, size, alpha) )\
122 dsttype beta = (dsttype)(1 - alpha); \
123 srcstep /= sizeof(src[0]); \
124 dststep /= sizeof(dst[0]); \
126 for( ; size.height--; src += srcstep, dst += dststep ) \
129 for( x = 0; x <= size.width - 4; x += 4 ) \
131 dsttype t0 = dst[x]*beta + cvtmacro(src[x])*alpha; \
132 dsttype t1 = dst[x+1]*beta + cvtmacro(src[x+1])*alpha; \
133 dst[x] = t0; dst[x + 1] = t1; \
135 t0 = dst[x + 2]*beta + cvtmacro(src[x + 2])*alpha; \
136 t1 = dst[x + 3]*beta + cvtmacro(src[x + 3])*alpha; \
137 dst[x + 2] = t0; dst[x + 3] = t1; \
140 for( ; x < size.width; x++ ) \
141 dst[x] = dst[x]*beta + cvtmacro(src[x])*alpha; \
148 ICV_DEF_ACCWEIGHT_FUNC( 8u32f, uchar, float, CV_8TO32F )
149 ICV_DEF_ACCWEIGHT_FUNC( 32f, float, float, CV_NOP )
152 #define ICV_DEF_ACCMASK_FUNC_C1( name, srctype, dsttype, cvtmacro ) \
153 IPCVAPI_IMPL( CvStatus, \
154 name,( const srctype *src, int srcstep, const uchar* mask, int maskstep,\
155 dsttype *dst, int dststep, CvSize size ), \
156 (src, srcstep, mask, maskstep, dst, dststep, size )) \
158 srcstep /= sizeof(src[0]); \
159 dststep /= sizeof(dst[0]); \
161 for( ; size.height--; src += srcstep, \
162 dst += dststep, mask += maskstep ) \
165 for( x = 0; x <= size.width - 2; x += 2 ) \
168 dst[x] += cvtmacro(src[x]); \
170 dst[x+1] += cvtmacro(src[x+1]); \
173 for( ; x < size.width; x++ ) \
175 dst[x] += cvtmacro(src[x]); \
182 ICV_DEF_ACCMASK_FUNC_C1( icvAdd_8u32f_C1IMR, uchar, float, CV_8TO32F )
183 ICV_DEF_ACCMASK_FUNC_C1( icvAdd_32f_C1IMR, float, float, CV_NOP )
184 ICV_DEF_ACCMASK_FUNC_C1( icvAddSquare_8u32f_C1IMR, uchar, float, CV_8TO32F_SQR )
185 ICV_DEF_ACCMASK_FUNC_C1( icvAddSquare_32f_C1IMR, float, float, CV_SQR )
188 #define ICV_DEF_ACCPRODUCTMASK_FUNC_C1( flavor, srctype, dsttype, cvtmacro ) \
189 IPCVAPI_IMPL( CvStatus, icvAddProduct_##flavor##_C1IMR, \
190 ( const srctype *src1, int step1, const srctype* src2, int step2, \
191 const uchar* mask, int maskstep, dsttype *dst, int dststep, CvSize size ),\
192 (src1, step1, src2, step2, mask, maskstep, dst, dststep, size )) \
194 step1 /= sizeof(src1[0]); \
195 step2 /= sizeof(src2[0]); \
196 dststep /= sizeof(dst[0]); \
198 for( ; size.height--; src1 += step1, src2 += step2, \
199 dst += dststep, mask += maskstep ) \
202 for( x = 0; x <= size.width - 2; x += 2 ) \
205 dst[x] += cvtmacro(src1[x])*cvtmacro(src2[x]); \
207 dst[x+1] += cvtmacro(src1[x+1])*cvtmacro(src2[x+1]); \
210 for( ; x < size.width; x++ ) \
212 dst[x] += cvtmacro(src1[x])*cvtmacro(src2[x]); \
219 ICV_DEF_ACCPRODUCTMASK_FUNC_C1( 8u32f, uchar, float, CV_8TO32F )
220 ICV_DEF_ACCPRODUCTMASK_FUNC_C1( 32f, float, float, CV_NOP )
222 #define ICV_DEF_ACCWEIGHTMASK_FUNC_C1( flavor, srctype, dsttype, cvtmacro ) \
223 IPCVAPI_IMPL( CvStatus, icvAddWeighted_##flavor##_C1IMR, \
224 ( const srctype *src, int srcstep, const uchar* mask, int maskstep, \
225 dsttype *dst, int dststep, CvSize size, dsttype alpha ), \
226 (src, srcstep, mask, maskstep, dst, dststep, size, alpha )) \
228 dsttype beta = (dsttype)(1 - alpha); \
229 srcstep /= sizeof(src[0]); \
230 dststep /= sizeof(dst[0]); \
232 for( ; size.height--; src += srcstep, \
233 dst += dststep, mask += maskstep ) \
236 for( x = 0; x <= size.width - 2; x += 2 ) \
239 dst[x] = dst[x]*beta + cvtmacro(src[x])*alpha; \
241 dst[x+1] = dst[x+1]*beta + cvtmacro(src[x+1])*alpha; \
244 for( ; x < size.width; x++ ) \
246 dst[x] = dst[x]*beta + cvtmacro(src[x])*alpha; \
252 ICV_DEF_ACCWEIGHTMASK_FUNC_C1( 8u32f, uchar, float, CV_8TO32F )
253 ICV_DEF_ACCWEIGHTMASK_FUNC_C1( 32f, float, float, CV_NOP )
256 #define ICV_DEF_ACCMASK_FUNC_C3( name, srctype, dsttype, cvtmacro ) \
257 IPCVAPI_IMPL( CvStatus, \
258 name,( const srctype *src, int srcstep, const uchar* mask, int maskstep,\
259 dsttype *dst, int dststep, CvSize size ), \
260 (src, srcstep, mask, maskstep, dst, dststep, size )) \
262 srcstep /= sizeof(src[0]); \
263 dststep /= sizeof(dst[0]); \
265 for( ; size.height--; src += srcstep, \
266 dst += dststep, mask += maskstep ) \
269 for( x = 0; x < size.width; x++ ) \
272 dsttype t0, t1, t2; \
273 t0 = dst[x*3] + cvtmacro(src[x*3]); \
274 t1 = dst[x*3+1] + cvtmacro(src[x*3+1]); \
275 t2 = dst[x*3+2] + cvtmacro(src[x*3+2]); \
286 ICV_DEF_ACCMASK_FUNC_C3( icvAdd_8u32f_C3IMR, uchar, float, CV_8TO32F )
287 ICV_DEF_ACCMASK_FUNC_C3( icvAdd_32f_C3IMR, float, float, CV_NOP )
288 ICV_DEF_ACCMASK_FUNC_C3( icvAddSquare_8u32f_C3IMR, uchar, float, CV_8TO32F_SQR )
289 ICV_DEF_ACCMASK_FUNC_C3( icvAddSquare_32f_C3IMR, float, float, CV_SQR )
292 #define ICV_DEF_ACCPRODUCTMASK_FUNC_C3( flavor, srctype, dsttype, cvtmacro ) \
293 IPCVAPI_IMPL( CvStatus, icvAddProduct_##flavor##_C3IMR, \
294 ( const srctype *src1, int step1, const srctype* src2, int step2, \
295 const uchar* mask, int maskstep, dsttype *dst, int dststep, CvSize size ),\
296 (src1, step1, src2, step2, mask, maskstep, dst, dststep, size )) \
298 step1 /= sizeof(src1[0]); \
299 step2 /= sizeof(src2[0]); \
300 dststep /= sizeof(dst[0]); \
302 for( ; size.height--; src1 += step1, src2 += step2, \
303 dst += dststep, mask += maskstep ) \
306 for( x = 0; x < size.width; x++ ) \
309 dsttype t0, t1, t2; \
310 t0 = dst[x*3]+cvtmacro(src1[x*3])*cvtmacro(src2[x*3]); \
311 t1 = dst[x*3+1]+cvtmacro(src1[x*3+1])*cvtmacro(src2[x*3+1]);\
312 t2 = dst[x*3+2]+cvtmacro(src1[x*3+2])*cvtmacro(src2[x*3+2]);\
323 ICV_DEF_ACCPRODUCTMASK_FUNC_C3( 8u32f, uchar, float, CV_8TO32F )
324 ICV_DEF_ACCPRODUCTMASK_FUNC_C3( 32f, float, float, CV_NOP )
327 #define ICV_DEF_ACCWEIGHTMASK_FUNC_C3( flavor, srctype, dsttype, cvtmacro ) \
328 IPCVAPI_IMPL( CvStatus, icvAddWeighted_##flavor##_C3IMR, \
329 ( const srctype *src, int srcstep, const uchar* mask, int maskstep, \
330 dsttype *dst, int dststep, CvSize size, dsttype alpha ), \
331 (src, srcstep, mask, maskstep, dst, dststep, size, alpha )) \
333 dsttype beta = (dsttype)(1 - alpha); \
334 srcstep /= sizeof(src[0]); \
335 dststep /= sizeof(dst[0]); \
337 for( ; size.height--; src += srcstep, \
338 dst += dststep, mask += maskstep ) \
341 for( x = 0; x < size.width; x++ ) \
344 dsttype t0, t1, t2; \
345 t0 = dst[x*3]*beta + cvtmacro(src[x*3])*alpha; \
346 t1 = dst[x*3+1]*beta + cvtmacro(src[x*3+1])*alpha; \
347 t2 = dst[x*3+2]*beta + cvtmacro(src[x*3+2])*alpha; \
357 ICV_DEF_ACCWEIGHTMASK_FUNC_C3( 8u32f, uchar, float, CV_8TO32F )
358 ICV_DEF_ACCWEIGHTMASK_FUNC_C3( 32f, float, float, CV_NOP )
361 #define ICV_DEF_INIT_ACC_TAB( FUNCNAME ) \
362 static void icvInit##FUNCNAME##Table( CvFuncTable* tab, CvBigFuncTable* masktab ) \
364 tab->fn_2d[CV_8U] = (void*)icv##FUNCNAME##_8u32f_C1IR; \
365 tab->fn_2d[CV_32F] = (void*)icv##FUNCNAME##_32f_C1IR; \
367 masktab->fn_2d[CV_8UC1] = (void*)icv##FUNCNAME##_8u32f_C1IMR; \
368 masktab->fn_2d[CV_32FC1] = (void*)icv##FUNCNAME##_32f_C1IMR; \
370 masktab->fn_2d[CV_8UC3] = (void*)icv##FUNCNAME##_8u32f_C3IMR; \
371 masktab->fn_2d[CV_32FC3] = (void*)icv##FUNCNAME##_32f_C3IMR; \
375 ICV_DEF_INIT_ACC_TAB( Add )
376 ICV_DEF_INIT_ACC_TAB( AddSquare )
377 ICV_DEF_INIT_ACC_TAB( AddProduct )
378 ICV_DEF_INIT_ACC_TAB( AddWeighted )
382 cvAcc( const void* arr, void* sumarr, const void* maskarr )
384 static CvFuncTable acc_tab;
385 static CvBigFuncTable accmask_tab;
386 static int inittab = 0;
388 CV_FUNCNAME( "cvAcc" );
393 int mat_step, sum_step, mask_step = 0;
395 CvMat stub, *mat = (CvMat*)arr;
396 CvMat sumstub, *sum = (CvMat*)sumarr;
397 CvMat maskstub, *mask = (CvMat*)maskarr;
401 icvInitAddTable( &acc_tab, &accmask_tab );
405 if( !CV_IS_MAT( mat ) || !CV_IS_MAT( sum ))
407 int coi1 = 0, coi2 = 0;
408 CV_CALL( mat = cvGetMat( mat, &stub, &coi1 ));
409 CV_CALL( sum = cvGetMat( sum, &sumstub, &coi2 ));
410 if( coi1 + coi2 != 0 )
411 CV_ERROR( CV_BadCOI, "" );
414 if( CV_MAT_DEPTH( sum->type ) != CV_32F )
415 CV_ERROR( CV_BadDepth, "" );
417 if( !CV_ARE_CNS_EQ( mat, sum ))
418 CV_ERROR( CV_StsUnmatchedFormats, "" );
420 sumdepth = CV_MAT_DEPTH( sum->type );
421 if( sumdepth != CV_32F && (maskarr != 0 || sumdepth != CV_64F))
422 CV_ERROR( CV_BadDepth, "Bad accumulator type" );
424 if( !CV_ARE_SIZES_EQ( mat, sum ))
425 CV_ERROR( CV_StsUnmatchedSizes, "" );
427 size = cvGetMatSize( mat );
428 type = CV_MAT_TYPE( mat->type );
430 mat_step = mat->step;
431 sum_step = sum->step;
435 CvFunc2D_2A func=(CvFunc2D_2A)acc_tab.fn_2d[CV_MAT_DEPTH(type)];
438 CV_ERROR( CV_StsUnsupportedFormat, "Unsupported type combination" );
440 size.width *= CV_MAT_CN(type);
441 if( CV_IS_MAT_CONT( mat->type & sum->type ))
443 size.width *= size.height;
444 mat_step = sum_step = CV_STUB_STEP;
448 IPPI_CALL( func( mat->data.ptr, mat_step, sum->data.ptr, sum_step, size ));
452 CvFunc2D_3A func = (CvFunc2D_3A)accmask_tab.fn_2d[type];
455 CV_ERROR( CV_StsUnsupportedFormat, "" );
457 CV_CALL( mask = cvGetMat( mask, &maskstub ));
459 if( !CV_IS_MASK_ARR( mask ))
460 CV_ERROR( CV_StsBadMask, "" );
462 if( !CV_ARE_SIZES_EQ( mat, mask ))
463 CV_ERROR( CV_StsUnmatchedSizes, "" );
465 mask_step = mask->step;
467 if( CV_IS_MAT_CONT( mat->type & sum->type & mask->type ))
469 size.width *= size.height;
470 mat_step = sum_step = mask_step = CV_STUB_STEP;
474 IPPI_CALL( func( mat->data.ptr, mat_step, mask->data.ptr, mask_step,
475 sum->data.ptr, sum_step, size ));
483 cvSquareAcc( const void* arr, void* sq_sum, const void* maskarr )
485 static CvFuncTable acc_tab;
486 static CvBigFuncTable accmask_tab;
487 static int inittab = 0;
489 CV_FUNCNAME( "cvSquareAcc" );
495 int mat_step, sum_step, mask_step = 0;
497 CvMat stub, *mat = (CvMat*)arr;
498 CvMat sumstub, *sum = (CvMat*)sq_sum;
499 CvMat maskstub, *mask = (CvMat*)maskarr;
503 icvInitAddSquareTable( &acc_tab, &accmask_tab );
507 CV_CALL( mat = cvGetMat( mat, &stub, &coi1 ));
508 CV_CALL( sum = cvGetMat( sum, &sumstub, &coi2 ));
510 if( coi1 != 0 || coi2 != 0 )
511 CV_ERROR( CV_BadCOI, "" );
513 if( !CV_ARE_CNS_EQ( mat, sum ))
514 CV_ERROR( CV_StsUnmatchedFormats, "" );
516 if( CV_MAT_DEPTH( sum->type ) != CV_32F )
517 CV_ERROR( CV_BadDepth, "" );
519 if( !CV_ARE_SIZES_EQ( mat, sum ))
520 CV_ERROR( CV_StsUnmatchedSizes, "" );
522 size = cvGetMatSize( mat );
523 type = CV_MAT_TYPE( mat->type );
525 mat_step = mat->step;
526 sum_step = sum->step;
530 CvFunc2D_2A func = (CvFunc2D_2A)acc_tab.fn_2d[CV_MAT_DEPTH(type)];
533 CV_ERROR( CV_StsUnsupportedFormat, "" );
535 size.width *= CV_MAT_CN(type);
537 if( CV_IS_MAT_CONT( mat->type & sum->type ))
539 size.width *= size.height;
540 mat_step = sum_step = CV_STUB_STEP;;
544 IPPI_CALL( func( mat->data.ptr, mat_step, sum->data.ptr, sum_step, size ));
548 CvFunc2D_3A func = (CvFunc2D_3A)accmask_tab.fn_2d[type];
551 CV_ERROR( CV_StsUnsupportedFormat, "" );
553 CV_CALL( mask = cvGetMat( mask, &maskstub ));
555 if( !CV_IS_MASK_ARR( mask ))
556 CV_ERROR( CV_StsBadMask, "" );
558 if( !CV_ARE_SIZES_EQ( mat, mask ))
559 CV_ERROR( CV_StsUnmatchedSizes, "" );
561 mask_step = mask->step;
563 if( CV_IS_MAT_CONT( mat->type & sum->type & mask->type ))
565 size.width *= size.height;
566 mat_step = sum_step = mask_step = CV_STUB_STEP;
570 IPPI_CALL( func( mat->data.ptr, mat_step, mask->data.ptr, mask_step,
571 sum->data.ptr, sum_step, size ));
579 cvMultiplyAcc( const void* arrA, const void* arrB,
580 void* acc, const void* maskarr )
582 static CvFuncTable acc_tab;
583 static CvBigFuncTable accmask_tab;
584 static int inittab = 0;
586 CV_FUNCNAME( "cvMultiplyAcc" );
590 int coi1, coi2, coi3;
592 int mat1_step, mat2_step, sum_step, mask_step = 0;
594 CvMat stub1, *mat1 = (CvMat*)arrA;
595 CvMat stub2, *mat2 = (CvMat*)arrB;
596 CvMat sumstub, *sum = (CvMat*)acc;
597 CvMat maskstub, *mask = (CvMat*)maskarr;
601 icvInitAddProductTable( &acc_tab, &accmask_tab );
605 CV_CALL( mat1 = cvGetMat( mat1, &stub1, &coi1 ));
606 CV_CALL( mat2 = cvGetMat( mat2, &stub2, &coi2 ));
607 CV_CALL( sum = cvGetMat( sum, &sumstub, &coi3 ));
609 if( coi1 != 0 || coi2 != 0 || coi3 != 0 )
610 CV_ERROR( CV_BadCOI, "" );
612 if( !CV_ARE_CNS_EQ( mat1, mat2 ) || !CV_ARE_CNS_EQ( mat1, sum ))
613 CV_ERROR( CV_StsUnmatchedFormats, "" );
615 if( CV_MAT_DEPTH( sum->type ) != CV_32F )
616 CV_ERROR( CV_BadDepth, "" );
618 if( !CV_ARE_SIZES_EQ( mat1, sum ) || !CV_ARE_SIZES_EQ( mat2, sum ))
619 CV_ERROR( CV_StsUnmatchedSizes, "" );
621 size = cvGetMatSize( mat1 );
622 type = CV_MAT_TYPE( mat1->type );
624 mat1_step = mat1->step;
625 mat2_step = mat2->step;
626 sum_step = sum->step;
630 CvFunc2D_3A func = (CvFunc2D_3A)acc_tab.fn_2d[CV_MAT_DEPTH(type)];
633 CV_ERROR( CV_StsUnsupportedFormat, "" );
635 size.width *= CV_MAT_CN(type);
637 if( CV_IS_MAT_CONT( mat1->type & mat2->type & sum->type ))
639 size.width *= size.height;
640 mat1_step = mat2_step = sum_step = CV_STUB_STEP;
644 IPPI_CALL( func( mat1->data.ptr, mat1_step, mat2->data.ptr, mat2_step,
645 sum->data.ptr, sum_step, size ));
649 CvFunc2D_4A func = (CvFunc2D_4A)accmask_tab.fn_2d[type];
652 CV_ERROR( CV_StsUnsupportedFormat, "" );
654 CV_CALL( mask = cvGetMat( mask, &maskstub ));
656 if( !CV_IS_MASK_ARR( mask ))
657 CV_ERROR( CV_StsBadMask, "" );
659 if( !CV_ARE_SIZES_EQ( mat1, mask ))
660 CV_ERROR( CV_StsUnmatchedSizes, "" );
662 mask_step = mask->step;
664 if( CV_IS_MAT_CONT( mat1->type & mat2->type & sum->type & mask->type ))
666 size.width *= size.height;
667 mat1_step = mat2_step = sum_step = mask_step = CV_STUB_STEP;
671 IPPI_CALL( func( mat1->data.ptr, mat1_step, mat2->data.ptr, mat2_step,
672 mask->data.ptr, mask_step,
673 sum->data.ptr, sum_step, size ));
680 typedef CvStatus (CV_STDCALL *CvAddWeightedFunc)( const void* src, int srcstep,
681 void* dst, int dststep,
682 CvSize size, float alpha );
684 typedef CvStatus (CV_STDCALL *CvAddWeightedMaskFunc)( const void* src, int srcstep,
685 void* dst, int dststep,
686 const void* mask, int maskstep,
687 CvSize size, float alpha );
690 cvRunningAvg( const void* arrY, void* arrU,
691 double alpha, const void* maskarr )
693 static CvFuncTable acc_tab;
694 static CvBigFuncTable accmask_tab;
695 static int inittab = 0;
697 CV_FUNCNAME( "cvRunningAvg" );
703 int mat_step, sum_step, mask_step = 0;
705 CvMat stub, *mat = (CvMat*)arrY;
706 CvMat sumstub, *sum = (CvMat*)arrU;
707 CvMat maskstub, *mask = (CvMat*)maskarr;
711 icvInitAddWeightedTable( &acc_tab, &accmask_tab );
715 CV_CALL( mat = cvGetMat( mat, &stub, &coi1 ));
716 CV_CALL( sum = cvGetMat( sum, &sumstub, &coi2 ));
718 if( coi1 != 0 || coi2 != 0 )
719 CV_ERROR( CV_BadCOI, "" );
721 if( !CV_ARE_CNS_EQ( mat, sum ))
722 CV_ERROR( CV_StsUnmatchedFormats, "" );
724 if( CV_MAT_DEPTH( sum->type ) != CV_32F )
725 CV_ERROR( CV_BadDepth, "" );
727 if( !CV_ARE_SIZES_EQ( mat, sum ))
728 CV_ERROR( CV_StsUnmatchedSizes, "" );
730 size = cvGetMatSize( mat );
731 type = CV_MAT_TYPE( mat->type );
733 mat_step = mat->step;
734 sum_step = sum->step;
738 CvAddWeightedFunc func = (CvAddWeightedFunc)acc_tab.fn_2d[CV_MAT_DEPTH(type)];
741 CV_ERROR( CV_StsUnsupportedFormat, "" );
743 size.width *= CV_MAT_CN(type);
744 if( CV_IS_MAT_CONT( mat->type & sum->type ))
746 size.width *= size.height;
747 mat_step = sum_step = CV_STUB_STEP;
751 IPPI_CALL( func( mat->data.ptr, mat_step,
752 sum->data.ptr, sum_step, size, (float)alpha ));
756 CvAddWeightedMaskFunc func = (CvAddWeightedMaskFunc)accmask_tab.fn_2d[type];
759 CV_ERROR( CV_StsUnsupportedFormat, "" );
761 CV_CALL( mask = cvGetMat( mask, &maskstub ));
763 if( !CV_IS_MASK_ARR( mask ))
764 CV_ERROR( CV_StsBadMask, "" );
766 if( !CV_ARE_SIZES_EQ( mat, mask ))
767 CV_ERROR( CV_StsUnmatchedSizes, "" );
769 mask_step = mask->step;
771 if( CV_IS_MAT_CONT( mat->type & sum->type & mask->type ))
773 size.width *= size.height;
774 mat_step = sum_step = mask_step = CV_STUB_STEP;
778 IPPI_CALL( func( mat->data.ptr, mat_step, mask->data.ptr, mask_step,
779 sum->data.ptr, sum_step, size, (float)alpha ));