mirror of
https://github.com/vgmstream/vgmstream.git
synced 2024-11-25 15:20:21 +01:00
Added a helper function for auto-detecting value endianness
This commit is contained in:
parent
454488b56c
commit
e2160f4e09
@ -89,7 +89,7 @@ VGMSTREAM * init_vgmstream_ea_snu(STREAMFILE *streamFile) {
|
||||
* 0x0c(4): some sub-offset? (0x20, found when @0x01 is set) */
|
||||
|
||||
/* use start_offset as endianness flag */
|
||||
if ((uint32_t)read_32bitLE(0x08,streamFile) > 0x0000FFFF) {
|
||||
if (guess_endianness32bit(0x08,streamFile)) {
|
||||
read_32bit = read_32bitBE;
|
||||
} else {
|
||||
read_32bit = read_32bitLE;
|
||||
|
@ -149,7 +149,7 @@ VGMSTREAM * init_vgmstream_ea_bnk(STREAMFILE *streamFile) {
|
||||
goto fail;
|
||||
|
||||
/* use header size as endianness flag */
|
||||
if ((uint32_t)read_32bitLE(0x08,streamFile) > 0x000F0000) { /* todo not very accurate */
|
||||
if (guess_endianness32bit(offset + 0x08,streamFile)) {
|
||||
read_32bit = read_32bitBE;
|
||||
read_16bit = read_16bitBE;
|
||||
} else {
|
||||
|
@ -171,6 +171,16 @@ static inline int8_t read_8bit(off_t offset, STREAMFILE * streamfile) {
|
||||
return buf[0];
|
||||
}
|
||||
|
||||
/* guess byte endianness from a given value, return true if big endian and false if little endian */
|
||||
/* TODO: possibly improve */
|
||||
static inline int guess_endianness16bit(off_t offset, STREAMFILE * streamfile) {
|
||||
return ((uint16_t)read_16bitLE(offset,streamfile) > (uint16_t)read_16bitBE(offset,streamfile)) ? 1 : 0;
|
||||
}
|
||||
|
||||
static inline int guess_endianness32bit(off_t offset, STREAMFILE * streamfile) {
|
||||
return ((uint32_t)read_32bitLE(offset,streamfile) > (uint32_t)read_32bitBE(offset,streamfile)) ? 1 : 0;
|
||||
}
|
||||
|
||||
/* various STREAMFILE helpers functions */
|
||||
|
||||
size_t get_streamfile_text_line(int dst_length, char * dst, off_t offset, STREAMFILE * streamfile, int *line_done_ptr);
|
||||
|
Loading…
Reference in New Issue
Block a user