Your output looks like a multiple of the original output in some form - the basic structure is there, but the image appears to be offset and banded for whatever reason. Are you running your filter in non-RGB mode (eg not per channel)?
You really should post some code, and not only the filter but more likely the calling loop and how you output the resulting image. Have you tried a pass thru filter - eg are you getting exactly the same output as the input when no filter is applied? There are so many links here that could be wrong that I wouldn't be surprised if your filter was working properly.
Oh and one more thing - have you accounted for a possible alpha channel?