File: il_endian.h

package info (click to toggle)
devil 1.6.7-5%2Betch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 11,536 kB
  • ctags: 7,441
  • sloc: ansic: 35,573; sh: 8,075; cpp: 7,465; pascal: 792; makefile: 399; python: 47
file content (99 lines) | stat: -rw-r--r-- 2,923 bytes parent folder | download | duplicates (3)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//-----------------------------------------------------------------------------
//
// ImageLib Sources
// Copyright (C) 2000-2002 by Denton Woods
// Last modified: 01/29/2002 <--Y2K Compliant! =]
//
// Filename: src-IL/include/il_endian.h
//
// Description: Handles Endian-ness
//
//-----------------------------------------------------------------------------

#ifndef IL_ENDIAN_H
#define IL_ENDIAN_H

#include "il_internal.h"

#if (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __BIG_ENDIAN__) \
 || (defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__))
	#undef __LITTLE_ENDIAN__
	#define Short(s) _SwapShort(s)
	#define UShort(s) _SwapUShort(s)
	#define Int(i) _SwapInt(i)
	#define UInt(i) _SwapUInt(i)
	#define Float(f) _SwapFloat(f)
	#define Double(d) _SwapDouble(d)
 
	#define BigShort(s)  
	#define BigUShort(s)  
	#define BigInt(i)  
	#define BigUInt(i)  
	#define BigFloat(f)  
	#define BigDouble(d)  
#else
	#undef __BIG_ENDIAN__
	#undef __LITTLE_ENDIAN__  // Not sure if it's defined by any compiler...
	#define __LITTLE_ENDIAN__
	#define Short(s)  
	#define UShort(s)  
	#define Int(i)  
	#define UInt(i)  
	#define Float(f)  
	#define Double(d)  

	#define BigUShort(s) _SwapUShort(s)
	#define BigUInt(i) _SwapUInt(i)
	#define BigInt(i) _SwapInt(i)
	#define BigUShort(s) _SwapUShort(s)
	#define BigUInt(i) _SwapUInt(i)
	#define BigFloat(f) _SwapFloat(f)
	#define BigDouble(d) _SwapDouble(d)
#endif


ILvoid	_SwapUShort(ILushort *s);
ILvoid	_SwapShort(ILshort *s);
ILvoid	_SwapUInt(ILuint *i);
ILvoid	_SwapInt(ILint *i);
ILvoid	_SwapFloat(ILfloat *f);
ILvoid	_SwapDouble(ILdouble *d);


// Only seem to work on unsigned values properly...
#define SwapShort(s) ((s>>8) | (s<<8))
#define SwapInt(i) ((i>>24) | ((i>>8) & 0xff00) | ((i<<8) & 0xff0000) | (i<<24))
//#define SwapFloat(f) ((f>>24) | ((f>>8) & 0xff00) | ((f<<8) & 0xff0000) | (f<<24))
//#define SwapDouble(d) ((f>>56) | ((f>>40) & 0xff00) | ((f>>24) & 0xff0000) |
//	((f>>8) & 0xff000000) | ((f<<8) & 0xff00000000) | ((f<<24) & 0xff0000000000) | ((f<<40) & 0xff000000000000) | (f<<56))


ILushort	GetLittleUShort(ILvoid);
ILshort		GetLittleShort(ILvoid);
ILuint		GetLittleUInt(ILvoid);
ILint		GetLittleInt(ILvoid);
ILfloat		GetLittleFloat(ILvoid);
ILdouble	GetLittleDouble(ILvoid);
ILushort	GetBigUShort(ILvoid);
ILshort		GetBigShort(ILvoid);
ILuint		GetBigUInt(ILvoid);
ILint		GetBigInt(ILvoid);
ILfloat		GetBigFloat(ILvoid);
ILdouble	GetBigDouble(ILvoid);

ILubyte		SaveLittleUShort(ILushort _s);
ILubyte		SaveLittleShort(ILshort _s);
ILubyte		SaveLittleUInt(ILuint _i);
ILubyte		SaveLittleInt(ILint _i);
ILubyte		SaveLittleFloat(ILfloat _f);
ILubyte		SaveLittleDouble(ILdouble _d);
ILubyte		SaveBigUShort(ILushort _s);
ILubyte		SaveBigShort(ILshort _s);
ILubyte		SaveBigUInt(ILuint _i);
ILubyte		SaveBigInt(ILint _i);
ILubyte		SaveBigFloat(ILfloat _f);
ILubyte		SaveBigDouble(ILdouble _d);

ILvoid		EndianSwapData(void *_Image);

#endif//ENDIAN_H