Skip to content

Commit

Permalink
Merge pull request #65 from edrosten/er/conversion-warning
Browse files Browse the repository at this point in the history
Fix a load of -Wconversion warnings
  • Loading branch information
edrosten authored Oct 22, 2020
2 parents 6bce685 + e2f6d82 commit c57d30f
Show file tree
Hide file tree
Showing 58 changed files with 827 additions and 884 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -Wno-stringop-overflow
- name: make
run: make
- name: make test
Expand Down
12 changes: 9 additions & 3 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
170 changes: 49 additions & 121 deletions cvd/colourspaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,127 +206,55 @@ namespace CVD
template<> struct type_name<MJPEG> { static std::string name(){return "MJPEG" ;}};
}

namespace Pixel {
template<int LIFT> struct traits<bayer_bggr, LIFT>
{
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<int LIFT> struct traits<bayer_rggb, LIFT>
{
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<int LIFT> struct traits<bayer_gbrg, LIFT>
{
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<int LIFT> struct traits<bayer_grbg, LIFT>
{
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<int LIFT> struct traits<bayer_bggr16, LIFT>
{
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<int LIFT> struct traits<bayer_rggb16, LIFT>
{
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<int LIFT> struct traits<bayer_gbrg16, LIFT>
{
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<int LIFT> struct traits<bayer_grbg16, LIFT>
{
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<int LIFT> struct traits<bayer_bggr16be, LIFT>
{
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<int LIFT> struct traits<bayer_rggb16be, LIFT>
{
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<int LIFT> struct traits<bayer_gbrg16be, LIFT>
{
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<int LIFT> struct traits<bayer_grbg16be, LIFT>
{
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<int LIFT> struct traits<bayer_bggr, LIFT> : public traits<unsigned char, LIFT>
{
};

template<int LIFT> struct traits<bayer_rggb, LIFT> : public traits<unsigned char, LIFT>
{
};

template<int LIFT> struct traits<bayer_gbrg, LIFT>: public traits<unsigned char, LIFT>
{
};

template<int LIFT> struct traits<bayer_grbg, LIFT>: public traits<unsigned char, LIFT>
{
};

template<int LIFT> struct traits<bayer_bggr16, LIFT>: public traits<unsigned short, LIFT>
{
};

template<int LIFT> struct traits<bayer_rggb16, LIFT>: public traits<unsigned short, LIFT>
{
};

template<int LIFT> struct traits<bayer_gbrg16, LIFT>: public traits<unsigned short, LIFT>
{
};

template<int LIFT> struct traits<bayer_grbg16, LIFT>: public traits<unsigned short, LIFT>
{
};

template<int LIFT> struct traits<bayer_bggr16be, LIFT>: public traits<unsigned short, LIFT>
{
};

template<int LIFT> struct traits<bayer_rggb16be, LIFT>: public traits<unsigned short, LIFT>
{
};

template<int LIFT> struct traits<bayer_gbrg16be, LIFT>: public traits<unsigned short, LIFT>
{
};

template<int LIFT> struct traits<bayer_grbg16be, LIFT>: public traits<unsigned short, LIFT>
{
};
}

}

Expand Down
10 changes: 5 additions & 5 deletions cvd/deinterlacebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class DeinterlaceBuffer : public VideoBuffer<T>
Fields::Fields m_fields;
bool m_loadnewframe;
ImageRef m_size;
unsigned int m_linebytes;
long m_linebytes;
bool line_double;
};

Expand Down Expand Up @@ -180,8 +180,8 @@ VideoFrame<T>* DeinterlaceBuffer<T>::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<T>::count; i++)
Pixel::Component<T>::get((*frame)[y][x],i) = (Pixel::Component<T>::get((*my_realframe)[y-1][x],i) +
Pixel::Component<T>::get((*my_realframe)[y+1][x],i))/2;
Pixel::Component<T>::get((*frame)[y][x],i) = static_cast<typename Pixel::Component<T>::type>((Pixel::Component<T>::get((*my_realframe)[y-1][x],i) +
Pixel::Component<T>::get((*my_realframe)[y+1][x],i))/2);

/*
//Copy line 0 from line 1, and copy over line 1 to line 1
Expand Down Expand Up @@ -221,8 +221,8 @@ VideoFrame<T>* DeinterlaceBuffer<T>::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<T>::count; i++)
Pixel::Component<T>::get((*frame)[y][x],i) = (Pixel::Component<T>::get((*my_realframe)[y-1][x],i) +
Pixel::Component<T>::get((*my_realframe)[y+1][x],i))/2;
Pixel::Component<T>::get((*frame)[y][x],i) = static_cast<typename Pixel::Component<T>::type>((Pixel::Component<T>::get((*my_realframe)[y-1][x],i) +
Pixel::Component<T>::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)
Expand Down
14 changes: 7 additions & 7 deletions cvd/distance_transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
{}

Expand Down Expand Up @@ -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<int>(dy);
const ImageRef candA(static_cast<int>(x - dx), static_cast<int>(y - ddy));
const ImageRef candB(static_cast<int>(x - dx), static_cast<int>(y + ddy));
const ImageRef candC(static_cast<int>(x + dx), static_cast<int>(y - ddy));
const ImageRef candD(static_cast<int>(x + dx), static_cast<int>(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)) {
Expand Down Expand Up @@ -199,7 +199,7 @@ namespace CVD {

private:
ImageRef sz;
double big_number;
int big_number;
std::vector <Precision> d;
std::vector <int> v;
std::vector <Precision> z;
Expand Down
2 changes: 1 addition & 1 deletion cvd/draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ std::vector<ImageRef> getCircle(int radius);
/// @param radius radius of the circle in pixels
/// @return vector containig ImageRef for the circle
/// @ingroup gGraphics
std::vector<ImageRef> getDisc(float radius);
std::vector<ImageRef> getDisc(double radius);


#if defined CVD_HAVE_TOON || defined DOXYGEN_IGNORE_INTERNAL
Expand Down
12 changes: 6 additions & 6 deletions cvd/glwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cvd/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ namespace Internal

//Class to give us a size 2 return value or fail on
//substituting S
template<int S>
template<unsigned long S>
struct SFINAE_dummy
{
typedef Two Type;
Expand Down
2 changes: 1 addition & 1 deletion cvd/image_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading

0 comments on commit c57d30f

Please sign in to comment.