2023-07-24 23:13:47 -07:00
|
|
|
#include "base85.h"
|
|
|
|
using std::vector;
|
|
|
|
// Functions modified from Dear ImGui and renamed to avoid collisions.
|
|
|
|
static unsigned int DecodeBase85Byte(char c) {
|
|
|
|
return c >= '\\' ? c-36 : c-35;
|
|
|
|
}
|
|
|
|
vector<unsigned char> DecodeBase85(const char *src) {
|
|
|
|
vector<unsigned char> dst_vec;
|
2024-09-28 10:31:06 -07:00
|
|
|
dst_vec.resize(((strlen(src) + 4) / 5) * 4);
|
2023-07-24 23:13:47 -07:00
|
|
|
unsigned char *dst = dst_vec.data();
|
|
|
|
size_t dst_size = 0;
|
|
|
|
while (*src)
|
|
|
|
{
|
|
|
|
unsigned int tmp = DecodeBase85Byte(src[0]) + 85 * (DecodeBase85Byte(src[1]) + 85 * (DecodeBase85Byte(src[2]) + 85 * (DecodeBase85Byte(src[3]) + 85 * DecodeBase85Byte(src[4]))));
|
|
|
|
dst[0] = ((tmp >> 0) & 0xFF); dst[1] = ((tmp >> 8) & 0xFF); dst[2] = ((tmp >> 16) & 0xFF); dst[3] = ((tmp >> 24) & 0xFF); // We can't assume little-endianness.
|
|
|
|
src += 5;
|
2024-09-28 10:31:06 -07:00
|
|
|
dst += 4;
|
2023-07-24 23:13:47 -07:00
|
|
|
dst_size += 4;
|
|
|
|
}
|
|
|
|
dst_vec.resize(dst_size);
|
|
|
|
return dst_vec;
|
|
|
|
}
|