1/*---------------------------------------------------------------------------*
2 *  imeld_tr.c  *
3 *                                                                           *
4 *  Copyright 2007, 2008 Nuance Communciations, Inc.                               *
5 *                                                                           *
6 *  Licensed under the Apache License, Version 2.0 (the 'License');          *
7 *  you may not use this file except in compliance with the License.         *
8 *                                                                           *
9 *  You may obtain a copy of the License at                                  *
10 *      http://www.apache.org/licenses/LICENSE-2.0                           *
11 *                                                                           *
12 *  Unless required by applicable law or agreed to in writing, software      *
13 *  distributed under the License is distributed on an 'AS IS' BASIS,        *
14 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
15 *  See the License for the specific language governing permissions and      *
16 *  limitations under the License.                                           *
17 *                                                                           *
18 *---------------------------------------------------------------------------*/
19
20
21#ifndef _RTT
22#include <stdio.h>
23#endif
24#include <stdlib.h>
25#include <math.h>
26#include <string.h>
27#ifdef unix
28#include <limits.h>
29#endif
30#include <assert.h>
31
32#include "prelib.h"
33#include "portable.h"
34
35#include "../cfront/sh_down.h"
36
37
38static const char imeld_tr[] = "$Id: imeld_tr.c,v 1.2.10.10 2008/04/01 18:23:20 dahan Exp $";
39
40void linear_transform_frame(preprocessed *prep, imeldata *fram, int do_shift)
41/*
42**  Note the matrix is the transpose of the transformation
43**  To transform a single frame in place */
44{
45  int      ii, jj;
46  imeldata vec[MAX_DIMEN];
47  int dim = prep->dim;
48
49  ASSERT(prep);
50  ASSERT(prep->dim < MAX_DIMEN);
51  ASSERT(fram);
52  for (ii = 0; ii < dim; ii++)
53  {
54    vec[ii] = 0;
55    for (jj = 0; jj < prep->dim; jj++)
56      vec[ii] += prep->matrix[ii][jj] * fram[jj];
57    ASSERT(prep->imel_shift > 0);
58    vec[ii] = (imeldata) SHIFT_DOWN((int)vec[ii],
59                                    (unsigned int)prep->imel_shift);
60  }
61
62  if (do_shift)
63  {
64    if (prep->offset)
65      for (ii = 0; ii < dim; ii++)
66        fram[ii] = RANGE(vec[ii] + prep->offset[ii], 0, 255);
67    else
68      for (ii = 0; ii < dim; ii++)
69        fram[ii] = RANGE(vec[ii], 0, 255);
70  }
71  else
72  {
73    for (ii = 0; ii < dim; ii++)
74      fram[ii] = vec[ii];
75  }
76  return;
77}
78
79void inverse_transform_frame (preprocessed *prep, imeldata *fram, int do_shift)
80/*
81**  Note the matrix is the transpose of the transformation
82**  To transform a single frame in place */
83{
84    int	     ii, jj;
85    imeldata vec[MAX_DIMEN];
86
87    ASSERT (prep);
88    ASSERT (prep->dim < MAX_DIMEN);
89    ASSERT (fram);
90
91    if (prep->offset && do_shift)
92	for (ii= 0; ii < prep->dim; ii++)
93	    fram[ii] -= prep->offset[ii];
94
95    for (ii= 0; ii < prep->dim; ii++) {
96	vec[ii]= 0;
97	for (jj= 0; jj < prep->dim; jj++)
98	    vec[ii] += prep->invmat[ii][jj] * fram[jj];
99	vec[ii]= SHIFT_DOWN (vec[ii], prep->inv_shift);
100    //floating pt // for (jj= 0; jj < prep->dim; jj++)
101	//floating pt // vec[ii] += (imeldata)(prep->inverse[ii][jj] * fram[jj]);
102    }
103    if (do_shift)
104	for (ii= 0; ii < prep->dim; ii++)
105	    fram[ii]= RANGE (vec[ii], 0, 255);
106    else
107	for (ii= 0; ii < prep->dim; ii++)
108	    fram[ii]= vec[ii];
109    return;
110}
111
112
113