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

Linux Cross Reference
Tina6/tina-libs/tina/sys/sysGen_swap.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/sysGen_swap.c,v $
 37  * Date    :  $Date: 2003/09/22 16:09:02 $
 38  * Version :  $Revision: 1.5 $
 39  * CVS Id  :  $Id: sysGen_swap.c,v 1.5 2003/09/22 16:09:02 tony Exp $
 40  *
 41  * Author  :  Legacy TINA
 42 */
 43 /**
 44  * @file Endian reversal routines.
 45  * @brief A flag is set to indicate the need for endian reversal on input of all binary
 46  * data from file. The routines below will then automatically handle byte swapping
 47  * as the data is read.
 48  *
 49  *********
 50 */
 51 
 52 #include "sysGen_swap.h"
 53 
 54 #if HAVE_CONFIG_H
 55   #include <config.h>
 56 #endif
 57 
 58 
 59 static int swapping_flag = 0;           /* static data! */
 60 
 61 int get_swapping_ts()
 62 {
 63         return swapping_flag;
 64 }
 65 
 66 void set_swapping_ts(int w)
 67 {
 68         swapping_flag = w;
 69 }
 70 
 71 
 72 void longd_swap(char *d)
 73 {
 74         union swap
 75         {
 76                 char in[16];
 77                 // a.lacey@man.ac.uk 5.9.03
 78                 // removed long as unnecessary
 79                 // long double out
 80                 double out;
 81         }
 82         Swap;
 83 
 84         if (!swapping_flag)
 85                 return;
 86         Swap.in[0] = *(d + 15);
 87         Swap.in[1] = *(d + 14);
 88         Swap.in[2] = *(d + 13);
 89         Swap.in[3] = *(d + 12);
 90         Swap.in[4] = *(d + 11);
 91         Swap.in[5] = *(d + 10);
 92         Swap.in[6] = *(d + 9);
 93         Swap.in[7] = *(d + 8);
 94         Swap.in[8] = *(d + 7);
 95         Swap.in[9] = *(d + 6);
 96         Swap.in[10] = *(d + 5);
 97         Swap.in[11] = *(d + 4);
 98         Swap.in[12] = *(d + 3);
 99         Swap.in[13] = *(d + 2);
100         Swap.in[14] = *(d + 1);
101         Swap.in[15] = *d;
102         // a.lacey@man.ac.uk 5.9.03
103         // removed long as unnecessary
104         // *long (double *) d = Swap.out;
105         *(double *) d = Swap.out;
106 }
107 
108 
109 void long_swap(char *d)
110 {
111         union swap
112         {
113                 char in[8];
114                 double out;
115         }
116         Swap;
117 
118         if (!swapping_flag)
119                 return;
120         Swap.in[0] = *(d + 7);
121         Swap.in[1] = *(d + 6);
122         Swap.in[2] = *(d + 5);
123         Swap.in[3] = *(d + 4);
124         Swap.in[4] = *(d + 3);
125         Swap.in[5] = *(d + 2);
126         Swap.in[6] = *(d + 1);
127         Swap.in[7] = *d;
128         *(double *) d = Swap.out;
129 }
130 
131 
132 void word_swap(char *d)
133 {
134         union swap
135         {
136                 char in[4];
137                 int out;
138         }
139         Swap;
140 
141         if (!swapping_flag)
142                 return;
143         Swap.in[0] = *(d + 3);
144         Swap.in[1] = *(d + 2);
145         Swap.in[2] = *(d + 1);
146         Swap.in[3] = *d;
147         *(int *) d = Swap.out;
148 }
149 
150 
151 void short_swap(char *d)
152 {
153         union swap
154         {
155                 char in[4];
156                 short out;
157         }
158         Swap;
159 
160         if (!swapping_flag)
161                 return;
162         Swap.in[0] = *(d + 1);
163         Swap.in[1] = *d;
164         *(short *) d = Swap.out;
165 }
166 

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