]> git.sesse.net Git - fjl/blob - unstuff.h
The bit source needs to actually consume the data it passes by...
[fjl] / unstuff.h
1 #ifndef _UNSTUFF_H
2 #define _UNSTUFF_H 1
3
4 #include <stdbool.h>
5 #include <stddef.h>
6 #include <stdint.h>
7
8 // Copies from src to dst, removing all instances of 0xFF 0xF0.
9 //
10 // Returns:
11 //   Number of bytes written to dst if successful.
12 //   -1 if a marker was encountered (0xFF followed by something else than 0xF0).
13 //   -1 if the last byte of "src" was 0xFF. 
14
15 typedef int (unstuff_func_t)(uint8_t*, const uint8_t*, size_t);
16
17 // Slow reference function.
18 int unstuff_reference(uint8_t* dst, const uint8_t* src, size_t len);
19
20 // Faster version (assuming few stuff bytes), using C standard library
21 // functions (that are hopefully more efficient, assuming few stuff bytes)
22 // to find the markers.
23 // Slightly over twice as fast as unstuff_reference().
24 int unstuff_fast(uint8_t* dst, const uint8_t* src, size_t len);
25
26 // SSE4.1 version working on 16 bytes at a time.
27 // 5-10% faster than unstuff_fast().
28 int unstuff_sse41(uint8_t* dst, const uint8_t* src, size_t len);
29
30 #endif /* !defined(_UNSTUFF_H) */