<?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; ASE</title>
	<atom:link href="http://blog.soulwire.co.uk/tag/ase-adobe-swatch-exchange/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>
	</channel>
</rss>

