From 0d94e8e01926ee0491e465c5140bfdce64416ff3 Mon Sep 17 00:00:00 2001 From: Edward Rosten Date: Tue, 13 Oct 2020 17:50:51 +0100 Subject: [PATCH 1/7] First squash of warnings --- configure | 40 +++++++ configure.ac | 1 + cvd/draw.h | 2 +- cvd/image.h | 2 +- cvd/image_ref.h | 4 +- cvd/morphology.h | 24 ++-- cvd/videosource.h | 4 +- cvd_src/bayer.cxx | 200 ++++++++++++++++---------------- cvd_src/connected_components.cc | 2 +- cvd_src/draw.cc | 2 +- cvd_src/image_io.cc | 2 +- cvd_src/image_io/pnm_grok.cxx | 8 +- cvd_src/noarch/yuv422.cpp | 2 +- cvd_src/videosource.cpp | 2 +- 14 files changed, 168 insertions(+), 127 deletions(-) diff --git a/configure b/configure index 089a90e3..54ab29bc 100755 --- a/configure +++ b/configure @@ -4842,6 +4842,46 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + if test $cvd_conf_test = 1 + then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + ts_success=yes + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + CXXFLAGS="$save_CXXFLAGS" + ts_success=no + fi + + + if test "" == "" + then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if compiler flag -Wconversion works" >&5 +$as_echo_n "checking if compiler flag -Wconversion works... " >&6; } + else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking " >&5 +$as_echo_n "checking ... " >&6; } + fi + save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -Wconversion" + + + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +int main(){} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + cvd_conf_test=1 +else + cvd_conf_test=0 +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + + + + if test $cvd_conf_test = 1 then { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 diff --git a/configure.ac b/configure.ac index 6ad619b3..3e6bb50e 100644 --- a/configure.ac +++ b/configure.ac @@ -163,6 +163,7 @@ AC_CANONICAL_HOST # TEST_AND_SET_CXXFLAG(-Wall) TEST_AND_SET_CXXFLAG(-Wextra) +TEST_AND_SET_CXXFLAG(-Wconversion) TEST_AND_SET_CXXFLAG(-pipe) #Hack: do this properly diff --git a/cvd/draw.h b/cvd/draw.h index 7b96dcf9..7e1f8a28 100644 --- a/cvd/draw.h +++ b/cvd/draw.h @@ -228,7 +228,7 @@ std::vector getCircle(int radius); /// @param radius radius of the circle in pixels /// @return vector containig ImageRef for the circle /// @ingroup gGraphics -std::vector getDisc(float radius); +std::vector getDisc(double radius); #if defined CVD_HAVE_TOON || defined DOXYGEN_IGNORE_INTERNAL diff --git a/cvd/image.h b/cvd/image.h index 5b914998..d0f7c999 100644 --- a/cvd/image.h +++ b/cvd/image.h @@ -123,7 +123,7 @@ namespace Internal //Class to give us a size 2 return value or fail on //substituting S - template + template struct SFINAE_dummy { typedef Two Type; diff --git a/cvd/image_ref.h b/cvd/image_ref.h index 28efd842..d5ef8fe0 100644 --- a/cvd/image_ref.h +++ b/cvd/image_ref.h @@ -203,9 +203,9 @@ inline std::istream& operator>>(std::istream& is, ImageRef& ref) //output produced above, as well as the older (x,y) format is >> std::ws; - unsigned char c = is.get(); + int c = is.get(); - if(is.eof()) + if(c == -1) return is; if(c == '(' ) diff --git a/cvd/morphology.h b/cvd/morphology.h index 830177fd..f21e9ae4 100644 --- a/cvd/morphology.h +++ b/cvd/morphology.h @@ -144,7 +144,7 @@ namespace CVD { //Find the rows which overlap with the image. Only work with these rows. int startrow = max(0, - y_lo - y); - int endrow = split_selem.size() - max(0, y + y_hi - in.size().y+1); + int endrow = static_cast(split_selem.size()) - max(0, y + y_hi - in.size().y+1); //Figure out the range of the "easy" bit. int x_first_full = max(0, -x_lo); //This is the first position at which we have a full kernel in the image @@ -182,13 +182,13 @@ namespace CVD int add_start=0, add_end=0, remove_start=0, remove_end=0; for(int i=0; i < startrow; i++) { - add_start+=split_add[i].size(); - remove_start+=split_remove[i].size(); + add_start+=static_cast(split_add[i].size()); + remove_start+=static_cast(split_remove[i].size()); } for(int i=0; i < endrow; i++) { - add_end+=split_add[i].size(); - remove_end+=split_remove[i].size(); + add_end+=static_cast(split_add[i].size()); + remove_end+=static_cast(split_remove[i].size()); } //Shift the kernel in the area which requires no tests. @@ -225,7 +225,7 @@ namespace CVD { //Find the rows which overlap with the image. Only work with these rows. int startrow = max(0, - y_lo - y); - int endrow = split_selem.size() - max(0, y + y_hi - in.size().y+1); + int endrow = static_cast(split_selem.size()) - max(0, y + y_hi - in.size().y+1); //Clear the accumulator acc.clear(); @@ -430,7 +430,7 @@ namespace CVD { for(int j=0; j < 256; j++) if(histogram[j]) - return j; + return static_cast(j); assert(0); return 0; @@ -446,7 +446,7 @@ namespace CVD { for(int j=255; j >=0 ; j--) if(histogram[j]) - return j; + return static_cast(j); assert(0); return 0; @@ -483,7 +483,7 @@ namespace CVD sum += histogram[j]; if(sum > threshold) - return j; + return static_cast(j); } return 255; @@ -499,7 +499,7 @@ namespace CVD sum += histogram[j]; if(sum > threshold) - return j; + return static_cast(j); } return 0; @@ -590,7 +590,7 @@ namespace CVD //Some helper classes for median template T median4(T a, T b, T c, T d) { - int v[4] = {a, b, c, d}; + T v[4] = {a, b, c, d}; std::nth_element(v, v+2, v+4); return v[2]; } @@ -602,7 +602,7 @@ namespace CVD template T median6(T a, T b, T c, T d, T e, T f) { - int v[6] = {a, b, c, d, e, f}; + T v[6] = {a, b, c, d, e, f}; std::nth_element(v, v+3, v+6); return v[3]; } diff --git a/cvd/videosource.h b/cvd/videosource.h index a738051f..e4620235 100644 --- a/cvd/videosource.h +++ b/cvd/videosource.h @@ -317,7 +317,7 @@ namespace CVD { template <> VideoBuffer* makeDVBuffer2(int cam, ImageRef size, float fps, ImageRef offset, bool verbose, bool bus_reset, int format7_mode); template <> VideoBuffer* makeDVBuffer2(int cam, ImageRef size, float fps, ImageRef offset, bool verbose, bool bus_reset, int format7_mode); - void get_dc1394_options(const VideoSource& vs, ImageRef& size, float& fps, ImageRef& offset, bool& verbose, bool& bus_reset, int& format7_mode); + void get_dc1394_options(const VideoSource& vs, ImageRef& size, int& fps, ImageRef& offset, bool& verbose, bool& bus_reset, int& format7_mode); //////////////////////////////////////////////////////////////////////////////// @@ -394,7 +394,7 @@ namespace CVD { else if (vs.protocol == "dc1394") { int cam_no = atoi(vs.identifier.c_str()); ImageRef size, offset; - float fps; + int fps; bool verbose; bool bus_reset; int format7_mode; diff --git a/cvd_src/bayer.cxx b/cvd_src/bayer.cxx index 173eba27..29b1b6ea 100644 --- a/cvd_src/bayer.cxx +++ b/cvd_src/bayer.cxx @@ -48,9 +48,9 @@ struct bayer_sample_rggb { T next0 = R::get(next[0]); T next1 = R::get(next[1]); out[0][0] = row0; - out[0][1] = (row1 + next0)/2; + out[0][1] = static_cast((row1 + next0)/2); out[0][2] = next1; - out[1][0] = (row0+row2)/2; + out[1][0] = static_cast((row0+row2)/2); out[1][1] = row1; out[1][2] = next1; } @@ -63,9 +63,9 @@ struct bayer_sample_rggb { T next0 = R::get(next[0]); T next1 = R::get(next[1]); out[0][0] = row0; - out[0][1] = (row_1+ row1 + next0)/3; - out[0][2] = (next_1+next1)/2; - out[1][0] = (row0+row2)/2; + out[0][1] = static_cast((row_1+ row1 + next0)/3); + out[0][2] = static_cast((next_1+next1)/2); + out[1][0] = static_cast((row0+row2)/2); out[1][1] = row1; out[1][2] = next1; } @@ -77,8 +77,8 @@ struct bayer_sample_rggb { T next0 = R::get(next[0]); T next1 = R::get(next[1]); out[0][0] = row0; - out[0][1] = (row_1+ row1 + next0)/3; - out[0][2] = (next_1+next1)/2; + out[0][1] = static_cast((row_1+ row1 + next0)/3); + out[0][2] = static_cast((next_1+next1)/2); out[1][0] = row0; out[1][1] = row1; out[1][2] = next1; @@ -94,11 +94,11 @@ struct bayer_sample_rggb { T next0 = R::get(next[0]); T next1 = R::get(next[1]); T next2 = R::get(next[2]); - out[0][0] = (prev0 + next0)/2; + out[0][0] = static_cast((prev0 + next0)/2); out[0][1] = row0; out[0][2] = row1; - out[1][0] = (prev0 + next0 + prev2 + next2)/4; - out[1][1] = (row0+row2+prev1+next1)/4; + out[1][0] = static_cast((prev0 + next0 + prev2 + next2)/4); + out[1][1] = static_cast((row0+row2+prev1+next1)/4); out[1][2] = row1; } static inline void odd_row(T (*out)[3], const T * previous, const T * row, const T * next){ @@ -112,11 +112,11 @@ struct bayer_sample_rggb { T next0 = R::get(next[0]); T next1 = R::get(next[1]); T next2 = R::get(next[2]); - out[0][0] = (prev0 + next0)/2; + out[0][0] = static_cast((prev0 + next0)/2); out[0][1] = row0; - out[0][2] = (row_1+row1)/2; - out[1][0] = (prev0 + next0 + prev2 + next2)/4; - out[1][1] = (row0+row2+prev1+next1)/4; + out[0][2] = static_cast((row_1+row1)/2); + out[1][0] = static_cast((prev0 + next0 + prev2 + next2)/4); + out[1][1] = static_cast((row0+row2+prev1+next1)/4); out[1][2] = row1; } static inline void odd_right(T (*out)[3], const T * previous, const T * row, const T * next){ @@ -127,11 +127,11 @@ struct bayer_sample_rggb { T row1 = R::get(row[1]); T next0 = R::get(next[0]); T next1 = R::get(next[1]); - out[0][0] = (prev0 + next0)/2; + out[0][0] = static_cast((prev0 + next0)/2); out[0][1] = row0; - out[0][2] = (row_1+row1)/2; - out[1][0] = (prev0 + next0)/2; - out[1][1] = (row0+prev1+next1)/3; + out[0][2] = static_cast((row_1+row1)/2); + out[1][0] = static_cast((prev0 + next0)/2); + out[1][1] = static_cast((row0+prev1+next1)/3); out[1][2] = row1; } @@ -144,9 +144,9 @@ struct bayer_sample_rggb { T next0 = R::get(next[0]); T next1 = R::get(next[1]); out[0][0] = row0; - out[0][1] = (row1+prev0+next0)/3; - out[0][2] = (prev1+next1)/2; - out[1][0] = (row0+row2)/2; + out[0][1] = static_cast((row1+prev0+next0)/3); + out[0][2] = static_cast((prev1+next1)/2); + out[1][0] = static_cast((row0+row2)/2); out[1][1] = row1; out[1][2] = out[0][2]; } @@ -162,11 +162,11 @@ struct bayer_sample_rggb { T next0 = R::get(next[0]); T next1 = R::get(next[1]); out[0][0] = row0; - out[0][1] = (row_1+row1+prev0+next0)/4; - out[0][2] = (prev_1+next_1+prev1+next1)/4; - out[1][0] = (row0+row2)/2; + out[0][1] = static_cast((row_1+row1+prev0+next0)/4); + out[0][2] = static_cast((prev_1+next_1+prev1+next1)/4); + out[1][0] = static_cast((row0+row2)/2); out[1][1] = row1; - out[1][2] = (prev1 + next1)/2; + out[1][2] = static_cast((prev1 + next1)/2); } static inline void even_right(T (*out)[3], const T * previous, const T * row, const T * next){ T prev_1 = R::get(previous[-1]); @@ -179,11 +179,11 @@ struct bayer_sample_rggb { T next0 = R::get(next[0]); T next1 = R::get(next[1]); out[0][0] = row0; - out[0][1] = (row_1+row1+prev0+next0)/4; - out[0][2] = (prev_1+next_1+prev1+next1)/4; + out[0][1] = static_cast((row_1+row1+prev0+next0)/4); + out[0][2] = static_cast((prev_1+next_1+prev1+next1)/4); out[1][0] = row0; out[1][1] = row1; - out[1][2] = (prev1 + next1)/2; + out[1][2] = static_cast((prev1 + next1)/2); } static inline void lower_left(T (*out)[3], const T * previous, const T * row){ @@ -196,8 +196,8 @@ struct bayer_sample_rggb { out[0][0] = prev0; out[0][1] = row0; out[0][2] = row1; - out[1][0] = (prev0+prev2)/2; - out[1][1] = (row0+row2+prev1)/3; + out[1][0] = static_cast((prev0+prev2)/2); + out[1][1] = static_cast((row0+row2+prev1)/3); out[1][2] = row1; } static inline void lower_row(T (*out)[3], const T * previous, const T * row){ @@ -210,9 +210,9 @@ struct bayer_sample_rggb { T row2 = R::get(row[2]); out[0][0] = prev0; out[0][1] = row0; - out[0][2] = (row_1+row1)/2; - out[1][0] = (prev0 + prev2)/2; - out[1][1] = (row0+row2+prev1)/3; + out[0][2] = static_cast((row_1+row1)/2); + out[1][0] = static_cast((prev0 + prev2)/2); + out[1][1] = static_cast((row0+row2+prev1)/3); out[1][2] = row1; } static inline void lower_right(T (*out)[3], const T * previous, const T * row){ @@ -223,9 +223,9 @@ struct bayer_sample_rggb { T row1 = R::get(row[1]); out[0][0] = prev0; out[0][1] = row0; - out[0][2] = (row_1+row1)/2; + out[0][2] = static_cast((row_1+row1)/2); out[1][0] = prev0; - out[1][1] = (row0+prev1)/2; + out[1][1] = static_cast((row0+prev1)/2); out[1][2] = row1; } }; @@ -244,10 +244,10 @@ struct bayer_sample_bggr { T row2 = R::get(row[2]); T next0 = R::get(next[0]); T next1 = R::get(next[1]); - out[0][2] = row0; - out[0][1] = (row1 + next0)/2; + out[0][2] = row0; //////////////////////////////////////////////// + out[0][1] = static_cast((row1 + next0)/2); out[0][0] = next1; - out[1][2] = (row0+row2)/2; + out[1][2] = static_cast((row0+row2)/2); out[1][1] = row1; out[1][0] = next1; } @@ -260,9 +260,9 @@ struct bayer_sample_bggr { T next0 = R::get(next[0]); T next1 = R::get(next[1]); out[0][2] = row0; - out[0][1] = (row_1+ row1 + next0)/3; - out[0][0] = (next_1+next1)/2; - out[1][2] = (row0+row2)/2; + out[0][1] = static_cast((row_1+ row1 + next0)/3); + out[0][0] = static_cast((next_1+next1)/2); + out[1][2] = static_cast((row0+row2)/2); out[1][1] = row1; out[1][0] = next1; } @@ -274,8 +274,8 @@ struct bayer_sample_bggr { T next0 = R::get(next[0]); T next1 = R::get(next[1]); out[0][2] = row0; - out[0][1] = (row_1+ row1 + next0)/3; - out[0][0] = (next_1+next1)/2; + out[0][1] = static_cast((row_1+ row1 + next0)/3); + out[0][0] = static_cast((next_1+next1)/2); out[1][2] = row0; out[1][1] = row1; out[1][0] = next1; @@ -291,11 +291,11 @@ struct bayer_sample_bggr { T next0 = R::get(next[0]); T next1 = R::get(next[1]); T next2 = R::get(next[2]); - out[0][2] = (prev0 + next0)/2; + out[0][2] = static_cast((prev0 + next0)/2); out[0][1] = row0; out[0][0] = row1; - out[1][2] = (prev0 + next0 + prev2 + next2)/4; - out[1][1] = (row0+row2+prev1+next1)/4; + out[1][2] = static_cast((prev0 + next0 + prev2 + next2)/4); + out[1][1] = static_cast((row0+row2+prev1+next1)/4); out[1][0] = row1; } static inline void odd_row(T (*out)[3], const T * previous, const T * row, const T * next){ @@ -309,11 +309,11 @@ struct bayer_sample_bggr { T next0 = R::get(next[0]); T next1 = R::get(next[1]); T next2 = R::get(next[2]); - out[0][2] = (prev0 + next0)/2; + out[0][2] = static_cast((prev0 + next0)/2); out[0][1] = row0; - out[0][0] = (row_1+row1)/2; - out[1][2] = (prev0 + next0 + prev2 + next2)/4; - out[1][1] = (row0+row2+prev1+next1)/4; + out[0][0] = static_cast((row_1+row1)/2); + out[1][2] = static_cast((prev0 + next0 + prev2 + next2)/4); + out[1][1] = static_cast((row0+row2+prev1+next1)/4); out[1][0] = row1; } static inline void odd_right(T (*out)[3], const T * previous, const T * row, const T * next){ @@ -324,11 +324,11 @@ struct bayer_sample_bggr { T row1 = R::get(row[1]); T next0 = R::get(next[0]); T next1 = R::get(next[1]); - out[0][2] = (prev0 + next0)/2; + out[0][2] = static_cast((prev0 + next0)/2); out[0][1] = row0; - out[0][0] = (row_1+row1)/2; - out[1][2] = (prev0 + next0)/2; - out[1][1] = (row0+prev1+next1)/3; + out[0][0] = static_cast((row_1+row1)/2); + out[1][2] = static_cast((prev0 + next0)/2); + out[1][1] = static_cast((row0+prev1+next1)/3); out[1][0] = row1; } @@ -341,9 +341,9 @@ struct bayer_sample_bggr { T next0 = R::get(next[0]); T next1 = R::get(next[1]); out[0][2] = row0; - out[0][1] = (row1+prev0+next0)/3; - out[0][0] = (prev1+next1)/2; - out[1][2] = (row0+row2)/2; + out[0][1] = static_cast((row1+prev0+next0)/3); + out[0][0] = static_cast((prev1+next1)/2); + out[1][2] = static_cast((row0+row2)/2); out[1][1] = row1; out[1][0] = out[0][0]; } @@ -359,11 +359,11 @@ struct bayer_sample_bggr { T next0 = R::get(next[0]); T next1 = R::get(next[1]); out[0][2] = row0; - out[0][1] = (row_1+row1+prev0+next0)/4; - out[0][0] = (prev_1+next_1+prev1+next1)/4; - out[1][2] = (row0+row2)/2; + out[0][1] = static_cast((row_1+row1+prev0+next0)/4); + out[0][0] = static_cast((prev_1+next_1+prev1+next1)/4); + out[1][2] = static_cast((row0+row2)/2); out[1][1] = row1; - out[1][0] = (prev1 + next1)/2; + out[1][0] = static_cast((prev1 + next1)/2); } static inline void even_right(T (*out)[3], const T * previous, const T * row, const T * next){ T prev_1 = R::get(previous[-1]); @@ -376,11 +376,11 @@ struct bayer_sample_bggr { T next0 = R::get(next[0]); T next1 = R::get(next[1]); out[0][2] = row0; - out[0][1] = (row_1+row1+prev0+next0)/4; - out[0][0] = (prev_1+next_1+prev1+next1)/4; + out[0][1] = static_cast((row_1+row1+prev0+next0)/4); + out[0][0] = static_cast((prev_1+next_1+prev1+next1)/4); out[1][2] = row0; out[1][1] = row1; - out[1][0] = (prev1 + next1)/2; + out[1][0] = static_cast((prev1 + next1)/2); } static inline void lower_left(T (*out)[3], const T * previous, const T * row){ @@ -393,8 +393,8 @@ struct bayer_sample_bggr { out[0][2] = prev0; out[0][1] = row0; out[0][0] = row1; - out[1][2] = (prev0+prev2)/2; - out[1][1] = (row0+row2+prev1)/3; + out[1][2] = static_cast((prev0+prev2)/2); + out[1][1] = static_cast((row0+row2+prev1)/3); out[1][0] = row1; } static inline void lower_row(T (*out)[3], const T * previous, const T * row){ @@ -407,9 +407,9 @@ struct bayer_sample_bggr { T row2 = R::get(row[2]); out[0][2] = prev0; out[0][1] = row0; - out[0][0] = (row_1+row1)/2; - out[1][2] = (prev0 + prev2)/2; - out[1][1] = (row0+row2+prev1)/3; + out[0][0] = static_cast((row_1+row1)/2); + out[1][2] = static_cast((prev0 + prev2)/2); + out[1][1] = static_cast((row0+row2+prev1)/3); out[1][0] = row1; } static inline void lower_right(T (*out)[3], const T * previous, const T * row){ @@ -420,9 +420,9 @@ struct bayer_sample_bggr { T row1 = R::get(row[1]); out[0][2] = prev0; out[0][1] = row0; - out[0][0] = (row_1+row1)/2; + out[0][0] = static_cast((row_1+row1)/2); out[1][2] = prev0; - out[1][1] = (row0+prev1)/2; + out[1][1] = static_cast((row0+prev1)/2); out[1][0] = row1; } }; @@ -443,8 +443,8 @@ struct bayer_sample_gbrg { out[0][0] = next0; out[0][1] = row0; out[0][2] = row1; - out[1][0] = (next0+next2)/2; - out[1][1] = (row0+row2+next1)/3; + out[1][0] = static_cast((next0+next2)/2); + out[1][1] = static_cast((row0+row2+next1)/3); out[1][2] = row1; } static inline void upper_row(T (*out)[3], const T * row, const T * next){ @@ -457,9 +457,9 @@ struct bayer_sample_gbrg { T next2 = R::get(next[2]); out[0][0] = next0; out[0][1] = row0; - out[0][2] = (row_1+row1)/2; - out[1][0] = (next0+next2)/2; - out[1][1] = (row0+row2+next1)/3; + out[0][2] = static_cast((row_1+row1)/2); + out[1][0] = static_cast((next0+next2)/2); + out[1][1] = static_cast((row0+row2+next1)/3); out[1][2] = row1; } static inline void upper_right(T (*out)[3], const T * row, const T * next){ @@ -470,9 +470,9 @@ struct bayer_sample_gbrg { T next1 = R::get(next[1]); out[0][0] = next0; out[0][1] = row0; - out[0][2] = (row_1+row1)/2; + out[0][2] = static_cast((row_1+row1)/2); out[1][0] = next0; - out[1][1] = (row0+next1)/2; + out[1][1] = static_cast((row0+next1)/2); out[1][2] = row1; } @@ -503,9 +503,9 @@ struct bayer_sample_gbrg { T row1 = R::get(row[1]); T row2 = R::get(row[2]); out[0][0] = row0; - out[0][1] = (prev0 + row1)/2; + out[0][1] = static_cast((prev0 + row1)/2); out[0][2] = prev1; - out[1][0] = (row0+row2)/2; + out[1][0] = static_cast((row0+row2)/2); out[1][1] = row1; out[1][2] = prev1; } @@ -518,9 +518,9 @@ struct bayer_sample_gbrg { T row1 = R::get(row[1]); T row2 = R::get(row[2]); out[0][0] = row0; - out[0][1] = (row_1+prev0 + row1)/3; - out[0][2] = (prev_1+prev1)/2; - out[1][0] = (row0+row2)/2; + out[0][1] = static_cast((row_1+prev0 + row1)/3); + out[0][2] = static_cast((prev_1+prev1)/2); + out[1][0] = static_cast((row0+row2)/2); out[1][1] = row1; out[1][2] = prev1; } @@ -532,8 +532,8 @@ struct bayer_sample_gbrg { T row0 = R::get(row[0]); T row1 = R::get(row[1]); out[0][0] = row0; - out[0][1] = (row_1+prev0 + row1)/3; - out[0][2] = (prev_1+prev1)/2; + out[0][1] = static_cast((row_1+prev0 + row1)/3); + out[0][2] = static_cast((prev_1+prev1)/2); out[1][0] = row0; out[1][1] = row1; out[1][2] = prev1; @@ -570,8 +570,8 @@ struct bayer_sample_grbg { out[0][2] = next0; out[0][1] = row0; out[0][0] = row1; - out[1][2] = (next0+next2)/2; - out[1][1] = (row0+row2+next1)/3; + out[1][2] = static_cast((next0+next2)/2); + out[1][1] = static_cast((row0+row2+next1)/3); out[1][0] = row1; } static inline void upper_row(T (*out)[3], const T * row, const T * next){ @@ -584,9 +584,9 @@ struct bayer_sample_grbg { T next2 = R::get(next[2]); out[0][2] = next0; out[0][1] = row0; - out[0][0] = (row_1+row1)/2; - out[1][2] = (next0+next2)/2; - out[1][1] = (row0+row2+next1)/3; + out[0][0] = static_cast((row_1+row1)/2); + out[1][2] = static_cast((next0+next2)/2); + out[1][1] = static_cast((row0+row2+next1)/3); out[1][0] = row1; } static inline void upper_right(T (*out)[3], const T * row, const T * next){ @@ -597,9 +597,9 @@ struct bayer_sample_grbg { T next1 = R::get(next[1]); out[0][2] = next0; out[0][1] = row0; - out[0][0] = (row_1+row1)/2; + out[0][0] = static_cast((row_1+row1)/2); out[1][2] = next0; - out[1][1] = (row0+next1)/2; + out[1][1] = static_cast((row0+next1)/2); out[1][0] = row1; } @@ -630,9 +630,9 @@ struct bayer_sample_grbg { T row1 = R::get(row[1]); T row2 = R::get(row[2]); out[0][2] = row0; - out[0][1] = (prev0 + row1)/2; + out[0][1] = static_cast((prev0 + row1)/2); out[0][0] = prev1; - out[1][2] = (row0+row2)/2; + out[1][2] = static_cast((row0+row2)/2); out[1][1] = row1; out[1][0] = prev1; } @@ -645,9 +645,9 @@ struct bayer_sample_grbg { T row1 = R::get(row[1]); T row2 = R::get(row[2]); out[0][2] = row0; - out[0][1] = (row_1+prev0 + row1)/3; - out[0][0] = (prev_1+prev1)/2; - out[1][2] = (row0+row2)/2; + out[0][1] = static_cast((row_1+prev0 + row1)/3); + out[0][0] = static_cast((prev_1+prev1)/2); + out[1][2] = static_cast((row0+row2)/2); out[1][1] = row1; out[1][0] = prev1; } @@ -659,8 +659,8 @@ struct bayer_sample_grbg { T row0 = R::get(row[0]); T row1 = R::get(row[1]); out[0][2] = row0; - out[0][1] = (row_1+prev0 + row1)/3; - out[0][0] = (prev_1+prev1)/2; + out[0][1] = static_cast((row_1+prev0 + row1)/3); + out[0][0] = static_cast((prev_1+prev1)/2); out[1][2] = row0; out[1][1] = row1; out[1][0] = prev1; @@ -737,7 +737,7 @@ void bayer_to_rgb(const T* bggr, int bggr_stride, T* rgb, int rgb_stride, unsign template -inline T cie(T * c) { return (c[0]*77 + c[1]*150 + c[2]*29)>>8; } +inline T cie(T * c) { return static_cast((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 diff --git a/cvd_src/connected_components.cc b/cvd_src/connected_components.cc index d1ff37c5..7a74cfc9 100644 --- a/cvd_src/connected_components.cc +++ b/cvd_src/connected_components.cc @@ -106,7 +106,7 @@ void connected_components(const vector& v, vector >& if(above_label == -1 && prev_x != pos.x-1) { parents.resize(parents.size()+1); - current_label = parents.size()-1; + current_label = static_cast(parents.size())-1; parents[current_label] = current_label; segments.resize(segments.size() + 1); diff --git a/cvd_src/draw.cc b/cvd_src/draw.cc index 1f487611..d73beccb 100644 --- a/cvd_src/draw.cc +++ b/cvd_src/draw.cc @@ -22,7 +22,7 @@ std::vector getCircle(int radius) { return points; } -std::vector getDisc(float radius) +std::vector getDisc(double radius) { std::vector points; diff --git a/cvd_src/image_io.cc b/cvd_src/image_io.cc index 523e0b89..fd50b8b1 100644 --- a/cvd_src/image_io.cc +++ b/cvd_src/image_io.cc @@ -90,7 +90,7 @@ ImageType::ImageType string_to_image_type(const std::string& name) std::string suffix = name.substr(dot+1,name.length()-dot-1); for (size_t i=0; i(tolower(suffix[i])); if (suffix == "ps") diff --git a/cvd_src/image_io/pnm_grok.cxx b/cvd_src/image_io/pnm_grok.cxx index 638e4b7f..9875f2f5 100644 --- a/cvd_src/image_io/pnm_grok.cxx +++ b/cvd_src/image_io/pnm_grok.cxx @@ -155,10 +155,10 @@ namespace CVD std::istream& i; bool is_text; int type, maxval; - int lines_so_far; + long lines_so_far; void read_header(); bool can_proc_lines(unsigned long); - long xs, ys; + int xs, ys; }; bool clean(istream& i) @@ -362,7 +362,7 @@ namespace CVD { int j=0; i >> j; //Ignore EOF: be leniant - *c = j & 0xff; + *c = static_cast(j & 0xff); } void get_num(istream& i, bool* c) @@ -377,7 +377,7 @@ namespace CVD { int j=0; i >> j; //Ignore EOF: be leniant - *c = j & 0xffff; + *c = static_cast(j & 0xffff); } template void get_num(istream& i, Rgb* c) diff --git a/cvd_src/noarch/yuv422.cpp b/cvd_src/noarch/yuv422.cpp index c6374374..8f450cb5 100644 --- a/cvd_src/noarch/yuv422.cpp +++ b/cvd_src/noarch/yuv422.cpp @@ -16,7 +16,7 @@ namespace CVD { else if(i>255) return 255; else - return i; + return static_cast(i); } struct yuv422_ind{ diff --git a/cvd_src/videosource.cpp b/cvd_src/videosource.cpp index 478e7fe1..373827f0 100644 --- a/cvd_src/videosource.cpp +++ b/cvd_src/videosource.cpp @@ -432,7 +432,7 @@ namespace CVD { } - void get_dc1394_options(const VideoSource& vs, ImageRef& size, float& fps, ImageRef& offset, bool& verbose, bool& bus_reset, int& format7_mode) + void get_dc1394_options(const VideoSource& vs, ImageRef& size, int& fps, ImageRef& offset, bool& verbose, bool& bus_reset, int& format7_mode) { size = offset = ImageRef(-1, -1); fps = -1; From 9bbcf407d7d44d0bf6259cba92f43acf1da91460 Mon Sep 17 00:00:00 2001 From: Edward Rosten Date: Thu, 22 Oct 2020 15:28:23 +0100 Subject: [PATCH 2/7] Fix -Wconversion warnings in gcc10 --- Makefile.in | 12 +- cvd/colourspaces.h | 170 +++-------- cvd/deinterlacebuffer.h | 10 +- cvd/distance_transform.h | 14 +- cvd/glwindow.h | 12 +- cvd/image_io.h | 2 +- cvd/image_ref.h | 2 + cvd/internal/convert_pixel_types.h | 2 +- cvd/internal/pixel_traits.h | 169 ++--------- cvd/internal/scalar_convert.h | 17 +- cvd/timer.h | 2 +- cvd/videosource.h | 4 +- cvd_src/Linux/dvbuffer3_dc1394v2.cc | 2 +- cvd_src/Linux/v4lbuffer.cc | 12 +- cvd_src/SSE/convolve_gaussian.cc | 426 ++++++++++++++------------- cvd_src/SSE2/faster_corner_12.cxx | 2 +- cvd_src/convolution.cc | 4 +- cvd_src/cvd_timer.cc | 2 +- cvd_src/fast/fast_10_detect.cxx | 2 +- cvd_src/fast/fast_11_detect.cxx | 2 +- cvd_src/fast/fast_12_detect.cxx | 2 +- cvd_src/fast/fast_7_detect.cxx | 2 +- cvd_src/fast/fast_8_detect.cxx | 2 +- cvd_src/fast/fast_9_detect.cxx | 2 +- cvd_src/gltext.cpp | 6 +- cvd_src/glwindow.cc | 6 +- cvd_src/image_io/bmp.cxx | 37 ++- cvd_src/image_io/cvdimage.cxx | 57 ++-- cvd_src/image_io/fits.cc | 2 +- cvd_src/image_io/fitswrite.cc | 27 +- cvd_src/image_io/jpeg.cxx | 24 +- cvd_src/image_io/png.cc | 12 +- cvd_src/image_io/save_postscript.cxx | 8 +- cvd_src/image_io/text.cxx | 2 +- cvd_src/image_io/tiff.cxx | 36 ++- cvd_src/image_io/tiffwrite.cc | 4 +- cvd_src/videodisplay.cc | 12 +- cvd_src/videofilebuffer2.cc | 4 +- cvd_src/videosource.cpp | 36 ++- progs/cvd_display_image.cxx | 2 +- progs/video_play_source.cc | 14 +- tests/convolution.cc | 2 +- tests/distance_transform_test.cc | 9 +- tests/fast_corner_test.cc | 18 +- tests/load_and_save.cc | 46 ++- 45 files changed, 568 insertions(+), 672 deletions(-) diff --git a/Makefile.in b/Makefile.in index 26021cf7..a60a0db1 100644 --- a/Makefile.in +++ b/Makefile.in @@ -157,10 +157,16 @@ all: libcvd.a $(soname) $(dllname) progs cyg%.dll lib%.dll.a: lib%.a $(LD) -shared -o cyg$*.dll -Wl,--out-implib=lib$*.dll.a -Wl,--export-all-symbols -Wl,--enable-auto-import -Wl,--whole-archive lib$*.a -Wl,--no-whole-archive $(LDFLAGS) $(LOADLIBES) -$(soname): $(OBJS) - rm -f $(sos) +$(soname2): $(OBJS) + rm -f $(soname2) $(LD) $(shared) -o $(soname2) $(OBJS) $(LDFLAGS) $(LOADLIBES) $(set_soname) + +$(soname1): $(soname2) + rm -f $(soname1) ln -s $(soname2) $(soname1) + +$(soname): $(soname1) + rm -f $(soname) ln -s $(soname1) $(soname) libcvd.a: $(OBJS) @@ -310,7 +316,7 @@ $(EXAMPLE_PROGS): % : %.cc clean: - rm -f tmp libcvd.a $(sos) $(dllname) $(ddllname) $(dllimportname) $(ddllimportname) + rm -f tmp libcvd.a *.so* $(dllname) $(ddllname) $(dllimportname) $(ddllimportname) find . -name '*.o' -o -name '*.d' | xargs rm -f find progs/ -perm /u+x -type f | xargs rm -f rm -rf html man diff --git a/cvd/colourspaces.h b/cvd/colourspaces.h index 5ff4b174..15029d28 100644 --- a/cvd/colourspaces.h +++ b/cvd/colourspaces.h @@ -206,127 +206,55 @@ namespace CVD template<> struct type_name { static std::string name(){return "MJPEG" ;}}; } - namespace Pixel { - template struct traits - { - typedef int wider_type; - typedef float float_type; - static const bool integral = true; - static const bool is_signed = false; - static const int bits_used = 8; - static const unsigned char max_intensity=(1 << bits_used) - 1; - }; - - template struct traits - { - typedef int wider_type; - typedef float float_type; - static const bool integral = true; - static const bool is_signed = false; - static const int bits_used = 8; - static const unsigned char max_intensity=(1 << bits_used) - 1; - }; - - template struct traits - { - typedef int wider_type; - typedef float float_type; - static const bool integral = true; - static const bool is_signed = false; - static const int bits_used = 8; - static const unsigned char max_intensity=(1 << bits_used) - 1; - }; - - template struct traits - { - typedef int wider_type; - typedef float float_type; - static const bool integral = true; - static const bool is_signed = false; - static const int bits_used = 8; - static const unsigned char max_intensity=(1 << bits_used) - 1; - }; - - template struct traits - { - typedef int wider_type; - typedef float float_type; - static const bool integral = true; - static const bool is_signed = false; - static const int bits_used = 16; - static const unsigned short max_intensity=(1 << bits_used) - 1; - }; - - template struct traits - { - typedef int wider_type; - typedef float float_type; - static const bool integral = true; - static const bool is_signed = false; - static const int bits_used = 16; - static const unsigned short max_intensity=(1 << bits_used) - 1; - }; - - template struct traits - { - typedef int wider_type; - typedef float float_type; - static const bool integral = true; - static const bool is_signed = false; - static const int bits_used = 16; - static const unsigned short max_intensity=(1 << bits_used) - 1; - }; - - template struct traits - { - typedef int wider_type; - typedef float float_type; - static const bool integral = true; - static const bool is_signed = false; - static const int bits_used = 16; - static const unsigned short max_intensity=(1 << bits_used) - 1; - }; - - template struct traits - { - typedef int wider_type; - typedef float float_type; - static const bool integral = true; - static const bool is_signed = false; - static const int bits_used = 16; - static const unsigned short max_intensity=(1 << bits_used) - 1; - }; - - template struct traits - { - typedef int wider_type; - typedef float float_type; - static const bool integral = true; - static const bool is_signed = false; - static const int bits_used = 16; - static const unsigned short max_intensity=(1 << bits_used) - 1; - }; - - template struct traits - { - typedef int wider_type; - typedef float float_type; - static const bool integral = true; - static const bool is_signed = false; - static const int bits_used = 16; - static const unsigned short max_intensity=(1 << bits_used) - 1; - }; - - template struct traits - { - typedef int wider_type; - typedef float float_type; - static const bool integral = true; - static const bool is_signed = false; - static const int bits_used = 16; - static const unsigned short max_intensity=(1 << bits_used) - 1; - }; - } + namespace Pixel { + template struct traits : public traits + { + }; + + template struct traits : public traits + { + }; + + template struct traits: public traits + { + }; + + template struct traits: public traits + { + }; + + template struct traits: public traits + { + }; + + template struct traits: public traits + { + }; + + template struct traits: public traits + { + }; + + template struct traits: public traits + { + }; + + template struct traits: public traits + { + }; + + template struct traits: public traits + { + }; + + template struct traits: public traits + { + }; + + template struct traits: public traits + { + }; + } } diff --git a/cvd/deinterlacebuffer.h b/cvd/deinterlacebuffer.h index fc8c1420..afa28fbb 100644 --- a/cvd/deinterlacebuffer.h +++ b/cvd/deinterlacebuffer.h @@ -113,7 +113,7 @@ class DeinterlaceBuffer : public VideoBuffer Fields::Fields m_fields; bool m_loadnewframe; ImageRef m_size; - unsigned int m_linebytes; + long m_linebytes; bool line_double; }; @@ -180,8 +180,8 @@ VideoFrame* DeinterlaceBuffer::get_frame() for(int y=2; y < m_size.y-1; y+=2) for(int x=0; x < m_size.x; x++) for(unsigned int i=0; i < Pixel::Component::count; i++) - Pixel::Component::get((*frame)[y][x],i) = (Pixel::Component::get((*my_realframe)[y-1][x],i) + - Pixel::Component::get((*my_realframe)[y+1][x],i))/2; + Pixel::Component::get((*frame)[y][x],i) = static_cast::type>((Pixel::Component::get((*my_realframe)[y-1][x],i) + + Pixel::Component::get((*my_realframe)[y+1][x],i))/2); /* //Copy line 0 from line 1, and copy over line 1 to line 1 @@ -221,8 +221,8 @@ VideoFrame* DeinterlaceBuffer::get_frame() for(int y=1; y < m_size.y-1; y+=2) for(int x=0; x < m_size.x; x++) for(unsigned int i=0; i < Pixel::Component::count; i++) - Pixel::Component::get((*frame)[y][x],i) = (Pixel::Component::get((*my_realframe)[y-1][x],i) + - Pixel::Component::get((*my_realframe)[y+1][x],i))/2; + Pixel::Component::get((*frame)[y][x],i) = static_cast::type>((Pixel::Component::get((*my_realframe)[y-1][x],i) + + Pixel::Component::get((*my_realframe)[y+1][x],i))/2); /* //Copy over and double the first set of lines for(int y=0; y < m_size.y-2; y+=2) diff --git a/cvd/distance_transform.h b/cvd/distance_transform.h index c60a3642..3684aff8 100644 --- a/cvd/distance_transform.h +++ b/cvd/distance_transform.h @@ -24,7 +24,7 @@ namespace CVD { public: DistanceTransformEuclidean() :sz(ImageRef(-1,-1)), - big_number(1e9) //Hmm, why doesn't HUGE_VAL work? + big_number(1'000'000'000) //Hmm, why doesn't HUGE_VAL work? //Anyway, hilariously small number here so it works with int, too. {} @@ -109,11 +109,11 @@ namespace CVD { } const double dx = pos[x]; const double dy = sqrt(hyp - dx * dx); - const int ddy = dy; - const ImageRef candA(x - dx, y - ddy); - const ImageRef candB(x - dx, y + ddy); - const ImageRef candC(x + dx, y - ddy); - const ImageRef candD(x + dx, y + ddy); + const int ddy = static_cast(dy); + const ImageRef candA(static_cast(x - dx), static_cast(y - ddy)); + const ImageRef candB(static_cast(x - dx), static_cast(y + ddy)); + const ImageRef candC(static_cast(x + dx), static_cast(y - ddy)); + const ImageRef candD(static_cast(x + dx), static_cast(y + ddy)); /** cerr << "hyp=" << hyp << " dx="<< dx << " dy=" << dy << " ddy=" << ddy << " A=" << candA << " B=" << candB << " C=" << candC << " D=" << candD << endl;*/ if (DT.in_image(candA) && func(candA)) { @@ -199,7 +199,7 @@ namespace CVD { private: ImageRef sz; - double big_number; + int big_number; std::vector d; std::vector v; std::vector z; diff --git a/cvd/glwindow.h b/cvd/glwindow.h index d9c1ca89..6a3cd157 100644 --- a/cvd/glwindow.h +++ b/cvd/glwindow.h @@ -49,19 +49,19 @@ namespace CVD { public: virtual ~EventHandler() {} /// Called for key press events - virtual void on_key_down(GLWindow&, int /*key*/) {} + virtual void on_key_down(GLWindow&, unsigned int /*key*/) {} /// Called for key release events - virtual void on_key_up(GLWindow& /*win*/, int /*key*/) {} + virtual void on_key_up(GLWindow& /*win*/, unsigned int /*key*/) {} /// Called for mouse movement events - virtual void on_mouse_move(GLWindow& /*win*/, ImageRef /*where*/, int /*state*/) {} + virtual void on_mouse_move(GLWindow& /*win*/, ImageRef /*where*/, unsigned int /*state*/) {} /// Called for mouse button press events - virtual void on_mouse_down(GLWindow& /*win*/, ImageRef /*where*/, int /*state*/, int /*button*/) {} + virtual void on_mouse_down(GLWindow& /*win*/, ImageRef /*where*/, unsigned int /*state*/, unsigned int /*button*/) {} /// Called for mouse button release events - virtual void on_mouse_up(GLWindow& /*win*/, ImageRef /*where*/, int /*state*/, int /*button*/) {} + virtual void on_mouse_up(GLWindow& /*win*/, ImageRef /*where*/, unsigned int /*state*/, unsigned int /*button*/) {} /// Called for window resize events virtual void on_resize(GLWindow& /*win*/, ImageRef /*size*/) {} /// Called for general window events (such as EVENT_CLOSE) - virtual void on_event(GLWindow& /*win*/, int /*event*/) {} + virtual void on_event(GLWindow& /*win*/, unsigned int /*event*/) {} }; struct Event { diff --git a/cvd/image_io.h b/cvd/image_io.h index 8bf964c1..fe4aa55f 100644 --- a/cvd/image_io.h +++ b/cvd/image_io.h @@ -174,7 +174,7 @@ namespace CVD else throw Exceptions::Image_IO::EofBeforeImage(); } - unsigned char c = i.peek(); + int c = i.peek(); if(!i.good()) throw Exceptions::Image_IO::EofBeforeImage(); diff --git a/cvd/image_ref.h b/cvd/image_ref.h index d5ef8fe0..f7a59dcf 100644 --- a/cvd/image_ref.h +++ b/cvd/image_ref.h @@ -32,6 +32,8 @@ class ImageRef //Construction /// Construct an ImageRef initialised at (0,0) constexpr ImageRef(); + constexpr ImageRef(const ImageRef&)=default; + /// Construct an ImageRef /// @param xp The x co-ordinate /// @param yp The y co-ordinate diff --git a/cvd/internal/convert_pixel_types.h b/cvd/internal/convert_pixel_types.h index 6642bb49..7f2925ee 100644 --- a/cvd/internal/convert_pixel_types.h +++ b/cvd/internal/convert_pixel_types.h @@ -75,7 +75,7 @@ namespace CVD{namespace Pixel Fortunately, we have forseen this eventuality, and scalar_convert can convert from type A, to type B when pixel type B is held in a variable of type C */ - to = scalar_convert::type,double>(wr*from.red + wg*from.green + wb*from.blue); + to = scalar_convert::type,double>(wr*static_cast(from.red) + wg*static_cast(from.green) + wb*static_cast(from.blue)); /* The following method could be used (for speed): diff --git a/cvd/internal/pixel_traits.h b/cvd/internal/pixel_traits.h index 853df432..d6a75dbe 100644 --- a/cvd/internal/pixel_traits.h +++ b/cvd/internal/pixel_traits.h @@ -10,132 +10,24 @@ namespace CVD { namespace Pixel { - //This is required for MIPSPro, since it is able to deduce more than gcc 3.3 - //before a template is instantiated - template struct traits_error + template struct traits { - }; - - // LIFT is a dummy parameter to lift the partial specialisations of traits - // on various types into templates again. Then the visibility of static const - // members is sorted out by the compiler correctly. - template struct traits: public traits_error - { - static const bool integral=traits_error::Error_trait_not_defined_for_this_class; - }; - - template struct traits - { - typedef int wider_type; - typedef float float_type; - static const bool integral = true; - static const bool is_signed = false; - static const int bits_used = 8; - static const unsigned char max_intensity=(1 << bits_used) - 1; - }; - - template struct traits - { - typedef int wider_type; - typedef float float_type; - static const bool integral = true; - static const bool is_signed = std::numeric_limits::is_signed; - static const int bits_used = std::numeric_limits::digits; - static const char max_intensity=(1 << bits_used) - 1; - }; - - template struct traits - { - typedef int wider_type; - typedef float float_type; - static const bool integral = true; - static const bool is_signed = false; - static const int bits_used = 7; - static const signed char max_intensity=(1 << bits_used) - 1; - }; - - template struct traits - { - typedef int wider_type; + static_assert(std::numeric_limits::is_specialized == true); + using element_type = T; + using wider_type = decltype(T{}*T{}); typedef float float_type; static const bool integral = true; - static const bool is_signed = true; - static const int bits_used = 15; - static const short max_intensity=(1 << bits_used) - 1; + static const bool is_signed = std::numeric_limits::is_signed; + static_assert(std::numeric_limits::is_integer == true); + static const int bits_used = std::numeric_limits::digits; + static const T max_intensity = std::numeric_limits::max(); }; - template struct traits - { - typedef int wider_type; - typedef float float_type; - static const bool integral = true; - static const bool is_signed = false; - static const int bits_used = 16; - static const unsigned short max_intensity=(1 << bits_used) - 1; - }; - template struct traits - { - typedef int wider_type; - typedef float float_type; - static const bool integral = true; - static const bool is_signed = true; - static const int bits_used = 16; - static const int max_intensity=(1 << bits_used) - 1; - }; - - template struct traits - { - typedef unsigned int wider_type; - typedef float float_type; - static const bool integral = true; - static const bool is_signed = false; - static const int bits_used = 16; - static const unsigned int max_intensity=(1 << bits_used) - 1; - }; - - template struct traits - { - typedef int wider_type; - typedef float float_type; - static const bool integral = true; - static const bool is_signed = true; - static const int bits_used = 16; - static const long max_intensity=(1 << bits_used) - 1; - }; - - template struct traits - { - typedef long long wider_type; - typedef double float_type; - static const bool integral = true; - static const bool is_signed = true; - static const int bits_used = 31; - static const long long max_intensity=(1ll << bits_used) - 1ll; - }; - - template struct traits - { - typedef unsigned long long wider_type; - typedef double float_type; - static const bool integral = true; - static const bool is_signed = false; - static const int bits_used = 31; - static const unsigned long long max_intensity=(1ull << bits_used) - 1ull; - }; - - template struct traits - { - typedef unsigned int wider_type; - typedef float float_type; - static const bool integral = true; - static const bool is_signed = false; - static const int bits_used = 16; - static const long max_intensity=(1 << bits_used) - 1; - }; template struct traits { + using element_type = float; typedef float wider_type; typedef float float_type; static const bool integral = false; @@ -147,6 +39,7 @@ namespace Pixel { template struct traits { + using element_type = double; typedef double wider_type; typedef double float_type; static const bool integral = false; @@ -158,6 +51,7 @@ namespace Pixel { template struct traits { + using element_type = long double; typedef long double wider_type; typedef long double float_type; static const bool integral = false; @@ -165,35 +59,24 @@ namespace Pixel { static const long double max_intensity; }; - template struct traits +#if defined (CVD_HAVE_TOON) + template struct traits > { - typedef int wider_type; // int holds a sum of many bools - typedef float float_type; // which floating point type can hold them? - static const bool integral = true; // bool is integral - static const bool is_signed = false; // bool is unsigned - static const int bits_used = 1; // only one bit - static const bool max_intensity= true; // the 'high' value + typedef TooN::Vector wider_type; + typedef TooN::Vector float_type; + static const bool integral = false; + static const bool is_signed = true; + static const TooN::Vector max_intensity; }; + template const TooN::Vector traits >::max_intensity = TooN::Vector(1.0); - -#if defined (CVD_HAVE_TOON) - template struct traits > - { - typedef TooN::Vector wider_type; - typedef TooN::Vector float_type; - static const bool integral = false; - static const bool is_signed = true; - static const TooN::Vector max_intensity; - }; - template const TooN::Vector traits >::max_intensity = TooN::Vector(1.0); - - template struct traits > - { - typedef TooN::Matrix wider_type; - typedef TooN::Matrix float_type; - static const bool integral = false; - static const bool is_signed = true; - }; + template struct traits > + { + typedef TooN::Matrix wider_type; + typedef TooN::Matrix float_type; + static const bool integral = false; + static const bool is_signed = true; + }; #endif diff --git a/cvd/internal/scalar_convert.h b/cvd/internal/scalar_convert.h index 2d9b85cd..84dbf081 100644 --- a/cvd/internal/scalar_convert.h +++ b/cvd/internal/scalar_convert.h @@ -26,7 +26,7 @@ namespace Pixel // truncate( 1011 * 1000100010.00100010001000100010001000... // // Which is equal to multiplying by (high_precision_max + 1)/(low_precision_max) - // Where strict rruncation occurs, ie 1.1111111... trucates to 1 + // Where strict truncation occurs, ie 1.1111111... trucates to 1 // template struct int_info { //Difference in number of bits used @@ -48,7 +48,7 @@ namespace Pixel { static To aggregate(To i) { - return i << shift | upshift::aggregate(i); + return static_cast::element_type>(i << shift | upshift::aggregate(i)); } }; template struct upshift @@ -76,7 +76,7 @@ namespace Pixel template struct shift_convert { template static To from(D f) { - return static_cast(f >> -int_info::diff); + return static_cast::element_type>(f >> -int_info::diff); } }; @@ -122,9 +122,14 @@ namespace Pixel //FIXME: why is the test on "From", not "D"?? template ::integral && traits::integral, bool int2 =traits::integral> struct ScalarConvert { static inline To from(const D& from) { - static const double factor = double(traits::max_intensity)/traits::max_intensity; - auto s = from * factor; - return static_cast(s); + + //Casts here to avoid conversion warnings since double can't represent uint64_t + static const double factor = static_cast(traits::max_intensity)/static_cast(traits::max_intensity); + //Cast to suppress conversion warning, since double can't represent uint64_t completely + auto s = static_cast(from) * factor; + //Cast to suppress conversion warning for special scalar types, like bayer whose underling + //type is char, but casting to bayer hits the constructor without the cast + return static_cast::element_type>(s); } }; diff --git a/cvd/timer.h b/cvd/timer.h index eefb66ad..d4ac5fb7 100644 --- a/cvd/timer.h +++ b/cvd/timer.h @@ -147,7 +147,7 @@ class SimpleTimer cumulative_time=0; for(int i=0; i<(int)time_buffer.size(); ++i) cumulative_time+=time_buffer[i]; - average=cumulative_time/time_buffer.size(); + average=cumulative_time/static_cast(time_buffer.size()); } return average; } diff --git a/cvd/videosource.h b/cvd/videosource.h index e4620235..a738051f 100644 --- a/cvd/videosource.h +++ b/cvd/videosource.h @@ -317,7 +317,7 @@ namespace CVD { template <> VideoBuffer* makeDVBuffer2(int cam, ImageRef size, float fps, ImageRef offset, bool verbose, bool bus_reset, int format7_mode); template <> VideoBuffer* makeDVBuffer2(int cam, ImageRef size, float fps, ImageRef offset, bool verbose, bool bus_reset, int format7_mode); - void get_dc1394_options(const VideoSource& vs, ImageRef& size, int& fps, ImageRef& offset, bool& verbose, bool& bus_reset, int& format7_mode); + void get_dc1394_options(const VideoSource& vs, ImageRef& size, float& fps, ImageRef& offset, bool& verbose, bool& bus_reset, int& format7_mode); //////////////////////////////////////////////////////////////////////////////// @@ -394,7 +394,7 @@ namespace CVD { else if (vs.protocol == "dc1394") { int cam_no = atoi(vs.identifier.c_str()); ImageRef size, offset; - int fps; + float fps; bool verbose; bool bus_reset; int format7_mode; diff --git a/cvd_src/Linux/dvbuffer3_dc1394v2.cc b/cvd_src/Linux/dvbuffer3_dc1394v2.cc index 04459118..763ace64 100644 --- a/cvd_src/Linux/dvbuffer3_dc1394v2.cc +++ b/cvd_src/Linux/dvbuffer3_dc1394v2.cc @@ -122,7 +122,7 @@ namespace CVD struct DV3Frame : public VideoFrame { DV3Frame(dc1394video_frame_t *pDC1394Frame) - : VideoFrame(const_cast(timer).conv_ntime(pDC1394Frame->timestamp / 1000000.0), + : VideoFrame(const_cast(timer).conv_ntime(static_cast(pDC1394Frame->timestamp) / 1000000.0), pDC1394Frame->image, ImageRef(pDC1394Frame->size[0], pDC1394Frame->size[1])) { mpDC1394Frame = pDC1394Frame; } diff --git a/cvd_src/Linux/v4lbuffer.cc b/cvd_src/Linux/v4lbuffer.cc index 2b083512..65fd340f 100644 --- a/cvd_src/Linux/v4lbuffer.cc +++ b/cvd_src/Linux/v4lbuffer.cc @@ -78,10 +78,10 @@ string unfourcc(unsigned long c) string ret; ret.resize(4); - ret[0] = c & 0xff; - ret[1] = (c>>8) & 0xff; - ret[2] = (c>>16) & 0xff; - ret[3] = (c>>24) & 0xff; + ret[0] = static_cast(c & 0xff); + ret[1] = static_cast((c>>8) & 0xff); + ret[2] = static_cast((c>>16) & 0xff); + ret[3] = static_cast((c>>24) & 0xff); return ret; } @@ -329,7 +329,7 @@ namespace V4L { // V4L struct v4l2_buffer buffer; buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buffer.memory = V4L2_MEMORY_MMAP; - buffer.index = i; + buffer.index = static_cast(i); if (0 != ioctl(fd, VIDIOC_QUERYBUF, &buffer)) throw Exceptions::V4LBuffer::DeviceSetup(dev, "V4L2: VIDIOC_QUERYBUF"); if (i == 0) @@ -407,7 +407,7 @@ namespace V4L { // V4L Buffer ret; ret.id = buffer.index; ret.data = static_cast(state->frames[buffer.index].data); - ret.when = buffer.timestamp.tv_usec * 1e-6 + buffer.timestamp.tv_sec; + ret.when = static_cast(buffer.timestamp.tv_usec) * 1e-6 + static_cast(buffer.timestamp.tv_sec); return ret; } diff --git a/cvd_src/SSE/convolve_gaussian.cc b/cvd_src/SSE/convolve_gaussian.cc index 1b919867..4d1c0d78 100644 --- a/cvd_src/SSE/convolve_gaussian.cc +++ b/cvd_src/SSE/convolve_gaussian.cc @@ -26,46 +26,46 @@ inline __m128 operator*( const __m128 & a, const __m128 & b){ #endif -inline void convolveMiddle5(const float* in, double factor, const double kernel[], int count, float* out) +inline void convolveMiddle5(const float* in, float factor, const float kernel[], int count, float* out) { int i; const __m128 ffff = _mm_set1_ps(factor); const __m128 k1 = _mm_set1_ps(kernel[0]); const __m128 k2 = _mm_set1_ps(kernel[1]); for (i=0; i+3& kernel, int count, float* out) +inline void convolveMiddle(const float* in, float factor, const vector& kernel, int count, float* out) { - const int ksize = kernel.size(); + const int ksize = static_cast(kernel.size()); if (ksize == 2) { - convolveMiddle5(in, factor, &kernel[0], count, out); - return; + convolveMiddle5(in, factor, &kernel[0], count, out); + return; } int i; const __m128 ffff = _mm_set1_ps(factor); for (i=0; i+3 inline __m128 load_ps(const float* f) { return _mm_load_ps(f); template inline void store_ps(float* f, __m128 d) { _mm_storeu_ps(f,d); } template <> inline void store_ps(float* f, __m128 d) { _mm_store_ps(f,d); } -template -inline void convolveVertical5(const vector& row, double factor, const double kernel[], int count, float* out) + template +inline void convolveVertical5(const vector& row, float factor, const float kernel[], int count, float* out) { const int ksize = 2; int i; for (i=0; i(out); ++i, ++out) { - double sum = row[ksize][i] * factor + (row[1][i] + row[3][i]) * kernel[0] + (row[0][i] + row[4][i]) * kernel[1]; - *out = sum; + float sum = row[ksize][i] * factor + (row[1][i] + row[3][i]) * kernel[0] + (row[0][i] + row[4][i]) * kernel[1]; + *out = sum; } const __m128 ffff = _mm_set1_ps(factor); @@ -90,45 +90,45 @@ inline void convolveVertical5(const vector& row, double factor, const do const __m128 k2 = _mm_set1_ps(kernel[1]); for (; i+3(row[ksize] + i) * ffff - + (load_ps(row[ksize-1]+i) + load_ps(row[ksize+1]+i)) * k1 - + (load_ps(row[ksize-2]+i) + load_ps(row[ksize+2]+i)) * k2); - store_ps(out, sum); + __m128 sum = (load_ps(row[ksize] + i) * ffff + + (load_ps(row[ksize-1]+i) + load_ps(row[ksize+1]+i)) * k1 + + (load_ps(row[ksize-2]+i) + load_ps(row[ksize+2]+i)) * k2); + store_ps(out, sum); } for (; i -inline void convolveVertical(const vector& row, double factor, const vector& kernel, int count, float* out) + template +inline void convolveVertical(const vector& row, float factor, const vector& kernel, int count, float* out) { const int ksize = static_cast(kernel.size()); if (ksize == 2) { - convolveVertical5(row, factor, &kernel[0], count, out); - return; + convolveVertical5(row, factor, &kernel[0], count, out); + return; } - + int i; for (i=0; i(out); ++i, ++out) { - double sum = row[ksize][i] * factor; - for (int k=1; k<=ksize; ++k) - sum += kernel[k-1] * (row[ksize-k][i] + row[ksize+k][i]); - *out = sum; + float sum = row[ksize][i] * factor; + for (int k=1; k<=ksize; ++k) + sum += kernel[k-1] * (row[ksize-k][i] + row[ksize+k][i]); + *out = sum; } const __m128 ffff = _mm_set1_ps(factor); for (; i+3(row[ksize] + i), ffff); - for (int k=1; k<=ksize; ++k) - sum += _mm_set1_ps(kernel[k-1]) * (load_ps(row[ksize-k]+i) + load_ps(row[ksize+k]+i)); - store_ps(out, sum); + __m128 sum = _mm_mul_ps(load_ps(row[ksize] + i), ffff); + for (int k=1; k<=ksize; ++k) + sum += _mm_set1_ps(kernel[k-1]) * (load_ps(row[ksize-k]+i) + load_ps(row[ksize+k]+i)); + store_ps(out, sum); } for (; i& I, BasicImage& out, d { assert(out.size() == I.size()); int ksize = (int)ceil(sigmas*sigma); - vector kernel(ksize); + vector kernel(ksize); double ksum = 1.0; for (int i=1; i<=ksize; i++) - ksum += 2*(kernel[i-1] = exp(-i*i/(2*sigma*sigma))); - double factor = 1.0/ksum; + ksum += 2*(kernel[i-1] = static_cast(exp(-i*i/(2*sigma*sigma)))); + float factor = static_cast(1.0/ksum); for (int i=0; i& I, BasicImage& out, d vector rows(swin+1); for (int k=0;k&, double, const vector&, int, float*); + typedef void (*CONV_VERT_FUNC)(const vector&, float, const vector&, int, float*); const bool aligned = is_aligned<16>(I[0]) && is_aligned<16>(I[1]); CONV_VERT_FUNC conv_vert = aligned ? (CONV_VERT_FUNC)convolveVertical : (CONV_VERT_FUNC)convolveVertical; for (int i=0; i ksize) - for (int j=w-ksize; j= swin) { - conv_vert(rows, factor, kernel, w, output); - output += w; - if (i == h-1) { - for (int r=0; r rrows(rows.size()); - rrows[ksize] = rows[ksize+r+1]; - for (int k=0; k rrows(rows.size()); - rrows[ksize] = rows[r+1]; - for (int k=0; k ksize) + for (int j=w-ksize; j= swin) { + conv_vert(rows, factor, kernel, w, output); + output += w; + if (i == h-1) { + for (int r=0; r rrows(rows.size()); + rrows[ksize] = rows[ksize+r+1]; + for (int k=0; k rrows(rows.size()); + rrows[ksize] = rows[r+1]; + for (int k=0; k in, BasicImag __m128 M[9] __attribute__((aligned(16))); #endif - { - double m[3][3]; - compute_triggs_M(b, m); - for (int i=0; i<3; ++i) - for (int j=0; j<3; ++j) - M[i*3+j] = _mm_set1_ps(m[i][j]); + { + double m[3][3]; + compute_triggs_M(b, m); + for (int i=0; i<3; ++i) + for (int j=0; j<3; ++j) + M[i*3+j] = _mm_set1_ps(static_cast(m[i][j])); } const double alpha = 1 + b[0] + b[1] + b[2]; - const __m128 a2 = _mm_set1_ps(alpha*alpha); - - - const __m128 inv_alpha = _mm_set1_ps(1.0/alpha); - const __m128 bb1 = _mm_set1_ps(b[0]); - const __m128 bb2 = _mm_set1_ps(b[1]); - const __m128 bb3 = _mm_set1_ps(b[2]); - + const __m128 a2 = _mm_set1_ps(static_cast(alpha*alpha)); + + + const __m128 inv_alpha = _mm_set1_ps(static_cast(1.0/alpha)); + const __m128 bb1 = _mm_set1_ps(static_cast(b[0])); + const __m128 bb2 = _mm_set1_ps(static_cast(b[1])); + const __m128 bb3 = _mm_set1_ps(static_cast(b[2])); + // horizontal for (int i=0; i=0; j-=4, o-=4) { - __m128 y00 = tmp[j] - (bb1*y1 + bb2*y2 + bb3*y3); - __m128 y01 = y3 = tmp[j-1] - (bb1*y00 + bb2*y1 + bb3*y2); - __m128 y02 = y2 = tmp[j-2] - (bb1*y01 + bb2*y00 + bb3*y1); - __m128 y03 = y1 = tmp[j-3] - (bb1*y02 + bb2*y01 + bb3*y00); - transpose(y03,y02,y01,y00); - _mm_store_ps(o, a2*y03); - _mm_store_ps(o+os, a2*y02); - _mm_store_ps(o+2*os, a2*y01); - _mm_store_ps(o+3*os, a2*y00); - } + const float* p = in[i]; + + __m128 y3, y2, y1; + y3 = y2 = y1 = inv_alpha*_mm_setr_ps(p[0], p[is], p[2*is], p[3*is]); + + for (int j=0; j+3=0; j-=4, o-=4) { + __m128 y00 = tmp[j] - (bb1*y1 + bb2*y2 + bb3*y3); + __m128 y01 = y3 = tmp[j-1] - (bb1*y00 + bb2*y1 + bb3*y2); + __m128 y02 = y2 = tmp[j-2] - (bb1*y01 + bb2*y00 + bb3*y1); + __m128 y03 = y1 = tmp[j-3] - (bb1*y02 + bb2*y01 + bb3*y00); + transpose(y03,y02,y01,y00); + _mm_store_ps(o, a2*y03); + _mm_store_ps(o+os, a2*y02); + _mm_store_ps(o+2*os, a2*y01); + _mm_store_ps(o+3*os, a2*y00); + } } // vertical for (int i=0; i=0; j-=4, o-=os) { - __m128 y0 = tmp[j] - (bb1*y1 + bb2*y2 + bb3*y3); - y3 = tmp[j-1] - (bb1*y0 + bb2*y1 + bb3*y2); - y2 = tmp[j-2] - (bb1*y3 + bb2*y0 + bb3*y1); - y1 = tmp[j-3] - (bb1*y2 + bb2*y3 + bb3*y0); - - _mm_store_ps(o, a2*y0);//_mm_min_ps(ones, _mm_max_ps(zeros,a4*y0))); - o -= os; - _mm_store_ps(o, a2*y3);//_mm_min_ps(ones, _mm_max_ps(zeros,a4*y3))); - o -= os; - _mm_store_ps(o, a2*y2);//_mm_min_ps(ones, _mm_max_ps(zeros,a4*y2))); - o -= os; - _mm_store_ps(o, a2*y1);//_mm_min_ps(ones, _mm_max_ps(zeros,a4*y1))); - } + const float* in = out[0] + i; + __m128 y3, y2, y1; + y3 = y2 = y1 = inv_alpha*_mm_load_ps(in); + + for (int j=0; j=0; j-=4, o-=os) { + __m128 y0 = tmp[j] - (bb1*y1 + bb2*y2 + bb3*y3); + y3 = tmp[j-1] - (bb1*y0 + bb2*y1 + bb3*y2); + y2 = tmp[j-2] - (bb1*y3 + bb2*y0 + bb3*y1); + y1 = tmp[j-3] - (bb1*y2 + bb2*y3 + bb3*y0); + + _mm_store_ps(o, a2*y0);//_mm_min_ps(ones, _mm_max_ps(zeros,a4*y0))); + o -= os; + _mm_store_ps(o, a2*y3);//_mm_min_ps(ones, _mm_max_ps(zeros,a4*y3))); + o -= os; + _mm_store_ps(o, a2*y2);//_mm_min_ps(ones, _mm_max_ps(zeros,a4*y2))); + o -= os; + _mm_store_ps(o, a2*y1);//_mm_min_ps(ones, _mm_max_ps(zeros,a4*y1))); + } } _mm_setcsr(csr_state); } @@ -383,21 +387,21 @@ void convolveGaussian(const BasicImage& I, BasicImage& out, double { int ksize = (int)ceil(sigma*sigmas); bool nice = ((I.size().x%4) == 0 && - (I.size().y%4)==0 && - (I.row_stride()%4) == 0 && - (out.row_stride()%4) == 0 && - is_aligned<16>(I[0]) && - is_aligned<16>(out[0])); + (I.size().y%4)==0 && + (I.row_stride()%4) == 0 && + (out.row_stride()%4) == 0 && + is_aligned<16>(I[0]) && + is_aligned<16>(out[0])); if (nice && ksize > 2) { - double b[3]; - compute_van_vliet_b(sigma, b); - van_vliet_blur_simd(b, I, out); + double b[3]; + compute_van_vliet_b(sigma, b); + van_vliet_blur_simd(b, I, out); } else if (ksize > 6) { - double b[3]; - compute_van_vliet_b(sigma, b); - van_vliet_blur(b, I, out); + double b[3]; + compute_van_vliet_b(sigma, b); + van_vliet_blur(b, I, out); } else - convolveGaussian_simd(I, out, sigma, sigmas); + convolveGaussian_simd(I, out, sigma, sigmas); } void convolveGaussian_fir(const BasicImage& I, BasicImage& out, double sigma, double sigmas) diff --git a/cvd_src/SSE2/faster_corner_12.cxx b/cvd_src/SSE2/faster_corner_12.cxx index 06163e67..cba80efc 100644 --- a/cvd_src/SSE2/faster_corner_12.cxx +++ b/cvd_src/SSE2/faster_corner_12.cxx @@ -143,7 +143,7 @@ namespace CVD row_start=I[++row]; continue; } - int x = *it - row_start; + int x = static_cast(*it - row_start); if (x > 2 && x < w-3) corners.push_back(ImageRef(x, row)); } diff --git a/cvd_src/convolution.cc b/cvd_src/convolution.cc index 56432d4f..83605b5b 100644 --- a/cvd_src/convolution.cc +++ b/cvd_src/convolution.cc @@ -53,7 +53,7 @@ void convolveGaussian5_1(Image& I) int sum= (3571*(src[0]+src[4*w]) + 16004*(src[w]+src[3*w]) + 26386*src[2*w]); - *(src) = sum >> 16; + *(src) = static_cast(sum >> 16); src += w; } } @@ -64,7 +64,7 @@ void convolveGaussian5_1(Image& I) int sum= (3571*(src[0]+src[4]) + 16004*(src[1]+src[3]) + 26386*src[2]); - *(src+2*w+2) = sum >> 16; + *(src+2*w+2) = static_cast(sum >> 16); ++src; } } diff --git a/cvd_src/cvd_timer.cc b/cvd_src/cvd_timer.cc index 13afc08d..593bbcf2 100644 --- a/cvd_src/cvd_timer.cc +++ b/cvd_src/cvd_timer.cc @@ -46,7 +46,7 @@ double cvd_timer::get_time() double get_time_of_day() { - return get_time_of_day_ns()/1e9; + return static_cast(get_time_of_day_ns())/1e9; } diff --git a/cvd_src/fast/fast_10_detect.cxx b/cvd_src/fast/fast_10_detect.cxx index 6afb4f9b..3ade3241 100644 --- a/cvd_src/fast/fast_10_detect.cxx +++ b/cvd_src/fast/fast_10_detect.cxx @@ -3158,7 +3158,7 @@ void fast_corner_detect_plain_10(const BasicImage& i, vector& co continue; success: - corners.push_back(ImageRef(cache_0-line_min, y)); + corners.push_back(ImageRef(static_cast(cache_0-line_min), y)); } } } diff --git a/cvd_src/fast/fast_11_detect.cxx b/cvd_src/fast/fast_11_detect.cxx index 8ca0f386..eace281b 100644 --- a/cvd_src/fast/fast_11_detect.cxx +++ b/cvd_src/fast/fast_11_detect.cxx @@ -2581,7 +2581,7 @@ void fast_corner_detect_plain_11(const BasicImage& i, vector& co continue; success: - corners.push_back(ImageRef(cache_0-line_min, y)); + corners.push_back(ImageRef(static_cast(cache_0-line_min), y)); } } } diff --git a/cvd_src/fast/fast_12_detect.cxx b/cvd_src/fast/fast_12_detect.cxx index ee752b35..64afa9ab 100644 --- a/cvd_src/fast/fast_12_detect.cxx +++ b/cvd_src/fast/fast_12_detect.cxx @@ -2253,7 +2253,7 @@ void fast_corner_detect_plain_12(const BasicImage& i, vector& co continue; success: - corners.push_back(ImageRef(cache_0-line_min, y)); + corners.push_back(ImageRef(static_cast(cache_0-line_min), y)); } } } diff --git a/cvd_src/fast/fast_7_detect.cxx b/cvd_src/fast/fast_7_detect.cxx index e425c96c..a18c092c 100644 --- a/cvd_src/fast/fast_7_detect.cxx +++ b/cvd_src/fast/fast_7_detect.cxx @@ -16045,7 +16045,7 @@ void fast_corner_detect_plain_7(const BasicImage& i, vector& cor continue; success: - corners.push_back(ImageRef(cache_0-line_min, y)); + corners.push_back(ImageRef(static_cast(cache_0-line_min), y)); } } } diff --git a/cvd_src/fast/fast_8_detect.cxx b/cvd_src/fast/fast_8_detect.cxx index 0317383c..d0c7d1b3 100644 --- a/cvd_src/fast/fast_8_detect.cxx +++ b/cvd_src/fast/fast_8_detect.cxx @@ -8423,7 +8423,7 @@ void fast_corner_detect_plain_8(const BasicImage& i, vector& cor continue; success: - corners.push_back(ImageRef(cache_0-line_min, y)); + corners.push_back(ImageRef(static_cast(cache_0-line_min), y)); } } } diff --git a/cvd_src/fast/fast_9_detect.cxx b/cvd_src/fast/fast_9_detect.cxx index c3436354..946fa20a 100644 --- a/cvd_src/fast/fast_9_detect.cxx +++ b/cvd_src/fast/fast_9_detect.cxx @@ -4660,7 +4660,7 @@ void fast_corner_detect_plain_9(const BasicImage& i, vector& cor continue; success: - corners.push_back(ImageRef(cache_0-line_min, y)); + corners.push_back(ImageRef(static_cast(cache_0-line_min), y)); } } } diff --git a/cvd_src/gltext.cpp b/cvd_src/gltext.cpp index b8f85105..0ad2c28e 100644 --- a/cvd_src/gltext.cpp +++ b/cvd_src/gltext.cpp @@ -149,14 +149,14 @@ std::pair glDrawText(const std::string& text, enum TEXT_STYLE sty continue; } if(c == '\t'){ - const float advance = tab_width - std::fmod(total, tab_width); + const double advance = tab_width - std::fmod(total, tab_width); total += advance; glTranslated(advance, 0, 0); continue; } const Internal::Font::Char * ch = font->findChar(c); if(!ch){ - c = toupper(c); + c = static_cast(toupper(c)); ch = font->findChar(c); if(!ch) { c = '?'; @@ -198,7 +198,7 @@ std::pair glGetExtends(const std::string & text, double spacing, } const Internal::Font::Char * ch = font->findChar(c); if(!ch){ - c = toupper(c); + c = static_cast(toupper(c)); ch = font->findChar(c); if(!ch) { c = '?'; diff --git a/cvd_src/glwindow.cc b/cvd_src/glwindow.cc index dc7f1a1c..1cdc6173 100644 --- a/cvd_src/glwindow.cc +++ b/cvd_src/glwindow.cc @@ -229,12 +229,12 @@ void CVD::GLWindow::handle_events(EventHandler& handler) case KeyPress: { XLookupString(&event.xkey, 0, 0, &k, 0); - handler.on_key_down(*this, k); + handler.on_key_down(*this, static_cast(k)); //KeySyms are 29 bits only break; } case KeyRelease: XLookupString(&event.xkey, 0, 0, &k, 0); - handler.on_key_up(*this, k); + handler.on_key_up(*this, static_cast(k)); break; //case UnmapNotify: active = 0; break; //case MapNotify: active = 1; break; @@ -255,7 +255,7 @@ void CVD::GLWindow::handle_events(EventHandler& handler) if (event.xclient.data.l[0] == (int)state->delete_atom) handler.on_event(*this, EVENT_CLOSE); else - handler.on_event(*this, event.xclient.message_type); + handler.on_event(*this, static_cast(event.xclient.message_type)); break; default: handler.on_event(*this, event.type); diff --git a/cvd_src/image_io/bmp.cxx b/cvd_src/image_io/bmp.cxx index 896a6d03..5a689c1f 100644 --- a/cvd_src/image_io/bmp.cxx +++ b/cvd_src/image_io/bmp.cxx @@ -13,20 +13,20 @@ namespace CVD struct BMPHeader { - unsigned long size; //!< header size - unsigned short reserved[2]; //!< reserved - unsigned long dataOffset; //!< offset to beginning of data - unsigned long infoSize; //!< size of info - unsigned long width; //!< width of image - unsigned long height; //!< height of image - unsigned short planes; //!< planes - unsigned short bpp; //!< colour depth - unsigned long compression; //!< compression type - unsigned long dataSize; //!< size of data - unsigned long xPelsPerMeter; //!< x resolution in pixels/meter - unsigned long yPelsPerMeter; //!< y resolution in pixels/meter - unsigned long colors; //!< number of specified colors in the map - unsigned long importantColors; //!< number of important colors + uint32_t size; //!< header size + uint16_t reserved[2]; //!< reserved + uint32_t dataOffset; //!< offset to beginning of data + uint32_t infoSize; //!< size of info + uint32_t width; //!< width of image + uint32_t height; //!< height of image + uint16_t planes; //!< planes + uint16_t bpp; //!< colour depth + uint32_t compression; //!< compression type + uint32_t dataSize; //!< size of data + uint32_t xPelsPerMeter; //!< x resolution in pixels/meter + uint32_t yPelsPerMeter; //!< y resolution in pixels/meter + uint32_t colors; //!< number of specified colors in the map + uint32_t importantColors; //!< number of important colors }; @@ -49,7 +49,7 @@ namespace CVD << (unsigned char)(0xff & (l >> 8)); } - inline unsigned long read_u4(istream& i) + inline uint32_t read_u4(istream& i) { //Data is little endian: //unsigned long r = i.get() | (i.get() << 8) | (i.get() << 16) | (i.get() << 24 ); @@ -57,24 +57,23 @@ namespace CVD int b = i.get(); int c = i.get(); int d = i.get(); - unsigned long r = a | (b << 8) | (c<<16) | (d << 24); + uint32_t r = a | (b << 8) | (c<<16) | (d << 24); if(i.eof()) throw(Exceptions::Image_IO::MalformedImage("EOF in header.")); return r; } - inline unsigned long read_u2(istream& i) + inline uint16_t read_u2(istream& i) { //Data is little endian: //unsigned long r = i.get() | (i.get() << 8); int a = i.get(); int b = i.get(); - unsigned long r = a | (b << 8); if(i.eof()) throw(Exceptions::Image_IO::MalformedImage("EOF in header.")); - return r; + return static_cast(a|(b<<8)); } BMPHeader read_header(istream& i) diff --git a/cvd_src/image_io/cvdimage.cxx b/cvd_src/image_io/cvdimage.cxx index ee7fe198..ec008833 100644 --- a/cvd_src/image_io/cvdimage.cxx +++ b/cvd_src/image_io/cvdimage.cxx @@ -33,7 +33,7 @@ void pred_horizontal_diff(const byte* in, int width, byte* out, int pred_len = 1 out[i] = in[i]; for (int i = pred_len; i < width; i++) - out[i] = (256 + in[i] - in[i-pred_len])&255; + out[i] = static_cast((256 + in[i] - in[i-pred_len])&255); } void pred_horizontal_undiff(const byte* in, int width, byte* out, int pred_len = 1) @@ -54,14 +54,14 @@ void pred_2doptimal_diff(const byte* in, int width, byte* buffer, byte* out, int { // simple vertical prediction for first column(s) for (int i = 0; i < pred_len; i++) { - out[i] = (256 + in[i] - buffer[i]) & 255; + out[i] = static_cast((256 + in[i] - buffer[i]) & 255); } // 0.75 i[x-1][y] + 0.75 i[x][y-1] - 0.5 i[x-1][y-1] // buffer is used to store the previous row for (int i = pred_len; i < width; i++) { int pred = (3*in[i-pred_len] - 2*buffer[i-pred_len] + 3*buffer[i]) / 4; - out[i] = (256 + in[i] - pred)&255; + out[i] = static_cast((256 + in[i] - pred)&255); buffer[i-pred_len] = in[i-pred_len]; } @@ -81,7 +81,7 @@ void pred_2doptimal_undiff(const byte* in, int width, byte* buffer, byte* out, i // see above for (int i = pred_len; i < width; i++) { int pred = (3*out[i-pred_len] - 2*buffer[i-pred_len] + 3*buffer[i]) / 4; - out[i] = (in[i] + pred)&255; + out[i] = static_cast((in[i] + pred)&255); buffer[i-pred_len] = out[i-pred_len]; } @@ -119,8 +119,8 @@ static const int pred_coeff_bluered[]={4, 0, 4}; //=> 24.1666 void pred_2dbayer_diff(const byte* in, int width, byte* buffer1, byte* buffer2, byte* out, bool greenfirst) { // simple vertical prediction for first two columns - out[0] = (256 + in[0] - buffer1[0]) & 255; - out[1] = (256 + in[1] - buffer1[1]) & 255; + out[0] = static_cast((256 + in[0] - buffer1[0]) & 255); + out[1] = static_cast((256 + in[1] - buffer1[1]) & 255); // for red and blue: 0.75 i[x-2][y] + 0.75 i[x][y-2] - 0.5 i[x-2][y-2] // for green: 0.25 i[x-2][y] + 0.5 i[x-1][y-1] - 0.25 i[x+1][y-1] @@ -131,7 +131,7 @@ void pred_2dbayer_diff(const byte* in, int width, byte* buffer1, byte* buffer2, int pred = (pred_coeff_green[0]*in[i-2] + pred_coeff_green[1]*buffer2[i-1] + pred_coeff_green[2]*buffer1[i]) / 8; - out[i] = (256 + in[i] - pred)&255; + out[i] = static_cast((256 + in[i] - pred)&255); buffer1[i-2] = in[i-2]; i++; } @@ -140,14 +140,14 @@ void pred_2dbayer_diff(const byte* in, int width, byte* buffer1, byte* buffer2, int pred = (pred_coeff_bluered[0]*in[i-2] + pred_coeff_bluered[1]*buffer1[i-2] + pred_coeff_bluered[2]*buffer1[i]) / 8; - out[i] = (256 + in[i] - pred)&255; + out[i] = static_cast((256 + in[i] - pred)&255); buffer1[i-2] = in[i-2]; i++; if (!(i((256 + in[i] - pred)&255); buffer1[i-2] = in[i-2]; } @@ -167,7 +167,7 @@ void pred_2dbayer_undiff(const byte* in, int width, byte* buffer1, byte* buffer2 int pred = (pred_coeff_green[0]*out[i-2] + pred_coeff_green[1]*buffer2[i-1] + pred_coeff_green[2]*buffer1[i]) / 8; - out[i] = (in[i] + pred)&255; + out[i] = static_cast((in[i] + pred)&255); buffer1[i-2] = out[i-2]; i++; } @@ -176,14 +176,14 @@ void pred_2dbayer_undiff(const byte* in, int width, byte* buffer1, byte* buffer2 int pred = (pred_coeff_bluered[0]*out[i-2] + pred_coeff_bluered[1]*buffer1[i-2] + pred_coeff_bluered[2]*buffer1[i]) / 8; - out[i] = (in[i] + pred)&255; + out[i] = static_cast((in[i] + pred)&255); buffer1[i-2] = out[i-2]; i++; if (!(i((in[i] + pred)&255); buffer1[i-2] = out[i-2]; } @@ -195,7 +195,11 @@ void pred_2dbayer_undiff(const byte* in, int width, byte* buffer1, byte* buffer2 struct Huff{ Huff* zero, *one, *parent; - int symbol; + //All intermediate nodes have a negative symbol to ensure uniqieness with the + //strict weak ordering defined below. The pointer could be used, but then the + //ordering would not be repeateable. + int symbol; + size_t count; bool operator()(const Huff* l, const Huff* r) const @@ -221,7 +225,7 @@ void create_normalized_hist(const Image& im, array& h) for(Image::const_iterator i = im.begin(); i!=im.end(); i++) h[*i]++; - int hi = *max_element(h.begin(), h.end()); + size_t hi = *max_element(h.begin(), h.end()); for(unsigned int i=0; i < h.size(); i++) if(h[i]) h[i] = (((uint64_t)h[i])* 65534 / hi)+1; @@ -362,7 +366,7 @@ vector huff_compress(const Image& im, const array& h PackType chunk = 0; for(unsigned int j=0; j < symbols[i].size(); j++) { - chunk |= ((PackType)symbols[i][j]) << (o%PackBits); + chunk |= static_cast(((PackType)symbols[i][j]) << (o%PackBits)); o++; if(o % PackBits == 0) { @@ -395,7 +399,7 @@ vector huff_compress(const Image& im, const array& h for(int j=1; j < fast_symbols_num_chunks[*i][off]; j++) r2.push_back(fast_symbols[*i][off][j]); - bit += symbols[*i].size(); + bit += static_cast(symbols[*i].size()); } @@ -428,8 +432,9 @@ template void huff_decompress(const vector

& b, const arrayzero; } - - *r = h->symbol; + + assert(h->symbol >= 0); + *r = static_cast(h->symbol); } } @@ -463,7 +468,7 @@ class ReadPimpl vector read_data(std::istream& is); void bayer_swap_rows(void); - long xs, ys; + int xs, ys; int bypp; // bytes per pixel int pred_len; enum cvd_predictors pred_mode; @@ -475,7 +480,7 @@ class ReadPimpl ImageRef reader::size() { - return ImageRef(t->x_size(), t->y_size()); + return ImageRef(static_cast(t->x_size()), static_cast(t->y_size())); } void reader::get_raw_pixel_line(unsigned char* d) @@ -541,7 +546,7 @@ ReadPimpl::ReadPimpl(istream& in) read_header(in); array h = read_hist(in); - diff.resize(ImageRef(xs*bypp,ys)); + diff.resize(ImageRef(static_cast(xs*bypp),static_cast(ys))); buffer.resize(xs*bypp); if ((pred_mode==PRED_2D_BAYER_1)||(pred_mode==PRED_2D_BAYER_2)) buffer2.resize(xs*bypp); @@ -611,7 +616,7 @@ vector ReadPimpl::read_data(std::istream& is) PackType tmp = 0; while (bits>0) { tmp <<= 8; - tmp |= is.get()&255; + tmp |= static_cast(is.get()&255); bits-=8; } data.push_back(tmp); @@ -704,7 +709,7 @@ class WritePimpl void write_data(std::ostream& os, vector& data); void bayer_swap_rows(void); - long xs, ys, row; + int xs, ys, row; int bypp; // bytes per pixel :) int pred_len; enum cvd_predictors pred_mode; @@ -833,8 +838,8 @@ void WritePimpl::write_hist(std::ostream& os, const array& h) // two least significant bytes out of each int, store them in a new // array, and dump that in just one call to ostream::write() for (unsigned int i = 0; i < h.size(); i++) { - os.put((h[i]>>8)&255); - os.put(h[i]&255); + os.put(static_cast((h[i]>>8)&255)); + os.put(static_cast((h[i]&255))); } } @@ -845,7 +850,7 @@ void WritePimpl::write_data(std::ostream& os, vector& data) for (vector::const_iterator it = data.begin(); it!=data.end(); ++it) { int bits = PackBits; while (bits>0) { - os.put(((*it)>>(bits-8))&255); + os.put(static_cast(((*it)>>(bits-8))&255)); bits-=8; } } diff --git a/cvd_src/image_io/fits.cc b/cvd_src/image_io/fits.cc index 9956bcad..96e73547 100644 --- a/cvd_src/image_io/fits.cc +++ b/cvd_src/image_io/fits.cc @@ -197,7 +197,7 @@ template void ReadPimpl::convert_raw_pixel_line(unsigned char* rowp, T* template class T> void ReadPimpl::convert_raw_pixel_line(unsigned char* rowp, T* d) { unsigned short* ds = (unsigned short*)d; - int elements=my_size.x * sizeof(T)/sizeof(unsigned short); + int elements=my_size.x * static_cast(sizeof(T)/sizeof(unsigned short)); for(int i=0; i < elements; i++) ds[i] = (unsigned short)(static_cast( ((short*)(rowp))[i]) + 32768); } diff --git a/cvd_src/image_io/fitswrite.cc b/cvd_src/image_io/fitswrite.cc index 81704856..ee9a7553 100644 --- a/cvd_src/image_io/fitswrite.cc +++ b/cvd_src/image_io/fitswrite.cc @@ -30,7 +30,7 @@ class CVD::FITS::WritePimpl void write_raw_pixel_line_(const Rgba* dat); void axes(const string& s, int x, int y); void write(const string& s); - void write_short(short s); + void write_ushort(uint16_t s); private: ostream& o; ImageRef my_size; @@ -111,37 +111,36 @@ template void WritePimpl::write_raw_pixel_line_(const C* dat) data.push_back(d[i]); } -void WritePimpl::write_short(short s) +void WritePimpl::write_ushort(uint16_t s) { - int num = (int)s - 32768; - short ns = num; - data.push_back((ns&0xff00)>>8); - data.push_back(ns&0xff); + int num = s - 32768; + data.push_back(static_cast((num&0xff00)>>8)); + data.push_back(static_cast(num&0xff)); } void WritePimpl::write_raw_pixel_line_(const unsigned short* dat) { for(int i=0; i < my_size.x; i++) - write_short(dat[i]); + write_ushort(dat[i]); } void WritePimpl::write_raw_pixel_line_(const Rgb* dat) { for(int i=0; i < my_size.x; i++) { - write_short(dat[i].red); - write_short(dat[i].green); - write_short(dat[i].blue); + write_ushort(dat[i].red); + write_ushort(dat[i].green); + write_ushort(dat[i].blue); } } void WritePimpl::write_raw_pixel_line_(const Rgba* dat) { for(int i=0; i < my_size.x; i++) { - write_short(dat[i].red); - write_short(dat[i].green); - write_short(dat[i].blue); - write_short(dat[i].alpha); + write_ushort(dat[i].red); + write_ushort(dat[i].green); + write_ushort(dat[i].blue); + write_ushort(dat[i].alpha); } } diff --git a/cvd_src/image_io/jpeg.cxx b/cvd_src/image_io/jpeg.cxx index 93bc83a6..f4336ec5 100644 --- a/cvd_src/image_io/jpeg.cxx +++ b/cvd_src/image_io/jpeg.cxx @@ -24,8 +24,8 @@ class ReadPimpl public: ReadPimpl(std::istream&); int channels(){return m_channels;} - long x_size() const {return xs;} - long y_size() const {return ys;} + int x_size() const {return xs;} + int y_size() const {return ys;} long elements_per_line() const {return xs * m_channels;} void get_raw_pixel_lines(unsigned char*, unsigned long nlines); ~ReadPimpl(); @@ -44,7 +44,7 @@ class ReadPimpl } private: - long xs, ys; + int xs, ys; int m_channels; struct jpeg_decompress_struct cinfo; struct jpeg_error_mgr jerr; @@ -156,7 +156,7 @@ struct jpeg_istream_src: public jpeg_source_mgr } //Store the byte... - me->buf[n] = c; + me->buf[n] = static_cast(c); } me->bytes_in_buffer = n; @@ -338,15 +338,15 @@ class WritePimpl public: WritePimpl(std::ostream&, int xsize, int ysize, const string& type, const std::map >& p, const std::string& comm=""); int channels(){return m_channels;} - long x_size() const {return xs;} - long y_size() const {return ys;} + int x_size() const {return xs;} + int y_size() const {return ys;} long elements_per_line() const {return xs * m_channels;} void write_raw_pixel_lines(const unsigned char*, unsigned long); template void write_raw_pixel_line(const C*); ~WritePimpl(); private: - long xs, ys, row; + int xs, ys, row; int m_channels; struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; @@ -415,17 +415,13 @@ WritePimpl::WritePimpl(std::ostream& out, int xsize, int ysize, const string& t, jpeg_start_compress(&cinfo, TRUE); - unsigned int commlen = comm.length(); - + string comment = comm; //NB: not 65536 Marker looks like: // marker_byte length_high length_low length*bytes // length includes the block header (3 bytes) - - if(commlen > 65533) - commlen = 65533; - + comment.resize(std::min(comment.length(), size_t(65533))); //Written without zero termination, since the length is also written - jpeg_write_marker(&cinfo, JPEG_COM, (JOCTET*)comm.c_str(), comm.length()); + jpeg_write_marker(&cinfo, JPEG_COM, (JOCTET*)comm.c_str(), static_cast(comment.size())); } void WritePimpl::write_raw_pixel_lines(const unsigned char* data, unsigned long nlines) diff --git a/cvd_src/image_io/png.cc b/cvd_src/image_io/png.cc index a3626bfa..6d48499a 100644 --- a/cvd_src/image_io/png.cc +++ b/cvd_src/image_io/png.cc @@ -148,7 +148,13 @@ template void PNGPimpl::read_pixels(P* data) png_read_rows(png_ptr, row_ptr, NULL, 1); } - +template int safe_cast(const T&)=delete; +int safe_cast(png_uint_32 t){ + if(t > numeric_limits::max()) + throw Exceptions::Image_IO::UnsupportedImageSubType("PNG", "dimension over INT_MAX"); + + return static_cast(t); +} PNGPimpl::PNGPimpl(std::istream& in) :i(in),type(""),row(0),png_ptr(0),info_ptr(0),end_info(0) @@ -217,8 +223,8 @@ PNGPimpl::PNGPimpl(std::istream& in) LOG("tRNS? = " << png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) << endl); - my_size.x = w; - my_size.y = h; + my_size.x = safe_cast(w); + my_size.y = safe_cast(h); //Figure out the type name, and what processing to to. if(depth == 1) diff --git a/cvd_src/image_io/save_postscript.cxx b/cvd_src/image_io/save_postscript.cxx index b14783b5..1f0ee778 100644 --- a/cvd_src/image_io/save_postscript.cxx +++ b/cvd_src/image_io/save_postscript.cxx @@ -54,7 +54,7 @@ namespace PS public: WritePimpl(std::ostream&, ImageRef size, const string& type, const string& extra_header=""); - void write_raw_pixel_lines(const unsigned char*, unsigned long); + void write_raw_pixel_lines(const unsigned char*, int); ~WritePimpl(); int channels(){return m_channels;} long x_size() const {return xs;} @@ -63,7 +63,7 @@ namespace PS std::ostream& o; private: - long xs, ys; + int xs, ys; int m_channels; std::string bytes_to_base85(int n); void output_header(); @@ -170,9 +170,9 @@ WritePimpl::~WritePimpl() o << "~>\n"; } -void WritePimpl::write_raw_pixel_lines(const unsigned char* data, unsigned long nlines) +void WritePimpl::write_raw_pixel_lines(const unsigned char* data, int nlines) { - if((long)nlines + lines > ys) + if(nlines + lines > ys) throw CVD::Exceptions::Image_IO::InternalLibraryError("CVD", "Write past end of image."); const unsigned char* end = data + (nlines * xs)*m_channels; diff --git a/cvd_src/image_io/text.cxx b/cvd_src/image_io/text.cxx index e79c7574..b8982d84 100644 --- a/cvd_src/image_io/text.cxx +++ b/cvd_src/image_io/text.cxx @@ -80,7 +80,7 @@ ReadPimpl::ReadPimpl(istream& is) break; if(my_size.y == 0) - my_size.x = raster_data[0].size(); + my_size.x = static_cast(raster_data[0].size()); else if(my_size.x != (int)raster_data.back().size()) { ostringstream err; diff --git a/cvd_src/image_io/tiff.cxx b/cvd_src/image_io/tiff.cxx index 2e8c65ab..ecc9c61b 100644 --- a/cvd_src/image_io/tiff.cxx +++ b/cvd_src/image_io/tiff.cxx @@ -25,10 +25,14 @@ class CVD::TIFF::TIFFPimpl string datatype(); template void get_raw_pixel_line(C* data); void get_raw_pixel_line(bool* data); + void get_raw_pixel_line(Rgba* data); private: + + template void checkRead(const C*); + istream& i; - unsigned long row; + uint32_t row; ImageRef my_size; string type; streamoff length; @@ -124,34 +128,48 @@ void attempt_invert(float* data, long num) { invert(data, num);} void attempt_invert(double* data, long num) { invert(data, num);} - -template void TIFFPimpl::get_raw_pixel_line(T* d) -{ +template +void TIFFPimpl::checkRead(const T*){ if(datatype() != PNM::type_name::name()) throw ReadTypeMismatch(datatype(), PNM::type_name::name()); if(row > (unsigned long)my_size.y) throw InternalLibraryError("CVD", "Read past end of image."); - +} + +void TIFFPimpl::get_raw_pixel_line(Rgba* data){ + checkRead(data); + if(use_cooked_rgba_interface) { uint32* raster = &raster_data[row*my_size.x]; uint32* end = raster + my_size.x; - //We will only ever get here if the type is Rgba - Rgba* data = reinterpret_cast* >(d); - for(;raster < end; raster++, data++) { data->red = TIFFGetR(*raster); data->green = TIFFGetG(*raster); data->blue = TIFFGetB(*raster); - data->alpha = TIFFGetA(*raster); + data->alpha = static_cast(TIFFGetA(*raster)); } row ++; } else + { + get_raw_pixel_line>(data); + } + +} + +template void TIFFPimpl::get_raw_pixel_line(T* d) +{ + checkRead(d); + if(use_cooked_rgba_interface) + { + throw InternalLibraryError("CVD", "Reading non-RGBA tiff data as RGBA"); + } + else { if(TIFFReadScanline(tif, (void*)d, row) == -1) throw MalformedImage(error_msg); diff --git a/cvd_src/image_io/tiffwrite.cc b/cvd_src/image_io/tiffwrite.cc index 12a04ea8..0dd3b7b7 100644 --- a/cvd_src/image_io/tiffwrite.cc +++ b/cvd_src/image_io/tiffwrite.cc @@ -30,7 +30,7 @@ class CVD::TIFF::TIFFWritePimpl ostream& o; ImageRef my_size; string type; - unsigned long row; + uint32_t row; ::TIFF* tif; streamoff length; long strip_size; @@ -184,7 +184,7 @@ void TIFFWritePimpl::write_raw_pixel_line(const bool* data) //Pack bools for(int i=0; i < my_size.x ;i++) - bool_rowbuf[i/8] |= (data[i] & 1) << (7-i%8); + bool_rowbuf[i/8] |= static_cast((data[i] & 1) << (7-i%8)); if(TIFFWriteScanline(tif, &bool_rowbuf[0], row) == -1) throw WriteError(error_msg); diff --git a/cvd_src/videodisplay.cc b/cvd_src/videodisplay.cc index da8a712e..80703e4c 100644 --- a/cvd_src/videodisplay.cc +++ b/cvd_src/videodisplay.cc @@ -212,13 +212,13 @@ void CVD::VideoDisplay::set_zoom(double left, double top, double right, double b glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glOrtho(left, right, bottom, top, -1 , 1); // If the origin is the top left + glOrtho(left, right, bottom, top, -1 , 1); // If the origin is the top left - glRasterPos2f(left, top); - - // video is now the same way as upside down to graphics! - glPixelZoom(scale, -scale); - //glPixelZoom(1,-1); + glRasterPos2d(left, top); + + // video is now the same way as upside down to graphics! + glPixelZoom(static_cast(scale), static_cast(-scale)); + //glPixelZoom(1,-1); } diff --git a/cvd_src/videofilebuffer2.cc b/cvd_src/videofilebuffer2.cc index b9cfa53f..87d7e509 100644 --- a/cvd_src/videofilebuffer2.cc +++ b/cvd_src/videofilebuffer2.cc @@ -406,7 +406,7 @@ class RawVideoFileBufferPIMPL { t = max(0., t); - uint64_t stamp = floor(t / stream_time_base + 0.5); + uint64_t stamp = static_cast(floor(t / stream_time_base + 0.5)); DE(endl); DS("seeking"); @@ -450,7 +450,7 @@ class RawVideoFileBufferPIMPL Dv(packet.pts); //Presentation time stamp (pts) is sometimes junk in keyframes. Dv(packet.dts); //decode time stamp - double timestamp = packet.dts * stream_time_base; + double timestamp = static_cast(packet.dts) * stream_time_base; approx_next_timestamp = timestamp + 1./ frame_rate; Dv(timestamp); diff --git a/cvd_src/videosource.cpp b/cvd_src/videosource.cpp index 373827f0..1550d6be 100644 --- a/cvd_src/videosource.cpp +++ b/cvd_src/videosource.cpp @@ -8,13 +8,13 @@ namespace CVD { void tolower(std::string& s) { for (size_t i=0; i(::tolower(s[i])); } - void tolower(char* s) + void tolower(char* s) { for (size_t i=0; s[i]; ++i) - s[i] = ::tolower(s[i]); + s[i] = static_cast(::tolower(s[i])); } using std::tolower; @@ -149,7 +149,14 @@ namespace CVD { void match(std::istream& in, char c) { if (in.peek() != c) { std::ostringstream oss; - oss << "expected '" << c <<"', got '" << escape(in.peek()) << "'"; + std::string x; + + if(in.peek() == -1) + x = ""; + else + x = escape(static_cast(in.peek())); + + oss << "expected '" << c <<"', got '" << x << "'"; throw ParseException(oss.str()); } in.ignore(); @@ -165,10 +172,17 @@ namespace CVD { std::string value; match(in, '"'); while (in.peek() != '"') { - char c = in.get(); + int cc = in.get(); + if(cc == -1) + throw ParseException("unmatched open quote"); + char c = static_cast(cc); value += c; - if (c == '\\') - value += in.get(); + if (c == '\\'){ + int c2 = in.get(); + if(c2 == -1) + throw ParseException("unmatched open quote"); + value += static_cast(c2); + } } match(in,'"'); return value; @@ -178,7 +192,7 @@ namespace CVD { { std::string word; while (isalnum(in.peek()) || in.peek()=='_') - word += in.get(); + word += static_cast(in.get()); return word; } @@ -198,7 +212,7 @@ namespace CVD { std::string prot; skip_ws(in); while (isalnum(in.peek())) - prot += in.get(); + prot += static_cast(in.get()); if (prot.length() == 0) throw ParseException("protocol must not be empty"); vs.protocol = prot; @@ -432,7 +446,7 @@ namespace CVD { } - void get_dc1394_options(const VideoSource& vs, ImageRef& size, int& fps, ImageRef& offset, bool& verbose, bool& bus_reset, int& format7_mode) + void get_dc1394_options(const VideoSource& vs, ImageRef& size, float& fps, ImageRef& offset, bool& verbose, bool& bus_reset, int& format7_mode) { size = offset = ImageRef(-1, -1); fps = -1; @@ -442,7 +456,7 @@ namespace CVD { for (VideoSource::option_list::const_iterator it=vs.options.begin(); it != vs.options.end(); ++it) { if (it->first == "fps") - fps = atoi(it->second.c_str()); + fps = stof(it->second); else if (it->first == "size") size = parseImageRef(it->second, true); else if (it->first == "offset") diff --git a/progs/cvd_display_image.cxx b/progs/cvd_display_image.cxx index 85af9cbf..20cdef83 100644 --- a/progs/cvd_display_image.cxx +++ b/progs/cvd_display_image.cxx @@ -50,7 +50,7 @@ int main() return 0; } } - catch(Exceptions::All a) + catch(const Exceptions::All& a) { std::cerr << "Error: " << a.what() << std::endl; } diff --git a/progs/video_play_source.cc b/progs/video_play_source.cc index 87c7da48..c7c5461b 100644 --- a/progs/video_play_source.cc +++ b/progs/video_play_source.cc @@ -43,7 +43,15 @@ #include #include +#ifdef __GNUC__ +#pragma GCC diagnostic push +#endif +#pragma GCC diagnostic ignored "-Wconversion" +#pragma GCC diagnostic ignored "-Wimplicit-fallthrough" #include "progs/tinyformat.h" +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif #ifdef CVD_HAVE_V4LBUFFER #include @@ -201,7 +209,7 @@ class MessageQueue private: std::deque data; std::mutex queue_mutex; - std::atomic length; + std::atomic length; std::condition_variable empty; @@ -239,7 +247,7 @@ class MessageQueue return a; } - int get_length() const + size_t get_length() const { return length; } @@ -322,7 +330,7 @@ template void play(string s, string fmt, unsigned int decimate) try{ img_save(*(s.first), s.second); } - catch(CVD::Exceptions::All e) + catch(const CVD::Exceptions::All& e) { cerr << "Error saving: " << fmt << ": " << e.what() << endl; } diff --git a/tests/convolution.cc b/tests/convolution.cc index ed0691fe..1a3fd298 100644 --- a/tests/convolution.cc +++ b/tests/convolution.cc @@ -5,7 +5,7 @@ using namespace CVD; -int main(int argc, char **argv) { +int main(int , char **) { Image img(ImageRef(2,5)); Image out(img.size()); convolveGaussian(img, out, 1.0); diff --git a/tests/distance_transform_test.cc b/tests/distance_transform_test.cc index e69bce97..2fde36da 100644 --- a/tests/distance_transform_test.cc +++ b/tests/distance_transform_test.cc @@ -4,7 +4,12 @@ #include #include using namespace CVD; -using namespace std; + +using std::mt19937; +using std::uniform_int_distribution; +using std::cout; +using std::cerr; +using std::endl; int main() { @@ -46,7 +51,7 @@ int main() { if(adt[p] != ImageRef(-1, -1)) { - float d = ((p - adt[p]).mag_squared()); + double d = ((p - adt[p]).mag_squared()); if(abs(d - out[p]) != 0) { diff --git a/tests/fast_corner_test.cc b/tests/fast_corner_test.cc index b03640a0..ea259655 100644 --- a/tests/fast_corner_test.cc +++ b/tests/fast_corner_test.cc @@ -7,8 +7,11 @@ #include #include +using std::vector; +using std::cout; +using std::endl; +using std::string; -using namespace std; namespace CVD { void fast_corner_detect_plain_9(const BasicImage& i, vector& corners, int b); @@ -139,28 +142,29 @@ int main(int , char** ) std::random_device device; std::ranlux48 engine(device()); std::uniform_real_distribution<> distribution(0.0, 1.0); + for(int n=16; n < 100; n+=1) { Image im(ImageRef(n, n)); for(Image::iterator i = im.begin(); i != im.end(); i++) - *i = (distribution(engine) * 256); + *i = static_cast((distribution(engine) * 256)); for(int k=0; k < 2; k++) { ImageRef start; - start.x = distribution(engine)*(n/2); - start.y = distribution(engine)*(n/2); + start.x = static_cast(distribution(engine)*(n/2)); + start.y = static_cast(distribution(engine)*(n/2)); ImageRef size = im.size() - start; - size.x = distribution(engine)*(size.x-1) + 1; - size.y = distribution(engine)*(size.y-1) + 1; + size.x = static_cast(distribution(engine)*(size.x-1) + 1); + size.y = static_cast(distribution(engine)*(size.y-1) + 1); SubImage ims = im.sub_image(start, size); - int threshold = distribution(engine) * 256; + int threshold = static_cast(distribution(engine) * 256); test_images(ims, fast_corner_detect_9, fast_corner_detect_plain_9, segment_test<9>, threshold, "FAST9"); test_images(ims, fast_corner_detect_10, fast_corner_detect_plain_10, segment_test<10>, threshold, "FAST10"); test_images(ims, fast_corner_detect_12, fast_corner_detect_plain_12, segment_test<12>, threshold, "FAST12"); diff --git a/tests/load_and_save.cc b/tests/load_and_save.cc index f570ae09..4595fec2 100644 --- a/tests/load_and_save.cc +++ b/tests/load_and_save.cc @@ -25,17 +25,31 @@ #include #include #include -#include +#include #include -using namespace std; using namespace CVD; +using std::cerr; +using std::clog; +using std::equal; +using std::endl; +using std::ifstream; +using std::ios; +using std::ios_base; +using std::map; +using std::max; +using std::min; +using std::ofstream; +using std::string; +using std::stringstream; using CVD::Internal::TypeList; using CVD::Internal::Head; +std::mt19937 rng; + template struct randpix { static C r() @@ -53,40 +67,40 @@ template struct randpix template<> struct randpix { - static double r() + static bool r() { - return rand() % 2; + return std::uniform_int_distribution<>(0,1)(rng); } }; template<> struct randpix { - static double r() + static byte r() { - return rand() % 256; + return static_cast(std::uniform_int_distribution<>(0,255)(rng)); } }; template<> struct randpix { - static double r() + static byte r() { - return rand() % 256; + return static_cast(std::uniform_int_distribution<>(0,255)(rng)); } }; template<> struct randpix { - static double r() + static byte r() { - return rand() % 256; + return static_cast(std::uniform_int_distribution<>(0,255)(rng)); } }; template<> struct randpix { - static double r() + static byte r() { - return rand() % 256; + return static_cast(std::uniform_int_distribution<>(0,255)(rng)); } }; @@ -106,7 +120,7 @@ template<> struct randpix { static float r() { - return rand() * 10./RAND_MAX - 5; + return std::uniform_real_distribution(-5,5)(rng); } }; @@ -133,7 +147,7 @@ template string make_output_file_name(string fin, string type) //T tmp; //Remove the path from the filename - for(int i=fin.size()-1; i >= 0; i--) + for(int i=static_cast(fin.size()-1); i >= 0; i--) { if(fin[i] != '/') fn = fin[i] + fn; @@ -201,7 +215,7 @@ template void loadsave_safe(const char*n) { loadsave(n); } - catch(CVD::Exceptions::All b0rk3d) + catch(const CVD::Exceptions::All& b0rk3d) { cerr << "Image " << n << " error: " << b0rk3d.what() << endl; } @@ -275,7 +289,7 @@ template struct randtest else cerr << "OK.\n"; } - catch(Exceptions::All w) + catch(const Exceptions::All& w) { cerr << w.what() << endl; } From c7ac67f816d434d32f7ae3df07149380178445c6 Mon Sep 17 00:00:00 2001 From: Edward Rosten Date: Thu, 22 Oct 2020 15:56:39 +0100 Subject: [PATCH 3/7] Turn on Werror --- .github/workflows/ccpp.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 5a0440c4..5770fd63 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -10,9 +10,15 @@ jobs: build-test-ubuntu: runs-on: ubuntu-18.04 steps: + - run: | + sudo apt-get update + sudo apt install g++-10 gcc-10 - uses: actions/checkout@v2 - name: configure run: ./configure + env: + CC: gcc-10 + CXX: g++-10 -Werror - name: make run: make - name: make test From 86ae4f60fabbad3cd43ccad67fc24286b26bba71 Mon Sep 17 00:00:00 2001 From: Edward Rosten Date: Thu, 22 Oct 2020 17:29:00 +0100 Subject: [PATCH 4/7] suppress gcc10 false positives --- .github/workflows/ccpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 5770fd63..c4d172ac 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -18,7 +18,7 @@ jobs: run: ./configure env: CC: gcc-10 - CXX: g++-10 -Werror + CXX: g++-10 -Werror -Wno-stringop-overflow - name: make run: make - name: make test From 615569d53147533a02616e2fe10001157dc37c8a Mon Sep 17 00:00:00 2001 From: Edward Rosten Date: Thu, 22 Oct 2020 17:51:16 +0100 Subject: [PATCH 5/7] Use C++11 static assert --- cvd/internal/pixel_traits.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cvd/internal/pixel_traits.h b/cvd/internal/pixel_traits.h index d6a75dbe..3acb0166 100644 --- a/cvd/internal/pixel_traits.h +++ b/cvd/internal/pixel_traits.h @@ -12,13 +12,13 @@ namespace Pixel { template struct traits { - static_assert(std::numeric_limits::is_specialized == true); + static_assert(std::numeric_limits::is_specialized == true, "Traits not defined for this type"); using element_type = T; using wider_type = decltype(T{}*T{}); typedef float float_type; static const bool integral = true; static const bool is_signed = std::numeric_limits::is_signed; - static_assert(std::numeric_limits::is_integer == true); + static_assert(std::numeric_limits::is_integer == true, "Library bug, we shouldn't be here"); static const int bits_used = std::numeric_limits::digits; static const T max_intensity = std::numeric_limits::max(); }; From 347bc1649c1c8ab77f06cebff80e7fb0d19893c0 Mon Sep 17 00:00:00 2001 From: Edward Rosten Date: Thu, 22 Oct 2020 18:12:44 +0100 Subject: [PATCH 6/7] More casts --- cvd_src/Win32/glwindow.cpp | 162 ++++++++++++++++++------------------ cvd_src/yuv411_to_stuff.cxx | 20 ++--- 2 files changed, 91 insertions(+), 91 deletions(-) diff --git a/cvd_src/Win32/glwindow.cpp b/cvd_src/Win32/glwindow.cpp index b00ff0fd..1fdf5934 100644 --- a/cvd_src/Win32/glwindow.cpp +++ b/cvd_src/Win32/glwindow.cpp @@ -50,30 +50,30 @@ namespace CVD { void GLWindow::init(const ImageRef& size, int bpp, const std::string& title, const std::string&) { - GLuint PixelFormat; // Holds The Results After Searching For A Match - WNDCLASS wc; // Windows Class Structure - DWORD dwExStyle; // Window Extended Style - DWORD dwStyle; // Window Style - RECT WindowRect; // Grabs Rectangle Upper Left / Lower Right Values - WindowRect.left=(long)0; // Set Left Value To 0 - WindowRect.right=(long)size.x; // Set Right Value To Requested Width - WindowRect.top=(long)0; // Set Top Value To 0 - WindowRect.bottom=(long)size.y; // Set Bottom Value To Requested Height - - //fullscreen=fullscreenflag; // Set The Global Fullscreen Flag + GLuint PixelFormat; // Holds The Results After Searching For A Match + WNDCLASS wc; // Windows Class Structure + DWORD dwExStyle; // Window Extended Style + DWORD dwStyle; // Window Style + RECT WindowRect; // Grabs Rectangle Upper Left / Lower Right Values + WindowRect.left=(long)0; // Set Left Value To 0 + WindowRect.right=(long)size.x; // Set Right Value To Requested Width + WindowRect.top=(long)0; // Set Top Value To 0 + WindowRect.bottom=(long)size.y; // Set Bottom Value To Requested Height + + //fullscreen=fullscreenflag; // Set The Global Fullscreen Flag // Grab An Instance For Our Window - HINSTANCE hInstance = GetModuleHandle(NULL); + HINSTANCE hInstance = GetModuleHandle(NULL); if(!windowClassRegistered){ - wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Size, And Own DC For Window. - wc.lpfnWndProc = (WNDPROC) WndProc; // WndProc Handles Messages - wc.cbClsExtra = 0; // No Extra Window Data - wc.cbWndExtra = 0; // No Extra Window Data - wc.hInstance = hInstance; // Set The Instance - wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load The Default Icon - wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer - wc.hbrBackground = NULL; // No Background Required For GL - wc.lpszMenuName = NULL; // We Don't Want A Menu - wc.lpszClassName = "glwindow"; // Set The Class Name + wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Size, And Own DC For Window. + wc.lpfnWndProc = (WNDPROC) WndProc; // WndProc Handles Messages + wc.cbClsExtra = 0; // No Extra Window Data + wc.cbWndExtra = 0; // No Extra Window Data + wc.hInstance = hInstance; // Set The Instance + wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load The Default Icon + wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer + wc.hbrBackground = NULL; // No Background Required For GL + wc.lpszMenuName = NULL; // We Don't Want A Menu + wc.lpszClassName = "glwindow"; // Set The Class Name if (!RegisterClass(&wc)) throw Exceptions::GLWindow::CreationError("Failed to register the Window Class."); @@ -81,14 +81,14 @@ namespace CVD { } #if 0 - if (fullscreen) // Attempt Fullscreen Mode? + if (fullscreen) // Attempt Fullscreen Mode? { - DEVMODE dmScreenSettings; // Device Mode - memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); // Makes Sure Memory's Cleared - dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Size Of The Devmode Structure - dmScreenSettings.dmPelsWidth = width; // Selected Screen Width - dmScreenSettings.dmPelsHeight = height; // Selected Screen Height - dmScreenSettings.dmBitsPerPel = bits; // Selected Bits Per Pixel + DEVMODE dmScreenSettings; // Device Mode + memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); // Makes Sure Memory's Cleared + dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Size Of The Devmode Structure + dmScreenSettings.dmPelsWidth = width; // Selected Screen Width + dmScreenSettings.dmPelsHeight = height; // Selected Screen Height + dmScreenSettings.dmBitsPerPel = bits; // Selected Bits Per Pixel dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT; // Try To Set Selected Mode And Get Results. NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar. @@ -97,72 +97,72 @@ namespace CVD { // If The Mode Fails, Offer Two Options. Quit Or Use Windowed Mode. if (MessageBox(NULL,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?","NeHe GL",MB_YESNO|MB_ICONEXCLAMATION)==IDYES) { - fullscreen=FALSE; // Windowed Mode Selected. Fullscreen = FALSE + fullscreen=FALSE; // Windowed Mode Selected. Fullscreen = FALSE } else { // Pop Up A Message Box Letting User Know The Program Is Closing. MessageBox(NULL,"Program Will Now Close.","ERROR",MB_OK|MB_ICONSTOP); - return FALSE; // Return FALSE + return FALSE; // Return FALSE } } } - if (fullscreen) // Are We Still In Fullscreen Mode? + if (fullscreen) // Are We Still In Fullscreen Mode? { - dwExStyle=WS_EX_APPWINDOW; // Window Extended Style - dwStyle=WS_POPUP; // Windows Style - ShowCursor(FALSE); // Hide Mouse Pointer + dwExStyle=WS_EX_APPWINDOW; // Window Extended Style + dwStyle=WS_POPUP; // Windows Style + ShowCursor(FALSE); // Hide Mouse Pointer } else #endif { - dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style - dwStyle=WS_OVERLAPPEDWINDOW; // Windows Style + dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style + dwStyle=WS_OVERLAPPEDWINDOW; // Windows Style } RECT oldRect = WindowRect; - AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); // Adjust Window To True Requested Size + AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); // Adjust Window To True Requested Size // Create The Window HWND hWnd; - if (!(hWnd=CreateWindowEx( dwExStyle, // Extended Style For The Window - "glwindow", // Class Name - NULL, //title.c_str(), // Window Title - dwStyle | // Defined Window Style - WS_CLIPSIBLINGS | // Required Window Style - WS_CLIPCHILDREN, // Required Window Style - 0, 0, // Window Position - WindowRect.right-WindowRect.left, // Calculate Window Width - WindowRect.bottom-WindowRect.top, // Calculate Window Height - NULL, // No Parent Window - NULL, // No Menu - hInstance, // Instance - NULL))) // Dont Pass Anything To WM_CREATE + if (!(hWnd=CreateWindowEx( dwExStyle, // Extended Style For The Window + "glwindow", // Class Name + NULL, //title.c_str(), // Window Title + dwStyle | // Defined Window Style + WS_CLIPSIBLINGS | // Required Window Style + WS_CLIPCHILDREN, // Required Window Style + 0, 0, // Window Position + WindowRect.right-WindowRect.left, // Calculate Window Width + WindowRect.bottom-WindowRect.top, // Calculate Window Height + NULL, // No Parent Window + NULL, // No Menu + hInstance, // Instance + NULL))) // Dont Pass Anything To WM_CREATE { throw Exceptions::GLWindow::CreationError("Window Creation Error."); } - static PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be + static PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be { - sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor - 1, // Version Number - PFD_DRAW_TO_WINDOW | // Format Must Support Window - PFD_SUPPORT_OPENGL | // Format Must Support OpenGL - PFD_DOUBLEBUFFER, // Must Support Double Buffering - PFD_TYPE_RGBA, // Request An RGBA Format - bpp, // Select Our Color Depth - 0, 0, 0, 0, 0, 0, // Color Bits Ignored - 0, // No Alpha Buffer - 0, // Shift Bit Ignored - 0, // No Accumulation Buffer - 0, 0, 0, 0, // Accumulation Bits Ignored - 32, // 32Bit Z-Buffer (Depth Buffer) - 8, // 8bit Stencil Buffer - 0, // No Auxiliary Buffer - PFD_MAIN_PLANE, // Main Drawing Layer - 0, // Reserved - 0, 0, 0 // Layer Masks Ignored + sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor + 1, // Version Number + PFD_DRAW_TO_WINDOW | // Format Must Support Window + PFD_SUPPORT_OPENGL | // Format Must Support OpenGL + PFD_DOUBLEBUFFER, // Must Support Double Buffering + PFD_TYPE_RGBA, // Request An RGBA Format + static_cast(bpp), // Select Our Color Depth + 0, 0, 0, 0, 0, 0, // Color Bits Ignored + 0, // No Alpha Buffer + 0, // Shift Bit Ignored + 0, // No Accumulation Buffer + 0, 0, 0, 0, // Accumulation Bits Ignored + 32, // 32Bit Z-Buffer (Depth Buffer) + 8, // 8bit Stencil Buffer + 0, // No Auxiliary Buffer + PFD_MAIN_PLANE, // Main Drawing Layer + 0, // Reserved + 0, 0, 0 // Layer Masks Ignored }; HDC hDC; @@ -182,9 +182,9 @@ namespace CVD { if(!wglMakeCurrent(hDC,hRC)) throw Exceptions::GLWindow::CreationError("Can't Activate The GL Rendering Context."); - ShowWindow(hWnd,SW_SHOW); // Show The Window - SetForegroundWindow(hWnd); // Slightly Higher Priority - SetFocus(hWnd); // Sets Keyboard Focus To The Window + ShowWindow(hWnd,SW_SHOW); // Show The Window + SetForegroundWindow(hWnd); // Slightly Higher Priority + SetFocus(hWnd); // Sets Keyboard Focus To The Window glLoadIdentity(); glViewport(0, 0, size.x, size.y); @@ -240,7 +240,7 @@ namespace CVD { if(state->hRC){ if (wglGetCurrentContext() == state->hRC) - if (!wglMakeCurrent(NULL,NULL)) + if (!wglMakeCurrent(NULL,NULL)) throw Exceptions::GLWindow::RuntimeError("Release of DC and RC failed."); if (!wglDeleteContext(state->hRC)) throw Exceptions::GLWindow::RuntimeError("Release Rendering Context failed."); @@ -402,7 +402,7 @@ namespace CVD { handler.on_event(*this, EVENT_EXPOSE); } - MSG msg; + MSG msg; currentHandler = &handler; // for events only received in Window Procedure @@ -547,7 +547,7 @@ namespace CVD { public: MakeSummary(GLWindow::EventSummary& summary_) : summary(summary_) {} - void on_key_down(GLWindow&, int key) { ++summary.key_down[key]; } + void on_key_down(GLWindow&, int key) { ++summary.key_down[key]; } void on_key_up(GLWindow&, int key) { ++summary.key_up[key]; } void on_mouse_move(GLWindow&, ImageRef where, int) { summary.cursor = where; summary.cursor_moved = true; } void on_mouse_down(GLWindow&, ImageRef where, int state, int button) { summary.mouse_down[button] = std::make_pair(where,state); } @@ -571,7 +571,7 @@ namespace CVD { throw Exceptions::GLWindow::RuntimeError("Window is not open."); } - MSG msg; + MSG msg; return PeekMessage(&msg, state->hWnd, 0, 0, PM_NOREMOVE) != 0; } @@ -585,10 +585,10 @@ namespace CVD { throw Exceptions::GLWindow::RuntimeError("wglMakeCurrent failed"); } - LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window - UINT uMsg, // Message For This Window - WPARAM wParam, // Additional Message Information - LPARAM lParam) // Additional Message Information + LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window + UINT uMsg, // Message For This Window + WPARAM wParam, // Additional Message Information + LPARAM lParam) // Additional Message Information { switch(uMsg){ case WM_WINDOWPOSCHANGED: diff --git a/cvd_src/yuv411_to_stuff.cxx b/cvd_src/yuv411_to_stuff.cxx index 63744c97..d9e865bf 100644 --- a/cvd_src/yuv411_to_stuff.cxx +++ b/cvd_src/yuv411_to_stuff.cxx @@ -30,12 +30,12 @@ void yuv411_to_rgb_y(const unsigned char* ip, int npix, unsigned char* op, unsig { //Format is uYYvYY //Y, 8 but uchar, (u,v) 8 bit uchar-127 - u = *ip - 128; - v = *(ip+3) - 128; + u = static_cast(*ip - 128); + v = static_cast(*(ip+3) - 128); - rv = 1.140*v; - guv = -0.394*u -0.581*v; - bu = 2.028*u; + rv = 1.140f*v; + guv = -0.394f*u -0.581f*v; + bu = 2.028f*u; y1 = ip[1]; y2 = ip[2]; @@ -81,12 +81,12 @@ void yuv411_to_rgb(const unsigned char* ip, int npix, unsigned char* op) { //Format is uYYvYY //Y, 8 but uchar, (u,v) 8 bit uchar-127 - u = *ip - 128; - v = *(ip+3) - 128; + u = static_cast(*ip - 128); + v = static_cast(*(ip+3) - 128); - rv = 1.140*v; - guv = -0.394*u -0.581*v; - bu = 2.028*u; + rv = 1.140f*v; + guv = -0.394f*u -0.581f*v; + bu = 2.028f*u; y1 = ip[1]; y2 = ip[2]; From e2f6d821a707735509991132776610b4bb1c34f0 Mon Sep 17 00:00:00 2001 From: Edward Rosten Date: Thu, 22 Oct 2020 18:15:41 +0100 Subject: [PATCH 7/7] More casts --- cvd_src/Win32/glwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cvd_src/Win32/glwindow.cpp b/cvd_src/Win32/glwindow.cpp index 1fdf5934..474bb1e5 100644 --- a/cvd_src/Win32/glwindow.cpp +++ b/cvd_src/Win32/glwindow.cpp @@ -151,7 +151,7 @@ namespace CVD { PFD_SUPPORT_OPENGL | // Format Must Support OpenGL PFD_DOUBLEBUFFER, // Must Support Double Buffering PFD_TYPE_RGBA, // Request An RGBA Format - static_cast(bpp), // Select Our Color Depth + static_cast(bpp), // Select Our Color Depth 0, 0, 0, 0, 0, 0, // Color Bits Ignored 0, // No Alpha Buffer 0, // Shift Bit Ignored