RichardNewton RichardNewton - 1 year ago 182
Java Question

Algorithm for a smudge tool?

I'm trying to implement a smudge tool like one you would find in Gimp or Photoshop. I've tried lots of variations but they all have problems. The basic method I've tried for smudging from position P1 to P2 on an image is:

  1. Copy a rectangle the size of the current brush from P1.

  2. Draw this rectangle at P2 with a low opacity.

It looks fine and smudges as expected but the main problems I'm having is that the smudge seems to make things darker. Especially when using a small brush spacing, repeated smudging will turn the area to black. Any suggestions on what I'm doing wrong or some standard algorithms I can look at? I've had a look at the Gimp source but it's very hard to follow.

If it matters, I'm working on a mobile device (Android, Java) so something fast would be preferable.

Answer Source

I suspect that you algorithm constantly renders your rectangles on top of each other, likely averaging their values to get the new color value below. Depending on how the particulars of you program is set up, I would wager that the RGB values are going to 0x000000 due to this repeated averaging. This also explains why smaller step distances blacken faster, as more steps equates to more averaging. I had a similar problem with a color changer that was repeatedly blurred going black on the edges.

A good tutorial on creating your own smudge tool can be found here:

Unfortunately, the examples are all in Objective-C but the text explains fairly well what is going on.

Hope this helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download