[arrayfire] 57/79: Fix for displaying images of type uchar, int and uint
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Mon Jun 15 13:38:07 UTC 2015
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch master
in repository arrayfire.
commit acbc41c10ff834579aab572a3c997e56c3c34a1e
Author: pradeep <pradeep at arrayfire.com>
Date: Wed Jun 10 16:05:10 2015 -0400
Fix for displaying images of type uchar, int and uint
---
examples/graphics/histogram.cpp | 2 +-
src/api/c/image.cpp | 25 ++++++++++++++++++++++++-
2 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/examples/graphics/histogram.cpp b/examples/graphics/histogram.cpp
index e91f6d5..c49a36f 100644
--- a/examples/graphics/histogram.cpp
+++ b/examples/graphics/histogram.cpp
@@ -26,7 +26,7 @@ int main(int argc, char *argv[])
while (!myWindow.close() && !imgWnd.close()) {
myWindow.hist(hist_out, 0, 255);
- imgWnd.image(img/255);
+ imgWnd.image(img.as(u8));
}
}
diff --git a/src/api/c/image.cpp b/src/api/c/image.cpp
index d51ac9c..8d075fa 100644
--- a/src/api/c/image.cpp
+++ b/src/api/c/image.cpp
@@ -22,8 +22,11 @@
#include <reorder.hpp>
#include <tile.hpp>
#include <join.hpp>
+#include <cast.hpp>
+#include <arith.hpp>
#include <iostream>
+#include <limits>
using af::dim4;
using namespace detail;
@@ -31,6 +34,26 @@ using namespace detail;
#if defined(WITH_GRAPHICS)
using namespace graphics;
+
+template<typename T>
+Array<T> normalizePerType(const Array<T>& in)
+{
+ Array<float> inFloat = cast<float, T>(in);
+
+ Array<float> cnst = createValueArray<float>(in.dims(),
+ std::numeric_limits<T>::max()/(255.0f+1.0e-6f));
+
+ Array<float> scaled = arithOp<float, af_mul_t>(inFloat, cnst, in.dims());
+
+ return cast<T, float>(scaled);
+}
+
+template<>
+Array<float> normalizePerType<float>(const Array<float>& in)
+{
+ return in;
+}
+
template<typename T>
static fg::Image* convert_and_copy_image(const af_array in)
{
@@ -46,7 +69,7 @@ static fg::Image* convert_and_copy_image(const af_array in)
fg::Image* ret_val = fgMngr.getImage(inDims[1], inDims[0], (fg::ColorMode)inDims[2], getGLType<T>());
- copy_image<T>(imgData, ret_val);
+ copy_image<T>(normalizePerType<T>(imgData), ret_val);
return ret_val;
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/arrayfire.git
More information about the debian-science-commits
mailing list