forked from arrayfire/arrayfire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrotate.cpp
More file actions
88 lines (76 loc) · 3.12 KB
/
rotate.cpp
File metadata and controls
88 lines (76 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*******************************************************
* Copyright (c) 2014, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#include <backend.hpp>
#include <common/ArrayInfo.hpp>
#include <common/err_common.hpp>
#include <handle.hpp>
#include <rotate.hpp>
#include <af/image.h>
#include <cmath>
using af::dim4;
using detail::cdouble;
using detail::cfloat;
using detail::intl;
using detail::uchar;
using detail::uint;
using detail::uintl;
using detail::ushort;
using std::cos;
using std::fabs;
using std::sin;
template<typename T>
static inline af_array rotate(const af_array in, const float theta,
const af::dim4 &odims,
const af_interp_type method) {
return getHandle(rotate<T>(castArray<T>(in), theta, odims, method));
}
af_err af_rotate(af_array *out, const af_array in, const float theta,
const bool crop, const af_interp_type method) {
try {
dim_t odims0 = 0, odims1 = 0;
const ArrayInfo &info = getInfo(in);
af::dim4 idims = info.dims();
if (!crop) {
odims0 = idims[0] * fabs(cos(theta)) + idims[1] * fabs(sin(theta));
odims1 = idims[1] * fabs(cos(theta)) + idims[0] * fabs(sin(theta));
} else {
odims0 = idims[0];
odims1 = idims[1];
}
af_dtype itype = info.getType();
ARG_ASSERT(4, method == AF_INTERP_NEAREST ||
method == AF_INTERP_BILINEAR ||
method == AF_INTERP_BILINEAR_COSINE ||
method == AF_INTERP_BICUBIC ||
method == AF_INTERP_BICUBIC_SPLINE ||
method == AF_INTERP_LOWER);
if (idims.elements() == 0) { return af_retain_array(out, in); }
DIM_ASSERT(1, idims.elements() > 0);
af::dim4 odims(odims0, odims1, idims[2], idims[3]);
af_array output = 0;
switch (itype) {
case f32: output = rotate<float>(in, theta, odims, method); break;
case f64: output = rotate<double>(in, theta, odims, method); break;
case c32: output = rotate<cfloat>(in, theta, odims, method); break;
case c64: output = rotate<cdouble>(in, theta, odims, method); break;
case s32: output = rotate<int>(in, theta, odims, method); break;
case u32: output = rotate<uint>(in, theta, odims, method); break;
case s64: output = rotate<intl>(in, theta, odims, method); break;
case u64: output = rotate<uintl>(in, theta, odims, method); break;
case s16: output = rotate<short>(in, theta, odims, method); break;
case u16: output = rotate<ushort>(in, theta, odims, method); break;
case u8:
case b8: output = rotate<uchar>(in, theta, odims, method); break;
default: TYPE_ERROR(1, itype);
}
std::swap(*out, output);
}
CATCHALL
return AF_SUCCESS;
}