libcvd-members
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libcvd-members] libcvd/cvd_src faster_corner.cxx


From: Ethan Eade
Subject: [libcvd-members] libcvd/cvd_src faster_corner.cxx
Date: Mon, 22 Jan 2007 14:23:37 +0000

CVSROOT:        /cvsroot/libcvd
Module name:    libcvd
Changes by:     Ethan Eade <ethaneade>  07/01/22 14:23:37

Modified files:
        cvd_src        : faster_corner.cxx 

Log message:
        Added checks for alignment and minimum image size.  
        Also changed whitespace, which cvs doesn't ignore.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd_src/faster_corner.cxx?cvsroot=libcvd&r1=1.1&r2=1.2

Patches:
Index: faster_corner.cxx
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd_src/faster_corner.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- faster_corner.cxx   20 Jan 2007 15:42:21 -0000      1.1
+++ faster_corner.cxx   22 Jan 2007 14:23:37 -0000      1.2
@@ -2,7 +2,7 @@
 
 #include <vector>
 #include <list>
-
+#include <cvd/utility.h>
 using namespace CVD;
 using namespace std;
 
@@ -15,10 +15,10 @@
 
 
 
-struct Less { template <class T1, class T2> static bool eval(const T1 a, const 
T2 b) { return a < b; }};
-struct Greater { template <class T1, class T2> static bool eval(const T1 a, 
const T2 b) { return b < a; }};
+    struct Less { template <class T1, class T2> static bool eval(const T1 a, 
const T2 b) { return a < b; }};
+    struct Greater { template <class T1, class T2> static bool eval(const T1 
a, const T2 b) { return b < a; }};
 
-template <class C> inline bool is_corner_12(const byte* p, int w, int t) {
+    template <class C> inline bool is_corner_12(const byte* p, int w, int t) {
     const int w3 = 3*w;
     if (!C::eval(p[-3],t)) {
         if (!C::eval(p[-w3],t) || !C::eval(p[1-w3],t) || !C::eval(p[2-2*w],t) 
|| !C::eval(p[3-w],t) || !C::eval(p[3],t) || !C::eval(p[3+w],t) || 
!C::eval(p[2+2*w],t) || !C::eval(p[1+w3],t) || !C::eval(p[w3],t))
@@ -74,10 +74,10 @@
         return (C::eval(p[-3+w],t));
     }
     return true;
-}
+    }
 
 
-template <int I, int N> struct BitCheck {
+    template <int I, int N> struct BitCheck {
     template <class C> static inline void eval(unsigned int three, const byte* 
p, const int w, const int barrier, C& corners) {
        const int BIT = 1<<I;
        if (three & BIT) {
@@ -91,14 +91,14 @@
        }
        BitCheck<I+1,N>::eval(three, p+1, w, barrier, corners);
     }
-};
+    };
 
-template <int N> struct BitCheck<N,N> { 
+    template <int N> struct BitCheck<N,N> { 
     template <class C> static inline void eval(unsigned int three, const byte* 
p, const int w, const int barrier, C& corners) {} 
-};
+    };
 
-template <int CHUNKS, class C> inline void process_16(unsigned int three, 
const byte* p, const int w, const int barrier, C& corners)
-{    
+    template <int CHUNKS, class C> inline void process_16(unsigned int three, 
const byte* p, const int w, const int barrier, C& corners)
+    {    
     three |= (three >> 16);
     const int BITS = 16/CHUNKS;
     const int mask = ((1<<BITS)-1);
@@ -108,7 +108,7 @@
        p += BITS;
        three >>= BITS;
     }
-}
+    }
 
 #define CHECK_BARRIER(here, other, flags)                              \
     {                                                                  \
@@ -119,8 +119,11 @@
        flags = _mm_movemask_epi8(diff) | (_mm_movemask_epi8(diff2) << 16); \
     }
 
-void faster_corner_detect_12(const BasicImage<byte>& I, std::vector<ImageRef>& 
corners, int barrier)
-{
+    template <bool Aligned> inline __m128i load_si128(const void* addr) { 
return _mm_loadu_si128((const __m128i*)addr); }
+    template <> inline __m128i load_si128<true>(const void* addr) { return 
_mm_load_si128((const __m128i*)addr); }
+    
+    template <bool Aligned> void faster_corner_detect_12(const 
BasicImage<byte>& I, std::vector<ImageRef>& corners, int barrier)
+    {
     const int w = I.size().x;
     const int stride = 3*w;
     typedef std::list<const byte*> Passed;
@@ -134,9 +137,9 @@
     for (int i=3; i<I.size().y-3; ++i) {
        const byte* p = I[i];
        for (int j=0; j<w/16; ++j, p+=16) {
-           const __m128i here = _mm_load_si128((const __m128i*)(p));
-           const __m128i above = _mm_load_si128((const __m128i*)(p-stride));
-           const __m128i below = _mm_load_si128((const __m128i*)(p+stride));
+               const __m128i here = load_si128<Aligned>((const __m128i*)(p));
+               const __m128i above = load_si128<Aligned>((const 
__m128i*)(p-stride));
+               const __m128i below = load_si128<Aligned>((const 
__m128i*)(p+stride));
            unsigned int up_flags, down_flags;
            CHECK_BARRIER(here, above, up_flags);
            CHECK_BARRIER(here, below, down_flags);
@@ -175,7 +178,21 @@
        if (x > 2 && x < w-3)
            corners.push_back(ImageRef(x, row));
     }
-}
+    }
+
+    void faster_corner_detect_12(const BasicImage<byte>& I, 
std::vector<ImageRef>& corners, int barrier)
+    {
+       if (I.size().x < 22) {
+           fast_corner_detect_12(I,corners,barrier);
+           return;
+       } else if (I.size().x < 22 || I.size().y < 7)
+           return;
+
+       if (is_aligned<16>(I[0]) && is_aligned<16>(I[1]))
+           faster_corner_detect_12<true>(I, corners, barrier);
+       else
+           faster_corner_detect_12<false>(I, corners, barrier);
+    }
 
 
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]