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

Linux Cross Reference
Tina6/tina-libs/tina/sys/sysMem_ccopy.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_ccopy.c,v $
 37  * Date    :  $Date: 2003/09/22 16:09:02 $
 38  * Version :  $Revision: 1.3 $
 39  * CVS Id  :  $Id: sysMem_ccopy.c,v 1.3 2003/09/22 16:09:02 tony Exp $
 40  *
 41  * Notes :
 42  *  Array & Vector copying. (char version)
 43  *  i.e. copy displaced vectors and arrays,  casting as necessary.
 44  *
 45  *********
 46 */
 47 
 48 #include "sysMem_ccopy.h"
 49 
 50 #if HAVE_CONFIG_H
 51   #include <config.h>
 52 #endif
 53 
 54 #include <math.h>
 55 #include <stdio.h>
 56 #include <tina/sys/sysGen_error.h>
 57 #include <tina/sys/sysMem_ralloc.h>
 58 
 59 
 60 /* make char copy of displaced vector of unsigned chars */
 61 
 62 char *cvector_uccopy(unsigned char *v, int n1, int n2)
 63 {
 64         char *ptr;
 65         int i;
 66 
 67         if (n2 <= n1)
 68         {
 69                 error("cvector_uccopy: bad array bounds", warning);
 70                 return (NULL);
 71         }
 72         ptr = (char *) ralloc((unsigned) (n2 - n1) * sizeof(char)) - n1;
 73         for (i = n1; i < n2; ++i)
 74         {
 75                 ptr[i] = v[i];
 76         }
 77         return (ptr);
 78 }
 79 
 80 /* make char copy of displaced array of unsigned chars */
 81 
 82 char **carray_uccopy(unsigned char **a, int m1, int n1, int m2, int n2)
 83 {
 84         char **ptr;
 85         int m = m2 - m1, n = n2 - n1;
 86         int i, j;
 87 
 88         if (m < 0 || n < 0)
 89         {
 90                 error("carray_uccopy: bad array bounds", non_fatal);
 91                 return (NULL);
 92         }
 93         if (m == 0 || n == 0)
 94         {
 95                 error("carray_uccopy: zero array size", warning);
 96                 return (NULL);
 97         }
 98         ptr = (char **) ralloc((unsigned) m * sizeof(char *)) - m1;
 99         for (i = m1; i < m2; ++i)
100                 ptr[i] = (char *) ralloc((unsigned) n * sizeof(char)) - n1;
101         for (i = m1; i < m2; ++i)
102                 for (j = n1; j < n2; ++j)
103                         ptr[i][j] = a[i][j];
104         return (ptr);
105 }
106 
107 /* make char copy of displaced lower triangle of unsigned chars */
108 
109 char **clower_uccopy(unsigned char **a, int m1, int n1, int m2, int n2)
110 {
111         char **ptr;
112         int m = m2 - m1, n = n2 - n1;
113         int i, j;
114 
115         if (m < 0 || n < 0)
116         {
117                 error("clower_uccopy: bad array bounds", non_fatal);
118                 return (NULL);
119         }
120         if (m == 0 || n == 0)
121         {
122                 error("clower_uccopy: zero array size", warning);
123                 return (NULL);
124         }
125         ptr = (char **) ralloc((unsigned) m * sizeof(char *)) - m1;
126         for (i = m1; i < m2; ++i)
127                 ptr[i] = (char *) ralloc((unsigned) n * sizeof(char)) - n1;
128         for (i = m1; i < m2; ++i)
129                 for (j = n1; j <= i; ++j)
130                         ptr[i][j] = a[i][j];
131         return (ptr);
132 }
133 
134 /* make char copy of displaced upper triangle of unsigned chars */
135 
136 char **cupper_uccopy(unsigned char **a, int n1, int n2)
137 {
138         char **ptr;
139         int n = n2 - n1;
140         int i, j;
141 
142         if (n < 0)
143         {
144                 error("cupper_uccopy: bad array bounds", non_fatal);
145                 return (NULL);
146         }
147         if (n == 0)
148         {
149                 error("cupper_uccopy: zero array size", warning);
150                 return (NULL);
151         }
152         ptr = (char **) ralloc((unsigned) n * sizeof(char *)) - n1;
153         for (i = n1; i < n2; ++i)
154                 ptr[i] = (char *) ralloc((unsigned) (n2 - i) * sizeof(char)) - i;
155         for (i = n1; i < n2; ++i)
156                 for (j = i; j < n2; ++j)
157                         ptr[i][j] = a[i][j];
158         return (ptr);
159 }
160 
161 /* make char copy of displaced vector of chars */
162 
163 char *cvector_ccopy(char *v, int n1, int n2)
164 {
165         char *ptr;
166         int i;
167 
168         if (n2 <= n1)
169         {
170                 error("cvector_ccopy: bad array bounds", warning);
171                 return (NULL);
172         }
173         ptr = (char *) ralloc((unsigned) (n2 - n1) * sizeof(char)) - n1;
174         for (i = n1; i < n2; ++i)
175         {
176                 ptr[i] = v[i];
177         }
178         return (ptr);
179 }
180 
181 /* make char copy of displaced array of chars */
182 
183 char **carray_ccopy(char **a, int m1, int n1, int m2, int n2)
184 {
185         char **ptr;
186         int m = m2 - m1, n = n2 - n1;
187         int i, j;
188 
189         if (m < 0 || n < 0)
190         {
191                 error("carray_ccopy: bad array bounds", non_fatal);
192                 return (NULL);
193         }
194         if (m == 0 || n == 0)
195         {
196                 error("carray_ccopy: zero array size", warning);
197                 return (NULL);
198         }
199         ptr = (char **) ralloc((unsigned) m * sizeof(char *)) - m1;
200         for (i = m1; i < m2; ++i)
201                 ptr[i] = (char *) ralloc((unsigned) n * sizeof(char)) - n1;
202         for (i = m1; i < m2; ++i)
203                 for (j = n1; j < n2; ++j)
204                         ptr[i][j] = a[i][j];
205         return (ptr);
206 }
207 
208 /* make char copy of displaced lower triangle of chars */
209 
210 char **clower_ccopy(char **a, int m1, int n1, int m2, int n2)
211 {
212         char **ptr;
213         int m = m2 - m1, n = n2 - n1;
214         int i, j;
215 
216         if (m < 0 || n < 0)
217         {
218                 error("clower_ccopy: bad array bounds", non_fatal);
219                 return (NULL);
220         }
221         if (m == 0 || n == 0)
222         {
223                 error("clower_ccopy: zero array size", warning);
224                 return (NULL);
225         }
226         ptr = (char **) ralloc((unsigned) m * sizeof(char *)) - m1;
227         for (i = m1; i < m2; ++i)
228                 ptr[i] = (char *) ralloc((unsigned) n * sizeof(char)) - n1;
229         for (i = m1; i < m2; ++i)
230                 for (j = n1; j <= i; ++j)
231                         ptr[i][j] = a[i][j];
232         return (ptr);
233 }
234 
235 /* make char copy of displaced upper triangle of chars */
236 
237 char **cupper_ccopy(char **a, int n1, int n2)
238 {
239         char **ptr;
240         int n = n2 - n1;
241         int i, j;
242 
243         if (n < 0)
244         {
245                 error("cupper_ccopy: bad array bounds", non_fatal);
246                 return (NULL);
247         }
248         if (n == 0)
249         {
250                 error("cupper_ccopy: zero array size", warning);
251                 return (NULL);
252         }
253         ptr = (char **) ralloc((unsigned) n * sizeof(char *)) - n1;
254         for (i = n1; i < n2; ++i)
255                 ptr[i] = (char *) ralloc((unsigned) (n2 - i) * sizeof(char)) - i;
256         for (i = n1; i < n2; ++i)
257                 for (j = i; j < n2; ++j)
258                         ptr[i][j] = a[i][j];
259         return (ptr);
260 }
261 
262 /* make char copy of displaced vector of shorts */
263 
264 char *cvector_scopy(short int *v, int n1, int n2)
265 {
266         char *ptr;
267         int i;
268 
269         if (n2 <= n1)
270         {
271                 error("cvector_scopy: bad array bounds", warning);
272                 return (NULL);
273         }
274         ptr = (char *) ralloc((unsigned) (n2 - n1) * sizeof(char)) - n1;
275         for (i = n1; i < n2; ++i)
276         {
277                 ptr[i] = (char) v[i];
278         }
279         return (ptr);
280 }
281 
282 /* make char copy of displaced array of shorts */
283 
284 char **carray_scopy(short int **a, int m1, int n1, int m2, int n2)
285 {
286         char **ptr;
287         int m = m2 - m1, n = n2 - n1;
288         int i, j;
289 
290         if (m < 0 || n < 0)
291         {
292                 error("carray_scopy: bad array bounds", non_fatal);
293                 return (NULL);
294         }
295         if (m == 0 || n == 0)
296         {
297                 error("carray_scopy: zero array size", warning);
298                 return (NULL);
299         }
300         ptr = (char **) ralloc((unsigned) m * sizeof(char *)) - m1;
301         for (i = m1; i < m2; ++i)
302                 ptr[i] = (char *) ralloc((unsigned) n * sizeof(char)) - n1;
303         for (i = m1; i < m2; ++i)
304                 for (j = n1; j < n2; ++j)
305                         ptr[i][j] = (char) a[i][j];
306         return (ptr);
307 }
308 
309 /* make char copy of displaced lower triangle of shorts */
310 
311 char **clower_scopy(short int **a, int m1, int n1, int m2, int n2)
312 {
313         char **ptr;
314         int m = m2 - m1, n = n2 - n1;
315         int i, j;
316 
317         if (m < 0 || n < 0)
318         {
319                 error("clower_scopy: bad array bounds", non_fatal);
320                 return (NULL);
321         }
322         if (m == 0 || n == 0)
323         {
324                 error("clower_scopy: zero array size", warning);
325                 return (NULL);
326         }
327         ptr = (char **) ralloc((unsigned) m * sizeof(char *)) - m1;
328         for (i = m1; i < m2; ++i)
329                 ptr[i] = (char *) ralloc((unsigned) n * sizeof(char)) - n1;
330         for (i = m1; i < m2; ++i)
331                 for (j = n1; j <= i; ++j)
332                         ptr[i][j] = (char) a[i][j];
333         return (ptr);
334 }
335 
336 /* make char copy of displaced upper triangle of shorts */
337 
338 char **cupper_scopy(short int **a, int n1, int n2)
339 {
340         char **ptr;
341         int n = n2 - n1;
342         int i, j;
343 
344         if (n < 0)
345         {
346                 error("cupper_scopy: bad array bounds", non_fatal);
347                 return (NULL);
348         }
349         if (n == 0)
350         {
351                 error("cupper_scopy: zero array size", warning);
352                 return (NULL);
353         }
354         ptr = (char **) ralloc((unsigned) n * sizeof(char *)) - n1;
355         for (i = n1; i < n2; ++i)
356                 ptr[i] = (char *) ralloc((unsigned) (n2 - i) * sizeof(char)) - i;
357         for (i = n1; i < n2; ++i)
358                 for (j = i; j < n2; ++j)
359                         ptr[i][j] = (char) a[i][j];
360         return (ptr);
361 }
362 
363 /* make char copy of displaced vector of ints */
364 
365 char *cvector_icopy(int *v, int n1, int n2)
366 {
367         char *ptr;
368         int i;
369 
370         if (n2 <= n1)
371         {
372                 error("cvector_icopy: bad array bounds", warning);
373                 return (NULL);
374         }
375         ptr = (char *) ralloc((unsigned) (n2 - n1) * sizeof(char)) - n1;
376         for (i = n1; i < n2; ++i)
377         {
378                 ptr[i] = v[i];
379         }
380         return (ptr);
381 }
382 
383 /* make char copy of displaced array of ints */
384 
385 char **carray_icopy(int **a, int m1, int n1, int m2, int n2)
386 {
387         char **ptr;
388         int m = m2 - m1, n = n2 - n1;
389         int i, j;
390 
391         if (m < 0 || n < 0)
392         {
393                 error("carray_icopy: bad array bounds", non_fatal);
394                 return (NULL);
395         }
396         if (m == 0 || n == 0)
397         {
398                 error("carray_icopy: zero array size", warning);
399                 return (NULL);
400         }
401         ptr = (char **) ralloc((unsigned) m * sizeof(char *)) - m1;
402         for (i = m1; i < m2; ++i)
403                 ptr[i] = (char *) ralloc((unsigned) n * sizeof(char)) - n1;
404         for (i = m1; i < m2; ++i)
405                 for (j = n1; j < n2; ++j)
406                         ptr[i][j] = a[i][j];
407         return (ptr);
408 }
409 
410 /* make char copy of displaced lower triangle of ints */
411 
412 char **clower_icopy(int **a, int m1, int n1, int m2, int n2)
413 {
414         char **ptr;
415         int m = m2 - m1, n = n2 - n1;
416         int i, j;
417 
418         if (m < 0 || n < 0)
419         {
420                 error("clower_icopy: bad array bounds", non_fatal);
421                 return (NULL);
422         }
423         if (m == 0 || n == 0)
424         {
425                 error("clower_icopy: zero array size", warning);
426                 return (NULL);
427         }
428         ptr = (char **) ralloc((unsigned) m * sizeof(char *)) - m1;
429         for (i = m1; i < m2; ++i)
430                 ptr[i] = (char *) ralloc((unsigned) n * sizeof(char)) - n1;
431         for (i = m1; i < m2; ++i)
432                 for (j = n1; j <= i; ++j)
433                         ptr[i][j] = a[i][j];
434         return (ptr);
435 }
436 
437 /* make char copy of displaced upper triangle of ints */
438 
439 char **cupper_icopy(int **a, int n1, int n2)
440 {
441         char **ptr;
442         int n = n2 - n1;
443         int i, j;
444 
445         if (n < 0)
446         {
447                 error("cupper_icopy: bad array bounds", non_fatal);
448                 return (NULL);
449         }
450         if (n == 0)
451         {
452                 error("cupper_icopy: zero array size", warning);
453                 return (NULL);
454         }
455         ptr = (char **) ralloc((unsigned) n * sizeof(char *)) - n1;
456         for (i = n1; i < n2; ++i)
457                 ptr[i] = (char *) ralloc((unsigned) (n2 - i) * sizeof(char)) - i;
458         for (i = n1; i < n2; ++i)
459                 for (j = i; j < n2; ++j)
460                         ptr[i][j] = a[i][j];
461         return (ptr);
462 }
463 
464 /* make char copy of displaced vector of floats */
465 
466 char *cvector_fcopy(float *v, int n1, int n2)
467 {
468         char *ptr;
469         int i;
470 
471         if (n2 <= n1)
472         {
473                 error("cvector_fcopy: bad array bounds", warning);
474                 return (NULL);
475         }
476         ptr = (char *) ralloc((unsigned) (n2 - n1) * sizeof(char)) - n1;
477         for (i = n1; i < n2; ++i)
478         {
479                 ptr[i] = (char) v[i];
480         }
481         return (ptr);
482 }
483 
484 /* make char copy of displaced array of floats */
485 
486 char **carray_fcopy(float **a, int m1, int n1, int m2, int n2)
487 {
488         char **ptr;
489         int m = m2 - m1, n = n2 - n1;
490         int i, j;
491 
492         if (m < 0 || n < 0)
493         {
494                 error("carray_fcopy: bad array bounds", non_fatal);
495                 return (NULL);
496         }
497         if (m == 0 || n == 0)
498         {
499                 error("carray_fcopy: zero array size", warning);
500                 return (NULL);
501         }
502         ptr = (char **) ralloc((unsigned) m * sizeof(char *)) - m1;
503         for (i = m1; i < m2; ++i)
504                 ptr[i] = (char *) ralloc((unsigned) n * sizeof(char)) - n1;
505         for (i = m1; i < m2; ++i)
506                 for (j = n1; j < n2; ++j)
507                         ptr[i][j] = (char) a[i][j];
508         return (ptr);
509 }
510 
511 /* make char copy of displaced lower triangle of floats */
512 
513 char **clower_fcopy(float **a, int m1, int n1, int m2, int n2)
514 {
515         char **ptr;
516         int m = m2 - m1, n = n2 - n1;
517         int i, j;
518 
519         if (m < 0 || n < 0)
520         {
521                 error("clower_fcopy: bad array bounds", non_fatal);
522                 return (NULL);
523         }
524         if (m == 0 || n == 0)
525         {
526                 error("clower_fcopy: zero array size", warning);
527                 return (NULL);
528         }
529         ptr = (char **) ralloc((unsigned) m * sizeof(char *)) - m1;
530         for (i = m1; i < m2; ++i)
531                 ptr[i] = (char *) ralloc((unsigned) n * sizeof(char)) - n1;
532         for (i = m1; i < m2; ++i)
533                 for (j = n1; j <= i; ++j)
534                         ptr[i][j] = (char) a[i][j];
535         return (ptr);
536 }
537 
538 /* make char copy of displaced upper triangle of floats */
539 
540 char **cupper_fcopy(float **a, int n1, int n2)
541 {
542         char **ptr;
543         int n = n2 - n1;
544         int i, j;
545 
546         if (n < 0)
547         {
548                 error("cupper_fcopy: bad array bounds", non_fatal);
549                 return (NULL);
550         }
551         if (n == 0)
552         {
553                 error("cupper_fcopy: zero array size", warning);
554                 return (NULL);
555         }
556         ptr = (char **) ralloc((unsigned) n * sizeof(char *)) - n1;
557         for (i = n1; i < n2; ++i)
558                 ptr[i] = (char *) ralloc((unsigned) (n2 - i) * sizeof(char)) - i;
559         for (i = n1; i < n2; ++i)
560                 for (j = i; j < n2; ++j)
561                         ptr[i][j] = (char) a[i][j];
562         return (ptr);
563 }
564 
565 /* make char copy of displaced vector of doubles */
566 
567 char *cvector_dcopy(double *v, int n1, int n2)
568 {
569         char *ptr;
570         int i;
571 
572         if (n2 <= n1)
573         {
574                 error("cvector_dcopy: bad array bounds", warning);
575                 return (NULL);
576         }
577         ptr = (char *) ralloc((unsigned) (n2 - n1) * sizeof(char)) - n1;
578         for (i = n1; i < n2; ++i)
579         {
580                 ptr[i] = (char) v[i];
581         }
582         return (ptr);
583 }
584 
585 /* make char copy of displaced array of doubles */
586 
587 char **carray_dcopy(double **a, int m1, int n1, int m2, int n2)
588 {
589         char **ptr;
590         int m = m2 - m1, n = n2 - n1;
591         int i, j;
592 
593         if (m < 0 || n < 0)
594         {
595                 error("carray_dcopy: bad array bounds", non_fatal);
596                 return (NULL);
597         }
598         if (m == 0 || n == 0)
599         {
600                 error("carray_dcopy: zero array size", warning);
601                 return (NULL);
602         }
603         ptr = (char **) ralloc((unsigned) m * sizeof(char *)) - m1;
604         for (i = m1; i < m2; ++i)
605                 ptr[i] = (char *) ralloc((unsigned) n * sizeof(char)) - n1;
606         for (i = m1; i < m2; ++i)
607                 for (j = n1; j < n2; ++j)
608                         ptr[i][j] = (char) a[i][j];
609         return (ptr);
610 }
611 
612 /* make char copy of displaced lower triangle of doubles */
613 
614 char **clower_dcopy(double **a, int m1, int n1, int m2, int n2)
615 {
616         char **ptr;
617         int m = m2 - m1, n = n2 - n1;
618         int i, j;
619 
620         if (m < 0 || n < 0)
621         {
622                 error("clower_dcopy: bad array bounds", non_fatal);
623                 return (NULL);
624         }
625         if (m == 0 || n == 0)
626         {
627                 error("clower_dcopy: zero array size", warning);
628                 return (NULL);
629         }
630         ptr = (char **) ralloc((unsigned) m * sizeof(char *)) - m1;
631         for (i = m1; i < m2; ++i)
632                 ptr[i] = (char *) ralloc((unsigned) n * sizeof(char)) - n1;
633         for (i = m1; i < m2; ++i)
634                 for (j = n1; j <= i; ++j)
635                         ptr[i][j] = (char) a[i][j];
636         return (ptr);
637 }
638 
639 /* make char copy of displaced upper triangle of doubles */
640 
641 char **cupper_dcopy(double **a, int n1, int n2)
642 {
643         char **ptr;
644         int n = n2 - n1;
645         int i, j;
646 
647         if (n < 0)
648         {
649                 error("cupper_dcopy: bad array bounds", non_fatal);
650                 return (NULL);
651         }
652         if (n == 0)
653         {
654                 error("cupper_dcopy: zero array size", warning);
655                 return (NULL);
656         }
657         ptr = (char **) ralloc((unsigned) n * sizeof(char *)) - n1;
658         for (i = n1; i < n2; ++i)
659                 ptr[i] = (char *) ralloc((unsigned) (n2 - i) * sizeof(char)) - i;
660         for (i = n1; i < n2; ++i)
661                 for (j = i; j < n2; ++j)
662                         ptr[i][j] = (char) a[i][j];
663         return (ptr);
664 }
665 

~ [ 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.