-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsta_bits.h
More file actions
420 lines (294 loc) · 7.55 KB
/
sta_bits.h
File metadata and controls
420 lines (294 loc) · 7.55 KB
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
#ifdef STA_PUBLIC_API
/*
#define STA_BITS_IMPLEMENTATION
#include "sta-main/sta_bits.h"
*/
a_bool a_u8_get_bit(uint8_t b,int bit_num);
void a_u8_set_bit(uint8_t * b,int bit_num,a_bool v);
int a_u8_get_2_bits(uint8_t b,int bit_num);
a_bool a_get_bit(const uint8_t * bits,int loc);
void a_set_bit(uint8_t * bits,int loc,int v);
void a_set_2_bits(uint8_t * bits,int loc,a_bool v,a_bool v2);
//++ left and right(r) side
a_bool a_inc_bits(uint8_t * bits,int max_bits);
a_bool a_inc_bits_r(uint8_t * bits,int max_bits);
// A Project By Arshad Latti
#endif
#ifndef STA_DEF_H_
#define STA_DEF_H_
#ifndef STA_NO_STDINT_H
#include <stdint.h>
#endif
/*
//#define STA_NO_STDINT_H
//#define STA_COMPILER_VC_6
#ifdef STA_COMPILER_VC_6
#include "stdint-vc6.h"
#endif
*/
#define a_bool int
#define a_true 1
#define a_false 0
#define a_null 0
// PACKED
/*
A_PACKED_BEGIN
struct disk_data
{
char x;
int y;
}A_PACKED;
A_PACKED_END
*/
#ifndef STA_PACKED_OPTIONS
//auto detect compiler
#define STA_PACKED_OPTIONS
#define STA_PACKED_COMPILER_GCC
//#define STA_PACKED_COMPILER_MSVC
//#define STA_PACKED_COMPILER_TCC
#endif
#ifdef STA_PACKED_COMPILER_GCC
#define A_PACKED_BEGIN
#define A_PACKED_END
#define A_PACKED __attribute__((packed))
#endif
#ifdef STA_PACKED_COMPILER_MSVC
#define A_PACKED_BEGIN #pragma pack( push,1 )
#define A_PACKED_END #pragma pack( pop )
#define A_PACKED
#endif
// Framebuffer Image
#define framebuffer_pixel_t uint32_t
struct s_framebuffer_image
{
framebuffer_pixel_t * pixels;
int32_t h,w,pitch;//all in pixels
};
typedef struct s_framebuffer_image framebuffer_image_t;
//AV_PIX_FMT_BGRA
struct s_framebuffer_color
{
uint8_t b;
uint8_t g;
uint8_t r;
uint8_t a;
};
typedef struct s_framebuffer_color framebuffer_color_t;
//
struct s_clip_rect
{
int32_t x,y,h,w;
};
typedef struct s_clip_rect clip_rect_t;
struct s_a_rect
{
int32_t x,y,x2,y2;
};
typedef struct s_a_rect a_rect_t;
struct s_a_rect_size
{
int h,w;
};
typedef struct s_a_rect_size a_rect_size_t;
struct s_a_point
{
int x,y;
};
typedef struct s_a_point a_point_t;
typedef struct s_a_date_time a_date_time_t;
struct s_a_date_time
{
uint16_t year;
uint8_t month;
uint8_t day;//date
uint8_t hour;
uint8_t minute;
uint8_t second;
uint8_t flags;// bit 1.0=utc 2.0=24hr 3.0=date valid 4.0=time valid 5.0valid 6-8=resvered FF=not valid
};
//
#define A_MIN(a,b) ((a) < (b) ? (a) : (b))
#define A_MAX(a,b) ((a) < (b) ? (b) : (a))
#define A_KB(k) ((k) * 1024)
#define A_MB(mb) (A_KB((mb) * 1024))
#define A_GB(gb) (A_MB((gb) * 1024))
#define A_TB(tb) (A_GB((tb) * 1024))
//if.not if.index
#define if_not(expr) if(!(expr))
#define if_index(expr) if((expr) >= 0)
#define for_i(i_max) int i; for(i=0;i<i_max;i++)
#define for_i_(i_max) for(i=0;i<i_max;i++)
#define for_var(i,i_max) int i; for(i=0;i<i_max;i++)
#define for_var_(i,i_max) for(i=0;i<i_max;i++)
// for_j
#define for_j(x_max) for_var(j,x_max)
#define for_j_(x_max) for_var_(j,x_max)
// for_k
#define for_k(x_max) for_var(k,x_max)
#define for_k_(x_max) for_var_(k,x_max)
// for_x for_y
#define for_x(x_max) int x; for(x=0;x<x_max;x++)
#define for_x_(x_max) for(x=0;x<x_max;x++)
#define for_y(y_max) int y; for(y=0;y<y_max;y++)
#define for_y_(y_max) for(y=0;y<y_max;y++)
// #define for_i_xy(w,h) int i_x,i_y,i_xy,i_xy_max; i_xy_max = w*h; for(i_xy=0;i_xy < i_xy_max;i_xy++
// use }}
// #define for_xy_next }}
#define next_xy }}
#define for_xy(w,h) int i_x,i_y;\
for(i_y = 0; i_y < h ; i_y++){\
for(i_x = 0; i_x < w ; i_x++){
#define for_xy_(w,h) for(i_y = 0; i_y < h ; i_y++){\
for(i_x = 0; i_x < w ; i_x++){
#define for_fi(fi) for_xy(fi->w,fi->h)
#define for_fi_(fi) for_xy_(fi->w,fi->h)
#define next_fi }
#define for_i_cc(s) int cc = strlen(s); int i; for(i=0;i<cc;i++)
#define for_i_cc_(s) cc = strlen(s); for(i=0;i<cc;i++)
//#define for_cc(s) for_i_cc(s)
#define return_if_null(expr) if(!(expr)) return 0
#define return_if_zero(expr) if(!(expr)) return 0
#define return_if_fail(expr) if((expr) != 0) return 0
#define return_if_not_find(expr) if((expr) < 0) return 0
// ptr
//#define if
#define if_null(expr) if(!(expr))
//status
#define if_success(expr) if((expr) == 0)
#define if_fail(expr) if((expr) != 0)
//index
#define if_not_find(expr) if((expr) < 0)
#define if_find(expr) if((expr) >=0)
#define puts_i(i) printf("%i\n",i);
#define puts_s_i(s,i) printf("%s %i\n",s,i);
#define IFF(expr,on_true,on_false) ((expr)? on_true : on_false)
#define bitwise_and(a,b) ((a)&(b))
#define bitwise_or(a,b) ((a)|(b))
#define bitwise_xor(a,b) ((a)^(b))
#define bitwise_not(a) (~(a))
#define bitwise_shift_left(a,n) ((a) << (n))
#define bitwise_shift_right(a,n) ((a) >> (n))
#define logical_and(a,b) ((a)&&(b))
#define logical_or(a,b) ((a)||(b))
#define logical_not(a) (!(a))
//#define A_DEBUG_PUTS
#ifdef A_DEBUG_PUTS
#define dputs_i(i) printf("%i\n",i);
#define dputs_s_i(s,i) printf("%s %i\n",s,i);
#endif
#define argc_msg(num,msg) if(argc < num){puts(msg); return 0;}
//todo expr = 0;
#define free_safe(expr) {if(expr) free(expr);}
/* verbose_printf */
//#define A_VERBOSE_PRINTF
#ifdef A_VERBOSE_PRINTF
#define verbose_printf printf
#else
#define verbose_printf(expr,...)
#endif
#endif
#ifndef STA_BITS_H
#define STA_BITS_H
//#include "STA/sta_def.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
#define STA_BITS_IMPLEMENTATION
#include "sta-main/sta_bits.h"
*/
a_bool a_u8_get_bit(uint8_t b,int bit_num);
void a_u8_set_bit(uint8_t * b,int bit_num,a_bool v);
int a_u8_get_2_bits(uint8_t b,int bit_num);
a_bool a_get_bit(const uint8_t * bits,int loc);
void a_set_bit(uint8_t * bits,int loc,int v);
void a_set_2_bits(uint8_t * bits,int loc,a_bool v,a_bool v2);
//++ left and right(r) side
a_bool a_inc_bits(uint8_t * bits,int max_bits);
a_bool a_inc_bits_r(uint8_t * bits,int max_bits);
// A Project By Arshad Latti
#ifdef __cplusplus
}
#endif
#endif
#ifdef STA_BITS_IMPLEMENTATION
#ifndef STA_BITS_IMPLEMENTATION_INCLUDED
#define STA_BITS_IMPLEMENTATION_INCLUDED
#ifdef __cplusplus
extern "C" {
#endif
a_bool a_get_bit(const uint8_t * bits,int loc)
{
return a_u8_get_bit(bits[loc/8],loc%8);
}
a_bool a_inc_bits(uint8_t * bits,int max_bits)
{
int i;
for(i=0;i<max_bits;i++)
{
if(a_get_bit(bits,i))
{
a_set_bit(bits,i,0);
}
else
{
a_set_bit(bits,i,1);
return a_true;
}
}
return a_false;
}
a_bool a_inc_bits_r(uint8_t * bits,int max_bits)
{
if(!max_bits) return a_false;
int i;
for(i=max_bits-1;i>=0;i--)
{
if(a_get_bit(bits,i))
{
a_set_bit(bits,i,0);
}
else
{
a_set_bit(bits,i,1);
return a_true;
}
}
return a_false;
}
void a_set_2_bits(uint8_t * bits,int loc,a_bool v,a_bool v2)
{
a_set_bit(bits,loc,v);
a_set_bit(bits,loc+1,v2);
}
void a_set_bit(uint8_t * bits,int loc,int v)
{
a_u8_set_bit(&bits[loc/8],loc%8,v);
}
int a_u8_get_2_bits(uint8_t b,int bit_num)
{
int index = 0;
if(a_u8_get_bit(b,bit_num))
index = 2;
if(a_u8_get_bit(b,bit_num+1))
index += 1;
return index;
}
a_bool a_u8_get_bit(uint8_t b,int bit_num)
{
if( b & (1<<bit_num))
return a_true;
return a_false;
}
void a_u8_set_bit(uint8_t * b,int bit_num,a_bool v)
{
if(v)
b[0] |= 1 << bit_num;
else
b[0] &= ~(1 << bit_num);
}
#ifdef __cplusplus
}
#endif
#endif
#endif