libcvd-members
[Top][All Lists]
Advanced

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

[libcvd-members] libcvd/cvd_src bayer.cxx


From: Gerhard Reitmayr
Subject: [libcvd-members] libcvd/cvd_src bayer.cxx
Date: Wed, 11 Mar 2009 22:39:14 +0000

CVSROOT:        /cvsroot/libcvd
Module name:    libcvd
Changes by:     Gerhard Reitmayr <gerhard>      09/03/11 22:39:14

Modified files:
        cvd_src        : bayer.cxx 

Log message:
        nicer use of templates

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd_src/bayer.cxx?cvsroot=libcvd&r1=1.6&r2=1.7

Patches:
Index: bayer.cxx
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd_src/bayer.cxx,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- bayer.cxx   11 Mar 2009 21:35:12 -0000      1.6
+++ bayer.cxx   11 Mar 2009 22:39:13 -0000      1.7
@@ -25,18 +25,11 @@
 
 namespace CVD{namespace ColourSpace{
 
-// TYPE is 0, 1, 2, 3 corresponding to the layouts RGGB = 0, GBRG = 1, GRBG = 
2, BGGR = 3
-// always works in blocks of two output pixels
-template <int TYPE>
-struct bayer_sample {
-};
-
 // RGRGRG
 // GBGBGB
 // RGRGRG
 // GBGBGB
-template <>
-struct bayer_sample<0> {
+struct bayer_sample_rggb {
        static inline void upper_left(unsigned char (*out)[3], const unsigned 
char * row, const unsigned char * next){
                out[0][0] = row[0];            out[0][1] = (row[1] + 
next[0])/2; out[0][2] = next[1];
                out[1][0] = (row[0]+row[2])/2; out[1][1] = row[1];              
 out[1][2] = next[1];
@@ -95,8 +88,7 @@
 // BGBGBG
 // GRGRGR
 // swap red and blue
-template <>
-struct bayer_sample<3> {
+struct bayer_sample_bggr {
        static inline void upper_left(unsigned char (*out)[3], const unsigned 
char * row, const unsigned char * next){
                out[0][2] = row[0];            out[0][1] = (row[1] + 
next[0])/2; out[0][0] = next[1];
                out[1][2] = (row[0]+row[2])/2; out[1][1] = row[1];              
 out[1][0] = next[1];
@@ -154,8 +146,7 @@
 // RGRGRG
 // GBGBGB
 // RGRGRG
-template <>
-struct bayer_sample<1> {
+struct bayer_sample_gbrg {
        static inline void upper_left(unsigned char (*out)[3], const unsigned 
char * row, const unsigned char * next){
                out[0][0] = next[0];            out[0][1] = row[0];             
        out[0][2] = row[1];
                out[1][0] = (next[0]+next[2])/2;out[1][1] = 
(row[0]+row[2]+next[1])/3;  out[1][2] = row[1];
@@ -170,23 +161,23 @@
        }
 
        static inline void odd_left(unsigned char (*out)[3], const unsigned 
char * previous, const unsigned char * row, const unsigned char * next){
-               bayer_sample<0>::even_left(out, previous, row, next);
+               bayer_sample_rggb::even_left(out, previous, row, next);
        }
        static inline void odd_row(unsigned char (*out)[3], const unsigned char 
* previous, const unsigned char * row, const unsigned char * next){
-               bayer_sample<0>::even_row(out, previous, row, next);
+               bayer_sample_rggb::even_row(out, previous, row, next);
        }
        static inline void odd_right(unsigned char (*out)[3], const unsigned 
char * previous, const unsigned char * row, const unsigned char * next){
-               bayer_sample<0>::even_right(out, previous, row, next);
+               bayer_sample_rggb::even_right(out, previous, row, next);
        }
 
        static inline void even_left(unsigned char (*out)[3], const unsigned 
char * previous, const unsigned char * row, const unsigned char * next){
-               bayer_sample<0>::odd_left(out, previous, row, next);
+               bayer_sample_rggb::odd_left(out, previous, row, next);
        }
        static inline void even_row(unsigned char (*out)[3], const unsigned 
char * previous, const unsigned char * row, const unsigned char * next){
-               bayer_sample<0>::odd_row(out, previous, row, next);
+               bayer_sample_rggb::odd_row(out, previous, row, next);
        }
        static inline void even_right(unsigned char (*out)[3], const unsigned 
char * previous, const unsigned char * row, const unsigned char * next){
-               bayer_sample<0>::odd_right(out, previous, row, next);
+               bayer_sample_rggb::odd_right(out, previous, row, next);
        }
 
        static inline void lower_left(unsigned char (*out)[3], const unsigned 
char * previous, const unsigned char * row){
@@ -207,8 +198,7 @@
 // BGBGBG
 // GRGRGR
 // BGBGBG
-template <>
-struct bayer_sample<2> {
+struct bayer_sample_grbg {
        static inline void upper_left(unsigned char (*out)[3], const unsigned 
char * row, const unsigned char * next){
                out[0][2] = next[0];            out[0][1] = row[0];             
        out[0][0] = row[1];
                out[1][2] = (next[0]+next[2])/2;out[1][1] = 
(row[0]+row[2]+next[1])/3;  out[1][0] = row[1];
@@ -223,23 +213,23 @@
        }
 
        static inline void odd_left(unsigned char (*out)[3], const unsigned 
char * previous, const unsigned char * row, const unsigned char * next){
-               bayer_sample<3>::even_left(out, previous, row, next);
+               bayer_sample_bggr::even_left(out, previous, row, next);
        }
        static inline void odd_row(unsigned char (*out)[3], const unsigned char 
* previous, const unsigned char * row, const unsigned char * next){
-               bayer_sample<3>::even_row(out, previous, row, next);
+               bayer_sample_bggr::even_row(out, previous, row, next);
        }
        static inline void odd_right(unsigned char (*out)[3], const unsigned 
char * previous, const unsigned char * row, const unsigned char * next){
-               bayer_sample<3>::even_right(out, previous, row, next);
+               bayer_sample_bggr::even_right(out, previous, row, next);
        }
 
        static inline void even_left(unsigned char (*out)[3], const unsigned 
char * previous, const unsigned char * row, const unsigned char * next){
-               bayer_sample<3>::odd_left(out, previous, row, next);
+               bayer_sample_bggr::odd_left(out, previous, row, next);
        }
        static inline void even_row(unsigned char (*out)[3], const unsigned 
char * previous, const unsigned char * row, const unsigned char * next){
-               bayer_sample<3>::odd_row(out, previous, row, next);
+               bayer_sample_bggr::odd_row(out, previous, row, next);
        }
        static inline void even_right(unsigned char (*out)[3], const unsigned 
char * previous, const unsigned char * row, const unsigned char * next){
-               bayer_sample<3>::odd_right(out, previous, row, next);
+               bayer_sample_bggr::odd_right(out, previous, row, next);
        }
 
        static inline void lower_left(unsigned char (*out)[3], const unsigned 
char * previous, const unsigned char * row){
@@ -257,7 +247,7 @@
 };
 
 // TYPE is 0, 1, 2, 3 corresponding to the layouts RGGB = 0, GBRG = 1, GRBG = 
2, BGGR = 3
-template <int TYPE>
+template <class SAMPLER>
 void bayer_to_rgb(const unsigned char* bggr, unsigned char* rgb, unsigned int 
width, unsigned int height)
 {
   const unsigned char* row = bggr;
@@ -267,66 +257,66 @@
 
   unsigned char (*out)[3] = (unsigned char (*)[3])rgb;
 
-  bayer_sample<TYPE>::upper_left(out, row, next);
+  SAMPLER::upper_left(out, row, next);
   out += 2; row += 2; next += 2;
   for (unsigned int j=0; j<midcount; ++j ) {
-       bayer_sample<TYPE>::upper_row(out, row, next);
+       SAMPLER::upper_row(out, row, next);
        out += 2; row += 2; next += 2;
   }
-  bayer_sample<TYPE>::upper_right(out, row, next);
+  SAMPLER::upper_right(out, row, next);
   out += 2; row += 2; next += 2;
 
   // Middle rows
   for (unsigned int i=1; i<height-1; i+=2) {
        // odd row
-       bayer_sample<TYPE>::odd_left(out, prev, row, next);
+       SAMPLER::odd_left(out, prev, row, next);
        out += 2; prev+= 2; row += 2; next += 2;
        for (unsigned int j=0; j<midcount; ++j) {
-               bayer_sample<TYPE>::odd_row(out, prev, row, next);
+               SAMPLER::odd_row(out, prev, row, next);
                out += 2; prev+= 2; row += 2; next += 2;
        }
-       bayer_sample<TYPE>::odd_right(out, prev, row, next);
+       SAMPLER::odd_right(out, prev, row, next);
        out += 2; prev+= 2; row += 2; next += 2;
        // even row
-       bayer_sample<TYPE>::even_left(out, prev, row, next);
+       SAMPLER::even_left(out, prev, row, next);
        out += 2; prev+= 2; row += 2; next += 2;
        for (unsigned int j=0; j<midcount; ++j) {
-               bayer_sample<TYPE>::even_row(out, prev, row, next);
+               SAMPLER::even_row(out, prev, row, next);
                out += 2; prev+= 2; row += 2; next += 2;
        }
-       bayer_sample<TYPE>::even_right(out, prev, row, next);
+       SAMPLER::even_right(out, prev, row, next);
        out += 2; prev+= 2; row += 2; next += 2;
   }
   // last row
-  bayer_sample<TYPE>::lower_left(out, prev, row);
+  SAMPLER::lower_left(out, prev, row);
   out += 2; prev+= 2; row += 2;
   for (unsigned int j=0; j<midcount; ++j) {
-       bayer_sample<TYPE>::lower_row(out, prev, row);
+       SAMPLER::lower_row(out, prev, row);
        out += 2; prev+= 2; row += 2;
   }
-  bayer_sample<TYPE>::lower_right(out, prev, row);
+  SAMPLER::lower_right(out, prev, row);
 }
 
 void bayer_to_rgb_rggb(const unsigned char* rggb, unsigned char* rgb, unsigned 
int width, unsigned int height){
-       bayer_to_rgb<0>(rggb, rgb, width, height);
+       bayer_to_rgb<bayer_sample_rggb>(rggb, rgb, width, height);
 }
 
 void bayer_to_rgb_gbrg(const unsigned char* rggb, unsigned char* rgb, unsigned 
int width, unsigned int height){
-       bayer_to_rgb<1>(rggb, rgb, width, height);
+       bayer_to_rgb<bayer_sample_gbrg>(rggb, rgb, width, height);
 }
 
 void bayer_to_rgb_grbg(const unsigned char* rggb, unsigned char* rgb, unsigned 
int width, unsigned int height){
-       bayer_to_rgb<2>(rggb, rgb, width, height);
+       bayer_to_rgb<bayer_sample_grbg>(rggb, rgb, width, height);
 }
 
 void bayer_to_rgb_bggr(const unsigned char* bggr, unsigned char* rgb, unsigned 
int width, unsigned int height){
-       bayer_to_rgb<3>(bggr, rgb, width, height);
+       bayer_to_rgb<bayer_sample_bggr>(bggr, rgb, width, height);
 }
 
 inline unsigned char cie(unsigned char * c) { return (c[0]*77 + c[1]*150 + 
c[2]*29)>>8; }
 
 // TYPE is 0, 1, 2, 3 corresponding to the layouts RGGB = 0, GBRG = 1, GRBG = 
2, BGGR = 3
-template<int TYPE>
+template<class SAMPLER>
 void bayer_to_grey(const unsigned char* bggr, unsigned char* grey, unsigned 
int width, unsigned int height)
 {
   const unsigned char* row = bggr;
@@ -336,70 +326,70 @@
 
   unsigned char out[2][3];
 
-  bayer_sample<TYPE>::upper_left(out, row, next);
+  SAMPLER::upper_left(out, row, next);
   grey[0] = cie(out[0]); grey[1] = cie(out[1]);
   grey += 2; row += 2; next += 2;
   for (unsigned int j=0; j<midcount; ++j ) {
-       bayer_sample<TYPE>::upper_row(out, row, next);
+       SAMPLER::upper_row(out, row, next);
        grey[0] = cie(out[0]); grey[1] = cie(out[1]);
        grey += 2; row += 2; next += 2;
   }
-  bayer_sample<TYPE>::upper_right(out, row, next);
+  SAMPLER::upper_right(out, row, next);
   grey[0] = cie(out[0]); grey[1] = cie(out[1]);
   grey += 2; row += 2; next += 2;
 
   // Middle rows
   for (unsigned int i=1; i<height-1; i+=2) {
        // odd row
-       bayer_sample<TYPE>::odd_left(out, prev, row, next);
+       SAMPLER::odd_left(out, prev, row, next);
        grey[0] = cie(out[0]); grey[1] = cie(out[1]);
        grey += 2; prev +=2; row += 2; next += 2;
        for (unsigned int j=0; j<midcount; ++j) {
-               bayer_sample<TYPE>::odd_row(out, prev, row, next);
+               SAMPLER::odd_row(out, prev, row, next);
                grey[0] = cie(out[0]); grey[1] = cie(out[1]);
                grey += 2; prev +=2; row += 2; next += 2;
        }
-       bayer_sample<TYPE>::odd_right(out, prev, row, next);
+       SAMPLER::odd_right(out, prev, row, next);
        grey[0] = cie(out[0]); grey[1] = cie(out[1]);
        grey += 2; prev +=2; row += 2; next += 2;
        // even row
-       bayer_sample<TYPE>::even_left(out, prev, row, next);
+       SAMPLER::even_left(out, prev, row, next);
        grey[0] = cie(out[0]); grey[1] = cie(out[1]);
        grey += 2; prev +=2; row += 2; next += 2;
        for (unsigned int j=0; j<midcount; ++j) {
-               bayer_sample<TYPE>::even_row(out, prev, row, next);
+               SAMPLER::even_row(out, prev, row, next);
                grey[0] = cie(out[0]); grey[1] = cie(out[1]);
                grey += 2; prev +=2; row += 2; next += 2;
        }
-       bayer_sample<TYPE>::even_right(out, prev, row, next);
+       SAMPLER::even_right(out, prev, row, next);
        grey[0] = cie(out[0]); grey[1] = cie(out[1]);
        grey += 2; prev +=2; row += 2; next += 2;
   }
   // last row
-  bayer_sample<TYPE>::lower_left(out, prev, row);
+  SAMPLER::lower_left(out, prev, row);
   grey[0] = cie(out[0]); grey[1] = cie(out[1]);
   grey += 2; row += 2; prev += 2;
   for (unsigned int j=0; j<midcount; ++j) {
        grey[0] = cie(out[0]); grey[1] = cie(out[1]);
        grey += 2; row += 2; prev += 2;
   }
-  bayer_sample<TYPE>::lower_right(out, prev, row);
+  SAMPLER::lower_right(out, prev, row);
 }
 
 void bayer_to_grey_rggb(const unsigned char* rggb, unsigned char* grey, 
unsigned int width, unsigned int height){
-       bayer_to_grey<0>(rggb, grey, width, height);
+       bayer_to_grey<bayer_sample_rggb>(rggb, grey, width, height);
 }
 
 void bayer_to_grey_gbrg(const unsigned char* rggb, unsigned char* grey, 
unsigned int width, unsigned int height){
-       bayer_to_grey<1>(rggb, grey, width, height);
+       bayer_to_grey<bayer_sample_gbrg>(rggb, grey, width, height);
 }
 
 void bayer_to_grey_grbg(const unsigned char* rggb, unsigned char* grey, 
unsigned int width, unsigned int height){
-       bayer_to_grey<2>(rggb, grey, width, height);
+       bayer_to_grey<bayer_sample_grbg>(rggb, grey, width, height);
 }
 
 void bayer_to_grey_bggr(const unsigned char* bggr, unsigned char* grey, 
unsigned int width, unsigned int height){
-       bayer_to_grey<3>(bggr, grey, width, height);
+       bayer_to_grey<bayer_sample_bggr>(bggr, grey, width, height);
 }
 
 }}




reply via email to

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