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.
42 /* ////////////////////////////////////////////////////////////////////
44 // CvMat basic operations: cvCopy, cvSet
50 /////////////////////////////////////////////////////////////////////////////////////////
52 // L/L COPY & SET FUNCTIONS //
54 /////////////////////////////////////////////////////////////////////////////////////////
57 IPCVAPI_IMPL( CvStatus, icvCopy_8u_C1R, ( const uchar* src, int srcstep,
58 uchar* dst, int dststep, CvSize size ),
59 (src, srcstep, dst, dststep, size) )
61 for( ; size.height--; src += srcstep, dst += dststep )
62 memcpy( dst, src, size.width );
68 static CvStatus CV_STDCALL
69 icvSet_8u_C1R( uchar* dst, int dst_step, CvSize size,
70 const void* scalar, int pix_size )
72 int copy_len = 12*pix_size;
73 uchar* dst_limit = dst + size.width;
77 while( dst + copy_len <= dst_limit )
79 memcpy( dst, scalar, copy_len );
83 memcpy( dst, scalar, dst_limit - dst );
88 dst = dst_limit - size.width + dst_step;
90 for( ; size.height--; dst += dst_step )
91 memcpy( dst, dst - dst_step, size.width );
98 /////////////////////////////////////////////////////////////////////////////////////////
100 // L/L COPY WITH MASK FUNCTIONS //
102 /////////////////////////////////////////////////////////////////////////////////////////
105 #define ICV_DEF_COPY_MASK_C1_CASE( type ) \
106 for( i = 0; i <= size.width-2; i += 2 ) \
111 dst[i+1] = src[i+1]; \
114 for( ; i < size.width; i++ ) \
120 #define ICV_DEF_COPY_MASK_C3_CASE( type ) \
121 for( i = 0; i < size.width; i++ ) \
124 type t0 = src[i*3]; \
125 type t1 = src[i*3+1]; \
126 type t2 = src[i*3+2]; \
135 #define ICV_DEF_COPY_MASK_C4_CASE( type ) \
136 for( i = 0; i < size.width; i++ ) \
139 type t0 = src[i*4]; \
140 type t1 = src[i*4+1]; \
151 #define ICV_DEF_COPY_MASK_2D( name, type, cn ) \
152 IPCVAPI_IMPL( CvStatus, \
153 name,( const type* src, int srcstep, type* dst, int dststep,\
154 CvSize size, const uchar* mask, int maskstep ), \
155 (src, srcstep, dst, dststep, size, mask, maskstep)) \
157 srcstep /= sizeof(src[0]); dststep /= sizeof(dst[0]); \
158 for( ; size.height--; src += srcstep, \
159 dst += dststep, mask += maskstep ) \
162 ICV_DEF_COPY_MASK_C##cn##_CASE( type ) \
169 #define ICV_DEF_SET_MASK_C1_CASE( type ) \
170 for( i = 0; i <= size.width-2; i += 2 ) \
178 for( ; i < size.width; i++ ) \
185 #define ICV_DEF_SET_MASK_C3_CASE( type ) \
186 for( i = 0; i < size.width; i++ ) \
194 #define ICV_DEF_SET_MASK_C4_CASE( type ) \
195 for( i = 0; i < size.width; i++ ) \
204 #define ICV_DEF_SET_MASK_2D( name, type, cn ) \
205 IPCVAPI_IMPL( CvStatus, \
206 name,( type* dst, int dststep, \
207 const uchar* mask, int maskstep, \
208 CvSize size, const type* scalar ), \
209 (dst, dststep, mask, maskstep, size, scalar))\
211 CV_UN_ENTRY_C##cn( type ); \
212 dststep /= sizeof(dst[0]); \
214 for( ; size.height--; mask += maskstep, \
218 ICV_DEF_SET_MASK_C##cn##_CASE( type ) \
225 ICV_DEF_SET_MASK_2D( icvSet_8u_C1MR, uchar, 1 )
226 ICV_DEF_SET_MASK_2D( icvSet_16s_C1MR, ushort, 1 )
227 ICV_DEF_SET_MASK_2D( icvSet_8u_C3MR, uchar, 3 )
228 ICV_DEF_SET_MASK_2D( icvSet_8u_C4MR, int, 1 )
229 ICV_DEF_SET_MASK_2D( icvSet_16s_C3MR, ushort, 3 )
230 ICV_DEF_SET_MASK_2D( icvSet_16s_C4MR, int64, 1 )
231 ICV_DEF_SET_MASK_2D( icvSet_32f_C3MR, int, 3 )
232 ICV_DEF_SET_MASK_2D( icvSet_32f_C4MR, int, 4 )
233 ICV_DEF_SET_MASK_2D( icvSet_64s_C3MR, int64, 3 )
234 ICV_DEF_SET_MASK_2D( icvSet_64s_C4MR, int64, 4 )
236 ICV_DEF_COPY_MASK_2D( icvCopy_8u_C1MR, uchar, 1 )
237 ICV_DEF_COPY_MASK_2D( icvCopy_16s_C1MR, ushort, 1 )
238 ICV_DEF_COPY_MASK_2D( icvCopy_8u_C3MR, uchar, 3 )
239 ICV_DEF_COPY_MASK_2D( icvCopy_8u_C4MR, int, 1 )
240 ICV_DEF_COPY_MASK_2D( icvCopy_16s_C3MR, ushort, 3 )
241 ICV_DEF_COPY_MASK_2D( icvCopy_16s_C4MR, int64, 1 )
242 ICV_DEF_COPY_MASK_2D( icvCopy_32f_C3MR, int, 3 )
243 ICV_DEF_COPY_MASK_2D( icvCopy_32f_C4MR, int, 4 )
244 ICV_DEF_COPY_MASK_2D( icvCopy_64s_C3MR, int64, 3 )
245 ICV_DEF_COPY_MASK_2D( icvCopy_64s_C4MR, int64, 4 )
247 #define CV_DEF_INIT_COPYSET_TAB_2D( FUNCNAME, FLAG ) \
248 static void icvInit##FUNCNAME##FLAG##Table( CvBtFuncTable* table ) \
250 table->fn_2d[1] = (void*)icv##FUNCNAME##_8u_C1##FLAG; \
251 table->fn_2d[2] = (void*)icv##FUNCNAME##_16s_C1##FLAG; \
252 table->fn_2d[3] = (void*)icv##FUNCNAME##_8u_C3##FLAG; \
253 table->fn_2d[4] = (void*)icv##FUNCNAME##_8u_C4##FLAG; \
254 table->fn_2d[6] = (void*)icv##FUNCNAME##_16s_C3##FLAG; \
255 table->fn_2d[8] = (void*)icv##FUNCNAME##_16s_C4##FLAG; \
256 table->fn_2d[12] = (void*)icv##FUNCNAME##_32f_C3##FLAG; \
257 table->fn_2d[16] = (void*)icv##FUNCNAME##_32f_C4##FLAG; \
258 table->fn_2d[24] = (void*)icv##FUNCNAME##_64s_C3##FLAG; \
259 table->fn_2d[32] = (void*)icv##FUNCNAME##_64s_C4##FLAG; \
262 CV_DEF_INIT_COPYSET_TAB_2D( Set, MR )
263 CV_DEF_INIT_COPYSET_TAB_2D( Copy, MR )
265 /////////////////////////////////////////////////////////////////////////////////////////
267 // H/L COPY & SET FUNCTIONS //
269 /////////////////////////////////////////////////////////////////////////////////////////
273 icvGetCopyMaskFunc( int elem_size )
275 static CvBtFuncTable copym_tab;
276 static int inittab = 0;
280 icvInitCopyMRTable( ©m_tab );
283 return (CvCopyMaskFunc)copym_tab.fn_2d[elem_size];
289 cvCopy( const void* srcarr, void* dstarr, const void* maskarr )
291 CV_FUNCNAME( "cvCopy" );
296 CvMat srcstub, *src = (CvMat*)srcarr;
297 CvMat dststub, *dst = (CvMat*)dstarr;
300 if( !CV_IS_MAT(src) || !CV_IS_MAT(dst) )
302 if( CV_IS_SPARSE_MAT(src) && CV_IS_SPARSE_MAT(dst))
304 CvSparseMat* src1 = (CvSparseMat*)src;
305 CvSparseMat* dst1 = (CvSparseMat*)dst;
306 CvSparseMatIterator iterator;
309 dst1->dims = src1->dims;
310 memcpy( dst1->size, src1->size, src1->dims*sizeof(src1->size[0]));
311 dst1->valoffset = src1->valoffset;
312 dst1->idxoffset = src1->idxoffset;
313 cvClearSet( dst1->heap );
315 if( src1->heap->active_count >= dst1->hashsize*CV_SPARSE_HASH_RATIO )
317 CV_CALL( cvFree( &dst1->hashtable ));
318 dst1->hashsize = src1->hashsize;
319 CV_CALL( dst1->hashtable =
320 (void**)cvAlloc( dst1->hashsize*sizeof(dst1->hashtable[0])));
323 memset( dst1->hashtable, 0, dst1->hashsize*sizeof(dst1->hashtable[0]));
325 for( node = cvInitSparseMatIterator( src1, &iterator );
326 node != 0; node = cvGetNextSparseNode( &iterator ))
328 CvSparseNode* node_copy = (CvSparseNode*)cvSetNew( dst1->heap );
329 int tabidx = node->hashval & (dst1->hashsize - 1);
330 CV_MEMCPY_AUTO( node_copy, node, dst1->heap->elem_size );
331 node_copy->next = (CvSparseNode*)dst1->hashtable[tabidx];
332 dst1->hashtable[tabidx] = node_copy;
336 else if( CV_IS_MATND(src) || CV_IS_MATND(dst) )
338 CvArr* arrs[] = { src, dst };
340 CvNArrayIterator iterator;
342 CV_CALL( cvInitNArrayIterator( 2, arrs, maskarr, stubs, &iterator ));
343 pix_size = CV_ELEM_SIZE(iterator.hdr[0]->type);
347 iterator.size.width *= pix_size;
348 if( iterator.size.width <= CV_MAX_INLINE_MAT_OP_SIZE*(int)sizeof(double))
352 memcpy( iterator.ptr[1], iterator.ptr[0], iterator.size.width );
354 while( cvNextNArraySlice( &iterator ));
360 icvCopy_8u_C1R( iterator.ptr[0], CV_STUB_STEP,
361 iterator.ptr[1], CV_STUB_STEP, iterator.size );
363 while( cvNextNArraySlice( &iterator ));
368 CvCopyMaskFunc func = icvGetCopyMaskFunc( pix_size );
370 CV_ERROR( CV_StsUnsupportedFormat, "" );
374 func( iterator.ptr[0], CV_STUB_STEP,
375 iterator.ptr[1], CV_STUB_STEP,
377 iterator.ptr[2], CV_STUB_STEP );
379 while( cvNextNArraySlice( &iterator ));
385 int coi1 = 0, coi2 = 0;
386 CV_CALL( src = cvGetMat( src, &srcstub, &coi1 ));
387 CV_CALL( dst = cvGetMat( dst, &dststub, &coi2 ));
391 CvArr* planes[] = { 0, 0, 0, 0 };
394 CV_ERROR( CV_StsBadArg, "COI + mask are not supported" );
396 planes[coi1-1] = dst;
397 CV_CALL( cvSplit( src, planes[0], planes[1], planes[2], planes[3] ));
402 CvArr* planes[] = { 0, 0, 0, 0 };
405 CV_ERROR( CV_StsBadArg, "COI + mask are not supported" );
407 planes[coi2-1] = src;
408 CV_CALL( cvMerge( planes[0], planes[1], planes[2], planes[3], dst ));
414 if( !CV_ARE_TYPES_EQ( src, dst ))
415 CV_ERROR_FROM_CODE( CV_StsUnmatchedFormats );
417 if( !CV_ARE_SIZES_EQ( src, dst ))
418 CV_ERROR_FROM_CODE( CV_StsUnmatchedSizes );
420 size = cvGetMatSize( src );
421 pix_size = CV_ELEM_SIZE(src->type);
425 int src_step = src->step, dst_step = dst->step;
426 size.width *= pix_size;
427 if( CV_IS_MAT_CONT( src->type & dst->type ) && (src_step == dst_step) && (src_step == src->width * pix_size))
429 size.width *= size.height;
431 if( size.width <= CV_MAX_INLINE_MAT_OP_SIZE*
432 CV_MAX_INLINE_MAT_OP_SIZE*(int)sizeof(double))
434 memcpy( dst->data.ptr, src->data.ptr, size.width );
439 src_step = dst_step = CV_STUB_STEP;
442 if( src->data.ptr != dst->data.ptr )
443 icvCopy_8u_C1R( src->data.ptr, src_step,
444 dst->data.ptr, dst_step, size );
448 CvCopyMaskFunc func = icvGetCopyMaskFunc(pix_size);
449 CvMat maskstub, *mask = (CvMat*)maskarr;
450 int src_step = src->step;
451 int dst_step = dst->step;
454 if( !CV_IS_MAT( mask ))
455 CV_CALL( mask = cvGetMat( mask, &maskstub ));
456 if( !CV_IS_MASK_ARR( mask ))
457 CV_ERROR( CV_StsBadMask, "" );
459 if( !CV_ARE_SIZES_EQ( src, mask ))
460 CV_ERROR( CV_StsUnmatchedSizes, "" );
462 mask_step = mask->step;
464 if( CV_IS_MAT_CONT( src->type & dst->type & mask->type ))
466 size.width *= size.height;
468 src_step = dst_step = mask_step = CV_STUB_STEP;
472 CV_ERROR( CV_StsUnsupportedFormat, "" );
474 IPPI_CALL( func( src->data.ptr, src_step, dst->data.ptr, dst_step,
475 size, mask->data.ptr, mask_step ));
482 /* dst(idx) = value */
484 cvSet( void* arr, CvScalar value, const void* maskarr )
486 static CvBtFuncTable setm_tab;
487 static int inittab = 0;
489 CV_FUNCNAME( "cvSet" );
493 CvMat stub, *mat = (CvMat*)arr;
499 if( !value.val[0] && !value.val[1] &&
500 !value.val[2] && !value.val[3] && !maskarr )
508 if( CV_IS_MATND(mat))
511 CvNArrayIterator iterator;
514 CV_CALL( cvInitNArrayIterator( 1, &arr, maskarr, &nstub, &iterator ));
516 type = CV_MAT_TYPE(iterator.hdr[0]->type);
517 pix_size1 = CV_ELEM_SIZE1(type);
518 pix_size = pix_size1*CV_MAT_CN(type);
520 CV_CALL( cvScalarToRawData( &value, buf, type, maskarr == 0 ));
524 iterator.size.width *= pix_size;
527 icvSet_8u_C1R( iterator.ptr[0], CV_STUB_STEP,
528 iterator.size, buf, pix_size1 );
530 while( cvNextNArraySlice( &iterator ));
534 CvFunc2D_2A1P func = (CvFunc2D_2A1P)(setm_tab.fn_2d[pix_size]);
536 CV_ERROR( CV_StsUnsupportedFormat, "" );
540 func( iterator.ptr[0], CV_STUB_STEP,
541 iterator.ptr[1], CV_STUB_STEP,
542 iterator.size, buf );
544 while( cvNextNArraySlice( &iterator ));
551 CV_CALL( mat = cvGetMat( mat, &stub, &coi ));
554 CV_ERROR( CV_BadCOI, "" );
558 type = CV_MAT_TYPE( mat->type );
559 pix_size = CV_ELEM_SIZE(type);
560 size = cvGetMatSize( mat );
561 mat_step = mat->step;
565 if( CV_IS_MAT_CONT( mat->type ))
567 size.width *= size.height;
569 if( size.width <= (int)(CV_MAX_INLINE_MAT_OP_SIZE*sizeof(double)))
571 if( type == CV_32FC1 )
573 float* dstdata = (float*)(mat->data.ptr);
574 float val = (float)value.val[0];
578 dstdata[size.width-1] = val;
580 while( --size.width );
585 if( type == CV_64FC1 )
587 double* dstdata = (double*)(mat->data.ptr);
588 double val = value.val[0];
592 dstdata[size.width-1] = val;
594 while( --size.width );
600 mat_step = CV_STUB_STEP;
604 size.width *= pix_size;
605 CV_CALL( cvScalarToRawData( &value, buf, type, 1 ));
607 IPPI_CALL( icvSet_8u_C1R( mat->data.ptr, mat_step, size, buf,
608 CV_ELEM_SIZE1(type)));
613 CvMat maskstub, *mask = (CvMat*)maskarr;
616 CV_CALL( mask = cvGetMat( mask, &maskstub ));
618 if( !CV_IS_MASK_ARR( mask ))
619 CV_ERROR( CV_StsBadMask, "" );
623 icvInitSetMRTable( &setm_tab );
627 if( !CV_ARE_SIZES_EQ( mat, mask ))
628 CV_ERROR( CV_StsUnmatchedSizes, "" );
630 mask_step = mask->step;
632 if( CV_IS_MAT_CONT( mat->type & mask->type ))
634 size.width *= size.height;
635 mat_step = mask_step = CV_STUB_STEP;
639 func = (CvFunc2D_2A1P)(setm_tab.fn_2d[pix_size]);
641 CV_ERROR( CV_StsUnsupportedFormat, "" );
643 CV_CALL( cvScalarToRawData( &value, buf, type, 0 ));
645 IPPI_CALL( func( mat->data.ptr, mat_step, mask->data.ptr,
646 mask_step, size, buf ));
653 /****************************************************************************************\
655 \****************************************************************************************/
657 icvSetByte_8u_C1R_t icvSetByte_8u_C1R_p = 0;
660 icvSetZero_8u_C1R( uchar* dst, int dststep, CvSize size )
662 if( size.width + size.height > 256 && icvSetByte_8u_C1R_p )
663 return icvSetByte_8u_C1R_p( 0, dst, dststep, size );
665 for( ; size.height--; dst += dststep )
666 memset( dst, 0, size.width );
672 cvSetZero( CvArr* arr )
674 CV_FUNCNAME( "cvSetZero" );
678 CvMat stub, *mat = (CvMat*)arr;
682 if( !CV_IS_MAT( mat ))
684 if( CV_IS_MATND(mat))
687 CvNArrayIterator iterator;
689 CV_CALL( cvInitNArrayIterator( 1, &arr, 0, &nstub, &iterator ));
690 iterator.size.width *= CV_ELEM_SIZE(iterator.hdr[0]->type);
692 if( iterator.size.width <= CV_MAX_INLINE_MAT_OP_SIZE*(int)sizeof(double) )
696 memset( iterator.ptr[0], 0, iterator.size.width );
698 while( cvNextNArraySlice( &iterator ));
704 icvSetZero_8u_C1R( iterator.ptr[0], CV_STUB_STEP, iterator.size );
706 while( cvNextNArraySlice( &iterator ));
710 else if( CV_IS_SPARSE_MAT(mat))
712 CvSparseMat* mat1 = (CvSparseMat*)mat;
713 cvClearSet( mat1->heap );
714 if( mat1->hashtable )
715 memset( mat1->hashtable, 0, mat1->hashsize*sizeof(mat1->hashtable[0]));
721 CV_CALL( mat = cvGetMat( mat, &stub, &coi ));
723 CV_ERROR( CV_BadCOI, "coi is not supported" );
727 size = cvGetMatSize( mat );
728 size.width *= CV_ELEM_SIZE(mat->type);
729 mat_step = mat->step;
731 if( CV_IS_MAT_CONT( mat->type ))
733 size.width *= size.height;
735 if( size.width <= CV_MAX_INLINE_MAT_OP_SIZE*(int)sizeof(double) )
737 memset( mat->data.ptr, 0, size.width );
741 mat_step = CV_STUB_STEP;
745 IPPI_CALL( icvSetZero_8u_C1R( mat->data.ptr, mat_step, size ));
751 /****************************************************************************************\
753 \****************************************************************************************/
755 #define ICV_DEF_FLIP_HZ_CASE_C1( type ) \
756 for( i = 0; i < (len+1)/2; i++ ) \
759 type t1 = src[len - i - 1]; \
761 dst[len - i - 1] = t0; \
765 #define ICV_DEF_FLIP_HZ_CASE_C3( type ) \
766 for( i = 0; i < (len+1)/2; i++ ) \
768 type t0 = src[i*3]; \
769 type t1 = src[(len - i)*3 - 3]; \
771 dst[(len - i)*3 - 3] = t0; \
773 t1 = src[(len - i)*3 - 2]; \
775 dst[(len - i)*3 - 2] = t0; \
777 t1 = src[(len - i)*3 - 1]; \
779 dst[(len - i)*3 - 1] = t0; \
783 #define ICV_DEF_FLIP_HZ_CASE_C4( type ) \
784 for( i = 0; i < (len+1)/2; i++ ) \
786 type t0 = src[i*4]; \
787 type t1 = src[(len - i)*4 - 4]; \
789 dst[(len - i)*4 - 4] = t0; \
791 t1 = src[(len - i)*4 - 3]; \
793 dst[(len - i)*4 - 3] = t0; \
795 t1 = src[(len - i)*4 - 2]; \
797 dst[(len - i)*4 - 2] = t0; \
799 t1 = src[(len - i)*4 - 1]; \
801 dst[(len - i)*4 - 1] = t0; \
805 #define ICV_DEF_FLIP_HZ_FUNC( flavor, arrtype, cn ) \
806 static CvStatus CV_STDCALL \
807 icvFlipHorz_##flavor( const arrtype* src, int srcstep, \
808 arrtype* dst, int dststep, CvSize size ) \
810 int i, len = size.width; \
811 srcstep /= sizeof(src[0]); dststep /= sizeof(dst[0]); \
813 for( ; size.height--; src += srcstep, dst += dststep ) \
815 ICV_DEF_FLIP_HZ_CASE_C##cn( arrtype ) \
822 ICV_DEF_FLIP_HZ_FUNC( 8u_C1R, uchar, 1 )
823 ICV_DEF_FLIP_HZ_FUNC( 8u_C2R, ushort, 1 )
824 ICV_DEF_FLIP_HZ_FUNC( 8u_C3R, uchar, 3 )
825 ICV_DEF_FLIP_HZ_FUNC( 16u_C2R, int, 1 )
826 ICV_DEF_FLIP_HZ_FUNC( 16u_C3R, ushort, 3 )
827 ICV_DEF_FLIP_HZ_FUNC( 32s_C2R, int64, 1 )
828 ICV_DEF_FLIP_HZ_FUNC( 32s_C3R, int, 3 )
829 ICV_DEF_FLIP_HZ_FUNC( 64s_C2R, int, 4 )
830 ICV_DEF_FLIP_HZ_FUNC( 64s_C3R, int64, 3 )
831 ICV_DEF_FLIP_HZ_FUNC( 64s_C4R, int64, 4 )
833 CV_DEF_INIT_PIXSIZE_TAB_2D( FlipHorz, R )
837 icvFlipVert_8u_C1R( const uchar* src, int srcstep,
838 uchar* dst, int dststep, CvSize size )
841 const uchar* src1 = src + (size.height - 1)*srcstep;
842 uchar* dst1 = dst + (size.height - 1)*dststep;
844 for( y = 0; y < (size.height + 1)/2; y++, src += srcstep, src1 -= srcstep,
845 dst += dststep, dst1 -= dststep )
848 if( ((size_t)(src)|(size_t)(dst)|(size_t)src1|(size_t)dst1) % sizeof(int) == 0 )
850 for( ; i <= size.width - 16; i += 16 )
852 int t0 = ((int*)(src + i))[0];
853 int t1 = ((int*)(src1 + i))[0];
855 ((int*)(dst + i))[0] = t1;
856 ((int*)(dst1 + i))[0] = t0;
858 t0 = ((int*)(src + i))[1];
859 t1 = ((int*)(src1 + i))[1];
861 ((int*)(dst + i))[1] = t1;
862 ((int*)(dst1 + i))[1] = t0;
864 t0 = ((int*)(src + i))[2];
865 t1 = ((int*)(src1 + i))[2];
867 ((int*)(dst + i))[2] = t1;
868 ((int*)(dst1 + i))[2] = t0;
870 t0 = ((int*)(src + i))[3];
871 t1 = ((int*)(src1 + i))[3];
873 ((int*)(dst + i))[3] = t1;
874 ((int*)(dst1 + i))[3] = t0;
877 for( ; i <= size.width - 4; i += 4 )
879 int t0 = ((int*)(src + i))[0];
880 int t1 = ((int*)(src1 + i))[0];
882 ((int*)(dst + i))[0] = t1;
883 ((int*)(dst1 + i))[0] = t0;
887 for( ; i < size.width; i++ )
902 cvFlip( const CvArr* srcarr, CvArr* dstarr, int flip_mode )
904 static CvBtFuncTable tab;
905 static int inittab = 0;
907 CV_FUNCNAME( "cvFlip" );
911 CvMat sstub, *src = (CvMat*)srcarr;
912 CvMat dstub, *dst = (CvMat*)dstarr;
914 CvFunc2D_2A func = 0;
919 icvInitFlipHorzRTable( &tab );
923 if( !CV_IS_MAT( src ))
926 CV_CALL( src = cvGetMat( src, &sstub, &coi ));
928 CV_ERROR( CV_BadCOI, "coi is not supported" );
933 else if( !CV_IS_MAT( dst ))
936 CV_CALL( dst = cvGetMat( dst, &dstub, &coi ));
938 CV_ERROR( CV_BadCOI, "coi is not supported" );
941 if( !CV_ARE_TYPES_EQ( src, dst ))
942 CV_ERROR( CV_StsUnmatchedFormats, "" );
944 if( !CV_ARE_SIZES_EQ( src, dst ))
945 CV_ERROR( CV_StsUnmatchedSizes, "" );
947 size = cvGetMatSize( src );
948 pix_size = CV_ELEM_SIZE( src->type );
952 size.width *= pix_size;
954 IPPI_CALL( icvFlipVert_8u_C1R( src->data.ptr, src->step,
955 dst->data.ptr, dst->step, size ));
959 int inplace = src->data.ptr == dst->data.ptr;
960 uchar* dst_data = dst->data.ptr;
961 int dst_step = dst->step;
963 func = (CvFunc2D_2A)(tab.fn_2d[pix_size]);
966 CV_ERROR( CV_StsUnsupportedFormat, "" );
968 if( flip_mode < 0 && !inplace )
970 dst_data += dst_step * (dst->height - 1);
971 dst_step = -dst_step;
974 IPPI_CALL( func( src->data.ptr, src->step, dst_data, dst_step, size ));
976 if( flip_mode < 0 && inplace )
978 size.width *= pix_size;
979 IPPI_CALL( icvFlipVert_8u_C1R( dst->data.ptr, dst->step,
980 dst->data.ptr, dst->step, size ));
989 cvRepeat( const CvArr* srcarr, CvArr* dstarr )
991 CV_FUNCNAME( "cvRepeat" );
995 CvMat sstub, *src = (CvMat*)srcarr;
996 CvMat dstub, *dst = (CvMat*)dstarr;
997 CvSize srcsize, dstsize;
1001 if( !CV_IS_MAT( src ))
1004 CV_CALL( src = cvGetMat( src, &sstub, &coi ));
1006 CV_ERROR( CV_BadCOI, "coi is not supported" );
1009 if( !CV_IS_MAT( dst ))
1012 CV_CALL( dst = cvGetMat( dst, &dstub, &coi ));
1014 CV_ERROR( CV_BadCOI, "coi is not supported" );
1017 if( !CV_ARE_TYPES_EQ( src, dst ))
1018 CV_ERROR( CV_StsUnmatchedFormats, "" );
1020 srcsize = cvGetMatSize( src );
1021 dstsize = cvGetMatSize( dst );
1022 pix_size = CV_ELEM_SIZE( src->type );
1024 for( y = 0, k = 0; y < dstsize.height; y++ )
1026 for( x = 0; x < dstsize.width; x += srcsize.width )
1029 if( l > dstsize.width - x )
1030 l = dstsize.width - x;
1031 memcpy( dst->data.ptr + y*dst->step + x*pix_size,
1032 src->data.ptr + k*src->step, l*pix_size );
1034 if( ++k == srcsize.height )