From 1585b4a6140363e7f7bc726d85abb6fbc27376fa Mon Sep 17 00:00:00 2001 From: hsc Date: Wed, 24 Oct 2012 09:58:50 +0000 Subject: [PATCH] nanojpeg: signedness fixes git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@1813 8c4709b5-6ec9-48aa-a5cd-a96041d1645a --- src/experiments/nanojpeg/experiment.cc | 4 ++-- src/experiments/nanojpeg/psnr.cc | 9 +++++---- src/experiments/nanojpeg/psnr.hpp | 6 +++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/experiments/nanojpeg/experiment.cc b/src/experiments/nanojpeg/experiment.cc index bbabe2d0..fd80f012 100644 --- a/src/experiments/nanojpeg/experiment.cc +++ b/src/experiments/nanojpeg/experiment.cc @@ -153,7 +153,7 @@ bool NanoJPEGExperiment::run() uint32_t newdata = data ^ (1 << bitnr); reg->setData(newdata); // note at what IP we did it - int32_t injection_ip = simulator.getRegisterManager().getInstructionPointer(); + uint32_t injection_ip = simulator.getRegisterManager().getInstructionPointer(); param.msg.set_injection_ip(injection_ip); log << "fault injected @ ip " << injection_ip << " reg " << reg->getName() << " 0x" << hex << ((int)data) << " -> 0x" << ((int)newdata) << endl; @@ -217,7 +217,7 @@ bool NanoJPEGExperiment::run() MemoryManager& mm = simulator.getMemoryManager(); uint32_t output_image_addr; mm.getBytes(addr_output_image_ptr, 4, &output_image_addr); - int32_t output_image_size; + uint32_t output_image_size; mm.getBytes(addr_output_image_size, 4, &output_image_size); log << "image address " << hex << output_image_addr << " size " << dec << output_image_size << endl; if (output_image_size != 3 * psnr.getWidth() * psnr.getHeight()) { diff --git a/src/experiments/nanojpeg/psnr.cc b/src/experiments/nanojpeg/psnr.cc index 404ef52b..14c402cc 100644 --- a/src/experiments/nanojpeg/psnr.cc +++ b/src/experiments/nanojpeg/psnr.cc @@ -20,11 +20,11 @@ static inline double square(double x) return x*x; } -static double image_rgb_mse(const unsigned char *f1, const unsigned char *f2, int width, int height, double max) +static double image_rgb_mse(const unsigned char *f1, const unsigned char *f2, unsigned width, unsigned height, double max) { double sum = 0.0; - for (int y = 0; y < height; ++y) { - for (int x = 0; x < width; ++x) { + for (unsigned y = 0; y < height; ++y) { + for (unsigned x = 0; x < width; ++x) { sum += square(f1[x*y*3+0] - f2[x*y*3+0]); sum += square(f1[x*y*3+1] - f2[x*y*3+1]); sum += square(f1[x*y*3+2] - f2[x*y*3+2]); @@ -33,7 +33,7 @@ static double image_rgb_mse(const unsigned char *f1, const unsigned char *f2, in return sum / (3 * height * width); } -static double image_rgb_psnr(const unsigned char *f1, const unsigned char *f2, int width, int height, double max) +static double image_rgb_psnr(const unsigned char *f1, const unsigned char *f2, unsigned width, unsigned height, double max) { double mse = image_rgb_mse(f1, f2, width, height, max); return 20.0 * log10(max / sqrt(mse)); @@ -76,4 +76,5 @@ bool PSNR::load_refimage(char const *refimage_filename) std::cerr << "image too small" << std::endl; return false; } + return true; } diff --git a/src/experiments/nanojpeg/psnr.hpp b/src/experiments/nanojpeg/psnr.hpp index 30a8ea58..a2ba4a75 100644 --- a/src/experiments/nanojpeg/psnr.hpp +++ b/src/experiments/nanojpeg/psnr.hpp @@ -7,7 +7,7 @@ class PSNR { private: std::string refimg; - int refimg_width, refimg_height, refimg_max; + unsigned refimg_width, refimg_height, refimg_max; public: PSNR(char const *refimage_filename) @@ -19,8 +19,8 @@ public: // we only accept P6 without comments bool load_refimage(char const *refimage_filename); double calculate(const std::string& img); - int getWidth() { return refimg_width; } - int getHeight() { return refimg_height; } + unsigned getWidth() { return refimg_width; } + unsigned getHeight() { return refimg_height; } }; #endif