-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_example.c
35 lines (29 loc) · 879 Bytes
/
test_example.c
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
/*
RLE ZOO single-header library example.
Copyright (c) 2022, Eddy L O Jansson. Licensed under The MIT License.
See https://github.com/eloj/rle-zoo
*/
#include <stdio.h>
#include <stdint.h>
#include <sys/types.h>
#define RLE_ZOO_PACKBITS_IMPLEMENTATION
#include "rle_packbits.h"
int main(void) {
const uint8_t input[] = "ABBCCCDDDDEEEEE";
size_t len = sizeof(input) - 1;
// Call with NULL for dest buffer to calculate output size.
// ssize_t compressed_size = packbits_compress(input, len, NULL, 0);
uint8_t dest[256];
ssize_t res = packbits_compress(input, len, dest, sizeof(dest));
if (res > 0) {
printf("Compressed '%s' (%zu bytes) into %zd bytes: ", input, len, res);
// Do something with the output.
for (int i = 0 ; i < res ; ++i) {
printf("%02X ", dest[i]);
}
printf("\n");
} else {
printf("Compression error: %zd\n", res);
}
return 0;
}