r1053: Add Russian translation.
[cinelerra_cv.git] / cinelerra / byteorder.h
blob931818e2d20f08d99a29b9d33d2c76ffc99f17c2
1 #ifndef BYTEORDER_H
2 #define BYTEORDER_H
4 #include <sys/types.h>
6 inline int get_byte_order()
7 { // 1 if little endian
8 return (*(u_int32_t*)"a ") & 0x00000001;
11 #define SWAP_ITERATE \
12 byte1 = buffer1[i]; \
13 byte2 = buffer2[i]; \
14 buffer1[i] = byte2; \
15 buffer2[i] = byte1; \
16 i += 2;
18 #define SWAP_24BIT_ITERATE \
19 byte1 = buffer1[i]; \
20 byte2 = buffer2[i]; \
21 byte3 = buffer3[i]; \
22 buffer1[i] = byte3; \
23 buffer2[i] = byte2; \
24 buffer3[i] = byte1; \
25 i += 3;
27 #define SWAP_32BIT_ITERATE \
28 byte1 = buffer1[i]; \
29 byte2 = buffer2[i]; \
30 byte3 = buffer3[i]; \
31 byte4 = buffer4[i]; \
32 buffer1[i] = byte4; \
33 buffer2[i] = byte1; \
34 buffer3[i] = byte2; \
35 buffer4[i] = byte3; \
36 i += 4;
38 inline int swap_bytes(int wordsize, unsigned char *buffer, long len)
40 register unsigned char byte1, byte2, byte3, byte4;
41 register unsigned char *buffer1 = buffer;
42 register unsigned char *buffer2 = buffer + 1;
43 register unsigned char *buffer3 = buffer + 2;
44 register unsigned char *buffer4 = buffer + 3;
46 register long i = 0, j = 0, k = 0;
48 //printf("swap bytes\n");
50 switch(wordsize)
52 case 1:
53 return 0;
54 break;
56 case 2:
57 len -= 8;
58 while(i < len){
59 SWAP_ITERATE
60 SWAP_ITERATE
61 SWAP_ITERATE
62 SWAP_ITERATE
65 len += 8;
66 while(i < len){
67 SWAP_ITERATE
69 return 0;
70 break;
72 case 3:
73 len -= 12;
74 while(i < len){
75 SWAP_24BIT_ITERATE
76 SWAP_24BIT_ITERATE
77 SWAP_24BIT_ITERATE
78 SWAP_24BIT_ITERATE
81 len += 12;
82 while(i < len){
83 SWAP_24BIT_ITERATE
85 return 0;
86 break;
88 case 4:
89 len -= 16;
90 while(i < len)
92 SWAP_32BIT_ITERATE
93 SWAP_32BIT_ITERATE
94 SWAP_32BIT_ITERATE
95 SWAP_32BIT_ITERATE
98 len += 16;
99 while(i < len)
101 SWAP_32BIT_ITERATE
103 return 0;
104 break;
106 return 1;
109 #endif