<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>bitmap &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/bitmap/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>Computer Algorithms: Data Compression with Bitmaps</title>
		<link>/2012/01/16/computer-algorithms-data-compression-with-bitmaps/</link>
		<comments>/2012/01/16/computer-algorithms-data-compression-with-bitmaps/#comments</comments>
		<pubDate>Mon, 16 Jan 2012 09:35:24 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[algorithms]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[bitmap]]></category>
		<category><![CDATA[bitmap compressing algorithm]]></category>
		<category><![CDATA[Bzip2]]></category>
		<category><![CDATA[Coding theory]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Data compression]]></category>
		<category><![CDATA[gif]]></category>
		<category><![CDATA[Graphics file formats]]></category>
		<category><![CDATA[image compression]]></category>
		<category><![CDATA[Information theory]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Lossless data compression]]></category>
		<category><![CDATA[Run-length encoding]]></category>
		<category><![CDATA[Technology/Internet]]></category>

		<guid isPermaLink="false">/?p=2604</guid>
		<description><![CDATA[Overview In my previous post we saw how to compress data consisting of very long runs of repeating elements. This type of compression is known as &#8220;run-length encoding&#8221; and can be very handy when transferring data with no loss. The problem is that the data must follow a specific format. Thus the string “aaaaaaaabbbbbbbb” can &#8230; <a href="/2012/01/16/computer-algorithms-data-compression-with-bitmaps/" class="more-link">Continue reading <span class="screen-reader-text">Computer Algorithms: Data Compression with Bitmaps</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2012/01/30/computer-algorithms-data-compression-with-relative-encoding/" rel="bookmark" title="Computer Algorithms: Data Compression with Relative Encoding">Computer Algorithms: Data Compression with Relative Encoding </a></li>
<li><a href="/2012/01/09/computer-algorithms-data-compression-with-run-length-encoding/" rel="bookmark" title="Computer Algorithms: Data Compression with Run-length Encoding">Computer Algorithms: Data Compression with Run-length Encoding </a></li>
<li><a href="/2012/01/23/computer-algorithms-data-compression-with-diagram-encoding-and-pattern-substitution/" rel="bookmark" title="Computer Algorithms: Data Compression with Diagram Encoding and Pattern Substitution">Computer Algorithms: Data Compression with Diagram Encoding and Pattern Substitution </a></li>
<li><a href="/2012/05/03/computer-algorithms-lossy-image-compression-with-run-length-encoding/" rel="bookmark" title="Computer Algorithms: Lossy Image Compression with Run-Length Encoding">Computer Algorithms: Lossy Image Compression with Run-Length Encoding </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Overview</h2>
<p>In <a href="/2012/01/09/computer-algorithms-data-compression-with-run-length-encoding/" title="Computer Algorithms: Data Compression with Run-length Encoding">my previous post</a> we saw how to compress data consisting of very long runs of repeating elements. This type of compression is known as &#8220;run-length encoding&#8221; and can be very handy when transferring data with no loss. The problem is that the data must follow a specific format. Thus the string <strong>“aaaaaaaabbbbbbbb”</strong> can be compressed as <strong>“a8b8”</strong>. Now a string with length 16 can be compressed as a string with length 4, which is 25% of its initial length without loosing any information. There will be a problem in case the characters (elements) were dispersed in a different way. What would happen if the characters are the same, but they don’t form long runs? What if the string was <strong>“abababababababab”</strong>? The same length, the same characters, but we cannot use run-length encoding! Indeed using this algorithm we’ll get at best the same string.</p>
<p>In this case, however, we can see another fact. The string consists of too many repeating elements, although not arranged one after another. We can compress this string with a bitmap. This means that we can save the positions of the occurrences of a given element with a sequence of bits, which can be easily converted into a decimal value. In the example above the string <strong>“abababababababab”</strong> can be compressed as <strong>“1010101010101010”</strong>, which is <strong>43690</strong> in decimals, and even better <strong>AAAA</strong> in hexadecimal. Thus the long string can be compressed. When decompressing (decoding) the message we can convert again from decimal/hexadecimal into binary and match the occurrences of the characters. Well, the example above is too simple, but let’s say only one of the characters is repeating and the rest of the string consists of different characters like this: <strong>“abacadaeafagahai”</strong>. Then we can use bitmap only for the character “a” &#8211; <strong>“1010101010101010”</strong> and compress it as <strong>“AAAA bcdefghi”</strong>. As you can see all the example strings are exactly 16 characters and that is a limitation. To use bitmaps with variable length of the data is a bit tricky and it is not always easy (if possible) to decompress it.</p>
<p><figure id="attachment_2624" style="width: 620px" class="wp-caption alignnone"><a href="/wp-content/uploads/2012/01/Run-lengthvs.BitmapCompression.png"><img src="/wp-content/uploads/2012/01/Run-lengthvs.BitmapCompression.png" alt="Bitmap Compression" title="Bitmap Compression" width="620" class="size-full wp-image-2624" srcset="/wp-content/uploads/2012/01/Run-lengthvs.BitmapCompression.png 1140w, /wp-content/uploads/2012/01/Run-lengthvs.BitmapCompression-300x160.png 300w, /wp-content/uploads/2012/01/Run-lengthvs.BitmapCompression-1024x547.png 1024w" sizes="(max-width: 1140px) 100vw, 1140px" /></a><figcaption class="wp-caption-text">Basically bitmap compression saves the positions of an element that is repeated very often in the message!</figcaption></figure><br />
<span id="more-2604"></span><br />
In the other hand bitmap compression  is not only applicable on strings. We can compress also arrays, objects or any kind of data. The example from my previous post is very suitable. Then we had to transfer a large array from a server to the client (browser) using <a href="/tag/json/" title="JSON on stoimen.com/blog">JSON</a>. The data then was very suitable for “run-length encoding”. Now let’s assume we have the same data &#8211; a set of different years, which this time are dispersed in a different way. </p>
<pre lang="PHP">
$data = array(
	0 	=> 1991,
	1 	=> 1992,
	2 	=> 1993,
	3 	=> 1994,
	4 	=> 1991,
	5 	=> 1992,
	6 	=> 1993,
	7 	=> 1992,
	8 	=> 1991,
	9 	=> 1991,
	10 	=> 1991,
	11 	=> 1992,
	12 	=> 1992,
	13 	=> 1991,
	14 	=> 1991,
	15 	=> 1992,	
	...
);
</pre>
<p>The JSON will encoded message will be the following (a simple but yet very large javascript array).</p>
<pre lang="PHP">
[1991,1992,1993,1994,1991,1992,1993,1992,1991,1991,1991,1992,1992,1991,1991,1992, ...]
</pre>
<p>However if we use bitmap compression we’ll get a &#8220;shorter&#8221; array.</p>
<pre lang="PHP">
$data = array(
	0 => array(1991, '1000100011100110'),
	1 => array(1992, '0100010100011001'),
	2 => array(1993, '0010001000000000'),
	3 => array(1994, '0001000000000000'),
);
</pre>
<p>Now the JSON is:</p>
<pre lang="PHP">
[[1991,"1000100011100110"],[1992,"0100010100011001"],[1993,"0010001000000000"],[1994,"0001000000000000"]]
</pre>
<p>It is obvious that the compression ratio is getting better and better as the uncompressed data grows. In fact, most of us know bitmap compression from images, because this algorithm is largely used for image compression. We can imagine how successful it can be when compressing black and white images (as black and white can be represented as 0 and 1s). Actually it is used for more than two colors (256 for instance) and again the level of compression is very high.</p>
<h2>Implementation</h2>
<p>The following implementation on <a href="/category/php/" title="PHP on stoimen.com">PHP</a> aims only to illustrate the bitmap compressing algorithm. As we know this algorithm can be applicable for any kind of data structures. </p>
<pre lang="PHP">
// too many repeating "a" characters
$msg = 'aazahalavaatalawacamaahakafaaaqaaaiauaacaaxaauaxaaaaaapaayatagaaoafaawayazavaaaazaaabararaaaaakakaaqaarazacajaazavanazaaaeanaaoajauaaaaaxalaraaapabataaavaaab';

function bitmap($message) 
{
	$i = 0;
	$bits = $rest = '';
	
	while ($v = $message[$i]) {
		if ($v == 'a') {
			$bits .= '1';
		} else {
			$bits .= '0';
			$rest .= $v;
		}
		$i++;
	}
	
	return number_format(bindec($bits), 0, '.', '') . $rest;;
}

echo bitmap($msg);

// uncompressed: 
acaaaaadaaaabalaaeaaaaganaaxakaavawamaasavajawaaaayaauaaadalanagaeaeamaarafalaazaaaiasaanaahaaazaraxaalaahaaawaaajasamahaajaakarapanaakaoakaanawalaacamauaamaal
// compressed:
152299251941730035874325065523548237677352452096zhlvtlwcmhkfqiucxuxpytgofwyzvzbrrkkqrzcjzvnzenojuxlrpbtvb
</pre>
<h2>Application</h2>
<p>This algorithm is very useful when there is an element in our data that repeats very often, so you need to investigate the nature of the data you want to compress. Actually because of this fact this algorithm is used for image compression as <a href="http://en.wikipedia.org/wiki/Portable_Network_Graphics" title="Portable Network Graphics" target="_blank">PNG8</a> or <a href="http://en.wikipedia.org/wiki/Graphics_Interchange_Format" title="Graphics Interchange Format" target="_blank">GIF</a>.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2012/01/30/computer-algorithms-data-compression-with-relative-encoding/" rel="bookmark" title="Computer Algorithms: Data Compression with Relative Encoding">Computer Algorithms: Data Compression with Relative Encoding </a></li>
<li><a href="/2012/01/09/computer-algorithms-data-compression-with-run-length-encoding/" rel="bookmark" title="Computer Algorithms: Data Compression with Run-length Encoding">Computer Algorithms: Data Compression with Run-length Encoding </a></li>
<li><a href="/2012/01/23/computer-algorithms-data-compression-with-diagram-encoding-and-pattern-substitution/" rel="bookmark" title="Computer Algorithms: Data Compression with Diagram Encoding and Pattern Substitution">Computer Algorithms: Data Compression with Diagram Encoding and Pattern Substitution </a></li>
<li><a href="/2012/05/03/computer-algorithms-lossy-image-compression-with-run-length-encoding/" rel="bookmark" title="Computer Algorithms: Lossy Image Compression with Run-Length Encoding">Computer Algorithms: Lossy Image Compression with Run-Length Encoding </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2012/01/16/computer-algorithms-data-compression-with-bitmaps/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Download Flex 3 bitmap with round corners</title>
		<link>/2009/03/15/download-flex-3-bitmap-with-round-corners/</link>
		<comments>/2009/03/15/download-flex-3-bitmap-with-round-corners/#comments</comments>
		<pubDate>Sun, 15 Mar 2009 14:25:13 +0000</pubDate>
		<dc:creator><![CDATA[stoimen]]></dc:creator>
				<category><![CDATA[download]]></category>
		<category><![CDATA[featured]]></category>
		<category><![CDATA[flex 3]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[bitmap]]></category>
		<category><![CDATA[round corners]]></category>

		<guid isPermaLink="false">/?p=381</guid>
		<description><![CDATA[Download a flex 3 application with two bitmaps with rounded corners.<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2009/03/15/flex-3-bitmap-with-round-corners/" rel="bookmark" title="Flex 3 bitmap with round corners">Flex 3 bitmap with round corners </a></li>
<li><a href="/2009/03/01/download-custom-flex-3-datechooser-2/" rel="bookmark" title="Download Custom Flex 3 DateChooser">Download Custom Flex 3 DateChooser </a></li>
<li><a href="/2009/03/04/flex-3-custom-preloader-download/" rel="bookmark" title="Flex 3 Custom Preloader Download">Flex 3 Custom Preloader Download </a></li>
<li><a href="/2009/02/06/flex-3-custom-preloader/" rel="bookmark" title="Flex 3 Custom Preloader">Flex 3 Custom Preloader </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>Related to the <a title="Flex 3 bitmap round corners" href="/2009/03/15/flex-3-bitmap-with-round-corners/" target="_self">post</a> with bitmaps with round corners, here&#8217;s the source code.</p>
<p><a title="Flex 3 bitmap with round corners" href="/wp-content/uploads/2009/03/rcornersmxml.zip" target="_blank">Download here</a>.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2009/03/15/flex-3-bitmap-with-round-corners/" rel="bookmark" title="Flex 3 bitmap with round corners">Flex 3 bitmap with round corners </a></li>
<li><a href="/2009/03/01/download-custom-flex-3-datechooser-2/" rel="bookmark" title="Download Custom Flex 3 DateChooser">Download Custom Flex 3 DateChooser </a></li>
<li><a href="/2009/03/04/flex-3-custom-preloader-download/" rel="bookmark" title="Flex 3 Custom Preloader Download">Flex 3 Custom Preloader Download </a></li>
<li><a href="/2009/02/06/flex-3-custom-preloader/" rel="bookmark" title="Flex 3 Custom Preloader">Flex 3 Custom Preloader </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2009/03/15/download-flex-3-bitmap-with-round-corners/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Flex 3 bitmap with round corners</title>
		<link>/2009/03/15/flex-3-bitmap-with-round-corners/</link>
		<comments>/2009/03/15/flex-3-bitmap-with-round-corners/#comments</comments>
		<pubDate>Sun, 15 Mar 2009 14:20:08 +0000</pubDate>
		<dc:creator><![CDATA[stoimen]]></dc:creator>
				<category><![CDATA[featured]]></category>
		<category><![CDATA[flex 3]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[bitmap]]></category>
		<category><![CDATA[round corners]]></category>

		<guid isPermaLink="false">/?p=377</guid>
		<description><![CDATA[How to setup round corners on a Bitmap into Flex 3.s<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2009/03/15/download-flex-3-bitmap-with-round-corners/" rel="bookmark" title="Download Flex 3 bitmap with round corners">Download Flex 3 bitmap with round corners </a></li>
<li><a href="/2010/02/17/htc-round-the-corners-on-ie/" rel="bookmark" title="HTC?! Round the corners on IE!">HTC?! Round the corners on IE! </a></li>
<li><a href="/2009/02/06/flex-3-custom-preloader/" rel="bookmark" title="Flex 3 Custom Preloader">Flex 3 Custom Preloader </a></li>
<li><a href="/2010/02/15/cross-browser-rounded-corners-works-on-ie-but-but-not-on-opera/" rel="bookmark" title="Cross-browser rounded corners! Works on IE but, but not on Opera!">Cross-browser rounded corners! Works on IE but, but not on Opera! </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>It is a common question, can it be used a bitmap into Flex with round corners.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="300" height="100" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="name" value="map" /><param name="bgcolor" value="#ffffff" /><param name="align" value="middle" /><param name="src" value="/wp-content/uploads/2009/03/rcorners.swf" /><param name="wmode" value="transparent" /><embed type="application/x-shockwave-flash" width="300" height="100" src="/wp-content/uploads/2009/03/rcorners.swf" wmode="transparent" align="middle" bgcolor="#ffffff" name="map"></embed></object></p>
<p>Actually the answer is yes, but the formal answer is &#8220;No&#8221;. Directly imported into the application the bitmap cannot be rounded. The solution is to cast it to bitmap. You can download the source code <a title="Download flex 3 Bitmap with round corners" href="/2009/03/15/download-flex-3-bitmap-with-round-corners/" target="_self">here</a>.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2009/03/15/download-flex-3-bitmap-with-round-corners/" rel="bookmark" title="Download Flex 3 bitmap with round corners">Download Flex 3 bitmap with round corners </a></li>
<li><a href="/2010/02/17/htc-round-the-corners-on-ie/" rel="bookmark" title="HTC?! Round the corners on IE!">HTC?! Round the corners on IE! </a></li>
<li><a href="/2009/02/06/flex-3-custom-preloader/" rel="bookmark" title="Flex 3 Custom Preloader">Flex 3 Custom Preloader </a></li>
<li><a href="/2010/02/15/cross-browser-rounded-corners-works-on-ie-but-but-not-on-opera/" rel="bookmark" title="Cross-browser rounded corners! Works on IE but, but not on Opera!">Cross-browser rounded corners! Works on IE but, but not on Opera! </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2009/03/15/flex-3-bitmap-with-round-corners/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Bitmaps in actionscript 3</title>
		<link>/2009/02/06/bitmaps-in-actionscript-3/</link>
		<comments>/2009/02/06/bitmaps-in-actionscript-3/#respond</comments>
		<pubDate>Fri, 06 Feb 2009 06:15:38 +0000</pubDate>
		<dc:creator><![CDATA[stoimen]]></dc:creator>
				<category><![CDATA[featured]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[bitmap]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[ram]]></category>
		<category><![CDATA[rgb]]></category>
		<category><![CDATA[stage]]></category>

		<guid isPermaLink="false">/?p=129</guid>
		<description><![CDATA[In actionscript 3 the bitmaps are stored with 4 bytes for each pixel. There are three bytes for RGB and one for the alpha channel. So you should be carefull when passing images to the flash, cause 20&#215;20 pixel image will be using apx. 1600 bytes of RAM, to optimize this send the image as &#8230; <a href="/2009/02/06/bitmaps-in-actionscript-3/" class="more-link">Continue reading <span class="screen-reader-text">Bitmaps in actionscript 3</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2012/01/16/computer-algorithms-data-compression-with-bitmaps/" rel="bookmark" title="Computer Algorithms: Data Compression with Bitmaps">Computer Algorithms: Data Compression with Bitmaps </a></li>
<li><a href="/2009/02/06/flex-3-custom-preloader/" rel="bookmark" title="Flex 3 Custom Preloader">Flex 3 Custom Preloader </a></li>
<li><a href="/2009/05/25/remove-dom-element-with-jquery/" rel="bookmark" title="Remove DOM Element with JQuery">Remove DOM Element with JQuery </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>In actionscript 3 the bitmaps are stored with 4 bytes for each pixel. There are three bytes for RGB and one for the alpha channel. So you should be carefull when passing images to the flash, cause 20&#215;20 pixel image will be using apx. 1600 bytes of RAM, to optimize this send the image as it should appear on stage and do not resize.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2012/01/16/computer-algorithms-data-compression-with-bitmaps/" rel="bookmark" title="Computer Algorithms: Data Compression with Bitmaps">Computer Algorithms: Data Compression with Bitmaps </a></li>
<li><a href="/2009/02/06/flex-3-custom-preloader/" rel="bookmark" title="Flex 3 Custom Preloader">Flex 3 Custom Preloader </a></li>
<li><a href="/2009/05/25/remove-dom-element-with-jquery/" rel="bookmark" title="Remove DOM Element with JQuery">Remove DOM Element with JQuery </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2009/02/06/bitmaps-in-actionscript-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
