| 1 |
#ifndef RLE6_H_ |
| 2 |
#define RLE6_H_ |
| 3 |
|
| 4 |
#include <stdint.h> |
| 5 |
|
| 6 |
#ifdef __GNUC__ |
| 7 |
#define LIKELY(x) __builtin_expect((x),1) |
| 8 |
#else |
| 9 |
#define LIKELY(x) (x) |
| 10 |
#endif |
| 11 |
#ifdef __cplusplus |
| 12 |
|
| 13 |
extern "C" { |
| 14 |
#endif |
| 15 |
|
| 16 |
int rle_insert_cached(uint8_t *block, int64_t x, int a, int64_t rl, int64_t cnt[6], const int64_t ec[6], int *beg, int64_t bc[6]); |
| 17 |
int rle_insert(uint8_t *block, int64_t x, int a, int64_t rl, int64_t cnt[6], const int64_t end_cnt[6]); |
| 18 |
void rle_split(uint8_t *block, uint8_t *new_block); |
| 19 |
void rle_count(const uint8_t *block, int64_t cnt[6]); |
| 20 |
void rle_rank2a(const uint8_t *block, int64_t x, int64_t y, int64_t *cx, int64_t *cy, const int64_t ec[6]); |
| 21 |
#define rle_rank1a(block, x, cx, ec) rle_rank2a(block, x, -1, cx, 0, ec) |
| 22 |
|
| 23 |
void rle_print(const uint8_t *block, int expand); |
| 24 |
|
| 25 |
#ifdef __cplusplus |
| 26 |
} |
| 27 |
#endif |
| 28 |
|
| 29 |
/****************** |
| 30 |
*** 43+3 codec *** |
| 31 |
******************/ |
| 32 |
|
| 33 |
extern const uint8_t rle_auxtab[8]; |
| 34 |
|
| 35 |
#define RLE_MIN_SPACE 18 |
| 36 |
#define rle_nptr(block) ((uint16_t*)(block)) |
| 37 |
|
| 38 |
// decode one run (c,l) and move the pointer p |
| 39 |
#define rle_dec1(p, c, l) do { \ |
| 40 |
(c) = *(p) & 7; \ |
| 41 |
if (LIKELY((*(p)&0x80) == 0)) { \ |
| 42 |
(l) = *(p)++ >> 3; \ |
| 43 |
} else if (LIKELY(*(p)>>5 == 6)) { \ |
| 44 |
(l) = (*(p)&0x18L)<<3L | ((p)[1]&0x3fL); \ |
| 45 |
(p) += 2; \ |
| 46 |
} else { \ |
| 47 |
int n = ((*(p)&0x10) >> 2) + 4; \ |
| 48 |
(l) = *(p)++ >> 3 & 1; \ |
| 49 |
while (--n) (l) = ((l)<<6) | (*(p)++&0x3fL); \ |
| 50 |
} \ |
| 51 |
} while (0) |
| 52 |
|
| 53 |
static inline int rle_enc1(uint8_t *p, int c, int64_t l) |
| 54 |
{ |
| 55 |
if (l < 1LL<<4) { |
| 56 |
*p = l << 3 | c; |
| 57 |
return 1; |
| 58 |
} else if (l < 1LL<<8) { |
| 59 |
*p = 0xC0 | l >> 6 << 3 | c; |
| 60 |
p[1] = 0x80 | (l & 0x3f); |
| 61 |
return 2; |
| 62 |
} else if (l < 1LL<<19) { |
| 63 |
*p = 0xE0 | l >> 18 << 3 | c; |
| 64 |
p[1] = 0x80 | (l >> 12 & 0x3f); |
| 65 |
p[2] = 0x80 | (l >> 6 & 0x3f); |
| 66 |
p[3] = 0x80 | (l & 0x3f); |
| 67 |
return 4; |
| 68 |
} else { |
| 69 |
int i, shift = 36; |
| 70 |
*p = 0xF0 | l >> 42 << 3 | c; |
| 71 |
for (i = 1; i < 8; ++i, shift -= 6) |
| 72 |
p[i] = 0x80 | (l>>shift & 0x3f); |
| 73 |
return 8; |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
#endif |