Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
148 lines (111 sloc) 32.2 KB
<!DOCTYPE html> <html> <head> <title>renderjob.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> renderjob.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>Handles all of the various rendering methods in Caman. Most of the image modification happens
here. A new RenderJob object is created for every render operation.</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">RenderJob</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>The number of blocks to split the image into during the render process to simulate
concurrency. This also helps the browser manage the (possibly) long running render jobs.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="vi">@Blocks = </span><span class="mi">4</span>
<span class="vi">@execute: </span><span class="nf">(instance, job, callback) -&gt;</span>
<span class="nv">rj = </span><span class="k">new</span> <span class="nx">RenderJob</span> <span class="nx">instance</span><span class="p">,</span> <span class="nx">job</span><span class="p">,</span> <span class="nx">callback</span>
<span class="k">switch</span> <span class="nx">job</span><span class="p">.</span><span class="nx">type</span>
<span class="k">when</span> <span class="nx">Filter</span><span class="p">.</span><span class="nx">Type</span><span class="p">.</span><span class="nx">LayerDequeue</span>
<span class="nv">layer = </span><span class="nx">instance</span><span class="p">.</span><span class="nx">canvasQueue</span><span class="p">.</span><span class="nx">shift</span><span class="p">()</span>
<span class="nx">instance</span><span class="p">.</span><span class="nx">executeLayer</span> <span class="nx">layer</span>
<span class="k">when</span> <span class="nx">Filter</span><span class="p">.</span><span class="nx">Type</span><span class="p">.</span><span class="nx">LayerFinished</span>
<span class="nx">instance</span><span class="p">.</span><span class="nx">applyCurrentLayer</span><span class="p">()</span>
<span class="nx">instance</span><span class="p">.</span><span class="nx">popContext</span><span class="p">()</span>
<span class="nx">callback</span><span class="p">()</span>
<span class="k">when</span> <span class="nx">Filter</span><span class="p">.</span><span class="nx">Type</span><span class="p">.</span><span class="nx">LoadOverlay</span> <span class="k">then</span> <span class="nx">rj</span><span class="p">.</span><span class="nx">loadOverlay</span> <span class="nx">job</span><span class="p">.</span><span class="nx">layer</span><span class="p">,</span> <span class="nx">job</span><span class="p">.</span><span class="nx">src</span>
<span class="k">when</span> <span class="nx">Filter</span><span class="p">.</span><span class="nx">Type</span><span class="p">.</span><span class="nx">Plugin</span> <span class="k">then</span> <span class="nx">rj</span><span class="p">.</span><span class="nx">executePlugin</span><span class="p">()</span>
<span class="k">else</span> <span class="nx">rj</span><span class="p">.</span><span class="nx">executeFilter</span><span class="p">()</span>
<span class="k">return</span> <span class="nx">instance</span>
<span class="nv">constructor: </span><span class="nf">(@c, @job, @renderDone) -&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>The core of the image rendering, this function executes the provided filter.</p>
<p>NOTE: this does not write the updated pixel data to the canvas. That happens when all filters
are finished rendering in order to be as fast as possible.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">executeFilter: </span><span class="o">-&gt;</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>Prepare all the required render data</p> </td> <td class="code"> <div class="highlight"><pre> <span class="vi">@blocksDone = </span><span class="mi">0</span>
<span class="nv">n = </span><span class="nx">@c</span><span class="p">.</span><span class="nx">pixelData</span><span class="p">.</span><span class="nx">length</span>
<span class="nv">blockPixelLength = </span><span class="nb">Math</span><span class="p">.</span><span class="nx">floor</span> <span class="p">(</span><span class="nx">n</span> <span class="sr">/ 4) /</span> <span class="nx">RenderJob</span><span class="p">.</span><span class="nx">Blocks</span>
<span class="nv">blockN = </span><span class="nx">blockPixelLength</span> <span class="o">*</span> <span class="mi">4</span>
<span class="nv">lastBlockN = </span><span class="nx">blockN</span> <span class="o">+</span> <span class="p">((</span><span class="nx">n</span> <span class="err">/ 4) % RenderJob.Blocks) * 4</span>
<span class="nx">Event</span><span class="p">.</span><span class="nx">trigger</span> <span class="nx">@c</span><span class="p">,</span> <span class="s2">&quot;processStart&quot;</span><span class="p">,</span> <span class="nx">@job</span>
<span class="k">if</span> <span class="nx">@job</span><span class="p">.</span><span class="nx">type</span> <span class="o">is</span> <span class="nx">Filter</span><span class="p">.</span><span class="nx">Type</span><span class="p">.</span><span class="nx">Single</span>
<span class="k">for</span> <span class="nx">j</span> <span class="k">in</span> <span class="p">[</span><span class="mi">0</span><span class="p">...</span><span class="nx">RenderJob</span><span class="p">.</span><span class="nx">Blocks</span><span class="p">]</span>
<span class="nv">start = </span><span class="nx">j</span> <span class="o">*</span> <span class="nx">blockN</span>
<span class="nv">end = </span><span class="nx">start</span> <span class="o">+</span> <span class="p">(</span><span class="k">if</span> <span class="nx">j</span> <span class="o">is</span> <span class="nx">RenderJob</span><span class="p">.</span><span class="nx">Blocks</span> <span class="o">-</span> <span class="mi">1</span> <span class="k">then</span> <span class="nx">lastBlockN</span> <span class="k">else</span> <span class="nx">blockN</span><span class="p">)</span>
<span class="nx">setTimeout</span> <span class="nx">do</span> <span class="p">(</span><span class="nx">j</span><span class="p">,</span> <span class="nx">start</span><span class="p">,</span> <span class="nx">end</span><span class="p">)</span> <span class="o">=&gt;</span>
<span class="o">=&gt;</span> <span class="nx">@renderBlock</span><span class="p">(</span><span class="nx">j</span><span class="p">,</span> <span class="nx">start</span><span class="p">,</span> <span class="nx">end</span><span class="p">)</span>
<span class="p">,</span> <span class="mi">0</span>
<span class="k">else</span>
<span class="nx">@renderKernel</span><span class="p">()</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>Executes a standalone plugin</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">executePlugin: </span><span class="o">-&gt;</span>
<span class="nx">Log</span><span class="p">.</span><span class="nx">debug</span> <span class="s2">&quot;Executing plugin #{@job.plugin}&quot;</span>
<span class="nx">Plugin</span><span class="p">.</span><span class="nx">execute</span> <span class="nx">@c</span><span class="p">,</span> <span class="nx">@job</span><span class="p">.</span><span class="nx">plugin</span><span class="p">,</span> <span class="nx">@job</span><span class="p">.</span><span class="nx">args</span>
<span class="nx">Log</span><span class="p">.</span><span class="nx">debug</span> <span class="s2">&quot;Plugin #{@job.plugin} finished!&quot;</span>
<span class="nx">@renderDone</span><span class="p">()</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>Renders a single block of the canvas with the current filter function</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">renderBlock: </span><span class="nf">(bnum, start, end) -&gt;</span>
<span class="nx">Log</span><span class="p">.</span><span class="nx">debug</span> <span class="s2">&quot;BLOCK ##{bnum} - Filter: #{@job.name}, Start: #{start}, End: #{end}&quot;</span>
<span class="nv">data = r: </span><span class="mi">0</span><span class="p">,</span> <span class="nv">g: </span><span class="mi">0</span><span class="p">,</span> <span class="nv">b: </span><span class="mi">0</span><span class="p">,</span> <span class="nv">a: </span><span class="mi">0</span>
<span class="nv">pixelInfo = </span><span class="k">new</span> <span class="nx">PixelInfo</span> <span class="nx">@c</span>
<span class="k">for</span> <span class="nx">i</span> <span class="k">in</span> <span class="p">[</span><span class="nx">start</span><span class="p">...</span><span class="nx">end</span><span class="p">]</span> <span class="k">by</span> <span class="mi">4</span>
<span class="nv">pixelInfo.loc = </span><span class="nx">i</span>
<span class="nv">data.r = </span><span class="nx">@c</span><span class="p">.</span><span class="nx">pixelData</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span>
<span class="nv">data.g = </span><span class="nx">@c</span><span class="p">.</span><span class="nx">pixelData</span><span class="p">[</span><span class="nx">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span>
<span class="nv">data.b = </span><span class="nx">@c</span><span class="p">.</span><span class="nx">pixelData</span><span class="p">[</span><span class="nx">i</span><span class="o">+</span><span class="mi">2</span><span class="p">]</span>
<span class="nv">data.a = </span><span class="nx">@c</span><span class="p">.</span><span class="nx">pixelData</span><span class="p">[</span><span class="nx">i</span><span class="o">+</span><span class="mi">3</span><span class="p">]</span>
<span class="nv">res = </span><span class="nx">@job</span><span class="p">.</span><span class="nx">processFn</span><span class="p">.</span><span class="nx">call</span> <span class="nx">pixelInfo</span><span class="p">,</span> <span class="nx">data</span>
<span class="nv">res.a = </span><span class="nx">data</span><span class="p">.</span><span class="nx">a</span> <span class="k">if</span> <span class="o">not</span> <span class="nx">res</span><span class="p">.</span><span class="nx">a</span><span class="o">?</span>
<span class="nx">@c</span><span class="p">.</span><span class="nx">pixelData</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span> <span class="o">=</span> <span class="nx">Util</span><span class="p">.</span><span class="nx">clampRGB</span> <span class="nx">res</span><span class="p">.</span><span class="nx">r</span>
<span class="nx">@c</span><span class="p">.</span><span class="nx">pixelData</span><span class="p">[</span><span class="nx">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="nx">Util</span><span class="p">.</span><span class="nx">clampRGB</span> <span class="nx">res</span><span class="p">.</span><span class="nx">g</span>
<span class="nx">@c</span><span class="p">.</span><span class="nx">pixelData</span><span class="p">[</span><span class="nx">i</span><span class="o">+</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="nx">Util</span><span class="p">.</span><span class="nx">clampRGB</span> <span class="nx">res</span><span class="p">.</span><span class="nx">b</span>
<span class="nx">@c</span><span class="p">.</span><span class="nx">pixelData</span><span class="p">[</span><span class="nx">i</span><span class="o">+</span><span class="mi">3</span><span class="p">]</span> <span class="o">=</span> <span class="nx">Util</span><span class="p">.</span><span class="nx">clampRGB</span> <span class="nx">res</span><span class="p">.</span><span class="nx">a</span>
<span class="nx">@blockFinished</span><span class="p">(</span><span class="nx">bnum</span><span class="p">)</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>Applies an image kernel to the canvas</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">renderKernel: </span><span class="o">-&gt;</span>
<span class="nv">name = </span><span class="nx">@job</span><span class="p">.</span><span class="nx">name</span>
<span class="nv">bias = </span><span class="nx">@job</span><span class="p">.</span><span class="nx">bias</span>
<span class="nv">divisor = </span><span class="nx">@job</span><span class="p">.</span><span class="nx">divisor</span>
<span class="nv">n = </span><span class="nx">@c</span><span class="p">.</span><span class="nx">pixelData</span><span class="p">.</span><span class="nx">length</span>
<span class="nv">adjust = </span><span class="nx">@job</span><span class="p">.</span><span class="nx">adjust</span>
<span class="nv">adjustSize = </span><span class="nb">Math</span><span class="p">.</span><span class="nx">sqrt</span> <span class="nx">adjust</span><span class="p">.</span><span class="nx">length</span>
<span class="nv">kernel = </span><span class="p">[]</span>
<span class="nv">modPixelData = </span><span class="p">[]</span>
<span class="nx">Log</span><span class="p">.</span><span class="nx">debug</span> <span class="s2">&quot;Rendering kernel - Filter: #{@job.name}&quot;</span>
<span class="nv">start = </span><span class="nx">@c</span><span class="p">.</span><span class="nx">dimensions</span><span class="p">.</span><span class="nx">width</span> <span class="o">*</span> <span class="mi">4</span> <span class="o">*</span> <span class="p">((</span><span class="nx">adjustSize</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">)</span>
<span class="nv">end = </span><span class="nx">n</span> <span class="o">-</span> <span class="p">(</span><span class="nx">@c</span><span class="p">.</span><span class="nx">dimensions</span><span class="p">.</span><span class="nx">width</span> <span class="o">*</span> <span class="mi">4</span> <span class="o">*</span> <span class="p">((</span><span class="nx">adjustSize</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">))</span>
<span class="nv">builder = </span><span class="p">(</span><span class="nx">adjustSize</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span>
<span class="nv">pixelInfo = </span><span class="k">new</span> <span class="nx">PixelInfo</span> <span class="nx">@c</span>
<span class="k">for</span> <span class="nx">i</span> <span class="k">in</span> <span class="p">[</span><span class="nx">start</span><span class="p">...</span><span class="nx">end</span><span class="p">]</span> <span class="k">by</span> <span class="mi">4</span>
<span class="nv">pixelInfo.loc = </span><span class="nx">i</span>
<span class="nv">builderIndex = </span><span class="mi">0</span>
<span class="k">for</span> <span class="nx">j</span> <span class="k">in</span> <span class="p">[</span><span class="o">-</span><span class="nx">builder</span><span class="p">..</span><span class="nx">builder</span><span class="p">]</span>
<span class="k">for</span> <span class="nx">k</span> <span class="k">in</span> <span class="p">[</span><span class="nx">builder</span><span class="p">..</span><span class="o">-</span><span class="nx">builder</span><span class="p">]</span>
<span class="nv">pixel = </span><span class="nx">pixelInfo</span><span class="p">.</span><span class="nx">getPixelRelative</span> <span class="nx">j</span><span class="p">,</span> <span class="nx">k</span>
<span class="nx">kernel</span><span class="p">[</span><span class="nx">builderIndex</span> <span class="o">*</span> <span class="mi">3</span><span class="p">]</span> <span class="o">=</span> <span class="nx">pixel</span><span class="p">.</span><span class="nx">r</span>
<span class="nx">kernel</span><span class="p">[</span><span class="nx">builderIndex</span> <span class="o">*</span> <span class="mi">3</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="nx">pixel</span><span class="p">.</span><span class="nx">g</span>
<span class="nx">kernel</span><span class="p">[</span><span class="nx">builderIndex</span> <span class="o">*</span> <span class="mi">3</span> <span class="o">+</span> <span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="nx">pixel</span><span class="p">.</span><span class="nx">b</span>
<span class="nx">builderIndex</span><span class="o">++</span>
<span class="nv">res = </span><span class="nx">@processKernel</span> <span class="nx">adjust</span><span class="p">,</span> <span class="nx">kernel</span><span class="p">,</span> <span class="nx">divisor</span><span class="p">,</span> <span class="nx">bias</span>
<span class="nx">modPixelData</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span> <span class="o">=</span> <span class="nx">Util</span><span class="p">.</span><span class="nx">clampRGB</span><span class="p">(</span><span class="nx">res</span><span class="p">.</span><span class="nx">r</span><span class="p">)</span>
<span class="nx">modPixelData</span><span class="p">[</span><span class="nx">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="nx">Util</span><span class="p">.</span><span class="nx">clampRGB</span><span class="p">(</span><span class="nx">res</span><span class="p">.</span><span class="nx">g</span><span class="p">)</span>
<span class="nx">modPixelData</span><span class="p">[</span><span class="nx">i</span><span class="o">+</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="nx">Util</span><span class="p">.</span><span class="nx">clampRGB</span><span class="p">(</span><span class="nx">res</span><span class="p">.</span><span class="nx">b</span><span class="p">)</span>
<span class="nx">modPixelData</span><span class="p">[</span><span class="nx">i</span><span class="o">+</span><span class="mi">3</span><span class="p">]</span> <span class="o">=</span> <span class="nx">@c</span><span class="p">.</span><span class="nx">pixelData</span><span class="p">[</span><span class="nx">i</span><span class="o">+</span><span class="mi">3</span><span class="p">]</span>
<span class="nx">@c</span><span class="p">.</span><span class="nx">pixelData</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span> <span class="o">=</span> <span class="nx">modPixelData</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span> <span class="k">for</span> <span class="nx">i</span> <span class="k">in</span> <span class="p">[</span><span class="nx">start</span><span class="p">...</span><span class="nx">end</span><span class="p">]</span>
<span class="nx">@blockFinished</span> <span class="o">-</span><span class="mi">1</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>Called when a single block is finished rendering. Once all blocks are done, we signal that this
filter is finished rendering and continue to the next step.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">blockFinished: </span><span class="nf">(bnum) -&gt;</span>
<span class="nx">Log</span><span class="p">.</span><span class="nx">debug</span> <span class="s2">&quot;Block ##{bnum} finished! Filter: #{@job.name}&quot;</span> <span class="k">if</span> <span class="nx">bnum</span> <span class="o">&gt;=</span> <span class="mi">0</span>
<span class="nx">@blocksDone</span><span class="o">++</span>
<span class="k">if</span> <span class="nx">@blocksDone</span> <span class="o">is</span> <span class="nx">RenderJob</span><span class="p">.</span><span class="nx">Blocks</span> <span class="o">or</span> <span class="nx">bnum</span> <span class="o">is</span> <span class="o">-</span><span class="mi">1</span>
<span class="nx">Log</span><span class="p">.</span><span class="nx">debug</span> <span class="s2">&quot;Filter #{@job.name} finished!&quot;</span> <span class="k">if</span> <span class="nx">bnum</span> <span class="o">&gt;=</span><span class="mi">0</span>
<span class="nx">Log</span><span class="p">.</span><span class="nx">debug</span> <span class="s2">&quot;Kernel filter #{@job.name} finished!&quot;</span> <span class="k">if</span> <span class="nx">bnum</span> <span class="o">&lt;</span> <span class="mi">0</span>
<span class="nx">Event</span><span class="p">.</span><span class="nx">trigger</span> <span class="nx">@c</span><span class="p">,</span> <span class="s2">&quot;processComplete&quot;</span><span class="p">,</span> <span class="nx">@job</span>
<span class="nx">@renderDone</span><span class="p">()</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 "filter function" for kernel adjustments.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">processKernel: </span><span class="nf">(adjust, kernel, divisor, bias) -&gt;</span>
<span class="nv">val = r: </span><span class="mi">0</span><span class="p">,</span> <span class="nv">g: </span><span class="mi">0</span><span class="p">,</span> <span class="nv">b: </span><span class="mi">0</span>
<span class="k">for</span> <span class="nx">i</span> <span class="k">in</span> <span class="p">[</span><span class="mi">0</span><span class="p">...</span><span class="nx">adjust</span><span class="p">.</span><span class="nx">length</span><span class="p">]</span>
<span class="nx">val</span><span class="p">.</span><span class="nx">r</span> <span class="o">+=</span> <span class="nx">adjust</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span> <span class="o">*</span> <span class="nx">kernel</span><span class="p">[</span><span class="nx">i</span> <span class="o">*</span> <span class="mi">3</span><span class="p">]</span>
<span class="nx">val</span><span class="p">.</span><span class="nx">g</span> <span class="o">+=</span> <span class="nx">adjust</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span> <span class="o">*</span> <span class="nx">kernel</span><span class="p">[</span><span class="nx">i</span> <span class="o">*</span> <span class="mi">3</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span>
<span class="nx">val</span><span class="p">.</span><span class="nx">b</span> <span class="o">+=</span> <span class="nx">adjust</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span> <span class="o">*</span> <span class="nx">kernel</span><span class="p">[</span><span class="nx">i</span> <span class="o">*</span> <span class="mi">3</span> <span class="o">+</span> <span class="mi">2</span><span class="p">]</span>
<span class="nv">val.r = </span><span class="p">(</span><span class="nx">val</span><span class="p">.</span><span class="nx">r</span> <span class="err">/ divisor) + bias</span>
<span class="nv">val.g = </span><span class="p">(</span><span class="nx">val</span><span class="p">.</span><span class="nx">g</span> <span class="err">/ divisor) + bias</span>
<span class="nv">val.b = </span><span class="p">(</span><span class="nx">val</span><span class="p">.</span><span class="nx">b</span> <span class="err">/ divisor) + bias</span>
<span class="nx">val</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>Loads an image onto the current canvas</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">loadOverlay: </span><span class="nf">(layer, src) -&gt;</span>
<span class="nv">img = </span><span class="nb">document</span><span class="p">.</span><span class="nx">createElement</span> <span class="s1">&#39;img&#39;</span>
<span class="nv">img.onload = </span><span class="o">=&gt;</span>
<span class="nx">layer</span><span class="p">.</span><span class="nx">context</span><span class="p">.</span><span class="nx">drawImage</span> <span class="nx">img</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">@c</span><span class="p">.</span><span class="nx">dimensions</span><span class="p">.</span><span class="nx">width</span><span class="p">,</span> <span class="nx">@c</span><span class="p">.</span><span class="nx">dimensions</span><span class="p">.</span><span class="nx">height</span>
<span class="nv">layer.imageData = </span><span class="nx">layer</span><span class="p">.</span><span class="nx">context</span><span class="p">.</span><span class="nx">getImageData</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">@c</span><span class="p">.</span><span class="nx">dimensions</span><span class="p">.</span><span class="nx">width</span><span class="p">,</span> <span class="nx">@c</span><span class="p">.</span><span class="nx">dimensions</span><span class="p">.</span><span class="nx">height</span>
<span class="nv">layer.pixelData = </span><span class="nx">layer</span><span class="p">.</span><span class="nx">imageData</span><span class="p">.</span><span class="nx">data</span>
<span class="vi">@c.pixelData = </span><span class="nx">layer</span><span class="p">.</span><span class="nx">pixelData</span>
<span class="nx">@c</span><span class="p">.</span><span class="nx">processNext</span><span class="p">()</span>
<span class="nv">proxyUrl = </span><span class="nx">IO</span><span class="p">.</span><span class="nx">remoteCheck</span> <span class="nx">src</span>
<span class="nv">img.src = </span><span class="k">if</span> <span class="nx">proxyUrl</span><span class="o">?</span> <span class="k">then</span> <span class="nx">proxyUrl</span> <span class="k">else</span> <span class="nx">src</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
Something went wrong with that request. Please try again.