aboutsummaryrefslogtreecommitdiffstats
path: root/docs/psdheader.html
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 &hellip;         <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">&#182;</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">&#182;</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">&quot;sig&quot;</span>
    <span class="s2">&quot;version&quot;</span>
    </pre></div>             </td>           </tr>                               <tr id="section-3">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-3">&#182;</a>               </div>               <p>These are reserved bytes, always zero</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="s2">&quot;r0&quot;</span>
    <span class="s2">&quot;r1&quot;</span>
    <span class="s2">&quot;r2&quot;</span>
    <span class="s2">&quot;r3&quot;</span>
    <span class="s2">&quot;r4&quot;</span>
    <span class="s2">&quot;r5&quot;</span>

    <span class="s2">&quot;channels&quot;</span>
    <span class="s2">&quot;rows&quot;</span>
    <span class="s2">&quot;cols&quot;</span>
    <span class="s2">&quot;depth&quot;</span>
    <span class="s2">&quot;mode&quot;</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">&#182;</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">&#39;Bitmap&#39;</span>
    <span class="mi">1</span><span class="o">:</span>  <span class="s1">&#39;GrayScale&#39;</span>
    <span class="mi">2</span><span class="o">:</span>  <span class="s1">&#39;IndexedColor&#39;</span>
    <span class="mi">3</span><span class="o">:</span>  <span class="s1">&#39;RGBColor&#39;</span>
    <span class="mi">4</span><span class="o">:</span>  <span class="s1">&#39;CMYKColor&#39;</span>
    <span class="mi">5</span><span class="o">:</span>  <span class="s1">&#39;HSLColor&#39;</span>
    <span class="mi">6</span><span class="o">:</span>  <span class="s1">&#39;HSBColor&#39;</span>
    <span class="mi">7</span><span class="o">:</span>  <span class="s1">&#39;Multichannel&#39;</span>
    <span class="mi">8</span><span class="o">:</span>  <span class="s1">&#39;Duotone&#39;</span>
    <span class="mi">9</span><span class="o">:</span>  <span class="s1">&#39;LabColor&#39;</span>
    <span class="mi">10</span><span class="o">:</span> <span class="s1">&#39;Gray16&#39;</span>
    <span class="mi">11</span><span class="o">:</span> <span class="s1">&#39;RGB48&#39;</span>
    <span class="mi">12</span><span class="o">:</span> <span class="s1">&#39;Lab48&#39;</span>
    <span class="mi">13</span><span class="o">:</span> <span class="s1">&#39;CMYK64&#39;</span>
    <span class="mi">14</span><span class="o">:</span> <span class="s1">&#39;DeepMultichannel&#39;</span>
    <span class="mi">15</span><span class="o">:</span> <span class="s1">&#39;Duotone16&#39;</span>

  <span class="nv">constructor: </span><span class="nf">(@file) -&gt;</span>

  <span class="nv">parse: </span><span class="o">-&gt;</span></pre></div>             </td>           </tr>                               <tr id="section-5">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-5">&#182;</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">&quot;&gt;4sH 6B HLLHH&quot;</span></pre></div>             </td>           </tr>                               <tr id="section-6">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-6">&#182;</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">&#182;</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">&#182;</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">&quot;8BPS&quot;</span>
      <span class="k">throw</span> <span class="s2">&quot;Not a PSD signature: #{@header[&#39;sig&#39;]}&quot;</span>
    </pre></div>             </td>           </tr>                               <tr id="section-9">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-9">&#182;</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">&quot;Can not handle PSD version #{@header[&#39;version&#39;]}&quot;</span></pre></div>             </td>           </tr>                               <tr id="section-10">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-10">&#182;</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">&lt;=</span> <span class="nx">@mode</span> <span class="o">&lt;</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">&quot;(#{@mode})&quot;</span></pre></div>             </td>           </tr>                               <tr id="section-11">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-11">&#182;</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">&quot;color mode data&quot;</span>

  <span class="nv">toJSON: </span><span class="o">-&gt;</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">&#182;</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>