1 | /* ------------------ */ |
---|
2 | /* --- nralloc3.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 <ctype.h> // isdigit |
---|
31 | #include <string.h> // memcpy |
---|
32 | #include <math.h> // fabs |
---|
33 | // #include <memory.h> // memcpy |
---|
34 | |
---|
35 | #include "mypredef.h" |
---|
36 | #include "nrtype.h" |
---|
37 | #include "nrdef.h" |
---|
38 | #include "nrmacro.h" |
---|
39 | #include "nrkernel.h" |
---|
40 | |
---|
41 | #include "nralloc1.h" |
---|
42 | #include "nralloc3.h" |
---|
43 | |
---|
44 | /* ----------------------------------------------------------------------- */ |
---|
45 | double*** d3tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh) |
---|
46 | /* ----------------------------------------------------------------------- */ |
---|
47 | /* allocate a float 3tensor with range t[nrl..nrh][ncl..nch][ndl..ndh] */ |
---|
48 | { |
---|
49 | long i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1; |
---|
50 | double ***t; |
---|
51 | |
---|
52 | /* allocate pointers to pointers to rows */ |
---|
53 | t=(double ***) malloc((size_t)((nrow+NR_END)*sizeof(double**))); |
---|
54 | if (!t) nrerror("allocation failure 1 in d3tensor()"); |
---|
55 | t += NR_END; |
---|
56 | t -= nrl; |
---|
57 | |
---|
58 | /* allocate pointers to rows and set pointers to them */ |
---|
59 | t[nrl]=(double **) malloc((size_t)((nrow*ncol+NR_END)*sizeof(double*))); |
---|
60 | if (!t[nrl]) nrerror("allocation failure 2 in d3tensor()"); |
---|
61 | t[nrl] += NR_END; |
---|
62 | t[nrl] -= ncl; |
---|
63 | |
---|
64 | /* allocate rows and set pointers to them */ |
---|
65 | t[nrl][ncl]=(double *) malloc((size_t)((nrow*ncol*ndep+NR_END)*sizeof(double))); |
---|
66 | if (!t[nrl][ncl]) nrerror("allocation failure 3 in d3tensor()"); |
---|
67 | t[nrl][ncl] += NR_END; |
---|
68 | t[nrl][ncl] -= ndl; |
---|
69 | |
---|
70 | for(j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep; |
---|
71 | for(i=nrl+1;i<=nrh;i++) { |
---|
72 | t[i]=t[i-1]+ncol; |
---|
73 | t[i][ncl]=t[i-1][ncl]+ncol*ndep; |
---|
74 | for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep; |
---|
75 | } |
---|
76 | |
---|
77 | /* return pointer to array of pointers to rows */ |
---|
78 | return t; |
---|
79 | } |
---|
80 | /* ------------------------------------------------------------------------------ */ |
---|
81 | void free_d3tensor(double ***t,long nrl,long nrh,long ncl,long nch,long ndl,long ndh) |
---|
82 | /* ------------------------------------------------------------------------------ */ |
---|
83 | /* free a float f3tensor allocated by d3tensor() */ |
---|
84 | { |
---|
85 | free((FREE_ARG) (t[nrl][ncl]+ndl-NR_END)); |
---|
86 | free((FREE_ARG) (t[nrl]+ncl-NR_END)); |
---|
87 | free((FREE_ARG) (t+nrl-NR_END)); |
---|
88 | } |
---|
89 | |
---|
90 | /* ------------------------------------------------------------------------------------ */ |
---|
91 | IMAGE_EXPORT(sint8***) si8cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch) |
---|
92 | /* ------------------------------------------------------------------------------------ */ |
---|
93 | { |
---|
94 | long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1; |
---|
95 | sint8 ***t; |
---|
96 | |
---|
97 | /* allocate pointers to pointers to rows */ |
---|
98 | t=(sint8***) malloc((size_t)((ndep+NR_END)*sizeof(sint8**))); |
---|
99 | if (!t) nrerror("allocation failure 1 in si8cube()"); |
---|
100 | t += NR_END; |
---|
101 | t -= ndl; |
---|
102 | |
---|
103 | /* allocate pointers to rows anc set pointers to them */ |
---|
104 | t[ndl]=(sint8**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(sint8*))); |
---|
105 | if (!t[ndl]) nrerror("allocation failure 2 in si8cube()"); |
---|
106 | t[ndl] += NR_END; |
---|
107 | t[ndl] -= nrl; |
---|
108 | |
---|
109 | /* allocate rows anc set pointers to them */ |
---|
110 | t[ndl][nrl]=(sint8*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(sint8))); |
---|
111 | if (!t[ndl][nrl]) nrerror("allocation failure 3 in si8cube()"); |
---|
112 | t[ndl][nrl] += NR_END; |
---|
113 | t[ndl][nrl] -= ncl; |
---|
114 | |
---|
115 | for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol; |
---|
116 | for(i=ndl+1;i<=ndh;i++) { |
---|
117 | t[i]=t[i-1]+nrow; |
---|
118 | t[i][nrl]=t[i-1][nrl]+nrow*nrol; |
---|
119 | for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol; |
---|
120 | } |
---|
121 | /* return pointer to array of pointers to rows */ |
---|
122 | return t; |
---|
123 | } |
---|
124 | /* ------------------------------------------------------------------------------------ */ |
---|
125 | IMAGE_EXPORT(uint8***) ui8cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch) |
---|
126 | /* ------------------------------------------------------------------------------------ */ |
---|
127 | { |
---|
128 | long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1; |
---|
129 | uint8 ***t; |
---|
130 | |
---|
131 | /* allocate pointers to pointers to rows */ |
---|
132 | t=(uint8***) malloc((size_t)((ndep+NR_END)*sizeof(uint8**))); |
---|
133 | if (!t) nrerror("allocation failure 1 in ui8cube()"); |
---|
134 | t += NR_END; |
---|
135 | t -= ndl; |
---|
136 | |
---|
137 | /* allocate pointers to rows anc set pointers to them */ |
---|
138 | t[ndl]=(uint8**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(uint8*))); |
---|
139 | if (!t[ndl]) nrerror("allocation failure 2 in ui8cube()"); |
---|
140 | t[ndl] += NR_END; |
---|
141 | t[ndl] -= nrl; |
---|
142 | |
---|
143 | /* allocate rows anc set pointers to them */ |
---|
144 | t[ndl][nrl]=(uint8*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(uint8))); |
---|
145 | if (!t[ndl][nrl]) nrerror("allocation failure 3 in ui8cube()"); |
---|
146 | t[ndl][nrl] += NR_END; |
---|
147 | t[ndl][nrl] -= ncl; |
---|
148 | |
---|
149 | for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol; |
---|
150 | for(i=ndl+1;i<=ndh;i++) { |
---|
151 | t[i]=t[i-1]+nrow; |
---|
152 | t[i][nrl]=t[i-1][nrl]+nrow*nrol; |
---|
153 | for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol; |
---|
154 | } |
---|
155 | /* return pointer to array of pointers to rows */ |
---|
156 | return t; |
---|
157 | } |
---|
158 | /* -------------------------------------------------------------------------------------- */ |
---|
159 | IMAGE_EXPORT(sint16***) si16cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch) |
---|
160 | /* -------------------------------------------------------------------------------------- */ |
---|
161 | { |
---|
162 | long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1; |
---|
163 | sint16 ***t; |
---|
164 | |
---|
165 | /* allocate pointers to pointers to rows */ |
---|
166 | t=(sint16 ***) malloc((size_t)((ndep+NR_END)*sizeof(sint16**))); |
---|
167 | if (!t) nrerror("allocation failure 1 in si16cube()"); |
---|
168 | t += NR_END; |
---|
169 | t -= ndl; |
---|
170 | |
---|
171 | /* allocate pointers to rows anc set pointers to them */ |
---|
172 | t[ndl]=(sint16 **) malloc((size_t)((ndep*nrow+NR_END)*sizeof(sint16*))); |
---|
173 | if (!t[ndl]) nrerror("allocation failure 2 in si16cube()"); |
---|
174 | t[ndl] += NR_END; |
---|
175 | t[ndl] -= nrl; |
---|
176 | |
---|
177 | /* allocate rows anc set pointers to them */ |
---|
178 | t[ndl][nrl]=(sint16 *) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(sint16))); |
---|
179 | if (!t[ndl][nrl]) nrerror("allocation failure 3 in si16cube()"); |
---|
180 | t[ndl][nrl] += NR_END; |
---|
181 | t[ndl][nrl] -= ncl; |
---|
182 | |
---|
183 | for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol; |
---|
184 | for(i=ndl+1;i<=ndh;i++) { |
---|
185 | t[i]=t[i-1]+nrow; |
---|
186 | t[i][nrl]=t[i-1][nrl]+nrow*nrol; |
---|
187 | for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol; |
---|
188 | } |
---|
189 | /* return pointer to array of pointers to rows */ |
---|
190 | return t; |
---|
191 | } |
---|
192 | /* -------------------------------------------------------------------------------------- */ |
---|
193 | IMAGE_EXPORT(uint16***) ui16cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch) |
---|
194 | /* -------------------------------------------------------------------------------------- */ |
---|
195 | { |
---|
196 | long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1; |
---|
197 | uint16 ***t; |
---|
198 | |
---|
199 | /* allocate pointers to pointers to rows */ |
---|
200 | t=(uint16***) malloc((size_t)((ndep+NR_END)*sizeof(uint16**))); |
---|
201 | if (!t) nrerror("allocation failure 1 in ui16cube()"); |
---|
202 | t += NR_END; |
---|
203 | t -= ndl; |
---|
204 | |
---|
205 | /* allocate pointers to rows anc set pointers to them */ |
---|
206 | t[ndl]=(uint16**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(uint16*))); |
---|
207 | if (!t[ndl]) nrerror("allocation failure 2 in ui16cube()"); |
---|
208 | t[ndl] += NR_END; |
---|
209 | t[ndl] -= nrl; |
---|
210 | |
---|
211 | /* allocate rows anc set pointers to them */ |
---|
212 | t[ndl][nrl]=(uint16*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(uint16))); |
---|
213 | if (!t[ndl][nrl]) nrerror("allocation failure 3 in ui16cube()"); |
---|
214 | t[ndl][nrl] += NR_END; |
---|
215 | t[ndl][nrl] -= ncl; |
---|
216 | |
---|
217 | for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol; |
---|
218 | for(i=ndl+1;i<=ndh;i++) { |
---|
219 | t[i]=t[i-1]+nrow; |
---|
220 | t[i][nrl]=t[i-1][nrl]+nrow*nrol; |
---|
221 | for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol; |
---|
222 | } |
---|
223 | /* return pointer to array of pointers to rows */ |
---|
224 | return t; |
---|
225 | } |
---|
226 | /* ------------------------------------------------------------------------------------ */ |
---|
227 | IMAGE_EXPORT(sint32***) si32cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch) |
---|
228 | /* ------------------------------------------------------------------------------------ */ |
---|
229 | { |
---|
230 | long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1; |
---|
231 | sint32 ***t; |
---|
232 | |
---|
233 | /* allocate pointers to pointers to rows */ |
---|
234 | t=(sint32***) malloc((size_t)((ndep+NR_END)*sizeof(sint32**))); |
---|
235 | if (!t) nrerror("allocation failure 1 in si32cube()"); |
---|
236 | t += NR_END; |
---|
237 | t -= ndl; |
---|
238 | |
---|
239 | /* allocate pointers to rows anc set pointers to them */ |
---|
240 | t[ndl]=(sint32**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(sint32*))); |
---|
241 | if (!t[ndl]) nrerror("allocation failure 2 in si32cube()"); |
---|
242 | t[ndl] += NR_END; |
---|
243 | t[ndl] -= nrl; |
---|
244 | |
---|
245 | /* allocate rows anc set pointers to them */ |
---|
246 | t[ndl][nrl]=(sint32*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(sint32))); |
---|
247 | if (!t[ndl][nrl]) nrerror("allocation failure 3 in si32cube()"); |
---|
248 | t[ndl][nrl] += NR_END; |
---|
249 | t[ndl][nrl] -= ncl; |
---|
250 | |
---|
251 | for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol; |
---|
252 | for(i=ndl+1;i<=ndh;i++) { |
---|
253 | t[i]=t[i-1]+nrow; |
---|
254 | t[i][nrl]=t[i-1][nrl]+nrow*nrol; |
---|
255 | for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol; |
---|
256 | } |
---|
257 | /* return pointer to array of pointers to rows */ |
---|
258 | return t; |
---|
259 | } |
---|
260 | /* -------------------------------------------------------------------------------------- */ |
---|
261 | IMAGE_EXPORT(uint32***) ui32cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch) |
---|
262 | /* -------------------------------------------------------------------------------------- */ |
---|
263 | { |
---|
264 | long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1; |
---|
265 | uint32 ***t; |
---|
266 | |
---|
267 | /* allocate pointers to pointers to rows */ |
---|
268 | t=(uint32***) malloc((size_t)((ndep+NR_END)*sizeof(uint32**))); |
---|
269 | if (!t) nrerror("allocation failure 1 in ui32cube()"); |
---|
270 | t += NR_END; |
---|
271 | t -= ndl; |
---|
272 | |
---|
273 | /* allocate pointers to rows anc set pointers to them */ |
---|
274 | t[ndl]=(uint32**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(uint32*))); |
---|
275 | if (!t[ndl]) nrerror("allocation failure 2 in ui32cube()"); |
---|
276 | t[ndl] += NR_END; |
---|
277 | t[ndl] -= nrl; |
---|
278 | |
---|
279 | /* allocate rows anc set pointers to them */ |
---|
280 | t[ndl][nrl]=(uint32*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(uint32))); |
---|
281 | if (!t[ndl][nrl]) nrerror("allocation failure 3 in ui32cube()"); |
---|
282 | t[ndl][nrl] += NR_END; |
---|
283 | t[ndl][nrl] -= ncl; |
---|
284 | |
---|
285 | for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol; |
---|
286 | for(i=ndl+1;i<=ndh;i++) { |
---|
287 | t[i]=t[i-1]+nrow; |
---|
288 | t[i][nrl]=t[i-1][nrl]+nrow*nrol; |
---|
289 | for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol; |
---|
290 | } |
---|
291 | /* return pointer to array of pointers to rows */ |
---|
292 | return t; |
---|
293 | } |
---|
294 | /* -------------------------------------------------------------------------------------- */ |
---|
295 | IMAGE_EXPORT(float32***) f32cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch) |
---|
296 | /* -------------------------------------------------------------------------------------- */ |
---|
297 | { |
---|
298 | long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1; |
---|
299 | float32 ***t; |
---|
300 | |
---|
301 | /* allocate pointers to pointers to rows */ |
---|
302 | t=(float32***) malloc((size_t)((ndep+NR_END)*sizeof(float32**))); |
---|
303 | if (!t) nrerror("allocation failure 1 in f32cube()"); |
---|
304 | t += NR_END; |
---|
305 | t -= ndl; |
---|
306 | |
---|
307 | /* allocate pointers to rows anc set pointers to them */ |
---|
308 | t[ndl]=(float32**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(float32*))); |
---|
309 | if (!t[ndl]) nrerror("allocation failure 2 in f32cube()"); |
---|
310 | t[ndl] += NR_END; |
---|
311 | t[ndl] -= nrl; |
---|
312 | |
---|
313 | /* allocate rows anc set pointers to them */ |
---|
314 | t[ndl][nrl]=(float32*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(float32))); |
---|
315 | if (!t[ndl][nrl]) nrerror("allocation failure 3 in f32cube()"); |
---|
316 | t[ndl][nrl] += NR_END; |
---|
317 | t[ndl][nrl] -= ncl; |
---|
318 | |
---|
319 | for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol; |
---|
320 | for(i=ndl+1;i<=ndh;i++) { |
---|
321 | t[i]=t[i-1]+nrow; |
---|
322 | t[i][nrl]=t[i-1][nrl]+nrow*nrol; |
---|
323 | for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol; |
---|
324 | } |
---|
325 | /* return pointer to array of pointers to rows */ |
---|
326 | return t; |
---|
327 | } |
---|
328 | /* -------------------------------------------------------------------------------------- */ |
---|
329 | IMAGE_EXPORT(float64***) f64cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch) |
---|
330 | /* -------------------------------------------------------------------------------------- */ |
---|
331 | { |
---|
332 | long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1; |
---|
333 | float64 ***t; |
---|
334 | |
---|
335 | /* allocate pointers to pointers to rows */ |
---|
336 | t=(float64***) malloc((size_t)((ndep+NR_END)*sizeof(float64**))); |
---|
337 | if (!t) nrerror("allocation failure 1 in f32cube()"); |
---|
338 | t += NR_END; |
---|
339 | t -= ndl; |
---|
340 | |
---|
341 | /* allocate pointers to rows anc set pointers to them */ |
---|
342 | t[ndl]=(float64**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(float64*))); |
---|
343 | if (!t[ndl]) nrerror("allocation failure 2 in f64cube()"); |
---|
344 | t[ndl] += NR_END; |
---|
345 | t[ndl] -= nrl; |
---|
346 | |
---|
347 | /* allocate rows anc set pointers to them */ |
---|
348 | t[ndl][nrl]=(float64*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(float64))); |
---|
349 | if (!t[ndl][nrl]) nrerror("allocation failure 3 in f64cube()"); |
---|
350 | t[ndl][nrl] += NR_END; |
---|
351 | t[ndl][nrl] -= ncl; |
---|
352 | |
---|
353 | for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol; |
---|
354 | for(i=ndl+1;i<=ndh;i++) { |
---|
355 | t[i]=t[i-1]+nrow; |
---|
356 | t[i][nrl]=t[i-1][nrl]+nrow*nrol; |
---|
357 | for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol; |
---|
358 | } |
---|
359 | /* return pointer to array of pointers to rows */ |
---|
360 | return t; |
---|
361 | } |
---|
362 | /* ------------------------------------------------------------------------------------ */ |
---|
363 | IMAGE_EXPORT(rgb8***) rgb8cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch) |
---|
364 | /* ------------------------------------------------------------------------------------ */ |
---|
365 | /* allocate a rgb8 cube with range t[ndl..ndh][nrl..nrh][ncl..nch] */ |
---|
366 | { |
---|
367 | long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1; |
---|
368 | rgb8 ***t; |
---|
369 | |
---|
370 | /* allocate pointers to pointers to rows */ |
---|
371 | t=(rgb8***) malloc((size_t)((ndep+NR_END)*sizeof(rgb8**))); |
---|
372 | if (!t) nrerror("allocation failure 1 in rgb8cube()"); |
---|
373 | t += NR_END; |
---|
374 | t -= ndl; |
---|
375 | |
---|
376 | /* allocate pointers to rows anc set pointers to them */ |
---|
377 | t[ndl]=(rgb8**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(rgb8*))); |
---|
378 | if (!t[ndl]) nrerror("allocation failure 2 in rgb8cube()"); |
---|
379 | t[ndl] += NR_END; |
---|
380 | t[ndl] -= nrl; |
---|
381 | |
---|
382 | /* allocate rows anc set pointers to them */ |
---|
383 | t[ndl][nrl]=(rgb8*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(rgb8))); |
---|
384 | if (!t[ndl][nrl]) nrerror("allocation failure 3 in rgb8cube()"); |
---|
385 | t[ndl][nrl] += NR_END; |
---|
386 | t[ndl][nrl] -= ncl; |
---|
387 | |
---|
388 | for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol; |
---|
389 | for(i=ndl+1;i<=ndh;i++) { |
---|
390 | t[i]=t[i-1]+nrow; |
---|
391 | t[i][nrl]=t[i-1][nrl]+nrow*nrol; |
---|
392 | for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol; |
---|
393 | } |
---|
394 | /* return pointer to array of pointers to rows */ |
---|
395 | return t; |
---|
396 | } |
---|
397 | /* -------------------------------------------------------------------------------------- */ |
---|
398 | IMAGE_EXPORT(rgbx8***) rgbx8cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch) |
---|
399 | /* -------------------------------------------------------------------------------------- */ |
---|
400 | /* allocate a rgb8 cube with range t[ndl..ndh][nrl..nrh][ncl..nch] */ |
---|
401 | { |
---|
402 | long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1; |
---|
403 | rgbx8 ***t; |
---|
404 | |
---|
405 | /* allocate pointers to pointers to rows */ |
---|
406 | t=(rgbx8***) malloc((size_t)((ndep+NR_END)*sizeof(rgbx8**))); |
---|
407 | if (!t) nrerror("allocation failure 1 in rgbx8cube()"); |
---|
408 | t += NR_END; |
---|
409 | t -= ndl; |
---|
410 | |
---|
411 | /* allocate pointers to rows anc set pointers to them */ |
---|
412 | t[ndl]=(rgbx8**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(rgbx8*))); |
---|
413 | if (!t[ndl]) nrerror("allocation failure 2 in rgbx8cube()"); |
---|
414 | t[ndl] += NR_END; |
---|
415 | t[ndl] -= nrl; |
---|
416 | |
---|
417 | /* allocate rows anc set pointers to them */ |
---|
418 | t[ndl][nrl]=(rgbx8*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(rgbx8))); |
---|
419 | if (!t[ndl][nrl]) nrerror("allocation failure 3 in rgbx8cube()"); |
---|
420 | t[ndl][nrl] += NR_END; |
---|
421 | t[ndl][nrl] -= ncl; |
---|
422 | |
---|
423 | for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol; |
---|
424 | for(i=ndl+1;i<=ndh;i++) { |
---|
425 | t[i]=t[i-1]+nrow; |
---|
426 | t[i][nrl]=t[i-1][nrl]+nrow*nrol; |
---|
427 | for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol; |
---|
428 | } |
---|
429 | /* return pointer to array of pointers to rows */ |
---|
430 | return t; |
---|
431 | } |
---|
432 | /* ------------------------------------------------------------------------------------------- */ |
---|
433 | IMAGE_EXPORT(void) free_si8cube(sint8 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh) |
---|
434 | /* ------------------------------------------------------------------------------------------- */ |
---|
435 | { |
---|
436 | free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END)); |
---|
437 | free((FREE_ARG) (c[nrl]+ncl-NR_END)); |
---|
438 | free((FREE_ARG) (c+nrl-NR_END)); |
---|
439 | } |
---|
440 | /* ------------------------------------------------------------------------------------------- */ |
---|
441 | IMAGE_EXPORT(void) free_ui8cube(uint8 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh) |
---|
442 | /* ------------------------------------------------------------------------------------------- */ |
---|
443 | { |
---|
444 | free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END)); |
---|
445 | free((FREE_ARG) (c[nrl]+ncl-NR_END)); |
---|
446 | free((FREE_ARG) (c+nrl-NR_END)); |
---|
447 | } |
---|
448 | /* --------------------------------------------------------------------------------------------- */ |
---|
449 | IMAGE_EXPORT(void) free_si16cube(sint16 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh) |
---|
450 | /* --------------------------------------------------------------------------------------------- */ |
---|
451 | { |
---|
452 | free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END)); |
---|
453 | free((FREE_ARG) (c[nrl]+ncl-NR_END)); |
---|
454 | free((FREE_ARG) (c+nrl-NR_END)); |
---|
455 | } |
---|
456 | /* --------------------------------------------------------------------------------------------- */ |
---|
457 | IMAGE_EXPORT(void) free_ui16cube(uint16 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh) |
---|
458 | /* --------------------------------------------------------------------------------------------- */ |
---|
459 | { |
---|
460 | free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END)); |
---|
461 | free((FREE_ARG) (c[nrl]+ncl-NR_END)); |
---|
462 | free((FREE_ARG) (c+nrl-NR_END)); |
---|
463 | } |
---|
464 | /* --------------------------------------------------------------------------------------------- */ |
---|
465 | IMAGE_EXPORT(void) free_si32cube(sint32 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh) |
---|
466 | /* --------------------------------------------------------------------------------------------- */ |
---|
467 | { |
---|
468 | free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END)); |
---|
469 | free((FREE_ARG) (c[nrl]+ncl-NR_END)); |
---|
470 | free((FREE_ARG) (c+nrl-NR_END)); |
---|
471 | } |
---|
472 | /* --------------------------------------------------------------------------------------------- */ |
---|
473 | IMAGE_EXPORT(void) free_ui32cube(uint32 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh) |
---|
474 | /* --------------------------------------------------------------------------------------------- */ |
---|
475 | { |
---|
476 | free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END)); |
---|
477 | free((FREE_ARG) (c[nrl]+ncl-NR_END)); |
---|
478 | free((FREE_ARG) (c+nrl-NR_END)); |
---|
479 | } |
---|
480 | /* --------------------------------------------------------------------------------------------- */ |
---|
481 | IMAGE_EXPORT(void) free_f32cube(float32 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh) |
---|
482 | /* --------------------------------------------------------------------------------------------- */ |
---|
483 | { |
---|
484 | free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END)); |
---|
485 | free((FREE_ARG) (c[nrl]+ncl-NR_END)); |
---|
486 | free((FREE_ARG) (c+nrl-NR_END)); |
---|
487 | } |
---|
488 | /* --------------------------------------------------------------------------------------------- */ |
---|
489 | IMAGE_EXPORT(void) free_f64cube(float64 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh) |
---|
490 | /* --------------------------------------------------------------------------------------------- */ |
---|
491 | { |
---|
492 | free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END)); |
---|
493 | free((FREE_ARG) (c[nrl]+ncl-NR_END)); |
---|
494 | free((FREE_ARG) (c+nrl-NR_END)); |
---|
495 | } |
---|
496 | /* ------------------------------------------------------------------------------------------- */ |
---|
497 | IMAGE_EXPORT(void) free_rgb8cube(rgb8 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh) |
---|
498 | /* ------------------------------------------------------------------------------------------- */ |
---|
499 | { |
---|
500 | free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END)); |
---|
501 | free((FREE_ARG) (c[nrl]+ncl-NR_END)); |
---|
502 | free((FREE_ARG) (c+nrl-NR_END)); |
---|
503 | } |
---|
504 | /* --------------------------------------------------------------------------------------------- */ |
---|
505 | IMAGE_EXPORT(void) free_rgbx8cube(rgbx8 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh) |
---|
506 | /* --------------------------------------------------------------------------------------------- */ |
---|
507 | { |
---|
508 | free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END)); |
---|
509 | free((FREE_ARG) (c[nrl]+ncl-NR_END)); |
---|
510 | free((FREE_ARG) (c+nrl-NR_END)); |
---|
511 | } |
---|