Hello,

Rick Root wrote:
>  From this code:
>
> http://www.jhlabs.com/ip/BoxBlurFilter.java
>
> I'm interested in the following snippet:
>
>       ta += ((rgb1 >> 24) & 0xff)-((rgb2 >> 24) & 0xff);
>       tr += ((rgb1 & 0xff0000)-(rgb2 & 0xff0000)) >> 16;
>       tg += ((rgb1 & 0xff00)-(rgb2 & 0xff00)) >> 8;
>       tb += (rgb1 & 0xff)-(rgb2 & 0xff);
>
> Here's the code I've written in CF.
>
>       ta = ta + 
> BitAnd(BitSHRN(rgbRight,24),255)-BitAnd(bitSHRN(rgbLeft,24),255);
>       tr = tr + 
> BitSHRN(BitAnd(rgbRight,16711680)-BitAnd(rgbLeft,16711680),16);
>       tg = tg + BitSHRN(BitAnd(rgbRight,65280)-BitAnd(rgbLeft,65280),8);
>       tb = tb + BitAnd(rgbRight,255)-BitAnd(rgbLeft,255);
>
> Unfortunately, this isn't working.  Either I've written the code wrong, 
> or the original code is wrong.  I don't understand what it's doing at 
> all other than it's SUPPOSED to cause a blur by doing something with 
> pixels to the left and right of a given pixel.
>   

The concept is almost right, with a blur every pixel has a percentage of 
its adjacent pixels added into it so the simple sum indicated by the tb 
above is correct except that there is no percentage component. The sum 
should be in the form new_pixel = old_pixel + 
percentage_of_blur(left_pixel-Right_Pixel) but that is at the pixel 
level, not with the RGB components. If you do simple math like that 
component-by-component you get some very messy artifacts with the major 
contributor being that fact that the eye is non-linear in that space. 
You need to convert everything to Y/R-Y/B-Y, HSV or a similar coding so 
that the manipulation occur along the correct axes. Take a peek at:
http://www.mbcomms.net.au/tools/ColourPicker1.cfm, grab a couple of 
colours and go to the "View Related Colours" page (button in lower right 
area of the first page, the design was based on the "squeeze as much as 
you can on the page" principle :-)) That page has a section lower down 
where graduations of colours take place, a blur in effect, quite 
smoothly. All of the maths behind that is HSV-based and works well.

We got that code from the 'Net, credits given there somewhere, and I can 
pass it on if you wish....



HTH

Kym K

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Create robust enterprise, web RIAs.
Upgrade & integrate Adobe Coldfusion MX7 with Flex 2
http://ad.doubleclick.net/clk;56760587;14748456;a?http://www.adobe.com/products/coldfusion/flex2/?sdid=LVNU

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:263896
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to