Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

48 lines (39 sloc) 12.234 kb
<!DOCTYPE html> <html> <head> <title>caman.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="analyze.html"> analyze.coffee </a> <a class="source" href="blender.html"> blender.coffee </a> <a class="source" href="calculate.html"> calculate.coffee </a> <a class="source" href="caman.html"> caman.coffee </a> <a class="source" href="camaninstance.html"> camaninstance.coffee </a> <a class="source" href="convert.html"> convert.coffee </a> <a class="source" href="event.html"> event.coffee </a> <a class="source" href="filter.html"> filter.coffee </a> <a class="source" href="io.html"> io.coffee </a> <a class="source" href="layer.html"> layer.coffee </a> <a class="source" href="logger.html"> logger.coffee </a> <a class="source" href="pixelinfo.html"> pixelinfo.coffee </a> <a class="source" href="plugin.html"> plugin.coffee </a> <a class="source" href="renderjob.html"> renderjob.coffee </a> <a class="source" href="store.html"> store.coffee </a> <a class="source" href="util.html"> util.coffee </a> <a class="source" href="blenders.html"> blenders.coffee </a> <a class="source" href="filters.html"> filters.coffee </a> <a class="source" href="blur.html"> blur.coffee </a> <a class="source" href="camera.html"> camera.coffee </a> <a class="source" href="compoundBlur.html"> compoundBlur.coffee </a> <a class="source" href="edges.html"> edges.coffee </a> <a class="source" href="posterize.html"> posterize.coffee </a> <a class="source" href="presets.html"> presets.coffee </a> <a class="source" href="size.html"> size.coffee </a> <a class="source" href="stackBlur.html"> stackBlur.coffee </a> <a class="source" href="threshold.html"> threshold.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> caman.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>NodeJS compatibility</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">if</span> <span class="nx">exports</span><span class="o">?</span>
<span class="nv">Root = </span><span class="nx">exports</span>
<span class="nv">Canvas = </span><span class="nx">require</span> <span class="s1">&#39;canvas&#39;</span>
<span class="nv">Image = </span><span class="nx">Canvas</span><span class="p">.</span><span class="nx">Image</span>
<span class="nv">fs = </span><span class="nx">require</span> <span class="s1">&#39;fs&#39;</span>
<span class="k">else</span>
<span class="nv">Root = </span><span class="nb">window</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>Here it begins. Caman is defined.
There are many different initialization for Caman, which are described on the
<a href="http://camanjs.com/docs">Basic Usage</a> page.</p>
<p>Initialization is tricky because we need to make sure everything we need is actually fully
loaded in the DOM before proceeding. When initialized on an image, we need to make sure that the
image is done loading before converting it to a canvas element and writing the pixel data. If we
do this prematurely, the browser will throw a DOM Error, and chaos will ensue. In the event that
we initialize Caman on a canvas element while specifying an image URL, we need to create a new
image element, load the image, then continue with initialization.</p>
<p>The main goal for Caman was simplicity, so all of this is handled transparently to the end-user.
This is also why this piece of code is a bit gross. Once everything is loaded, and Caman is
initialized, the callback function is fired.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">Root.Caman = Caman = </span><span class="o">-&gt;</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>NodeJS version</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">return</span> <span class="k">new</span> <span class="nx">CamanInstance</span> <span class="nx">arguments</span><span class="p">,</span> <span class="nx">CamanInstance</span><span class="p">.</span><span class="nx">Type</span><span class="p">.</span><span class="nx">Node</span> <span class="k">if</span> <span class="nx">exports</span><span class="o">?</span>
<span class="k">switch</span> <span class="nx">arguments</span><span class="p">.</span><span class="nx">length</span>
<span class="k">when</span> <span class="mi">1</span>
<span class="k">return</span> <span class="nx">Store</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="nx">arguments</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="k">if</span> <span class="nx">Store</span><span class="p">.</span><span class="nx">has</span> <span class="nx">arguments</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="k">return</span> <span class="k">new</span> <span class="nx">CamanInstance</span> <span class="nx">arguments</span><span class="p">,</span> <span class="nx">CamanInstance</span><span class="p">.</span><span class="nx">Type</span><span class="p">.</span><span class="nx">Image</span>
<span class="k">when</span> <span class="mi">2</span>
<span class="k">return</span> <span class="nx">Store</span><span class="p">.</span><span class="nx">execute</span> <span class="nx">arguments</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="nx">arguments</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">if</span> <span class="nx">Store</span><span class="p">.</span><span class="nx">has</span> <span class="nx">arguments</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="k">if</span> <span class="k">typeof</span> <span class="nx">arguments</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">is</span> <span class="s1">&#39;function&#39;</span>
<span class="k">return</span> <span class="k">new</span> <span class="nx">CamanInstance</span><span class="p">(</span><span class="nx">arguments</span><span class="p">,</span> <span class="nx">CamanInstance</span><span class="p">.</span><span class="nx">Type</span><span class="p">.</span><span class="nx">Unknown</span><span class="p">)</span>
<span class="k">else</span>
<span class="k">return</span> <span class="k">new</span> <span class="nx">CamanInstance</span><span class="p">(</span><span class="nx">arguments</span><span class="p">,</span> <span class="nx">CamanInstance</span><span class="p">.</span><span class="nx">Type</span><span class="p">.</span><span class="nx">Canvas</span><span class="p">)</span>
<span class="k">when</span> <span class="mi">3</span>
<span class="k">return</span> <span class="nx">Store</span><span class="p">.</span><span class="nx">execute</span> <span class="nx">arguments</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="nx">arguments</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="k">if</span> <span class="nx">Store</span><span class="p">.</span><span class="nx">has</span> <span class="nx">arguments</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="k">return</span> <span class="k">new</span> <span class="nx">CamanInstance</span><span class="p">(</span><span class="nx">arguments</span><span class="p">,</span> <span class="nx">CamanInstance</span><span class="p">.</span><span class="nx">Type</span><span class="p">.</span><span class="nx">Canvas</span><span class="p">)</span>
<span class="nv">Caman.version =</span>
<span class="nv">release: </span><span class="s2">&quot;3.0&quot;</span>
<span class="nv">date: </span><span class="s2">&quot;1/18/12&quot;</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>Debug mode enables console logging</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">Caman.DEBUG = </span><span class="kc">false</span>
<span class="nv">Caman.toString = </span><span class="o">-&gt;</span>
<span class="s2">&quot;Version &quot;</span> <span class="o">+</span> <span class="nx">Caman</span><span class="p">.</span><span class="nx">version</span><span class="p">.</span><span class="nx">release</span> <span class="o">+</span> <span class="s2">&quot;, Released &quot;</span> <span class="o">+</span> <span class="nx">Caman</span><span class="p">.</span><span class="nx">version</span><span class="p">.</span><span class="nx">date</span><span class="p">;</span>
<span class="nv">Caman.remoteProxy = </span><span class="s2">&quot;&quot;</span>
<span class="nv">Caman.Util = </span><span class="nx">Util</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
Jump to Line
Something went wrong with that request. Please try again.