axl_rle_encode
This commit is contained in:
parent
035de52e31
commit
ffc22e74c0
2 changed files with 54 additions and 0 deletions
44
axl_rle.c
Normal file
44
axl_rle.c
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
#include "axl_rle.h"
|
||||||
|
#include "axl_vlq.h"
|
||||||
|
#include "axl_memory.h"
|
||||||
|
|
||||||
|
u32 axl_rle_encode(const u8* src, u32 src_size, u8* dst, u32 dst_size)
|
||||||
|
{
|
||||||
|
u8 vlq_buff[AXL_VLQ_MAX_LEN];
|
||||||
|
const u8* head = src;
|
||||||
|
u32 used_size = 0;
|
||||||
|
|
||||||
|
while(head < src + src_size)
|
||||||
|
{
|
||||||
|
const u8 value = *head;
|
||||||
|
u32 count = 0;
|
||||||
|
|
||||||
|
while(head < src + src_size && *head == value)
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
head++;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 vlq_len = axl_vlq_encode(count, vlq_buff);
|
||||||
|
u32 req_size = vlq_len + 1;
|
||||||
|
|
||||||
|
if(req_size + used_size > dst_size)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
axl_memcpy(dst, vlq_buff, vlq_len);
|
||||||
|
dst += vlq_len;
|
||||||
|
axl_memcpy(dst, &value, 1);
|
||||||
|
dst += 1;
|
||||||
|
|
||||||
|
used_size += req_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
return used_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 axl_rle_decode(const u8* src, u32 src_size, u8* dst, u32 dst_size)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
10
axl_rle.h
Normal file
10
axl_rle.h
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
#ifndef AXL_RLE_H
|
||||||
|
#define AXL_RLE_H
|
||||||
|
|
||||||
|
#include "axl_types.h"
|
||||||
|
|
||||||
|
u32 axl_rle_encode(const u8* src, u32 src_size, u8* dst, u32 dst_size);
|
||||||
|
u32 axl_rle_decode(const u8* src, u32 src_size, u8* dst, u32 dst_size);
|
||||||
|
|
||||||
|
#endif // !AXL_RLE_H
|
||||||
|
|
||||||
Loading…
Reference in a new issue