MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / readImage

Function readImage

src/api/c/imageio.cpp:59–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

57
58template<typename T, FI_CHANNELS fi_color, FI_CHANNELS fo_color>
59static af_err readImage(af_array* rImage, const uchar* pSrcLine,
60 const int nSrcPitch, const uint fi_w, const uint fi_h) {
61 // create an array to receive the loaded image data.
62 AF_CHECK(af_init());
63 auto* pDst = pinnedAlloc<float>(fi_w * fi_h * 4); // 4 channels is max
64 float* pDst0 = pDst;
65 float* pDst1 = pDst + (fi_w * fi_h * 1);
66 float* pDst2 = pDst + (fi_w * fi_h * 2);
67 float* pDst3 = pDst + (fi_w * fi_h * 3);
68
69 uint indx = 0;
70 uint step = fi_color;
71
72 for (uint x = 0; x < fi_w; ++x) {
73 for (uint y = 0; y < fi_h; ++y) {
74 const T* src = reinterpret_cast<const T*>(pSrcLine - y * nSrcPitch);
75 if (fo_color == 1) {
76 pDst0[indx] = static_cast<T>(*(src + (x * step)));
77 } else if (fo_color >= 3) {
78 if (static_cast<af_dtype>(af::dtype_traits<T>::af_type) == u8) {
79 pDst0[indx] =
80 static_cast<float>(*(src + (x * step + FI_RGBA_RED)));
81 pDst1[indx] =
82 static_cast<float>(*(src + (x * step + FI_RGBA_GREEN)));
83 pDst2[indx] =
84 static_cast<float>(*(src + (x * step + FI_RGBA_BLUE)));
85 if (fo_color == 4) {
86 pDst3[indx] = static_cast<float>(
87 *(src + (x * step + FI_RGBA_ALPHA)));
88 }
89 } else {
90 // Non 8-bit types do not use ordering
91 // See Pixel Access Functions Chapter in FreeImage Doc
92 pDst0[indx] = static_cast<float>(*(src + (x * step + 0)));
93 pDst1[indx] = static_cast<float>(*(src + (x * step + 1)));
94 pDst2[indx] = static_cast<float>(*(src + (x * step + 2)));
95 if (fo_color == 4) {
96 pDst3[indx] =
97 static_cast<float>(*(src + (x * step + 3)));
98 }
99 }
100 }
101 indx++;
102 }
103 }
104
105 af::dim4 dims(fi_h, fi_w, fo_color, 1);
106 af_err err = af_create_array(rImage, pDst, dims.ndims(), dims.get(),
107 (af_dtype)af::dtype_traits<float>::af_type);
108 pinnedFree(pDst);
109 return err;
110}
111
112#ifdef FREEIMAGE_STATIC
113// NOTE: Redefine the MODULE_FUNCTION_INIT macro to call the static functions

Callers

nothing calls this directly

Calls 5

af_initFunction · 0.70
af_create_arrayFunction · 0.70
pinnedFreeFunction · 0.50
ndimsMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected