[PHP]代码
<?php /** * @link http://www.php.cn/ * @author Jakub Vrana, http://www.php.cn/ * @copyright 2009 Jakub Vrana * @license http://www.php.cn/ Apache License, Version 2.0 */ /** LZW compression * @param string data to compress * @return string binary data */ function lzw_compress($string) { // compression $dict = array_flip(range("\0", "\xFF")); $dict_size = 256; $word = $string[0]; $dict_count = 256; $bits = 8; $bits_max = 256; $return = ""; $rest = 0; $rest_length = 0; for ($i = 1, $j = strlen($string); $i < $j; $i++) { $x = $string[$i]; $y = $word . $x; if (isset($dict[$y])) { $word .= $x; } else { $rest = ($rest << $bits) + $dict[$word]; $rest_length += $bits; $dict_count++; if ($dict_count > $bits_max) { $bits_max = 1 << ++$bits; } while ($rest_length > 7) { $rest_length -= 8; $return .= chr($rest >> $rest_length); $rest &= (1 << $rest_length) - 1; } $dict[$y] = $dict_size++; $word = $x; } } $rest = ($rest << $bits) + $dict[$word]; $rest_length += $bits; $dict_count++; if ($dict_count > $bits_max) { $bits_max = 1 << ++$bits; } while ($rest_length > 0) { if($rest_length>7){ $rest_length -= 8; $return .= chr($rest >> $rest_length); $rest &= (1 << $rest_length) - 1; }else{ $return .= chr($rest << (8 - $rest_length)); $rest_length = 0; } } return $return; } /** LZW decompression * @param string compressed binary data * @return string original data */ function lzw_decompress($binary) { // convert binary string to codes $rest = 0; $rest_length = 0; $out_count = 257; $bits = 9; $bits_max = 512; // decompression $dict = range("\0", "\xFF"); $w = $binary[0]; $return = $w; for ($i = 1, $j = strlen($binary); $i < $j; $i++) { $rest = ($rest << 8) + ord($binary[$i]); $rest_length += 8; if ($rest_length >= $bits) { $rest_length -= $bits; // decompression $e = $dict[$rest >> $rest_length]; if (!isset($e)) { $e = $w . $w[0]; } $return .= $e; $dict[] = $w . $e[0]; $w = $e; //--decompression $rest &= (1 << $rest_length) - 1; if (++$out_count > $bits_max) { $bits_max = 1 << ++$bits; } } } return $return; } ?>
声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事
R.E.P.O.説明されたエネルギー結晶と彼らが何をするか(黄色のクリスタル)
3週間前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最高のグラフィック設定
3週間前By尊渡假赌尊渡假赌尊渡假赌
アサシンのクリードシャドウズ:シーシェルリドルソリューション
2週間前ByDDD
R.E.P.O.誰も聞こえない場合はオーディオを修正する方法
3週間前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:Myriseのすべてのロックを解除する方法
3週間前By尊渡假赌尊渡假赌尊渡假赌

ホットツール

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境

AtomエディタMac版ダウンロード
最も人気のあるオープンソースエディター

Safe Exam Browser
Safe Exam Browser は、オンライン試験を安全に受験するための安全なブラウザ環境です。このソフトウェアは、あらゆるコンピュータを安全なワークステーションに変えます。あらゆるユーティリティへのアクセスを制御し、学生が無許可のリソースを使用するのを防ぎます。

SublimeText3 Linux 新バージョン
SublimeText3 Linux 最新バージョン

SublimeText3 中国語版
中国語版、とても使いやすい
