-
Notifications
You must be signed in to change notification settings - Fork 1
/
mpp_common.h
216 lines (181 loc) · 7.53 KB
/
mpp_common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
* Copyright 2015 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_COMMON_H__
#define __MPP_COMMON_H__
#include "rk_type.h"
#define MPP_TAG_SIZE 32
#define MPP_ABS(x) ((x) < (0) ? -(x) : (x))
#define MPP_MAX(a, b) ((a) > (b) ? (a) : (b))
#define MPP_MAX3(a, b, c) MPP_MAX(MPP_MAX(a,b),c)
#define MPP_MAX4(a, b, c, d) MPP_MAX((a), MPP_MAX3((b), (c), (d)))
#define MPP_MIN(a,b) ((a) > (b) ? (b) : (a))
#define MPP_MIN3(a,b,c) MPP_MIN(MPP_MIN(a,b),c)
#define MPP_MIN4(a, b, c, d) MPP_MIN((a), MPP_MIN3((b), (c), (d)))
#define MPP_DIV(a, b) ((b) ? (a) / (b) : (a))
#define MPP_CLIP3(l, h, v) ((v) < (l) ? (l) : ((v) > (h) ? (h) : (v)))
#define MPP_SIGN(a) ((a) < (0) ? (-1) : (1))
#define MPP_DIV_SIGN(a, b) (((a) + (MPP_SIGN(a) * (b)) / 2) / (b))
#define MPP_SWAP(type, a, b) do {type SWAP_tmp = b; b = a; a = SWAP_tmp;} while(0)
#define MPP_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0]))
#define MPP_ALIGN(x, a) (((x)+(a)-1)&~((a)-1))
#define MPP_VSWAP(a, b) { a ^= b; b ^= a; a ^= b; }
#define MPP_RB16(x) ((((const RK_U8*)(x))[0] << 8) | ((const RK_U8*)(x))[1])
#define MPP_WB16(p, d) do { \
((RK_U8*)(p))[1] = (d); \
((RK_U8*)(p))[0] = (d)>>8; } while(0)
#define MPP_RL16(x) ((((const RK_U8*)(x))[1] << 8) | \
((const RK_U8*)(x))[0])
#define MPP_WL16(p, d) do { \
((RK_U8*)(p))[0] = (d); \
((RK_U8*)(p))[1] = (d)>>8; } while(0)
#define MPP_RB32(x) ((((const RK_U8*)(x))[0] << 24) | \
(((const RK_U8*)(x))[1] << 16) | \
(((const RK_U8*)(x))[2] << 8) | \
((const RK_U8*)(x))[3])
#define MPP_WB32(p, d) do { \
((RK_U8*)(p))[3] = (d); \
((RK_U8*)(p))[2] = (d)>>8; \
((RK_U8*)(p))[1] = (d)>>16; \
((RK_U8*)(p))[0] = (d)>>24; } while(0)
#define MPP_RL32(x) ((((const RK_U8*)(x))[3] << 24) | \
(((const RK_U8*)(x))[2] << 16) | \
(((const RK_U8*)(x))[1] << 8) | \
((const RK_U8*)(x))[0])
#define MPP_WL32(p, d) do { \
((RK_U8*)(p))[0] = (d); \
((RK_U8*)(p))[1] = (d)>>8; \
((RK_U8*)(p))[2] = (d)>>16; \
((RK_U8*)(p))[3] = (d)>>24; } while(0)
#define MPP_RB64(x) (((RK_U64)((const RK_U8*)(x))[0] << 56) | \
((RK_U64)((const RK_U8*)(x))[1] << 48) | \
((RK_U64)((const RK_U8*)(x))[2] << 40) | \
((RK_U64)((const RK_U8*)(x))[3] << 32) | \
((RK_U64)((const RK_U8*)(x))[4] << 24) | \
((RK_U64)((const RK_U8*)(x))[5] << 16) | \
((RK_U64)((const RK_U8*)(x))[6] << 8) | \
(RK_U64)((const RK_U8*)(x))[7])
#define MPP_WB64(p, d) do { \
((RK_U8*)(p))[7] = (d); \
((RK_U8*)(p))[6] = (d)>>8; \
((RK_U8*)(p))[5] = (d)>>16; \
((RK_U8*)(p))[4] = (d)>>24; \
((RK_U8*)(p))[3] = (d)>>32; \
((RK_U8*)(p))[2] = (d)>>40; \
((RK_U8*)(p))[1] = (d)>>48; \
((RK_U8*)(p))[0] = (d)>>56; } while(0)
#define MPP_RL64(x) (((RK_U64)((const RK_U8*)(x))[7] << 56) | \
((RK_U64)((const RK_U8*)(x))[6] << 48) | \
((RK_U64)((const RK_U8*)(x))[5] << 40) | \
((RK_U64)((const RK_U8*)(x))[4] << 32) | \
((RK_U64)((const RK_U8*)(x))[3] << 24) | \
((RK_U64)((const RK_U8*)(x))[2] << 16) | \
((RK_U64)((const RK_U8*)(x))[1] << 8) | \
(RK_U64)((const RK_U8*)(x))[0])
#define MPP_WL64(p, d) do { \
((RK_U8*)(p))[0] = (d); \
((RK_U8*)(p))[1] = (d)>>8; \
((RK_U8*)(p))[2] = (d)>>16; \
((RK_U8*)(p))[3] = (d)>>24; \
((RK_U8*)(p))[4] = (d)>>32; \
((RK_U8*)(p))[5] = (d)>>40; \
((RK_U8*)(p))[6] = (d)>>48; \
((RK_U8*)(p))[7] = (d)>>56; } while(0)
#define MPP_RB24(x) ((((const RK_U8*)(x))[0] << 16) | \
(((const RK_U8*)(x))[1] << 8) | \
((const RK_U8*)(x))[2])
#define MPP_WB24(p, d) do { \
((RK_U8*)(p))[2] = (d); \
((RK_U8*)(p))[1] = (d)>>8; \
((RK_U8*)(p))[0] = (d)>>16; } while(0)
#define MPP_RL24(x) ((((const RK_U8*)(x))[2] << 16) | \
(((const RK_U8*)(x))[1] << 8) | \
((const RK_U8*)(x))[0])
#define MPP_WL24(p, d) do { \
((RK_U8*)(p))[0] = (d); \
((RK_U8*)(p))[1] = (d)>>8; \
((RK_U8*)(p))[2] = (d)>>16; } while(0)
#include <stdio.h>
#if defined(_WIN32) && !defined(__MINGW32CE__)
#define snprintf _snprintf
#define fseeko _fseeki64
#include <direct.h>
#include <io.h>
#include <sys/stat.h>
#define chdir _chdir
#define mkdir _mkdir
#define access _access
#define off_t _off_t
#define R_OK 4 /* Test for read permission. */
#define W_OK 2 /* Test for write permission. */
#define X_OK 1 /* Test for execute permission. */
#define F_OK 0 /* Test for existence. */
#elif defined(__MINGW32CE__)
#define fseeko fseeko64
#else
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#define mkdir(x) mkdir(x, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
#endif
#define __RETURN __Return
#define __FAILED __failed
#define ARG_T(t) t
#define ARG_N(a,b,c,d,N,...) N
#define ARG_N_HELPER(...) ARG_T(ARG_N(__VA_ARGS__))
#define COUNT_ARG(...) ARG_N_HELPER(__VA_ARGS__,4,3,2,1,0)
#define SZ_1K (1024)
#define SZ_2K (SZ_1K*2)
#define SZ_4K (SZ_1K*4)
#define SZ_8K (SZ_1K*8)
#define SZ_16K (SZ_1K*16)
#define SZ_32K (SZ_1K*32)
#define SZ_64K (SZ_1K*64)
#define SZ_128K (SZ_1K*128)
#define SZ_256K (SZ_1K*256)
#define SZ_512K (SZ_1K*512)
#define SZ_1M (SZ_1K*SZ_1K)
#define SZ_2M (SZ_1M*2)
#define SZ_4M (SZ_1M*4)
#define SZ_8M (SZ_1M*8)
#define SZ_16M (SZ_1M*16)
#define SZ_32M (SZ_1M*32)
#define SZ_64M (SZ_1M*64)
#define SZ_80M (SZ_1M*80)
#define SZ_128M (SZ_1M*128)
#ifdef __cplusplus
extern "C" {
#endif
RK_S32 mpp_log2(RK_U32 v);
RK_S32 mpp_log2_16bit(RK_U32 v);
static __inline RK_S32 mpp_ceil_log2(RK_S32 x)
{
return mpp_log2((x - 1) << 1);
}
static __inline RK_S32 mpp_clip(RK_S32 a, RK_S32 amin, RK_S32 amax)
{
if (a < amin) return amin;
else if (a > amax) return amax;
else return a;
}
static __inline RK_U32 mpp_is_32bit()
{
return ((sizeof(void *) == 4) ? (1) : (0));
}
RK_S32 axb_div_c(RK_S32 a, RK_S32 b, RK_S32 c);
#ifdef __cplusplus
}
#endif
#endif /*__MPP_COMMON_H__*/