| 36 | } |
| 37 | |
| 38 | af_err af_rotate(af_array *out, const af_array in, const float theta, |
| 39 | const bool crop, const af_interp_type method) { |
| 40 | try { |
| 41 | dim_t odims0 = 0, odims1 = 0; |
| 42 | |
| 43 | const ArrayInfo &info = getInfo(in); |
| 44 | af::dim4 idims = info.dims(); |
| 45 | |
| 46 | if (!crop) { |
| 47 | odims0 = idims[0] * fabs(cos(theta)) + idims[1] * fabs(sin(theta)); |
| 48 | odims1 = idims[1] * fabs(cos(theta)) + idims[0] * fabs(sin(theta)); |
| 49 | } else { |
| 50 | odims0 = idims[0]; |
| 51 | odims1 = idims[1]; |
| 52 | } |
| 53 | |
| 54 | af_dtype itype = info.getType(); |
| 55 | |
| 56 | ARG_ASSERT(4, method == AF_INTERP_NEAREST || |
| 57 | method == AF_INTERP_BILINEAR || |
| 58 | method == AF_INTERP_BILINEAR_COSINE || |
| 59 | method == AF_INTERP_BICUBIC || |
| 60 | method == AF_INTERP_BICUBIC_SPLINE || |
| 61 | method == AF_INTERP_LOWER); |
| 62 | |
| 63 | if (idims.elements() == 0) { return af_retain_array(out, in); } |
| 64 | DIM_ASSERT(1, idims.elements() > 0); |
| 65 | |
| 66 | af::dim4 odims(odims0, odims1, idims[2], idims[3]); |
| 67 | |
| 68 | af_array output = 0; |
| 69 | switch (itype) { |
| 70 | case f32: output = rotate<float>(in, theta, odims, method); break; |
| 71 | case f64: output = rotate<double>(in, theta, odims, method); break; |
| 72 | case c32: output = rotate<cfloat>(in, theta, odims, method); break; |
| 73 | case c64: output = rotate<cdouble>(in, theta, odims, method); break; |
| 74 | case s32: output = rotate<int>(in, theta, odims, method); break; |
| 75 | case u32: output = rotate<uint>(in, theta, odims, method); break; |
| 76 | case s64: output = rotate<intl>(in, theta, odims, method); break; |
| 77 | case u64: output = rotate<uintl>(in, theta, odims, method); break; |
| 78 | case s16: output = rotate<short>(in, theta, odims, method); break; |
| 79 | case u16: output = rotate<ushort>(in, theta, odims, method); break; |
| 80 | case s8: output = rotate<schar>(in, theta, odims, method); break; |
| 81 | case u8: |
| 82 | case b8: output = rotate<uchar>(in, theta, odims, method); break; |
| 83 | default: TYPE_ERROR(1, itype); |
| 84 | } |
| 85 | std::swap(*out, output); |
| 86 | } |
| 87 | CATCHALL |
| 88 | |
| 89 | return AF_SUCCESS; |
| 90 | } |
no test coverage detected