~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina6/tina-libs/tina/sys/sysMem_fcopy.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**********
  2  * 
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  * 
 35  * Program :    TINA
 36  * File    :  $Source: /home/tina/cvs/tina-libs/tina/sys/sysMem_fcopy.c,v $
 37  * Date    :  $Date: 2003/09/22 16:09:02 $
 38  * Version :  $Revision: 1.3 $
 39  * CVS Id  :  $Id: sysMem_fcopy.c,v 1.3 2003/09/22 16:09:02 tony Exp $
 40  *
 41  * Notes :
 42  *
 43  *  Array & Vector copying. (float version)
 44  *  i.e. copy displaced vectors and arrays, casting as necessary.
 45  *
 46  *********
 47 */
 48 
 49 #include "sysMem_fcopy.h"
 50 
 51 #if HAVE_CONFIG_H
 52   #include <config.h>
 53 #endif
 54 
 55 #include <math.h>
 56 #include <stdio.h>
 57 #include <tina/sys/sysGen_error.h>
 58 #include <tina/sys/sysMem_ralloc.h>
 59 
 60 
 61 
 62 /* make float copy of displaced vector of unsigned chars */
 63 
 64 float *fvector_uccopy(unsigned char *v, int n1, int n2)
 65 {
 66         float *ptr;
 67         int i;
 68 
 69         if (n2 <= n1)
 70         {
 71                 error("fvector_uccopy: bad array bounds", warning);
 72                 return (NULL);
 73         }
 74         ptr = (float *) ralloc((unsigned) (n2 - n1) * sizeof(float)) - n1;
 75         for (i = n1; i < n2; ++i)
 76         {
 77                 ptr[i] = v[i];
 78         }
 79         return (ptr);
 80 }
 81 
 82 /* make float copy of displaced array of unsigned chars */
 83 
 84 float **farray_uccopy(unsigned char **a, int m1, int n1, int m2, int n2)
 85 {
 86         float **ptr;
 87         int m = m2 - m1, n = n2 - n1;
 88         int i, j;
 89 
 90         if (m < 0 || n < 0)
 91         {
 92                 error("farray_uccopy: bad array bounds", non_fatal);
 93                 return (NULL);
 94         }
 95         if (m == 0 || n == 0)
 96         {
 97                 error("farray_uccopy: zero array size", warning);
 98                 return (NULL);
 99         }
100         ptr = (float **) ralloc((unsigned) m * sizeof(float *)) - m1;
101         for (i = m1; i < m2; ++i)
102                 ptr[i] = (float *) ralloc((unsigned) n * sizeof(float)) - n1;
103         for (i = m1; i < m2; ++i)
104                 for (j = n1; j < n2; ++j)
105                         ptr[i][j] = a[i][j];
106         return (ptr);
107 }
108 
109 /* make float copy of displaced lower triangle of unsigned chars */
110 
111 float **flower_uccopy(unsigned char **a, int m1, int n1, int m2, int n2)
112 {
113         float **ptr;
114         int m = m2 - m1, n = n2 - n1;
115         int i, j;
116 
117         if (m < 0 || n < 0)
118         {
119                 error("flower_uccopy: bad array bounds", non_fatal);
120                 return (NULL);
121         }
122         if (m == 0 || n == 0)
123         {
124                 error("flower_uccopy: zero array size", warning);
125                 return (NULL);
126         }
127         ptr = (float **) ralloc((unsigned) m * sizeof(float *)) - m1;
128         for (i = m1; i < m2; ++i)
129                 ptr[i] = (float *) ralloc((unsigned) n * sizeof(float)) - n1;
130         for (i = m1; i < m2; ++i)
131                 for (j = n1; j <= i; ++j)
132                         ptr[i][j] = a[i][j];
133         return (ptr);
134 }
135 
136 /* make float copy of displaced upper triangle of unsigned chars */
137 
138 float **fupper_uccopy(unsigned char **a, int n1, int n2)
139 {
140         float **ptr;
141         int n = n2 - n1;
142         int i, j;
143 
144         if (n < 0)
145         {
146                 error("fupper_uccopy: bad array bounds", non_fatal);
147                 return (NULL);
148         }
149         if (n == 0)
150         {
151                 error("fupper_uccopy: zero array size", warning);
152                 return (NULL);
153         }
154         ptr = (float **) ralloc((unsigned) n * sizeof(float *)) - n1;
155         for (i = n1; i < n2; ++i)
156                 ptr[i] = (float *) ralloc((unsigned) (n2 - i) * sizeof(float)) - i;
157         for (i = n1; i < n2; ++i)
158                 for (j = i; j < n2; ++j)
159                         ptr[i][j] = a[i][j];
160         return (ptr);
161 }
162 
163 /* make float copy of displaced vector of chars */
164 
165 float *fvector_ccopy(char *v, int n1, int n2)
166 {
167         float *ptr;
168         int i;
169 
170         if (n2 <= n1)
171         {
172                 error("fvector_ccopy: bad array bounds", warning);
173                 return (NULL);
174         }
175         ptr = (float *) ralloc((unsigned) (n2 - n1) * sizeof(float)) - n1;
176         for (i = n1; i < n2; ++i)
177         {
178                 ptr[i] = v[i];
179         }
180         return (ptr);
181 }
182 
183 /* make float copy of displaced array of chars */
184 
185 float **farray_ccopy(char **a, int m1, int n1, int m2, int n2)
186 {
187         float **ptr;
188         int m = m2 - m1, n = n2 - n1;
189         int i, j;
190 
191         if (m < 0 || n < 0)
192         {
193                 error("farray_ccopy: bad array bounds", non_fatal);
194                 return (NULL);
195         }
196         if (m == 0 || n == 0)
197         {
198                 error("farray_ccopy: zero array size", warning);
199                 return (NULL);
200         }
201         ptr = (float **) ralloc((unsigned) m * sizeof(float *)) - m1;
202         for (i = m1; i < m2; ++i)
203                 ptr[i] = (float *) ralloc((unsigned) n * sizeof(float)) - n1;
204         for (i = m1; i < m2; ++i)
205                 for (j = n1; j < n2; ++j)
206                         ptr[i][j] = a[i][j];
207         return (ptr);
208 }
209 
210 /* make float copy of displaced lower triangle of chars */
211 
212 float **flower_ccopy(char **a, int m1, int n1, int m2, int n2)
213 {
214         float **ptr;
215         int m = m2 - m1, n = n2 - n1;
216         int i, j;
217 
218         if (m < 0 || n < 0)
219         {
220                 error("flower_ccopy: bad array bounds", non_fatal);
221                 return (NULL);
222         }
223         if (m == 0 || n == 0)
224         {
225                 error("flower_ccopy: zero array size", warning);
226                 return (NULL);
227         }
228         ptr = (float **) ralloc((unsigned) m * sizeof(float *)) - m1;
229         for (i = m1; i < m2; ++i)
230                 ptr[i] = (float *) ralloc((unsigned) n * sizeof(float)) - n1;
231         for (i = m1; i < m2; ++i)
232                 for (j = n1; j <= i; ++j)
233                         ptr[i][j] = a[i][j];
234         return (ptr);
235 }
236 
237 /* make float copy of displaced upper triangle of chars */
238 
239 float **fupper_ccopy(char **a, int n1, int n2)
240 {
241         float **ptr;
242         int n = n2 - n1;
243         int i, j;
244 
245         if (n < 0)
246         {
247                 error("fupper_ccopy: bad array bounds", non_fatal);
248                 return (NULL);
249         }
250         if (n == 0)
251         {
252                 error("fupper_ccopy: zero array size", warning);
253                 return (NULL);
254         }
255         ptr = (float **) ralloc((unsigned) n * sizeof(float *)) - n1;
256         for (i = n1; i < n2; ++i)
257                 ptr[i] = (float *) ralloc((unsigned) (n2 - i) * sizeof(float)) - i;
258         for (i = n1; i < n2; ++i)
259                 for (j = i; j < n2; ++j)
260                         ptr[i][j] = a[i][j];
261         return (ptr);
262 }
263 
264 /* make float copy of displaced vector of shorts */
265 
266 float *fvector_scopy(short int *v, int n1, int n2)
267 {
268         float *ptr;
269         int i;
270 
271         if (n2 <= n1)
272         {
273                 error("fvector_scopy: bad array bounds", warning);
274                 return (NULL);
275         }
276         ptr = (float *) ralloc((unsigned) (n2 - n1) * sizeof(float)) - n1;
277         for (i = n1; i < n2; ++i)
278         {
279                 ptr[i] = v[i];
280         }
281         return (ptr);
282 }
283 
284 /* make float copy of displaced array of shorts */
285 
286 float **farray_scopy(short int **a, int m1, int n1, int m2, int n2)
287 {
288         float **ptr;
289         int m = m2 - m1, n = n2 - n1;
290         int i, j;
291 
292         if (m < 0 || n < 0)
293         {
294                 error("farray_scopy: bad array bounds", non_fatal);
295                 return (NULL);
296         }
297         if (m == 0 || n == 0)
298         {
299                 error("farray_scopy: zero array size", warning);
300                 return (NULL);
301         }
302         ptr = (float **) ralloc((unsigned) m * sizeof(float *)) - m1;
303         for (i = m1; i < m2; ++i)
304                 ptr[i] = (float *) ralloc((unsigned) n * sizeof(float)) - n1;
305         for (i = m1; i < m2; ++i)
306                 for (j = n1; j < n2; ++j)
307                         ptr[i][j] = a[i][j];
308         return (ptr);
309 }
310 
311 /* make float copy of displaced lower triangle of shorts */
312 
313 float **flower_scopy(short int **a, int m1, int n1, int m2, int n2)
314 {
315         float **ptr;
316         int m = m2 - m1, n = n2 - n1;
317         int i, j;
318 
319         if (m < 0 || n < 0)
320         {
321                 error("flower_scopy: bad array bounds", non_fatal);
322                 return (NULL);
323         }
324         if (m == 0 || n == 0)
325         {
326                 error("flower_scopy: zero array size", warning);
327                 return (NULL);
328         }
329         ptr = (float **) ralloc((unsigned) m * sizeof(float *)) - m1;
330         for (i = m1; i < m2; ++i)
331                 ptr[i] = (float *) ralloc((unsigned) n * sizeof(float)) - n1;
332         for (i = m1; i < m2; ++i)
333                 for (j = n1; j <= i; ++j)
334                         ptr[i][j] = a[i][j];
335         return (ptr);
336 }
337 
338 /* make float copy of displaced upper triangle of shorts */
339 
340 float **fupper_scopy(short int **a, int n1, int n2)
341 {
342         float **ptr;
343         int n = n2 - n1;
344         int i, j;
345 
346         if (n < 0)
347         {
348                 error("fupper_scopy: bad array bounds", non_fatal);
349                 return (NULL);
350         }
351         if (n == 0)
352         {
353                 error("fupper_scopy: zero array size", warning);
354                 return (NULL);
355         }
356         ptr = (float **) ralloc((unsigned) n * sizeof(float *)) - n1;
357         for (i = n1; i < n2; ++i)
358                 ptr[i] = (float *) ralloc((unsigned) (n2 - i) * sizeof(float)) - i;
359         for (i = n1; i < n2; ++i)
360                 for (j = i; j < n2; ++j)
361                         ptr[i][j] = a[i][j];
362         return (ptr);
363 }
364 
365 /* make float copy of displaced vector of ints */
366 
367 float *fvector_icopy(int *v, int n1, int n2)
368 {
369         float *ptr;
370         int i;
371 
372         if (n2 <= n1)
373         {
374                 error("fvector_icopy: bad array bounds", warning);
375                 return (NULL);
376         }
377         ptr = (float *) ralloc((unsigned) (n2 - n1) * sizeof(float)) - n1;
378         for (i = n1; i < n2; ++i)
379         {
380                 ptr[i] = (float) v[i];
381         }
382         return (ptr);
383 }
384 
385 /* make float copy of displaced array of ints */
386 
387 float **farray_icopy(int **a, int m1, int n1, int m2, int n2)
388 {
389         float **ptr;
390         int m = m2 - m1, n = n2 - n1;
391         int i, j;
392 
393         if (m < 0 || n < 0)
394         {
395                 error("farray_icopy: bad array bounds", non_fatal);
396                 return (NULL);
397         }
398         if (m == 0 || n == 0)
399         {
400                 error("farray_icopy: zero array size", warning);
401                 return (NULL);
402         }
403         ptr = (float **) ralloc((unsigned) m * sizeof(float *)) - m1;
404         for (i = m1; i < m2; ++i)
405                 ptr[i] = (float *) ralloc((unsigned) n * sizeof(float)) - n1;
406         for (i = m1; i < m2; ++i)
407                 for (j = n1; j < n2; ++j)
408                         ptr[i][j] = (float) a[i][j];
409         return (ptr);
410 }
411 
412 /* make float copy of displaced lower triangle of ints */
413 
414 float **flower_icopy(int **a, int m1, int n1, int m2, int n2)
415 {
416         float **ptr;
417         int m = m2 - m1, n = n2 - n1;
418         int i, j;
419 
420         if (m < 0 || n < 0)
421         {
422                 error("flower_icopy: bad array bounds", non_fatal);
423                 return (NULL);
424         }
425         if (m == 0 || n == 0)
426         {
427                 error("flower_icopy: zero array size", warning);
428                 return (NULL);
429         }
430         ptr = (float **) ralloc((unsigned) m * sizeof(float *)) - m1;
431         for (i = m1; i < m2; ++i)
432                 ptr[i] = (float *) ralloc((unsigned) n * sizeof(float)) - n1;
433         for (i = m1; i < m2; ++i)
434                 for (j = n1; j <= i; ++j)
435                         ptr[i][j] = (float) a[i][j];
436         return (ptr);
437 }
438 
439 /* make float copy of displaced upper triangle of ints */
440 
441 float **fupper_icopy(int **a, int n1, int n2)
442 {
443         float **ptr;
444         int n = n2 - n1;
445         int i, j;
446 
447         if (n < 0)
448         {
449                 error("fupper_icopy: bad array bounds", non_fatal);
450                 return (NULL);
451         }
452         if (n == 0)
453         {
454                 error("fupper_icopy: zero array size", warning);
455                 return (NULL);
456         }
457         ptr = (float **) ralloc((unsigned) n * sizeof(float *)) - n1;
458         for (i = n1; i < n2; ++i)
459                 ptr[i] = (float *) ralloc((unsigned) (n2 - i) * sizeof(float)) - i;
460         for (i = n1; i < n2; ++i)
461                 for (j = i; j < n2; ++j)
462                         ptr[i][j] = (float) a[i][j];
463         return (ptr);
464 }
465 
466 /* make float copy of displaced vector of floats */
467 
468 float *fvector_fcopy(float *v, int n1, int n2)
469 {
470         float *ptr;
471         int i;
472 
473         if (n2 <= n1)
474         {
475                 error("fvector_fcopy: bad array bounds", warning);
476                 return (NULL);
477         }
478         ptr = (float *) ralloc((unsigned) (n2 - n1) * sizeof(float)) - n1;
479         for (i = n1; i < n2; ++i)
480         {
481                 ptr[i] = v[i];
482         }
483         return (ptr);
484 }
485 
486 /* make float copy of displaced array of floats */
487 
488 float **farray_fcopy(float **a, int m1, int n1, int m2, int n2)
489 {
490         float **ptr;
491         int m = m2 - m1, n = n2 - n1;
492         int i, j;
493 
494         if (m < 0 || n < 0)
495         {
496                 error("farray_fcopy: bad array bounds", non_fatal);
497                 return (NULL);
498         }
499         if (m == 0 || n == 0)
500         {
501                 error("farray_fcopy: zero array size", warning);
502                 return (NULL);
503         }
504         ptr = (float **) ralloc((unsigned) m * sizeof(float *)) - m1;
505         for (i = m1; i < m2; ++i)
506                 ptr[i] = (float *) ralloc((unsigned) n * sizeof(float)) - n1;
507         for (i = m1; i < m2; ++i)
508                 for (j = n1; j < n2; ++j)
509                         ptr[i][j] = a[i][j];
510         return (ptr);
511 }
512 
513 /* make float copy of displaced lower triangle of floats */
514 
515 float **flower_fcopy(float **a, int m1, int n1, int m2, int n2)
516 {
517         float **ptr;
518         int m = m2 - m1, n = n2 - n1;
519         int i, j;
520 
521         if (m < 0 || n < 0)
522         {
523                 error("flower_fcopy: bad array bounds", non_fatal);
524                 return (NULL);
525         }
526         if (m == 0 || n == 0)
527         {
528                 error("flower_fcopy: zero array size", warning);
529                 return (NULL);
530         }
531         ptr = (float **) ralloc((unsigned) m * sizeof(float *)) - m1;
532         for (i = m1; i < m2; ++i)
533                 ptr[i] = (float *) ralloc((unsigned) n * sizeof(float)) - n1;
534         for (i = m1; i < m2; ++i)
535                 for (j = n1; j <= i; ++j)
536                         ptr[i][j] = a[i][j];
537         return (ptr);
538 }
539 
540 /* make float copy of displaced upper triangle of floats */
541 
542 float **fupper_fcopy(float **a, int n1, int n2)
543 {
544         float **ptr;
545         int n = n2 - n1;
546         int i, j;
547 
548         if (n < 0)
549         {
550                 error("fupper_fcopy: bad array bounds", non_fatal);
551                 return (NULL);
552         }
553         if (n == 0)
554         {
555                 error("fupper_fcopy: zero array size", warning);
556                 return (NULL);
557         }
558         ptr = (float **) ralloc((unsigned) n * sizeof(float *)) - n1;
559         for (i = n1; i < n2; ++i)
560                 ptr[i] = (float *) ralloc((unsigned) (n2 - i) * sizeof(float)) - i;
561         for (i = n1; i < n2; ++i)
562                 for (j = i; j < n2; ++j)
563                         ptr[i][j] = a[i][j];
564         return (ptr);
565 }
566 
567 /* make float copy of displaced vector of doubles */
568 
569 float *fvector_dcopy(double *v, int n1, int n2)
570 {
571         float *ptr;
572         int i;
573 
574         if (n2 <= n1)
575         {
576                 error("fvector_dcopy: bad array bounds", warning);
577                 return (NULL);
578         }
579         ptr = (float *) ralloc((unsigned) (n2 - n1) * sizeof(float)) - n1;
580         for (i = n1; i < n2; ++i)
581         {
582                 ptr[i] = (float) v[i];
583         }
584         return (ptr);
585 }
586 
587 /* make float copy of displaced array of doubles */
588 
589 float **farray_dcopy(double **a, int m1, int n1, int m2, int n2)
590 {
591         float **ptr;
592         int m = m2 - m1, n = n2 - n1;
593         int i, j;
594 
595         if (m < 0 || n < 0)
596         {
597                 error("farray_dcopy: bad array bounds", non_fatal);
598                 return (NULL);
599         }
600         if (m == 0 || n == 0)
601         {
602                 error("farray_dcopy: zero array size", warning);
603                 return (NULL);
604         }
605         ptr = (float **) ralloc((unsigned) m * sizeof(float *)) - m1;
606         for (i = m1; i < m2; ++i)
607                 ptr[i] = (float *) ralloc((unsigned) n * sizeof(float)) - n1;
608         for (i = m1; i < m2; ++i)
609                 for (j = n1; j < n2; ++j)
610                         ptr[i][j] = (float) a[i][j];
611         return (ptr);
612 }
613 
614 /* make float copy of displaced lower triangle of doubles */
615 
616 float **flower_dcopy(double **a, int m1, int n1, int m2, int n2)
617 {
618         float **ptr;
619         int m = m2 - m1, n = n2 - n1;
620         int i, j;
621 
622         if (m < 0 || n < 0)
623         {
624                 error("flower_dcopy: bad array bounds", non_fatal);
625                 return (NULL);
626         }
627         if (m == 0 || n == 0)
628         {
629                 error("flower_dcopy: zero array size", warning);
630                 return (NULL);
631         }
632         ptr = (float **) ralloc((unsigned) m * sizeof(float *)) - m1;
633         for (i = m1; i < m2; ++i)
634                 ptr[i] = (float *) ralloc((unsigned) n * sizeof(float)) - n1;
635         for (i = m1; i < m2; ++i)
636                 for (j = n1; j <= i; ++j)
637                         ptr[i][j] = (float) a[i][j];
638         return (ptr);
639 }
640 
641 /* make float copy of displaced upper triangle of doubles */
642 
643 float **fupper_dcopy(double **a, int n1, int n2)
644 {
645         float **ptr;
646         int n = n2 - n1;
647         int i, j;
648 
649         if (n < 0)
650         {
651                 error("fupper_dcopy: bad array bounds", non_fatal);
652                 return (NULL);
653         }
654         if (n == 0)
655         {
656                 error("fupper_dcopy: zero array size", warning);
657                 return (NULL);
658         }
659         ptr = (float **) ralloc((unsigned) n * sizeof(float *)) - n1;
660         for (i = n1; i < n2; ++i)
661                 ptr[i] = (float *) ralloc((unsigned) (n2 - i) * sizeof(float)) - i;
662         for (i = n1; i < n2; ++i)
663                 for (j = i; j < n2; ++j)
664                         ptr[i][j] = (float) a[i][j];
665         return (ptr);
666 }
667 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.