/*
 * _coder_MLS_applyDeform_api.c
 *
 * Code generation for function '_coder_MLS_applyDeform_api'
 *
 */

/* Include files */
#include "rt_nonfinite.h"
#include "MLS_applyDeform.h"
#include "_coder_MLS_applyDeform_api.h"
#include "MLS_applyDeform_data.h"

/* Variable Definitions */
static const int32_T iv0[3] = { 360, 640, 3 };

/* Function Declarations */
static uint8_T (*b_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u,
  const emlrtMsgIdentifier *parentId))[691200];
static const mxArray *b_emlrt_marshallOut(const real_T u);
static real_T (*c_emlrt_marshallIn(const emlrtStack *sp, const mxArray *f, const
  char_T *identifier))[460800];
static real_T (*d_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
  emlrtMsgIdentifier *parentId))[460800];
static void e_emlrt_marshallIn(const emlrtStack *sp, const mxArray *v, const
  char_T *identifier, real_T **y_data, int32_T y_size[2]);
static uint8_T (*emlrt_marshallIn(const emlrtStack *sp, const mxArray *oldImg,
  const char_T *identifier))[691200];
static const mxArray *emlrt_marshallOut(const uint8_T u[691200]);
static void f_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
  emlrtMsgIdentifier *parentId, real_T **y_data, int32_T y_size[2]);
static real_T (*g_emlrt_marshallIn(const emlrtStack *sp, const mxArray
  *grid_size, const char_T *identifier))[2];
static real_T (*h_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
  emlrtMsgIdentifier *parentId))[2];
static uint8_T (*i_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src,
  const emlrtMsgIdentifier *msgId))[691200];
static real_T (*j_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src,
  const emlrtMsgIdentifier *msgId))[460800];
static void k_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, const
  emlrtMsgIdentifier *msgId, real_T **ret_data, int32_T ret_size[2]);
static real_T (*l_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src,
  const emlrtMsgIdentifier *msgId))[2];

/* Function Definitions */
static uint8_T (*b_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u,
  const emlrtMsgIdentifier *parentId))[691200]
{
  uint8_T (*y)[691200];
  y = i_emlrt_marshallIn(sp, emlrtAlias(u), parentId);
  emlrtDestroyArray(&u);
  return y;
}
  static const mxArray *b_emlrt_marshallOut(const real_T u)
{
  const mxArray *y;
  const mxArray *m1;
  y = NULL;
  m1 = emlrtCreateDoubleScalar(u);
  emlrtAssign(&y, m1);
  return y;
}

static real_T (*c_emlrt_marshallIn(const emlrtStack *sp, const mxArray *f, const
  char_T *identifier))[460800]
{
  real_T (*y)[460800];
  emlrtMsgIdentifier thisId;
  thisId.fIdentifier = (const char *)identifier;
  thisId.fParent = NULL;
  thisId.bParentIsCell = false;
  y = d_emlrt_marshallIn(sp, emlrtAlias(f), &thisId);
  emlrtDestroyArray(&f);
  return y;
}
  static real_T (*d_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u,
  const emlrtMsgIdentifier *parentId))[460800]
{
  real_T (*y)[460800];
  y = j_emlrt_marshallIn(sp, emlrtAlias(u), parentId);
  emlrtDestroyArray(&u);
  return y;
}

static void e_emlrt_marshallIn(const emlrtStack *sp, const mxArray *v, const
  char_T *identifier, real_T **y_data, int32_T y_size[2])
{
  emlrtMsgIdentifier thisId;
  real_T *r0;
  thisId.fIdentifier = (const char *)identifier;
  thisId.fParent = NULL;
  thisId.bParentIsCell = false;
  f_emlrt_marshallIn(sp, emlrtAlias(v), &thisId, &r0, y_size);
  *y_data = r0;
  emlrtDestroyArray(&v);
}

static uint8_T (*emlrt_marshallIn(const emlrtStack *sp, const mxArray *oldImg,
  const char_T *identifier))[691200]
{
  uint8_T (*y)[691200];
  emlrtMsgIdentifier thisId;
  thisId.fIdentifier = (const char *)identifier;
  thisId.fParent = NULL;
  thisId.bParentIsCell = false;
  y = b_emlrt_marshallIn(sp, emlrtAlias(oldImg), &thisId);
  emlrtDestroyArray(&oldImg);
  return y;
}
  static const mxArray *emlrt_marshallOut(const uint8_T u[691200])
{
  const mxArray *y;
  const mxArray *m0;
  static const int32_T iv1[3] = { 0, 0, 0 };

  y = NULL;
  m0 = emlrtCreateNumericArray(3, iv1, mxUINT8_CLASS, mxREAL);
  emlrtMxSetData((mxArray *)m0, (void *)&u[0]);
  emlrtSetDimensions((mxArray *)m0, iv0, 3);
  emlrtAssign(&y, m0);
  return y;
}

static void f_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
  emlrtMsgIdentifier *parentId, real_T **y_data, int32_T y_size[2])
{
  real_T *r1;
  k_emlrt_marshallIn(sp, emlrtAlias(u), parentId, &r1, y_size);
  *y_data = r1;
  emlrtDestroyArray(&u);
}

static real_T (*g_emlrt_marshallIn(const emlrtStack *sp, const mxArray
  *grid_size, const char_T *identifier))[2]
{
  real_T (*y)[2];
  emlrtMsgIdentifier thisId;
  thisId.fIdentifier = (const char *)identifier;
  thisId.fParent = NULL;
  thisId.bParentIsCell = false;
  y = h_emlrt_marshallIn(sp, emlrtAlias(grid_size), &thisId);
  emlrtDestroyArray(&grid_size);
  return y;
}
  static real_T (*h_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u,
  const emlrtMsgIdentifier *parentId))[2]
{
  real_T (*y)[2];
  y = l_emlrt_marshallIn(sp, emlrtAlias(u), parentId);
  emlrtDestroyArray(&u);
  return y;
}

static uint8_T (*i_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src,
  const emlrtMsgIdentifier *msgId))[691200]
{
  uint8_T (*ret)[691200];
  emlrtCheckBuiltInR2012b(sp, msgId, src, "uint8", false, 3U, iv0);
  ret = (uint8_T (*)[691200])emlrtMxGetData(src);
  emlrtDestroyArray(&src);
  return ret;
}
  static real_T (*j_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src,
  const emlrtMsgIdentifier *msgId))[460800]
{
  real_T (*ret)[460800];
  static const int32_T dims[3] = { 360, 640, 2 };

  emlrtCheckBuiltInR2012b(sp, msgId, src, "double", false, 3U, dims);
  ret = (real_T (*)[460800])emlrtMxGetData(src);
  emlrtDestroyArray(&src);
  return ret;
}

static void k_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, const
  emlrtMsgIdentifier *msgId, real_T **ret_data, int32_T ret_size[2])
{
  static const int32_T dims[2] = { 2405, 2 };

  const boolean_T bv0[2] = { true, true };

  int32_T iv2[2];
  emlrtCheckVsBuiltInR2012b(sp, msgId, src, "double", false, 2U, dims, &bv0[0],
    iv2);
  ret_size[0] = iv2[0];
  ret_size[1] = iv2[1];
  *ret_data = (real_T *)emlrtMxGetData(src);
  emlrtDestroyArray(&src);
}

static real_T (*l_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src,
  const emlrtMsgIdentifier *msgId))[2]
{
  real_T (*ret)[2];
  static const int32_T dims[2] = { 1, 2 };

  emlrtCheckBuiltInR2012b(sp, msgId, src, "double", false, 2U, dims);
  ret = (real_T (*)[2])emlrtMxGetData(src);
  emlrtDestroyArray(&src);
  return ret;
}
  void MLS_applyDeform_api(const mxArray * const prhs[4], const mxArray *plhs[2])
{
  uint8_T (*newImg)[691200];
  uint8_T (*oldImg)[691200];
  real_T (*f)[460800];
  real_T (*v_data)[4810];
  int32_T v_size[2];
  real_T (*grid_size)[2];
  real_T finterp;
  emlrtStack st = { NULL,              /* site */
    NULL,                              /* tls */
    NULL                               /* prev */
  };

  st.tls = emlrtRootTLSGlobal;
  newImg = (uint8_T (*)[691200])mxMalloc(sizeof(uint8_T [691200]));

  /* Marshall function inputs */
  oldImg = emlrt_marshallIn(&st, emlrtAlias(prhs[0]), "oldImg");
  f = c_emlrt_marshallIn(&st, emlrtAlias(prhs[1]), "f");
  e_emlrt_marshallIn(&st, emlrtAlias(prhs[2]), "v", (real_T **)&v_data, v_size);
  grid_size = g_emlrt_marshallIn(&st, emlrtAlias(prhs[3]), "grid_size");

  /* Invoke the target function */
  MLS_applyDeform(&st, *oldImg, *f, *v_data, v_size, *grid_size, *newImg,
                  &finterp);

  /* Marshall function outputs */
  plhs[0] = emlrt_marshallOut(*newImg);
  plhs[1] = b_emlrt_marshallOut(finterp);
}

/* End of code generation (_coder_MLS_applyDeform_api.c) */
