[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 Hentai를 무료로 생성하십시오.

인기 기사
R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
1 몇 달 전By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 최고의 그래픽 설정
1 몇 달 전By尊渡假赌尊渡假赌尊渡假赌
어 ass 신 크리드 그림자 : 조개 수수께끼 솔루션
3 몇 주 전ByDDD
Windows 11 KB5054979의 새로운 기능 및 업데이트 문제를 해결하는 방법
2 몇 주 전ByDDD
Will R.E.P.O. 크로스 플레이가 있습니까?
1 몇 달 전By尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

PhpStorm 맥 버전
최신(2018.2.1) 전문 PHP 통합 개발 도구

Eclipse용 SAP NetWeaver 서버 어댑터
Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

SublimeText3 영어 버전
권장 사항: Win 버전, 코드 프롬프트 지원!

Atom Editor Mac 버전 다운로드
가장 인기 있는 오픈 소스 편집기

Dreamweaver Mac版
시각적 웹 개발 도구
