views:

60

answers:

1

I'm trying to write a graphical effect where a circle moves around an image smudging the image as it goes (like the way the smudge tool in Gimp or Photoshop would work). The basic algorithm I'm using is:

  1. the circle moves from position A to position B on the bitmap
  2. copy a circle of pixels from position A into a temporary bitmap
  3. draw this circle of pixels from the temporary bitmap to position B using alpha of about 50%.

This works fine and looks like what I would expect, where the image will look like it's getting smudged if the circle moves 1 pixel at a time over the image.

I now want to add some texture to the smudge effect. I have a bitmap that contains a picture of a paint blob. The algorithm from the above is modified to the following so the smudge takes the shape of this paint blob:

  1. as before
  2. replace the temporary bitmap pixels with the paint blob texture then copy the circle of pixels from position A into the temporary bitmap but only keep the pixels that match up against paint blob pixels (i.e. use Porter-Duff "source in destination" mode when drawing the circle into the temporary bitmap).
  3. as before

This almost works and it looks like it's fine initially but gradually the smudging makes the colors in my image darker! If the circle passes over the same area several times, the colors eventually change to black. Any ideas what I could be doing wrong?

I've implemented the above in Android. I happened upon this post about bitmaps in Android (like my paint blob texture) being loaded with "premultiplied alpha", where the author says it caused his images to become darker because of it: http://www.kittehface.com/2010/06/androidbitmap-and-premultiplied-alpha.html

I suspect I'm suffering from a similar problem but I don't understand what's going on well enough and don't know how to fix it. Does anyone have hints at what might be going on?

+2  A: 

Well from first glance the reason the image is getting darker is because #3 in the first three steps. You overlaying a pixel over an existing pixel at 50%. You might want to consider using the mean of the original pixel value and the new pixel value. You might want to research some blurring algorithms.

Samuel
I've tried searching for variations of "smudging algorithms" and I'm not getting anything that is significantly different from what I'm doing. I see what you mean about the pixel values. Are there are other Porter-Duff modes I could use that would calculate the mean for me? I'm working in Android and doing per-pixel calculations is super slow so I need to get the graphics library to do the hard work.
RichardNewton
I'm not familiar enough with the Android graphics library to recommend the best way to do it. I'm sorry
Samuel
It wouldn't be specific to Android though. Are there any standard graphics tricks you know that I can try?
RichardNewton