101 #define IMPLEMENT_RLE_COMPR_FN(name, datatype_t, max_value) \
102 int name(datatype_t* output_buf, size_t* output_size, \
103 const datatype_t* input_buf, size_t input_size) \
105 size_t true_output_size = 0; \
106 size_t input_idx = 0; \
108 if (output_buf == NULL || output_size == NULL \
109 || input_buf == NULL) \
112 if (input_size == 0) { \
114 return PCOMP_STAT_SUCCESS; \
117 if (*output_size < 2) { \
118 return PCOMP_STAT_INVALID_BUFFER; \
121 while (input_idx < input_size) { \
122 datatype_t first_datum_in_the_run = input_buf[input_idx]; \
123 datatype_t count = 0; \
124 while (count < max_value && input_idx < input_size \
125 && input_buf[input_idx] \
126 == first_datum_in_the_run) { \
131 if (true_output_size >= *output_size - 2) { \
132 return PCOMP_STAT_INVALID_BUFFER; \
135 output_buf[true_output_size++] = count; \
136 output_buf[true_output_size++] = first_datum_in_the_run; \
139 *output_size = true_output_size; \
140 return PCOMP_STAT_SUCCESS; \
302 #define IMPLEMENT_RLE_DECOMPR_FN(name, datatype_t) \
303 int name(datatype_t* output_buf, size_t output_size, \
304 const datatype_t* input_buf, size_t input_size) \
306 size_t input_idx = 0; \
307 size_t output_idx = 0; \
309 if (output_buf == NULL || input_buf == NULL) \
312 if (input_size == 0) { \
313 return PCOMP_STAT_SUCCESS; \
316 if (input_size % 2 != 0) { \
317 return PCOMP_STAT_INVALID_ENCODING; \
320 while (output_idx < output_size \
321 && input_idx < input_size - 1) { \
322 datatype_t count = input_buf[input_idx]; \
323 datatype_t value = input_buf[input_idx + 1]; \
326 for (idx = 0; idx < count; ++idx) { \
327 output_buf[output_idx++] = value; \
333 return PCOMP_STAT_SUCCESS; \
336 IMPLEMENT_RLE_DECOMPR_FN(pcomp_decompress_rle_int8, int8_t)
337 IMPLEMENT_RLE_DECOMPR_FN(pcomp_decompress_rle_int16, int16_t)
338 IMPLEMENT_RLE_DECOMPR_FN(pcomp_decompress_rle_int32, int32_t)
339 IMPLEMENT_RLE_DECOMPR_FN(pcomp_decompress_rle_int64, int64_t)
341 IMPLEMENT_RLE_DECOMPR_FN(pcomp_decompress_rle_uint8, uint8_t)
342 IMPLEMENT_RLE_DECOMPR_FN(pcomp_decompress_rle_uint16, uint16_t)
343 IMPLEMENT_RLE_DECOMPR_FN(pcomp_decompress_rle_uint32, uint32_t)
344 IMPLEMENT_RLE_DECOMPR_FN(pcomp_decompress_rle_uint64, uint64_t)
int pcomp_compress_rle_int16(int16_t *output_buf, size_t *output_size, const int16_t *input_buf, size_t input_size)
Compress an array of int16_t values using the RLE compression.
int pcomp_compress_rle_int32(int32_t *output_buf, size_t *output_size, const int32_t *input_buf, size_t input_size)
Compress an array of int32_t values using the RLE compression.
size_t pcomp_rle_bufsize(size_t input_size)
Calculate an upper limit for the size of a buffer holding RLE-encoded streams.
int pcomp_compress_rle_uint64(uint64_t *output_buf, size_t *output_size, const uint64_t *input_buf, size_t input_size)
Compress an array of uint64_t values using the RLE compression.
int pcomp_compress_rle_uint16(uint16_t *output_buf, size_t *output_size, const uint16_t *input_buf, size_t input_size)
Compress an array of uint16_t values using the RLE compression.
int pcomp_compress_rle_int64(int64_t *output_buf, size_t *output_size, const int64_t *input_buf, size_t input_size)
Compress an array of int64_t values using the RLE compression.
int pcomp_compress_rle_int8(int8_t *output_buf, size_t *output_size, const int8_t *input_buf, size_t input_size)
Compress an array of int8_t values using the RLE compression.
int pcomp_compress_rle_uint32(uint32_t *output_buf, size_t *output_size, const uint32_t *input_buf, size_t input_size)
Compress an array of uint32_t values using the RLE compression.
int pcomp_compress_rle_uint8(uint8_t *output_buf, size_t *output_size, const uint8_t *input_buf, size_t input_size)
Compress an array of uint8_t values using the RLE compression.
Header file for Libpolycomp.