From 8e53cfeda96cbd3cc8d1ae7f819fef023a3deaa9 Mon Sep 17 00:00:00 2001 From: Massimiliano Corsini maxcorsini Date: Mon, 22 Jan 2007 16:35:10 +0000 Subject: [PATCH] improve qimage conversion --- src/meshlabplugins/epoch_io/scalar_image.cpp | 12 --------- src/meshlabplugins/epoch_io/scalar_image.h | 28 +++++++++++++++++++- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/meshlabplugins/epoch_io/scalar_image.cpp b/src/meshlabplugins/epoch_io/scalar_image.cpp index 32330052d..de9e48add 100644 --- a/src/meshlabplugins/epoch_io/scalar_image.cpp +++ b/src/meshlabplugins/epoch_io/scalar_image.cpp @@ -178,18 +178,6 @@ ScalarImage::ScalarImage(QImage img) } -template <> -QImage ScalarImage::convertToQImage() -{ - QImage img(w,h,QImage::Format_RGB32); - for(int x=0;x bool ScalarImage::Subsample(const int factor, ScalarImage &fli) { diff --git a/src/meshlabplugins/epoch_io/scalar_image.h b/src/meshlabplugins/epoch_io/scalar_image.h index 9f8662c1d..3a4b27a75 100644 --- a/src/meshlabplugins/epoch_io/scalar_image.h +++ b/src/meshlabplugins/epoch_io/scalar_image.h @@ -19,7 +19,33 @@ public: return v[y*w+x]; }; - QImage convertToQImage(); + inline QImage convertToQImage() + { + QImage img(w,h,QImage::Format_RGB32); + + float max = 0.0f; + float min = Val(0,0); + for (int y = 0; y < h; y++) + for (int x = 0; x < w; x++) + { + if (Val(x, y) < min) + min = Val(x, y); + if (Val(x, y) > max) + max = Val(x, y); + } + + float scale = 1.0f / max; + for (int y = 0; y < h; y++) + for (int x = 0; x < w; x++) + { + float value = (Val(x, y) - min) * scale; + value *= 255.0f; + img.setPixel(x,y,qRgb(value,value,value)); + } + + return img; + } + ScalarImage(QImage img); ScalarImage(){}; bool Subsample(const int factor, ScalarImage &fli);