source: soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc2.c @ 821

Last change on this file since 821 was 821, checked in by meunier, 8 years ago
  • Added several versions of rosenfeld: { SLOW, FAST } x { FEATURES, NO_FEATURES }
  • Added native linux compilation support
  • Added a script to check results natively
  • Started to refactor nrc code
File size: 9.6 KB
Line 
1/* ------------------ */
2/* --- nralloc2.c --- */
3/* ------------------ */
4
5/*
6 * Copyright (c) 2000-2014, Lionel Lacassagne, All rights reserved
7 * Univ Paris Sud XI, CNRS
8 *
9 * Distributed under the Boost Software License, Version 1.0
10 * see accompanying file LICENSE.txt or copy it at
11 * http://www.boost.org/LICENSE_1_0.txt
12*/
13
14/*
15 * this code is based on the "Numerical Recipes in C 2nd edition" nrutil.c nrutil.h files from
16 * William H. Press, Saul A. Teukolsky, William T. Vetterling, Brian P. Flannery
17 *
18 * The original code is not-copyrighted.
19 * The original routines are placed into the public domain
20 * (see Appendix B: utility routines, pp 964)
21 * for more information, visit http://www.nr.com
22 */
23
24/*
25* 2002/06/11 ajout des fonctions endline
26*/
27#include <stdio.h>
28#include <stddef.h>
29#include <stdlib.h>
30#include <malloc.h>
31#include <math.h> // fabs
32
33#include "nrc_os_config.h"
34#include "mypredef.h"
35#include "nrtype.h"
36#include "nrtypex.h"
37#include "nrdef.h"
38#include "nrmacro.h"
39#include "nrkernel.h"
40
41#include "nralloc2.h"
42
43/*
44 * --------------
45 * --- matrix ---
46 * --------------
47 */
48
49
50#undef type_matrix
51#define type_matrix(t) \
52t ** short_name(t,,matrix)(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \
53{                                                                              \
54    int32_t nrow = nrh - nrl + 1;                                              \
55    int32_t ncol = nch - ncl + 1;                                              \
56    t ** m;                                                                    \
57    /* allocate pointers to row */                                             \
58    m = malloc((nrow + NR_END) * sizeof(t *));                                 \
59    if (m == NULL) {                                                           \
60        nrerror("*** Error: allocation failure in %s\n", __func__);            \
61    }                                                                          \
62    m += NR_END;                                                               \
63    m -= nrl;                                                                  \
64    /* allocate rows and set pointers to them */                               \
65    m[nrl] = malloc((nrow * ncol + NR_END) * sizeof(t));                       \
66    if (m[nrl] == NULL) {                                                      \
67        nrerror("*** Error: allocation failure in %s\n", __func__);            \
68    }                                                                          \
69    m[nrl] += NR_END;                                                          \
70    m[nrl] -= ncl;                                                             \
71    for (int32_t i = nrl + 1; i <= nrh; i++) {                                 \
72        m[i] = m[i - 1] + ncol;                                                \
73    }                                                                          \
74    /* return pointer to array of pointers to rows */                          \
75    return m;                                                                  \
76}
77
78
79type_matrix(int8_t);
80type_matrix(uint8_t);
81type_matrix(int16_t);
82type_matrix(uint16_t);
83type_matrix(int32_t);
84type_matrix(uint32_t);
85type_matrix(int64_t);
86type_matrix(uint64_t);
87type_matrix(float);
88type_matrix(double);
89type_matrix(void_p);
90type_matrix(rgb8);
91type_matrix(rgbx8);
92type_matrix(rgb32);
93type_matrix(rgbx32);
94type_matrix(complex32);
95type_matrix(complex64);
96type_matrix(si16Point);
97type_matrix(ui16Point);
98type_matrix(si32Point);
99type_matrix(ui32Point);
100type_matrix(f32Point);
101type_matrix(si16Triplet);
102type_matrix(ui16Triplet);
103type_matrix(si32Triplet);
104type_matrix(ui32Triplet);
105type_matrix(f32Triplet);
106
107
108
109
110#undef type_matrix0
111#define type_matrix0(t) \
112t ** short_name(t,,matrix0)(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \
113{                                                                               \
114    int32_t nrow = nrh - nrl + 1;                                               \
115    int32_t ncol = nch - ncl + 1;                                               \
116    t ** m;                                                                     \
117    /* allocate pointers to row */                                              \
118    m = malloc((nrow + NR_END) * sizeof(t *));                                  \
119    if (m == NULL) {                                                            \
120        nrerror("*** Error: allocation failure in %s\n", __func__);             \
121    }                                                                           \
122    m += NR_END;                                                                \
123    m -= nrl;                                                                   \
124    /* allocate rows and set pointers to them */                                \
125    m[nrl] = calloc((nrow * ncol + NR_END), sizeof(t));                         \
126    if (m[nrl] == NULL) {                                                       \
127        nrerror("*** Error: allocation failure in %s\n", __func__);             \
128    }                                                                           \
129    m[nrl] += NR_END;                                                           \
130    m[nrl] -= ncl;                                                              \
131    for (int32_t i = nrl + 1; i <= nrh; i++) {                                  \
132        m[i] = m[i - 1] + ncol;                                                 \
133    }                                                                           \
134    /* return pointer to array of pointers to rows */                           \
135    return m;                                                                   \
136}
137
138
139type_matrix0(int8_t);
140type_matrix0(uint8_t);
141type_matrix0(int16_t);
142type_matrix0(uint16_t);
143type_matrix0(int32_t);
144type_matrix0(uint32_t);
145type_matrix0(int64_t);
146type_matrix0(uint64_t);
147type_matrix0(float);
148type_matrix0(double);
149type_matrix0(void_p);
150type_matrix0(rgb8);
151type_matrix0(rgbx8);
152type_matrix0(rgb32);
153type_matrix0(rgbx32);
154type_matrix0(complex32);
155type_matrix0(complex64);
156
157
158#if TARGET_OS == GIETVM
159
160#undef remote_type_matrix
161#define remote_type_matrix(t) \
162t ** short_name(t,remote_,matrix)(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \
163{                                                                              \
164    int32_t nrow = nrh - nrl + 1;                                              \
165    int32_t ncol = nch - ncl + 1;                                              \
166    t ** m;                                                                    \
167    /* allocate pointers to row */                                             \
168    m = malloc((nrow + NR_END) * sizeof(t *));                                 \
169    if (m == NULL) {                                                           \
170        nrerror("*** Error: allocation failure in %s\n", __func__);            \
171    }                                                                          \
172    m += NR_END;                                                               \
173    m -= nrl;                                                                  \
174    /* allocate rows and set pointers to them */                               \
175    m[nrl] = malloc((nrow * ncol + NR_END) * sizeof(t));                       \
176    if (m[nrl] == NULL) {                                                      \
177        nrerror("*** Error: allocation failure in %s\n", __func__);            \
178    }                                                                          \
179    m[nrl] += NR_END;                                                          \
180    m[nrl] -= ncl;                                                             \
181    for (int32_t i = nrl + 1; i <= nrh; i++) {                                 \
182        m[i] = m[i - 1] + ncol;                                                \
183    }                                                                          \
184    /* return pointer to array of pointers to rows */                          \
185    return m;                                                                  \
186}
187
188
189remote_type_matrix(int8_t);
190remote_type_matrix(uint8_t);
191remote_type_matrix(int16_t);
192remote_type_matrix(uint16_t);
193remote_type_matrix(int32_t);
194remote_type_matrix(uint32_t);
195remote_type_matrix(int64_t);
196remote_type_matrix(uint64_t);
197remote_type_matrix(float);
198remote_type_matrix(double);
199remote_type_matrix(void_p);
200remote_type_matrix(rgb8);
201remote_type_matrix(rgbx8);
202remote_type_matrix(rgb32);
203remote_type_matrix(rgbx32);
204remote_type_matrix(complex32);
205remote_type_matrix(complex64);
206
207#endif
208
209
210#undef free_type_matrix
211#define free_type_matrix(t) \
212void short_name(t,free_,matrix)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \
213{ \
214    free((FREE_ARG) (m[nrl] + ncl - NR_END)); \
215    free((FREE_ARG) (m + nrl - NR_END)); \
216}
217
218free_type_matrix(int8_t);
219free_type_matrix(uint8_t);
220free_type_matrix(int16_t);
221free_type_matrix(uint16_t);
222free_type_matrix(int32_t);
223free_type_matrix(uint32_t);
224free_type_matrix(int64_t);
225free_type_matrix(uint64_t);
226free_type_matrix(float);
227free_type_matrix(double);
228free_type_matrix(void_p);
229free_type_matrix(rgb8);
230free_type_matrix(rgbx8);
231free_type_matrix(rgb32);
232free_type_matrix(rgbx32);
233free_type_matrix(complex32);
234free_type_matrix(complex64);
235free_type_matrix(si16Point);
236free_type_matrix(ui16Point);
237free_type_matrix(si32Point);
238free_type_matrix(ui32Point);
239free_type_matrix(f32Point);
240free_type_matrix(si16Triplet);
241free_type_matrix(ui16Triplet);
242free_type_matrix(si32Triplet);
243free_type_matrix(ui32Triplet);
244free_type_matrix(f32Triplet);
245
246
247
248// Local Variables:
249// tab-width: 4
250// c-basic-offset: 4
251// c-file-offsets:((innamespace . 0)(inline-open . 0))
252// indent-tabs-mode: nil
253// End:
254// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
255
Note: See TracBrowser for help on using the repository browser.