Identifying Endia Issues

I recently learned about content and still have difficulty identifying problem areas.

Here is a piece of code that uses data loaded from a binary file (Dxt textures). I am not sure if in this situation problems can arise, such as width, height and hexadecimal comparison. What do I need to change and why?

DxtHeader* header = (DxtHeader*)data;
width = header->width;
height = header->height;

uint pixelFormat = header->pixelFormat.fourCC;
if (pixelFormat == 0x31545844){
    ...
} else if (pixelFormat == 0x33545844){
    ...
} else if (pixelFormat == 0x35545844){
    ...
}
+3
source share
2 answers

, , (, ), . , "" -, . int a = 0xABCD; char b = *(char *)&a;.

, , , -. , endianness , , . , #ifdefs, . C ( , ++, , ):

#ifdef (LITTLE_ENDIAN)
#define FILE_TO_NATIVE_16(x)  ((((x) & 0xFF) << 8) | ((x) >> 8))
#else
#define FILE_TO_NATIVE_16(x)  (x)
#endif

..

, .

+1

, , . , endian .

, DXT- , DXTs Windows, .

+1

Source: https://habr.com/ru/post/1761139/


All Articles