📄 cxmatrix.cpp
字号:
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// Intel License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of Intel Corporation may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "_cxcore.h"
/****************************************************************************************\
* Matrix transpose *
\****************************************************************************************/
/////////////////// macros for inplace transposition of square matrix ////////////////////
#define ICV_DEF_TRANSP_INP_CASE_C1( \
arrtype, len ) \
{ \
arrtype* arr1 = arr; \
step /= sizeof(arr[0]); \
\
while( --len ) \
{ \
arr += step, arr1++; \
arrtype* arr2 = arr; \
arrtype* arr3 = arr1; \
\
do \
{ \
arrtype t0 = arr2[0]; \
arrtype t1 = arr3[0]; \
arr2[0] = t1; \
arr3[0] = t0; \
\
arr2++; \
arr3 += step; \
} \
while( arr2 != arr3 ); \
} \
}
#define ICV_DEF_TRANSP_INP_CASE_C3( \
arrtype, len ) \
{ \
arrtype* arr1 = arr; \
int y; \
step /= sizeof(arr[0]); \
\
for( y = 1; y < len; y++ ) \
{ \
arr += step, arr1 += 3; \
arrtype* arr2 = arr; \
arrtype* arr3 = arr1; \
\
for( ; arr2!=arr3; arr2+=3, \
arr3+=step )\
{ \
arrtype t0 = arr2[0]; \
arrtype t1 = arr3[0]; \
arr2[0] = t1; \
arr3[0] = t0; \
t0 = arr2[1]; \
t1 = arr3[1]; \
arr2[1] = t1; \
arr3[1] = t0; \
t0 = arr2[2]; \
t1 = arr3[2]; \
arr2[2] = t1; \
arr3[2] = t0; \
} \
} \
}
#define ICV_DEF_TRANSP_INP_CASE_C4( \
arrtype, len ) \
{ \
arrtype* arr1 = arr; \
int y; \
step /= sizeof(arr[0]); \
\
for( y = 1; y < len; y++ ) \
{ \
arr += step, arr1 += 4; \
arrtype* arr2 = arr; \
arrtype* arr3 = arr1; \
\
for( ; arr2!=arr3; arr2+=4, \
arr3+=step )\
{ \
arrtype t0 = arr2[0]; \
arrtype t1 = arr3[0]; \
arr2[0] = t1; \
arr3[0] = t0; \
t0 = arr2[1]; \
t1 = arr3[1]; \
arr2[1] = t1; \
arr3[1] = t0; \
t0 = arr2[2]; \
t1 = arr3[2]; \
arr2[2] = t1; \
arr3[2] = t0; \
t0 = arr2[3]; \
t1 = arr3[3]; \
arr2[3] = t1; \
arr3[3] = t0; \
} \
} \
}
//////////////// macros for non-inplace transposition of rectangular matrix //////////////
#define ICV_DEF_TRANSP_CASE_C1( arrtype ) \
{ \
int x, y; \
srcstep /= sizeof(src[0]); \
dststep /= sizeof(dst[0]); \
\
for( y = 0; y <= size.height - 2; y += 2, \
src += 2*srcstep, dst += 2 ) \
{ \
const arrtype* src1 = src + srcstep; \
arrtype* dst1 = dst; \
\
for( x = 0; x <= size.width - 2; \
x += 2, dst1 += dststep ) \
{ \
arrtype t0 = src[x]; \
arrtype t1 = src1[x]; \
dst1[0] = t0; \
dst1[1] = t1; \
dst1 += dststep; \
\
t0 = src[x + 1]; \
t1 = src1[x + 1]; \
dst1[0] = t0; \
dst1[1] = t1; \
} \
\
if( x < size.width ) \
{ \
arrtype t0 = src[x]; \
arrtype t1 = src1[x]; \
dst1[0] = t0; \
dst1[1] = t1; \
} \
} \
\
if( y < size.height ) \
{ \
arrtype* dst1 = dst; \
for( x = 0; x <= size.width - 2; \
x += 2, dst1 += 2*dststep ) \
{ \
arrtype t0 = src[x]; \
arrtype t1 = src[x + 1]; \
dst1[0] = t0; \
dst1[dststep] = t1; \
} \
\
if( x < size.width ) \
{ \
arrtype t0 = src[x]; \
dst1[0] = t0; \
} \
} \
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -