#include "imresize.h"
#include <math.h>
/* Function Declarations */
static void b_bsxfun(const emxArray_real_T *a, const emxArray_real_T *b,
emxArray_real_T *c);
static void bsxfun(const emxArray_int32_T *a, const emxArray_int32_T *b,
emxArray_int32_T *c);
static void contributions(int in_length, double out_length, double scale, double
kernel_width, emxArray_real_T *weights, emxArray_int32_T *indices);
static void sort(double x[2], int idx[2]);
static void b_bsxfun(const emxArray_real_T *a, const emxArray_real_T *b,
emxArray_real_T *c)
{
int csz_idx_0;
int csz_idx_1;
int i5;
int varargin_3;
int acoef;
int bcoef;
int i6;
int k;
csz_idx_0 = b->size[0];
csz_idx_1 = a->size[0];
if (csz_idx_0 < csz_idx_1) {
csz_idx_1 = csz_idx_0;
}
if (b->size[0] == 1) {
csz_idx_0 = a->size[0];
}
else if (a->size[0] == 1) {
csz_idx_0 = b->size[0];
}
else if (a->size[0] == b->size[0]) {
csz_idx_0 = a->size[0];
}
else {
csz_idx_0 = csz_idx_1;
}
csz_idx_1 = b->size[1];
i5 = c->size[0] * c->size[1];
c->size[0] = csz_idx_0;
c->size[1] = csz_idx_1;
emxEnsureCapacity_real_T(c, i5);
if ((c->size[0] != 0) && (c->size[1] != 0)) {
csz_idx_0 = (b->size[1] != 1);
i5 = c->size[1] - 1;
for (csz_idx_1 = 0; csz_idx_1 <= i5; csz_idx_1++) {
varargin_3 = csz_idx_0 * csz_idx_1;
acoef = (a->size[0] != 1);
bcoef = (b->size[0] != 1);
i6 = c->size[0] - 1;
for (k = 0; k <= i6; k++) {
c->data[k + c->size[0] * csz_idx_1] = a->data[acoef * k] - b->data[bcoef
* k + b->size[0] * varargin_3];
}
}
}
}
static void bsxfun(const emxArray_int32_T *a, const emxArray_int32_T *b,
emxArray_int32_T *c)
{
int csz_idx_0;
int csz_idx_1;
int i3;
int varargin_3;
int acoef;
int i4;
int k;
csz_idx_0 = a->size[0];
csz_idx_1 = b->size[1];
i3 = c->size[0] * c->size[1];
c->size[0] = csz_idx_0;
c->size[1] = csz_idx_1;
emxEnsureCapacity_int32_T(c, i3);
if ((c->size[0] != 0) && (c->size[1] != 0)) {
csz_idx_0 = (b->size[1] != 1);
i3 = c->size[1] - 1;
for (csz_idx_1 = 0; csz_idx_1 <= i3; csz_idx_1++) {
varargin_3 = csz_idx_0 * csz_idx_1;
acoef = (a->size[0] != 1);
i4 = c->size[0] - 1;
for (k = 0; k <= i4; k++) {
c->data[k + c->size[0] * csz_idx_1] = a->data[acoef * k] + b->
data[varargin_3];
}
}
}
}
static void contributions(int in_length, double out_length, double scale, double
kernel_width, emxArray_real_T *weights, emxArray_int32_T *indices)
{
emxArray_real_T *y;
int i2;
int nx;
emxArray_real_T *u;
double k;
emxArray_real_T *x;
int b_k;
emxArray_int32_T *b_y;
emxArray_int32_T *b_x;
int yk;
emxArray_real_T *absx;
emxArray_real_T *c_x;
int i;
unsigned int sz_idx_0;
unsigned int sz_idx_1;
int vlen;
int vstride;
int aux_data[3096];
int c_k;
emxArray_boolean_T *copyCols;
emxArray_int32_T *r0;
boolean_T exitg1;
boolean_T b0;
emxArray_int32_T *r1;
emxArray_int32_T *b_indices;
/* Contributions, using pixel indices */
if (scale < 1.0) {
kernel_width = 4.0 / scale;
}
emxInit_real_T(&y, 2);
if (out_length < 1.0) {
y->size[0] = 1;
y->size[1] = 0;
}
else {
i2 = y->size[0] * y->size[1];
y->size[0] = 1;
nx = (int)floor(out_length - 1.0);
y->size[1] = nx + 1;
emxEnsureCapacity_real_T(y, i2);
for (i2 = 0; i2 <= nx; i2++) {
y->data[i2] = 1.0 + (double)i2;
}
}
emxInit_real_T(&u, 1);
k = 0.5 * (1.0 - 1.0 / scale);
i2 = u->size[0];
u->size[0] = y->size[1];
emxEnsureCapacity_real_T(u, i2);
nx = y->size[1];
for (i2 = 0; i2 < nx; i2++) {
u->data[i2] = y->data[i2] / scale + k;
}
emxFree_real_T(&y);
emxInit_real_T(&x, 1);
k = kernel_width / 2.0;
i2 = x->size[0];
x->size[0] = u->size[0];
emxEnsureCapacity_real_T(x, i2);
nx = u->size[0];
for (i2 = 0; i2 < nx; i2++) {
x->data[i2] = u->data[i2] - k;
}
nx = x->size[0];
for (b_k = 0; b_k < nx; b_k++) {
x->data[b_k] = floor(x->data[b_k]);
}
emxInit_int32_T(&b_y, 2);
nx = (int)(ceil(kernel_width) + 2.0);
if (nx - 1 < 0) {
nx = 0;
}
i2 = b_y->size[0] * b_y->size[1];
b_y->size[0] = 1;
b_y->size[1] = nx;
emxEnsureCapacity_int32_T(b_y, i2);
if (nx > 0) {
b_y->data[0] = 0;
yk = 0;
for (b_k = 2; b_k <= nx; b_k++) {
yk++;
b_y->data[b_k - 1] = yk;
}
}
emxInit_int32_T(&b_x, 1);
i2 = b_x->size[0];
b_x->size[0] = x->size[0];
emxEnsureCapacity_int32_T(b_x, i2);
nx = x->size[0];
for (i2 = 0; i2 < nx; i2++) {
b_x->data[i2] = (int)x->data[i2];
}
emxFree_real_T(&x);
emxInit_real_T(&absx, 2);
bsxfun(b_x, b_y, indices);
i2 = absx->size[0] * absx->size[1];
absx->size[0] = indices->size[0];
absx->size[1] = indices->size[1];
emxEnsureCapacity_real_T(absx, i2);
nx = indices->size[0] * indices->size[1];
emxFree_int32_T(&b_x);
emxFree_int32_T(&b_y);
for (i2 = 0; i2 < nx; i2++) {
absx->data[i2] = indices->data[i2];
}
emxInit_real_T(&c_x, 2);
b_bsxfun(u, absx, c_x);
if (scale < 1.0) {
i2 = c_x->size[0] * c_x->size[1];
i = c_x->size[0] * c_x->size[1];
emxEnsureCapacity_real_T(c_x, i);
nx = i2 - 1;
for (i2 = 0; i2 <= nx; i2++) {
c_x->data[i2] *= scale;
}
}
nx = c_x->size[0] * c_x->size[1];
sz_idx_0 = (unsigned int)c_x->size[0];
sz_idx_1 = (unsigned int)c_x->size[1];
i2 = absx->size[0] * absx->size[1];
absx->size[0] = (int)sz_idx_0;
absx->size[1] = (int)sz_idx_1;
emxEnsureCapacity_real_T(absx, i2);
for (b_k = 0; b_k < nx; b_k++) {
absx->data[b_k] = fabs(c_x->data[b_k]);
}
sz_idx_0 = (unsigned int)absx->size[0];
sz_idx_1 = (unsigned int)absx->size[1];
i2 = c_x->size[0] * c_x->size[1];
c_x->size[0] = (int)sz_idx_0;
c_x->size[1] = (int)sz_idx_1;
emxEnsureCapacity_real_T(c_x, i2);
nx = (int)sz_idx_0 * (int)sz_idx_1;
for (b_k = 0; b_k < nx; b_k++) {
c_x->data[b_k] = absx->data[b_k] * absx->data[b_k];
}
sz_idx_0 = (unsigned int)absx->size[0];
sz_idx_1 = (unsigned int)absx->size[1];
i2 = weights->size[0] * weights->size[1];
weights->size[0] = (int)sz_idx_0;
weights->size[1] = (int)sz_idx_1;
emxEnsureCapacity_real_T(weights, i2);
nx = (int)sz_idx_0 * (int)sz_idx_1;
for (b_k = 0; b_k < nx; b_k++) {
weights->data[b_k] = pow(absx->data[b_k], 3.0);
}
i2 = weights->size[0] * weights->size[1];
i = weights->size[0] * weights->size[1];
emxEnsureCapacity_real_T(weights, i);
nx = i2 - 1;
for (i2 = 0; i2 <= nx; i2++) {
weights->data[i2] = ((1.5 * weights->data[i2] - 2.5 * c_x->data[i2]) + 1.0) *
(double)(absx->data[i2] <= 1.0) + (((-0.5 * weights->data[i2] + 2.5 *
c_x->data[i2]) - 4.0 * absx->data[i2]) + 2.0) * (double)((1.0 < absx->
data[i2]) && (absx->data[i2] <= 2.0));
}
if (scale < 1.0) {
i2 = weights->size[0] * weights->size[1];
i = weights->size[0] * weights->size[1];
emxEnsureCapacity_real_T(weights, i);
nx = i2 - 1;
for (i2 = 0; i2 <= nx; i2++) {
weights->data[i2] *= scale;
}
}
vlen = weights->size[1];
if ((weights->size[0] == 0) || (weights->size[1] == 0)) {
sz_idx_0 = (unsigned int)weights->size[0];
i2 = u->size[0];
u->size[0] = (int)sz_idx_0;
emxEnsureCapacity_real_T(u, i2);
nx = (int)sz_idx_0;
for (i2 = 0; i2 < nx; i2++) {
u->data[i2] = 0.0;
}
}
else {
vstride = weights->size[0];
i2 = u->size[0];
u->size[0] = weights->size[0];
emxEnsureCapacity_real_T(u, i2);
for (nx = 0; nx < vstride; nx++) {
u->data[nx] = weights->data[nx];
}
for (b_k = 2; b_k <= vlen; b_k++) {
yk = (b_k - 1) * vstride;
for (nx = 0; nx < vstride; nx++) {
u->data[nx] += weights->data[yk + nx];
}
}
}
i2 = c_x->size[0] * c_x->size[1];
c_x->size[0] = weights->size[0];
c_x->size[1] = weights->size[1];
emxEnsureCapacity_real_T(c_x, i2);
nx = weights->size[0] * weights->size[1];
for (i2 = 0; i2 < nx; i2++) {
c_x->data[i2] = weights->data[i2];
}
n