wsdl: add prototypes for VC endian swap routines (avoid warning)
endian.*: split out of lib.* to reduce default dependencies tex,zip: now include endian.h This was SVN commit r1838.
This commit is contained in:
parent
faff797cd6
commit
f3a61e4f69
45
source/lib/endian.cpp
Normal file
45
source/lib/endian.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "endian.h"
|
||||
|
||||
|
||||
u16 read_le16(const void* p)
|
||||
{
|
||||
#if SDL_BYTE_ORDER == SDL_BIG_ENDIAN
|
||||
const u8* _p = (const u8*)p;
|
||||
return (u16)_p[0] | (u16)_p[1] << 8;
|
||||
#else
|
||||
return *(u16*)p;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
u32 read_le32(const void* p)
|
||||
{
|
||||
#if SDL_BYTE_ORDER == SDL_BIG_ENDIAN
|
||||
return SDL_Swap32(*(u32*)p);
|
||||
#else
|
||||
return *(u32*)p;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
u16 read_be16(const void* p)
|
||||
{
|
||||
#if SDL_BYTE_ORDER == SDL_BIG_ENDIAN
|
||||
return *(u16*)p;
|
||||
#else
|
||||
const u8* _p = (const u8*)p;
|
||||
return (u16)_p[0] | (u16)_p[1] << 8;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
u32 read_be32(const void* p)
|
||||
{
|
||||
#if SDL_BYTE_ORDER == SDL_BIG_ENDIAN
|
||||
return *(u32*)p;
|
||||
#else
|
||||
return SDL_Swap32(*(u32*)p);
|
||||
#endif
|
||||
}
|
24
source/lib/endian.h
Normal file
24
source/lib/endian.h
Normal file
@ -0,0 +1,24 @@
|
||||
#include "sdl.h"
|
||||
|
||||
// converts 4 character string to u32 for easy comparison
|
||||
// can't pass code as string, and use s[0]..s[3], because
|
||||
// VC6/7 don't realize the macro is constant
|
||||
// (it should be useable as a switch{} expression)
|
||||
//
|
||||
// these casts are ugly but necessary. u32 is required because u8 << 8 == 0;
|
||||
// the additional u8 cast ensures each character is treated as unsigned
|
||||
// (otherwise, they'd be promoted to signed int before the u32 cast,
|
||||
// which would break things).
|
||||
#if SDL_BYTE_ORDER == SDL_BIG_ENDIAN
|
||||
#define FOURCC(a,b,c,d) ( ((u32)(u8)a) << 24 | ((u32)(u8)b) << 16 | \
|
||||
((u32)(u8)c) << 8 | ((u32)(u8)d) << 0 )
|
||||
#else
|
||||
#define FOURCC(a,b,c,d) ( ((u32)(u8)a) << 0 | ((u32)(u8)b) << 8 | \
|
||||
((u32)(u8)c) << 16 | ((u32)(u8)d) << 24 )
|
||||
#endif
|
||||
|
||||
|
||||
extern u16 read_le16(const void* p);
|
||||
extern u32 read_le32(const void* p);
|
||||
extern u16 read_be16(const void* p);
|
||||
extern u32 read_be32(const void* p);
|
@ -19,8 +19,6 @@
|
||||
#include "types.h"
|
||||
#include "lib.h"
|
||||
|
||||
#include "sdl.h" // endian functions
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -325,47 +323,6 @@ u16 fp_to_u16(double in)
|
||||
|
||||
|
||||
|
||||
u16 read_le16(const void* p)
|
||||
{
|
||||
#if SDL_BYTE_ORDER == SDL_BIG_ENDIAN
|
||||
const u8* _p = (const u8*)p;
|
||||
return (u16)_p[0] | (u16)_p[1] << 8;
|
||||
#else
|
||||
return *(u16*)p;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
u32 read_le32(const void* p)
|
||||
{
|
||||
#if SDL_BYTE_ORDER == SDL_BIG_ENDIAN
|
||||
return SDL_Swap32(*(u32*)p);
|
||||
#else
|
||||
return *(u32*)p;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
u16 read_be16(const void* p)
|
||||
{
|
||||
#if SDL_BYTE_ORDER == SDL_BIG_ENDIAN
|
||||
return *(u16*)p;
|
||||
#else
|
||||
const u8* _p = (const u8*)p;
|
||||
return (u16)_p[0] | (u16)_p[1] << 8;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
u32 read_be32(const void* p)
|
||||
{
|
||||
#if SDL_BYTE_ORDER == SDL_BIG_ENDIAN
|
||||
return *(u32*)p;
|
||||
#else
|
||||
return SDL_Swap32(*(u32*)p);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
// big endian!
|
||||
|
@ -21,13 +21,10 @@
|
||||
#include <assert.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "posix.h"
|
||||
#include "types.h"
|
||||
|
||||
#include "sysdep/sysdep.h"
|
||||
|
||||
#include "sdl.h" // for endian stuff
|
||||
|
||||
|
||||
// tell STL not to generate exceptions, if compiling without exceptions
|
||||
// (usually done for performance reasons).
|
||||
@ -211,22 +208,6 @@ enum LibError
|
||||
|
||||
#endif
|
||||
|
||||
// converts 4 character string to u32 for easy comparison
|
||||
// can't pass code as string, and use s[0]..s[3], because
|
||||
// VC6/7 don't realize the macro is constant
|
||||
// (it should be useable as a switch{} expression)
|
||||
//
|
||||
// these casts are ugly but necessary. u32 is required because u8 << 8 == 0;
|
||||
// the additional u8 cast ensures each character is treated as unsigned
|
||||
// (otherwise, they'd be promoted to signed int before the u32 cast,
|
||||
// which would break things).
|
||||
#if SDL_BYTE_ORDER == SDL_BIG_ENDIAN
|
||||
#define FOURCC(a,b,c,d) ( ((u32)(u8)a) << 24 | ((u32)(u8)b) << 16 | \
|
||||
((u32)(u8)c) << 8 | ((u32)(u8)d) << 0 )
|
||||
#else
|
||||
#define FOURCC(a,b,c,d) ( ((u32)(u8)a) << 0 | ((u32)(u8)b) << 8 | \
|
||||
((u32)(u8)c) << 16 | ((u32)(u8)d) << 24 )
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@ -304,11 +285,6 @@ extern u16 addusw(u16 x, u16 y);
|
||||
extern u16 subusw(u16 x, u16 y);
|
||||
|
||||
|
||||
extern u16 read_le16(const void* p);
|
||||
extern u32 read_le32(const void* p);
|
||||
extern u16 read_be16(const void* p);
|
||||
extern u32 read_be32(const void* p);
|
||||
|
||||
|
||||
extern bool is_pow2(long n);
|
||||
|
||||
|
@ -18,16 +18,18 @@
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "lib.h"
|
||||
#include "res.h"
|
||||
#include "tex.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "lib.h"
|
||||
#include "res.h"
|
||||
#include "tex.h"
|
||||
#include "endian.h"
|
||||
|
||||
|
||||
// supported formats:
|
||||
//#define NO_DDS
|
||||
//#define NO_TGA
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "lib.h"
|
||||
#include "zip.h"
|
||||
#include "res.h"
|
||||
#include "endian.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
|
@ -120,6 +120,9 @@ extern int SDL_SetGamma(float r, float g, float b);
|
||||
// Debug-mode ICC doesn't like the intrinsics, so only use them
|
||||
// for MSVC and non-debug ICC.
|
||||
#if defined(_MSC_VER) && !( defined(__INTEL_COMPILER) && !defined(NDEBUG) )
|
||||
extern unsigned short _byteswap_ushort(unsigned short);
|
||||
extern unsigned long _byteswap_ulong(unsigned long);
|
||||
extern unsigned __int64 _byteswap_uint64(unsigned __int64);
|
||||
#pragma intrinsic(_byteswap_ushort)
|
||||
#pragma intrinsic(_byteswap_ulong)
|
||||
#pragma intrinsic(_byteswap_uint64)
|
||||
|
Loading…
Reference in New Issue
Block a user