<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" 
      xmlns:thr="http://purl.org/syndication/thread/1.0">
  <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/05/back-to-filters.html" />
  <link rel="self" type="application/atom+xml" href="http://www.insideria.com/atom.xml" />
  <id>tag:www.insideria.com,2009://34/tag:www.insideria.com,2008://34.23796-</id>
  <updated>2009-11-16T15:43:21Z</updated>
  <title>Comments for Back To Filters... (http://www.insideria.com/2008/05/back-to-filters.html)</title>
  <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.21-en</generator>
  <entry>
    <id>tag:www.insideria.com,2008://34.23796</id>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/05/back-to-filters.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.oreilly.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=34/entry_id=23796" title="Back To Filters..." />
    <published>2008-05-23T01:56:48Z</published>
    <updated>2008-05-23T11:24:40Z</updated>
    <title>Back To Filters...</title>
    <summary>With all this talk about Astro, and PixelBender, it made me think more about graphics filters.   So, I thought I&apos;d revisit them.   A few months back, I did a series on graphics tricks. This time, I&apos;m sticking to the good old filters (not the shiny new ones in PixelBender), and decided to focus on displacement map filters.   Basically, the displacement map filter displaces the pixels of a component, based on the bitmap data that is passed into the filter. </summary>
    <author>
      <name>Andrew Trice</name>
      
    </author>
    
    <category term="Blogs" />
    
    <content type="html" xml:lang="en" xml:base="http://www.insideria.com/">
      <![CDATA[With all this talk about <a href="http://labs.adobe.com/technologies/flashplayer10/" target="_blank">Astro</a>, and <a target="_blank" href="http://www.adobe.com/cfusion/exchange/index.cfm?event=productHome&exc=26&loc=en_us">PixelBender</a>, it made me think more about graphics filters.   So, I thought I'd revisit them.   A few months back, I did a series on graphics tricks:<br /><br />

<a href="http://www.insideria.com/2008/01/flex-graphics-tricks-part-1-ma.html" target="_blank">Flex Graphics Tricks Part 1: Masks</a><br />

<a href="http://www.insideria.com/2008/02/flex-graphics-tricks-part-2-bl.html" target="_blank">Flex Graphics Tricks Part 2: Blend Modes</a><br />

<a href="http://www.insideria.com/2008/02/flex-graphics-tricks-part-3-gr.html" target="_blank">Flex Graphics Tricks Part 3: Graphics Filters</a><br /><br />

This time, I'm sticking to the good old filters (not the shiny new ones in PixelBender), and decided to focus on displacement map filters.   Basically, the displacement map filter displaces the pixels of a component, based on the bitmap data that is passed into the filter.   The Adobe documents sum it up better than I can:
<br /><br />
<blockquote>The DisplacementMapFilter class uses pixel values from a BitmapData object (known as the displacement map image) to perform a displacement effect on a new object. The displacement map image is typically different than the actual display object or BitmapData instance to which the filter is being applied. A displacement effect involves displacing pixels in the filtered image--in other words, shifting them away from their original location to some extent. This filter can be used to create a shifted, warped, or mottled effect.</blockquote>
<br />
You can read more about it on the Adobe Documentation at: <a target="_blank" href="http://livedocs.adobe.com/flex/3/html/help.html?content=Filtering_Visual_Objects_18.html">http://livedocs.adobe.com/flex/3/html/help.html?content=Filtering_Visual_Objects_18.html</a>
<br /><br />
I decided to take my previous post on <a href="http://www.insideria.com/2008/05/google-releases-as3-maps-api.html" target="_blank">Google Maps,</a> and show how to put a displacement filter on it.   Here's the example:

<iframe 
src="http://www.tricedesigns.com/portfolio/google_displacement/main.html"
width="425" height="350" frameborder="0">
</iframe>
<br />
<em>Move the mouse over the map to see the effect.</em>
<br /><br />
Now, here's how it works.   I put a DisplaceMentMapFilter directly on the UIComponent container that is used to display the Google map component.   This will cause the graphics filter to displace the graphics of the uicomponent, thus any child componets as well.
<br /><br />
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;"> 
<code language="perl">
<pre> 
&lt;?xml <span class="category2">version</span>="<span class="quote">1.0</span>" encoding="<span class="quote">utf-8</span>"?&gt;
&lt;mx:DisplacementMapFilter 
	id="<span class="quote">displacementMap</span>" 
	scaleX="<span class="quote">100</span>" 
	mode="<span class="quote">{ DisplacementMapFilterMode.CLAMP }</span>"
	componentX="<span class="quote">{ BitmapDataChannel.RED }</span>"/&gt;</pre>
</code>

</div></div> <br />

On the filter, there are a few key parameters that you will need to know about:  In this example, I only used the X direction to keep it simple.
<br /><br />
<b>componentX</b> and <b>componentY</b><br />
These two parameters are used to determine which color channels of the displacement bitmap should be applied to the distortion of the target object.  In this example, I am only looking at the values of the RED color channel.  <br /><br />

<b>scaleX</b> and <b>scaleY</b> <br />
This is a multiplier that determines the amount to displace the image pixels based on the colors in the displacement bitmap.  When using the color channel, you can displace both in the positive and negative direction.  A hex value on the red channel of 7F would be a displacement of 0 (no displacement).  7f is halfway between 0 and FF.  The values 0 and FF would represent the extremes of the displacement (-scaleX, and scaleX).   You can use different color channels to have different displacement in the X and Y directions.<br /><br />

<div class="ap_r_front"  style="margin: 0px 14px; 14px; 14px;"><a href="http://www.insideria.com/upload/2008/05/back_to_filters/displacementSource.png" class="highslide" onclick="return hs.expand(this)"><img src="http://www.insideria.com/upload/2008/05/back_to_filters/displacementSource.png" alt="displacementSource.png" title="Click to enlarge" width="148"/></a></div>In this example, I'm using this source image over a canvas with a background color #7F7F7F (neutral) as the displacement bitmap source.  The image position is updated on the mouseMove event to follow the mouse, so the achieved effect is a "magnified" view of the image just below the mouse.
<br /><br />
You can view the application in a new window at:<br />
<a target="_blank" href="http://www.tricedesigns.com/portfolio/google_displacement/main.html">http://www.tricedesigns.com/portfolio/google_displacement/main.html</a>
<br /><br />
You can view the source at:<br />
<a target="_blank" href="http://www.tricedesigns.com/portfolio/google_displacement/srcview/index.html">http://www.tricedesigns.com/portfolio/google_displacement/srcview/index.html</a>
<br /><br />
___________________________________<br />
<strong>Andrew Trice</strong><br />
Principal Architect<br />
<a href="http://www.cynergysystems.com" target="_blank">Cynergy Systems
http://www.cynergysystems.com</a>]]>
      
    </content>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.23796-comment:2017341</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.23796" type="text/html" href="http://www.insideria.com/2008/05/back-to-filters.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/05/back-to-filters.html#comment-2017341" />
    <title>Comment from Philip Thonbo on 2008-05-24</title>
    <author>
        <name>Philip Thonbo</name>
        <uri>http://www.thonbo.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.thonbo.com">
        <![CDATA[<p>actually the neutral base is 808080 and your lens is a bit distorted too much on the x axis - i just made this to show you how its really ment to be...</p>

<p><a href="http://thonbo.com/tempShowCase/lensLab.html">http://thonbo.com/tempShowCase/lensLab.html</a></p>]]>
    </content>
    <published>2008-05-24T08:41:24Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.23796-comment:2017444</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.23796" type="text/html" href="http://www.insideria.com/2008/05/back-to-filters.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/05/back-to-filters.html#comment-2017444" />
    <title>Comment from Andrew Trice on 2008-05-29</title>
    <author>
        <name>Andrew Trice</name>
        <uri>http://www.tricedesigns.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.tricedesigns.com">
        <![CDATA[<p>Thanks Philip, that's a great example.   I kept mine simple, and only in the x direction on purpose.   Yours shows a lot more of the capability that the displacement filters are capable of.  </p>]]>
    </content>
    <published>2008-05-29T23:02:06Z</published>
  </entry>

</feed
