Skip to content

Commit

Permalink
fix image loading for s8 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
verstatx committed Oct 6, 2023
1 parent 2816713 commit 1fd7f20
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/api/c/imageio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static af_err readImage(af_array* rImage, const uchar* pSrcLine,
if (fo_color == 1) {
pDst0[indx] = static_cast<T>(*(src + (x * step)));
} else if (fo_color >= 3) {
if (static_cast<af_dtype>(af::dtype_traits<T>::af_type) == u8) { // FIXME s8?
if (static_cast<af_dtype>(af::dtype_traits<T>::af_type) == u8) {
pDst0[indx] =
static_cast<float>(*(src + (x * step + FI_RGBA_RED)));
pDst1[indx] =
Expand Down Expand Up @@ -201,7 +201,7 @@ static af_err readImage(af_array* rImage, const uchar* pSrcLine,
if (fo_color == 1) {
pDst[indx] = static_cast<T>(*(src + (x * step)));
} else if (fo_color >= 3) {
if (static_cast<af_dtype>(af::dtype_traits<T>::af_type) == u8) { // FIXME s8?
if (static_cast<af_dtype>(af::dtype_traits<T>::af_type) == u8) {
r = *(src + (x * step + FI_RGBA_RED));
g = *(src + (x * step + FI_RGBA_GREEN));
b = *(src + (x * step + FI_RGBA_BLUE));
Expand Down
5 changes: 2 additions & 3 deletions src/api/c/imageio2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static af_err readImage_t(af_array* rImage, const uchar* pSrcLine,
if (fi_color == 1) {
pDst0[indx] = *(src + (x * step));
} else if (fi_color >= 3) {
if (static_cast<af_dtype>(af::dtype_traits<T>::af_type) == u8) { // FIXME s8?
if (static_cast<af_dtype>(af::dtype_traits<T>::af_type) == u8) {
pDst0[indx] = *(src + (x * step + FI_RGBA_RED));
pDst1[indx] = *(src + (x * step + FI_RGBA_GREEN));
pDst2[indx] = *(src + (x * step + FI_RGBA_BLUE));
Expand Down Expand Up @@ -102,7 +102,6 @@ static af_err readImage_t(af_array* rImage, const uchar* pSrcLine,
}

FREE_IMAGE_TYPE getFIT(FI_CHANNELS channels, af_dtype type) {
// FIXME s8?
if (channels == AFFI_GRAY) {
if (type == u8) { return FIT_BITMAP; }
if (type == u16) {
Expand Down Expand Up @@ -365,7 +364,7 @@ static void save_t(T* pDstLine, const af_array in, const dim4& dims,
if (channels == 1) {
*(pDstLine + x * step) = pSrc0[indx]; // r -> 0
} else if (channels >= 3) {
if (static_cast<af_dtype>(af::dtype_traits<T>::af_type) == u8) { // FIXME s8?
if (static_cast<af_dtype>(af::dtype_traits<T>::af_type) == u8) {
*(pDstLine + x * step + FI_RGBA_RED) =
pSrc0[indx]; // r -> 0
*(pDstLine + x * step + FI_RGBA_GREEN) =
Expand Down
7 changes: 6 additions & 1 deletion test/arrayfire_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,12 @@ af_err conv_image(af_array *out, af_array in) {

T *out_data = new T[nElems];

for (int i = 0; i < (int)nElems; i++) out_data[i] = (T)in_data[i];
float s8_offset = 0;
if ((af_dtype)af::dtype_traits<T>::af_type == s8) {
s8_offset = -128.f;
}

for (int i = 0; i < (int)nElems; i++) out_data[i] = (T)(in_data[i] + s8_offset);

af_create_array(&outArray, out_data, idims.ndims(), idims.get(),
(af_dtype)af::dtype_traits<T>::af_type);
Expand Down

0 comments on commit 1fd7f20

Please sign in to comment.