Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A friend and I were trying to do this a while back for a project, and found writing an inline method that does this in ActionScript to be incredibly slow. You have to scan each pixel and do a computation against it, but doing it with PixelBender proved to be lightning fast (if you can use Flash 10, otherwise your stuck with slow AS).</p> <p>The pixel bender code looks like:</p> <pre><code>input image4 src; output float4 dst; // How close of a match you want parameter float threshold &lt; minValue: 0.0; maxValue: 1.0; defaultValue: 0.4; &gt;; // Color you are matching against. parameter float3 color &lt; defaultValue: float3(1.0, 1.0, 1.0); &gt;; void evaluatePixel() { float4 current = sampleNearest(src, outCoord()); dst = float4((distance(current.rgb, color) &lt; threshold) ? 0.0 : current); } </code></pre> <p>If you need to do it in AS you can use something like:</p> <pre><code>function threshold(source:BitmapData, dest:BitmapData, color:uint, threshold:Number) { dest.lock(); var x:uint, y:uint; for (y = 0; y &lt; source.height; y++) { for (x = 0; x &lt; source.width; x++) { var c1:uint = source.getPixel(x, y); var c2:uint = color; var rx:uint = Math.abs(((c1 &amp; 0xff0000) &gt;&gt; 16) - ((c2 &amp; 0xff0000) &gt;&gt; 16)); var gx:uint = Math.abs(((c1 &amp; 0xff00) &gt;&gt; 8) - ((c2 &amp; 0xff00) &gt;&gt; 8)); var bx:uint = Math.abs((c1 &amp; 0xff) - (c2 &amp; 0xff)); var dist = Math.sqrt(rx*rx + gx*gx + bx*bx); if (dist &lt;= threshold) dest.setPixel(x, y, 0x00ffffff); else dest.setPixel(x, y, c1); } } dest.unlock(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload