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
76 lines (63 loc) · 2.74 KB
/
rotate.cpp
File metadata and controls
76 lines (63 loc) · 2.74 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
/*******************************************************
* 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 <af/image.h>
#include <err_common.hpp>
#include <handle.hpp>
#include <ArrayInfo.hpp>
#include <backend.hpp>
#include <rotate.hpp>
using af::dim4;
using namespace detail;
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>(getArray<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 {
unsigned odims0 = 0, odims1 = 0;
ArrayInfo info = getInfo(in);
af::dim4 idims = info.dims();
if(!crop) {
odims0 = idims[0] * fabs(std::cos(theta)) + idims[1] * fabs(std::sin(theta));
odims1 = idims[1] * fabs(std::cos(theta)) + idims[0] * fabs(std::sin(theta));
} else {
odims0 = idims[0];
odims1 = idims[1];
}
af_dtype itype = info.getType();
ARG_ASSERT(3, method == AF_INTERP_NEAREST ||
method == AF_INTERP_BILINEAR ||
method == AF_INTERP_LOWER);
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: output = rotate<uchar >(in, theta, odims, method); break;
case b8: output = rotate<uchar >(in, theta, odims, method); break;
default: TYPE_ERROR(1, itype);
}
std::swap(*out,output);
} CATCHALL
return AF_SUCCESS;
}