So I'm developing a web application to more easily be able distribute color palettes created with Photoshop in a *.ACO or *.ASE format to colleagues who doesn't have those programs. I've come quite a long way setting up the basics, but now I'm totally stuck for the sole reason that I can't figure out how the swatch files are structured.
This is what I get when I open the *.ASE file in a text editor:
ASEF & S w a t c h 1 RGB & S w a t c h 2 RGB ?
Œ ?€ ?€ & S w a t c h 3 RGB ?oïð?)̪>mí & S w a t c h 1 RGB & S w a t c h 2 RGB ?
Œ ?€ ?€ & S w a t c h 3 RGB ?oïð?)̪>mí & S w a t c h 1 RGB & S w a t c h 2 RGB ?
Œ ?€ ?€ & S w a t c h 3 RGB ?oïð?)̪>mí & S w a t c h 1 RGB & S w a t c h 2 RGB ?
Œ ?€ ?€ & S w a t c h 3 RGB ?oïð?)̪>mí
and when I open it in NP++ it looks like this:
I was hoping (and naively expecting) that the format would be in some comprehensible XML structure, but it's clearly not..
I've tried researching the subject and found these sources:
http://www.nomodes.com/aco.html
http://www.selapa.net/swatches/colors/fileformats.php
http://www.adobe.com/devnet-apps/photoshop/fileformatashtml/PhotoshopFileFormats.htm#50577411_31265
But to be honest it feels to complicated for me to be able to wrap my head around.. If anyone with better knowledge about file coding formats or color coding formats has any input for me I would greatly appreciate it!
The files are available here for download if you want to have a look at them:
https://www.dropbox.com/sh/9vo2h7ophpfc201/p7saMtxi_k
What you are seeing is the ASCII representation of the binary file. In the link you shared previously you will see that the file format is binary. So that lets take that as the starting point. Now open the file and read it in like so,
$handle = fopen("temp.aco", "rb");
while (!feof($handle))
{
$data = fread($handle, 2);
echo bin2hex($data)."<br/>";
}
This opens the .aco file and reads until the end of file is reached. By using fread and setting the second parameter to 2 you read in 2 bytes worth of data from the file. You will then see output like so,
0001 0008 0000 fafa e2e2 dbdb 0000
Now looking at your other link you will see that the first number 0001 represents the version number 0008 represents the number of colours in the file (in my case 8) then you have the colour type which will typically be 0000 (RGB) 0001 (HSB) 0002 (CMYK) see the colour conversion table for the rest.
Colours are made up of either 3 or 4 words so sometimes you can ignore the last word it will be zero'd. So lets see an example of this,
0000-(RGB Type) fafa-(Red represented by 0..65535 range) e2e2-(Green represented by 0..65535 range) dbdb-(Blue represented by 0..65535 range) 0000-(no data needed in this positioned so zero'd)
By converting the words read to an unsigned int and following the conversion table you will get the appropriate rgb values. Here is my code for parsing the various types.
function colorInColorSpace($colorSpace, $w, $x, $y, $z){
// RGB
if($colorSpace==0){
$r = $w/256;
$g = $x/256;
$b = $y/256;
//z component not used in rgb format
print $colorSpace." ".$r." ".$g." ".$b."<br/>";
}
//HSB
else if($colorSpace==1){
$h = $w/182.04;
$s = $x/655.35;
$b = $y/655.35;
print $colorSpace." ".$h." ".$s." ".$b."<br/>";
}
//CYMK
else if($colorSpace==2){
$c = 100 - ($w/655.35);
$m = 100 - ($x/655.35);
$y = 100 - ($y/655.35);
$k = 100 - ($z/655.35);
print $colorSpace." ".$c." ".$m." ".$y." ".$k."<br/>";
}
//Lab
else if($colorSpace==7){
// print $colorSpace." ".bin2hex($w[0])." ".bin2hex($w[1])."<br/>";
}
//Grayscale
else if($colorSpace==8){
$greyscale = $w/39.0625;
print $colorSpace." ".$greyscale."<br/>";
}
//Wide CYMK
else if($colorSpace==9){
$c = $w/100;
$m = $x/100;
$y = $y/100;
$k = $z/100;
print $colorSpace." ".$c." ".$m." ".$y." ".$k."<br/>";
}
}
Hope this helps.
Just for reference to others, I faced a similar problem and found this C program that reads ACO files and convert them into html. http://www.hping.org/aco2html/
It's a great tool, but as I wanted to modify it and made it better, I decided to port it to JavaScript. Here's my code on Github https://github.com/websemantics/Color-Palette-Toolkit
There's also a live demo
http://websemantics.github.io/Color-Palette-Toolkit/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With