[arrayfire] 157/248: Fix imageio load order in case of bitmap and not bitmap

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Tue Nov 17 15:54:19 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 6a21345024d351f6a8ecde7f66219add116b91e3
Author: Shehzan Mohammed <shehzan at arrayfire.com>
Date:   Thu Oct 29 21:48:08 2015 -0400

    Fix imageio load order in case of bitmap and not bitmap
---
 src/api/c/imageio.cpp  | 50 +++++++++++++++++++++++++++++++++-----------------
 src/api/c/imageio2.cpp | 41 ++++++++++++++++++++++++++++++-----------
 2 files changed, 63 insertions(+), 28 deletions(-)

diff --git a/src/api/c/imageio.cpp b/src/api/c/imageio.cpp
index 9e0a3ff..3442a2a 100644
--- a/src/api/c/imageio.cpp
+++ b/src/api/c/imageio.cpp
@@ -46,20 +46,28 @@ static af_err readImage(af_array *rImage, const uchar* pSrcLine, const int nSrcP
     float* pDst2 = pDst + (fi_w * fi_h * 2);
     float* pDst3 = pDst + (fi_w * fi_h * 3);
 
-    int offR = 2; int offG = 1; int offB = 0; int offA = 3;
-    if (fo_color == 3 && fi_color == 1) {       //Convert gray to color
-        offG = 0; offR = 0;
-    }
     uint indx = 0;
     uint step = fi_color;
 
     for (uint x = 0; x < fi_w; ++x) {
         for (uint y = 0; y < fi_h; ++y) {
             const T *src = (T*)(pSrcLine - y * nSrcPitch);
-                               pDst2[indx] = (float) *(src + (x * step + offB));
-            if (fo_color >= 3) pDst1[indx] = (float) *(src + (x * step + offG));
-            if (fo_color >= 3) pDst0[indx] = (float) *(src + (x * step + offR));
-            if (fo_color == 4) pDst3[indx] = (float) *(src + (x * step + offA));
+            if(fo_color == 1) {
+                pDst0[indx] = (T) *(src + (x * step));
+            } else if(fo_color >= 3) {
+                if((af_dtype) af::dtype_traits<T>::af_type == u8) {
+                    pDst0[indx] = (float) *(src + (x * step + FI_RGBA_RED));
+                    pDst1[indx] = (float) *(src + (x * step + FI_RGBA_GREEN));
+                    pDst2[indx] = (float) *(src + (x * step + FI_RGBA_BLUE));
+                } else {
+                    // Non 8-bit types do not use ordering
+                    // See Pixel Access Functions Chapter in FreeImage Doc
+                    pDst0[indx] = (float) *(src + (x * step + 0));
+                    pDst1[indx] = (float) *(src + (x * step + 1));
+                    pDst2[indx] = (float) *(src + (x * step + 2));
+                }
+                if (fo_color == 4) pDst3[indx] = (float) *(src + (x * step + FI_RGBA_ALPHA));
+            }
             indx++;
         }
     }
@@ -85,12 +93,20 @@ static af_err readImage(af_array *rImage, const uchar* pSrcLine, const int nSrcP
     for (uint x = 0; x < fi_w; ++x) {
         for (uint y = 0; y < fi_h; ++y) {
             const T *src = (T*)(pSrcLine - y * nSrcPitch);
-            if (fo_color == 1) {
-                pDst[indx] = (float) *(src + (x * step));
-            } else if (fo_color >=3) {
-                b = (float) *(src + (x * step + 0));
-                g = (float) *(src + (x * step + 1));
-                r = (float) *(src + (x * step + 2));
+            if(fo_color == 1) {
+                pDst[indx] = (T) *(src + (x * step));
+            } else if(fo_color >= 3) {
+                if((af_dtype) af::dtype_traits<T>::af_type == u8) {
+                    r = (T) *(src + (x * step + FI_RGBA_RED));
+                    g = (T) *(src + (x * step + FI_RGBA_GREEN));
+                    b = (T) *(src + (x * step + FI_RGBA_BLUE));
+                } else {
+                    // Non 8-bit types do not use ordering
+                    // See Pixel Access Functions Chapter in FreeImage Doc
+                    r = (T) *(src + (x * step + 0));
+                    g = (T) *(src + (x * step + 1));
+                    b = (T) *(src + (x * step + 2));
+                }
                 pDst[indx] = r * 0.2989f + g * 0.5870f + b * 0.1140f;
             }
             indx++;
@@ -189,11 +205,11 @@ af_err af_load_image(af_array *out, const char* filename, const bool isColor)
                     AF_CHECK((readImage<float,  AFFI_RGBA, AFFI_RGBA>)(&rImage, pSrcLine, nSrcPitch, fi_w, fi_h));
             } else if (fi_color == 1) {
                 if(fi_bpc == 8)
-                    AF_CHECK((readImage<uchar,  AFFI_GRAY, AFFI_RGBA>)(&rImage, pSrcLine, nSrcPitch, fi_w, fi_h));
+                    AF_CHECK((readImage<uchar,  AFFI_GRAY, AFFI_RGB>)(&rImage, pSrcLine, nSrcPitch, fi_w, fi_h));
                 else if(fi_bpc == 16)
-                    AF_CHECK((readImage<ushort, AFFI_GRAY, AFFI_RGBA>)(&rImage, pSrcLine, nSrcPitch, fi_w, fi_h));
+                    AF_CHECK((readImage<ushort, AFFI_GRAY, AFFI_RGB>)(&rImage, pSrcLine, nSrcPitch, fi_w, fi_h));
                 else if(fi_bpc == 32)
-                    AF_CHECK((readImage<float,  AFFI_GRAY, AFFI_RGBA>)(&rImage, pSrcLine, nSrcPitch, fi_w, fi_h));
+                    AF_CHECK((readImage<float,  AFFI_GRAY, AFFI_RGB>)(&rImage, pSrcLine, nSrcPitch, fi_w, fi_h));
             } else {             //3 channel image
                 if(fi_bpc == 8)
                     AF_CHECK((readImage<uchar,  AFFI_RGB, AFFI_RGB>)(&rImage, pSrcLine, nSrcPitch, fi_w, fi_h));
diff --git a/src/api/c/imageio2.cpp b/src/api/c/imageio2.cpp
index 6075ffc..c40d237 100644
--- a/src/api/c/imageio2.cpp
+++ b/src/api/c/imageio2.cpp
@@ -44,17 +44,28 @@ static af_err readImage_t(af_array *rImage, const uchar* pSrcLine, const int nSr
     T* pDst2 = pDst + (fi_w * fi_h * 2);
     T* pDst3 = pDst + (fi_w * fi_h * 3);
 
-    int offR = 2; int offG = 1; int offB = 0; int offA = 3;
     uint indx = 0;
     uint step = fi_color;
 
     for (uint x = 0; x < fi_w; ++x) {
         for (uint y = 0; y < fi_h; ++y) {
-            const T *src = (T*)(pSrcLine - y * nSrcPitch);
-                               pDst2[indx] = (T) *(src + (x * step + offB));
-            if (fi_color >= 3) pDst1[indx] = (T) *(src + (x * step + offG));
-            if (fi_color >= 3) pDst0[indx] = (T) *(src + (x * step + offR));
-            if (fi_color == 4) pDst3[indx] = (T) *(src + (x * step + offA));
+            const T *src = (T*)((uchar*)pSrcLine - y * nSrcPitch);
+            if(fi_color == 1) {
+                pDst0[indx] = (T) *(src + (x * step));
+            } else if(fi_color >= 3) {
+                if((af_dtype) af::dtype_traits<T>::af_type == u8) {
+                    pDst0[indx] = (T) *(src + (x * step + FI_RGBA_RED));
+                    pDst1[indx] = (T) *(src + (x * step + FI_RGBA_GREEN));
+                    pDst2[indx] = (T) *(src + (x * step + FI_RGBA_BLUE));
+                } else {
+                    // Non 8-bit types do not use ordering
+                    // See Pixel Access Functions Chapter in FreeImage Doc
+                    pDst0[indx] = (T) *(src + (x * step + 0));
+                    pDst1[indx] = (T) *(src + (x * step + 1));
+                    pDst2[indx] = (T) *(src + (x * step + 2));
+                }
+                if (fi_color == 4) pDst3[indx] = (T) *(src + (x * step + FI_RGBA_ALPHA));
+            }
             indx++;
         }
     }
@@ -224,13 +235,21 @@ static void save_t(T* pDstLine, const af_array in, const dim4 dims, uint nDstPit
     for (uint y = 0; y < fi_h; ++y) {
         for (uint x = 0; x < fi_w; ++x) {
             if(channels == 1) {
-                *(pDstLine + x * step + 0) = (T) pSrc0[indx]; // b -> 0
+                *(pDstLine + x * step + FI_RGBA_RED) = (T) pSrc0[indx]; // r -> 0
             } else if(channels >=3) {
-                *(pDstLine + x * step + 0) = (T) pSrc2[indx]; // b -> 0
-                *(pDstLine + x * step + 1) = (T) pSrc1[indx]; // g -> 1
-                *(pDstLine + x * step + 2) = (T) pSrc0[indx]; // r -> 2
+                if((af_dtype) af::dtype_traits<T>::af_type == u8) {
+                    *(pDstLine + x * step + FI_RGBA_BLUE)  = (T) pSrc2[indx]; // b -> 0
+                    *(pDstLine + x * step + FI_RGBA_GREEN) = (T) pSrc1[indx]; // g -> 1
+                    *(pDstLine + x * step + FI_RGBA_RED)   = (T) pSrc0[indx]; // r -> 2
+                } else {
+                    // Non 8-bit types do not use ordering
+                    // See Pixel Access Functions Chapter in FreeImage Doc
+                    *(pDstLine + x * step + 0) = (T) pSrc0[indx]; // r -> 0
+                    *(pDstLine + x * step + 1) = (T) pSrc1[indx]; // g -> 1
+                    *(pDstLine + x * step + 2) = (T) pSrc2[indx]; // b -> 2
+                }
             }
-            if(channels >= 4) *(pDstLine + x * step + 3) = (T) pSrc3[indx]; // a
+            if(channels >= 4) *(pDstLine + x * step + FI_RGBA_ALPHA) = (T) pSrc3[indx]; // a
             ++indx;
         }
         pDstLine = (T*)(((uchar*)pDstLine) - nDstPitch);

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