<?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>Soulwire &#187; Colour</title>
	<atom:link href="http://blog.soulwire.co.uk/tag/colour/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.soulwire.co.uk</link>
	<description>Art + Technology</description>
	<lastBuildDate>Mon, 21 Mar 2011 22:27:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>ASE (Adobe Swatch Exchange) Encoder</title>
		<link>http://blog.soulwire.co.uk/code/actionscript-3/as3-ase-adobe-swatch-exchange-encoder</link>
		<comments>http://blog.soulwire.co.uk/code/actionscript-3/as3-ase-adobe-swatch-exchange-encoder#comments</comments>
		<pubDate>Tue, 30 Mar 2010 14:00:52 +0000</pubDate>
		<dc:creator>Soulwire</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[ASE]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Colour]]></category>

		<guid isPermaLink="false">http://blog.soulwire.co.uk/?p=1061</guid>
		<description><![CDATA[The Adobe Swatch Exchange (ASE) is a useful file format for importing colour schemes into applications in the Creative Suite (Photoshop, Illustrator etc). I&#8217;ve been optimising the BitmapData colour palette algorithm (coming shortly in another post) and for the demo thought that it would be nice to give you the option to save the extracted [...]


Related posts:<ol><li><a href='http://blog.soulwire.co.uk/code/actionscript-3/extract-average-colours-from-bitmapdata' rel='bookmark' title='Permanent Link: BitmapData Average Colours'>BitmapData Average Colours</a></li>
<li><a href='http://blog.soulwire.co.uk/code/actionscript-3/colourutils-bitmapdata-extract-colour-palette' rel='bookmark' title='Permanent Link: BitmapData Colour Palette'>BitmapData Colour Palette</a></li>
<li><a href='http://blog.soulwire.co.uk/laboratory/flash/as3-bitmapdata-glitch-generator' rel='bookmark' title='Permanent Link: Smack My Glitch Up'>Smack My Glitch Up</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.soulwire.co.uk/wp-content/uploads/2010/03/aseencoder-demo.swf" rel="lightbox;width=800;height=450;" ><img src="http://blog.soulwire.co.uk/wp-content/uploads/2010/03/aseencoder-710x399.jpg" alt="AS3 ASE Adobe Swatch Exchange Encoder Demo" title="AS3 ASE Adobe Swatch Exchange Encoder Demo" width="710" height="399" class="alignnone size-medium wp-image-1073" /></a></p>
<p>The <strong>Adobe Swatch Exchange (ASE)</strong> is a useful file format for importing colour schemes into applications in the Creative Suite (Photoshop, Illustrator etc).<span id="more-1061"></span></p>
<p>I&#8217;ve been optimising the <a href="http://blog.soulwire.co.uk/code/actionscript-3/colourutils-bitmapdata-extract-colour-palette" >BitmapData colour palette algorithm</a> (coming shortly in another post) and for the demo thought that it would be nice to give you the option to save the extracted color palette (a feature that people have been requesting in the comments). I added an option for saving a TXT file containing the hexadecimal and RGB colour values, but thought it would be nice to offer the choice of downloading the palette in <strong>ASE format</strong> so you can quickly incorporate the colour scheme in your artwork or designs, one of the nice features of <a rel="nofollow" href="http://blog.soulwire.co.uk//goto/http://kuler.adobe.com/" >Kuler</a>.</p>
<p>So the first step was to open up and existing ASE file (created by Photoshop) in a hex editor (I use <a rel="nofollow" href="http://blog.soulwire.co.uk//goto/http://www.suavetech.com/0xed/0xed.html" >0xED</a> which is an excellent and free editor for OS X). Looking at the bytes of the file showed that it was evidently a quite simple format and wouldn&#8217;t be difficult to reverse engineer. I also found the <a rel="nofollow" href="http://blog.soulwire.co.uk//goto/http://www.selapa.net/couleurs/fileformats.php#adobe_ase" >ASE file format specification</a> and a <a rel="nofollow" href="http://blog.soulwire.co.uk//goto/http://www.colourlovers.com/web/blog/2007/11/08/color-palettes-in-adobe-swatch-exchange-ase" >PHP implementation</a> over at <strong>Colour Lovers</strong>, both of which were quite helpful.</p>
<p>This AS3 code will take an Array of colours (adding Vectors to the &lt;pre&gt; tag seems to cause problems, though my local source code does use a Vector of uints) and encode the <a rel="nofollow" href="http://blog.soulwire.co.uk//goto/http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/utils/ByteArray.html" >ByteArray</a> of an ASE file, ready to save using <a rel="nofollow" href="http://blog.soulwire.co.uk//goto/http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/FileReference.html" >FileReference</a> of <a rel="nofollow" href="http://blog.soulwire.co.uk//goto/http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/filesystem/FileStream.html" >FileStream</a> in AIR&#8230;</p>
<pre>
const FILE_SIGNATURE : String = "ASEF";

function encode ( pixels : Array ):ByteArray
{
	var swatch : ByteArray = new ByteArray();
	var ase : ByteArray = new ByteArray();
	var hex:String;
	var pix:uint;

	ase.writeUTFBytes (FILE_SIGNATURE);// header
	ase.writeInt (0x10000);// version
	ase.writeInt (pixels.length * 2);// blocks

	for (var i : int = 0; i < pixels.length; ++i)
	{
		pix = pixels[i];
		swatch.length = 0;

		// start of group

		ase.writeShort (0xC001);
		ase.writeInt (0);
		ase.writeShort (1);

		// swatch name

		hex = pix.toString(16);
		while (hex.length < 6) hex = "0" + hex;

		swatch.writeShort ((hex = "#" + hex).length + 1);
		for (var n : int = 0; n < hex.length; ++n) swatch.writeShort (hex.charCodeAt(n));
		swatch.writeShort (0);

		// colours

		swatch.writeUTFBytes ("RGB ");
		swatch.writeFloat ((pix >> 16 &#038; 0xFF) / 255);
		swatch.writeFloat ((pix >> 8 &#038; 0xFF) / 255);
		swatch.writeFloat ((pix &#038; 0xFF) / 255);
		swatch.writeShort (2);

		// write swatch

		ase.writeInt (swatch.length);
		ase.writeBytes (swatch);
	}

	return ase;
}
</pre>
<p>I&#8217;ll put the full code in <a rel="nofollow" href="http://blog.soulwire.co.uk//goto/http://code.google.com/p/soulwire/" >my repository</a> along with the improved <em>ColourUtils</em> Class which prompted the <strong>ASEEncoder</strong>, though for now you can just copy and paste this snippet and <a href="http://blog.soulwire.co.uk/wp-content/uploads/2010/03/aseencoder-demo.swf" rel="lightbox;width=800;height=450;" >play with the demo</a> above to save the top colour schemes from Colour Lovers as ASE files, which you can then import into Adobe Creative Suite applications.</p>
<p>Here is an example of how to encode a palette and then save it to the file system:</p>
<pre>
var colours : Array = [0xFF0000, 0x00FF00, 0x0000FF];
var aseFile : ByteArray = encode( colours );
var fileRef : FileReference = new FileReference();
fileRef.save( aseFile, "swatch.ase" );
</pre>
<p>The AS3 ASEEncoder currently only encodes swatches as RGB, though saving CMYK should only be a matter of converting the colour space and then changing the swatch declaration.</p>
<p>Going in the other direction, it would be nice to provide a method to decode existing ASE files into a Vector of uints, something which I&#8217;ll look at once the new ColourUtils is online.</p>


<p>Related posts:<ol><li><a href='http://blog.soulwire.co.uk/code/actionscript-3/extract-average-colours-from-bitmapdata' rel='bookmark' title='Permanent Link: BitmapData Average Colours'>BitmapData Average Colours</a></li>
<li><a href='http://blog.soulwire.co.uk/code/actionscript-3/colourutils-bitmapdata-extract-colour-palette' rel='bookmark' title='Permanent Link: BitmapData Colour Palette'>BitmapData Colour Palette</a></li>
<li><a href='http://blog.soulwire.co.uk/laboratory/flash/as3-bitmapdata-glitch-generator' rel='bookmark' title='Permanent Link: Smack My Glitch Up'>Smack My Glitch Up</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.soulwire.co.uk/code/actionscript-3/as3-ase-adobe-swatch-exchange-encoder/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Smack My Glitch Up</title>
		<link>http://blog.soulwire.co.uk/laboratory/flash/as3-bitmapdata-glitch-generator</link>
		<comments>http://blog.soulwire.co.uk/laboratory/flash/as3-bitmapdata-glitch-generator#comments</comments>
		<pubDate>Wed, 03 Feb 2010 21:37:51 +0000</pubDate>
		<dc:creator>Soulwire</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Generative]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Transmissions]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Colour]]></category>
		<category><![CDATA[Experiments]]></category>
		<category><![CDATA[Glitch]]></category>

		<guid isPermaLink="false">http://blog.soulwire.co.uk/?p=1003</guid>
		<description><![CDATA[Sometimes it&#8217;s good to break things&#8230; During a recent project I needed to find a way of simulating digital interference on an image / video stream. At first, it seemed the best approach might be to use the graphics API or Bitmap effects, but why imitate when you can have the real thing. The principle [...]


Related posts:<ol><li><a href='http://blog.soulwire.co.uk/art-design/generative/webcam-glitch-art' rel='bookmark' title='Permanent Link: Webcam Glitch Art'>Webcam Glitch Art</a></li>
<li><a href='http://blog.soulwire.co.uk/code/actionscript-3/as3-ase-adobe-swatch-exchange-encoder' rel='bookmark' title='Permanent Link: ASE (Adobe Swatch Exchange) Encoder'>ASE (Adobe Swatch Exchange) Encoder</a></li>
<li><a href='http://blog.soulwire.co.uk/laboratory/flash/recursive-polygon-subdivision' rel='bookmark' title='Permanent Link: Recursive Polygon Subdivision'>Recursive Polygon Subdivision</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.soulwire.co.uk/wp-content/uploads/2010/02/glitchmap.swf" title="AS3 Glitch Generator" rel="lightbox;width=900;height=650;" ><img class="alignnone size-full wp-image-1006" title="Glitchmap - AS3 Glitch Generator" src="http://blog.soulwire.co.uk/wp-content/uploads/2010/02/glitch-generator.jpg" alt="Glitchmap - AS3 Glitch Generator" width="710" height="360" /></a></p>
<p><em>Sometimes it&#8217;s good to break things&#8230;</em></p>
<p>During a recent project I needed to find a way of simulating digital interference on an image / video stream. At first, it seemed the best approach might be to use the graphics API or Bitmap effects, but why imitate when you can have the real thing.<span id="more-1003"></span></p>
<p>The principle is incredibly simple. Corrupt / alter a byte (or several bytes) in the ByteArray of a JPEG and then load this back into a DisplayObject using <em>Loader.loadBytes()</em>. Because of the way in which <a rel="nofollow" href="http://blog.soulwire.co.uk//goto/http://en.wikipedia.org/wiki/JPEG#Syntax_and_structure" >JPEGs work</a>, the image will still display but the corrupt bytes will mangle the output to varying degrees, depending on how many bytes have been corrupted. The result is an interesting glitch pattern, a bit like those which were accidentally created <a href="http://blog.soulwire.co.uk/art-design/generative/webcam-glitch-art" title="Webcam glitch images" >when my webcam drivers lost the plot</a>.</p>
<p>It is also possible to corrupt other image formats (png, gif etc) in the same way, by first passing the image ByteArray through a <a rel="nofollow" href="http://blog.soulwire.co.uk//goto/http://code.google.com/p/as3corelib/source/browse/trunk/src/com/adobe/images/JPGEncoder.as" >JPEGEncoder</a>.</p>
<p>I&#8217;ve implemented this technique in the <strong>Glitchmap</strong> class, which you can download and play with at the bottom of this post. I hope that it will provide a few moments of fun, if not a practical use <em>(I&#8217;m thinking image gallery transitions or <a href="http://blog.soulwire.co.uk/laboratory/flash/actionscript3-dynamic-sound-visualisation" >music </a><a href="http://blog.soulwire.co.uk/art-design/portfolio/more-bandcamp-music-visualisations" >visualisations</a>)</em>.</p>
<p>The small gottcha is that it isn&#8217;t desirable to mess with the JPEG headers, so when the clean ByteArray is passed to the <em>Glitchmap</em> class, it will determine the length of the header by reading through the bytes until it finds the <em>SOS (start of scan)</em> declaration <em>(0xFFDA)</em>. The next two bytes represent the length of the <em>SOS</em>, so it skips forward by this amount &#8211; the resulting position in the ByteArray should be the end of the header, and so between this point and the <em>EOI (end of image)</em> the data corruption takes place. I&#8217;m not sure whether this is the best way of determining the JPEG header size; <em>perhaps any CS graduates / students out there can help me out?</em></p>
<p>After I posted the <a href="http://blog.soulwire.co.uk/art-design/generative/webcam-glitch-art" >webcam glitch images</a>, Jon used them in his title sequences for the <a rel="nofollow" href="http://blog.soulwire.co.uk//goto/http://www.youtube.com/watch?v=k5scRdXr7wU"  rel="shadowbox[post-1003];player=swf;width=640;height=385;">48 hour film gala</a>. If you find a similar creative use for this script or the <a href="http://blog.soulwire.co.uk/wp-content/uploads/2010/02/glitchmap.swf" title="AS3 Glitch Generator" rel="lightbox;width=900;height=650;" >glitch generator</a> then please let us all know.</p>
<p>I think the next step is to experiment with merging the bytes of multiple glitched images in order to create transition effects. I may also build an AIR app and see what the best way of outputting video might be (using NativeProcess for screen capture perhaps?).</p>
<a href="http://blog.soulwire.co.uk/wp-content/plugins/download-monitor/download.php?id=Glitchmap.zip" class="download" title="AS3 BitmapData Glitch Generator (Glitchmap): Glitchmap is a class for generating glitch imagery from AS3 BitmapData"  rel="nofollow"><strong>Download:</strong> AS3 BitmapData Glitch Generator (Glitchmap)</a>
<p><em>You can also download the Glitchmap Class and the <a href="http://blog.soulwire.co.uk/wp-content/uploads/2010/02/glitchmap.swf" title="AS3 Glitch Generator" rel="lightbox;width=900;height=650;" >Glitch Generator</a> source code from the <a rel="nofollow" href="http://blog.soulwire.co.uk//goto/http://code.google.com/p/soulwire/" title="Soulwire code repository" >soulwire code repository</a>.</em></p>


<p>Related posts:<ol><li><a href='http://blog.soulwire.co.uk/art-design/generative/webcam-glitch-art' rel='bookmark' title='Permanent Link: Webcam Glitch Art'>Webcam Glitch Art</a></li>
<li><a href='http://blog.soulwire.co.uk/code/actionscript-3/as3-ase-adobe-swatch-exchange-encoder' rel='bookmark' title='Permanent Link: ASE (Adobe Swatch Exchange) Encoder'>ASE (Adobe Swatch Exchange) Encoder</a></li>
<li><a href='http://blog.soulwire.co.uk/laboratory/flash/recursive-polygon-subdivision' rel='bookmark' title='Permanent Link: Recursive Polygon Subdivision'>Recursive Polygon Subdivision</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.soulwire.co.uk/laboratory/flash/as3-bitmapdata-glitch-generator/feed</wfw:commentRss>
		<slash:comments>65</slash:comments>
		</item>
		<item>
		<title>BitmapData Colour Palette</title>
		<link>http://blog.soulwire.co.uk/code/actionscript-3/colourutils-bitmapdata-extract-colour-palette</link>
		<comments>http://blog.soulwire.co.uk/code/actionscript-3/colourutils-bitmapdata-extract-colour-palette#comments</comments>
		<pubDate>Sat, 11 Oct 2008 19:52:35 +0000</pubDate>
		<dc:creator>Soulwire</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Colour]]></category>
		<category><![CDATA[Experiments]]></category>

		<guid isPermaLink="false">http://blog.soulwire.co.uk/?p=195</guid>
		<description><![CDATA[My previous post explained and provided a very simple method for extracting colours from a BitmapData image, by averaging the colours in specific areas. This can have several applications, for example it features in a large amount of prototypes for the update to my Motion Tracking engine. However, if you want to create an accurate and [...]


Related posts:<ol><li><a href='http://blog.soulwire.co.uk/code/actionscript-3/extract-average-colours-from-bitmapdata' rel='bookmark' title='Permanent Link: BitmapData Average Colours'>BitmapData Average Colours</a></li>
<li><a href='http://blog.soulwire.co.uk/code/actionscript-3/as3-ase-adobe-swatch-exchange-encoder' rel='bookmark' title='Permanent Link: ASE (Adobe Swatch Exchange) Encoder'>ASE (Adobe Swatch Exchange) Encoder</a></li>
<li><a href='http://blog.soulwire.co.uk/code/actionscript-3/webcam-motion-detection-tracking' rel='bookmark' title='Permanent Link: AS3 Webcam Motion Tracking'>AS3 Webcam Motion Tracking</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.soulwire.co.uk/wp-content/uploads/2008/10/colour-palette.swf" title="Extracting the Colour Palette from an Image" rel="lightbox;width=800;height=450;" ><img class="alignnone size-medium wp-image-582" title="Bitmapdata Colour Palette" src="http://blog.soulwire.co.uk/wp-content/uploads/2008/10/bitmapdata-colour-palette-710x399.jpg" alt="Bitmapdata Colour Palette" width="710" height="399" /></a></p>
<p>My <a href="http://blog.soulwire.co.uk/code/actionscript-3/extract-average-colours-from-bitmapdata" title="BitmapData average colour" >previous post</a> explained and provided a very simple method for <a href="http://blog.soulwire.co.uk/code/actionscript-3/extract-average-colours-from-bitmapdata" title="Extracting the average colour from a BitmapData image" >extracting colours from a BitmapData image</a>, by averaging the colours in specific areas. This can have several applications, for example it features in a large amount of prototypes for the update to my <a href="http://blog.soulwire.co.uk/code/actionscript-3/webcam-motion-detection-tracking" title="AS3 Webcam Motion Tracking engine" >Motion Tracking engine</a>. However, if you want to create an accurate and representative colour palette from an image it has several flaws, the most obvious being that by averaging colours, you are actually removing or diluting the striking but perhaps less frequent colours in the image – the very colours which often make an image’s colour palette so exiting!</p>
<p>So, if we’re to extract an exciting and more representative palette from an image, we need a more intelligent algorithm; one which takes into account what makes a colour palette interesting – the contrasts and juxtapositions of colours within the image.<span id="more-195"></span></p>
<p>After some experimentation I arrived at the following solution. <a href="#getcode">I have posted the code bellow</a>, but I think it’s important to understand how it works and why each step is taken, so without further ado, here be my approach to calculating the colour palette of a BitmapData image&#8230;</p>
<h2>Reducing the colours</h2>
<p>We’re going to be performing quite a few operations on the colours in our input image, so for the sake of performance it’s wise to reduce the colours in the image as much as possible without losing the overall look and feel of the palette.</p>
<p><a rel="nofollow" href="http://blog.soulwire.co.uk//goto/http://en.nicoptere.net/" title="Nicolas Barradeau's blog"  target="_blank">Nicolas Barradeau</a> has done some really cool things with this, and his <a rel="nofollow" href="http://blog.soulwire.co.uk//goto/http://en.nicoptere.net/?p=8" title="Colour Depth Change"  target="_blank">Color Depth Change</a> script is really worth checking out. We can actually enhance this technique slightly by omitting the two loops which cycle through every pixel in the image and use <strong>paletteMap</strong>. The result is good enough for our needs and substantially quicker. I’m also glad I could use the BitmapData paletteMap method, because up until now I hadn’t ever had a use for it :)</p>
<p>I’ve found that reducing the image’s colour palette to 64 colours works well performance wise and still looks great, but you might want to use anything up to 256.</p>
<p>I won’t go into how paletteMap works, and <a rel="nofollow" href="http://blog.soulwire.co.uk//goto/http://livedocs.adobe.com/flex/201/langref/flash/display/BitmapData.html#paletteMap()"  target="_blank">the docs</a> aren’t very helpful on this matter so I suggest you check out Google if you want a bit more information. In short, we create a new index of colours for the image by creating three arrays, one for each channel (red, green and blue) and pass these values to the paletteMap method, which takes care of the rest at blisteringly fast speeds. What we are left with is a dithered version of our original image, allowing us to analyse it’s pixels in a much speedier manner.</p>
<pre lang="actionscript">public static function reduceColours( source:BitmapData, colours:int = 16 ):void
{
	var Ra:Array = new Array(256);
	var Ga:Array = new Array(256);
	var Ba:Array = new Array(256);

	var n:Number = 256 / ( colours / 3 );

	for (var i:int = 0; i < 256; i++)
	{
		Ba[i] = Math.floor(i / n) * n;
		Ga[i] = Ba[i] << 8;
		Ra[i] = Ga[i] << 8;
	}

	source.paletteMap( source, source.rect, new Point(), Ra, Ga, Ba );
}</pre>
<p>Note: at this stage, if you’re working with a very large image, it’s advisable to draw the image to a smaller BitmapData using a scaled Matrix, as we will be looping over its pixels and so a 2000 x 2000 image is likely to make your CPU rather pissed off at you!</p>
<h2>Indexing the colours</h2>
<p>The next step is to build an index of the colours in the image. By index, I mean that we want a list of unique colours and a tally for each telling us how many times they occur in the image. We can do this by using an Object or a Dictionary, which uses the colour values as a key and a counter as the value.</p>
<pre lang="actionscript">public static function indexColours( source:BitmapData, sort:Boolean = true ):Array
{

	var n:Object = {};
	var a:Array = [];
	var p:int;

	for (var x:int = 0; x < source.width; x++)
	{
		for (var y:int = 0; y < source.height; y++)
		{
			p = source.getPixel(x, y);
			n[p] ? n[p]++ : n[p] = 1;
		}
	}

	for (var c:String in n)
	{
		a.push ( { colour:c, count:n[c] } );
	}

	function byCount( a:Object, b:Object ):int
	{
		if ( a.count > b.count ) return 1;
		if ( a.count < b.count ) return -1;
		return 0;
	}

	return a.sort( byCount, Array.DESCENDING );
}</pre>
<p>We are left with an Object containing all the colours in the image, grouped by their colour value and with a reference to how frequently they appear. We can then use a <em>for in</em> loop to create an array from the Objects properties.</p>
<p>Finally, we need to sort the resulting Array, essentially by popularity, so that the colours which appear most frequently within the image are at the start of the Array. We can do this using the Array’s sort method, and passing a custom function which compares each colour’s count or frequency to that of the other colours. Now we can discard the count value, and what we are left with is a correctly ordered array of unsigned integers representing our entire spectrum of colours.</p>
<h2>Finding unique, contrasting colours</h2>
<p>At this point, we could simply take the first values from the array and call this our palette, after all if we wanted, say, a 16 colour palette then we know that the first 16 colours in our Array are the most frequently occurring colours in our source image. The problem with this is that, as with most things in life, just because something is popular doesn’t necessarily make it good! Take a landscape photograph for example; there may be a beautiful collection of flowers with striking colours in the foreground, and a burning orange and pink sunset descending over the horizon, yet the first group of colours in our Array will likely be a host of different shades of green from the hills and fields – not exactly what we were hoping for!</p>
<p>So we need an algorithm which can discern between colours and tell us which of our colours have a sufficient variance, therefore producing a palette which fairly represents the broader spectrum of colours in our image.</p>
<p>The best solution that I found was to add up the square of the red, green and blue components of two colours and compare their results. If they are sufficiently different (as determined by a variable tolerance) then we have a match.</p>
<pre lang="actionscript">public static function similar( colour1:uint, colour2:uint, tolerance:Number = 0.01 ):Boolean
{
	var RGB1:Object = Hex24ToRGB( colour1 );
	var RGB2:Object = Hex24ToRGB( colour2 );

	tolerance = tolerance * ( 255 * 255 * 3 ) << 0;

	var distance:Number = 0;

	distance += Math.pow( RGB1.red - RGB2.red, 2 );
	distance += Math.pow( RGB1.green - RGB2.green, 2 );
	distance += Math.pow( RGB1.blue - RGB2.blue, 2 );

	return distance <= tolerance;
}</pre>
<p>To apply this idea, we need to create an empty Array which will eventually become our results. We then begin to loop through our colours, taking the first and comparing it to subsequent colours until we find one which is sufficiently different. We then push this colour into our results Array, and then continue searching, this time comparing each colour in our initial Array to each colour in our growing Array of unique colours. Once we have reached our predefined quota of colours, or the end of the Array, we have our beautiful colour palette!</p>
<pre lang="actionscript">public static function different( colour:uint, colours:Array, tolerance:Number = 0.01 ):Boolean
{
	for (var i:int = 0; i < colours.length; i++)
	{
		if ( similar( colour, colours[i], tolerance ) )
		{
			return false;
		}
	}
	return true;
}

public static function uniqueColours( colours:Array, maximum:int, tolerance:Number = 0.01 ):Array
{
	var unique:Array = [];

	for (var i:int = 0; i < colours.length &#038;&#038; unique.length < maximum; i++)
	{
		if ( different( colours[i], unique, tolerance ) )
		{
			unique.push( colours[i] );
		}
	}

	return unique;
}</pre>
<h2 name="getcode" id="getcode">Putting it all together</h2>
<p>I’ve packaged the above technique, as well as the <strong>averageColour </strong>and <strong>averageColours </strong>methods from my last post into a <strong>ColourUtils</strong> class. Most of the methods detailed above, despite being necessary steps in finding an image’s colour palette, are useful in their own right and so I have separated them out into a documented collection of static methods.</p>
<p>You can download the <strong>ColourUtils </strong>class and also some examples of how to use it:</p>
<a href="http://blog.soulwire.co.uk/wp-content/plugins/download-monitor/download.php?id=ColourUtils.zip" class="download" title="ColourUtils: A useful class for extracting colour palettes from images and BitmapData objects based on an interestingness algorithm, ensuring contrasting colours are selected."  rel="nofollow"><strong>Download:</strong> ColourUtils</a> <a href="http://blog.soulwire.co.uk/wp-content/plugins/download-monitor/download.php?id=ColourUtils-Demo.zip" class="download" title="ColourUtils Demo: An example of how to use the ColourUtils class to extract a colour palette from an image or BitmapData."  rel="nofollow"><strong>Download:</strong> ColourUtils Demo</a>
<h2>Possible Enhancements</h2>
<p>I have a few ideas for possible enhancements to the algorithm, and <strong>would like to hear yours</strong> if you have any. Currently, these are my intentions for the next revision:</p>
<ul>
<li>Integration of the <a rel="nofollow" href="http://blog.soulwire.co.uk//goto/http://www.colourlovers.com/blog/2007/09/02/the-muller-formula-or-predictable-color-preferences/" >Müller formula</a> so that a single colour from a group of similar colours is chosen not by its frequency but by its suitability for the extracted palette – i.e. a colour with greater tonal variation is preferred by the algorithm much the same way as it would be by the eye.</li>
<li>Palette colour sorting by hue, saturation or brightness.</li>
<li>A faster way of discarding unwanted colours, preferably before looping through the colour index, resulting in much better performance.</li>
</ul>


<p>Related posts:<ol><li><a href='http://blog.soulwire.co.uk/code/actionscript-3/extract-average-colours-from-bitmapdata' rel='bookmark' title='Permanent Link: BitmapData Average Colours'>BitmapData Average Colours</a></li>
<li><a href='http://blog.soulwire.co.uk/code/actionscript-3/as3-ase-adobe-swatch-exchange-encoder' rel='bookmark' title='Permanent Link: ASE (Adobe Swatch Exchange) Encoder'>ASE (Adobe Swatch Exchange) Encoder</a></li>
<li><a href='http://blog.soulwire.co.uk/code/actionscript-3/webcam-motion-detection-tracking' rel='bookmark' title='Permanent Link: AS3 Webcam Motion Tracking'>AS3 Webcam Motion Tracking</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.soulwire.co.uk/code/actionscript-3/colourutils-bitmapdata-extract-colour-palette/feed</wfw:commentRss>
		<slash:comments>59</slash:comments>
		</item>
		<item>
		<title>BitmapData Average Colours</title>
		<link>http://blog.soulwire.co.uk/code/actionscript-3/extract-average-colours-from-bitmapdata</link>
		<comments>http://blog.soulwire.co.uk/code/actionscript-3/extract-average-colours-from-bitmapdata#comments</comments>
		<pubDate>Fri, 10 Oct 2008 18:21:46 +0000</pubDate>
		<dc:creator>Soulwire</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Colour]]></category>
		<category><![CDATA[Experiments]]></category>

		<guid isPermaLink="false">http://blog.soulwire.co.uk/?p=165</guid>
		<description><![CDATA[If you want a very simple way of extracting a colour palette from an image, one technique would be to average the colour values within specific areas. Averaging colour values is almost identical to averaging numbers, except with the added initial step of finding the red, green and blue components of the colour. To do [...]


Related posts:<ol><li><a href='http://blog.soulwire.co.uk/code/actionscript-3/colourutils-bitmapdata-extract-colour-palette' rel='bookmark' title='Permanent Link: BitmapData Colour Palette'>BitmapData Colour Palette</a></li>
<li><a href='http://blog.soulwire.co.uk/code/actionscript-3/as3-ase-adobe-swatch-exchange-encoder' rel='bookmark' title='Permanent Link: ASE (Adobe Swatch Exchange) Encoder'>ASE (Adobe Swatch Exchange) Encoder</a></li>
<li><a href='http://blog.soulwire.co.uk/code/actionscript-3/webcam-motion-detection-tracking' rel='bookmark' title='Permanent Link: AS3 Webcam Motion Tracking'>AS3 Webcam Motion Tracking</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.soulwire.co.uk/wp-content/uploads/2008/10/average-colour.swf" rel="lightbox;width=800;height=450;" title="Finding the average colours in an image" ><img src="http://blog.soulwire.co.uk/wp-content/uploads/2008/10/average-colours-710x399.jpg" alt="BitmapData Average Colours" title="BitmapData Average Colours" width="710" height="399" class="alignnone size-medium wp-image-618" /></a></p>
<p>If you want a very simple way of extracting a colour palette from an image, one technique would be to average the colour values within specific areas. Averaging colour values is almost identical to averaging numbers, except with the added initial step of finding the red, green and blue components of the colour. To do this we can use <strong>bitwise operators</strong>, in this case <strong>bitwise shift</strong>, to perform fast operations on each <em>bit </em>inside the unsigned integer returned by <em>getPixel</em> or <em>getPixel32</em>.  If you want to know more about bitwise operators, <strong>Moock </strong>has written a detailed and, as ever, very clear article on where, when and why to use bitewise operations. You can read it <a rel="nofollow" href="http://blog.soulwire.co.uk//goto/http://www.moock.org/asdg/technotes/bitwise/"  target="_blank">here</a>.</p>
<p>So once you’re familiar with how to shift the bits of an integer, you can easily get the RGB values from a 24 bit hexadecimal by moving the bits to the right by a certain amount using the <strong>bitwise right </strong><strong>shift </strong> operator (<strong>&gt;&gt;</strong>).<span id="more-165"></span></p>
<p>For example, getting the red, green and blue values from a 24 bit integer would look like:</p>
<pre lang="actionscript">var colour:uint = 0x33CC99;

var R:Number = colour &gt;&gt; 16 &amp; 0xFF;
var G:Number = colour &gt;&gt; 8  &amp; 0xFF;
var B:Number = colour &amp; 0xFF;</pre>
<p>And finding the alpha, red, green and blue values of a 32 bit integer:</p>
<pre lang="actionscript">var colour:uint = 0xFF33CC99;

var A:Number = colour &gt;&gt; 24 &amp; 0xFF;
var R:Number = colour &gt;&gt; 16 &amp; 0xFF;
var G:Number = colour &gt;&gt; 8 &amp; 0xFF;
var B:Number = colour &amp; 0xFF;</pre>
<p>So we know that by shifting the bits to the right, we can effectively break an unsigned integer representing a colour into its specific components, but what about changing these components back into an RGB or ARGB value? Well, it’s simply a matter of shifting the bits in the other direction, using the <strong>bitwise left shift </strong>operator, which looks like this <strong>&lt;&lt;</strong> (two less than operators next to each other).</p>
<p>So using this bitwise shift left operator, you can take your RGB or ARGB values and cram the little buggers back into a usable format, with a little help from <em>bitwise OR</em>:</p>
<pre lang="actionscript">// RGB
var colourRBG:uint = (R &lt;&lt; 16 | G &lt;&lt; 8 | B);

// ARGB
var colourARBG:uint = (A &lt;&lt; 24 | R &lt;&lt; 16 | G &lt;&lt; 8 | B);</pre>
<p>Right, so we know how to take an unsigned integer, for example one that’s been returned from <strong>getPixel </strong>or <strong>getPixel32 </strong>and break it down into its <strong>RGB </strong>or <strong>ARGB </strong>components &#8211; and then for the sake of universal harmony, put it back together again and release it back into its 24 or 32bit world with all its binary friends.</p>
<p>So now, finding the average colour within a set of colours is simply a question of averaging the red, green and blue values of all the colours, and then turning these averages into a new colour.</p>
<p>The method bellow does just this, by looping through the pixels in a BitmapData object, adding up all of the red, green and blue values, dividing them by the total number of pixels and then creating a new colour from the results.</p>
<pre lang="actionscript">public static function averageColour( source:BitmapData ):uint
{
	var red:Number = 0;
	var green:Number = 0;
	var blue:Number = 0;

	var count:Number = 0;
	var pixel:Number;

	for (var x:int = 0; x &lt; source.width; x++)
	{
		for (var y:int = 0; y &lt; source.height; y++)
		{
			pixel = source.getPixel(x, y);

			red += pixel &gt;&gt; 16 &amp; 0xFF;
			green += pixel &gt;&gt; 8 &amp; 0xFF;
			blue += pixel &amp; 0xFF;

			count++
		}
	}

	red /= count;
	green /= count;
	blue /= count;

	return red &lt;&lt; 16 | green &lt;&lt; 8 | blue;
}</pre>
<p>So taking this a step further; say we want an array of 64 colours from an image, we can break the input image down into 64 chunks and find the averages of each. The easiest way of doing this is to build a grid, copy the pixels in each cell and use the averageColour function to return the average colour value of that cell.</p>
<pre lang="actionscript">public static function averageColours( source:BitmapData, colours:int ):Array
{
	var averages:Array = new Array();
	var columns:int = Math.round( Math.sqrt( colours ) );

	var row:int = 0;
	var col:int = 0;

	var x:int = 0;
	var y:int = 0;

	var w:int = Math.round( source.width / columns );
	var h:int = Math.round( source.height / columns );

	for (var i:int = 0; i &lt; colours; i++)
	{
		var rect:Rectangle = new Rectangle( x, y, w, h );

		var box:BitmapData = new BitmapData( w, h, false );
		box.copyPixels( source, rect, new Point() );

		averages.push( averageColour( box ) );
		box.dispose();

		col = i % columns;

		x = w * col;
		y = h * row;

		if ( col == columns - 1 ) row++;
	}

	return averages;
}</pre>
<p>In terms of building an accurate colour palette from an image, this isn’t a great method, mainly because averaging the colours doesn’t give you a fair representation of the <em>range</em> of colours in the image. The palette returned can often be somewhat muddy; however it is still a technique that I’ve found a use for on a surprisingly regular basis and so thought it worth sharing. Becoming familiar with bitwise operators is also a useful exercise and so, if they aren’t already part of your life, I suggest you begin to woo them with your nerdy charm.</p>


<p>Related posts:<ol><li><a href='http://blog.soulwire.co.uk/code/actionscript-3/colourutils-bitmapdata-extract-colour-palette' rel='bookmark' title='Permanent Link: BitmapData Colour Palette'>BitmapData Colour Palette</a></li>
<li><a href='http://blog.soulwire.co.uk/code/actionscript-3/as3-ase-adobe-swatch-exchange-encoder' rel='bookmark' title='Permanent Link: ASE (Adobe Swatch Exchange) Encoder'>ASE (Adobe Swatch Exchange) Encoder</a></li>
<li><a href='http://blog.soulwire.co.uk/code/actionscript-3/webcam-motion-detection-tracking' rel='bookmark' title='Permanent Link: AS3 Webcam Motion Tracking'>AS3 Webcam Motion Tracking</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.soulwire.co.uk/code/actionscript-3/extract-average-colours-from-bitmapdata/feed</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>Webcam Glitch Art</title>
		<link>http://blog.soulwire.co.uk/art-design/generative/webcam-glitch-art</link>
		<comments>http://blog.soulwire.co.uk/art-design/generative/webcam-glitch-art#comments</comments>
		<pubDate>Fri, 09 Nov 2007 14:13:36 +0000</pubDate>
		<dc:creator>Soulwire</dc:creator>
				<category><![CDATA[Generative]]></category>
		<category><![CDATA[Colour]]></category>
		<category><![CDATA[Glitch]]></category>

		<guid isPermaLink="false">http://blog.soulwire.co.uk/?p=47</guid>
		<description><![CDATA[What happens when you let vista install drivers for you? Shit happens. But in this case, good shit. I was playing around with flash and using the Camera class to save stills via the CS3 AIR extension. Unfortunately, my webcam drivers had not been installed correctly, but the results were some really interesting glitches. You [...]


Related posts:<ol><li><a href='http://blog.soulwire.co.uk/laboratory/flash/as3-bitmapdata-glitch-generator' rel='bookmark' title='Permanent Link: Smack My Glitch Up'>Smack My Glitch Up</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-009-710x355.jpg" alt="Webcam Glitch Art" title="webcam-glitch-009" width="710" height="355" class="alignnone size-medium wp-image-787" /></p>
<p>What happens when you let vista install drivers for you? Shit happens. But in this case, good shit.<span id="more-47"></span></p>
<p>I was playing around with flash and using the Camera class to save stills via the CS3 AIR extension. Unfortunately, my webcam drivers had not been installed correctly, but the results were some really interesting glitches.</p>

<a href="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-001.jpg"  rel='shadowbox[album-47];player=img;' title='webcam-glitch-001'><img width="155" height="155" src="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-001-155x155.jpg" class="attachment-thumbnail" alt="webcam-glitch-001" title="webcam-glitch-001" /></a>
<a href="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-002.jpg"  rel='shadowbox[album-47];player=img;' title='webcam-glitch-002'><img width="155" height="155" src="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-002-155x155.jpg" class="attachment-thumbnail" alt="webcam-glitch-002" title="webcam-glitch-002" /></a>
<a href="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-003.jpg"  rel='shadowbox[album-47];player=img;' title='webcam-glitch-003'><img width="155" height="155" src="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-003-155x155.jpg" class="attachment-thumbnail" alt="webcam-glitch-003" title="webcam-glitch-003" /></a>
<a href="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-004.jpg"  rel='shadowbox[album-47];player=img;' title='webcam-glitch-004'><img width="155" height="155" src="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-004-155x155.jpg" class="attachment-thumbnail" alt="webcam-glitch-004" title="webcam-glitch-004" /></a>
<a href="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-005.jpg"  rel='shadowbox[album-47];player=img;' title='webcam-glitch-005'><img width="155" height="155" src="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-005-155x155.jpg" class="attachment-thumbnail" alt="webcam-glitch-005" title="webcam-glitch-005" /></a>
<a href="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-006.jpg"  rel='shadowbox[album-47];player=img;' title='webcam-glitch-006'><img width="155" height="155" src="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-006-155x155.jpg" class="attachment-thumbnail" alt="webcam-glitch-006" title="webcam-glitch-006" /></a>
<a href="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-007.jpg"  rel='shadowbox[album-47];player=img;' title='webcam-glitch-007'><img width="155" height="155" src="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-007-155x155.jpg" class="attachment-thumbnail" alt="webcam-glitch-007" title="webcam-glitch-007" /></a>
<a href="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-008.jpg"  rel='shadowbox[album-47];player=img;' title='webcam-glitch-008'><img width="155" height="155" src="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-008-155x155.jpg" class="attachment-thumbnail" alt="webcam-glitch-008" title="webcam-glitch-008" /></a>
<a href="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-009.jpg"  rel='shadowbox[album-47];player=img;' title='webcam-glitch-009'><img width="155" height="155" src="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-009-155x155.jpg" class="attachment-thumbnail" alt="Webcam Glitch Art" title="webcam-glitch-009" /></a>
<a href="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-010.jpg"  rel='shadowbox[album-47];player=img;' title='webcam-glitch-010'><img width="155" height="155" src="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-010-155x155.jpg" class="attachment-thumbnail" alt="webcam-glitch-010" title="webcam-glitch-010" /></a>
<a href="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-011.jpg"  rel='shadowbox[album-47];player=img;' title='webcam-glitch-011'><img width="155" height="155" src="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-011-155x155.jpg" class="attachment-thumbnail" alt="webcam-glitch-011" title="webcam-glitch-011" /></a>
<a href="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-012.jpg"  rel='shadowbox[album-47];player=img;' title='webcam-glitch-012'><img width="155" height="155" src="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-012-155x155.jpg" class="attachment-thumbnail" alt="webcam-glitch-012" title="webcam-glitch-012" /></a>
<a href="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-013.jpg"  rel='shadowbox[album-47];player=img;' title='webcam-glitch-013'><img width="155" height="155" src="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-013-155x155.jpg" class="attachment-thumbnail" alt="webcam-glitch-013" title="webcam-glitch-013" /></a>
<a href="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-014.jpg"  rel='shadowbox[album-47];player=img;' title='webcam-glitch-014'><img width="155" height="155" src="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-014-155x155.jpg" class="attachment-thumbnail" alt="webcam-glitch-014" title="webcam-glitch-014" /></a>
<a href="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-015.jpg"  rel='shadowbox[album-47];player=img;' title='webcam-glitch-015'><img width="155" height="155" src="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-015-155x155.jpg" class="attachment-thumbnail" alt="webcam-glitch-015" title="webcam-glitch-015" /></a>
<a href="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-016.jpg"  rel='shadowbox[album-47];player=img;' title='webcam-glitch-016'><img width="155" height="155" src="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-016-155x155.jpg" class="attachment-thumbnail" alt="webcam-glitch-016" title="webcam-glitch-016" /></a>
<a href="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-017.jpg"  rel='shadowbox[album-47];player=img;' title='webcam-glitch-017'><img width="155" height="155" src="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-017-155x155.jpg" class="attachment-thumbnail" alt="webcam-glitch-017" title="webcam-glitch-017" /></a>
<a href="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-018.jpg"  rel='shadowbox[album-47];player=img;' title='webcam-glitch-018'><img width="155" height="155" src="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-018-155x155.jpg" class="attachment-thumbnail" alt="webcam-glitch-018" title="webcam-glitch-018" /></a>
<a href="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-019.jpg"  rel='shadowbox[album-47];player=img;' title='webcam-glitch-019'><img width="155" height="155" src="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-019-155x155.jpg" class="attachment-thumbnail" alt="webcam-glitch-019" title="webcam-glitch-019" /></a>
<a href="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-020.jpg"  rel='shadowbox[album-47];player=img;' title='webcam-glitch-020'><img width="155" height="155" src="http://blog.soulwire.co.uk/wp-content/uploads/2007/11/webcam-glitch-020-155x155.jpg" class="attachment-thumbnail" alt="webcam-glitch-020" title="webcam-glitch-020" /></a>

<p>You can see the full set and high res versions on <a rel="nofollow" href="http://blog.soulwire.co.uk//goto/http://www.flickr.com/photos/soulwire/sets/72157603055370065/" title="Webcam Glitch Art"  target="_blank">Flickr</a></p>
<p>It got me thinking about the ByteArray and socket classes in AS3, with some experimentation, maybe there will be a way to screw up BitmapData in a similar way? Bring back the 90’s and the cool glitch art that seemed to be coming out more often then. It’s amazing what eye candy can be produced by malfunctions.</p>


<p>Related posts:<ol><li><a href='http://blog.soulwire.co.uk/laboratory/flash/as3-bitmapdata-glitch-generator' rel='bookmark' title='Permanent Link: Smack My Glitch Up'>Smack My Glitch Up</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.soulwire.co.uk/art-design/generative/webcam-glitch-art/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

