~ubuntu-branches/ubuntu/precise/stellarium/precise

« back to all changes in this revision

Viewing changes to src/stelutils/bytes.h

  • Committer: Bazaar Package Importer
  • Author(s): Cédric Delfosse
  • Date: 2009-03-13 20:07:22 UTC
  • mfrom: (1.1.8 upstream) (4.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090313200722-l66s4zy2s3e8up0s
Tags: 0.10.2-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// bytes.h
2
 
// 
3
 
// Copyright (C) 2001, Colin Walters <walters@verbum.org>
4
 
//
5
 
// This program is free software; you can redistribute it and/or
6
 
// modify it under the terms of the GNU General Public License
7
 
// as published by the Free Software Foundation; either version 2
8
 
// of the License, or (at your option) any later version.
9
 
 
10
 
#ifndef _BYTES_H_
11
 
#define _BYTES_H_
12
 
 
13
 
#ifdef HAVE_CONFIG_H
14
 
# include "config.h"
15
 
#endif
16
 
 
17
 
/* Use the system byteswap.h definitions if we have them */
18
 
#ifdef HAVE_BYTESWAP_H
19
 
#include <byteswap.h>
20
 
#else
21
 
static unsigned short bswap_16 (unsigned short val)
22
 
{
23
 
  return ((((val) >> 8) & 0xff) | (((val) & 0xff) << 8));
24
 
}
25
 
 
26
 
static unsigned int bswap_32(unsigned int val) {
27
 
  return (((val) & 0xff000000) >> 24) | (((val) & 0x00ff0000) >>  8) |
28
 
    (((val) & 0x0000ff00) <<  8) | (((val) & 0x000000ff) << 24);
29
 
}
30
 
#endif
31
 
 
32
 
#define SWAP_FLOAT(x, y) do { *(unsigned int *)&x = bswap_32( *(unsigned int *)&y ); } while (0)
33
 
 
34
 
#ifdef WORDS_BIGENDIAN
35
 
 
36
 
#define LE_TO_CPU_INT16(ret, val) (ret = bswap_16(val))
37
 
 
38
 
#define LE_TO_CPU_INT32(ret, val) (ret = bswap_32(val))
39
 
 
40
 
#define LE_TO_CPU_FLOAT(ret, val) SWAP_FLOAT(ret, val)
41
 
 
42
 
#define BE_TO_CPU_INT16(ret, val) (ret = val)
43
 
 
44
 
#define BE_TO_CPU_INT32(ret, val) (ret = val)
45
 
 
46
 
#define BE_TO_CPU_FLOAT(ret, val) (ret = val)
47
 
 
48
 
#else
49
 
 
50
 
#define BE_TO_CPU_INT16(ret, val) (ret = bswap_16(val))
51
 
 
52
 
#define BE_TO_CPU_INT32(ret, val) (ret = bswap_32(val))
53
 
 
54
 
#define BE_TO_CPU_FLOAT(ret, val) SWAP_FLOAT(ret, val)
55
 
 
56
 
#define LE_TO_CPU_INT16(ret, val) (ret = val)
57
 
 
58
 
#define LE_TO_CPU_INT32(ret, val) (ret = val)
59
 
 
60
 
#define LE_TO_CPU_FLOAT(ret, val) (ret = val)
61
 
 
62
 
#endif
63
 
 
64
 
#endif // _BYTES_H_