-
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.
1. 使用新算法,大幅提升编解码速度。 2. 新算法不向后兼容,但在大部分情况下可保证接近的结果。 3. 如果想使用旧算法,请前往github仓库页面的traditional_ver文件夹中自行编译使用
- Loading branch information
Showing
22 changed files
with
483 additions
and
215 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Binary file not shown.
Binary file not shown.
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
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,4 @@ | ||
cmake_minimum_required(VERSION 3.0.0) | ||
project(base1432 VERSION 2.0) | ||
|
||
add_library(base1432 ./base1432le.c) |
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,151 @@ | ||
//base1432le.c | ||
//fumiama 20210408 | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include "base1432le.h" | ||
|
||
//#define DEBUG | ||
|
||
LENDAT* encode(const uint8_t* data, const u_int32_t len) { | ||
LENDAT* encd = (LENDAT*)malloc(sizeof(LENDAT)); | ||
uint32_t outlen = len / 7 * 8; | ||
uint8_t offset = len % 7; | ||
switch(offset) { //算上偏移标志字符占用的2字节 | ||
case 0: break; | ||
case 1: outlen += 4; break; | ||
case 2: | ||
case 3: outlen += 6; break; | ||
case 4: | ||
case 5: outlen += 8; break; | ||
case 6: outlen += 10; break; | ||
default: break; | ||
} | ||
#ifdef DEBUG | ||
printf("outlen: %llu, offset: %u, malloc: %llu\n", outlen, offset, outlen + 8); | ||
#endif | ||
encd->data = (uint8_t*)malloc(outlen + 8); //冗余的8B用于可能的结尾的覆盖 | ||
encd->len = outlen; | ||
uint32_t* vals = (uint32_t*)(encd->data); | ||
uint32_t n = 0; | ||
uint32_t i = 0; | ||
for(; i < len; i += 7) { | ||
register uint32_t sum = 0x0000003f & ((uint32_t)data[i] >> 2); | ||
sum |= ((((uint32_t)data[i + 1] >> 2) | (data[i] << 6)) << 8) & 0x0000ff00; | ||
sum |= ((((uint32_t)data[i + 1] << 4) | ((uint32_t)data[i + 2] >> 4)) << 16) & 0x003f0000; | ||
sum |= ((((uint32_t)data[i + 2] << 4) | ((uint32_t)data[i + 3] >> 4)) << 24) & 0xff000000; | ||
sum += 0x004e004e; | ||
vals[n++] = sum; | ||
#ifdef DEBUG | ||
printf("n: %u, add sum: %08x\n", n, sum); | ||
#endif | ||
sum = ((((uint32_t)data[i + 3] << 2) | ((uint32_t)data[i + 4] >> 6))) & 0x0000003f; | ||
sum |= ((((uint32_t)data[i + 4] << 2) | ((uint32_t)data[i + 5] >> 6)) << 8) & 0x0000ff00; | ||
sum |= ((uint32_t)data[i + 5] << 16) & 0x003f0000; | ||
sum |= ((uint32_t)data[i + 6] << 24) & 0xff000000; | ||
sum += 0x004e004e; | ||
vals[n++] = sum; | ||
#ifdef DEBUG | ||
printf("n: %u, add sum: %08x\n", n, sum); | ||
#endif | ||
} | ||
if(offset > 0) { | ||
register uint32_t sum = 0x0000003f & (data[i] >> 2); | ||
sum |= (((uint32_t)data[i] << 6) << 8) & 0x0000c000; | ||
if(offset > 1) { | ||
sum |= (((uint32_t)data[i + 1] >> 2) << 8) & 0x00003f00; | ||
sum |= (((uint32_t)data[i + 1] << 4) << 16) & 0x00300000; | ||
if(offset > 2) { | ||
sum |= (((uint32_t)data[i + 2] >> 4) << 16) & 0x000f0000; | ||
sum |= (((uint32_t)data[i + 2] << 4) << 24) & 0xf0000000; | ||
if(offset == 2) { | ||
sum += 0x004e004e; | ||
vals[n++] = sum; | ||
} | ||
if(offset > 3) { | ||
sum |= (((uint32_t)data[i + 3] >> 4) << 24) & 0x0f000000; | ||
sum += 0x004e004e; | ||
vals[n++] = sum; | ||
sum = (((uint32_t)data[i + 3] << 2)) & 0x0000003c; | ||
if(offset > 4) { | ||
sum |= (((uint32_t)data[i + 4] >> 6)) & 0x00000003; | ||
sum |= (((uint32_t)data[i + 4] << 2) << 8) & 0x0000fc00; | ||
if(offset > 5) { | ||
sum |= (((uint32_t)data[i + 5] >> 6) << 8) & 0x00000300; | ||
sum |= ((uint32_t)data[i + 5] << 16) & 0x003f0000; | ||
} | ||
} | ||
sum += 0x004e004e; | ||
vals[n] = sum; | ||
} | ||
} | ||
} | ||
encd->data[outlen - 2] = '='; | ||
encd->data[outlen - 1] = offset; | ||
} | ||
return encd; | ||
} | ||
|
||
LENDAT* decode(const uint8_t* data, const u_int32_t len) { | ||
LENDAT* decd = (LENDAT*)malloc(sizeof(LENDAT)); | ||
uint32_t outlen = len; | ||
uint8_t offset = 0; | ||
if(data[len-2] == '=') { | ||
offset = data[len-1]; | ||
switch(offset) { //算上偏移标志字符占用的2字节 | ||
case 0: break; | ||
case 1: outlen -= 4; break; | ||
case 2: | ||
case 3: outlen -= 6; break; | ||
case 4: | ||
case 5: outlen -= 8; break; | ||
case 6: outlen -= 10; break; | ||
default: break; | ||
} | ||
} | ||
outlen = outlen / 8 * 7 + offset; | ||
decd->data = (uint8_t*)malloc(outlen); | ||
decd->len = outlen; | ||
uint32_t* vals = (uint32_t*)data; | ||
uint32_t n = 0; | ||
uint32_t i = 0; | ||
for(; n < len / 4; n++) { //n实际每次自增2 | ||
register uint32_t sum = vals[n++]; | ||
sum -= 0x004e004e; | ||
decd->data[i++] = ((sum & 0x0000003f) << 2) | ((sum & 0x0000c000) >> 14); | ||
decd->data[i++] = ((sum & 0x00003f00) >> 6) | ((sum & 0x00300000) >> 20); | ||
decd->data[i++] = ((sum & 0x000f0000) >> 12) | ((sum & 0xf0000000) >> 28); | ||
decd->data[i] = ((sum & 0x0f000000) >> 20); | ||
sum = vals[n]; | ||
sum -= 0x004e004e; | ||
decd->data[i++] |= ((sum & 0x0000003c) >> 2); | ||
decd->data[i++] = ((sum & 0x00000003) << 6) | ((sum & 0x0000fc00) >> 10); | ||
decd->data[i++] = ((sum & 0x00000300) >> 2) | ((sum & 0x003f0000) >> 16); | ||
decd->data[i++] = ((sum & 0xff000000) >> 24); | ||
} | ||
if(offset > 0) { | ||
register uint32_t sum = vals[n++]; | ||
sum -= 0x0000004e; | ||
decd->data[i++] = ((sum & 0x0000003f) << 2) | ((sum & 0x0000c000) >> 14); | ||
if(offset > 1) { | ||
sum -= 0x004e0000; | ||
decd->data[i++] = ((sum & 0x00003f00) >> 6) | ((sum & 0x00300000) >> 20); | ||
if(offset > 2) { | ||
decd->data[i++] = ((sum & 0x000f0000) >> 12) | ((sum & 0xf0000000) >> 28); | ||
if(offset > 3) { | ||
decd->data[i++] = (sum & 0x0f000000) >> 20; | ||
sum = vals[n]; | ||
sum -= 0x0000004e; | ||
decd->data[i++] |= (sum & 0x0000003c) >> 2; | ||
if(offset > 4) { | ||
decd->data[i++] = ((sum & 0x00000003) << 6) | ((sum & 0x0000fc00) >> 10); | ||
if(offset > 5) { | ||
sum -= 0x004e0000; | ||
decd->data[i++] = ((sum & 0x00000300) >> 2) | ((sum & 0x003f0000) >> 16); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return decd; | ||
} |
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,13 @@ | ||
//base1432le.h | ||
//fumiama 20210408 | ||
#include <stdint.h> | ||
|
||
#define B14BUFSIZ 8192 | ||
struct LENDAT { | ||
uint8_t* data; | ||
uint32_t len; | ||
}; | ||
typedef struct LENDAT LENDAT; | ||
|
||
LENDAT* encode(const uint8_t* data, const u_int32_t len); | ||
LENDAT* decode(const uint8_t* data, const u_int32_t len); |
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,4 @@ | ||
cmake_minimum_required(VERSION 3.0.0) | ||
project(base1464 VERSION 2.0) | ||
|
||
add_library(base1464 ./base1464le.c) |
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,138 @@ | ||
//base1464le.c | ||
//fumiama 20210407 | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include "base1464le.h" | ||
|
||
//#define DEBUG | ||
|
||
LENDAT* encode(const uint8_t* data, const u_int64_t len) { | ||
LENDAT* encd = (LENDAT*)malloc(sizeof(LENDAT)); | ||
uint64_t outlen = len / 7 * 8; | ||
uint8_t offset = len % 7; | ||
switch(offset) { //算上偏移标志字符占用的2字节 | ||
case 0: break; | ||
case 1: outlen += 4; break; | ||
case 2: | ||
case 3: outlen += 6; break; | ||
case 4: | ||
case 5: outlen += 8; break; | ||
case 6: outlen += 10; break; | ||
default: break; | ||
} | ||
#ifdef DEBUG | ||
printf("outlen: %llu, offset: %u, malloc: %llu\n", outlen, offset, outlen + 8); | ||
#endif | ||
encd->data = (uint8_t*)malloc(outlen + 8); //冗余的8B用于可能的结尾的覆盖 | ||
encd->len = outlen; | ||
uint64_t* vals = (uint64_t*)(encd->data); | ||
uint64_t n = 0; | ||
uint64_t i = 0; | ||
for(; i < len; i += 7) { | ||
register uint64_t sum = 0x000000000000003f & ((uint64_t)data[i] >> 2); | ||
sum |= ((((uint64_t)data[i + 1] >> 2) | (data[i] << 6)) << 8) & 0x000000000000ff00; | ||
sum |= ((((uint64_t)data[i + 1] << 4) | ((uint64_t)data[i + 2] >> 4)) << 16) & 0x00000000003f0000; | ||
sum |= ((((uint64_t)data[i + 2] << 4) | ((uint64_t)data[i + 3] >> 4)) << 24) & 0x00000000ff000000; | ||
sum |= ((((uint64_t)data[i + 3] << 2) | ((uint64_t)data[i + 4] >> 6)) << 32) & 0x0000003f00000000; | ||
sum |= ((((uint64_t)data[i + 4] << 2) | ((uint64_t)data[i + 5] >> 6)) << 40) & 0x0000ff0000000000; | ||
sum |= ((uint64_t)data[i + 5] << 48) & 0x003f000000000000; | ||
sum |= ((uint64_t)data[i + 6] << 56) & 0xff00000000000000; | ||
sum += 0x004e004e004e004e; | ||
vals[n++] = sum; | ||
#ifdef DEBUG | ||
printf("i: %llu, add sum: %016llx\n", i, sum); | ||
#endif | ||
} | ||
if(offset > 0) { | ||
register uint64_t sum = 0x000000000000003f & (data[i] >> 2); | ||
sum |= (((uint64_t)data[i] << 6) << 8) & 0x000000000000c000; | ||
if(offset > 1) { | ||
sum |= (((uint64_t)data[i + 1] >> 2) << 8) & 0x0000000000003f00; | ||
sum |= (((uint64_t)data[i + 1] << 4) << 16) & 0x0000000000300000; | ||
if(offset > 2) { | ||
sum |= (((uint64_t)data[i + 2] >> 4) << 16) & 0x00000000000f0000; | ||
sum |= (((uint64_t)data[i + 2] << 4) << 24) & 0x00000000f0000000; | ||
if(offset > 3) { | ||
sum |= (((uint64_t)data[i + 3] >> 4) << 24) & 0x000000000f000000; | ||
sum |= (((uint64_t)data[i + 3] << 2) << 32) & 0x0000003c00000000; | ||
if(offset > 4) { | ||
sum |= (((uint64_t)data[i + 4] >> 6) << 32) & 0x0000000300000000; | ||
sum |= (((uint64_t)data[i + 4] << 2) << 40) & 0x0000fc0000000000; | ||
if(offset > 5) { | ||
sum |= (((uint64_t)data[i + 5] >> 6) << 40) & 0x0000030000000000; | ||
sum |= ((uint64_t)data[i + 5] << 48) & 0x003f000000000000; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
sum += 0x004e004e004e004e; | ||
vals[n] = sum; | ||
#ifdef DEBUG | ||
printf("i: %llu, add sum: %016llx\n", i, sum); | ||
#endif | ||
encd->data[outlen - 2] = '='; | ||
encd->data[outlen - 1] = offset; | ||
} | ||
return encd; | ||
} | ||
|
||
LENDAT* decode(const uint8_t* data, const u_int64_t len) { | ||
LENDAT* decd = (LENDAT*)malloc(sizeof(LENDAT)); | ||
uint64_t outlen = len; | ||
uint8_t offset = 0; | ||
if(data[len-2] == '=') { | ||
offset = data[len-1]; | ||
switch(offset) { //算上偏移标志字符占用的2字节 | ||
case 0: break; | ||
case 1: outlen -= 4; break; | ||
case 2: | ||
case 3: outlen -= 6; break; | ||
case 4: | ||
case 5: outlen -= 8; break; | ||
case 6: outlen -= 10; break; | ||
default: break; | ||
} | ||
} | ||
outlen = outlen / 8 * 7 + offset; | ||
decd->data = (uint8_t*)malloc(outlen); | ||
decd->len = outlen; | ||
uint64_t* vals = (uint64_t*)data; | ||
uint64_t n = 0; | ||
uint64_t i = 0; | ||
for(; n < len / 8; n++) { | ||
register uint64_t sum = vals[n]; | ||
sum -= 0x004e004e004e004e; | ||
decd->data[i++] = ((sum & 0x000000000000003f) << 2) | ((sum & 0x000000000000c000) >> 14); | ||
decd->data[i++] = ((sum & 0x0000000000003f00) >> 6) | ((sum & 0x0000000000300000) >> 20); | ||
decd->data[i++] = ((sum & 0x00000000000f0000) >> 12) | ((sum & 0x00000000f0000000) >> 28); | ||
decd->data[i++] = ((sum & 0x000000000f000000) >> 20) | ((sum & 0x0000003c00000000) >> 34); | ||
decd->data[i++] = ((sum & 0x0000000300000000) >> 26) | ((sum & 0x0000fc0000000000) >> 42); | ||
decd->data[i++] = ((sum & 0x0000030000000000) >> 34) | ((sum & 0x003f000000000000) >> 48); | ||
decd->data[i++] = ((sum & 0xff00000000000000) >> 56); | ||
} | ||
if(offset > 0) { | ||
register uint64_t sum = vals[n]; | ||
sum -= 0x000000000000004e; | ||
decd->data[i++] = ((sum & 0x000000000000003f) << 2) | ((sum & 0x000000000000c000) >> 14); | ||
if(offset > 1) { | ||
sum -= 0x00000000004e0000; | ||
decd->data[i++] = ((sum & 0x0000000000003f00) >> 6) | ((sum & 0x0000000000300000) >> 20); | ||
if(offset > 2) { | ||
decd->data[i++] = ((sum & 0x00000000000f0000) >> 12) | ((sum & 0x00000000f0000000) >> 28); | ||
if(offset > 3) { | ||
sum -= 0x0000004e00000000; | ||
decd->data[i++] = ((sum & 0x000000000f000000) >> 20) | ((sum & 0x0000003c00000000) >> 34); | ||
if(offset > 4) { | ||
decd->data[i++] = ((sum & 0x0000000300000000) >> 26) | ((sum & 0x0000fc0000000000) >> 42); | ||
if(offset > 5) { | ||
sum -= 0x004e000000000000; | ||
decd->data[i++] = ((sum & 0x0000030000000000) >> 34) | ((sum & 0x003f000000000000) >> 48); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return decd; | ||
} |
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,13 @@ | ||
//base1464le.h | ||
//fumiama 20210408 | ||
#include <stdint.h> | ||
|
||
#define B14BUFSIZ 16384 | ||
struct LENDAT { | ||
uint8_t* data; | ||
uint64_t len; | ||
}; | ||
typedef struct LENDAT LENDAT; | ||
|
||
LENDAT* encode(const uint8_t* data, const u_int64_t len); | ||
LENDAT* decode(const uint8_t* data, const u_int64_t len); |
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,19 @@ | ||
cmake_minimum_required(VERSION 3.10.2) | ||
|
||
project("base16384") | ||
|
||
add_library(base14 SHARED base16384.cpp) | ||
|
||
add_library(base14c STATIC base16384.c) | ||
|
||
IF(CMAKE_SIZEOF_VOID_P EQUAL 8) | ||
add_definitions("-DCPUBIT64") | ||
add_subdirectory("./64") | ||
target_link_libraries(base14c base1464) | ||
ELSE() | ||
add_definitions("-DCPUBIT32") | ||
add_subdirectory("./32") | ||
target_link_libraries(base14c base1432) | ||
ENDIF() | ||
|
||
target_link_libraries(base14 base14c) |
Oops, something went wrong.