A: 

If t_a is not a floating point value, then calculations such as (255 - t_a) / 255 are done as integers too. You need to cast one of your inputs to a float beforehand, e.g ((255 - t_a) / 255f).

Hannesh
I tried that, but unfortunately didn't help.
TuomasR
+1  A: 

You need to change a lot of this.

t_r, t_a etc must all be floats from 0 to 1. Do all your calculations in floating point, then multiply by 255 and then cast to int.

Hannesh
Did that, no help. Image still comes out wrong. Code here: http://pastebin.com/9YVU53nU
TuomasR
Ah, I was missing one division by 255 in the beginning, now it works, thanks.
TuomasR