Merge commit '0566ab4d3d' into merge-2.4
authorRoman Donchenko <roman.donchenko@itseez.com>
Mon, 30 Dec 2013 12:51:46 +0000 (16:51 +0400)
committerRoman Donchenko <roman.donchenko@itseez.com>
Mon, 30 Dec 2013 12:51:46 +0000 (16:51 +0400)
Conflicts:
modules/core/src/system.cpp

1  2 
modules/core/src/system.cpp
modules/ocl/src/gftt.cpp

@@@ -107,7 -107,7 +107,7 @@@ std::wstring GetTempPathWinRT(
      if (FAILED(WindowsCreateStringReference(RuntimeClass_Windows_Storage_ApplicationData,
                                              (UINT32)wcslen(RuntimeClass_Windows_Storage_ApplicationData), &hstrHead, &str)))
          return wstr;
-     if (FAILED(Windows::Foundation::GetActivationFactory(str, appdataFactory.ReleaseAndGetAddressOf())))
+     if (FAILED(RoGetActivationFactory(str, IID_PPV_ARGS(appdataFactory.ReleaseAndGetAddressOf()))))
          return wstr;
      if (FAILED(appdataFactory->get_Current(appdataRef.ReleaseAndGetAddressOf())))
          return wstr;
@@@ -177,7 -177,7 +177,7 @@@ namespace c
  
  Exception::Exception() { code = 0; line = 0; }
  
 -Exception::Exception(int _code, const string& _err, const string& _func, const string& _file, int _line)
 +Exception::Exception(int _code, const String& _err, const String& _func, const String& _file, int _line)
  : code(_code), err(_err), func(_func), file(_file), line(_line)
  {
      formatMessage();
@@@ -404,36 -404,24 +404,36 @@@ int64 getCPUTickCount(void
  
  #endif
  
 -const std::string& getBuildInformation()
 +const String& getBuildInformation()
  {
 -    static std::string build_info =
 +    static String build_info =
  #include "version_string.inc"
      ;
      return build_info;
  }
  
 -string format( const char* fmt, ... )
 +String format( const char* fmt, ... )
  {
 -    char buf[1 << 16];
 -    va_list args;
 -    va_start( args, fmt );
 -    vsprintf( buf, fmt, args );
 -    return string(buf);
 +    char buf[1024];
 +
 +    va_list va;
 +    va_start(va, fmt);
 +    int len = vsnprintf(buf, sizeof(buf), fmt, va);
 +    va_end(va);
 +
 +    if (len >= (int)sizeof(buf))
 +    {
 +        String s(len, '\0');
 +        va_start(va, fmt);
 +        len = vsnprintf((char*)s.c_str(), len + 1, fmt, va);
 +        va_end(va);
 +        return s;
 +    }
 +
 +    return String(buf, len);
  }
  
 -string tempfile( const char* suffix )
 +String tempfile( const char* suffix )
  {
  #ifdef HAVE_WINRT
      std::wstring temp_dir = L"";
          temp_dir = std::wstring(opencv_temp_dir);
  #else
      const char *temp_dir = getenv("OPENCV_TEMP_PATH");
 +    String fname;
  #endif
 -    string fname;
  
  #if defined WIN32 || defined _WIN32
  #ifdef HAVE_WINRT
          temp_dir = temp_dir2;
      }
      if(0 == ::GetTempFileNameA(temp_dir, "ocv", 0, temp_file))
 -        return string();
 +        return String();
  
      DeleteFileA(temp_file);
  
          fname = temp_dir;
          char ech = fname[fname.size() - 1];
          if(ech != '/' && ech != '\\')
 -            fname += "/";
 -        fname += "__opencv_temp.XXXXXX";
 +            fname = fname + "/";
 +        fname = fname + "__opencv_temp.XXXXXX";
      }
  
      const int fd = mkstemp((char*)fname.c_str());
 -    if (fd == -1) return string();
 +    if (fd == -1) return String();
  
      close(fd);
      remove(fname.c_str());
@@@ -557,11 -545,6 +557,11 @@@ void error( const Exception& exc 
      throw exc;
  }
  
 +void error(int _code, const String& _err, const char* _func, const char* _file, int _line)
 +{
 +    error(cv::Exception(_code, _err, _func, _file, _line));
 +}
 +
  CvErrorCallback
  redirectError( CvErrorCallback errCallback, void* userdata, void** prevUserdata)
  {
@@@ -665,7 -648,7 +665,7 @@@ CV_IMPL const char* cvErrorStr( int sta
      case CV_StsNotImplemented :      return "The function/feature is not implemented";
      case CV_StsBadMemBlock :         return "Memory block has been corrupted";
      case CV_StsAssert :              return "Assertion failed";
 -    case CV_GpuNotSupported :        return "No GPU support";
 +    case CV_GpuNotSupported :        return "No CUDA support";
      case CV_GpuApiCallError :        return "Gpu API call";
      case CV_OpenGlNotSupported :     return "No OpenGL support";
      case CV_OpenGlApiCallError :     return "OpenGL API call";
@@@ -734,8 -717,124 +734,8 @@@ cvErrorFromIppStatus( int status 
      }
  }
  
 -static CvModuleInfo cxcore_info = { 0, "cxcore", CV_VERSION, 0 };
 -
 -CvModuleInfo* CvModule::first = 0, *CvModule::last = 0;
 -
 -CvModule::CvModule( CvModuleInfo* _info )
 -{
 -    cvRegisterModule( _info );
 -    info = last;
 -}
 -
 -CvModule::~CvModule(void)
 -{
 -    if( info )
 -    {
 -        CvModuleInfo* p = first;
 -        for( ; p != 0 && p->next != info; p = p->next )
 -            ;
 -
 -        if( p )
 -            p->next = info->next;
 -
 -        if( first == info )
 -            first = info->next;
 -
 -        if( last == info )
 -            last = p;
 -
 -        free( info );
 -        info = 0;
 -    }
 -}
 -
 -CV_IMPL int
 -cvRegisterModule( const CvModuleInfo* module )
 -{
 -    CV_Assert( module != 0 && module->name != 0 && module->version != 0 );
 -
 -    size_t name_len = strlen(module->name);
 -    size_t version_len = strlen(module->version);
 -
 -    CvModuleInfo* module_copy = (CvModuleInfo*)malloc( sizeof(*module_copy) +
 -                                name_len + 1 + version_len + 1 );
 -
 -    *module_copy = *module;
 -    module_copy->name = (char*)(module_copy + 1);
 -    module_copy->version = (char*)(module_copy + 1) + name_len + 1;
 -
 -    memcpy( (void*)module_copy->name, module->name, name_len + 1 );
 -    memcpy( (void*)module_copy->version, module->version, version_len + 1 );
 -    module_copy->next = 0;
 -
 -    if( CvModule::first == 0 )
 -        CvModule::first = module_copy;
 -    else
 -        CvModule::last->next = module_copy;
 -
 -    CvModule::last = module_copy;
 -
 -    return 0;
 -}
 -
 -CvModule cxcore_module( &cxcore_info );
 -
 -CV_IMPL void
 -cvGetModuleInfo( const char* name, const char **version, const char **plugin_list )
 -{
 -    static char joint_verinfo[1024]   = "";
 -    static char plugin_list_buf[1024] = "";
 -
 -    if( version )
 -        *version = 0;
 -
 -    if( plugin_list )
 -        *plugin_list = 0;
 -
 -    CvModuleInfo* module;
 -
 -    if( version )
 -    {
 -        if( name )
 -        {
 -            size_t i, name_len = strlen(name);
 -
 -            for( module = CvModule::first; module != 0; module = module->next )
 -            {
 -                if( strlen(module->name) == name_len )
 -                {
 -                    for( i = 0; i < name_len; i++ )
 -                    {
 -                        int c0 = toupper(module->name[i]), c1 = toupper(name[i]);
 -                        if( c0 != c1 )
 -                            break;
 -                    }
 -                    if( i == name_len )
 -                        break;
 -                }
 -            }
 -            if( !module )
 -                CV_Error( CV_StsObjectNotFound, "The module is not found" );
 -
 -            *version = module->version;
 -        }
 -        else
 -        {
 -            char* ptr = joint_verinfo;
 -
 -            for( module = CvModule::first; module != 0; module = module->next )
 -            {
 -                sprintf( ptr, "%s: %s%s", module->name, module->version, module->next ? ", " : "" );
 -                ptr += strlen(ptr);
 -            }
 -
 -            *version = joint_verinfo;
 -        }
 -    }
 -
 -    if( plugin_list )
 -        *plugin_list = plugin_list_buf;
 +namespace cv {
 +bool __termination = false;
  }
  
  namespace cv
@@@ -764,27 -863,61 +764,27 @@@ struct Mutex::Imp
      int refcount;
  };
  
 -#ifndef __GNUC__
 -int _interlockedExchangeAdd(int* addr, int delta)
 -{
 -#if defined _MSC_VER && _MSC_VER >= 1500
 -    return (int)_InterlockedExchangeAdd((long volatile*)addr, delta);
  #else
 -    return (int)InterlockedExchangeAdd((long volatile*)addr, delta);
 -#endif
 -}
 -#endif // __GNUC__
 -
 -#elif defined __APPLE__
 -
 -#include <libkern/OSAtomic.h>
 -
 -struct Mutex::Impl
 -{
 -    Impl() { sl = OS_SPINLOCK_INIT; refcount = 1; }
 -    ~Impl() {}
 -
 -    void lock() { OSSpinLockLock(&sl); }
 -    bool trylock() { return OSSpinLockTry(&sl); }
 -    void unlock() { OSSpinLockUnlock(&sl); }
 -
 -    OSSpinLock sl;
 -    int refcount;
 -};
 -
 -#elif defined __linux__ && !defined ANDROID
  
  struct Mutex::Impl
  {
 -    Impl() { pthread_spin_init(&sl, 0); refcount = 1; }
 -    ~Impl() { pthread_spin_destroy(&sl); }
 -
 -    void lock() { pthread_spin_lock(&sl); }
 -    bool trylock() { return pthread_spin_trylock(&sl) == 0; }
 -    void unlock() { pthread_spin_unlock(&sl); }
 -
 -    pthread_spinlock_t sl;
 -    int refcount;
 -};
 -
 -#else
 +    Impl()
 +    {
 +        pthread_mutexattr_t attr;
 +        pthread_mutexattr_init(&attr);
 +        pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
 +        pthread_mutex_init(&mt, &attr);
 +        pthread_mutexattr_destroy(&attr);
  
 -struct Mutex::Impl
 -{
 -    Impl() { pthread_mutex_init(&sl, 0); refcount = 1; }
 -    ~Impl() { pthread_mutex_destroy(&sl); }
 +        refcount = 1;
 +    }
 +    ~Impl() { pthread_mutex_destroy(&mt); }
  
 -    void lock() { pthread_mutex_lock(&sl); }
 -    bool trylock() { return pthread_mutex_trylock(&sl) == 0; }
 -    void unlock() { pthread_mutex_unlock(&sl); }
 +    void lock() { pthread_mutex_lock(&mt); }
 +    bool trylock() { return pthread_mutex_trylock(&mt) == 0; }
 +    void unlock() { pthread_mutex_unlock(&mt); }
  
 -    pthread_mutex_t sl;
 +    pthread_mutex_t mt;
      int refcount;
  };
  
@@@ -911,13 -1044,12 +911,13 @@@ public
  
  BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID);
  
 -BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID)
 +BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID lpReserved)
  {
      if (fdwReason == DLL_THREAD_DETACH || fdwReason == DLL_PROCESS_DETACH)
      {
 +        if (lpReserved != NULL) // called after ExitProcess() call
 +            cv::__termination = true;
          cv::deleteThreadAllocData();
 -        cv::deleteThreadRNGData();
          cv::deleteThreadData();
      }
      return TRUE;
@@@ -1039,8 -1171,6 +1039,8 @@@ TLSStorage::~TLSStorage(
      tlsData_.clear();
  }
  
 +TLSData<CoreTLSData> coreTlsData;
 +
  } // namespace cv
  
  /* End of file. */
diff --combined modules/ocl/src/gftt.cpp
@@@ -109,7 -109,7 +109,7 @@@ static void findCorners_caller
      oclMat&         corners,        //output array with detected corners
      oclMat&         counter)        //output value with number of detected corners, have to be 0 before call
  {
 -    string  opt;
 +    String  opt;
      std::vector<int> k;
      Context * cxt = Context::getContext();
  
  
      const int mask_strip = mask.step / mask.elemSize1();
  
 -    args.push_back(make_pair( sizeof(cl_mem),   (void*)&(eig_mat.data)));
 +    args.push_back(std::make_pair( sizeof(cl_mem),   (void*)&(eig_mat.data)));
  
      int src_pitch = (int)eig_mat.step;
 -    args.push_back(make_pair( sizeof(cl_int),   (void*)&src_pitch ));
 -    args.push_back(make_pair( sizeof(cl_mem),   (void*)&mask.data ));
 -    args.push_back(make_pair( sizeof(cl_mem),   (void*)&corners.data ));
 -    args.push_back(make_pair( sizeof(cl_int),   (void*)&mask_strip));
 -    args.push_back(make_pair( sizeof(cl_mem),   (void*)&eigMinMax.data ));
 -    args.push_back(make_pair( sizeof(cl_float), (void*)&qualityLevel ));
 -    args.push_back(make_pair( sizeof(cl_int),   (void*)&eig_mat.rows ));
 -    args.push_back(make_pair( sizeof(cl_int),   (void*)&eig_mat.cols ));
 -    args.push_back(make_pair( sizeof(cl_int),   (void*)&corners.cols ));
 -    args.push_back(make_pair( sizeof(cl_mem),   (void*)&counter.data ));
 +    args.push_back(std::make_pair( sizeof(cl_int),   (void*)&src_pitch ));
 +    args.push_back(std::make_pair( sizeof(cl_mem),   (void*)&mask.data ));
 +    args.push_back(std::make_pair( sizeof(cl_mem),   (void*)&corners.data ));
 +    args.push_back(std::make_pair( sizeof(cl_int),   (void*)&mask_strip));
 +    args.push_back(std::make_pair( sizeof(cl_mem),   (void*)&eigMinMax.data ));
 +    args.push_back(std::make_pair( sizeof(cl_float), (void*)&qualityLevel ));
 +    args.push_back(std::make_pair( sizeof(cl_int),   (void*)&eig_mat.rows ));
 +    args.push_back(std::make_pair( sizeof(cl_int),   (void*)&eig_mat.cols ));
 +    args.push_back(std::make_pair( sizeof(cl_int),   (void*)&corners.cols ));
 +    args.push_back(std::make_pair( sizeof(cl_mem),   (void*)&counter.data ));
  
      size_t globalThreads[3] = {eig_mat.cols, eig_mat.rows, 1};
      size_t localThreads[3]  = {16, 16, 1};
@@@ -159,14 -159,14 +159,14 @@@ static void minMaxEig_caller(const oclM
      int offset = src.offset / src.elemSize();
  
      {// first parallel pass
 -        vector<pair<size_t , const void *> > args;
 -        args.push_back( make_pair( sizeof(cl_mem) , (void *)&src.data));
 -        args.push_back( make_pair( sizeof(cl_mem) , (void *)&dst_data ));
 -        args.push_back( make_pair( sizeof(cl_int) , (void *)&cols ));
 -        args.push_back( make_pair( sizeof(cl_int) , (void *)&invalid_cols ));
 -        args.push_back( make_pair( sizeof(cl_int) , (void *)&offset));
 -        args.push_back( make_pair( sizeof(cl_int) , (void *)&elemnum));
 -        args.push_back( make_pair( sizeof(cl_int) , (void *)&groupnum));
 +        std::vector<std::pair<size_t , const void *> > args;
 +        args.push_back( std::make_pair( sizeof(cl_mem) , (void *)&src.data));
 +        args.push_back( std::make_pair( sizeof(cl_mem) , (void *)&dst_data ));
 +        args.push_back( std::make_pair( sizeof(cl_int) , (void *)&cols ));
 +        args.push_back( std::make_pair( sizeof(cl_int) , (void *)&invalid_cols ));
 +        args.push_back( std::make_pair( sizeof(cl_int) , (void *)&offset));
 +        args.push_back( std::make_pair( sizeof(cl_int) , (void *)&elemnum));
 +        args.push_back( std::make_pair( sizeof(cl_int) , (void *)&groupnum));
          size_t globalThreads[3] = {groupnum * 256, 1, 1};
          size_t localThreads[3] = {256, 1, 1};
          openCLExecuteKernel(src.clCxt, &arithm_minMax, "arithm_op_minMax", globalThreads, localThreads,
      }
  
      {// run final "serial" kernel to find accumulate results from threads and reset corner counter
 -        vector<pair<size_t , const void *> > args;
 -        args.push_back( make_pair( sizeof(cl_mem) , (void *)&dst_data ));
 -        args.push_back( make_pair( sizeof(cl_int) , (void *)&groupnum ));
 -        args.push_back( make_pair( sizeof(cl_mem) , (void *)&tozero.data ));
 +        std::vector<std::pair<size_t , const void *> > args;
 +        args.push_back( std::make_pair( sizeof(cl_mem) , (void *)&dst_data ));
 +        args.push_back( std::make_pair( sizeof(cl_int) , (void *)&groupnum ));
 +        args.push_back( std::make_pair( sizeof(cl_mem) , (void *)&tozero.data ));
          size_t globalThreads[3] = {1, 1, 1};
          size_t localThreads[3] = {1, 1, 1};
          openCLExecuteKernel(src.clCxt, &imgproc_gftt, "arithm_op_minMax_final", globalThreads, localThreads,
@@@ -208,7 -208,7 +208,7 @@@ void cv::ocl::GoodFeaturesToTrackDetect
      if(!use_cpu_sorter)
      {   // round to 2^n
          unsigned int n=1;
-         for(n=1;n<(unsigned int)corner_array_size;n<<=1);
+         for(n=1;n<(unsigned int)corner_array_size;n<<=1) ;
          corner_array_size = (int)n;
  
          ensureSizeIsEnough(1, corner_array_size , CV_32FC2, tmpCorners_);
      }
  
      int total = tmpCorners_.cols; // by default the number of corner is full array
 -    vector<DefCorner>   tmp(tmpCorners_.cols); // input buffer with corner for HOST part of algorithm
 +    std::vector<DefCorner>   tmp(tmpCorners_.cols); // input buffer with corner for HOST part of algorithm
  
      //find points with high eigenvalue and put it into the output array
      findCorners_caller(
      if(use_cpu_sorter)
      {// sort detected corners on cpu side.
          tmp.resize(total);
 -        cv::sort(tmp,DefCornerCompare());
 +        std::sort(tmp.begin(), tmp.end(), DefCornerCompare());
      }
  
      //estimate maximal size of final output array
      int total_max = maxCorners > 0 ? std::min(maxCorners, total) : total;
      int D2 = (int)ceil(minDistance * minDistance);
      // allocate output buffer
 -    vector<Point2f> tmp2;
 +    std::vector<Point2f> tmp2;
      tmp2.reserve(total_max);
  
  
              {
                  for (int xx = x1; xx <= x2; xx++)
                  {
 -                    vector<Point2i>& m = grid[yy * grid_width + xx];
 +                    std::vector<Point2i>& m = grid[yy * grid_width + xx];
                      if (m.empty())
                          continue;
                      for(size_t j = 0; j < m.size(); j++)
      else
          corners.release();
  }
 -void cv::ocl::GoodFeaturesToTrackDetector_OCL::downloadPoints(const oclMat &points, vector<Point2f> &points_v)
 +void cv::ocl::GoodFeaturesToTrackDetector_OCL::downloadPoints(const oclMat &points, std::vector<Point2f> &points_v)
  {
      CV_DbgAssert(points.type() == CV_32FC2);
      points_v.resize(points.cols);