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

Function gray2rgb

src/api/c/rgb_gray.cpp:75–105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73
74template<typename T, typename cType>
75static af_array gray2rgb(const af_array& in, const float r, const float g,
76 const float b) {
77 if (r == 1.0 && g == 1.0 && b == 1.0) {
78 dim4 tileDims(1, 1, 3, 1);
79 return getHandle(arrayfire::common::tile(getArray<T>(in), tileDims));
80 }
81
82 af_array mod_input = 0;
83 dim4 inputDims = getInfo(in).dims();
84
85 dim4 matDims(inputDims[0], inputDims[1], 1, inputDims[2] * inputDims[3]);
86
87 AF_CHECK(af_moddims(&mod_input, in, matDims.ndims(), matDims.get()));
88 Array<cType> mod_in = cast<cType>(getArray<cType>(mod_input));
89
90 Array<cType> rCnst = createValueArray<cType>(matDims, scalar<cType>(r));
91 Array<cType> gCnst = createValueArray<cType>(matDims, scalar<cType>(g));
92 Array<cType> bCnst = createValueArray<cType>(matDims, scalar<cType>(b));
93
94 Array<cType> expr1 = arithOp<cType, af_mul_t>(mod_in, rCnst, matDims);
95 Array<cType> expr2 = arithOp<cType, af_mul_t>(mod_in, gCnst, matDims);
96 Array<cType> expr3 = arithOp<cType, af_mul_t>(mod_in, bCnst, matDims);
97
98 AF_CHECK(af_release_array(mod_input));
99
100 // join channels
101 dim4 odims(expr1.dims()[0], expr1.dims()[1], 3);
102 Array<cType> out = createEmptyArray<cType>(odims);
103 join<cType>(out, 2, {expr3, expr1, expr2});
104 return getHandle(out);
105}
106
107template<typename T, typename cType, bool isRGB2GRAY>
108static af_array convert(const af_array& in, const float r, const float g,

Callers 2

TESTFunction · 0.50
gray_rgb.cppFile · 0.50

Calls 7

getHandleFunction · 0.70
tileFunction · 0.70
af_moddimsFunction · 0.70
af_release_arrayFunction · 0.70
dimsMethod · 0.45
ndimsMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected