<?xml version="1.0" encoding="utf-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: LZW compression methods in AS2</title>
	<atom:link href="http://www.razorberry.com/blog/archives/2004/08/22/lzw-compression-methods-in-as2/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.razorberry.com/blog/archives/2004/08/22/lzw-compression-methods-in-as2/</link>
	<description>since 2004!</description>
	<pubDate>Fri, 21 Nov 2008 21:37:55 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: Yehia</title>
		<link>http://www.razorberry.com/blog/archives/2004/08/22/lzw-compression-methods-in-as2/#comment-3157</link>
		<dc:creator>Yehia</dc:creator>
		<pubDate>Wed, 16 Jul 2008 16:46:44 +0000</pubDate>
		<guid isPermaLink="false">/?p=5#comment-3157</guid>
		<description>People PLEASE, I am suffering here, any of the above php code doesn't decode correctly. is that relevant to code page or what  that is different on the server than my client ? the character codes are the root of evil. the numbers i get for the same string on AS2 is different than Php. my solution has to be AS2 based.

Please email me back
yehia.shouman@gmail.com</description>
		<content:encoded><![CDATA[<p>People PLEASE, I am suffering here, any of the above php code doesn&#8217;t decode correctly. is that relevant to code page or what  that is different on the server than my client ? the character codes are the root of evil. the numbers i get for the same string on AS2 is different than Php. my solution has to be AS2 based.</p>
<p>Please email me back<br />
<a href="mailto:yehia.shouman@gmail.com">yehia.shouman@gmail.com</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: venkateshwarlu</title>
		<link>http://www.razorberry.com/blog/archives/2004/08/22/lzw-compression-methods-in-as2/#comment-3090</link>
		<dc:creator>venkateshwarlu</dc:creator>
		<pubDate>Mon, 05 May 2008 07:56:53 +0000</pubDate>
		<guid isPermaLink="false">/?p=5#comment-3090</guid>
		<description>:roll: yeh this is great example for compression and uncompress of data
 using LZW algorithm iwant the C#.net implementation of the LZW algorithm so that i can compress in flex and un compress in c#
and again compress in c# an un compress in Flex</description>
		<content:encoded><![CDATA[<p> <img src='http://www.razorberry.com/blog/wp-includes/images/smilies/icon_rolleyes.gif' alt=':roll:' class='wp-smiley' /> yeh this is great example for compression and uncompress of data<br />
 using LZW algorithm iwant the C#.net implementation of the LZW algorithm so that i can compress in flex and un compress in c#<br />
and again compress in c# an un compress in Flex</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: axaq</title>
		<link>http://www.razorberry.com/blog/archives/2004/08/22/lzw-compression-methods-in-as2/#comment-3035</link>
		<dc:creator>axaq</dc:creator>
		<pubDate>Tue, 18 Mar 2008 15:01:40 +0000</pubDate>
		<guid isPermaLink="false">/?p=5#comment-3035</guid>
		<description>Hi, 
I have used the code you have modified on FP9 and I get the slow down error when tried to compress a bitmap image data. 
I have the hexadecimal data of a bitmap image and I want to compress this data. Can you help me about this? Is there any thing to optimize the compressor?

thanks</description>
		<content:encoded><![CDATA[<p>Hi,<br />
I have used the code you have modified on FP9 and I get the slow down error when tried to compress a bitmap image data.<br />
I have the hexadecimal data of a bitmap image and I want to compress this data. Can you help me about this? Is there any thing to optimize the compressor?</p>
<p>thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ash</title>
		<link>http://www.razorberry.com/blog/archives/2004/08/22/lzw-compression-methods-in-as2/#comment-2313</link>
		<dc:creator>Ash</dc:creator>
		<pubDate>Thu, 24 Jan 2008 15:01:51 +0000</pubDate>
		<guid isPermaLink="false">/?p=5#comment-2313</guid>
		<description>Excellent! Thanks Billy.</description>
		<content:encoded><![CDATA[<p>Excellent! Thanks Billy.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: billy</title>
		<link>http://www.razorberry.com/blog/archives/2004/08/22/lzw-compression-methods-in-as2/#comment-2312</link>
		<dc:creator>billy</dc:creator>
		<pubDate>Thu, 24 Jan 2008 02:00:29 +0000</pubDate>
		<guid isPermaLink="false">/?p=5#comment-2312</guid>
		<description>This is pretty much a literal translation into php and works for me.

You may need some extra libraries (for mb_* calls)

Here are the tricky parts to porting to PHP:
1.  ord/chr in php don't handle unicode (I've included two functions thanks to the community on php.net)
2.  after preg_splitting with //g (to split unicode), there is a blank item in the beginning and end of the array (which i pop and shift off)
3.  I give this code without any warranty of its validity -- check everything before you use in production

function encode_lzw($str)
{
  $dico = array();

  for ($i = 0; $i &#60; 256; $i++)
  {
    $dico[unichr($i)] = $i;
  }

  $res = "";
  $len = strlen($str);
  $nbChar = 256;
  $buffer = "";

  for ($i = 0; $i &#60;= $len; $i++)
  {
    $current = $str[$i];
    if ($i &#60; strlen($str) &#38;&#38; $dico[$buffer . $current] !== null)
    {
      $buffer .= $current;
    }
    else
    {
      $res .= unichr($dico[$buffer]);
      $dico[$buffer . $current] = $nbChar;
      $nbChar++;
      $buffer = $current;
    }
  }

  return $res;
}

function decode_lzw($str)
{
  $dico = array();

  for ($i = 0; $i &#60; 256; $i++)
  {
    $c = unichr($i);
    $dico[$i] = $c;
  }

  $nbChar = 256;
  $buffer = "";
  $chaine = "";
  $result = "";
  $strSplit = preg_split('//u', $str);
  array_pop($strSplit);
  array_shift($strSplit);

  $length   = count($strSplit);

  for ($i = 0; $i &#60; $length; $i++)
  {
    $code = uniord($strSplit[$i]);
    $current = $dico[$code];
    if ($buffer == "")
    {
      $buffer = $current;
      $result .= $current;
    }
    else
    {
      if ($code &#60;= 255)
      {
        $result .= $current;
        $chaine = $buffer . $current;
        $dico[$nbChar] = $chaine;
        $nbChar++;
        $buffer = $current;
      }
      else
      {
        $chaine = $dico[$code];
        if ($chaine == "") $chaine = $buffer . $buffer[0];
        $result .= $chaine;
        $dico[$nbChar] = $buffer . $chaine[0];
        $nbChar++;
        $buffer = $chaine;
      }
    }
  }

  return $result;
}

function unichr($u)
{
  $str = html_entity_decode('&#38;#'.$u.';',ENT_NOQUOTES,'UTF-8');
  return $str;
}

function uniord($u) {
  $k = mb_convert_encoding($u, 'UCS-2LE', 'UTF-8');
  $k1 = ord(substr($k, 0, 1));
  $k2 = ord(substr($k, 1, 1));
  return $k2 * 256 + $k1;
}</description>
		<content:encoded><![CDATA[<p>This is pretty much a literal translation into php and works for me.</p>
<p>You may need some extra libraries (for mb_* calls)</p>
<p>Here are the tricky parts to porting to PHP:<br />
1.  ord/chr in php don&#8217;t handle unicode (I&#8217;ve included two functions thanks to the community on php.net)<br />
2.  after preg_splitting with //g (to split unicode), there is a blank item in the beginning and end of the array (which i pop and shift off)<br />
3.  I give this code without any warranty of its validity &#8212; check everything before you use in production</p>
<p>function encode_lzw($str)<br />
{<br />
  $dico = array();</p>
<p>  for ($i = 0; $i &lt; 256; $i++)<br />
  {<br />
    $dico[unichr($i)] = $i;<br />
  }</p>
<p>  $res = &#8220;&#8221;;<br />
  $len = strlen($str);<br />
  $nbChar = 256;<br />
  $buffer = &#8220;&#8221;;</p>
<p>  for ($i = 0; $i &lt;= $len; $i++)<br />
  {<br />
    $current = $str[$i];<br />
    if ($i &lt; strlen($str) &amp;&amp; $dico[$buffer . $current] !== null)<br />
    {<br />
      $buffer .= $current;<br />
    }<br />
    else<br />
    {<br />
      $res .= unichr($dico[$buffer]);<br />
      $dico[$buffer . $current] = $nbChar;<br />
      $nbChar++;<br />
      $buffer = $current;<br />
    }<br />
  }</p>
<p>  return $res;<br />
}</p>
<p>function decode_lzw($str)<br />
{<br />
  $dico = array();</p>
<p>  for ($i = 0; $i &lt; 256; $i++)<br />
  {<br />
    $c = unichr($i);<br />
    $dico[$i] = $c;<br />
  }</p>
<p>  $nbChar = 256;<br />
  $buffer = &#8220;&#8221;;<br />
  $chaine = &#8220;&#8221;;<br />
  $result = &#8220;&#8221;;<br />
  $strSplit = preg_split(&#8217;//u&#8217;, $str);<br />
  array_pop($strSplit);<br />
  array_shift($strSplit);</p>
<p>  $length   = count($strSplit);</p>
<p>  for ($i = 0; $i &lt; $length; $i++)<br />
  {<br />
    $code = uniord($strSplit[$i]);<br />
    $current = $dico[$code];<br />
    if ($buffer == &#8220;&#8221;)<br />
    {<br />
      $buffer = $current;<br />
      $result .= $current;<br />
    }<br />
    else<br />
    {<br />
      if ($code &lt;= 255)<br />
      {<br />
        $result .= $current;<br />
        $chaine = $buffer . $current;<br />
        $dico[$nbChar] = $chaine;<br />
        $nbChar++;<br />
        $buffer = $current;<br />
      }<br />
      else<br />
      {<br />
        $chaine = $dico[$code];<br />
        if ($chaine == &#8220;&#8221;) $chaine = $buffer . $buffer[0];<br />
        $result .= $chaine;<br />
        $dico[$nbChar] = $buffer . $chaine[0];<br />
        $nbChar++;<br />
        $buffer = $chaine;<br />
      }<br />
    }<br />
  }</p>
<p>  return $result;<br />
}</p>
<p>function unichr($u)<br />
{<br />
  $str = html_entity_decode(&#8217;&amp;#&#8217;.$u.&#8217;;',ENT_NOQUOTES,&#8217;UTF-8&#8242;);<br />
  return $str;<br />
}</p>
<p>function uniord($u) {<br />
  $k = mb_convert_encoding($u, &#8216;UCS-2LE&#8217;, &#8216;UTF-8&#8242;);<br />
  $k1 = ord(substr($k, 0, 1));<br />
  $k2 = ord(substr($k, 1, 1));<br />
  return $k2 * 256 + $k1;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eros</title>
		<link>http://www.razorberry.com/blog/archives/2004/08/22/lzw-compression-methods-in-as2/#comment-2291</link>
		<dc:creator>Eros</dc:creator>
		<pubDate>Thu, 03 Jan 2008 13:26:15 +0000</pubDate>
		<guid isPermaLink="false">/?p=5#comment-2291</guid>
		<description>Hi man,
We could really use a decompression algorithm for PHP, able to decompress a string compressed with your AS class...</description>
		<content:encoded><![CDATA[<p>Hi man,<br />
We could really use a decompression algorithm for PHP, able to decompress a string compressed with your AS class&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Amit</title>
		<link>http://www.razorberry.com/blog/archives/2004/08/22/lzw-compression-methods-in-as2/#comment-2192</link>
		<dc:creator>Amit</dc:creator>
		<pubDate>Tue, 23 Oct 2007 11:57:08 +0000</pubDate>
		<guid isPermaLink="false">/?p=5#comment-2192</guid>
		<description>Hi, 
I have a problem. I have compressed data in AS2 at client side and compressed in using LZW(Flash) and send it to server, but when we decompress over server using java decompression (mentioned at - Server-side (Java) decompression
http://www.geocities.com/yccheok/lzw/lzw.html), it doesnt decompress properly.

If i compress and decompress in same environment(Flash to Flash or Java to Java ) then it is going ok.

Any help is appreciated.

~Amit</description>
		<content:encoded><![CDATA[<p>Hi,<br />
I have a problem. I have compressed data in AS2 at client side and compressed in using LZW(Flash) and send it to server, but when we decompress over server using java decompression (mentioned at - Server-side (Java) decompression<br />
<a href="http://www.geocities.com/yccheok/lzw/lzw.html" rel="nofollow">http://www.geocities.com/yccheok/lzw/lzw.html</a>), it doesnt decompress properly.</p>
<p>If i compress and decompress in same environment(Flash to Flash or Java to Java ) then it is going ok.</p>
<p>Any help is appreciated.</p>
<p>~Amit</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Element</title>
		<link>http://www.razorberry.com/blog/archives/2004/08/22/lzw-compression-methods-in-as2/#comment-2080</link>
		<dc:creator>Element</dc:creator>
		<pubDate>Fri, 17 Aug 2007 09:29:07 +0000</pubDate>
		<guid isPermaLink="false">/?p=5#comment-2080</guid>
		<description>Do you have decompress function on PHP?
Thx~ :cry:</description>
		<content:encoded><![CDATA[<p>Do you have decompress function on PHP?<br />
Thx~ <img src='http://www.razorberry.com/blog/wp-includes/images/smilies/icon_cry.gif' alt=':cry:' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cauê</title>
		<link>http://www.razorberry.com/blog/archives/2004/08/22/lzw-compression-methods-in-as2/#comment-2047</link>
		<dc:creator>Cauê</dc:creator>
		<pubDate>Tue, 31 Jul 2007 17:52:05 +0000</pubDate>
		<guid isPermaLink="false">/?p=5#comment-2047</guid>
		<description>Man... I LOVE YOU.. Ahuahuhau...
TNKSSSS!!!!!!!! TNKS!!!!!!!!!!!!!!!!!
Easy to use and powerfull!!!!
Tnks!</description>
		<content:encoded><![CDATA[<p>Man&#8230; I LOVE YOU.. Ahuahuhau&#8230;<br />
TNKSSSS!!!!!!!! TNKS!!!!!!!!!!!!!!!!!<br />
Easy to use and powerfull!!!!<br />
Tnks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hassaan</title>
		<link>http://www.razorberry.com/blog/archives/2004/08/22/lzw-compression-methods-in-as2/#comment-1981</link>
		<dc:creator>hassaan</dc:creator>
		<pubDate>Wed, 13 Jun 2007 12:19:54 +0000</pubDate>
		<guid isPermaLink="false">/?p=5#comment-1981</guid>
		<description>No one replied yet have any body information regarding my problem:roll:</description>
		<content:encoded><![CDATA[<p>No one replied yet have any body information regarding my problem:roll:</p>
]]></content:encoded>
	</item>
</channel>
</rss>
