blob: 763633a5c49f7adccf26bf4f27092761959ce040 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
*/
#define import_spp
#define import_knames
#include <iraf.h>
/* BSWAP4 - Move bytes from array "a" to array "b", swapping the four bytes
* in each successive 4 byte group, i.e., 12345678 becomes 43218765.
* The input and output arrays may be the same but may not partially overlap.
*/
BSWAP4 (a, aoff, b, boff, nbytes)
XCHAR *a; /* input array */
XINT *aoff; /* first byte in input array */
XCHAR *b; /* output array */
XINT *boff; /* first byte in output array */
XINT *nbytes; /* number of bytes to swap */
{
register char *ip, *op, *tp;
register int n;
static char temp[4];
tp = temp;
ip = (char *)a + *aoff - 1;
op = (char *)b + *boff - 1;
/* Swap successive four byte groups.
*/
for (n = *nbytes >> 2; --n >= 0; ) {
*tp++ = *ip++;
*tp++ = *ip++;
*tp++ = *ip++;
*tp++ = *ip++;
*op++ = *--tp;
*op++ = *--tp;
*op++ = *--tp;
*op++ = *--tp;
}
/* If there are any odd bytes left, move them to the output array.
* Do not bother to swap as it is unclear how to swap a partial
* group, and really incorrect if the data is not modulus 4.
*/
for (n = *nbytes & 03; --n >= 0; )
*op++ = *ip++;
}
|