static void icvSumCol_32s16s( const int** src, short* dst, int dst_step, int count, void* params ) { CvBoxFilter* state = (CvBoxFilter*)params; int ksize = state->get_kernel_size().height; int ktotal = ksize*state->get_kernel_size().width; int i, width = state->get_width(); int cn = CV_MAT_CN(state->get_src_type()); int* sum = (int*)state->get_sum_buf(); int* _sum_count = state->get_sum_count_ptr(); int sum_count = *_sum_count; dst_step /= sizeof(dst[0]); width *= cn; src += sum_count; count += ksize - 1 - sum_count; for( ; count--; src++ ) { const int* sp = src[0]; if( sum_count+1 < ksize ) { for( i = 0; i <= width - 2; i += 2 ) { int s0 = sum[i] + sp[i], s1 = sum[i+1] + sp[i+1]; sum[i] = s0; sum[i+1] = s1; } for( ; i < width; i++ ) sum[i] += sp[i]; sum_count++; } else if( ktotal < 128 ) { const int* sm = src[-ksize+1]; for( i = 0; i <= width - 2; i += 2 ) { int s0 = sum[i] + sp[i], s1 = sum[i+1] + sp[i+1]; dst[i] = (short)s0; dst[i+1] = (short)s1; s0 -= sm[i]; s1 -= sm[i+1]; sum[i] = s0; sum[i+1] = s1; } for( ; i < width; i++ ) { int s0 = sum[i] + sp[i]; dst[i] = (short)s0; sum[i] = s0 - sm[i]; } dst += dst_step; } else { const int* sm = src[-ksize+1]; for( i = 0; i <= width - 2; i += 2 ) { int s0 = sum[i] + sp[i], s1 = sum[i+1] + sp[i+1]; dst[i] = CV_CAST_16S(s0); dst[i+1] = CV_CAST_16S(s1); s0 -= sm[i]; s1 -= sm[i+1]; sum[i] = s0; sum[i+1] = s1; } for( ; i < width; i++ ) { int s0 = sum[i] + sp[i]; dst[i] = CV_CAST_16S(s0); sum[i] = s0 - sm[i]; } dst += dst_step; } } *_sum_count = sum_count; }
// convert CvScalar to specified type void cvScalarToRawData( CvScalar* scalar, int flags, void* data, int extend_to_12 ) { CV_FUNCNAME( "cvScalarToRawData" ); __BEGIN__; int type = CV_ARR_TYPE( flags ); int cn = CV_ARR_CN( type ); int depth = type & CV_ARR_DEPTH_MASK; assert( scalar && data ); assert( (unsigned)(cn - 1) < 4 ); switch( depth ) { case CV_8UC1: while( cn-- ) { int t = cvRound( scalar->val[cn] ); ((uchar*)data)[cn] = CV_CAST_8U(t); } break; case CV_8SC1: while( cn-- ) { int t = cvRound( scalar->val[cn] ); ((char*)data)[cn] = CV_CAST_8S(t); } break; case CV_16SC1: while( cn-- ) { int t = cvRound( scalar->val[cn] ); ((short*)data)[cn] = CV_CAST_16S(t); } break; case CV_32SC1: while( cn-- ) ((int*)data)[cn] = cvRound( scalar->val[cn] ); break; case CV_32FC1: while( cn-- ) ((float*)data)[cn] = (float)(scalar->val[cn]); break; case CV_64FC1: while( cn-- ) ((double*)data)[cn] = (double)(scalar->val[cn]); break; default: assert(0); CV_ERROR_FROM_CODE( CV_BadDepth ); } if( extend_to_12 ) { int pix_size = icvPixSize[type]; int offset = icvPixSize[depth]*12; do { offset -= pix_size; memcpy( (char*)data + offset, data, pix_size ); } while( offset > pix_size ); } __END__; }