18910140161

lz77图像压缩算法代码,我如何LZ77,LZM等算法压缩字符串?

顺晟科技

2022-09-29 10:20:57

118

PHP 和 JS 相互传输压缩字符串

有个小项目,专门PHP和小程序传输像素数据,数据如下

String = "100100FF00AA200300F1F1F1150001F9F9F9"
分解 100100FF00AA 200300F1F1F1 150001F9F9F9
意思 100x100 RGB FF00AA

组成 字符串的只有16进制

参考 LZW算法压缩字符串数据

function LZW_compress(text){
    const dict = { 0: '零', 1: '一', 2: '二' }, result = []
    let temp = "", UTFCode = 25165 // 汉字笔画较少的区间开始
    text.split("").reduce((prev, cur)=>{
        const string = prev + cur
        if(dict[string]) temp = string;
        else{
            dict[string] = String.fromCharCode(UTFCode++);
            result.push(dict[prev]);
            temp = cur.toString();
        }
        return temp
    }, "")
    if(temp) result.push(dict[temp]);
    return result.join("");
}

现在 有点小蒙圈了 不知道怎么压缩好了,请大家给点算法思路,谢谢大家

相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航