-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
123 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "algo-heatshrink.h" | ||
|
||
#include "../lib/heatshrink/heatshrink_common.h" | ||
#include "../lib/heatshrink/heatshrink_encoder.h" | ||
#include "../lib/heatshrink/heatshrink_decoder.h" | ||
|
||
static heatshrink_decoder dec; | ||
static heatshrink_encoder enc; | ||
|
||
void heatshrink_init() | ||
{ | ||
heatshrink_decoder_reset(&dec); | ||
heatshrink_encoder_reset(&enc); | ||
} | ||
|
||
void heatshrink_compress(uint8_t *input, size_t insize, uint8_t *output, size_t *outsize) | ||
{ | ||
heatshrink_encoder_reset(&enc); | ||
|
||
size_t sunk = 0; | ||
size_t polled = 0; | ||
size_t count = 0; | ||
size_t comp_sz = *outsize; | ||
while (sunk < insize) { | ||
heatshrink_encoder_sink(&enc, &input[sunk], insize - sunk, &count); | ||
sunk += count; | ||
if (sunk == insize) { | ||
heatshrink_encoder_finish(&enc); | ||
} | ||
|
||
HSE_poll_res pres; | ||
do { | ||
pres = heatshrink_encoder_poll(&enc, &output[polled], comp_sz - polled, &count); | ||
polled += count; | ||
} while (pres == HSER_POLL_MORE); | ||
if (sunk == insize) { | ||
heatshrink_encoder_finish(&enc); | ||
} | ||
} | ||
|
||
*outsize = polled; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef __ALGO_HEATSHRINK_H__ | ||
#define __ALGO_HEATSHRINK_H__ | ||
|
||
#include "pico/stdlib.h" | ||
|
||
void heatshrink_init(); | ||
void heatshrink_compress(uint8_t* input, size_t insize, uint8_t* output, size_t* outsize); | ||
|
||
#endif // __ALGO_HEATSHRINK_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters