| 51 | namespace { |
| 52 | template<typename T, FI_CHANNELS fi_color> |
| 53 | static af_err readImage_t(af_array* rImage, const uchar* pSrcLine, |
| 54 | const int nSrcPitch, const uint fi_w, |
| 55 | const uint fi_h) { |
| 56 | // create an array to receive the loaded image data. |
| 57 | AF_CHECK(af_init()); |
| 58 | T* pDst = pinnedAlloc<T>(fi_w * fi_h * 4); // 4 channels is max |
| 59 | T* pDst0 = pDst; |
| 60 | T* pDst1 = pDst + (fi_w * fi_h * 1); |
| 61 | T* pDst2 = pDst + (fi_w * fi_h * 2); |
| 62 | T* pDst3 = pDst + (fi_w * fi_h * 3); |
| 63 | |
| 64 | uint indx = 0; |
| 65 | uint step = fi_color; |
| 66 | |
| 67 | for (uint x = 0; x < fi_w; ++x) { |
| 68 | for (uint y = 0; y < fi_h; ++y) { |
| 69 | const T* src = reinterpret_cast<T*>(const_cast<uchar*>(pSrcLine) - |
| 70 | y * nSrcPitch); |
| 71 | if (fi_color == 1) { |
| 72 | pDst0[indx] = *(src + (x * step)); |
| 73 | } else if (fi_color >= 3) { |
| 74 | if (static_cast<af_dtype>(af::dtype_traits<T>::af_type) == u8) { |
| 75 | pDst0[indx] = *(src + (x * step + FI_RGBA_RED)); |
| 76 | pDst1[indx] = *(src + (x * step + FI_RGBA_GREEN)); |
| 77 | pDst2[indx] = *(src + (x * step + FI_RGBA_BLUE)); |
| 78 | if (fi_color == 4) { |
| 79 | pDst3[indx] = *(src + (x * step + FI_RGBA_ALPHA)); |
| 80 | } |
| 81 | } else { |
| 82 | // Non 8-bit types do not use ordering |
| 83 | // See Pixel Access Functions Chapter in FreeImage Doc |
| 84 | pDst0[indx] = *(src + (x * step + 0)); |
| 85 | pDst1[indx] = *(src + (x * step + 1)); |
| 86 | pDst2[indx] = *(src + (x * step + 2)); |
| 87 | if (fi_color == 4) { |
| 88 | pDst3[indx] = *(src + (x * step + 3)); |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | indx++; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | af::dim4 dims(fi_h, fi_w, fi_color, 1); |
| 97 | af_err err = |
| 98 | af_create_array(rImage, pDst, dims.ndims(), dims.get(), |
| 99 | static_cast<af_dtype>(af::dtype_traits<T>::af_type)); |
| 100 | pinnedFree(pDst); |
| 101 | return err; |
| 102 | } |
| 103 | |
| 104 | FREE_IMAGE_TYPE getFIT(FI_CHANNELS channels, af_dtype type) { |
| 105 | if (channels == AFFI_GRAY) { |
nothing calls this directly
no test coverage detected