Home | History | Annotate | Download | only in src
      1 /*M///////////////////////////////////////////////////////////////////////////////////////
      2 //
      3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
      4 //
      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.
      8 //
      9 //
     10 //                        Intel License Agreement
     11 //                For Open Source Computer Vision Library
     12 //
     13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
     14 // Third party copyrights are property of their respective owners.
     15 //
     16 // Redistribution and use in source and binary forms, with or without modification,
     17 // are permitted provided that the following conditions are met:
     18 //
     19 //   * Redistribution's of source code must retain the above copyright notice,
     20 //     this list of conditions and the following disclaimer.
     21 //
     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.
     25 //
     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.
     28 //
     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.
     39 //
     40 //M*/
     41 
     42 #ifndef _CXCORE_INTERNAL_H_
     43 #define _CXCORE_INTERNAL_H_
     44 
     45 #if defined _MSC_VER && _MSC_VER >= 1200
     46     /* disable warnings related to inline functions */
     47     #pragma warning( disable: 4711 4710 4514 )
     48 #endif
     49 
     50 typedef unsigned long ulong;
     51 
     52 #ifdef __BORLANDC__
     53     #define     WIN32
     54     #define     CV_DLL
     55     #undef      _CV_ALWAYS_PROFILE_
     56     #define     _CV_ALWAYS_NO_PROFILE_
     57 #endif
     58 
     59 #include "cxcore.h"
     60 #include "cxmisc.h"
     61 #include "_cxipp.h"
     62 #include <math.h>
     63 #include <assert.h>
     64 #include <string.h>
     65 #include <stdlib.h>
     66 #include <stdio.h>
     67 #include <limits.h>
     68 #include <float.h>
     69 
     70 // -128.f ... 255.f
     71 extern const float icv8x32fTab[];
     72 #define CV_8TO32F(x)  icv8x32fTab[(x)+128]
     73 
     74 extern const ushort icv8x16uSqrTab[];
     75 #define CV_SQR_8U(x)  icv8x16uSqrTab[(x)+255]
     76 
     77 extern const char* icvHersheyGlyphs[];
     78 
     79 extern const signed char icvDepthToType[];
     80 
     81 #define icvIplToCvDepth( depth ) \
     82     icvDepthToType[(((depth) & 255) >> 2) + ((depth) < 0)]
     83 
     84 extern const uchar icvSaturate8u[];
     85 #define CV_FAST_CAST_8U(t)   (assert(-256 <= (t) && (t) <= 512), icvSaturate8u[(t)+256])
     86 #define CV_MIN_8U(a,b)       ((a) - CV_FAST_CAST_8U((a) - (b)))
     87 #define CV_MAX_8U(a,b)       ((a) + CV_FAST_CAST_8U((b) - (a)))
     88 
     89 typedef CvFunc2D_3A1I CvArithmBinMaskFunc2D;
     90 typedef CvFunc2D_2A1P1I CvArithmUniMaskFunc2D;
     91 
     92 
     93 /****************************************************************************************\
     94 *                                   Complex arithmetics                                  *
     95 \****************************************************************************************/
     96 
     97 struct CvComplex32f;
     98 struct CvComplex64f;
     99 
    100 struct CvComplex32f
    101 {
    102     float re, im;
    103 
    104     CvComplex32f() {}
    105     CvComplex32f( float _re, float _im=0 ) : re(_re), im(_im) {}
    106     explicit CvComplex32f( const CvComplex64f& v );
    107     //CvComplex32f( const CvComplex32f& v ) : re(v.re), im(v.im) {}
    108     //CvComplex32f& operator = (const CvComplex32f& v ) { re = v.re; im = v.im; return *this; }
    109     operator CvComplex64f() const;
    110 };
    111 
    112 struct CvComplex64f
    113 {
    114     double re, im;
    115 
    116     CvComplex64f() {}
    117     CvComplex64f( double _re, double _im=0 ) : re(_re), im(_im) {}
    118     explicit CvComplex64f( const CvComplex32f& v );
    119     //CvComplex64f( const CvComplex64f& v ) : re(v.re), im(v.im) {}
    120     //CvComplex64f& operator = (const CvComplex64f& v ) { re = v.re; im = v.im; return *this; }
    121     operator CvComplex32f() const;
    122 };
    123 
    124 inline CvComplex32f::CvComplex32f( const CvComplex64f& v ) : re((float)v.re), im((float)v.im) {}
    125 inline CvComplex64f::CvComplex64f( const CvComplex32f& v ) : re(v.re), im(v.im) {}
    126 
    127 inline CvComplex32f operator + (CvComplex32f a, CvComplex32f b)
    128 {
    129     return CvComplex32f( a.re + b.re, a.im + b.im );
    130 }
    131 
    132 inline CvComplex32f& operator += (CvComplex32f& a, CvComplex32f b)
    133 {
    134     a.re += b.re;
    135     a.im += b.im;
    136     return a;
    137 }
    138 
    139 inline CvComplex32f operator - (CvComplex32f a, CvComplex32f b)
    140 {
    141     return CvComplex32f( a.re - b.re, a.im - b.im );
    142 }
    143 
    144 inline CvComplex32f& operator -= (CvComplex32f& a, CvComplex32f b)
    145 {
    146     a.re -= b.re;
    147     a.im -= b.im;
    148     return a;
    149 }
    150 
    151 inline CvComplex32f operator - (CvComplex32f a)
    152 {
    153     return CvComplex32f( -a.re, -a.im );
    154 }
    155 
    156 inline CvComplex32f operator * (CvComplex32f a, CvComplex32f b)
    157 {
    158     return CvComplex32f( a.re*b.re - a.im*b.im, a.re*b.im + a.im*b.re );
    159 }
    160 
    161 inline double abs(CvComplex32f a)
    162 {
    163     return sqrt( (double)a.re*a.re + (double)a.im*a.im );
    164 }
    165 
    166 inline CvComplex32f conj(CvComplex32f a)
    167 {
    168     return CvComplex32f( a.re, -a.im );
    169 }
    170 
    171 
    172 inline CvComplex32f operator / (CvComplex32f a, CvComplex32f b)
    173 {
    174     double t = 1./((double)b.re*b.re + (double)b.im*b.im);
    175     return CvComplex32f( (float)((a.re*b.re + a.im*b.im)*t),
    176                          (float)((-a.re*b.im + a.im*b.re)*t) );
    177 }
    178 
    179 inline CvComplex32f operator * (double a, CvComplex32f b)
    180 {
    181     return CvComplex32f( (float)(a*b.re), (float)(a*b.im) );
    182 }
    183 
    184 inline CvComplex32f operator * (CvComplex32f a, double b)
    185 {
    186     return CvComplex32f( (float)(a.re*b), (float)(a.im*b) );
    187 }
    188 
    189 inline CvComplex32f::operator CvComplex64f() const
    190 {
    191     return CvComplex64f(re,im);
    192 }
    193 
    194 
    195 inline CvComplex64f operator + (CvComplex64f a, CvComplex64f b)
    196 {
    197     return CvComplex64f( a.re + b.re, a.im + b.im );
    198 }
    199 
    200 inline CvComplex64f& operator += (CvComplex64f& a, CvComplex64f b)
    201 {
    202     a.re += b.re;
    203     a.im += b.im;
    204     return a;
    205 }
    206 
    207 inline CvComplex64f operator - (CvComplex64f a, CvComplex64f b)
    208 {
    209     return CvComplex64f( a.re - b.re, a.im - b.im );
    210 }
    211 
    212 inline CvComplex64f& operator -= (CvComplex64f& a, CvComplex64f b)
    213 {
    214     a.re -= b.re;
    215     a.im -= b.im;
    216     return a;
    217 }
    218 
    219 inline CvComplex64f operator - (CvComplex64f a)
    220 {
    221     return CvComplex64f( -a.re, -a.im );
    222 }
    223 
    224 inline CvComplex64f operator * (CvComplex64f a, CvComplex64f b)
    225 {
    226     return CvComplex64f( a.re*b.re - a.im*b.im, a.re*b.im + a.im*b.re );
    227 }
    228 
    229 inline double abs(CvComplex64f a)
    230 {
    231     return sqrt( (double)a.re*a.re + (double)a.im*a.im );
    232 }
    233 
    234 inline CvComplex64f operator / (CvComplex64f a, CvComplex64f b)
    235 {
    236     double t = 1./((double)b.re*b.re + (double)b.im*b.im);
    237     return CvComplex64f( (a.re*b.re + a.im*b.im)*t,
    238                          (-a.re*b.im + a.im*b.re)*t );
    239 }
    240 
    241 inline CvComplex64f operator * (double a, CvComplex64f b)
    242 {
    243     return CvComplex64f( a*b.re, a*b.im );
    244 }
    245 
    246 inline CvComplex64f operator * (CvComplex64f a, double b)
    247 {
    248     return CvComplex64f( a.re*b, a.im*b );
    249 }
    250 
    251 inline CvComplex64f::operator CvComplex32f() const
    252 {
    253     return CvComplex32f((float)re,(float)im);
    254 }
    255 
    256 inline CvComplex64f conj(CvComplex64f a)
    257 {
    258     return CvComplex64f( a.re, -a.im );
    259 }
    260 
    261 inline CvComplex64f operator + (CvComplex64f a, CvComplex32f b)
    262 {
    263     return CvComplex64f( a.re + b.re, a.im + b.im );
    264 }
    265 
    266 inline CvComplex64f operator + (CvComplex32f a, CvComplex64f b)
    267 {
    268     return CvComplex64f( a.re + b.re, a.im + b.im );
    269 }
    270 
    271 inline CvComplex64f operator - (CvComplex64f a, CvComplex32f b)
    272 {
    273     return CvComplex64f( a.re - b.re, a.im - b.im );
    274 }
    275 
    276 inline CvComplex64f operator - (CvComplex32f a, CvComplex64f b)
    277 {
    278     return CvComplex64f( a.re - b.re, a.im - b.im );
    279 }
    280 
    281 inline CvComplex64f operator * (CvComplex64f a, CvComplex32f b)
    282 {
    283     return CvComplex64f( a.re*b.re - a.im*b.im, a.re*b.im + a.im*b.re );
    284 }
    285 
    286 inline CvComplex64f operator * (CvComplex32f a, CvComplex64f b)
    287 {
    288     return CvComplex64f( a.re*b.re - a.im*b.im, a.re*b.im + a.im*b.re );
    289 }
    290 
    291 
    292 typedef CvStatus (CV_STDCALL * CvCopyMaskFunc)(const void* src, int src_step,
    293                                                void* dst, int dst_step, CvSize size,
    294                                                const void* mask, int mask_step);
    295 
    296 CvCopyMaskFunc icvGetCopyMaskFunc( int elem_size );
    297 
    298 CvStatus CV_STDCALL icvSetZero_8u_C1R( uchar* dst, int dststep, CvSize size );
    299 
    300 CvStatus CV_STDCALL icvScale_32f( const float* src, float* dst, int len, float a, float b );
    301 CvStatus CV_STDCALL icvScale_64f( const double* src, double* dst, int len, double a, double b );
    302 
    303 CvStatus CV_STDCALL icvLUT_Transform8u_8u_C1R( const uchar* src, int srcstep, uchar* dst,
    304                                                int dststep, CvSize size, const uchar* lut );
    305 CvStatus CV_STDCALL icvLUT_Transform8u_16u_C1R( const uchar* src, int srcstep, ushort* dst,
    306                                                 int dststep, CvSize size, const ushort* lut );
    307 CvStatus CV_STDCALL icvLUT_Transform8u_32s_C1R( const uchar* src, int srcstep, int* dst,
    308                                                 int dststep, CvSize size, const int* lut );
    309 CvStatus CV_STDCALL icvLUT_Transform8u_64f_C1R( const uchar* src, int srcstep, double* dst,
    310                                                 int dststep, CvSize size, const double* lut );
    311 
    312 CvStatus CV_STDCALL icvLUT_Transform8u_8u_C2R( const uchar* src, int srcstep, uchar* dst,
    313                                                int dststep, CvSize size, const uchar* lut );
    314 CvStatus CV_STDCALL icvLUT_Transform8u_8u_C3R( const uchar* src, int srcstep, uchar* dst,
    315                                                int dststep, CvSize size, const uchar* lut );
    316 CvStatus CV_STDCALL icvLUT_Transform8u_8u_C4R( const uchar* src, int srcstep, uchar* dst,
    317                                                int dststep, CvSize size, const uchar* lut );
    318 
    319 typedef CvStatus (CV_STDCALL * CvLUT_TransformFunc)( const void* src, int srcstep, void* dst,
    320                                                      int dststep, CvSize size, const void* lut );
    321 
    322 CV_INLINE CvStatus
    323 icvLUT_Transform8u_8s_C1R( const uchar* src, int srcstep, schar* dst,
    324                             int dststep, CvSize size, const schar* lut )
    325 {
    326     return icvLUT_Transform8u_8u_C1R( src, srcstep, (uchar*)dst,
    327                                       dststep, size, (const uchar*)lut );
    328 }
    329 
    330 CV_INLINE CvStatus
    331 icvLUT_Transform8u_16s_C1R( const uchar* src, int srcstep, short* dst,
    332                             int dststep, CvSize size, const short* lut )
    333 {
    334     return icvLUT_Transform8u_16u_C1R( src, srcstep, (ushort*)dst,
    335                                        dststep, size, (const ushort*)lut );
    336 }
    337 
    338 CV_INLINE CvStatus
    339 icvLUT_Transform8u_32f_C1R( const uchar* src, int srcstep, float* dst,
    340                             int dststep, CvSize size, const float* lut )
    341 {
    342     return icvLUT_Transform8u_32s_C1R( src, srcstep, (int*)dst,
    343                                        dststep, size, (const int*)lut );
    344 }
    345 
    346 #endif /*_CXCORE_INTERNAL_H_*/
    347