add window layout feature, resource wdw select used, blue_dot/blond_cv theme fix...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / byteorder.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #ifndef BYTEORDER_H
23 #define BYTEORDER_H
24
25 #include <sys/types.h>
26
27 inline int get_byte_order()
28 {                // 1 if little endian
29         return (*(const u_int32_t*)"a   ") & 0x00000001;
30 }
31
32 #define SWAP_ITERATE \
33         byte1 = buffer1[i]; \
34         byte2 = buffer2[i]; \
35         buffer1[i] = byte2; \
36         buffer2[i] = byte1; \
37         i += 2;
38
39 #define SWAP_24BIT_ITERATE \
40         byte1 = buffer1[i]; \
41         byte2 = buffer2[i]; \
42         byte3 = buffer3[i]; \
43         buffer1[i] = byte3; \
44         buffer2[i] = byte2; \
45         buffer3[i] = byte1; \
46         i += 3;
47
48 #define SWAP_32BIT_ITERATE \
49         byte1 = buffer1[i]; \
50         byte2 = buffer2[i]; \
51         byte3 = buffer3[i]; \
52         byte4 = buffer4[i]; \
53         buffer1[i] = byte4; \
54         buffer2[i] = byte1; \
55         buffer3[i] = byte2; \
56         buffer4[i] = byte3; \
57         i += 4;
58
59 inline int swap_bytes(int wordsize, unsigned char *buffer, long len)
60 {
61         unsigned char byte1, byte2, byte3, byte4;
62         unsigned char *buffer1 = buffer;
63         unsigned char *buffer2 = buffer + 1;
64         unsigned char *buffer3 = buffer + 2;
65         unsigned char *buffer4 = buffer + 3;
66         long i = 0;
67
68 //printf("swap bytes\n");
69
70         switch( wordsize ) {
71         case 1:
72                 return 0;
73
74         case 2:
75                 len -= 8;
76                 while( i < len ) {
77                         SWAP_ITERATE
78                         SWAP_ITERATE
79                         SWAP_ITERATE
80                         SWAP_ITERATE
81                 }
82
83                 len += 8;
84                 while( i < len ) {
85                         SWAP_ITERATE
86                 }
87                 return 0;
88
89         case 3:
90                 len -= 12;
91                 while( i < len ) {
92                         SWAP_24BIT_ITERATE
93                         SWAP_24BIT_ITERATE
94                         SWAP_24BIT_ITERATE
95                         SWAP_24BIT_ITERATE
96                 }
97
98                 len += 12;
99                 while( i < len ) {
100                         SWAP_24BIT_ITERATE
101                 }
102                 return 0;
103
104         case 4:
105                 len -= 16;
106                 while( i < len ) {
107                         SWAP_32BIT_ITERATE
108                         SWAP_32BIT_ITERATE
109                         SWAP_32BIT_ITERATE
110                         SWAP_32BIT_ITERATE
111                 }
112
113                 len += 16;
114                 while( i < len ) {
115                         SWAP_32BIT_ITERATE
116                 }
117                 return 0;
118         }
119
120         return 1;
121 }
122
123 #endif