[arrayfire] 153/248: Moved common functions from imageio into header file
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Tue Nov 17 15:54:18 UTC 2015
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch dfsg-clean
in repository arrayfire.
commit 551cd560cb8e2741a2f48a5868c99efea220fbd4
Author: Shehzan Mohammed <shehzan at arrayfire.com>
Date: Thu Oct 29 16:12:53 2015 -0400
Moved common functions from imageio into header file
---
src/api/c/imageio.cpp | 93 ++-------------------------------------
src/api/c/imageio_helper.h | 105 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 109 insertions(+), 89 deletions(-)
diff --git a/src/api/c/imageio.cpp b/src/api/c/imageio.cpp
index 259e0d7..9e0a3ff 100644
--- a/src/api/c/imageio.cpp
+++ b/src/api/c/imageio.cpp
@@ -9,20 +9,21 @@
#if defined(WITH_FREEIMAGE)
+#include "imageio_helper.h"
+
#include <af/array.h>
+#include <af/index.h>
+#include <af/dim4.hpp>
#include <af/arith.h>
#include <af/algorithm.h>
#include <af/blas.h>
#include <af/data.h>
#include <af/image.h>
-#include <af/index.h>
-#include <err_common.hpp>
#include <backend.hpp>
#include <ArrayInfo.hpp>
#include <traits.hpp>
#include <memory.hpp>
-#include <FreeImage.h>
#include <string>
#include <cstring>
#include <cstdio>
@@ -31,94 +32,8 @@
using af::dim4;
using namespace detail;
-class FI_Manager
-{
- public:
- static bool initialized;
- FI_Manager()
- {
-#ifdef FREEIMAGE_LIB
- FreeImage_Initialise();
-#endif
- initialized = true;
- }
-
- ~FI_Manager()
- {
-#ifdef FREEIMAGE_LIB
- FreeImage_DeInitialise();
-#endif
- }
-};
-
bool FI_Manager::initialized = false;
-static void FI_Init()
-{
- static FI_Manager manager = FI_Manager();
-}
-
-class FI_BitmapResource
-{
-public:
- explicit FI_BitmapResource(FIBITMAP * p) :
- pBitmap(p)
- {
- }
-
- ~FI_BitmapResource()
- {
- FreeImage_Unload(pBitmap);
- }
-private:
- FIBITMAP * pBitmap;
-};
-
-typedef enum {
- AFFI_GRAY = 1,
- AFFI_RGB = 3,
- AFFI_RGBA = 4
-} FI_CHANNELS;
-
-
-// Helpers
-void FreeImageErrorHandler(FREE_IMAGE_FORMAT oFif, const char* zMessage);
-
-// Error handler for FreeImage library.
-// In case this handler is invoked, it throws an af exception.
-void FreeImageErrorHandler(FREE_IMAGE_FORMAT oFif, const char* zMessage)
-{
- printf("FreeImage Error Handler: %s\n", zMessage);
-}
-
-// Split a MxNx3 image into 3 separate channel matrices.
-// Produce 3 channels if needed
-static af_err channel_split(const af_array rgb, const af::dim4 &dims,
- af_array *outr, af_array *outg, af_array *outb, af_array *outa)
-{
- try {
- af_seq idx[4][3] = {{af_span, af_span, {0, 0, 1}},
- {af_span, af_span, {1, 1, 1}},
- {af_span, af_span, {2, 2, 1}},
- {af_span, af_span, {3, 3, 1}}
- };
-
- if (dims[2] == 4) {
- AF_CHECK(af_index(outr, rgb, dims.ndims(), idx[0]));
- AF_CHECK(af_index(outg, rgb, dims.ndims(), idx[1]));
- AF_CHECK(af_index(outb, rgb, dims.ndims(), idx[2]));
- AF_CHECK(af_index(outa, rgb, dims.ndims(), idx[3]));
- } else if (dims[2] == 3) {
- AF_CHECK(af_index(outr, rgb, dims.ndims(), idx[0]));
- AF_CHECK(af_index(outg, rgb, dims.ndims(), idx[1]));
- AF_CHECK(af_index(outb, rgb, dims.ndims(), idx[2]));
- } else {
- AF_CHECK(af_index(outr, rgb, dims.ndims(), idx[0]));
- }
- } CATCHALL;
- return AF_SUCCESS;
-}
-
template<typename T, FI_CHANNELS fi_color, FI_CHANNELS fo_color>
static af_err readImage(af_array *rImage, const uchar* pSrcLine, const int nSrcPitch,
const uint fi_w, const uint fi_h)
diff --git a/src/api/c/imageio_helper.h b/src/api/c/imageio_helper.h
new file mode 100644
index 0000000..907571b
--- /dev/null
+++ b/src/api/c/imageio_helper.h
@@ -0,0 +1,105 @@
+/*******************************************************
+ * Copyright (c) 2014, ArrayFire
+ * All rights reserved.
+ *
+ * This file is distributed under 3-clause BSD license.
+ * The complete license agreement can be obtained at:
+ * http://arrayfire.com/licenses/BSD-3-Clause
+ ********************************************************/
+
+#ifndef IMAGEIO_HELPER_H
+#define IMAGEIO_HELPER_H
+
+#include <FreeImage.h>
+
+#include <af/array.h>
+#include <af/index.h>
+#include <af/dim4.hpp>
+#include <err_common.hpp>
+
+class FI_Manager
+{
+ public:
+ static bool initialized;
+ FI_Manager()
+ {
+#ifdef FREEIMAGE_LIB
+ FreeImage_Initialise();
+#endif
+ initialized = true;
+ }
+
+ ~FI_Manager()
+ {
+#ifdef FREEIMAGE_LIB
+ FreeImage_DeInitialise();
+#endif
+ }
+};
+
+static void FI_Init()
+{
+ static FI_Manager manager = FI_Manager();
+}
+
+class FI_BitmapResource
+{
+public:
+ explicit FI_BitmapResource(FIBITMAP * p) :
+ pBitmap(p)
+ {
+ }
+
+ ~FI_BitmapResource()
+ {
+ FreeImage_Unload(pBitmap);
+ }
+private:
+ FIBITMAP * pBitmap;
+};
+
+typedef enum {
+ AFFI_GRAY = 1,
+ AFFI_RGB = 3,
+ AFFI_RGBA = 4
+} FI_CHANNELS;
+
+// Helpers
+void FreeImageErrorHandler(FREE_IMAGE_FORMAT oFif, const char* zMessage);
+
+// Error handler for FreeImage library.
+// In case this handler is invoked, it throws an af exception.
+void FreeImageErrorHandler(FREE_IMAGE_FORMAT oFif, const char* zMessage)
+{
+ printf("FreeImage Error Handler: %s\n", zMessage);
+}
+
+// Split a MxNx3 image into 3 separate channel matrices.
+// Produce 3 channels if needed
+static af_err channel_split(const af_array rgb, const af::dim4 &dims,
+ af_array *outr, af_array *outg, af_array *outb, af_array *outa)
+{
+ try {
+ af_seq idx[4][3] = {{af_span, af_span, {0, 0, 1}},
+ {af_span, af_span, {1, 1, 1}},
+ {af_span, af_span, {2, 2, 1}},
+ {af_span, af_span, {3, 3, 1}}
+ };
+
+ if (dims[2] == 4) {
+ AF_CHECK(af_index(outr, rgb, dims.ndims(), idx[0]));
+ AF_CHECK(af_index(outg, rgb, dims.ndims(), idx[1]));
+ AF_CHECK(af_index(outb, rgb, dims.ndims(), idx[2]));
+ AF_CHECK(af_index(outa, rgb, dims.ndims(), idx[3]));
+ } else if (dims[2] == 3) {
+ AF_CHECK(af_index(outr, rgb, dims.ndims(), idx[0]));
+ AF_CHECK(af_index(outg, rgb, dims.ndims(), idx[1]));
+ AF_CHECK(af_index(outb, rgb, dims.ndims(), idx[2]));
+ } else {
+ AF_CHECK(af_index(outr, rgb, dims.ndims(), idx[0]));
+ }
+ } CATCHALL;
+ return AF_SUCCESS;
+}
+
+#endif
--
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