blob: cb0fd51865f7e512fcd11e187e960c3074a82318 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
<!DOCTYPE html> <html> <head> <title>psdheader.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To … <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="blackwhite.html"> blackwhite.coffee </a> <a class="source" href="brightnesscontrast.html"> brightnesscontrast.coffee </a> <a class="source" href="colorbalance.html"> colorbalance.coffee </a> <a class="source" href="curves.html"> curves.coffee </a> <a class="source" href="exposure.html"> exposure.coffee </a> <a class="source" href="gradient.html"> gradient.coffee </a> <a class="source" href="huesaturation.html"> huesaturation.coffee </a> <a class="source" href="invert.html"> invert.coffee </a> <a class="source" href="layereffect.html"> layereffect.coffee </a> <a class="source" href="levels.html"> levels.coffee </a> <a class="source" href="pattern.html"> pattern.coffee </a> <a class="source" href="photofilter.html"> photofilter.coffee </a> <a class="source" href="posterize.html"> posterize.coffee </a> <a class="source" href="selectivecolor.html"> selectivecolor.coffee </a> <a class="source" href="solidcolor.html"> solidcolor.coffee </a> <a class="source" href="threshold.html"> threshold.coffee </a> <a class="source" href="typetool.html"> typetool.coffee </a> <a class="source" href="vibrance.html"> vibrance.coffee </a> <a class="source" href="log.html"> log.coffee </a> <a class="source" href="psd.html"> psd.coffee </a> <a class="source" href="psdassert.html"> psdassert.coffee </a> <a class="source" href="psdchannelimage.html"> psdchannelimage.coffee </a> <a class="source" href="psdcolor.html"> psdcolor.coffee </a> <a class="source" href="psddescriptor.html"> psddescriptor.coffee </a> <a class="source" href="psdfile.html"> psdfile.coffee </a> <a class="source" href="psdheader.html"> psdheader.coffee </a> <a class="source" href="psdimage.html"> psdimage.coffee </a> <a class="source" href="psdlayer.html"> psdlayer.coffee </a> <a class="source" href="psdlayermask.html"> psdlayermask.coffee </a> <a class="source" href="psdresource.html"> psdresource.coffee </a> <a class="source" href="util.html"> util.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> psdheader.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">¶</a> </div> <p>The PSD header describes all kinds of important information pertaining to
the PSD file such as size, color channels, color depth, and so on.</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">PSDHeader</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">¶</a> </div> <p>All of the sections that the header contains. These will become properties
of the instantiated header object once parsed.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">HEADER_SECTIONS = </span><span class="p">[</span>
<span class="s2">"sig"</span>
<span class="s2">"version"</span>
</pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">¶</a> </div> <p>These are reserved bytes, always zero</p> </td> <td class="code"> <div class="highlight"><pre> <span class="s2">"r0"</span>
<span class="s2">"r1"</span>
<span class="s2">"r2"</span>
<span class="s2">"r3"</span>
<span class="s2">"r4"</span>
<span class="s2">"r5"</span>
<span class="s2">"channels"</span>
<span class="s2">"rows"</span>
<span class="s2">"cols"</span>
<span class="s2">"depth"</span>
<span class="s2">"mode"</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">¶</a> </div> <p>Common names for various color modes, which are specified by an integer in
the header.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">MODES =</span>
<span class="mi">0</span><span class="o">:</span> <span class="s1">'Bitmap'</span>
<span class="mi">1</span><span class="o">:</span> <span class="s1">'GrayScale'</span>
<span class="mi">2</span><span class="o">:</span> <span class="s1">'IndexedColor'</span>
<span class="mi">3</span><span class="o">:</span> <span class="s1">'RGBColor'</span>
<span class="mi">4</span><span class="o">:</span> <span class="s1">'CMYKColor'</span>
<span class="mi">5</span><span class="o">:</span> <span class="s1">'HSLColor'</span>
<span class="mi">6</span><span class="o">:</span> <span class="s1">'HSBColor'</span>
<span class="mi">7</span><span class="o">:</span> <span class="s1">'Multichannel'</span>
<span class="mi">8</span><span class="o">:</span> <span class="s1">'Duotone'</span>
<span class="mi">9</span><span class="o">:</span> <span class="s1">'LabColor'</span>
<span class="mi">10</span><span class="o">:</span> <span class="s1">'Gray16'</span>
<span class="mi">11</span><span class="o">:</span> <span class="s1">'RGB48'</span>
<span class="mi">12</span><span class="o">:</span> <span class="s1">'Lab48'</span>
<span class="mi">13</span><span class="o">:</span> <span class="s1">'CMYK64'</span>
<span class="mi">14</span><span class="o">:</span> <span class="s1">'DeepMultichannel'</span>
<span class="mi">15</span><span class="o">:</span> <span class="s1">'Duotone16'</span>
<span class="nv">constructor: </span><span class="nf">(@file) -></span>
<span class="nv">parse: </span><span class="o">-></span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">¶</a> </div> <p>Read the header section</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">data = </span><span class="nx">@file</span><span class="p">.</span><span class="nx">readf</span> <span class="s2">">4sH 6B HLLHH"</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">¶</a> </div> <p>Add all of the header sections as properties of this object.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="err">@</span><span class="p">[</span><span class="nx">section</span><span class="p">]</span> <span class="o">=</span> <span class="nx">data</span><span class="p">.</span><span class="nx">shift</span><span class="p">()</span> <span class="k">for</span> <span class="nx">section</span> <span class="k">in</span> <span class="nx">HEADER_SECTIONS</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">¶</a> </div> <p>Store size in an easy to use place for later</p> </td> <td class="code"> <div class="highlight"><pre> <span class="vi">@size = </span><span class="p">[</span><span class="nx">@rows</span><span class="p">,</span> <span class="nx">@cols</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">¶</a> </div> <p>This must be 8BPS according to the spec, or else this is not a valid PSD
file.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="nx">@sig</span> <span class="o">isnt</span> <span class="s2">"8BPS"</span>
<span class="k">throw</span> <span class="s2">"Not a PSD signature: #{@header['sig']}"</span>
</pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">¶</a> </div> <p>The spec only covers version 1 of PSDs. I believe this is the only
version available at this time, anyways.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="nx">@version</span> <span class="o">isnt</span> <span class="mi">1</span>
<span class="k">throw</span> <span class="s2">"Can not handle PSD version #{@header['version']}"</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">¶</a> </div> <p>Store the common mode name</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="mi">0</span> <span class="o"><=</span> <span class="nx">@mode</span> <span class="o"><</span> <span class="mi">16</span>
<span class="vi">@modename = </span><span class="nx">MODES</span><span class="p">[</span><span class="nx">@mode</span><span class="p">]</span>
<span class="k">else</span>
<span class="vi">@modename = </span><span class="s2">"(#{@mode})"</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">¶</a> </div> <p>Information about the color mode is a bit complex. We're skipping this
for now. TODO.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="vi">@colormodepos = </span><span class="nx">@file</span><span class="p">.</span><span class="nx">pos</span>
<span class="nx">@file</span><span class="p">.</span><span class="nx">skipBlock</span> <span class="s2">"color mode data"</span>
<span class="nv">toJSON: </span><span class="o">-></span>
<span class="nv">data = </span><span class="p">{}</span>
<span class="k">for</span> <span class="nx">section</span> <span class="k">in</span> <span class="nx">HEADER_SECTIONS</span>
<span class="nx">data</span><span class="p">[</span><span class="nx">section</span><span class="p">]</span> <span class="o">=</span> <span class="err">@</span><span class="p">[</span><span class="nx">section</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">¶</a> </div> <p>Some extra data</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">data.modename = </span><span class="nx">@modename</span>
<span class="nx">data</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
|