[arrayfire] 226/408: Modifed colorspace function wrapper code for efficiency

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Sep 21 19:12:03 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch debian/sid
in repository arrayfire.

commit b55a459a09f792f3177079f05b1f26c1c68f7249
Author: pradeep <pradeep at arrayfire.com>
Date:   Tue Aug 11 11:54:18 2015 -0400

    Modifed colorspace function wrapper code for efficiency
---
 src/api/c/colorspace.cpp | 64 ++++++++++++++++++++++++++++++++++++------------
 1 file changed, 48 insertions(+), 16 deletions(-)

diff --git a/src/api/c/colorspace.cpp b/src/api/c/colorspace.cpp
index 5933033..c73424f 100644
--- a/src/api/c/colorspace.cpp
+++ b/src/api/c/colorspace.cpp
@@ -8,28 +8,60 @@
  ********************************************************/
 
 #include <af/defines.h>
+#include <af/array.h>
 #include <af/image.h>
 #include <err_common.hpp>
 
-af_err af_color_space(af_array *out, const af_array image, const af_cspace_t to, const af_cspace_t from)
+template<af_cspace_t FROM, af_cspace_t TO>
+af_err convert(af_array *out, const af_array image)
 {
-    bool hsv2rgb  = (from==AF_HSV   && to==AF_RGB  );
-    bool rgb2hsv  = (from==AF_RGB   && to==AF_HSV  );
-    bool gray2rgb = (from==AF_GRAY  && to==AF_RGB  );
-    bool rgb2gray = (from==AF_RGB   && to==AF_GRAY );
-    bool ycbcr2rgb= (from==AF_YCbCr && to==AF_RGB  );
-    bool rgb2ycbcr= (from==AF_RGB   && to==AF_YCbCr);
+    return AF_ERR_NOT_SUPPORTED;
+}
+
+#define INSTANTIATE_CSPACE_DEFS1(F, T, FUNC)                \
+template<>                                                  \
+af_err convert<F, T>(af_array *out, const af_array image)   \
+{                                                           \
+    return FUNC(out, image);                                \
+}
+
+#define INSTANTIATE_CSPACE_DEFS2(F, T, FUNC, ...)           \
+template<>                                                  \
+af_err convert<F, T>(af_array *out, const af_array image)   \
+{                                                           \
+    return FUNC(out, image, __VA_ARGS__);                   \
+}
 
-    ARG_ASSERT(2, (hsv2rgb || rgb2hsv || gray2rgb || rgb2gray || ycbcr2rgb || rgb2ycbcr));
+INSTANTIATE_CSPACE_DEFS1(AF_HSV  , AF_RGB  , af_hsv2rgb  );
+INSTANTIATE_CSPACE_DEFS1(AF_RGB  , AF_HSV  , af_rgb2hsv  );
+INSTANTIATE_CSPACE_DEFS2(AF_RGB  , AF_GRAY , af_rgb2gray , 0.2126f, 0.7152f, 0.0722f);
+INSTANTIATE_CSPACE_DEFS2(AF_GRAY , AF_RGB  , af_gray2rgb , 1.0f, 1.0f, 1.0f);
+INSTANTIATE_CSPACE_DEFS2(AF_YCbCr, AF_RGB  , af_ycbcr2rgb, AF_YCC_601);
+INSTANTIATE_CSPACE_DEFS2(AF_RGB  , AF_YCbCr, af_rgb2ycbcr, AF_YCC_601);
 
-    af_err result = AF_SUCCESS;
+template<af_cspace_t FROM>
+static af_err convert(af_array *out, const af_array image, const af_cspace_t to)
+{
+    switch(to) {
+        case AF_GRAY : return convert<FROM, AF_GRAY >(out, image);
+        case AF_RGB  : return convert<FROM, AF_RGB  >(out, image);
+        case AF_HSV  : return convert<FROM, AF_HSV  >(out, image);
+        case AF_YCbCr: return convert<FROM, AF_YCbCr>(out, image);
+        default: return AF_ERR_ARG;
+    }
+}
 
-    if (hsv2rgb)   result = af_hsv2rgb(out, image);
-    if (rgb2hsv)   result = af_rgb2hsv(out, image);
-    if (gray2rgb)  result = af_gray2rgb(out, image, 1.0f, 1.0f, 1.0f);
-    if (rgb2gray)  result = af_rgb2gray(out, image, 0.2126f, 0.7152f, 0.0722f);
-    if (ycbcr2rgb) result = af_ycbcr2rgb(out, image, AF_YCC_601);
-    if (rgb2ycbcr) result = af_rgb2ycbcr(out, image, AF_YCC_601);
+af_err af_color_space(af_array *out, const af_array image, const af_cspace_t to, const af_cspace_t from)
+{
+    if (from==to) {
+        return af_retain_array(out, image);
+    }
 
-    return result;
+    switch(from) {
+        case AF_GRAY : return convert<AF_GRAY >(out, image, to);
+        case AF_RGB  : return convert<AF_RGB  >(out, image, to);
+        case AF_HSV  : return convert<AF_HSV  >(out, image, to);
+        case AF_YCbCr: return convert<AF_YCbCr>(out, image, to);
+        default: return AF_ERR_ARG;
+    }
 }

-- 
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