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

Function save_t

src/api/c/imageio2.cpp:330–407  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

328
329template<typename T, FI_CHANNELS channels>
330static void save_t(T* pDstLine, const af_array in, const dim4& dims,
331 uint nDstPitch) {
332 af_array rr = 0, gg = 0, bb = 0, aa = 0;
333 AF_CHECK(channel_split(in, dims, &rr, &gg, &bb,
334 &aa)); // convert array to 3 channels if needed
335
336 af_array rrT = 0, ggT = 0, bbT = 0, aaT = 0;
337 T *pSrc0 = 0, *pSrc1 = 0, *pSrc2 = 0, *pSrc3 = 0;
338
339 uint step = channels; // force 3 channels saving
340 uint indx = 0;
341
342 AF_CHECK(af_transpose(&rrT, rr, false));
343 if (channels >= 3) { AF_CHECK(af_transpose(&ggT, gg, false)); }
344 if (channels >= 3) { AF_CHECK(af_transpose(&bbT, bb, false)); }
345 if (channels >= 4) { AF_CHECK(af_transpose(&aaT, aa, false)); }
346
347 const ArrayInfo& cinfo = getInfo(rrT);
348 pSrc0 = pinnedAlloc<T>(cinfo.elements());
349 if (channels >= 3) { pSrc1 = pinnedAlloc<T>(cinfo.elements()); }
350 if (channels >= 3) { pSrc2 = pinnedAlloc<T>(cinfo.elements()); }
351 if (channels >= 4) { pSrc3 = pinnedAlloc<T>(cinfo.elements()); }
352
353 AF_CHECK(af_get_data_ptr((void*)pSrc0, rrT));
354 if (channels >= 3) { AF_CHECK(af_get_data_ptr((void*)pSrc1, ggT)); }
355 if (channels >= 3) { AF_CHECK(af_get_data_ptr((void*)pSrc2, bbT)); }
356 if (channels >= 4) { AF_CHECK(af_get_data_ptr((void*)pSrc3, aaT)); }
357
358 const uint fi_w = dims[1];
359 const uint fi_h = dims[0];
360
361 // Copy the array into FreeImage buffer
362 for (uint y = 0; y < fi_h; ++y) {
363 for (uint x = 0; x < fi_w; ++x) {
364 if (channels == 1) {
365 *(pDstLine + x * step) = pSrc0[indx]; // r -> 0
366 } else if (channels >= 3) {
367 if (static_cast<af_dtype>(af::dtype_traits<T>::af_type) == u8) {
368 *(pDstLine + x * step + FI_RGBA_RED) =
369 pSrc0[indx]; // r -> 0
370 *(pDstLine + x * step + FI_RGBA_GREEN) =
371 pSrc1[indx]; // g -> 1
372 *(pDstLine + x * step + FI_RGBA_BLUE) =
373 pSrc2[indx]; // b -> 2
374 if (channels >= 4) {
375 *(pDstLine + x * step + FI_RGBA_ALPHA) =
376 pSrc3[indx]; // a
377 }
378 } else {
379 // Non 8-bit types do not use ordering
380 // See Pixel Access Functions Chapter in FreeImage Doc
381 *(pDstLine + x * step + 0) = pSrc0[indx]; // r -> 0
382 *(pDstLine + x * step + 1) = pSrc1[indx]; // g -> 1
383 *(pDstLine + x * step + 2) = pSrc2[indx]; // b -> 2
384 if (channels >= 4) {
385 *(pDstLine + x * step + 3) = pSrc3[indx]; // a
386 }
387 }

Callers

nothing calls this directly

Calls 6

channel_splitFunction · 0.70
af_transposeFunction · 0.70
af_get_data_ptrFunction · 0.70
af_release_arrayFunction · 0.70
pinnedFreeFunction · 0.50
elementsMethod · 0.45

Tested by

no test coverage detected